Message.php 32 KB

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