|  | @@ -12,9 +12,10 @@ use Main\Lib\Core;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  class Card
 |  |  class Card
 | 
											
												
													
														|  |  {
 |  |  {
 | 
											
												
													
														|  | 
 |  | +	public $lock = 'cardv1';
 | 
											
												
													
														|  |  	public function test()
 |  |  	public function test()
 | 
											
												
													
														|  |  	{
 |  |  	{
 | 
											
												
													
														|  | -		$len = Dever::queue('test', 'len');
 |  | 
 | 
											
												
													
														|  | 
 |  | +		$len = Dever::queue($this->lock, 'len');
 | 
											
												
													
														|  |  		return $len;
 |  |  		return $len;
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -32,11 +33,9 @@ class Card
 | 
											
												
													
														|  |  			if ($one) {
 |  |  			if ($one) {
 | 
											
												
													
														|  |  				return $one;
 |  |  				return $one;
 | 
											
												
													
														|  |  			} else {
 |  |  			} 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 {
 |  |  				} else {
 | 
											
												
													
														|  |  					$list = Dever::db('youzan/card_list')->getAll(array('option_card_id' => $info['id'], 'option_status' => 1));
 |  |  					$list = Dever::db('youzan/card_list')->getAll(array('option_card_id' => $info['id'], 'option_status' => 1));
 | 
											
												
													
														|  |  					$key = array_rand($list);
 |  |  					$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);
 | 
											
												
													
														|  | 
 |  | +			}
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  
 |  |  
 |