| 
					
				 | 
			
			
				@@ -12,6 +12,17 @@ use Main\Lib\Core; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 class Card 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public function test1() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return Dever::queue('test', 111); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public function test2() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return Dever::queue('test'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	# 分配优惠券,此处需要做高并发处理 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	public function get() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		$key = Dever::input('key'); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -23,10 +34,21 @@ class Card 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		if ($info) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			$one = Dever::db('youzan/card_list')->one(array('option_card_id' => $info['id'], 'option_user' => $user)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			if (!$one) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				$one = Dever::db('youzan/card_list')->getAll(array('option_card_id' => $info['id'], 'option_status' => 1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				$key = array_rand($one); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				if (isset($one[$key]) && $one[$key]) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-					Dever::db('youzan/card_list')->update(array('where_id' => $one[$key]['id'], 'user' => $user, 'status' => 2)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				$id = Dever::queue('lock'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if ($id) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					$card =  Dever::db('youzan/card_list')->one($id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} /*else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					$list = Dever::db('youzan/card_list')->getAll(array('option_card_id' => $info['id'], 'option_status' => 1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					$key = array_rand($list); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					if (isset($list[$key]) && $list[$key]) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						$card = $list[$key]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if (isset($card) && $card) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					Dever::db('youzan/card_list')->update(array('where_id' => $card['id'], 'user' => $user, 'status' => 2)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 					# 检查info,有无msg_key,有则发送模板消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 					if ($msg_project_id && $info['msg_key'] && $info['page'] && $info['msg_content']) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -36,7 +58,7 @@ class Card 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 						$send = Dever::load('applet/msg')->getData($info['msg_content']); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 						Dever::load('applet/msg')->sendOne($info['msg_key'], $msg_project_id, $user, $info['msg_page'], $send); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 					} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-					return $one[$key]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					return $card; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -123,7 +145,8 @@ class Card 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			$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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			$id = Dever::db('youzan/card_list')->insert($update); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			Dever::queue('lock', $id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |