| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?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_wechat_room}}".
- *
- * @property integer $id
- */
- class ActivityWechatRoom extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%activity_wechat_room}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- ]
- ];
- }
- public function beforeSave($insert) {
- if(parent::beforeSave($insert)){
- $goods_ids = explode(',', $this->goods_ids);
-
- $activityAtList = self::activityAtList($this->store_id, true);
- foreach($activityAtList as $activity){
- if($activity['id'] == $this->id){
- continue;
- }
- $at_goods_ids = explode(',', $activity['goods_ids']);
- $existGoodsIds = array_intersect($goods_ids, $at_goods_ids);
- if($existGoodsIds){
- $this->addError('goods_ids', '操作失败,商品【id:'. implode(',', $existGoodsIds) .'】已参加别的活动[活动id:' . $activity['id'] . ']');
- return false;
- }
- }
-
- return true;
- }
- return false;
- }
- //商品进行中活动
- public static function activityAtByGoodsId($goods_id = 0, &$goods_ext = null) {
- $query = self::find()->alias('a')->leftJoin(['ag' => ActivityWechatRoomGoods::tableName()], 'a.id=ag.activity_id');
- $query->andWhere([
- 'and',
- ['ag.goods_id' => $goods_id, 'a.is_delete' => 0, 'ag.is_delete' => 0, 'a.status' => 1],
- ['<', 'a.start_time', time()],
- ['>', 'a.end_time', time()],
- ]);
- $info = $query->asArray()->one();
- if($info){
- $goods_ext = ActivityWechatRoomGoods::findOne(['activity_id' => $info['id'], 'goods_id' => $goods_id, 'is_delete' => 0]);
- }
- return $info;
- }
- //店铺进行中活动
- public static function activityAt($id) {
- $query = self::find();
- $query->andWhere([
- 'and',
- ['id' => $id, 'is_delete' => 0, 'status' => 1],
- ['<', 'start_time', time()],
- ['>', 'end_time', time()],
- ]);
- $info = $query->one();
- return $info;
- }
- //店铺进行中活动
- public static function activityAtList($store_id = 0, $asArray = false) {
- $query = self::find();
- $query->andWhere([
- 'and',
- ['is_delete' => 0, 'status' => 1],
- ['<', 'start_time', time()],
- ['>', 'end_time', time()],
- ]);
- if($store_id > -1){
- $query->andWhere(['store_id' => $store_id]);
- }
- $asArray && $query->asArray();
- $list = $query->all();
- return $list;
- }
- }
|