ActivityNewUser.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. */
  27. class ActivityNewUser extends \yii\db\ActiveRecord
  28. {
  29. /**
  30. * @inheritdoc
  31. */
  32. public static function tableName()
  33. {
  34. return '{{%activity_new_user}}';
  35. }
  36. public function behaviors()
  37. {
  38. return [
  39. [
  40. 'class' => TimestampBehavior::class,
  41. 'attributes' => [
  42. ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
  43. ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']
  44. ]
  45. ]
  46. ];
  47. }
  48. /**
  49. * @inheritdoc
  50. */
  51. public function rules()
  52. {
  53. return [
  54. [['id', 'start_time', 'end_time', 'is_delete', 'store_id', 'status', 'is_platform', 'is_platform_audit'], 'integer'],
  55. [['name'], 'string'],
  56. [['created_at', 'updated_at', 'goods_ids', 'coupon_ids', 'buy_limit'], 'safe']
  57. ];
  58. }
  59. public function beforeSave($insert)
  60. {
  61. if (parent::beforeSave($insert)) {
  62. //$this->dirtyAttributes 改动的项目
  63. if (intval($this->is_platform === 1) && !empty($this->dirtyAttributes) && !isset($this->dirtyAttributes['status']) && !in_array($this->dirtyAttributes['is_platform_audit'], [1, 2])) {
  64. $this->is_platform_audit = 0;
  65. }
  66. return true;
  67. }
  68. return false;
  69. }
  70. /**
  71. * @inheritdoc
  72. */
  73. public function attributeLabels()
  74. {
  75. return [
  76. 'id' => 'ID',
  77. 'name' => '活动名称',
  78. 'start_time' => '开始时间',
  79. 'end_time' => '结束时间',
  80. 'created_at' => '创建时间',
  81. 'updated_at' => '修改时间',
  82. 'is_delete' => 'is_delete',
  83. 'store_id' => 'Store Id',
  84. 'status' => '状态',
  85. 'goods_ids' => 'goods_ids',
  86. 'coupon_ids' => 'coupon_ids',
  87. ];
  88. }
  89. //店铺进行中活动
  90. public static function activityAt($store_id) {
  91. $query = self::find();
  92. $query->andWhere([
  93. 'and',
  94. ['is_delete' => 0, 'status' => 1, 'store_id' => $store_id],
  95. ['<', 'start_time', time()],
  96. ['>', 'end_time', time()],
  97. ]);
  98. $query->andWhere(['OR', ['is_platform' => 0], ['is_platform' => 1, 'is_platform_audit' => 1, 'status' => 1]]);
  99. return $query->one();
  100. }
  101. }