| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?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 ActivityRebateOrderN extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%activity_rebate_order_n}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- ]
- ];
- }
-
- public function beforeSave($insert) {
- if(parent::beforeSave($insert)){
-
-
- $has = self::find()->andWhere([
- 'store_id' => $this->store_id,
- 'goods_id' => $this->goods_id,
- 'is_delete' => 0,
- 'status' => 1,
- ])->andWhere([
- '!=', 'id', (int)$this->id
- ])->one();
- if($has){
- $this->addError('goods_id', '操作失败,商品已存在活动信息,活动id:' . $has->id);
- return false;
- }
- return true;
- }
- return false;
- }
-
- public static function decodeRules($rules) {
- if(is_string($rules)){
- $rules = json_decode($rules, true);
- }
- if(!is_array($rules)){
- return null;
- }
- if(empty($rules['list'])){
- //默认值
- $rules = [
- 'type' => '0', //0固定值,1百分比
- 'list' => [
- [
- 'order_count' => '0',
- 'price' => '0',
- ]
- ],
- ];
- }
- $rules['total_price'] = 0;
- foreach($rules['list'] as &$item){
- $rules['total_price'] += $item['price'];
- if($item['user_price_order']){
- $item['user_price_order_no'] = Order::find()->where(['id' => $item['user_price_order']])->select('order_no')->asArray()->column();
- }
- }
- $rules['total_price'] = sprintf("%.2f", $rules['total_price']);
- return $rules;
- }
-
- public static function encodeRules($rules) {
- return json_encode($rules);
- }
-
- public static function activityAt($store_id = 0, $goods_id = 0) {
- $query = self::find();
- $query->andWhere([
- 'store_id' => $store_id,
- 'goods_id' => $goods_id,
- 'is_delete' => 0,
- 'status' => 1,
- ]);
- $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]);
- }
- $asArray && $query->asArray();
- $list = $query->all();
- return $list;
- }
-
- public static function passBaseRebate($store_id = 0, $goods_id = 0, $parent_id = 0) {
- $activity = self::activityAt($store_id, $goods_id);
- if($activity){
- if($activity->base_rebate == 0){
- return true;
- }
- }
- return false;
- }
- }
|