0], [['is_enable'], 'default', 'value' => 0], [['detail'], 'string', 'max' => 80], [['id'], 'required'], [['id'], 'integer'], [['keyword'], 'string'], [['keyword'], 'trim'], [['page'], 'integer'], [['page'], 'default', 'value' => 1] ]; } public function attributeLabels() { return [ 'level' => '等级权重', 'name' => '等级名称', 'goods_list' => '商品列表', 'checked_condition_keys' => '选中的表达式key', 'goods_warehouse_ids' => '选中的商品goods_warehouse_ids', 'checked_condition_values' => '选中的表达式的值', 'upgrade_type_goods' => '购物升级', 'upgrade_type_condition' => '条件升级', 'condition_type' => '条件升级的方式', 'goods_type' => '购物方式', 'is_auto_upgrade' => '是否开启自动升级', 'buy_goods_type' => '订单结算方式', 'extra_limit_price' => '额外奖励上限金额', 'extra_is_limit' => '额外奖励是否上线', 'extra_type' => '额外存在的条件 1 购物 2 条件 3 任意', 'extra_price' => '额外奖励金额', 'is_extra' => '是否开启额外奖励', 'price' => '永久奖励金额', 'detail' => '等级说明', 'is_enable' => '是否启用', ]; } public function getDetail() { $weights = (new StoreBossLevelCommon)->getLevelWeights(); $level = StoreBossLevel::findOne(['id' => $this->id, 'is_delete' => 0]); if ($level) { if ($level->checked_condition_values) { $level->checked_condition_values = Json::decode($level->checked_condition_values); } if ($level->checked_condition_keys) { $level->checked_condition_keys = Json::decode($level->checked_condition_keys); } if ($level->goods_warehouse_ids) { $level->goods_warehouse_ids = Json::decode($level->goods_warehouse_ids); } else { $level->goods_warehouse_ids = []; } if ($level->goods_list) { $level->goods_list = Json::decode($level->goods_list); } else { $level->goods_list = []; } return [ 'code' => 0, 'msg' => '', 'data' => [ 'detail' => $level, 'weights' => $weights['newList'] ] ]; } } public function save() { if (!$this->validate()) { return $this->responseErrorInfo(); } $level = StoreBossLevel::findOne(['id' => $this->id, 'is_delete' => 0]); if (!$level) { return ['code' => 1, 'msg' => '所选择的分销商等级不存在或已删除,请刷新后重试']; } $store = \Yii::$app->session->get('o2o'); $bossExists = StoreBoss::find()->where([ 'mall_id' => $store['mall_id'], 'store_id' =>$store['id'], 'status' => 1, 'level' => $level->level ])->asArray()->one(); if ($bossExists) { return ['code' => 1, 'msg' => '该分销商等级下还有分销商存在,暂时不能删除']; } $level->is_delete = 1; if (!$level->save()) { return $this->responseErrorMsg($level); } return ['code' => 0, 'msg' => '删除成功!']; } public function search() { if (!$this->validate()) { return $this->responseErrorInfo(); } $store = \Yii::$app->session->get('o2o'); $where[] = ['=', 'mall_id', $store['mall_id']]; $where[] = ['=','store_id', $store['id']]; $where[] = ['=','is_delete', 0]; if($this->keyword){ $where[]=['or', ['like', 'name',$this->keyword], ['like', 'level', $this->keyword]]; } $params = [ // 'select' => '*', 'where' => $where, 'order' => 'level asc', 'page' => $this->page, 'limit' => 20, ]; $lists = StoreBossLevel::listPage($params, false, true); return [ 'code' => 0, 'msg' => '', 'data' => [ 'list' => $lists['list'], 'pagination' => $lists['pagination'] ] ]; } public function setData() { $store = Yii::$app->session->get('o2o'); if(!$store) $store = Store::findOne(['id' => $this->store_id]); try { if ($this->equal_price_type == 1) { if ($this->price > 100) { throw new \Exception('平级奖佣金百分比不能大于100%'); } } $level = StoreBossLevel::findOne(['is_delete' => 0, 'mall_id' => $store['mall_id'], 'store_id' => $store['id'], 'level' => $this->level]); if ($level) { if ($level->id != $this->id) { return [ 'code' => 1, 'msg' => '选中的权重已经存在对应的记录' ]; } } $level = StoreBossLevel::findOne(['is_delete' => 0, 'mall_id' => $store['mall_id'],'store_id' => $store['id'], 'id' => $this->id]); if ($level) { if ($level->level != $this->level) { $boss = StoreBoss::find()->where(['status' => 1, 'mall_id' =>$store['mall_id'],'store_id' => $store['id'], 'level' => $level->level])->asArray()->one(); if ($boss) { return [ 'code' =>1, 'msg' => '当前等级下已存在股东,不可变更等级权重!' ]; } } } if (!$level) { $level = new StoreBossLevel(); $level->is_delete = 0; $level->store_id = $store['id']; $level->mall_id = $store['mall_id']; } $level->attributes=$this-> attributes; $level->checked_condition_keys = Json::encode($this->checked_condition_keys); $level->checked_condition_values = Json::encode($this->checked_condition_values); $level->goods_list = Json::encode($this->goods_list); $level->goods_warehouse_ids = Json::encode($this->goods_warehouse_ids); if (!$level->save()) { throw new \Exception($level->getErrorMessage()); // throw new \Exception($this->responseErrorMsg($level)); } else { return [ 'code' => 0, 'msg' => '保存成功' ]; } } catch (\Exception $exception) { // $this->error($exception->getMessage()); return [ 'code' => 1, 'msg' => $exception->getMessage() ]; } } }