Message.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use AlibabaCloud\Client\AlibabaCloud;
  6. /**
  7. * ============================================================================
  8. *
  9. * ============================================================================
  10. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  11. * 网站地址: https://www.valimart.net/
  12. * ----------------------------------------------------------------------------
  13. *
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Message extends AdminControl {
  18. public function initialize() {
  19. parent::initialize();
  20. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/message.lang.php');
  21. }
  22. /**
  23. * 邮件设置
  24. */
  25. public function email() {
  26. $config_model = model('config');
  27. if (!(request()->isPost())) {
  28. $list_config = rkcache('config', true);
  29. View::assign('list_config', $list_config);
  30. $this->setAdminCurItem('email');
  31. return View::fetch('email');
  32. } else {
  33. $update_array = array();
  34. $update_array['email_host'] = input('post.email_host');
  35. $update_array['email_secure'] = input('post.email_secure');
  36. $update_array['email_port'] = input('post.email_port');
  37. $update_array['email_addr'] = input('post.email_addr');
  38. $update_array['email_id'] = input('post.email_id');
  39. $update_array['email_pass'] = input('post.email_pass');
  40. $result = $config_model->editConfig($update_array);
  41. if ($result === true) {
  42. $this->log(lang('ds_edit') . lang('email_set'), 1);
  43. $this->success(lang('ds_common_save_succ'));
  44. } else {
  45. $this->log(lang('ds_edit') . lang('email_set'), 0);
  46. $this->error(lang('ds_common_save_fail'));
  47. }
  48. }
  49. }
  50. /**
  51. * 短信平台设置
  52. */
  53. public function mobile() {
  54. $config_model = model('config');
  55. if (!(request()->isPost())) {
  56. $list_config = rkcache('config', true);
  57. $smscf_num = '';
  58. if($list_config['smscf_type']=='wj' && !empty($list_config['smscf_wj_username'])&&!empty($list_config['smscf_wj_key'])){
  59. //如果配置了信息,可以查看具体可用短信条数
  60. $smscf_num = http_request('http://www.smschinese.cn/web_api/SMS/?Action=SMS_Num&Uid='.$list_config['smscf_wj_username'].'&Key='.$list_config['smscf_wj_key'],'get');
  61. }
  62. View::assign('smscf_num', $smscf_num);
  63. View::assign('list_config', $list_config);
  64. $this->setAdminCurItem('mobile');
  65. return View::fetch('mobile');
  66. } else {
  67. $update_array = array();
  68. $update_array['smscf_type'] = input('post.smscf_type');
  69. $update_array['smscf_ali_id'] = input('post.smscf_ali_id');
  70. $update_array['smscf_ali_secret'] = input('post.smscf_ali_secret');
  71. $update_array['smscf_ten_id'] = input('post.smscf_ten_id');
  72. $update_array['smscf_ten_secret'] = input('post.smscf_ten_secret');
  73. $update_array['smscf_sign'] = input('post.smscf_sign');
  74. $update_array['smscf_wj_username'] = input('post.smscf_wj_username');
  75. $update_array['smscf_wj_key'] = input('post.smscf_wj_key');
  76. $update_array['sms_register'] = input('post.sms_register');
  77. $update_array['sms_login'] = input('post.sms_login');
  78. $update_array['sms_password'] = input('post.sms_password');
  79. $result = $config_model->editConfig($update_array);
  80. if ($result === true) {
  81. $this->log(lang('ds_edit') . lang('message_mobile'), 1);
  82. $this->success(lang('ds_common_save_succ'));
  83. } else {
  84. $this->log(lang('ds_edit') . lang('message_mobile'), 0);
  85. $this->error(lang('ds_common_save_fail'));
  86. }
  87. }
  88. }
  89. /**
  90. * 短信发送日志
  91. */
  92. public function smslog()
  93. {
  94. $condition = array();
  95. $add_time_from = input('get.add_time_from');
  96. $add_time_to = input('get.add_time_to');
  97. if (trim($add_time_from) != '') {
  98. $add_time_from = strtotime(trim($add_time_from));
  99. if ($add_time_from !== false) {
  100. $condition[]=array('smslog_smstime','>=', $add_time_from);
  101. }
  102. }
  103. if (trim($add_time_to) != '') {
  104. $add_time_to = strtotime(trim($add_time_to));
  105. if ($add_time_to !== false) {
  106. $add_time_to=$add_time_to+86399;
  107. $condition[]=array('smslog_smstime','<=', $add_time_to);
  108. }
  109. }
  110. $member_name = input('get.member_name');
  111. if(!empty($member_name)){
  112. $condition[]=array('member_name','like',"%" . $member_name . "%");
  113. }
  114. $smslog_phone = input('get.smslog_phone');
  115. if(!empty($smslog_phone)){
  116. $condition[]=array('smslog_phone','like',"%" . $smslog_phone . "%");
  117. }
  118. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  119. $condition[]=array('smslog_state','<>',0);
  120. $smslog_model = model('smslog');
  121. $smslog_list = $smslog_model->getSmsList($condition,10);
  122. View::assign('smslog_list', $smslog_list);
  123. View::assign('show_page', $smslog_model->page_info->render());
  124. $this->setAdminCurItem('smslog');
  125. return View::fetch();
  126. }
  127. /**
  128. * 短信日志删除
  129. */
  130. public function smslog_del(){
  131. $smslog_id = input('param.smslog_id');
  132. $smslog_id_array = ds_delete_param($smslog_id);
  133. if ($smslog_id_array === FALSE) {
  134. ds_json_encode(10001, lang('param_error'));
  135. }
  136. $condition = array();
  137. $smslog_model = model('smslog');
  138. $condition[]=array('smslog_id','in', $smslog_id_array);
  139. $smslog_list = $smslog_model->delSmsLog($condition);
  140. if ($smslog_list) {
  141. ds_json_encode(10000, lang('ds_common_del_succ'));
  142. } else {
  143. ds_json_encode(10001, lang('ds_common_del_fail'));
  144. }
  145. }
  146. /**
  147. * 邮件模板列表
  148. */
  149. public function email_tpl() {
  150. $mailtemplates_model = model('mailtemplates');
  151. $templates_list = $mailtemplates_model->getTplList();
  152. View::assign('templates_list', $templates_list);
  153. $this->setAdminCurItem('email_tpl');
  154. return View::fetch('email_tpl');
  155. }
  156. /**
  157. * 编辑邮件模板
  158. */
  159. public function email_tpl_edit() {
  160. $mailtemplates_model = model('mailtemplates');
  161. if (!request()->isPost()) {
  162. if (!(input('param.code'))) {
  163. $this->error(lang('mailtemplates_edit_code_null'));
  164. }
  165. $templates_array = $mailtemplates_model->getTplInfo(array('mailmt_code' => input('param.code')));
  166. View::assign('templates_array', $templates_array);
  167. $this->setAdminCurItem('email_tpl_edit');
  168. return View::fetch('email_tpl_edit');
  169. } else {
  170. $data = array(
  171. 'code' => input('post.code'),
  172. 'title' => input('post.title'),
  173. 'content' => input('post.content'),
  174. );
  175. $mailtemplatese_validate = ds_validate('mailtemplates');
  176. if (!$mailtemplatese_validate->scene('email_tpl_edit')->check($data)) {
  177. $this->error($mailtemplatese_validate->getError());
  178. } else {
  179. $update_array = array();
  180. $update_array['mailmt_code'] = input('post.code');
  181. $update_array['mailmt_title'] = input('post.title');
  182. $update_array['mailmt_content'] = input('post.content');
  183. $result = $mailtemplates_model->editTpl($update_array, array('mailmt_code' => input('post.code')));
  184. if ($result>=0) {
  185. $this->log(lang('ds_edit') . lang('email_tpl'), 1);
  186. $this->success(lang('mailtemplates_edit_succ'), 'admin/Message/email_tpl');
  187. } else {
  188. $this->log(lang('ds_edit') . lang('email_tpl'), 0);
  189. $this->error(lang('mailtemplates_edit_fail'));
  190. }
  191. }
  192. }
  193. }
  194. /**
  195. * 测试邮件发送
  196. *
  197. * @param
  198. * @return
  199. */
  200. public function email_testing() {
  201. /**
  202. * 读取语言包
  203. */
  204. $email_host = trim(input('post.email_host'));
  205. $email_secure = trim(input('post.email_secure'));
  206. $email_port = trim(input('post.email_port'));
  207. $email_addr = trim(input('post.email_addr'));
  208. $email_id = trim(input('post.email_id'));
  209. $email_pass = trim(input('post.email_pass'));
  210. $email_test = trim(input('post.email_test'));
  211. $subject = lang('test_email');
  212. $site_url = HOME_SITE_URL;
  213. /**
  214. //邮件发送测试
  215. $email_host = 'smtp.126.com';
  216. $email_secure = 'tls';//tls ssl
  217. $email_port = '25';//465 25
  218. $email_addr = '';
  219. $email_id = '';
  220. $email_pass = '';
  221. $email_test = '181814630@qq.com';
  222. */
  223. $site_name = config('ds_config.site_name');
  224. $message = '<p>' . lang('this_is_to') . "<a href='" . $site_url . "' target='_blank'>" . $site_name . '</a>' . lang('test_email_set_ok') . '</p>';
  225. $obj_email = new \sendmsg\Email();
  226. $obj_email->set('email_server', $email_host);
  227. $obj_email->set('email_secure', $email_secure);
  228. $obj_email->set('email_port', $email_port);
  229. $obj_email->set('email_user', $email_id);
  230. $obj_email->set('email_password', $email_pass);
  231. $obj_email->set('email_from', $email_addr);
  232. $obj_email->set('site_name', $site_name);
  233. $result = $obj_email->send($email_test, $subject, $message);
  234. if ($result === false) {
  235. $data['msg'] = lang('test_email_send_fail');
  236. echo json_encode($data);exit;
  237. } else {
  238. $data['msg'] = lang('test_email_send_ok');
  239. echo json_encode($data);exit;
  240. }
  241. }
  242. /**
  243. * 测试手机短信发送
  244. *
  245. * @param
  246. * @return
  247. */
  248. public function mobile_testing() {
  249. $mobile = input('param.mobile_test');
  250. $content = input('param.mobile_test_content');
  251. $smscf_type = input('param.smscf_type');
  252. $smscf_ali_id = input('param.smscf_ali_id');
  253. $smscf_ali_secret = input('param.smscf_ali_secret');
  254. $ali_template_param = input('param.ali_template_param');
  255. $ali_template_code = input('param.ali_template_code');
  256. $ali_template_content = input('param.ali_template_content');
  257. $smscf_ten_id = input('param.smscf_ten_id');
  258. $smscf_ten_secret = input('param.smscf_ten_secret');
  259. $ten_template_param = input('param.ten_template_param');
  260. $ten_template_code = input('param.ten_template_code');
  261. $ten_template_content = input('param.ten_template_content');
  262. $user_id = urlencode(input('param.smscf_wj_username')); // 这里填写用户名
  263. $key = urlencode(input('param.smscf_wj_key')); // 这里填接口安全密钥
  264. $smscf_sign = input('param.smscf_sign');
  265. config('ds_config.smscf_type', $smscf_type);
  266. config('ds_config.smscf_wj_username', $user_id);
  267. config('ds_config.smscf_wj_key', $key);
  268. config('ds_config.smscf_ali_id', $smscf_ali_id);
  269. config('ds_config.smscf_ali_secret', $smscf_ali_secret);
  270. config('ds_config.smscf_ten_id', $smscf_ten_id);
  271. config('ds_config.smscf_ten_secret', $smscf_ten_secret);
  272. config('ds_config.smscf_sign', $smscf_sign);
  273. $smslog_param = array(
  274. 'ali_template_code' => $ali_template_code,
  275. 'ali_template_param' => array(),
  276. 'ten_template_code' => $ten_template_code,
  277. 'ten_template_param' => array(),
  278. );
  279. if ($smscf_type == 'wj') {
  280. $smslog_param['message'] = $content;
  281. } elseif ($smscf_type == 'ali') {
  282. $param = json_decode(htmlspecialchars_decode($ali_template_param), true);
  283. if (!$param) {
  284. echo json_encode(array('msg' => lang('ali_template_param_error')));
  285. exit;
  286. }
  287. $smslog_param['message'] = ds_replace_text(htmlspecialchars_decode($ali_template_content), $param);
  288. $smslog_param['ali_template_param'] = $param;
  289. } elseif ($smscf_type == 'ten') {
  290. $param = json_decode(htmlspecialchars_decode($ten_template_param), true);
  291. if (!$param) {
  292. echo json_encode(array('msg' => lang('ten_template_param_error')));
  293. exit;
  294. }
  295. $smslog_param['message'] = ds_replace_text(htmlspecialchars_decode($ten_template_content), $param);
  296. $smslog_param['ten_template_param'] = $param;
  297. } else {
  298. echo json_encode(array('msg' => lang('param_error')));
  299. exit;
  300. }
  301. $result = model('smslog')->sendSms($mobile, $smslog_param);
  302. if ($result['code'] == 10000) {
  303. $data['msg'] = '测试手机短信发送成功';
  304. } else {
  305. $data['msg'] = $result['message'];
  306. }
  307. echo json_encode($data);
  308. exit;
  309. }
  310. /**
  311. * 商家消息模板
  312. */
  313. public function seller_tpl()
  314. {
  315. $mstpl_list = model('storemsgtpl')->getStoremsgtplList(array());
  316. View::assign('mstpl_list', $mstpl_list);
  317. $this->setAdminCurItem('seller_tpl');
  318. return View::fetch('seller_tpl');
  319. }
  320. /**
  321. * 商家消息模板编辑
  322. */
  323. public function seller_tpl_edit() {
  324. if (!request()->isPost()) {
  325. $code = trim(input('param.code'));
  326. if (empty($code)) {
  327. $this->error(lang('param_error'));
  328. }
  329. $condition = array();
  330. $condition[] = array('storemt_code','=',$code);
  331. $smtpl_info = model('storemsgtpl')->getStoremsgtplInfo($condition);
  332. View::assign('smtpl_info', $smtpl_info);
  333. $this->setAdminCurItem('seller_tpl_edit');
  334. return View::fetch('seller_tpl_edit');
  335. } else {
  336. $code = trim(input('post.code'));
  337. $type = trim(input('post.type'));
  338. if (empty($code) || empty($type)) {
  339. $this->error(lang('param_error'));
  340. }
  341. switch ($type) {
  342. case 'message':
  343. $this->seller_tpl_update_message();
  344. break;
  345. case 'short':
  346. $this->seller_tpl_update_short();
  347. break;
  348. case 'mail':
  349. $this->seller_tpl_update_mail();
  350. break;
  351. case 'weixin':
  352. $this->seller_tpl_update_weixin();
  353. break;
  354. }
  355. }
  356. }
  357. /**
  358. * 商家消息模板更新站内信
  359. */
  360. private function seller_tpl_update_message() {
  361. $message_content = trim(input('post.message_content'));
  362. if (empty($message_content)) {
  363. $this->error(lang('param_error'));
  364. }
  365. // 条件
  366. $condition = array();
  367. $condition[] = array('storemt_code','=',trim(input('post.code')));
  368. // 数据
  369. $update = array();
  370. $update['storemt_message_switch'] = intval(input('post.message_switch'));
  371. $update['storemt_message_content'] = $message_content;
  372. $update['storemt_message_forced'] = intval(input('post.message_forced'));
  373. $result = model('storemsgtpl')->editStoremsgtpl($condition, $update);
  374. $this->seller_tpl_update_showmessage($result);
  375. }
  376. /**
  377. * 商家消息模板更新短消息
  378. */
  379. private function seller_tpl_update_short() {
  380. $short_content = trim(input('post.short_content'));
  381. if (empty($short_content)) {
  382. $this->error(lang('param_error'));
  383. }
  384. // 条件
  385. $condition = array();
  386. $condition[] = array('storemt_code','=',trim(input('post.code')));
  387. // 数据
  388. $update = array();
  389. $update['storemt_short_switch'] = intval(input('post.short_switch'));
  390. $update['storemt_short_content'] = $short_content;
  391. $update['smt_short_forced'] = intval(input('post.short_forced'));
  392. $result = model('storemsgtpl')->editStoremsgtpl($condition, $update);
  393. $this->seller_tpl_update_showmessage($result);
  394. }
  395. /**
  396. * 商家消息模板更新邮件
  397. */
  398. private function seller_tpl_update_mail() {
  399. $mail_subject = trim(input('post.mail_subject'));
  400. $mail_content = trim(input('post.mail_content'));
  401. if ((empty($mail_subject) || empty($mail_content))) {
  402. $this->error(lang('param_error'));
  403. }
  404. // 条件
  405. $condition = array();
  406. $condition[] = array('storemt_code','=',trim(input('post.code')));
  407. // 数据
  408. $update = array();
  409. $update['storemt_mail_switch'] = intval(input('post.mail_switch'));
  410. $update['storemt_mail_subject'] = $mail_subject;
  411. $update['storemt_mail_content'] = $mail_content;
  412. $update['storemt_mail_forced'] = intval(input('post.mail_forced'));
  413. $result = model('storemsgtpl')->editStoremsgtpl($condition, $update);
  414. $this->seller_tpl_update_showmessage($result);
  415. }
  416. /**
  417. * 商家消息模板更新邮件
  418. */
  419. private function seller_tpl_update_weixin() {
  420. $weixin_code = trim(input('post.weixin_code'));
  421. if (empty($weixin_code)) {
  422. $this->error(lang('param_error'));
  423. }
  424. // 条件
  425. $condition = array();
  426. $condition[] = array('storemt_code','=',trim(input('post.code')));
  427. // 数据
  428. $update = array();
  429. $update['storemt_weixin_switch'] = intval(input('post.weixin_switch'));
  430. $update['storemt_weixin_code'] = $weixin_code;
  431. $update['storemt_weixin_forced'] = intval(input('post.weixin_forced'));
  432. $result = model('storemsgtpl')->editStoremsgtpl($condition, $update);
  433. $this->seller_tpl_update_showmessage($result);
  434. }
  435. private function seller_tpl_update_showmessage($result) {
  436. if ($result>=0) {
  437. $this->success(lang('ds_common_op_succ'), (string)url('Message/seller_tpl'));
  438. } else {
  439. $this->error(lang('ds_common_op_fail'));
  440. }
  441. }
  442. /**
  443. * 用户消息模板
  444. */
  445. public function member_tpl() {
  446. $mmtpl_list = model('membermsgtpl')->getMembermsgtplList(array());
  447. View::assign('mmtpl_list', $mmtpl_list);
  448. $this->setAdminCurItem('member_tpl');
  449. return View::fetch('member_tpl');
  450. }
  451. /**
  452. * 用户消息模板编辑
  453. */
  454. public function member_tpl_edit() {
  455. if (!request()->isPost()) {
  456. $code = trim(input('param.code'));
  457. if (empty($code)) {
  458. $this->error(lang('param_error'));
  459. }
  460. $condition = array();
  461. $condition[] = array('membermt_code','=',$code);
  462. $mmtpl_info = model('membermsgtpl')->getMembermsgtplInfo($condition);
  463. View::assign('mmtpl_info', $mmtpl_info);
  464. $this->setAdminCurItem('member_tpl_edit');
  465. return View::fetch('member_tpl_edit');
  466. } else {
  467. $code = trim(input('post.code'));
  468. $type = trim(input('post.type'));
  469. if (empty($code) || empty($type)) {
  470. $this->error(lang('param_error'));
  471. }
  472. switch ($type) {
  473. case 'message':
  474. $this->member_tpl_update_message();
  475. break;
  476. case 'short':
  477. $this->member_tpl_update_short();
  478. break;
  479. case 'mail':
  480. $this->member_tpl_update_mail();
  481. break;
  482. case 'weixin':
  483. $this->member_tpl_update_weixin();
  484. break;
  485. }
  486. }
  487. }
  488. public function ali_tpl(){
  489. $mstpl_list = model('storemsgtpl')->getStoremsgtplList(array());
  490. $mmtpl_list = model('membermsgtpl')->getMembermsgtplList(array());
  491. $mailtemplates_model = model('mailtemplates');
  492. $templates_list = $mailtemplates_model->getTplList(array(array('mailmt_code','<>','bind_email')));
  493. View::assign('mstpl_list',$mstpl_list);
  494. View::assign('mmtpl_list',$mmtpl_list);
  495. View::assign('templates_list',$templates_list);
  496. $this->setAdminCurItem('message_ali_tpl');
  497. return View::fetch();
  498. }
  499. public function ali_tpl_edit(){
  500. $type=input('param.type');
  501. $code=input('param.code');
  502. $name=input('param.name');
  503. switch($type){
  504. case 'membermsgtpl':
  505. if (!model('membermsgtpl')->editMembermsgtpl(array('membermt_code' => $name), array('ali_template_code' => $code))) {
  506. ds_json_encode(10001, lang('ds_common_op_fail'));
  507. } else {
  508. ds_json_encode(10000, lang('ds_common_op_succ'));
  509. }
  510. break;
  511. case 'storemsgtpl':
  512. if (!model('storemsgtpl')->editStoremsgtpl(array('storemt_code' => $name), array('ali_template_code' => $code))) {
  513. ds_json_encode(10001, lang('ds_common_op_fail'));
  514. } else {
  515. ds_json_encode(10000, lang('ds_common_op_succ'));
  516. }
  517. break;
  518. case 'mailmsgtemlates':
  519. if (!model('mailtemplates')->editTpl(array('ali_template_code' => $code), array('mailmt_code' => $name))) {
  520. ds_json_encode(10001, lang('ds_common_op_fail'));
  521. } else {
  522. ds_json_encode(10000, lang('ds_common_op_succ'));
  523. }
  524. break;
  525. default:
  526. ds_json_encode(10001, lang('param_error'));
  527. }
  528. }
  529. public function ali_tpl_query() {
  530. $code = input('param.code');
  531. AlibabaCloud::accessKeyClient(config('ds_config.smscf_ali_id'), config('ds_config.smscf_ali_secret'))
  532. ->regionId('cn-hangzhou')
  533. ->asDefaultClient();
  534. try {
  535. $result = AlibabaCloud::rpc()
  536. ->product('Dysmsapi')
  537. // ->scheme('https') // https | http
  538. ->version('2017-05-25')
  539. ->action('QuerySmsTemplate')
  540. ->method('POST')
  541. ->host('dysmsapi.aliyuncs.com')
  542. ->options([
  543. 'query' => [
  544. 'RegionId' => "cn-hangzhou",
  545. 'TemplateCode' => $code,
  546. ],
  547. ])
  548. ->request();
  549. } catch (\Exception $e) {
  550. ds_json_encode(10001, $e->getErrorMessage());
  551. }
  552. ds_json_encode(10000, lang('ds_common_op_succ'),$result->toArray());
  553. }
  554. public function ten_tpl() {
  555. $mstpl_list = model('storemsgtpl')->getStoremsgtplList(array());
  556. $mmtpl_list = model('membermsgtpl')->getMembermsgtplList(array());
  557. $mailtemplates_model = model('mailtemplates');
  558. $templates_list = $mailtemplates_model->getTplList(array(array('mailmt_code','<>', 'bind_email')));
  559. View::assign('mstpl_list', $mstpl_list);
  560. View::assign('mmtpl_list', $mmtpl_list);
  561. View::assign('templates_list', $templates_list);
  562. $this->setAdminCurItem('message_ten_tpl');
  563. return View::fetch();
  564. }
  565. public function ten_tpl_edit() {
  566. $type = input('param.type');
  567. $code = input('param.code');
  568. $name = input('param.name');
  569. switch ($type) {
  570. case 'membermsgtpl':
  571. if (!model('membermsgtpl')->editMembermsgtpl(array('membermt_code' => $name), array('ten_template_code' => $code))) {
  572. ds_json_encode(10001, lang('ds_common_op_fail'));
  573. } else {
  574. ds_json_encode(10000, lang('ds_common_op_succ'));
  575. }
  576. break;
  577. case 'storemsgtpl':
  578. if (!model('storemsgtpl')->editStoremsgtpl(array('storemt_code' => $name), array('ten_template_code' => $code))) {
  579. ds_json_encode(10001, lang('ds_common_op_fail'));
  580. } else {
  581. ds_json_encode(10000, lang('ds_common_op_succ'));
  582. }
  583. break;
  584. case 'mailmsgtemlates':
  585. if (!model('mailtemplates')->editTpl(array('ten_template_code' => $code), array('mailmt_code' => $name))) {
  586. ds_json_encode(10001, lang('ds_common_op_fail'));
  587. } else {
  588. ds_json_encode(10000, lang('ds_common_op_succ'));
  589. }
  590. break;
  591. default:
  592. ds_json_encode(10001, lang('param_error'));
  593. }
  594. }
  595. //接口
  596. public function ten_tpl_query() {
  597. $code = input('param.code');
  598. // 短信应用 SDK AppID
  599. $appid = config('ds_config.smscf_ten_id'); // SDK AppID 以1400开头
  600. // 短信应用 SDK AppKey
  601. $appkey = config('ds_config.smscf_ten_secret');
  602. try {
  603. $cred = new Credential($appid,$appkey);
  604. $httpProfile = new HttpProfile();
  605. $httpProfile->setEndpoint("sms.tencentcloudapi.com");
  606. $clientProfile = new ClientProfile();
  607. $clientProfile->setHttpProfile($httpProfile);
  608. $client = new SmsClient($cred,"",$clientProfile);
  609. $req = new DescribeSmsTemplateListRequest();
  610. $params = array($code);
  611. $req->fromJsonString($params);
  612. $result = $client->DescribeSmsTemplateList($req);
  613. $rsp = json_decode($result);
  614. } catch (\Exception $e) {
  615. echo var_dump($e);
  616. }
  617. ds_json_encode(10000, lang('ds_common_op_succ'), $rsp->toArray());
  618. }
  619. /**
  620. * 商家消息模板更新站内信
  621. */
  622. private function member_tpl_update_message() {
  623. $message_content = trim(input('post.message_content'));
  624. if (empty($message_content)) {
  625. $this->error(lang('param_error'));
  626. }
  627. // 条件
  628. $condition = array();
  629. $condition[] = array('membermt_code','=',trim(input('post.code')));
  630. // 数据
  631. $update = array();
  632. $update['membermt_message_switch'] = intval(input('post.message_switch'));
  633. $update['membermt_message_content'] = $message_content;
  634. $result = model('membermsgtpl')->editMembermsgtpl($condition, $update);
  635. $this->member_tpl_update_showmessage($result);
  636. }
  637. /**
  638. * 商家消息模板更新短消息
  639. */
  640. private function member_tpl_update_short() {
  641. $short_content = trim(input('post.short_content'));
  642. if (empty($short_content)) {
  643. $this->error(lang('param_error'));
  644. }
  645. // 条件
  646. $condition = array();
  647. $condition[] = array('membermt_code','=',trim(input('post.code')));
  648. // 数据
  649. $update = array();
  650. $update['membermt_short_switch'] = intval(input('post.short_switch'));
  651. $update['membermt_short_content'] = $short_content;
  652. $result = model('membermsgtpl')->editMembermsgtpl($condition, $update);
  653. $this->member_tpl_update_showmessage($result);
  654. }
  655. /**
  656. * 商家消息模板更新邮件
  657. */
  658. private function member_tpl_update_weixin() {
  659. $weixin_code = trim(input('post.weixin_code'));
  660. if (empty($weixin_code)) {
  661. $this->error(lang('param_error'));
  662. }
  663. // 条件
  664. $condition = array();
  665. $condition[] = array('membermt_code','=',trim(input('post.code')));
  666. // 数据
  667. $update = array();
  668. $update['membermt_weixin_switch'] = intval(input('post.weixin_switch'));
  669. $update['membermt_weixin_code'] = $weixin_code;
  670. $result = model('membermsgtpl')->editMembermsgtpl($condition, $update);
  671. $this->member_tpl_update_showmessage($result);
  672. }
  673. /**
  674. * 商家消息模板更新邮件
  675. */
  676. private function member_tpl_update_mail() {
  677. $mail_subject = trim(input('post.mail_subject'));
  678. $mail_content = trim(input('post.mail_content'));
  679. if ((empty($mail_subject) || empty($mail_content))) {
  680. $this->error(lang('param_error'));
  681. }
  682. // 条件
  683. $condition = array();
  684. $condition[] = array('membermt_code','=',trim(input('post.code')));
  685. // 数据
  686. $update = array();
  687. $update['membermt_mail_switch'] = intval(input('post.mail_switch'));
  688. $update['membermt_mail_subject'] = $mail_subject;
  689. $update['membermt_mail_content'] = $mail_content;
  690. $result = model('membermsgtpl')->editMembermsgtpl($condition, $update);
  691. $this->member_tpl_update_showmessage($result);
  692. }
  693. private function member_tpl_update_showmessage($result) {
  694. if ($result>=0) {
  695. $this->success(lang('ds_common_op_succ'), (string)url('Message/member_tpl'));
  696. } else {
  697. $this->error(lang('ds_common_op_fail'));
  698. }
  699. }
  700. /**
  701. * 获取卖家栏目列表,针对控制器下的栏目
  702. */
  703. protected function getAdminItemList() {
  704. $menu_array = array(
  705. array(
  706. 'name' => 'email',
  707. 'text' => lang('email_set'),
  708. 'url' => (string)url('Message/email')
  709. ),
  710. array(
  711. 'name' => 'mobile',
  712. 'text' => lang('message_mobile'),
  713. 'url' => (string)url('Message/mobile')
  714. ),
  715. array(
  716. 'name' => 'smslog',
  717. 'text' => lang('message_smslog'),
  718. 'url' => (string)url('Message/smslog')
  719. ),
  720. array(
  721. 'name' => 'seller_tpl',
  722. 'text' => lang('message_seller_tpl'),
  723. 'url' => (string)url('Message/seller_tpl')
  724. ),
  725. array(
  726. 'name' => 'member_tpl',
  727. 'text' => lang('message_member_tpl'),
  728. 'url' => (string)url('Message/member_tpl')
  729. ),
  730. array(
  731. 'name' => 'email_tpl',
  732. 'text' => lang('message_email_tpl'),
  733. 'url' => (string)url('Message/email_tpl')
  734. ),
  735. );
  736. if(config('ds_config.smscf_type')=='ali'){
  737. array_splice($menu_array, 2, 0, array(array(
  738. 'name' => 'message_ali_tpl',
  739. 'text' => lang('message_ali_tpl'),
  740. 'url' => (string)url('Message/ali_tpl')
  741. )));
  742. }
  743. if (config('ds_config.smscf_type') == 'ten') {
  744. array_splice($menu_array, 2, 0, array(array(
  745. 'name' => 'message_ten_tpl',
  746. 'text' => lang('message_ten_tpl'),
  747. 'url' => (string)url('Message/ten_tpl')
  748. )));
  749. }
  750. if (request()->action() == 'seller_tpl_edit') {
  751. $menu_array[] = array(
  752. 'name' => 'seller_tpl_edit',
  753. 'text' => lang('message_seller_tpl_edit'),
  754. 'url' => "javascript:void(0)"
  755. );
  756. }
  757. if (request()->action() == 'member_tpl_edit') {
  758. $menu_array[] = array(
  759. 'name' => 'member_tpl_edit',
  760. 'text' => lang('message_member_tpl_edit'),
  761. 'url' => "javascript:void(0)"
  762. );
  763. }
  764. if (request()->action() == 'email_tpl_edit') {
  765. $menu_array[] = array(
  766. 'name' => 'email_tpl_edit',
  767. 'text' => lang('message_email_tpl_edit'),
  768. 'url' => "javascript:void(0)"
  769. );
  770. }
  771. return $menu_array;
  772. }
  773. }
  774. ?>