VerifyCardSale.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use yii\db\ActiveRecord;
  9. use yii\behaviors\TimestampBehavior;
  10. use Yii;
  11. /**
  12. * This is the model class for table "{{%verify_card_sale}}".
  13. *
  14. * @property int $id
  15. * @property int $store_id
  16. * @property int $verify_card_id 核销卡id
  17. * @property int $user_id 用户id
  18. * @property int $use_num 核销次数
  19. * @property int $left_num 剩余次数
  20. * @property int $sale_time 售卖时间
  21. * @property int $end_time 有效期
  22. * @property int $is_delete 状态
  23. * @property int $status 状态
  24. * @property int $goods_id 商品id
  25. * @property int $order_type 订单类型
  26. * @property int $created_at 核销卡创建时间
  27. * @property int|null $updated_at 更新时间
  28. * @property string $account_id 卡密账号id
  29. * @property int $is_trans_send 是否是转赠卡
  30. * @property int $video_status 视频卡是否过期
  31. * @property int $is_cash 是否折现:0=否,1=是
  32. */
  33. class VerifyCardSale extends \yii\db\ActiveRecord
  34. {
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public static function tableName()
  39. {
  40. return '{{%verify_card_sale}}';
  41. }
  42. const IS_DELETE_YES = 1;//已删除
  43. const IS_DELETE_NO = 0;//未删除
  44. const ORDER_TYPE_MIAOSHA = 1; //秒杀
  45. const ORDER_TYPE_PINTUAN = 2; //拼团
  46. const ORDER_TYPE_STORE = 0; //商城
  47. const STATUS_YES = 0;//正常使用
  48. const STATUS_USED = 1;//已使用
  49. const STATUS_EXPIRED = 2;//已过期
  50. public function behaviors()
  51. {
  52. return [
  53. [
  54. 'class' => TimestampBehavior::class,
  55. 'attributes' => [
  56. ActiveRecord::EVENT_BEFORE_INSERT => ['updated_at', 'created_at'],
  57. ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at'
  58. ]
  59. ]
  60. ];
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. public function rules()
  66. {
  67. return [
  68. [['store_id', 'verify_card_id', 'user_id', 'use_num', 'left_num', 'sale_time', 'end_time', 'is_delete', 'status', 'goods_id', 'order_type', 'account_id', 'is_trans_send', 'video_status', 'is_cash'], 'integer'],
  69. ];
  70. }
  71. /**
  72. * {@inheritdoc}
  73. */
  74. public function attributeLabels()
  75. {
  76. return [
  77. 'id' => 'ID',
  78. 'store_id' => 'Store ID',
  79. 'verify_card_id' => '核销卡id',
  80. 'user_id' => '用户id',
  81. 'use_num' => '核销次数',
  82. 'left_num' => '剩余次数',
  83. 'sale_time' => '售卖时间',
  84. 'end_time' => '有效期',
  85. 'is_delete' => '状态(0、正常1、已使用2、已过期)',
  86. 'status' => '状态',
  87. 'goods_id' => '商品id',
  88. 'order_type' => '订单类型(0、商城,1、秒杀,2、拼团)',
  89. 'account_id' => '卡密账号id',
  90. 'video_status' => '视频卡是否过期',
  91. 'is_cash' => '是否折现:0=否,1=是',
  92. ];
  93. }
  94. // 取消下单时送的核销卡
  95. public static function cancelCard($order)
  96. {
  97. if (!empty($order->get_verify_id)) {
  98. $ids = \explode(',', $order->get_verify_id);
  99. foreach ($ids as $id) {
  100. $card = self::findOne($id);
  101. if ($card) {
  102. $card->status = 2;
  103. $card->save();
  104. }
  105. }
  106. }
  107. }
  108. }