123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- declare(strict_types=0);
- defined('InShopNC') or exit('Access Invalid!');
- use const mtopcard\UnusedCard;
- use const mtopcard\ReserveCard;
- use const mtopcard\AssignedCard;
- use const mtopcard\FreezedCard;
- class card_keyModel extends Model
- {
- public function __construct()
- {
- parent::__construct('card_key');
- }
- public function getCardByOrderId($order_id)
- {
- return $this->field('*')->where(['order_id' => $order_id])->select();
- }
- public function getCards($cond)
- {
- return $this->field('*')->where($cond)->select();
- }
- public function addCard($params)
- {
- return $this->insert($params);
- }
- public function getCardsList($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 addCards($params)
- {
- return $this->insertAll($params);
- }
- public function getUsable($card_type, $amount,$store_ids)
- {
- if(empty($store_ids)) {
- Log::record("获取卡密需要指定获取的店铺",Log::ERR);
- return [];
- }
- return $this->where(['card_state' => UnusedCard, 'card_type' => $card_type, 'amount' => $amount, 'store_id' => ['in',$store_ids]])
- ->lock(true)
- ->master(true)
- ->find();
- }
- public function reserve($card_id)
- {
- return $this->where(['card_id' => $card_id, 'card_state' => UnusedCard])
- ->update(['card_state' => ReserveCard]);
- }
- public function assign($order_id, $oper = "")
- {
- if(empty($oper)) {
- return $this->where(['order_id' => $order_id, 'card_state' => ReserveCard])
- ->update(['card_state' => AssignedCard, 'assigned_time' => time()]);
- }
- else {
- return $this->where(['order_id' => $order_id, 'card_state' => ReserveCard])
- ->update(['card_state' => AssignedCard, 'allocator' => $oper,'assigned_time' => time()]);
- }
- }
- public function reuse_card($card_id)
- {
- //只有已经预留了的卡才可以重新回收使用。
- return $this->where(['card_id' => $card_id, 'card_state' => ReserveCard])
- ->update(['card_state' => UnusedCard, 'order_id' => 0,
- 'member_id' => 0,
- 'out_store_id' => 0,
- 'receive_card_no' => '',
- 'receive_card_type' => 0,
- 'reserved_time' => 0,
- 'assigned_time' => 0]);
- }
- public function reuse($order_id)
- {
- //只有已经预留了的卡才可以重新回收使用。
- return $this->where(['order_id' => $order_id, 'card_state' => ReserveCard])
- ->update(['card_state' => UnusedCard, 'order_id' => 0,
- 'member_id' => 0,
- 'out_store_id' => 0,
- 'receive_card_no' => '',
- 'receive_card_type' => 0,
- 'reserved_time' => 0,
- 'assigned_time' => 0]);
- }
- public function freeze($order_id,$errmsg = '')
- {
- //只有已经预留了的卡才可以重新回收使用。
- return $this->where(['order_id' => $order_id, 'card_state' => ReserveCard])
- ->update(['card_state' => FreezedCard, 'errmsg' => $errmsg, 'order_id' => 0]);
- }
- public function manual_freeze($card_id,$errmsg = '')
- {
- //只有已经预留了的卡才可以重新回收使用。
- return $this->where(['card_id' => $card_id, 'card_state' => UnusedCard])
- ->lock(true)
- ->update(['card_state' => FreezedCard, 'errmsg' => $errmsg, 'order_id' => 0]);
- }
- public function unfreeze($card_id)
- {
- //只有已经预留了的卡才可以重新回收使用。
- return $this->where(['card_id' => $card_id, 'card_state' => FreezedCard])
- ->update(['card_state' => UnusedCard,
- 'order_id' => 0,
- 'member_id' => 0,
- 'out_store_id' => 0,
- 'receive_card_no' => '',
- 'receive_card_type' => 0,
- 'reserved_time' => 0,
- 'assigned_time' => 0,
- 'errmsg' => '']);
- }
- }
|