FreeQueue.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use yii\behaviors\TimestampBehavior;
  9. use yii\db\ActiveRecord;
  10. /**
  11. * This is the model class for table "{{%activity_new_user}}".
  12. *
  13. * @property integer $id
  14. * @property string $name
  15. * @property integer $start_time
  16. * @property integer $end_time
  17. * @property integer $created_at
  18. * @property integer $updated_at
  19. * @property integer $is_delete
  20. * @property integer $store_id
  21. * @property integer $status
  22. * @property string $goods_ids
  23. * @property string $coupon_ids
  24. * @property integer $is_platform
  25. * @property integer $is_platform_audit
  26. * @property string $single_bili
  27. * @property string $self_bili
  28. * @property string $share_bili
  29. */
  30. class FreeQueue extends \yii\db\ActiveRecord
  31. {
  32. /**
  33. * @inheritdoc
  34. */
  35. public static function tableName()
  36. {
  37. return '{{%free_queue}}';
  38. }
  39. public function behaviors()
  40. {
  41. return [
  42. [
  43. 'class' => TimestampBehavior::class,
  44. 'attributes' => [
  45. ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
  46. ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']
  47. ]
  48. ]
  49. ];
  50. }
  51. /**
  52. * @inheritdoc
  53. */
  54. public function rules()
  55. {
  56. return [
  57. [['id', 'start_time', 'end_time', 'is_delete', 'store_id', 'status', 'is_platform', 'is_platform_audit'], 'integer'],
  58. [['name'], 'string'],
  59. [['cashback_bili','single_bili', 'self_bili', 'share_bili'], 'number'],
  60. [['created_at', 'updated_at', 'goods_ids', 'coupon_ids', 'buy_limit'], 'safe']
  61. ];
  62. }
  63. public function beforeSave($insert)
  64. {
  65. if (parent::beforeSave($insert)) {
  66. //$this->dirtyAttributes 改动的项目
  67. if (intval($this->is_platform === 1) && !empty($this->dirtyAttributes) && !isset($this->dirtyAttributes['status']) && !in_array($this->dirtyAttributes['is_platform_audit'], [1, 2])) {
  68. $this->is_platform_audit = 0;
  69. }
  70. return true;
  71. }
  72. return false;
  73. }
  74. /**
  75. * @inheritdoc
  76. */
  77. public function attributeLabels()
  78. {
  79. return [
  80. 'id' => 'ID',
  81. 'name' => '活动名称',
  82. 'start_time' => '开始时间',
  83. 'end_time' => '结束时间',
  84. 'created_at' => '创建时间',
  85. 'updated_at' => '修改时间',
  86. 'is_delete' => 'is_delete',
  87. 'store_id' => 'Store Id',
  88. 'status' => '状态',
  89. 'goods_ids' => 'goods_ids',
  90. 'coupon_ids' => 'coupon_ids',
  91. ];
  92. }
  93. //店铺进行中活动
  94. public static function activityAt($store_id) {
  95. $query = self::find();
  96. $query->andWhere([
  97. 'and',
  98. ['is_delete' => 0, 'status' => 1, 'store_id' => $store_id],
  99. ['<', 'start_time', time()],
  100. ['>', 'end_time', time()],
  101. ]);
  102. $query->andWhere(['OR', ['is_platform' => 0], ['is_platform' => 1, 'is_platform_audit' => 1, 'status' => 1]]);
  103. return $query->one();
  104. }
  105. }