| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419 |
- <?php
- namespace backend\modules\admin\controllers;
- use backend\controllers\AdminController;
- use common\enums\StatusEnum;
- use common\enums\SettingEnum;
- use common\models\common\PlatformSetting;
- use common\models\mall\Mall;
- use common\models\notice\Notice;
- use Yii;
- use yii\helpers\Json;
- class SettingController extends AdminController
- {
- public function actionIndex()
- {
- 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'];
- }
- }
- // 检查发薪猫域名是否变化,如果变化修改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;
- }
- }
|