dever 6 years ago
parent
commit
3fa34a0966
2 changed files with 14 additions and 6 deletions
  1. 1 1
      youzan/database/card.php
  2. 13 5
      youzan/src/Card.php

+ 1 - 1
youzan/database/card.php

@@ -30,7 +30,7 @@ return array
 			'desc' 		=> '',
 			'match' 	=> 'is_numeric',
 			'search'	=> 'order',
-			//'list'		=> true,
+			'list'		=> true,
 		),
 
 		'project_id'		=> array

+ 13 - 5
youzan/src/Card.php

@@ -13,16 +13,24 @@ use Main\Lib\Core;
 class Card
 {
 	public $lock = 'cardv1';
-	public function test()
+	public function len($id = false)
 	{
-		$len = Dever::queue($this->lock, 'len');
+		$id = Dever::input('id', $id);
+		$len = Dever::queue($this->lock . '_' . $id, 'len');
 		return $len;
 	}
 
 	public function total()
 	{
-		$total = Dever::db('youzan/card_list')->total(array('option_state' => 1, 'option_status' => 1));
-		return Dever::lock($this->lock, $total);
+		$info = Dever::db('youzan/card')->state();
+		if ($info) {
+			foreach ($info as $k => $v) {
+				$total = Dever::db('youzan/card_list')->total(array('option_state' => 1, 'option_status' => 1, 'option_card_id' => $v['id']));
+				Dever::lock($this->lock . '_' . $v['id'], $total);
+			}
+		}
+		
+		return true;
 	}
 
 	# 分配优惠券,此处需要做高并发处理
@@ -39,7 +47,7 @@ class Card
 			if ($one) {
 				return $one;
 			} else {
-				$state = Dever::lock($this->lock);
+				$state = Dever::lock($this->lock . '_' . $info['id']);
 				if (!$state) {
 					Dever::alert('error');
 				} else {