| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;
- /**
- * This is the model class for table "{{%activity_new_user}}".
- *
- * @property integer $id
- * @property string $name
- * @property integer $start_time
- * @property integer $end_time
- * @property integer $created_at
- * @property integer $updated_at
- * @property integer $is_delete
- * @property integer $store_id
- * @property integer $status
- * @property string $goods_ids
- * @property string $coupon_ids
- * @property integer $is_platform
- * @property integer $is_platform_audit
- */
- class ActivityNewUser extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%activity_new_user}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- 'attributes' => [
- ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
- ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']
- ]
- ]
- ];
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['id', 'start_time', 'end_time', 'is_delete', 'store_id', 'status', 'is_platform', 'is_platform_audit'], 'integer'],
- [['name'], 'string'],
- [['created_at', 'updated_at', 'goods_ids', 'coupon_ids', 'buy_limit'], 'safe']
- ];
- }
- public function beforeSave($insert)
- {
- if (parent::beforeSave($insert)) {
- //$this->dirtyAttributes 改动的项目
- if (intval($this->is_platform === 1) && !empty($this->dirtyAttributes) && !isset($this->dirtyAttributes['status']) && !in_array($this->dirtyAttributes['is_platform_audit'], [1, 2])) {
- $this->is_platform_audit = 0;
- }
- return true;
- }
- return false;
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'name' => '活动名称',
- 'start_time' => '开始时间',
- 'end_time' => '结束时间',
- 'created_at' => '创建时间',
- 'updated_at' => '修改时间',
- 'is_delete' => 'is_delete',
- 'store_id' => 'Store Id',
- 'status' => '状态',
- 'goods_ids' => 'goods_ids',
- 'coupon_ids' => 'coupon_ids',
- ];
- }
- //店铺进行中活动
- public static function activityAt($store_id) {
- $query = self::find();
- $query->andWhere([
- 'and',
- ['is_delete' => 0, 'status' => 1, 'store_id' => $store_id],
- ['<', 'start_time', time()],
- ['>', 'end_time', time()],
- ]);
- $query->andWhere(['OR', ['is_platform' => 0], ['is_platform' => 1, 'is_platform_audit' => 1, 'status' => 1]]);
- return $query->one();
- }
- }
|