45], [['detail'], 'string', 'max' => 255], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'store_id' => 'Store ID', 'level' => 'Level', 'name' => 'Name', 'is_auto_upgrade' => 'Is Auto Upgrade', 'detail' => 'Detail', 'price' => 'Price', 'created_at' => 'Created At', 'updated_at' => 'Updated At', 'status' => 'Status', 'checked_condition_values' => 'Checked Condition Values', 'is_enable' => 'Is Enable', 'checked_condition_keys' => 'Checked Condition Keys', 'condition_type' => 'Condition Type', 'upgrade_type_goods' => 'Upgrade Type Goods', 'upgrade_type_condition' => 'Upgrade Type Condition', 'goods_warehouse_ids' => 'Goods Warehouse Ids', 'goods_list' => 'Goods List', 'goods_type' => 'Goods Type', 'buy_goods_type' => 'Buy Goods Type', ]; } /** * 获取可升级的等级列表 * @Author bing * @DateTime 2020-11-07 09:59:33 * @copyright: Copyright (c) 2020 广东七件事集团 * @param integer $level * @param integer $mall_id * @param integer $store_id * @param string $order * @return void|mixed */ public static function getCanLevelList($level,$mall_id,$store_id,$order = 'desc'){ return self::find() ->where(['mall_id' => $mall_id,'store_id' => $store_id, 'is_enable' => 1, 'is_delete' => 0]) ->andWhere(['>', 'level', $level]) ->orderBy("level $order") ->all(); } public static function getList($mall_id,$store_id) { $levelList = self::find()->where([ 'mall_id' => $mall_id,'store_id' => $store_id, 'status' => [StatusEnum::ENABLED,StatusEnum::DISABLED], 'is_enable' => 1, ])->select(['id', 'level', 'name'])->orderBy(['level' => SORT_ASC])->asArray()->all(); return $levelList; } /** * @desc:保存数据 * @Author: hua * @Date: 2021/10/20 * @Time: 15:46 * @Copyright: copyright (c) 2021 广东七件事集团 * @param array $params * @return AgentLevel|false|null * @throws \Exception */ public static function setData(array $params) { $t = \Yii::$app->db->beginTransaction(); try { if(empty($params['id']) && !empty($params['level'])){ $level_exist = self::findOne(['mall_id' => $params['mall_id'], 'level' => $params['level'], 'store_id'=>$params['store_id'],'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]); if($level_exist) throw new \Exception('该等级已存在数据'); } if(!empty($params['id'])){ $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]); if (empty($model)) throw new \Exception('服务不存在或已删除'); }else{ $model = new self(); $model->loadDefaultValues(); } if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage()); $model->checked_condition_keys = json_encode($params['checked_condition_keys']); $model->checked_condition_values = json_encode($params['checked_condition_values']); $model->goods_list = json_encode($params['goods_list']); $model->goods_warehouse_ids = json_encode($params['goods_warehouse_ids']); if (!$model->save()) throw new \Exception($model->getErrorMessage()); $t->commit(); return $model; } catch (\Exception $e) { $t->rollBack(); self::$static_error = $e->getMessage(); return false; } } public static function getDetail($params) { $weights = self::getLevelWeights(); $level = self::findOne(['id' => $params['id'], 'status' => [StatusEnum::ENABLED,StatusEnum::DISABLED]]); if ($level) { if ($level->checked_condition_values) { $level->checked_condition_values = json_decode($level->checked_condition_values,true); } if ($level->checked_condition_keys) { $level->checked_condition_keys = json_decode($level->checked_condition_keys,true); } if ($level->goods_warehouse_ids) { $level->goods_warehouse_ids = json_decode($level->goods_warehouse_ids,true); } else { $level->goods_warehouse_ids = []; } if ($level->goods_list) { $level->goods_list = json_decode($level->goods_list,true); } else { $level->goods_list = []; } } return [ 'code' => 0, 'msg' => '', 'data' => [ 'detail' => $level, 'weights' => $weights['newList'] ] ]; } public static function getLevelWeights() { $store = Yii::$app->session->get('o2o'); // if(empty($store)){ $list = self::find()->select('level,name')->where([ 'mall_id' =>$store ['mall_id'], 'store_id' => $store['id'], 'status' => [StatusEnum::ENABLED,StatusEnum::DISABLED] ])->orderBy(['level' => SORT_ASC])->all(); $level_list = array_column($list,'level'); $newList = []; $matchList = []; for ($i = 1; $i <= 10; $i++) { $newList[] = [ 'name' => '权重' . $i, 'level' => $i, 'disabled' => in_array($i, $level_list), ]; if(isset($list[$i-1])){ $matchList[] = [ 'name' => $list[$i-1]['name'], 'level' => "$i", 'disabled' => in_array($i, $level_list), ]; } } return ['newList'=>$newList,'matchList'=>$matchList]; } public static function del($params){ try{ $model = self::findOne(['id'=>$params['id']]); if(!empty($model)){ $res = StoreBossAgent::findOne(['level'=>$model->level,'mall_id'=>$params['mall_id'],'status'=>[StatusEnum::ENABLED,StatusEnum::DISABLED],'store_id'=>$params['store_id']]); if(!empty($res)) throw new \Exception('该等级关联了股东'); $model->status = StatusEnum::DELETE; $res = $model->save(); if($res==false) throw new \Exception($model->getErrorMessage()); } return true; }catch (\Exception $e){ self::$static_error = $e->getMessage(); return false; } } }