Selaa lähdekoodia

add fetch_order transfor

stanley-king 3 vuotta sitten
vanhempi
commit
26dbaec140
2 muutettua tiedostoa jossa 67 lisäystä ja 1 poistoa
  1. 61 1
      data/model/fetch_order.model.php
  2. 6 0
      helper/refill/RefillBase.php

+ 61 - 1
data/model/fetch_order.model.php

@@ -6,11 +6,71 @@ defined('InShopNC') or exit('Access Invalid!');
 
 class fetch_orderModel extends Model
 {
+    const FETCH_ORDER_UNAVALIABLE = 0;
+    const FETCH_ORDER_AVALIABLE = 1;
+    const FETCH_ORDER_PROCESSING = 2;
+    const FETCH_ORDER_PROCESSED = 3;
+    
     public function __construct()
     {
         parent::__construct('fetch_order');
     }
 
+    public function add($fetch_datas)
+    {
+        return $this->insert($fetch_datas);
+    }
+
+    //抢单
+    public function fetch($store_id, $member_id, $card_type, $amount, $count)
+    {
+        try {
+            $tran = new trans_wapper($this,__METHOD__);
+            $items = $this->where(['fetch_status' => self::FETCH_ORDER_AVALIABLE, 'card_type' => $card_type, 'amount' => $amount, 'store_id' => $store_id])
+                ->limit($count)
+                ->lock(true)
+                ->master(true)->select();
+            foreach ($items as $item) {
+                $fetch_id = $item['fetch_id'];
+                $this->where(['fetch_id' => $fetch_id])->update(['fetch_status' => self::FETCH_ORDER_PROCESSING,'member_id' => $member_id,'fetch_time' => time()]);
+            }
+            $tran->commit();
+
+            return $items;
+        }
+        catch (Exception $ex) {
+            Log::record(__METHOD__ . " fetch order trans err:" . $ex->getMessage() ,Log::ERR);
+            return [];
+        }
+    }
+
+    //退回订单,抢完后,但不想处理的单子.
+    public function reput($fetch_id)
+    {
+        return $this->where(['fetch_id' => $fetch_id,'fetch_status' => self::FETCH_ORDER_PROCESSING])->update(['member_id' => 0,'fetch_time' => 0,'fetch_status' => self::FETCH_ORDER_AVALIABLE]);
+    }
+
+    //处理完成的单子
+    public function processed($fetch_id,$official_sn = '')
+    {
+        return $this->where(['fetch_id' => $fetch_id,'fetch_status' => self::FETCH_ORDER_PROCESSING])
+                    ->update(['fetch_status' => self::FETCH_ORDER_PROCESSING,'finsh_time' => time(),'official_sn' => $official_sn]);
+    }
+
+    //超时未处理订单,不可以再接单.
+    public function timeout($fetch_id)
+    {
+        return $this->where(['fetch_id' => $fetch_id,'fetch_status' => self::FETCH_ORDER_AVALIABLE])
+                    ->update(['fetch_status' => self::FETCH_ORDER_UNAVALIABLE]);
+    }
+
+    //用户已经抢到,尚未处理完成的单子列表
+    public function fetch_order_list($store_id, $member_id)
+    {
+        return $this->field('*')->where(['store_id' => $store_id,'member_id' => $member_id])->select();
+    }
+
+    //
     public function getFetchOrderList($condition, $pagesize = '', $field = '*', $order = 'add_time desc', $limit = '')
     {
         $list = $this->field($field)->where($condition)->page($pagesize)->order($order)->limit($limit)->select();
@@ -18,9 +78,9 @@ class fetch_orderModel extends Model
         return $list;
     }
 
+    //
     public function editFetchOrder($update,$condition)
     {
         return $this->where($condition)->update($update);
     }
-
 }

+ 6 - 0
helper/refill/RefillBase.php

@@ -470,6 +470,12 @@ class RefillBase
                 if ($provider->refill_type() == 'api') {
                     $logic_vr_order = Logic("vr_order");
                     $logic_vr_order->changeOrderStateSend($order_id,true);
+                } else {
+                    $fetch_order_mod = Model('fetch_order');
+                    $fetch_datas = ['order_id' => $order_id, 'order_sn' => $order_sn, 'store_id' => $order_info['store_id'],
+                        'fetch_status' => 1, 'card_no' => $card_no, 'card_type' => $card_type, 'refill_amount' => $amount,
+                        'add_time' => time()];
+                    $fetch_order_mod->add($fetch_datas);
                 }
 
                 $data = ['commit_time' => time(), 'ch_trade_no' => $trade_no];