where("name='baseconfig'")->limit(1)->one(); check_record_exists($baseConfigModel); $baseconfig = string2array($baseConfigModel->value); $wapConfigModel = Config::find()->where("name='wapconfig'")->limit(1)->one(); check_record_exists($wapConfigModel); $wapconfig = string2array($wapConfigModel->value); $imageConfigModel = Config::find()->where("name='imageconfig'")->limit(1)->one(); check_record_exists($imageConfigModel); $imageconfig = string2array($imageConfigModel->value); $csrConfigModel = Config::find()->where("name='csr'")->limit(1)->one(); check_record_exists($csrConfigModel); $csr = string2array($csrConfigModel->value); $ueditorConfigModel = Config::find()->where("name='ueditor'")->limit(1)->one(); check_record_exists($ueditorConfigModel); $ueditorconfig = string2array($ueditorConfigModel->value); $baiduConfigModel = Config::find()->where("name='baiduconfig'")->limit(1)->one(); check_record_exists($baiduConfigModel); $baiduconfig = string2array($baiduConfigModel->value); $withdrawConfigModel = Config::find()->where("name='withdraw'")->limit(1)->one(); check_record_exists($withdrawConfigModel); $withdrawconfig = string2array($withdrawConfigModel->value); $higherConfigModel = Config::find()->where("name='higherconfig'")->limit(1)->one(); check_record_exists($higherConfigModel); $higherconfig = string2array($higherConfigModel->value); if(Yii::$app->request->post()){ $post = Yii::$app->request->post(); if(!empty($post['baseconfig'])) { $post['baseconfig']['open_cert'] = $post['baseconfig']['open_cert']?$post['baseconfig']['open_cert']:0; $post['baseconfig']['open_org'] = $post['baseconfig']['open_org']?$post['baseconfig']['open_org']:0; $post['baseconfig']['incomerank'] = $post['baseconfig']['incomerank']?$post['baseconfig']['incomerank']:0; $post['baseconfig']['open_virtual'] = $post['baseconfig']['open_virtual']?$post['baseconfig']['open_virtual']:0; $baseconfig = $post['baseconfig']; $baseConfigModel->value = array2string($post['baseconfig']); if($baseConfigModel->save()) { Yii::$app->session->setFlash('success','操作成功'); } $tab = 1; } if(!empty($post['wapconfig'])) { $wapconfig = $post['wapconfig']; $wapConfigModel->value = array2string($post['wapconfig']); if($wapConfigModel->save()) { Yii::$app->session->setFlash('success','操作成功'); } $tab = 2; } if(!empty($post['imageconfig'])) { $imageconfig = $post['imageconfig']; $imageConfigModel->value = array2string($post['imageconfig']); if($imageConfigModel->save()) { Yii::$app->session->setFlash('success','操作成功'); } $tab = 3; } if(!empty($post['csr'])) { $post['csr']['wx_mpapi'] = $post['csr']['wx_mpapi']?$post['csr']['wx_mpapi']:0; $csr = $post['csr']; $csrConfigModel->value = array2string($post['csr']); if($csrConfigModel->save()) { Yii::$app->session->setFlash('success','操作成功'); } $tab = 4; } if(!empty($post['ueditor'])) { $ueditorconfig = $post['ueditor']; $ueditorConfigModel->value = array2string($post['ueditor']); if($ueditorConfigModel->save()) { $array = $post['ueditor']; $array['imageMaxSize'] = $array['imageMaxSize']*1024*1024; $array['scrawlMaxSize'] = $array['scrawlMaxSize']*1024*1024; $array['catcherMaxSize'] = $array['catcherMaxSize']*1024*1024; $array['videoMaxSize'] = $array['videoMaxSize']*1024*1024; $array['fileMaxSize'] = $array['fileMaxSize']*1024*1024; $this->setConfig($array,'ueditor'); Yii::$app->session->setFlash('success','操作成功'); } $tab = 5; } if(!empty($post['baiduconfig'])) { $baiduconfig = $post['baiduconfig']; $baiduConfigModel->value = array2string($post['baiduconfig']); if($baiduConfigModel->save()) { Yii::$app->session->setFlash('success','操作成功'); } $tab = 6; } if(!empty($post['withdraw'])) { $withdrawconfig = $post['withdraw']; $withdrawConfigModel->value = array2string($post['withdraw']); if($withdrawConfigModel->save()) { Yii::$app->session->setFlash('success','操作成功'); } $tab = 7; } if(!empty($post['higherconfig'])) { $post['higherconfig']['open_sphinx'] = $post['higherconfig']['open_sphinx']?$post['higherconfig']['open_sphinx']:0; $post['higherconfig']['multisearch'] = $post['higherconfig']['multisearch']?$post['higherconfig']['multisearch']:0; $post['higherconfig']['splitdb'] = $post['higherconfig']['splitdb']?$post['higherconfig']['splitdb']:0; $post['higherconfig']['htmlrule'] = $post['higherconfig']['htmlrule']?$post['higherconfig']['htmlrule']:0; $post['higherconfig']['opencpc'] = $post['higherconfig']['opencpc']?$post['higherconfig']['opencpc']:0; $higherconfig = $post['higherconfig']; $higherConfigModel->value = array2string($post['higherconfig']); if($higherConfigModel->save()) { $array['htmlrule'] = $higherconfig['htmlrule']; $this->setConfig($array,'params'); Yii::$app->session->setFlash('success','操作成功'); } $tab = 9; } } else { $tab = 1; } return $this->render('base',array('tab'=>$tab,'baseconfig'=>$baseconfig,'wapconfig'=>$wapconfig,'imageconfig'=>$imageconfig,'csr'=>$csr,'baiduconfig'=>$baiduconfig,'withdrawconfig'=>$withdrawconfig,'higherconfig'=>$higherconfig,'ueditorconfig'=>$ueditorconfig)); } public function actionUpload() { $model = Config::find()->where("name='attachment'")->limit(1)->one(); check_record_exists($model); $config = string2array($model->value); $ossModel = Config::find()->where("name='oss'")->limit(1)->one(); check_record_exists($ossModel); $ossConfig = string2array($ossModel->value); $tab = 1; if(Yii::$app->request->post()){ $post = Yii::$app->request->post(); if(!empty($post['attachment'])) { $model->value = array2string($post['attachment']); if($model->save()) { $config = $post['attachment']; $file_types = join(",",explode("|",$config['file_type'])); $array['extensions'] = $file_types; $array['fileNumLimit'] = $config['file_num_limit']; $array['fileSingleSizeLimit'] = $config['file_single_size_limit']*1024*1024; $array['fileSizeLimit'] = $config['file_size_limit']*1024*1024; $this->setConfig($array,'params'); Yii::$app->session->setFlash('success','操作成功'); } $tab =1; } if(!empty($post['oss'])) { $post['oss']['OPEN_OSS'] = $post['oss']['OPEN_OSS']?$post['oss']['OPEN_OSS']:0; $post['oss']['OPEN_INTERNAL'] = $post['oss']['OPEN_INTERNAL']?$post['oss']['OPEN_INTERNAL']:0; $post['oss']['OSS_THUMB'] = $post['oss']['OSS_THUMB']?$post['oss']['OSS_THUMB']:0; $ossModel->value = array2string($post['oss']); if($ossModel->save()) { $ossConfig = $post['oss']; $this->setConfig($ossConfig,'oss'); Yii::$app->session->setFlash('success','操作成功'); } $tab =2; } } return $this->render('upload',array('config'=>$config,'ossConfig'=>$ossConfig,'tab'=>$tab)); } public function actionPay() { $model = Config::find()->where("name='pay'")->limit(1)->one(); check_record_exists($model); $config = string2array($model->value); if(Yii::$app->request->post()){ $post = Yii::$app->request->post(); if(!empty($post['pay']['weixin_config'])) { $post['pay']['weixin_pay'] = $post['pay']['weixin_pay']?$post['pay']['weixin_pay']:0; } if(!empty($post['pay']['apd_config'])) { $post['pay']['apd_pay'] = $post['pay']['apd_pay']?$post['pay']['apd_pay']:0; } if(!empty($post['pay']['apw_config'])) { $post['pay']['apw_pay'] = $post['pay']['apw_pay']?$post['pay']['apw_pay']:0; } if(!empty($post['pay']['hpwx_config'])) { $post['pay']['hpwx_pay'] = $post['pay']['hpwx_pay']?$post['pay']['hpwx_pay']:0; } if(!empty($post['pay']['hpali_config'])) { $post['pay']['hpali_pay'] = $post['pay']['hpali_pay']?$post['pay']['hpali_pay']:0; } if(!empty($post['pay']['wxh5_config'])) { $post['pay']['wxh5_pay'] = $post['pay']['wxh5_pay']?$post['pay']['wxh5_pay']:0; } if(!empty($post['pay']['coupon_config'])) { $post['pay']['open_coupon'] = $post['pay']['open_coupon']?$post['pay']['open_coupon']:0; } if($_FILES['weixin_apiclient_cert']['name']) { $tempFile = $_FILES['weixin_apiclient_cert']['tmp_name']; $targetPath = Yii::$app->params['wxPayCertPath']; dir_create($targetPath); $targetFile = $targetPath.'apiclient_cert.pem'; move_uploaded_file($tempFile,$targetFile); $post['pay']['weixin_apiclient_cert'] = str_replace(Yii::$app->params['wxPayCertPath'],"",$targetFile); $certList['weixin_apiclient_cert'] = $targetFile; } else { $certList['weixin_apiclient_cert'] = Yii::$app->params['wxPayCertPath'].'apiclient_cert.pem'; } if($_FILES['weixin_apiclient_key']['name']) { $tempFile = $_FILES['weixin_apiclient_key']['tmp_name']; $targetPath = Yii::$app->params['wxPayCertPath']; dir_create($targetPath); $targetFile = $targetPath.'apiclient_key.pem'; move_uploaded_file($tempFile,$targetFile); $post['pay']['weixin_apiclient_key'] = str_replace(Yii::$app->params['wxPayCertPath'],"",$targetFile); $certList['weixin_apiclient_key'] = $targetFile; } else { $certList['weixin_apiclient_key'] = Yii::$app->params['wxPayCertPath'].'apiclient_key.pem'; } if($_FILES['weixin_cert']['name']) { $tempFile = $_FILES['weixin_cert']['tmp_name']; $targetPath = Yii::$app->params['wxPayCertPath']; dir_create($targetPath); $targetFile = $targetPath.'weixin_cert.pem'; move_uploaded_file($tempFile,$targetFile); $post['pay']['weixin_cert'] = str_replace(Yii::$app->params['wxPayCertPath'],"",$targetFile); $certList['weixin_cert'] = $targetFile; } else { $certList['weixin_cert'] = Yii::$app->params['wxPayCertPath'].'weixin_cert.pem'; } $newConfig = array_merge($config,$post['pay']); $model->value = array2string($newConfig); if($model->save()) { $config = $newConfig; $this->setConfig($post['pay'],'pay'); if(!empty($certList))$this->setConfig($certList,'pay'); Yii::$app->session->setFlash('success','操作成功'); //$this->refresh(); } } return $this->render('pay',array('config'=>$config)); } //短信配置 public function actionSms(){ $configModel = Config::find()->where("name='sms'")->limit(1)->one(); check_record_exists($configModel); $config = string2array($configModel->value); if(Yii::$app->request->post()){ $post = Yii::$app->request->post(); $post['sms']['open_sms'] = $post['sms']['open_sms']?$post['sms']['open_sms']:0; $post['sms']['open_imgvalid'] = $post['sms']['open_imgvalid']?$post['sms']['open_imgvalid']:0; $configModel->value = array2string($post['sms']); if($configModel->save()) { $config = $post['sms']; Yii::$app->session->setFlash('success','操作成功'); } } if (Yii::$app->request->isAjax) { $query = MobileMsgTpl::find(); $data = []; $params = Yii::$app->request->get('MobileMsgTpl'); $query = mergeParams($query,$params); //排序 if(isset($_GET['sort'])&&isset($_GET['sortOrder'])) { $resultList = $query->orderBy([$_GET['sort']=>($_GET['sortOrder']=='asc'?SORT_ASC:SORT_DESC)])->all(); } else { $resultList = $query->orderBy(['id'=>SORT_ASC])->all(); } foreach($resultList as $result) { $data[] = array('id'=>$result->id,'key'=>$result->key,'name'=>$result->name,'code'=>$result->code,'tpl'=>$result->tpl,'type'=>MobileMsgTpl::typeOptions($result->type)); } echo_json($data); } $this->tableTitle = array( array('field'=>'id','title'=>Yii::t('attr','mobile_msg_tpl.id'),'align'=>'center','sortable'=>true,'class'=>'col-md-2'), array('field'=>'key','title'=>Yii::t('attr','mobile_msg_tpl.key'),'align'=>'center'), array('field'=>'name','title'=>Yii::t('attr','mobile_msg_tpl.name'),'align'=>'center'), array('field'=>'code','title'=>Yii::t('attr','mobile_msg_tpl.code'),'align'=>'center'), array('field'=>'tpl','title'=>Yii::t('attr','mobile_msg_tpl.tpl'),'align'=>'center'), array('field'=>'type','title'=>Yii::t('attr','mobile_msg_tpl.type'),'align'=>'center'), array('field'=>'operate','title'=>'操作','align'=>'center','events'=>'window.operateEvents','formatter'=>'operateFormatter'), ); $this->tableConfig = array('table'=>MobileMsgTpl::shortTableName(),'url'=>$this->createRealUrl(['admin/settings/sms']),'idField'=>MobileMsgTpl::modelPrimaryKey(),'checkbox'=>0,'dropmenu'=>1,'pagination'=>false,'refresh'=>true); return $this->render('sms',array('config'=>$config,'model'=>new MobileMsgTpl())); } //添加短信模板 public function actionAddsms() { $model = new MobileMsgTpl(); if(Yii::$app->request->isAjax&&$model->load(Yii::$app->request->post())){ $exist = MobileMsgTpl::find()->alias("a")->where("a.key='".$model->key."'")->exists(); if($exist) { $msgdata = ['error' => 1,'msg' => '已存在相同Key,添加失败']; echo_json($msgdata); } if(!$model->validate()) { $msgdata = ['error' => 1,'msg' => $model->returnFirstError()]; } else { if($model->save()) { $msgdata = ['error' => 0,'msg' => '操作成功']; } else { $msgdata = ['error' => 1,'msg' => '操作失败']; } } echo_json($msgdata); } return $this->renderAjax('addsms',array('model'=>$model)); } //编辑短信模板 public function actionEditsms() { $id = $this->getKeyId(); $model = MobileMsgTpl::findOne($id); check_record_exists($model); if($model->load(Yii::$app->request->post())){ if(!$model->validate()) { $msgdata = ['error' => 1,'msg' => $model->returnFirstError()]; } else { if($model->save()) { $msgdata = ['error' => 0,'msg' => '操作成功']; } else { $msgdata = ['error' => 1,'msg' => '操作失败']; } } echo_json($msgdata); } return $this->renderAjax('addsms',array('model'=>$model)); } //删除短信模板 public function actionDelsms() { $id = $this->getKeyId(); $model = MobileMsgTpl::findOne($id); check_record_exists($model); if($model->delete()) { $msgdata = ['error' => 0,'msg' => '删除成功']; } else { $msgdata = ['error' => 1,'msg' => '删除失败']; } echo_json($msgdata); } //测试短信发送 public function actionSendsms() { $id = $this->getKeyId(); $model = MobileMsgTpl::findOne($id); check_record_exists($model); $post = Yii::$app->request->post(); if(!empty($post['mobile'])){ preg_match_all('/{(.*?)}/i',$model->tpl,$return); $args = explode("|",$post['args']); if(is_array($args))foreach($args as $k=>$arg) { $newArgs[$return[1][$k]] = $arg; } $sms = new Sms(); $sms->init(); $result = $sms->send($model->key,$post['mobile'],$newArgs,2); if($result) { $msgdata = ['error' => 0,'msg' => '发送成功']; } else { $msgdata = ['error' => 1,'msg' => '发送失败']; } echo_json($msgdata); } return $this->renderAjax('sendsms'); } //邮箱配置 public function actionMail(){ $configModel = Config::find()->where("name='mailer'")->limit(1)->one(); check_record_exists($configModel); $config = string2array($configModel->value); if(Yii::$app->request->post()){ $post = Yii::$app->request->post(); $post['mailer']['open'] = $post['mailer']['open']?$post['mailer']['open']:0; $configModel->value = array2string($post['mailer']); if($configModel->save()) { $config = $post['mailer']; $this->setConfig($config,'mailer'); Yii::$app->session->setFlash('success','操作成功'); } } if (Yii::$app->request->isAjax) { $query = EmailTpl::find(); $data = []; $params = Yii::$app->request->get('EmailTpl'); $query = mergeParams($query,$params); //排序 if(isset($_GET['sort'])&&isset($_GET['sortOrder'])) { $resultList = $query->orderBy([$_GET['sort']=>($_GET['sortOrder']=='asc'?SORT_ASC:SORT_DESC)])->all(); } else { $resultList = $query->orderBy(['id'=>SORT_ASC])->all(); } foreach($resultList as $result) { $data[] = array('id'=>$result->id,'key'=>$result->key,'title'=>$result->title,'tpl'=>$result->tpl,'type'=>EmailTpl::typeOptions($result->type)); } echo_json($data); } $this->tableTitle = array( array('field'=>'id','title'=>Yii::t('attr','email_tpl.id'),'align'=>'center','sortable'=>true,'class'=>'col-md-2'), array('field'=>'key','title'=>Yii::t('attr','email_tpl.key'),'align'=>'center'), array('field'=>'title','title'=>Yii::t('attr','email_tpl.title'),'align'=>'center'), array('field'=>'type','title'=>Yii::t('attr','email_tpl.type'),'align'=>'center'), array('field'=>'operate','title'=>'操作','align'=>'center','events'=>'window.operateEvents','formatter'=>'operateFormatter'), ); $this->tableConfig = array('table'=>EmailTpl::shortTableName(),'url'=>$this->createRealUrl(['admin/settings/mail']),'idField'=>EmailTpl::modelPrimaryKey(),'checkbox'=>1,'dropmenu'=>1,'pagination'=>false,'refresh'=>true); return $this->render('mail',array('config'=>$config,'model'=>new EmailTpl())); } //添加邮件模板 public function actionAddmailtpl() { $model = new EmailTpl(); if(Yii::$app->request->isAjax&&$model->load(Yii::$app->request->post())){ $exist = EmailTpl::find()->alias("a")->where("a.key='".$model->key."'")->exists(); if($exist) { $msgdata = ['error' => 1,'msg' => '已存在相同Key,添加失败']; echo_json($msgdata); } if(!$model->validate()) { $msgdata = ['error' => 1,'msg' => $model->returnFirstError()]; } else { if($model->save()) { $msgdata = ['error' => 0,'msg' => '操作成功']; } else { $msgdata = ['error' => 1,'msg' => '操作失败']; } } echo_json($msgdata); } return $this->renderAjax('addmailtpl',array('model'=>$model)); } //编辑邮箱模板 public function actionEditmailtpl() { $id = $this->getKeyId(); $model = EmailTpl::findOne($id); check_record_exists($model); if($model->load(Yii::$app->request->post())){ if(!$model->validate()) { $msgdata = ['error' => 1,'msg' => $model->returnFirstError()]; } else { if($model->save()) { $msgdata = ['error' => 0,'msg' => '操作成功']; } else { $msgdata = ['error' => 1,'msg' => '操作失败']; } } echo_json($msgdata); } return $this->renderAjax('addmailtpl',array('model'=>$model)); } //删除邮件模板 public function actionDelmailtpl() { $id = $this->getKeyId(); $model = EmailTpl::findOne($id); check_record_exists($model); if($model->delete()) { $msgdata = ['error' => 0,'msg' => '删除成功']; } else { $msgdata = ['error' => 1,'msg' => '删除失败']; } echo_json($msgdata); } //测试邮件发送 public function actionSendmail() { $id = $this->getKeyId(); $model = EmailTpl::findOne($id); check_record_exists($model); $post = Yii::$app->request->post(); if(!empty($post['mailaddress'])){ preg_match_all('/{(.*?)}/i',$model->tpl,$return); $newArgs = []; $args = explode("|",$post['args']); if(is_array($args))foreach($args as $k=>$arg) { $newArgs[$return[1][$k]] = $arg; } $mailer = new Emailer(); $result = $mailer->send($model->key,$post['mailaddress'],$newArgs); if($result) { $msgdata = ['error' => 0,'msg' => '发送成功']; } else { $msgdata = ['error' => 1,'msg' => '发送失败']; } echo_json($msgdata); } return $this->renderAjax('sendmail'); } //金币设置 public function actionCoin(){ $settings = getSysconfigValue('coin'); $configModel = Config::find()->where("name='coin'")->limit(1)->one(); check_record_exists($configModel); $config = string2array($configModel->value); if(Yii::$app->request->post()){ $post = Yii::$app->request->post(); $configModel->value = array2string($post['coin']); if($configModel->save()) { $config = $post['coin']; $this->writeConfigFile($config,'coin'); Yii::$app->session->setFlash('success','操作成功'); } } return $this->render('coin',array('config'=>$config,'settings'=>$settings)); } //积分设置 public function actionPoint(){ $settings = getSysconfigValue('point'); $configModel = Config::find()->where("name='point'")->limit(1)->one(); check_record_exists($configModel); $config = string2array($configModel->value); if(Yii::$app->request->post()){ $post = Yii::$app->request->post(); $configModel->value = array2string($post['point']); if($configModel->save()) { $config = $post['point']; $this->writeConfigFile($config,'point'); Yii::$app->session->setFlash('success','操作成功'); } } return $this->render('point',array('config'=>$config,'settings'=>$settings)); } //第三方登录设置 public function actionOpenauth(){ $model = Config::find()->where("name='openauth'")->limit(1)->one(); check_record_exists($model); $config = string2array($model->value); if(Yii::$app->request->post()){ $post = Yii::$app->request->post(); if(!empty($post['openauth']['systemConfig'])) { $post['openauth']['commonAccount'] = $post['openauth']['commonAccount']?$post['openauth']['commonAccount']:0; $post['openauth']['fastAccount'] = $post['openauth']['fastAccount']?$post['openauth']['fastAccount']:0; $post['openauth']['fastAccountType'] = $post['openauth']['fastAccountType']?$post['openauth']['fastAccountType']:0; $tab = 1; } if(!empty($post['openauth']['mpConfig'])) { $post['openauth']['openMpLogin'] = $post['openauth']['openMpLogin']?$post['openauth']['openMpLogin']:0; $post['openauth']['mpAutoLoginWap'] = $post['openauth']['mpAutoLoginWap']?$post['openauth']['mpAutoLoginWap']:0; $post['openauth']['openMpSubLogin'] = $post['openauth']['openMpSubLogin']?$post['openauth']['openMpSubLogin']:0; $tab = 2; } if(!empty($post['openauth']['qqConfig'])) { $post['openauth']['openQqLogin'] = $post['openauth']['openQqLogin']?$post['openauth']['openQqLogin']:0; $post['openauth']['m_openQqLogin'] = $post['openauth']['m_openQqLogin']?$post['openauth']['m_openQqLogin']:0; $tab = 3; } if(!empty($post['openauth']['dingConfig'])) { $post['openauth']['dingtalkLogin'] = $post['openauth']['dingtalkLogin']?$post['openauth']['dingtalkLogin']:0; $post['openauth']['m_dingtalkLogin'] = $post['openauth']['m_dingtalkLogin']?$post['openauth']['m_dingtalkLogin']:0; $tab = 4; } if(!empty($post['openauth']['systemUnion'])) { $post['openauth']['openUnionId'] = $post['openauth']['openUnionId']?$post['openauth']['openUnionId']:0; $tab = 5; } $newConfig = array_merge($config,$post['openauth']); $model->value = array2string($newConfig); if($model->save()) { $config = $newConfig; $this->writeConfigFile($newConfig,'openauth'); Yii::$app->session->setFlash('success','操作成功'); //$this->refresh(); } } return $this->render('openauth',array('config'=>$config,'tab'=>$tab)); } }