table)->one($id); if (!$info) { return; } $user = Dever::param('user', $param); if (!$user) { $user = Dever::db('component/user')->state(array('option_project_id' => $info['project_id'])); } if ($user) { foreach ($user as $v) { $this->set($v, $info['id'], $delete); } } } public function set($user, $id, $delete = false) { $result = array(); if (is_numeric($user) && $user > 0) { $user = Dever::db('component/user')->one($user); } if ($user && $user['oauth_id']) { $oauth = Dever::db('main/oauth')->one($user['oauth_id']); $send = array(); $send['d'] = $delete; $send['i'] = $id; $send['t'] = $this->table; $send['o'] = $oauth['id']; $send['u'] = $user['id']; $result = Dever::daemon($this->url($send), 'component'); } return $result; } public function url($send) { $send = base64_encode(json_encode($send)); $url = 'core.call?param=' . $send; return $url; } public function call() { $send = json_decode(base64_decode(Dever::input('param')), true); if (isset($send['o']) && $send['o'] > 0 && isset($send['i']) && $send['i'] > 0) { $table = 'component/' . $send['t']; $info = Dever::db($table)->one($send['i']); $wechat = new Wechat($info['project_id'], 'component'); $oauth = $wechat->oauth($send['o']); if ($oauth && $oauth['value']) { $oauth['oauth'] = $oauth['value']; $oauth = Dever::load($table)->handle($oauth, $info, $send['d'], $send['u'], $wechat); $result = $wechat->curl($oauth['method'], $oauth, false); $this->log($table, $send['u'], $info, $result, $oauth['method'], $oauth); } } return; } public function log($table, $user, $info, $result, $method, $param) { print_r($result); if ($table == 'component/version') { $insert['user_id'] = $user; $insert['name'] = $info['name']; $insert['template_id'] = $info['template_id']; $insert['project_id'] = $info['project_id']; $insert['version_id'] = $info['id']; $insert['result'] = json_encode($result); Dever::db($table . '_log')->insert($insert); } elseif ($table == 'component/auditing') { if (isset($result['auditid'])) { $update['auditid'] = $result['auditid']; } $update['result'] = json_encode($result); $update['where_id'] = $info['id']; Dever::db($table)->update($update); } elseif ($table == 'component/publish' || $table == 'component/revert' || $table == 'component/unaudit') { if ($result['errcode'] == 0) { $update['status'] = 2; } else { $update['status'] = 3; } $update['result'] = json_encode($result); $update['where_id'] = $info['id']; Dever::db($table)->update($update); if ($table == 'component/unaudit') { $audit = array('option_user_id' => $info['user_id'], 'option_project_id' => $info['project_id'], 'option_version_id' => $info['version_id'], 'option_status' => 1); $audit = Dever::db('component/auditing')->all($audit); if ($audit) { foreach ($audit as $k => $v) { $update = array(); $update['set_status'] = 3; $update['set_statusDesc'] = '撤回'; $update['where_id'] = $v['id']; Dever::db('component/auditing')->update($update); } } } } die; } }