Message.php 32 KB

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