| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?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 "{{%saas_partner_level}}".
- *
- * @property integer $id
- * @property integer $level
- * @property string $name
- * @property string $rate
- * @property string $achieve
- * @property integer $is_delete
- * @property integer $status
- * @property integer $created_at
- * @property integer $updated_at
- */
- class SaasStoreUnionLevel extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%saas_store_union_level}}';
- }
- 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 [
- [['level', 'status','is_delete'], 'integer'],
- [['rate','achieve'], 'number'],
- [['name'], 'string'],
- [['created_at', 'updated_at'], 'safe']
- ];
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'level' => '等级',
- 'name' => '名称',
- 'rate' => '比例',
- 'status' => '状态',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- public static function levelUp($store_id,$pool_id){
- $achieve = StoreUnionPoolDetail::find()->where(['store_id'=>$store_id,'pool_id'=>$pool_id])->sum('total_pv')?:0;
- $level = SaasStoreUnionLevel::find()->andWhere(['<=','achieve',$achieve])->orderBy('achieve desc')->one();
- if (!empty($level)){
- $union = SaasStoreUnion::find()->where(['store_id'=>$store_id])->one();
- if (empty($union)){
- $union = new SaasStoreUnion();
- $union->store_id = $store_id;
- }
- $storeLevel = SaasStoreUnionLevel::findOne($union->level_id);
- if (!$union->level_id || empty($storeLevel) || $storeLevel->level < $level->level){
- $union->level_id = $level->id;
- $union->save();
- }
- }
- }
- }
|