card_key.model.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. declare(strict_types=0);
  3. defined('InShopNC') or exit('Access Invalid!');
  4. use const mtopcard\UnusedCard;
  5. use const mtopcard\ReserveCard;
  6. use const mtopcard\AssignedCard;
  7. use const mtopcard\FreezedCard;
  8. class card_keyModel extends Model
  9. {
  10. public function __construct()
  11. {
  12. parent::__construct('card_key');
  13. }
  14. public function getCardByOrderId($order_id)
  15. {
  16. return $this->field('*')->where(['order_id' => $order_id])->select();
  17. }
  18. public function getCards($cond)
  19. {
  20. return $this->field('*')->where($cond)->select();
  21. }
  22. public function addCard($params)
  23. {
  24. return $this->insert($params);
  25. }
  26. public function getUsable($card_type, $amount)
  27. {
  28. return $this->where(['card_state' => UnusedCard, 'card_type' => $card_type, 'amount' => $amount])
  29. ->find();
  30. }
  31. public function reserve($card_id)
  32. {
  33. return $this->where(['card_id' => $card_id, 'card_state' => UnusedCard])
  34. ->update(['card_state' => ReserveCard]);
  35. }
  36. public function assign($card_id, $oper)
  37. {
  38. return $this->where(['card_id' => $card_id, 'card_state' => ReserveCard])
  39. ->update(['card_state' => AssignedCard, 'allocator' => $oper,'assigned_time' => time()]);
  40. }
  41. public function reuse($card_id)
  42. {
  43. //只有已经预留了的卡才可以重新回收使用。
  44. return $this->where(['card_id' => $card_id, 'card_state' => ReserveCard])
  45. ->update(['card_state' => UnusedCard,'member_id' => 0,'order_id' => 0,
  46. 'receive_card_no' => '','receive_card_type' => '',
  47. 'reserved_time' => 0, 'assigned_time' => 0]);
  48. }
  49. public function freeze($card_id)
  50. {
  51. //只有已经预留了的卡才可以重新回收使用。
  52. return $this->where(['card_id' => $card_id,'card_state' => ReserveCard])
  53. ->update(['card_state' => FreezedCard,'member_id' => 0,'order_id' => 0,
  54. 'receive_card_no' => '','receive_card_type' => '',
  55. 'reserved_time' => 0, 'assigned_time' => 0]);
  56. }
  57. public function unfreeze($card_id)
  58. {
  59. //只有已经预留了的卡才可以重新回收使用。
  60. return $this->where(['card_id' => $card_id, 'card_state' => FreezedCard])
  61. ->update(['card_state' => UnusedCard]);
  62. }
  63. }