12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?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 getUsable($card_type, $amount)
- {
- return $this->where(['card_state' => UnusedCard, 'card_type' => $card_type, 'amount' => $amount])
- ->find();
- }
- public function reserve($card_id)
- {
- return $this->where(['card_id' => $card_id, 'card_state' => UnusedCard])
- ->update(['card_state' => ReserveCard]);
- }
- public function assign($card_id, $oper)
- {
- return $this->where(['card_id' => $card_id, 'card_state' => ReserveCard])
- ->update(['card_state' => AssignedCard, 'allocator' => $oper,'assigned_time' => time()]);
- }
- public function reuse($card_id)
- {
- //只有已经预留了的卡才可以重新回收使用。
- return $this->where(['card_id' => $card_id, 'card_state' => ReserveCard])
- ->update(['card_state' => UnusedCard,'member_id' => 0,'order_id' => 0,
- 'receive_card_no' => '','receive_card_type' => '',
- 'reserved_time' => 0, 'assigned_time' => 0]);
- }
- public function freeze($card_id)
- {
- //只有已经预留了的卡才可以重新回收使用。
- return $this->where(['card_id' => $card_id,'card_state' => ReserveCard])
- ->update(['card_state' => FreezedCard,'member_id' => 0,'order_id' => 0,
- 'receive_card_no' => '','receive_card_type' => '',
- 'reserved_time' => 0, 'assigned_time' => 0]);
- }
- public function unfreeze($card_id)
- {
- //只有已经预留了的卡才可以重新回收使用。
- return $this->where(['card_id' => $card_id, 'card_state' => FreezedCard])
- ->update(['card_state' => UnusedCard]);
- }
- }
|