wupengfei hace 2 años
padre
commit
db0af36b85
Se han modificado 2 ficheros con 15 adiciones y 6 borrados
  1. 6 5
      application/api/common.php
  2. 9 1
      application/api/controller/Order.php

+ 6 - 5
application/api/common.php

@@ -133,19 +133,20 @@ function cancel_goods_order($user_id = 0)
 }
 
 // 商品抽签
-function goods_draw($goods_id)
-{
+function goods_draw($goods_id){
     $redis = new Redis();
     $goods_info = Db::name('store_collect')->find($goods_id);
     $stock = $redis->get('collection_count_'.$goods_id);
     if(!$stock) return ['code'=>201,'msg'=>'商品库存不足'];
     $apply_list = Db::name('store_collection_draw')->where(['coll_id'=>$goods_id,'is_ballot'=>0])->column('id,user_id,code');
-    shuffle($apply_list);
-    $ballot = array_slice($apply_list,0,$stock);
+    shuffle($apply_list);// 打乱申请记录顺序
+    $ballot = array_slice($apply_list,0,$stock);//截取数据
     $ballot_ids = array_column($ballot,'id');
+    $ballot_user = array_column($ballot,'user_id');
     Db::name('store_collection_draw')->where(['coll_id'=>$goods_id,'is_ballot'=>0])->whereIn('id',implode($ballot_ids))->update(['is_ballot'=>1]);
     Db::name('store_collection_draw')->where(['coll_id'=>$goods_id,'is_ballot'=>0])->whereNotIn('id',implode($ballot_ids))->update(['is_ballot'=>2]);
-    $redis->hMSet('lucky_draw',[$goods_id=>json_encode($ballot_ids)]);
+    Db::name('store_collect')->where('id',$goods_id)->update(['is_task'=>1]);
+    $redis->hMSet('lucky_draw',['goods_id_'.$goods_id=>json_encode($ballot_user)]);
     return ['code'=>200,'msg'=>'ok'];
 }
 

+ 9 - 1
application/api/controller/Order.php

@@ -59,6 +59,14 @@ class Order extends Base
         if ($user['is_auth']==0) $this->error('请实名认证后购买!');
         $coll_info = getCollectionInfoHash($id);
         if ($coll_info['is_deleted']==1 || $coll_info['status']==0) $this->error('藏品已下架');
+        // 抽签发行方式验证是否中签
+        if($coll_info['issue_mode'] == 2){
+            $check_redis = new Redis();
+            $luck_draw = $check_redis->hget('lucky_draw','goods_id_'.$id);
+            if(!$luck_draw) $this->error('抽签未出结果');
+            $luck_draw = json_decode($luck_draw,true);
+            if(!in_array($this->uid,$luck_draw)) $this->error('没有中签');
+        }
 
         $inventory = getCollectionInventory($id);
 
@@ -135,7 +143,7 @@ class Order extends Base
             'create_at'=>date('Y-m-d H:i:s'),
             'total_price'=>$total_price,
             'pay_price'=>$total_fee,
-            'pay_type'=>$pay_type
+            'pay_type'=>$pay_type,
         ];
         $com = true;
         $retrun_data['order_no'] = $order_no;