Message.php 32 KB

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