dever 6 lat temu
rodzic
commit
baab5ec963
5 zmienionych plików z 37 dodań i 34 usunięć
  1. 0 9
      applet/config/base.php
  2. 9 0
      config/base.php
  3. 3 0
      main/lib/Core.php
  4. 0 8
      youzan/config/base.php
  5. 25 17
      youzan/src/Card.php

+ 0 - 9
applet/config/base.php

@@ -5,15 +5,6 @@ $config['base'] = array
 (
 	# 后台头部菜单
 	'top' => 'main/project_id-3',
-
-	# 定义队列
-	'queue' => array
-	(
-		'method' => 'redis',
-		'host' => '172.26.102.182',
-		'port' => '6379',
-		'key' => false,
-	),
 );
 
 # 模板配置

+ 9 - 0
config/base.php

@@ -8,6 +8,15 @@ $config['base'] = array
 
 	# 小程序内容端接口地址
 	'applet_content' => 'http://cm.5dev.cn/applet_on/content/v1/',
+
+	
+	# 定义队列
+	'queue' => array
+	(
+		'method' => 'db',
+		'host' => '172.26.102.182',
+		'port' => '6379',
+	),
 );
 
 # 模板配置

+ 3 - 0
main/lib/Core.php

@@ -23,6 +23,9 @@ function callAction($send)
 					Dever::load($send['a'] . '/' . $send['e'], $send['i'], $result, $send['p']);
 				}
 			}
+			if ($send['e']) {
+				Dever::load($send['a'] . '/' . $send['e'], $send['i'], $result, $send['p'], true);
+			}
 		} else {
 			$result = $wechat->curl($send['t'], $param, false);
 			if ($send['e']) {

+ 0 - 8
youzan/config/base.php

@@ -5,14 +5,6 @@ $config['base'] = array
 (
 	# 后台头部菜单
 	'top' => 'main/project_id-7',
-
-	# 定义队列
-	'queue' => array
-	(
-		'method' => 'db',
-		'host' => '172.26.102.182',
-		'port' => '6379',
-	),
 );
 
 # 模板配置

+ 25 - 17
youzan/src/Card.php

@@ -12,9 +12,10 @@ use Main\Lib\Core;
 
 class Card
 {
+	public $lock = 'cardv1';
 	public function test()
 	{
-		$len = Dever::queue('test', 'len');
+		$len = Dever::queue($this->lock, 'len');
 		return $len;
 	}
 
@@ -32,11 +33,9 @@ class Card
 			if ($one) {
 				return $one;
 			} else {
-				
-				//$id = Dever::queue('card');
-				$id = false;
-				if ($id) {
-					$card =  Dever::db('youzan/card_list')->one($id);
+				$state = Dever::lock($this->lock);
+				if (!$state) {
+					Dever::alert('error');
 				} else {
 					$list = Dever::db('youzan/card_list')->getAll(array('option_card_id' => $info['id'], 'option_status' => 1));
 					$key = array_rand($list);
@@ -132,18 +131,27 @@ class Card
 		}
 	}
 
-	public function createEnd($project_id, $data, $id = false)
+	public function createEnd($project_id, $data, $id = false, $end = false)
 	{
-		$info = Dever::db('youzan/card')->one($id);
-		if ($info && isset($data['response']['promocard']['group_id'])) {
-			$update['card_id'] = $info['id'];
-			$update['project_id'] = $info['project_id'];
-			$update['user'] = '';
-			$update['status'] = 1;
-			$update['group_id'] = $data['response']['promocard']['group_id'];
-			$update['code_url'] = $data['response']['promocard']['fetch_url'];
-			$update['result'] = json_encode($data);
-			Dever::db('youzan/card_list')->insert($update);
+		if ($end) {
+			# 如果执行结束,则加到库存里
+			$total = Dever::db('youzan/card_list')->total(array('option_state' => 1, 'option_status' => 1));
+			Dever::lock($this->lock, $total);
+		} else {
+			$info = Dever::db('youzan/card')->one($id);
+			//$data['response']['promocard']['group_id'] = 1;
+			//$data['response']['promocard']['fetch_url'] = rand(1,100);
+			if ($info && isset($data['response']['promocard']['group_id'])) {
+				$update['card_id'] = $info['id'];
+				$update['project_id'] = $info['project_id'];
+				$update['user'] = '';
+				$update['status'] = 1;
+				$update['group_id'] = $data['response']['promocard']['group_id'];
+				$update['code_url'] = $data['response']['promocard']['fetch_url'];
+				$update['cdate'] = time();
+				$update['result'] = json_encode($data);
+				Dever::db('youzan/card_list')->insert($update);
+			}
 		}
 	}