request->isAjax) { if (Yii::$app->request->isGet) { $detail = Mch::getOne([['id' => $this->mch_id], ['mall_id' => $this->mall_id]], true); $detail['cIds'] = []; $detail['province'] = 0; $detail['city'] = 0; $detail['district'] = 0; $detail['cIds'][] = []; $detail['address_detail'] = ''; $detail['ll'] = $detail['latitude'] . ',' . $detail['longitude']; if (!empty($detail['freight_type'])){ $detail['freight_type'] = json_decode($detail['freight_type'], true); }else{ $detail['freight_type'] =[ 'express_delivery'=>0, ]; } if (!empty($detail['intra_city_distribution'])) $detail['intra_city_distribution'] = json_decode($detail['intra_city_distribution'], true); $detail['customer_service'] = !empty($detail['customer_service']) ? json_decode($detail['customer_service'], true) : ['web_service_url' => '']; return $this->success('操作成功', ['detail' => $detail]); } if (Yii::$app->request->isPost) { $params = Yii::$app->request->post(); $params['form']['id'] = $this->mch_id; $params['form']['mall_id'] = $this->mall_id; // $params['form']['check_status'] = 0; $res = Mch::setData($params['form']); if ($res == false) return $this->success('操作失败'); return $this->success('操作成功'); } } return $this->render($this->action->id); } public function actionGoodsModel() { // 获取组件配置 $addons_setting = AddonsLimit::getGlobalSetting($this->mall_id); $addons_arr = []; $basic = \Yii::$app->services->setting->addons->get($this->mall_id, MchEnum::ADDONS_NAME, 'basic'); if(!empty($basic['store_agent_status'])) $addons_arr[] =AddonsEnum::ADDONS_NAME_AGENT; if(!empty($basic['store_area_status'])) $addons_arr[] =AddonsEnum::ADDONS_NAME_AREA; if(!empty($basic['store_distribution_status'])) $addons_arr[] =AddonsEnum::ADDONS_NAME_DISTRIBUTION; if(!empty($basic['store_boss_status'])) $addons_arr[] =AddonsEnum::ADDONS_NAME_BOSS; if($addons_setting){ foreach ($addons_setting as $key=>$val){ if(!in_array($key,$addons_arr)) unset($addons_setting[$key]); } }else{ $addons_setting = []; } if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { // 获取商品详情 $goods_model = MchModel::getOne([['mall_id' => $this->mall_id, 'mch_id' => $this->mch_id]], true); $content = []; if (!empty($goods_model['content'])) { $content = json_decode($goods_model['content'], true); } // 获取配置 foreach ($content as $key => &$item) { if (isset($content[$key])) { $setting[$key] = json_decode($content[$key], true); } } // 获取等级 $level_params = ['where' => [['=', 'mall_id', $this->mall_id], ['=', 'status', StatusEnum::ENABLED]], 'select' => 'level,name']; $level_params['mall_id'] = $this->mall_id; $level = GlobalInvoke::exec(GlobalInvoke::GOODS_MODEL_LEVEL, $this->mall_id, $level_params); $commission_type_map = GoodsTypeEnum::getCommissionTypeMap($this->mall_id); unset($commission_type_map['digital']); $status = $goods_model['status']??0; return $this->success('操作成功', compact('status', 'level', 'setting', 'commission_type_map')); } else { $basic = \Yii::$app->services->setting->addons->get($this->mall_id, MchEnum::ADDONS_NAME, 'basic'); $mch_setting = MchSettings::findOne(['mch_id'=>$this->mch_id,'mall_id'=>$this->mall_id]); if(!empty($mch_setting)){ if($mch_setting['store_settle_type']!=4){ return $this->error('分佣由平台承担,您无权编辑'); } }else{ if($basic['settle_type']!=4){ return $this->error('分佣由平台承担,您无权编辑'); } } $params = Yii::$app->request->post('form'); $status = 0; if (!empty($params['status'])) { $status = $params['status']; unset($params['status']); } $res = Yii::$app->services->validate->validate($params, [ [array_keys($addons_setting), 'string'] ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); try { $param = [ 'mall_id' => $this->mall_id, 'mch_id' => $this->mch_id, 'status' => $status, 'content' => json_encode($params), ]; $res = MchModel::setData($param); if ($res === false) return $this->error(MchModel::getStaticError()); return $this->success("保存成功"); } catch (\Exception $e) { return $this->error("保存失败,msg=" . $e->getMessage()); } } } return $this->render($this->action->id, ['addons_setting' => $addons_setting]); } public function actionFreightRules() { if (Yii::$app->request->isAjax) { if (Yii::$app->request->isGet) { $keyword = Yii::$app->request->get('keyword', ''); $where = [['mall_id' => $this->mall_id, 'mch_id' => $this->mch_id, 'status' => StatusEnum::ENABLED]]; $keyword && $where[] = ['like', 'name', $keyword . '%', false]; $order = 'id desc'; $params = compact('where', 'order'); $page_data = FreightRules::listPage($params); if($page_data === false) return $this->error(FreightRules::getStaticError()); return $this->success('操作成功',$page_data); }else{ $form = Yii::$app->request->post(); $rules = [[['id'], 'required'], [['id'], 'integer']]; switch ($form['type']) { case 'destroy': $form['status'] = StatusEnum::DELETE; $rules[] = [['status'], 'required']; break; case 'default': $rules[] = [['is_default'], 'required']; break; } $res = Yii::$app->services->validate->validate($form, $rules); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $form['mall_id'] = $this->mall_id; $form['mch_id'] = $this->mch_id; $res = FreightRules::setData($form); if ($res === false) return $this->error(FreightRules::getStaticError()); return $this->success('操作成功',[]); } } return $this->render($this->action->id); } public function actionFreightEdit(){ if (Yii::$app->request->isAjax) { if (Yii::$app->request->isGet) { $get = Yii::$app->request->get(); $res = Yii::$app->services->validate->validate($get, [[['id'], 'required'], [['id'], 'integer']]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $detail = FreightRules::getOne([['id' => $get['id'], 'mall_id' => $this->mall_id, 'mch_id' => $this->mch_id]], true); $detail['rule'] = json_decode($detail['rule'],true); return $this->success('操作成功',compact('detail')); } else { $form = Yii::$app->request->post('form'); $res = Yii::$app->services->validate->validate($form, [ [['id','select_com','compute_type'], 'integer'], [['name', 'type', 'rule'], 'safe'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $form['rule'] = json_decode($form['rule'], true); $form['mall_id'] = $this->mall_id; $form['mch_id'] = $this->mch_id; $res = FreightRules::setData($form); if ($res === false) return $this->error(FreightRules::getStaticError()); return $this->success('操作成功'); } } return $this->render($this->action->id); } //todo 不用验证权限 public function actionGetAddressList() { $get = Yii::$app->request->get(); if (!empty($get['id'])) $where[] = ['parent_id' => $get['id']]; $where[] = ['level' => $get['level'] ?? 1]; $params['where'] = $where; $params['select'] = 'id,name,parent_id,level'; $list = Region::lists($params); return $this->success('操作成功', $list); } public function actionStoreCateTree() { if (Yii::$app->request->isAjax) { if (Yii::$app->request->isGet) { $cond = [['mall_id' => $this->mall_id]]; $list = StoreCate::getCates($cond, [], true, 'id,name,parent_id'); $list = StoreCate::getTreeCate($list); return $this->success('操作成功', compact('list')); } } } //修改密码 public function actionUpdatePassword(){ $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['old_pass','new_pass','check_pass'], 'required'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); if($params['new_pass']!=$params['check_pass']) return $this->error('新密码和确认密码不一致'); if(!$this->admin->validatePassword($params['old_pass'])){ return $this->error('旧密码不正确'); } $this->admin->password = Yii::$app->security->generatePasswordHash($params['new_pass']); $res = $this->admin->save(); if ($res === false) return $this->error('修改密码失败'); return $this->success('操作成功'); } }