Core.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | tester 体验者设置
  5. |--------------------------------------------------------------------------
  6. */
  7. namespace Component\Src;
  8. use Dever;
  9. use Main\Lib\Wechat;
  10. class Core
  11. {
  12. public function update($id, $data, $param = array())
  13. {
  14. $delete = false;
  15. if (isset($param['state']) && $param['state'] == 2) {
  16. $delete = true;
  17. }
  18. $info = Dever::db('component/' . $this->table)->one($id);
  19. if (!$info) {
  20. return;
  21. }
  22. $user = Dever::param('user', $param);
  23. if (!$user) {
  24. $user = Dever::db('component/user')->state(array('option_project_id' => $info['project_id']));
  25. }
  26. if ($user) {
  27. foreach ($user as $v) {
  28. $this->set($v, $info['id'], $delete);
  29. }
  30. }
  31. }
  32. public function set($user, $id, $delete = false)
  33. {
  34. $result = array();
  35. if (is_numeric($user) && $user > 0) {
  36. $user = Dever::db('component/user')->one($user);
  37. }
  38. if ($user && $user['oauth_id']) {
  39. $oauth = Dever::db('main/oauth')->one($user['oauth_id']);
  40. $send = array();
  41. $send['d'] = $delete;
  42. $send['i'] = $id;
  43. $send['t'] = $this->table;
  44. $send['o'] = $oauth['id'];
  45. $send['u'] = $user['id'];
  46. $result = Dever::daemon($this->url($send), 'component');
  47. }
  48. return $result;
  49. }
  50. public function url($send)
  51. {
  52. $send = base64_encode(json_encode($send));
  53. $url = 'core.call?param=' . $send;
  54. return $url;
  55. }
  56. public function call()
  57. {
  58. $send = json_decode(base64_decode(Dever::input('param')), true);
  59. if (isset($send['o']) && $send['o'] > 0 && isset($send['i']) && $send['i'] > 0) {
  60. $table = 'component/' . $send['t'];
  61. $info = Dever::db($table)->one($send['i']);
  62. $wechat = new Wechat($info['project_id'], 'component');
  63. $oauth = $wechat->oauth($send['o']);
  64. if ($oauth && $oauth['value']) {
  65. $oauth['oauth'] = $oauth['value'];
  66. $oauth = Dever::load($table)->handle($oauth, $info, $send['d'], $send['u'], $wechat);
  67. $result = $wechat->curl($oauth['method'], $oauth, false);
  68. $this->log($table, $send['u'], $info, $result, $oauth['method'], $oauth);
  69. }
  70. }
  71. return;
  72. }
  73. public function log($table, $user, $info, $result, $method, $param)
  74. {
  75. print_r($result);
  76. if ($table == 'component/version') {
  77. $insert['user_id'] = $user;
  78. $insert['name'] = $info['name'];
  79. $insert['template_id'] = $info['template_id'];
  80. $insert['project_id'] = $info['project_id'];
  81. $insert['version_id'] = $info['id'];
  82. $insert['result'] = json_encode($result);
  83. Dever::db($table . '_log')->insert($insert);
  84. } elseif ($table == 'component/auditing') {
  85. if (isset($result['auditid'])) {
  86. $update['auditid'] = $result['auditid'];
  87. }
  88. $update['result'] = json_encode($result);
  89. $update['where_id'] = $info['id'];
  90. Dever::db($table)->update($update);
  91. } elseif ($table == 'component/publish' || $table == 'component/revert' || $table == 'component/unaudit') {
  92. if ($result['errcode'] == 0) {
  93. $update['status'] = 2;
  94. } else {
  95. $update['status'] = 3;
  96. }
  97. $update['result'] = json_encode($result);
  98. $update['where_id'] = $info['id'];
  99. Dever::db($table)->update($update);
  100. if ($table == 'component/unaudit') {
  101. $audit = array('option_user_id' => $info['user_id'], 'option_project_id' => $info['project_id'], 'option_version_id' => $info['version_id'], 'option_status' => 1);
  102. $audit = Dever::db('component/auditing')->all($audit);
  103. if ($audit) {
  104. foreach ($audit as $k => $v) {
  105. $update = array();
  106. $update['set_status'] = 3;
  107. $update['set_statusDesc'] = '撤回';
  108. $update['where_id'] = $v['id'];
  109. Dever::db('component/auditing')->update($update);
  110. }
  111. }
  112. }
  113. }
  114. die;
  115. }
  116. }