SettingsController.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. <?php
  2. namespace app\modules\admin\controllers;
  3. use app\common\controllers\BController;
  4. use app\modules\admin\models\Config;
  5. use app\models\MobileMsgTpl;
  6. use app\models\EmailTpl;
  7. use app\common\components\Sms;
  8. use app\common\components\Emailer;
  9. use app\modules\admin\models\Sysconfig;
  10. use Yii;
  11. class SettingsController extends BController
  12. {
  13. public $layout = 'main';
  14. public function actionBase()
  15. {
  16. $baseConfigModel = Config::find()->where("name='baseconfig'")->limit(1)->one();
  17. check_record_exists($baseConfigModel);
  18. $baseconfig = string2array($baseConfigModel->value);
  19. $wapConfigModel = Config::find()->where("name='wapconfig'")->limit(1)->one();
  20. check_record_exists($wapConfigModel);
  21. $wapconfig = string2array($wapConfigModel->value);
  22. $imageConfigModel = Config::find()->where("name='imageconfig'")->limit(1)->one();
  23. check_record_exists($imageConfigModel);
  24. $imageconfig = string2array($imageConfigModel->value);
  25. $csrConfigModel = Config::find()->where("name='csr'")->limit(1)->one();
  26. check_record_exists($csrConfigModel);
  27. $csr = string2array($csrConfigModel->value);
  28. $ueditorConfigModel = Config::find()->where("name='ueditor'")->limit(1)->one();
  29. check_record_exists($ueditorConfigModel);
  30. $ueditorconfig = string2array($ueditorConfigModel->value);
  31. $baiduConfigModel = Config::find()->where("name='baiduconfig'")->limit(1)->one();
  32. check_record_exists($baiduConfigModel);
  33. $baiduconfig = string2array($baiduConfigModel->value);
  34. $withdrawConfigModel = Config::find()->where("name='withdraw'")->limit(1)->one();
  35. check_record_exists($withdrawConfigModel);
  36. $withdrawconfig = string2array($withdrawConfigModel->value);
  37. $higherConfigModel = Config::find()->where("name='higherconfig'")->limit(1)->one();
  38. check_record_exists($higherConfigModel);
  39. $higherconfig = string2array($higherConfigModel->value);
  40. if(Yii::$app->request->post()){
  41. $post = Yii::$app->request->post();
  42. if(!empty($post['baseconfig']))
  43. {
  44. $post['baseconfig']['open_cert'] = $post['baseconfig']['open_cert']?$post['baseconfig']['open_cert']:0;
  45. $post['baseconfig']['open_org'] = $post['baseconfig']['open_org']?$post['baseconfig']['open_org']:0;
  46. $post['baseconfig']['incomerank'] = $post['baseconfig']['incomerank']?$post['baseconfig']['incomerank']:0;
  47. $post['baseconfig']['open_virtual'] = $post['baseconfig']['open_virtual']?$post['baseconfig']['open_virtual']:0;
  48. $baseconfig = $post['baseconfig'];
  49. $baseConfigModel->value = array2string($post['baseconfig']);
  50. if($baseConfigModel->save())
  51. {
  52. Yii::$app->session->setFlash('success','操作成功');
  53. }
  54. $tab = 1;
  55. }
  56. if(!empty($post['wapconfig']))
  57. {
  58. $wapconfig = $post['wapconfig'];
  59. $wapConfigModel->value = array2string($post['wapconfig']);
  60. if($wapConfigModel->save())
  61. {
  62. Yii::$app->session->setFlash('success','操作成功');
  63. }
  64. $tab = 2;
  65. }
  66. if(!empty($post['imageconfig']))
  67. {
  68. $imageconfig = $post['imageconfig'];
  69. $imageConfigModel->value = array2string($post['imageconfig']);
  70. if($imageConfigModel->save())
  71. {
  72. Yii::$app->session->setFlash('success','操作成功');
  73. }
  74. $tab = 3;
  75. }
  76. if(!empty($post['csr']))
  77. {
  78. $post['csr']['wx_mpapi'] = $post['csr']['wx_mpapi']?$post['csr']['wx_mpapi']:0;
  79. $csr = $post['csr'];
  80. $csrConfigModel->value = array2string($post['csr']);
  81. if($csrConfigModel->save())
  82. {
  83. Yii::$app->session->setFlash('success','操作成功');
  84. }
  85. $tab = 4;
  86. }
  87. if(!empty($post['ueditor']))
  88. {
  89. $ueditorconfig = $post['ueditor'];
  90. $ueditorConfigModel->value = array2string($post['ueditor']);
  91. if($ueditorConfigModel->save())
  92. {
  93. $array = $post['ueditor'];
  94. $array['imageMaxSize'] = $array['imageMaxSize']*1024*1024;
  95. $array['scrawlMaxSize'] = $array['scrawlMaxSize']*1024*1024;
  96. $array['catcherMaxSize'] = $array['catcherMaxSize']*1024*1024;
  97. $array['videoMaxSize'] = $array['videoMaxSize']*1024*1024;
  98. $array['fileMaxSize'] = $array['fileMaxSize']*1024*1024;
  99. $this->setConfig($array,'ueditor');
  100. Yii::$app->session->setFlash('success','操作成功');
  101. }
  102. $tab = 5;
  103. }
  104. if(!empty($post['baiduconfig']))
  105. {
  106. $baiduconfig = $post['baiduconfig'];
  107. $baiduConfigModel->value = array2string($post['baiduconfig']);
  108. if($baiduConfigModel->save())
  109. {
  110. Yii::$app->session->setFlash('success','操作成功');
  111. }
  112. $tab = 6;
  113. }
  114. if(!empty($post['withdraw']))
  115. {
  116. $withdrawconfig = $post['withdraw'];
  117. $withdrawConfigModel->value = array2string($post['withdraw']);
  118. if($withdrawConfigModel->save())
  119. {
  120. Yii::$app->session->setFlash('success','操作成功');
  121. }
  122. $tab = 7;
  123. }
  124. if(!empty($post['higherconfig']))
  125. {
  126. $post['higherconfig']['open_sphinx'] = $post['higherconfig']['open_sphinx']?$post['higherconfig']['open_sphinx']:0;
  127. $post['higherconfig']['multisearch'] = $post['higherconfig']['multisearch']?$post['higherconfig']['multisearch']:0;
  128. $post['higherconfig']['splitdb'] = $post['higherconfig']['splitdb']?$post['higherconfig']['splitdb']:0;
  129. $post['higherconfig']['htmlrule'] = $post['higherconfig']['htmlrule']?$post['higherconfig']['htmlrule']:0;
  130. $post['higherconfig']['opencpc'] = $post['higherconfig']['opencpc']?$post['higherconfig']['opencpc']:0;
  131. $higherconfig = $post['higherconfig'];
  132. $higherConfigModel->value = array2string($post['higherconfig']);
  133. if($higherConfigModel->save())
  134. {
  135. $array['htmlrule'] = $higherconfig['htmlrule'];
  136. $this->setConfig($array,'params');
  137. Yii::$app->session->setFlash('success','操作成功');
  138. }
  139. $tab = 9;
  140. }
  141. }
  142. else
  143. {
  144. $tab = 1;
  145. }
  146. return $this->render('base',array('tab'=>$tab,'baseconfig'=>$baseconfig,'wapconfig'=>$wapconfig,'imageconfig'=>$imageconfig,'csr'=>$csr,'baiduconfig'=>$baiduconfig,'withdrawconfig'=>$withdrawconfig,'higherconfig'=>$higherconfig,'ueditorconfig'=>$ueditorconfig));
  147. }
  148. public function actionUpload()
  149. {
  150. $model = Config::find()->where("name='attachment'")->limit(1)->one();
  151. check_record_exists($model);
  152. $config = string2array($model->value);
  153. $ossModel = Config::find()->where("name='oss'")->limit(1)->one();
  154. check_record_exists($ossModel);
  155. $ossConfig = string2array($ossModel->value);
  156. $tab = 1;
  157. if(Yii::$app->request->post()){
  158. $post = Yii::$app->request->post();
  159. if(!empty($post['attachment']))
  160. {
  161. $model->value = array2string($post['attachment']);
  162. if($model->save())
  163. {
  164. $config = $post['attachment'];
  165. $file_types = join(",",explode("|",$config['file_type']));
  166. $array['extensions'] = $file_types;
  167. $array['fileNumLimit'] = $config['file_num_limit'];
  168. $array['fileSingleSizeLimit'] = $config['file_single_size_limit']*1024*1024;
  169. $array['fileSizeLimit'] = $config['file_size_limit']*1024*1024;
  170. $this->setConfig($array,'params');
  171. Yii::$app->session->setFlash('success','操作成功');
  172. }
  173. $tab =1;
  174. }
  175. if(!empty($post['oss']))
  176. {
  177. $post['oss']['OPEN_OSS'] = $post['oss']['OPEN_OSS']?$post['oss']['OPEN_OSS']:0;
  178. $post['oss']['OPEN_INTERNAL'] = $post['oss']['OPEN_INTERNAL']?$post['oss']['OPEN_INTERNAL']:0;
  179. $post['oss']['OSS_THUMB'] = $post['oss']['OSS_THUMB']?$post['oss']['OSS_THUMB']:0;
  180. $ossModel->value = array2string($post['oss']);
  181. if($ossModel->save())
  182. {
  183. $ossConfig = $post['oss'];
  184. $this->setConfig($ossConfig,'oss');
  185. Yii::$app->session->setFlash('success','操作成功');
  186. }
  187. $tab =2;
  188. }
  189. }
  190. return $this->render('upload',array('config'=>$config,'ossConfig'=>$ossConfig,'tab'=>$tab));
  191. }
  192. public function actionPay()
  193. {
  194. $model = Config::find()->where("name='pay'")->limit(1)->one();
  195. check_record_exists($model);
  196. $config = string2array($model->value);
  197. if(Yii::$app->request->post()){
  198. $post = Yii::$app->request->post();
  199. if(!empty($post['pay']['weixin_config']))
  200. {
  201. $post['pay']['weixin_pay'] = $post['pay']['weixin_pay']?$post['pay']['weixin_pay']:0;
  202. }
  203. if(!empty($post['pay']['apd_config']))
  204. {
  205. $post['pay']['apd_pay'] = $post['pay']['apd_pay']?$post['pay']['apd_pay']:0;
  206. }
  207. if(!empty($post['pay']['apw_config']))
  208. {
  209. $post['pay']['apw_pay'] = $post['pay']['apw_pay']?$post['pay']['apw_pay']:0;
  210. }
  211. if(!empty($post['pay']['hpwx_config']))
  212. {
  213. $post['pay']['hpwx_pay'] = $post['pay']['hpwx_pay']?$post['pay']['hpwx_pay']:0;
  214. }
  215. if(!empty($post['pay']['hpali_config']))
  216. {
  217. $post['pay']['hpali_pay'] = $post['pay']['hpali_pay']?$post['pay']['hpali_pay']:0;
  218. }
  219. if(!empty($post['pay']['wxh5_config']))
  220. {
  221. $post['pay']['wxh5_pay'] = $post['pay']['wxh5_pay']?$post['pay']['wxh5_pay']:0;
  222. }
  223. if(!empty($post['pay']['coupon_config']))
  224. {
  225. $post['pay']['open_coupon'] = $post['pay']['open_coupon']?$post['pay']['open_coupon']:0;
  226. }
  227. if($_FILES['weixin_apiclient_cert']['name'])
  228. {
  229. $tempFile = $_FILES['weixin_apiclient_cert']['tmp_name'];
  230. $targetPath = Yii::$app->params['wxPayCertPath'];
  231. dir_create($targetPath);
  232. $targetFile = $targetPath.'apiclient_cert.pem';
  233. move_uploaded_file($tempFile,$targetFile);
  234. $post['pay']['weixin_apiclient_cert'] = str_replace(Yii::$app->params['wxPayCertPath'],"",$targetFile);
  235. $certList['weixin_apiclient_cert'] = $targetFile;
  236. }
  237. else
  238. {
  239. $certList['weixin_apiclient_cert'] = Yii::$app->params['wxPayCertPath'].'apiclient_cert.pem';
  240. }
  241. if($_FILES['weixin_apiclient_key']['name'])
  242. {
  243. $tempFile = $_FILES['weixin_apiclient_key']['tmp_name'];
  244. $targetPath = Yii::$app->params['wxPayCertPath'];
  245. dir_create($targetPath);
  246. $targetFile = $targetPath.'apiclient_key.pem';
  247. move_uploaded_file($tempFile,$targetFile);
  248. $post['pay']['weixin_apiclient_key'] = str_replace(Yii::$app->params['wxPayCertPath'],"",$targetFile);
  249. $certList['weixin_apiclient_key'] = $targetFile;
  250. }
  251. else
  252. {
  253. $certList['weixin_apiclient_key'] = Yii::$app->params['wxPayCertPath'].'apiclient_key.pem';
  254. }
  255. if($_FILES['weixin_cert']['name'])
  256. {
  257. $tempFile = $_FILES['weixin_cert']['tmp_name'];
  258. $targetPath = Yii::$app->params['wxPayCertPath'];
  259. dir_create($targetPath);
  260. $targetFile = $targetPath.'weixin_cert.pem';
  261. move_uploaded_file($tempFile,$targetFile);
  262. $post['pay']['weixin_cert'] = str_replace(Yii::$app->params['wxPayCertPath'],"",$targetFile);
  263. $certList['weixin_cert'] = $targetFile;
  264. }
  265. else
  266. {
  267. $certList['weixin_cert'] = Yii::$app->params['wxPayCertPath'].'weixin_cert.pem';
  268. }
  269. $newConfig = array_merge($config,$post['pay']);
  270. $model->value = array2string($newConfig);
  271. if($model->save())
  272. {
  273. $config = $newConfig;
  274. $this->setConfig($post['pay'],'pay');
  275. if(!empty($certList))$this->setConfig($certList,'pay');
  276. Yii::$app->session->setFlash('success','操作成功');
  277. //$this->refresh();
  278. }
  279. }
  280. return $this->render('pay',array('config'=>$config));
  281. }
  282. //短信配置
  283. public function actionSms(){
  284. $configModel = Config::find()->where("name='sms'")->limit(1)->one();
  285. check_record_exists($configModel);
  286. $config = string2array($configModel->value);
  287. if(Yii::$app->request->post()){
  288. $post = Yii::$app->request->post();
  289. $post['sms']['open_sms'] = $post['sms']['open_sms']?$post['sms']['open_sms']:0;
  290. $post['sms']['open_imgvalid'] = $post['sms']['open_imgvalid']?$post['sms']['open_imgvalid']:0;
  291. $configModel->value = array2string($post['sms']);
  292. if($configModel->save())
  293. {
  294. $config = $post['sms'];
  295. Yii::$app->session->setFlash('success','操作成功');
  296. }
  297. }
  298. if (Yii::$app->request->isAjax) {
  299. $query = MobileMsgTpl::find();
  300. $data = [];
  301. $params = Yii::$app->request->get('MobileMsgTpl');
  302. $query = mergeParams($query,$params);
  303. //排序
  304. if(isset($_GET['sort'])&&isset($_GET['sortOrder']))
  305. {
  306. $resultList = $query->orderBy([$_GET['sort']=>($_GET['sortOrder']=='asc'?SORT_ASC:SORT_DESC)])->all();
  307. }
  308. else
  309. {
  310. $resultList = $query->orderBy(['id'=>SORT_ASC])->all();
  311. }
  312. foreach($resultList as $result)
  313. {
  314. $data[] = array('id'=>$result->id,'key'=>$result->key,'name'=>$result->name,'code'=>$result->code,'tpl'=>$result->tpl,'type'=>MobileMsgTpl::typeOptions($result->type));
  315. }
  316. echo_json($data);
  317. }
  318. $this->tableTitle = array(
  319. array('field'=>'id','title'=>Yii::t('attr','mobile_msg_tpl.id'),'align'=>'center','sortable'=>true,'class'=>'col-md-2'),
  320. array('field'=>'key','title'=>Yii::t('attr','mobile_msg_tpl.key'),'align'=>'center'),
  321. array('field'=>'name','title'=>Yii::t('attr','mobile_msg_tpl.name'),'align'=>'center'),
  322. array('field'=>'code','title'=>Yii::t('attr','mobile_msg_tpl.code'),'align'=>'center'),
  323. array('field'=>'tpl','title'=>Yii::t('attr','mobile_msg_tpl.tpl'),'align'=>'center'),
  324. array('field'=>'type','title'=>Yii::t('attr','mobile_msg_tpl.type'),'align'=>'center'),
  325. array('field'=>'operate','title'=>'操作','align'=>'center','events'=>'window.operateEvents','formatter'=>'operateFormatter'),
  326. );
  327. $this->tableConfig = array('table'=>MobileMsgTpl::shortTableName(),'url'=>$this->createRealUrl(['admin/settings/sms']),'idField'=>MobileMsgTpl::modelPrimaryKey(),'checkbox'=>0,'dropmenu'=>1,'pagination'=>false,'refresh'=>true);
  328. return $this->render('sms',array('config'=>$config,'model'=>new MobileMsgTpl()));
  329. }
  330. //添加短信模板
  331. public function actionAddsms()
  332. {
  333. $model = new MobileMsgTpl();
  334. if(Yii::$app->request->isAjax&&$model->load(Yii::$app->request->post())){
  335. $exist = MobileMsgTpl::find()->alias("a")->where("a.key='".$model->key."'")->exists();
  336. if($exist)
  337. {
  338. $msgdata = ['error' => 1,'msg' => '已存在相同Key,添加失败'];
  339. echo_json($msgdata);
  340. }
  341. if(!$model->validate())
  342. {
  343. $msgdata = ['error' => 1,'msg' => $model->returnFirstError()];
  344. }
  345. else
  346. {
  347. if($model->save())
  348. {
  349. $msgdata = ['error' => 0,'msg' => '操作成功'];
  350. }
  351. else
  352. {
  353. $msgdata = ['error' => 1,'msg' => '操作失败'];
  354. }
  355. }
  356. echo_json($msgdata);
  357. }
  358. return $this->renderAjax('addsms',array('model'=>$model));
  359. }
  360. //编辑短信模板
  361. public function actionEditsms()
  362. {
  363. $id = $this->getKeyId();
  364. $model = MobileMsgTpl::findOne($id);
  365. check_record_exists($model);
  366. if($model->load(Yii::$app->request->post())){
  367. if(!$model->validate())
  368. {
  369. $msgdata = ['error' => 1,'msg' => $model->returnFirstError()];
  370. }
  371. else
  372. {
  373. if($model->save())
  374. {
  375. $msgdata = ['error' => 0,'msg' => '操作成功'];
  376. }
  377. else
  378. {
  379. $msgdata = ['error' => 1,'msg' => '操作失败'];
  380. }
  381. }
  382. echo_json($msgdata);
  383. }
  384. return $this->renderAjax('addsms',array('model'=>$model));
  385. }
  386. //删除短信模板
  387. public function actionDelsms()
  388. {
  389. $id = $this->getKeyId();
  390. $model = MobileMsgTpl::findOne($id);
  391. check_record_exists($model);
  392. if($model->delete())
  393. {
  394. $msgdata = ['error' => 0,'msg' => '删除成功'];
  395. }
  396. else
  397. {
  398. $msgdata = ['error' => 1,'msg' => '删除失败'];
  399. }
  400. echo_json($msgdata);
  401. }
  402. //测试短信发送
  403. public function actionSendsms()
  404. {
  405. $id = $this->getKeyId();
  406. $model = MobileMsgTpl::findOne($id);
  407. check_record_exists($model);
  408. $post = Yii::$app->request->post();
  409. if(!empty($post['mobile'])){
  410. preg_match_all('/{(.*?)}/i',$model->tpl,$return);
  411. $args = explode("|",$post['args']);
  412. if(is_array($args))foreach($args as $k=>$arg)
  413. {
  414. $newArgs[$return[1][$k]] = $arg;
  415. }
  416. $sms = new Sms();
  417. $sms->init();
  418. $result = $sms->send($model->key,$post['mobile'],$newArgs,2);
  419. if($result)
  420. {
  421. $msgdata = ['error' => 0,'msg' => '发送成功'];
  422. }
  423. else
  424. {
  425. $msgdata = ['error' => 1,'msg' => '发送失败'];
  426. }
  427. echo_json($msgdata);
  428. }
  429. return $this->renderAjax('sendsms');
  430. }
  431. //邮箱配置
  432. public function actionMail(){
  433. $configModel = Config::find()->where("name='mailer'")->limit(1)->one();
  434. check_record_exists($configModel);
  435. $config = string2array($configModel->value);
  436. if(Yii::$app->request->post()){
  437. $post = Yii::$app->request->post();
  438. $post['mailer']['open'] = $post['mailer']['open']?$post['mailer']['open']:0;
  439. $configModel->value = array2string($post['mailer']);
  440. if($configModel->save())
  441. {
  442. $config = $post['mailer'];
  443. $this->setConfig($config,'mailer');
  444. Yii::$app->session->setFlash('success','操作成功');
  445. }
  446. }
  447. if (Yii::$app->request->isAjax) {
  448. $query = EmailTpl::find();
  449. $data = [];
  450. $params = Yii::$app->request->get('EmailTpl');
  451. $query = mergeParams($query,$params);
  452. //排序
  453. if(isset($_GET['sort'])&&isset($_GET['sortOrder']))
  454. {
  455. $resultList = $query->orderBy([$_GET['sort']=>($_GET['sortOrder']=='asc'?SORT_ASC:SORT_DESC)])->all();
  456. }
  457. else
  458. {
  459. $resultList = $query->orderBy(['id'=>SORT_ASC])->all();
  460. }
  461. foreach($resultList as $result)
  462. {
  463. $data[] = array('id'=>$result->id,'key'=>$result->key,'title'=>$result->title,'tpl'=>$result->tpl,'type'=>EmailTpl::typeOptions($result->type));
  464. }
  465. echo_json($data);
  466. }
  467. $this->tableTitle = array(
  468. array('field'=>'id','title'=>Yii::t('attr','email_tpl.id'),'align'=>'center','sortable'=>true,'class'=>'col-md-2'),
  469. array('field'=>'key','title'=>Yii::t('attr','email_tpl.key'),'align'=>'center'),
  470. array('field'=>'title','title'=>Yii::t('attr','email_tpl.title'),'align'=>'center'),
  471. array('field'=>'type','title'=>Yii::t('attr','email_tpl.type'),'align'=>'center'),
  472. array('field'=>'operate','title'=>'操作','align'=>'center','events'=>'window.operateEvents','formatter'=>'operateFormatter'),
  473. );
  474. $this->tableConfig = array('table'=>EmailTpl::shortTableName(),'url'=>$this->createRealUrl(['admin/settings/mail']),'idField'=>EmailTpl::modelPrimaryKey(),'checkbox'=>1,'dropmenu'=>1,'pagination'=>false,'refresh'=>true);
  475. return $this->render('mail',array('config'=>$config,'model'=>new EmailTpl()));
  476. }
  477. //添加邮件模板
  478. public function actionAddmailtpl()
  479. {
  480. $model = new EmailTpl();
  481. if(Yii::$app->request->isAjax&&$model->load(Yii::$app->request->post())){
  482. $exist = EmailTpl::find()->alias("a")->where("a.key='".$model->key."'")->exists();
  483. if($exist)
  484. {
  485. $msgdata = ['error' => 1,'msg' => '已存在相同Key,添加失败'];
  486. echo_json($msgdata);
  487. }
  488. if(!$model->validate())
  489. {
  490. $msgdata = ['error' => 1,'msg' => $model->returnFirstError()];
  491. }
  492. else
  493. {
  494. if($model->save())
  495. {
  496. $msgdata = ['error' => 0,'msg' => '操作成功'];
  497. }
  498. else
  499. {
  500. $msgdata = ['error' => 1,'msg' => '操作失败'];
  501. }
  502. }
  503. echo_json($msgdata);
  504. }
  505. return $this->renderAjax('addmailtpl',array('model'=>$model));
  506. }
  507. //编辑邮箱模板
  508. public function actionEditmailtpl()
  509. {
  510. $id = $this->getKeyId();
  511. $model = EmailTpl::findOne($id);
  512. check_record_exists($model);
  513. if($model->load(Yii::$app->request->post())){
  514. if(!$model->validate())
  515. {
  516. $msgdata = ['error' => 1,'msg' => $model->returnFirstError()];
  517. }
  518. else
  519. {
  520. if($model->save())
  521. {
  522. $msgdata = ['error' => 0,'msg' => '操作成功'];
  523. }
  524. else
  525. {
  526. $msgdata = ['error' => 1,'msg' => '操作失败'];
  527. }
  528. }
  529. echo_json($msgdata);
  530. }
  531. return $this->renderAjax('addmailtpl',array('model'=>$model));
  532. }
  533. //删除邮件模板
  534. public function actionDelmailtpl()
  535. {
  536. $id = $this->getKeyId();
  537. $model = EmailTpl::findOne($id);
  538. check_record_exists($model);
  539. if($model->delete())
  540. {
  541. $msgdata = ['error' => 0,'msg' => '删除成功'];
  542. }
  543. else
  544. {
  545. $msgdata = ['error' => 1,'msg' => '删除失败'];
  546. }
  547. echo_json($msgdata);
  548. }
  549. //测试邮件发送
  550. public function actionSendmail()
  551. {
  552. $id = $this->getKeyId();
  553. $model = EmailTpl::findOne($id);
  554. check_record_exists($model);
  555. $post = Yii::$app->request->post();
  556. if(!empty($post['mailaddress'])){
  557. preg_match_all('/{(.*?)}/i',$model->tpl,$return);
  558. $newArgs = [];
  559. $args = explode("|",$post['args']);
  560. if(is_array($args))foreach($args as $k=>$arg)
  561. {
  562. $newArgs[$return[1][$k]] = $arg;
  563. }
  564. $mailer = new Emailer();
  565. $result = $mailer->send($model->key,$post['mailaddress'],$newArgs);
  566. if($result)
  567. {
  568. $msgdata = ['error' => 0,'msg' => '发送成功'];
  569. }
  570. else
  571. {
  572. $msgdata = ['error' => 1,'msg' => '发送失败'];
  573. }
  574. echo_json($msgdata);
  575. }
  576. return $this->renderAjax('sendmail');
  577. }
  578. //金币设置
  579. public function actionCoin(){
  580. $settings = getSysconfigValue('coin');
  581. $configModel = Config::find()->where("name='coin'")->limit(1)->one();
  582. check_record_exists($configModel);
  583. $config = string2array($configModel->value);
  584. if(Yii::$app->request->post()){
  585. $post = Yii::$app->request->post();
  586. $configModel->value = array2string($post['coin']);
  587. if($configModel->save())
  588. {
  589. $config = $post['coin'];
  590. $this->writeConfigFile($config,'coin');
  591. Yii::$app->session->setFlash('success','操作成功');
  592. }
  593. }
  594. return $this->render('coin',array('config'=>$config,'settings'=>$settings));
  595. }
  596. //积分设置
  597. public function actionPoint(){
  598. $settings = getSysconfigValue('point');
  599. $configModel = Config::find()->where("name='point'")->limit(1)->one();
  600. check_record_exists($configModel);
  601. $config = string2array($configModel->value);
  602. if(Yii::$app->request->post()){
  603. $post = Yii::$app->request->post();
  604. $configModel->value = array2string($post['point']);
  605. if($configModel->save())
  606. {
  607. $config = $post['point'];
  608. $this->writeConfigFile($config,'point');
  609. Yii::$app->session->setFlash('success','操作成功');
  610. }
  611. }
  612. return $this->render('point',array('config'=>$config,'settings'=>$settings));
  613. }
  614. //第三方登录设置
  615. public function actionOpenauth(){
  616. $model = Config::find()->where("name='openauth'")->limit(1)->one();
  617. check_record_exists($model);
  618. $config = string2array($model->value);
  619. if(Yii::$app->request->post()){
  620. $post = Yii::$app->request->post();
  621. if(!empty($post['openauth']['systemConfig']))
  622. {
  623. $post['openauth']['commonAccount'] = $post['openauth']['commonAccount']?$post['openauth']['commonAccount']:0;
  624. $post['openauth']['fastAccount'] = $post['openauth']['fastAccount']?$post['openauth']['fastAccount']:0;
  625. $post['openauth']['fastAccountType'] = $post['openauth']['fastAccountType']?$post['openauth']['fastAccountType']:0;
  626. $tab = 1;
  627. }
  628. if(!empty($post['openauth']['mpConfig']))
  629. {
  630. $post['openauth']['openMpLogin'] = $post['openauth']['openMpLogin']?$post['openauth']['openMpLogin']:0;
  631. $post['openauth']['mpAutoLoginWap'] = $post['openauth']['mpAutoLoginWap']?$post['openauth']['mpAutoLoginWap']:0;
  632. $post['openauth']['openMpSubLogin'] = $post['openauth']['openMpSubLogin']?$post['openauth']['openMpSubLogin']:0;
  633. $tab = 2;
  634. }
  635. if(!empty($post['openauth']['qqConfig']))
  636. {
  637. $post['openauth']['openQqLogin'] = $post['openauth']['openQqLogin']?$post['openauth']['openQqLogin']:0;
  638. $post['openauth']['m_openQqLogin'] = $post['openauth']['m_openQqLogin']?$post['openauth']['m_openQqLogin']:0;
  639. $tab = 3;
  640. }
  641. if(!empty($post['openauth']['dingConfig']))
  642. {
  643. $post['openauth']['dingtalkLogin'] = $post['openauth']['dingtalkLogin']?$post['openauth']['dingtalkLogin']:0;
  644. $post['openauth']['m_dingtalkLogin'] = $post['openauth']['m_dingtalkLogin']?$post['openauth']['m_dingtalkLogin']:0;
  645. $tab = 4;
  646. }
  647. if(!empty($post['openauth']['systemUnion']))
  648. {
  649. $post['openauth']['openUnionId'] = $post['openauth']['openUnionId']?$post['openauth']['openUnionId']:0;
  650. $tab = 5;
  651. }
  652. $newConfig = array_merge($config,$post['openauth']);
  653. $model->value = array2string($newConfig);
  654. if($model->save())
  655. {
  656. $config = $newConfig;
  657. $this->writeConfigFile($newConfig,'openauth');
  658. Yii::$app->session->setFlash('success','操作成功');
  659. //$this->refresh();
  660. }
  661. }
  662. return $this->render('openauth',array('config'=>$config,'tab'=>$tab));
  663. }
  664. }