request->isAjax) { if (\Yii::$app->request->post()) { $setting = \Yii::$app->request->post('setting'); $trans = \Yii::$app->db->beginTransaction(); try { // 重新组合配置 foreach ($setting as $group => $value) { foreach ($value as $name => $val) { $data[$group][$name] = $val['value']; } } // 检查发薪猫域名是否变化,如果变化修改nginx vhosts $beforeCatH5Url = PlatformSetting::getConfByGroup('system', true)['cat_h5_url']['value'] ?? ''; if (!empty($data['system']['cat_h5_url']) && $beforeCatH5Url != $data['system']['cat_h5_url']) { // $isChangeSalaryUrl = true; } \Yii::$app->services->setting->platform->set($data); $trans->commit(); // 创建发薪猫nginx vhosts文件 if (!empty($isChangeSalaryUrl)) { try { \services\common\UpgradeService::makeSalaryVhosts(); }catch (\Exception $e) { $data['system']['cat_h5_url'] = $beforeCatH5Url; \Yii::$app->services->setting->platform->set($data); $this->success('配置修改成功,发薪猫H5链接修改失败,原因:' . $e->getMessage()); return; } } $this->success('操作成功'); } catch (\Exception $e) { $trans->rollBack(); \Yii::error('edit platformSetting error:' . $e->getMessage()); $this->error('编辑失败'); } } else { $system = PlatformSetting::getConfByGroup('system', true); $storage = PlatformSetting::getConfByGroup('storage', true); $storage_driver = PlatformSetting::getConfByGroup('storage_driver', true); $limit = PlatformSetting::getConfByGroup('limit', true); $mall_create_syn = PlatformSetting::getConfByGroup('mall_create_syn', true); $map = PlatformSetting::getConfByGroup('map', true); $sms = PlatformSetting::getConfByGroup('sms', true); $backups = PlatformSetting::getConfByGroup('backups', true); if(!empty($mall_create_syn['mode'])){ $res = json_decode($mall_create_syn['mode']['value'],true); if(is_array($res)){ $mall_create_syn['mode']['value'] = $res; }else{ $mall_create_syn['mode']['value'] = []; } }else{ $mall_create_syn['mode']['value'] = []; } $data = compact('system', 'storage', 'storage_driver', 'limit','mall_create_syn', 'map','sms', 'backups'); $mallList = Mall::lists(['where'=>[ ['status'=>StatusEnum::ENABLED], ['or', ['expired_at'=>0], ['>','expired_at',time()], ] ],'order'=>'id asc','select'=>'id,name']); $data['mallList'] = $mallList; $this->success('操作成功', $data); } } return $this->render($this->action->id); } /** * 支付设置 * @Author: lun * @DateTime: 2022/2/24 0024 18:29 * @Copyright: copyright (c) 2021 广东七件事集团 * @return string */ public function actionPay() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->post()) { $setting = \Yii::$app->request->post('setting'); // 重新组合配置 $data = self::makeUpParams($setting); $res = Yii::$app->services->setting->set($data); if($res === false) return $this->error(Yii::$app->services->setting->mall->getError()); $this->success('保存成功'); } else { $params = \Yii::$app->request->get(); // 检查提交的参数 $res = Yii::$app->services->validate->validate($params,[ [['type'], 'required'], [['type'], 'string'] ]); if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); // 获取分组 $groups = SettingEnum::getPlatformType($params['type']); $data = PlatformSetting::getConfByGroup($groups, true); $return = self::returnArray($data); $this->success('获取成功', $return); } } return $this->render($this->action->id); } // 编辑或获取配置信息 public function actionEdit() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->post()) { $setting = \Yii::$app->request->post('setting'); $trans = \Yii::$app->db->beginTransaction(); try { // 重新组合配置 foreach ($setting as $group => $value) { foreach ($value as $name => $val) { $data[$group][$name] = $val['value']; } } \Yii::$app->services->setting->platform->set($data); $trans->commit(); $this->success('操作成功'); } catch (\Exception $e) { $trans->rollBack(); \Yii::error('edit platformSetting error:' . $e->getMessage()); $this->error('编辑失败'); } } else { $system = PlatformSetting::getConfByGroup('system', true); $storage = PlatformSetting::getConfByGroup('storage', true); $storage_driver = PlatformSetting::getConfByGroup('storage_driver', true); $limit = PlatformSetting::getConfByGroup('limit', true); $mall_create_syn = PlatformSetting::getConfByGroup('mall_create_syn', true); if(!empty($mall_create_syn['mode'])){ $res = json_decode($mall_create_syn['mode']['value'],true); if(is_array($res)){ $mall_create_syn['mode']['value'] = $res; }else{ $mall_create_syn['mode']['value'] = []; } }else{ $mall_create_syn['mode']['value'] = []; } $map = PlatformSetting::getConfByGroup('map', true); $data = compact('system', 'storage', 'storage_driver', 'limit','mall_create_syn','map','sms'); $mallList = Mall::lists(['where'=>[ ['status'=>StatusEnum::ENABLED], ['or', ['expired_at'=>0], ['>','expired_at',time()], ] ],'order'=>'id asc','select'=>'id,name']); $data['mallList'] = $mallList; $this->success('操作成功', $data); } } } /** * 教程中心 * @Author: ltm * @DateTime: 2022/2/24 0024 18:30 * @Copyright: copyright (c) 2021 广东七件事集团 * @return string */ public function actionCourse(){ if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->post()) { $setting = \Yii::$app->request->post('setting'); $trans = \Yii::$app->db->beginTransaction(); try { // 重新组合配置 foreach ($setting as $group => $value) { foreach ($value as $name => $val) { $data[$group][$name] = $val['value']; } } \Yii::$app->services->setting->platform->set($data); $trans->commit(); $this->success('操作成功'); } catch (\Exception $e) { $trans->rollBack(); \Yii::error('edit platformSetting error:' . $e->getMessage()); $this->error('编辑失败'); } } else { $system = PlatformSetting::getConfByGroup('system', true); $video_tutorials_map = PlatformSetting::getConfByGroup('video_tutorial', true); $video_tutorials=\Yii::$app->params['video_tutorial']; foreach ($video_tutorials as &$item){ if(isset($video_tutorials_map['type'.$item['id']])){ $value = json_decode($video_tutorials_map['type'.$item['id']]['value'],true); $item['name'] = $value['name']; $item['url'] = $value['url']; } } $system['video_tutorials'] = $video_tutorials; $this->success('操作成功', $system); } } return $this->render($this->action->id); } public function actionCourseVideo(){ if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->post()) { $post = \Yii::$app->request->post(); try { $temp= ['id'=>$post['id']]; $temp['url'] = $post['url']??''; $temp['name'] = $post['name']??''; $data['video_tutorial']['type'.$post['id']] = $temp; \Yii::$app->services->setting->platform->set($data); return $this->success('操作成功'); } catch (\Exception $e) { \Yii::error('edit platformSetting error:' . $e->getMessage()); $this->error('编辑失败'); } } } } /** * @Author: ltm * @DateTime: 2022/3/16 0016 18:42 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $data * @return string */ public function actionNotice(){ if (\Yii::$app->request->isAjax) { $get = \Yii::$app->request->get(); // 检查提交的参数 $res = \Yii::$app->services->validate->validate($get,[ [['keyword'], 'safe'], [['limit'],'default','value' => '15'], ]); if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $where = []; if($get['keyword']) $where[] = ['like', 'content', $get['keyword']]; $where[] = ['>=', 'status', StatusEnum::DISABLED]; $order = 'created_at desc'; $params = array('where' => $where, 'order'=>$order, 'limit' => $get['limit']); $list = Notice::listPage($params, false, true); $this->success('获取成功', $list); } return $this->render($this->action->id); } public function actionNoticeEdit(){ if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->post()) { $post = \Yii::$app->request->post(); // 检查提交的参数 $res = \Yii::$app->services->validate->validate($post,[ [['content'],'required'], [['id','status'], 'safe'], ]); if($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $post = Notice::exceptNullVal($post); $res = Notice::setData($post); if($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $this->success('操作成功'); } } } public function actionNoticeDel(){ if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->post()) { $post = \Yii::$app->request->post(); // 检查提交的参数 $res = \Yii::$app->services->validate->validate($post,[ [['id'],'required'], ]); if($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $post['status'] = StatusEnum::DELETE; $post = Notice::exceptNullVal($post); $res = Notice::setData($post); if($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $this->success('操作成功'); } } } /** * @Author: ltm * @DateTime: 2022/3/16 0016 18:42 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $data * @return string */ public function actionNoticeList() { $retuest = \Yii::$app->request; if ($retuest->isAjax) { if ($retuest->isGet) { $get = \Yii::$app->request->get(); // 检查提交的参数 $res = \Yii::$app->services->validate->validate($get,[ [['keyword'], 'safe'], [['limit'],'default','value' => '15'], ]); if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $where = []; if($get['keyword']) $where[] = ['like', 'content', $get['keyword']]; $where[] = ['>=', 'status', StatusEnum::DISABLED]; $order = 'created_at desc'; $params = array('where' => $where, 'order'=>$order, 'limit' => $get['limit']); $list = Notice::listPage($params, false, true); $this->success('获取成功', $list); } } else { return $this->render($this->action->id); } } // 编辑或获取配置信息 public function actionSettingEdit() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->post()) { $setting = \Yii::$app->request->post('setting'); // 重新组合配置 $data = self::makeUpParams($setting); $res = Yii::$app->services->setting->set($data); if($res === false) return $this->error(Yii::$app->services->setting->mall->getError()); $this->success('保存成功'); } else { $params = \Yii::$app->request->get(); // 检查提交的参数 $res = Yii::$app->services->validate->validate($params,[ [['type'], 'required'], [['type'], 'string'] ]); if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); // 获取分组 $groups = SettingEnum::getPlatformType($params['type']); $data = PlatformSetting::getConfByGroup($groups, true); $return = self::returnArray($data); $this->success('获取成功', $return); } } } /** * 数组重组 * @param array $params * @return array */ private static function makeUpParams(array $params) { $data = []; // 重新组合配置 foreach ($params as $group => $value) { foreach ($value as $name => $val) { $data[$group][$name] = $val['value']; } } return $data; } /** * 字符串转数组 * @param array $data * @param string $changeText * @return array */ private static function returnArray(array $data, $changeText = 'checkbox') { foreach ($data as $key => $item) { foreach ($item as $k => $value) { $type = $value['type'] ?? ''; if ($type == $changeText) { $data[$key][$k]['value'] = Json::decode($value['value'], true); } } } return $data; } }