dever 6 سال پیش
والد
کامیت
101281405e
1فایلهای تغییر یافته به همراه51 افزوده شده و 34 حذف شده
  1. 51 34
      component/src/Auditing.php

+ 51 - 34
component/src/Auditing.php

@@ -32,14 +32,61 @@ class Auditing extends Core
 		return;
 	}
 
+	/**
+     * 定期获取审核状态
+     * 
+     * @return mixed
+     */
+    public function cron()
+    {
+        $data = Dever::db('component/auditing')->state();
+        if ($data) {
+        	$wechat = array();
+        	foreach ($data as $k => $v) {
+        		if ($v['status'] == 1 && $v['auditid']) {
+        			$user = Dever::db('component/user')->one($v['uid']);
+					$oauth = Dever::db('main/oauth')->one($user['oauth_id']);
+					if (!isset($wechat[$v['project_id']])) {
+						$wechat[$v['project_id']] = new Wechat($v['project_id'], 'component');
+					}
+					
+					$oauth = $wechat[$v['project_id']]->oauth($oauth['id']);
+					$oauth['oauth'] = $oauth['value'];
+					$oauth['auditid'] = $v['auditid'];
+					$result = $wechat[$v['project_id']]->curl('applet_auditstatus', $oauth, false);
+					
+					$update = array();
+					if (isset($result['status'])) {
+						if ($result['status'] == 2) {
+							$html['审核状态'] = '审核中';
+							$update['status'] = 1;
+						} elseif($result['status'] == 1) {
+							$html['审核状态'] = '审核失败';
+							$update['status'] = 3;
+						} else {
+							$html['审核状态'] = '审核成功';
+							$update['status'] = 2;
+						}
+					}
+					if (isset($result['reason'])) {
+						$html['说明'] = $result['reason'];
+						$update['statusDesc'] = $result['reason'];
+					}
+
+					if ($update) {
+						$update['where_id'] = $v['id'];
+						Dever::db('component/auditing')->update($update);
+					}
+        		}
+        	}
+        }
+    }
+
 	# 查看审核状态
 	public function view($id)
 	{
 		$info = Dever::db('component/auditing')->one($id);
 		$status = $info['status'];
-		$uid = $info['user_id'];
-		$project = $info['project_id'];
-		$auditid = $info['auditid'];
 		$html = array();
 		if ($status == 2) {
 			$html['审核状态'] = '审核成功';
@@ -47,38 +94,8 @@ class Auditing extends Core
 			$html['审核状态'] = '审核失败';
 			$html['说明'] = $info['statusDesc'];
 		} elseif ($status == 1) {
-			$user = Dever::db('component/user')->one($uid);
-			$oauth = Dever::db('main/oauth')->one($user['oauth_id']);
-			$wechat = new Wechat($project, 'component');
-			$oauth = $wechat->oauth($oauth['id']);
-			$oauth['oauth'] = $oauth['value'];
-			$oauth['auditid'] = $auditid;
-			$result = $wechat->curl('applet_auditstatus', $oauth, false);
-			
-			$update = array();
-			if (isset($result['status'])) {
-				if ($result['status'] == 2) {
-					$html['审核状态'] = '审核中';
-					$update['status'] = 1;
-				} elseif($result['status'] == 1) {
-					$html['审核状态'] = '审核失败';
-					$update['status'] = 3;
-				} else {
-					$html['审核状态'] = '审核成功';
-					$update['status'] = 2;
-				}
-			}
-			if (isset($result['reason'])) {
-				$html['说明'] = $result['reason'];
-				$update['statusDesc'] = $result['reason'];
-			}
-
-			if ($update) {
-				$update['where_id'] = $id;
-				Dever::db('component/auditing')->update($update);
-			}
+			$html['审核状态'] = '审核中';
 		}
-		
 
 		$html = Dever::table($html);
 		return $html;