| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use Yii;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;
- /**
- * This is the model class for table "{{%activity_rebate_order_n}}".
- *
- * @property integer $id
- */
- class ActivityOrderRebateSelf extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%activity_rebate_order_self}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- ]
- ];
- }
-
- public function beforeSave($insert) {
- if(parent::beforeSave($insert)){
-
-
- $query = self::find()->alias('a')->leftJoin(['ag' => ActivityOrderRebateSelfGoods::tableName()], 'a.id = ag.act_id');
- $goods_ids = explode(',', $this->goods_ids);
- $this->goods_ids = implode(',', array_unique($goods_ids));
- $query->andWhere([
- 'a.store_id' => $this->store_id,
- 'ag.goods_id' => $goods_ids,
- 'a.is_delete' => 0,
- 'a.status' => 1,
- ]);
- $query->andWhere([
- 'and',
- ['<', 'a.start_time', $this->end_time],
- ['>', 'a.end_time', $this->start_time],
- ]);
- $has = $query->andWhere([
- '!=', 'a.id', (int)$this->id
- ])->one();
- if($has){
- $hasGoodIds = explode(',', $has->goods_ids);
- $this->addError('goods_id', '操作失败,商品已存在活动信息,活动id:' . $has->id . ' 商品id:' . implode(',', array_intersect($goods_ids, $hasGoodIds)));
- return false;
- }
- return true;
- }
- return false;
- }
-
- public static function activityAt($store_id = 0, $goods_id = 0, $time = null) {
- if($time === null){
- $time = time();
- }
- $query = self::find()->alias('a')->leftJoin(['ag' => ActivityOrderRebateSelfGoods::tableName()], 'a.id = ag.act_id');
- $query->andWhere([
- 'a.store_id' => $store_id,
- 'ag.goods_id' => $goods_id,
- 'a.is_delete' => 0,
- 'a.status' => 1,
- ]);
- $query->andWhere([
- 'and',
- ['<', 'a.start_time', $time],
- ['>', 'a.end_time', $time],
- ]);
- $info = $query->one();
- return $info;
- }
- //店铺进行中活动
- public static function activityAtList($store_id = 0, $asArray = false) {
- $query = self::find();
- $query->andWhere([
- 'is_delete' => 0,
- 'status' => 1,
- ]);
- if($store_id > -1){
- $query->andWhere(['store_id' => $store_id]);
- }
- $query->andWhere([
- 'and',
- ['<', 'start_time', time()],
- ['>', 'end_time', time()],
- ]);
- $asArray && $query->asArray();
- $list = $query->all();
- return $list;
- }
- }
|