App.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php namespace Api\Lib;
  2. use Dever;
  3. class App
  4. {
  5. public function update($db, $data)
  6. {
  7. $func = Dever::db('app_func_work', 'api')->select(array('app_func_id' => $data['id']));
  8. if ($func) {
  9. $platform = array();
  10. Dever::db('app_platform', 'api')->delete(array('app_id' => $data['app_id']));
  11. foreach ($func as $k => $v) {
  12. $api = Dever::db('api', 'api')->find($v['api_id']);
  13. if ($api) {
  14. $platform[$api['platform_id']] = $api['platform_id'];
  15. }
  16. }
  17. foreach ($platform as $k => $v) {
  18. Dever::db('app_platform', 'api')->insert(array('app_id' => $data['app_id'], 'platform_id' => $v));
  19. }
  20. }
  21. }
  22. public function updateApi($db, $data)
  23. {
  24. if (isset($data['notify']) && $data['notify'] == 2) {
  25. Dever::db('api/api_notify')->delete(array('api_id' => $data['id']));
  26. }
  27. }
  28. public function getPlatform($app)
  29. {
  30. $set['join'] = array
  31. (
  32. array
  33. (
  34. 'table' => 'platform',
  35. 'type' => 'left join',
  36. 'on' => 'platform.id=app_platform.platform_id',
  37. ),
  38. );
  39. $set['col'] = 'platform.id as id,platform.name as name';
  40. $platform = Dever::db('app_platform', 'api')->select(array('app_id' => $app), $set);
  41. return $platform;
  42. }
  43. public function getSetting($platform_id)
  44. {
  45. return Dever::db('platform_setting', 'api')->select(array('platform_id' => $platform_id));
  46. }
  47. public function getCert($platform_id)
  48. {
  49. return Dever::db('platform_cert', 'api')->select(array('platform_id' => $platform_id));
  50. }
  51. public function getCertName($id)
  52. {
  53. $info = Dever::db('platform_cert', 'api')->find($id);
  54. return $info['name'];
  55. }
  56. public function getApi($func_id, $env = 1)
  57. {
  58. $set['join'] = array
  59. (
  60. array
  61. (
  62. 'table' => 'api',
  63. 'type' => 'left join',
  64. 'on' => 'api.id=app_func_work.api_id',
  65. ),
  66. );
  67. $set['col'] = 'api.*';
  68. $set['order'] = 'app_func_work.sort asc,api.id desc';
  69. $where['app_func_work.app_func_id'] = $func_id;
  70. if ($env) {
  71. $where['api.env'] = $env;
  72. }
  73. return Dever::db('app_func_work', 'api')->select($where, $set);
  74. }
  75. public function getAppPlatform($app_id, $platform_id)
  76. {
  77. $app = Dever::db('app', 'api')->find($app_id);
  78. $platform = Dever::db('platform', 'api')->find($platform_id);
  79. return $app['name'] . '-' . $platform['name'];
  80. }
  81. }