1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- 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();
- if (empty($list)) return [];
- return $list;
- }
- //
- public function editFetchOrder($update,$condition)
- {
- return $this->where($condition)->update($update);
- }
- }
|