Message.php 32 KB

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