RedPacket.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use app\constants\OptionSetting;
  9. use app\modules\alliance\models\CurrencyForm;
  10. use app\plugins\scanCodePay\models\Order as ScanCodePayOrder;
  11. use app\plugins\scanCodePay\models\Order as ScanOrder;
  12. use yii\db\ActiveRecord;
  13. use yii\behaviors\TimestampBehavior;
  14. use Yii;
  15. use yii\helpers\Json;
  16. /**
  17. * This is the model class for table "{{%red_packet}}".
  18. *
  19. * @property integer $id
  20. * @property integer $store_id
  21. * @property integer $user_id
  22. * @property integer $saas_id
  23. * @property integer $currency_id
  24. * @property float $amount
  25. * @property double $remaining_amount
  26. * @property integer $remaining_count
  27. * @property integer $total
  28. * @property integer $type
  29. * @property integer $status
  30. * @property string $image_url
  31. * @property string $name
  32. * @property integer $is_delete
  33. * @property integer $created_at
  34. * @property integer $updated_at
  35. */
  36. class RedPacket extends \yii\db\ActiveRecord
  37. {
  38. const TYPE_NORMAL = 1; // 普通红包
  39. const TYPE_RANDOM = 2; // 手气红包
  40. const STATUS_ACTIVE = 1; // 有效
  41. const STATUS_EMPTY = 2; // 已抢完
  42. const STATUS_EXPIRED = 3; // 已过期
  43. const STATUS_FAIL = 4; // 已作废
  44. /**
  45. * @inheritdoc
  46. */
  47. public static function tableName()
  48. {
  49. return '{{%red_packet}}';
  50. }
  51. public function behaviors()
  52. {
  53. return [
  54. [
  55. 'class' => TimestampBehavior::class,
  56. 'attributes' => [
  57. ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
  58. ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']
  59. ]
  60. ]
  61. ];
  62. }
  63. public function rules()
  64. {
  65. return [
  66. [['user_id', 'amount', 'total'], 'required'],
  67. [['user_id', 'total', 'type','status','id','created_at', 'updated_at','remaining_count','store_id','currency_id','is_delete'], 'integer'],
  68. [['amount'], 'number', 'min' => 0.01],
  69. [[ 'remaining_amount'], 'number'],
  70. [[ 'image_url','name'], 'string'],
  71. ['total', 'integer', 'min' => 1],
  72. ['type', 'in', 'range' => [self::TYPE_NORMAL, self::TYPE_RANDOM]],
  73. ['status', 'default', 'value' => self::STATUS_ACTIVE],
  74. ];
  75. }
  76. public function getRecords()
  77. {
  78. return $this->hasMany(RedPacketRecord::class, ['packet_id' => 'id']);
  79. }
  80. public static function getStatusText($status)
  81. {
  82. $text = [
  83. self::STATUS_ACTIVE => '有效',
  84. self::STATUS_EMPTY => '已抢完',
  85. self::STATUS_EXPIRED => '已过期',
  86. self::STATUS_FAIL => '已作废',
  87. ];
  88. return $text[$status];
  89. }
  90. }