Message.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\shop\controller;
  11. use app\model\message\Message as MessageModel;
  12. use app\model\order\Config as OrderConfigModel;
  13. use app\model\message\Sms;
  14. use addon\wechat\model\Config as WechatConfig;
  15. use addon\weapp\model\Config as WeappConfig;
  16. use addon\aliapp\model\Config as AliappConfig;
  17. use addon\niusms\model\Config as NiuSmsConfig;
  18. use addon\niusms\model\Sms as NiuSms;
  19. /**
  20. * 消息管理 控制器
  21. */
  22. class Message extends BaseShop
  23. {
  24. /**
  25. * 消息管理 列表
  26. */
  27. public function lists()
  28. {
  29. $message_model = new MessageModel();
  30. //买家消息
  31. $member_message_list_result = $message_model->getMessageList($this->site_id, 1);
  32. $member_message_list = $member_message_list_result[ "data" ];
  33. $this->assign("member_message_list", $member_message_list);
  34. //卖家通知
  35. $shop_message_list_result = $message_model->getMessageList($this->site_id, 2);
  36. $shop_message_list = $shop_message_list_result[ "data" ];
  37. $this->assign("shop_message_list", $shop_message_list);
  38. //核销配置
  39. $config_model = new OrderConfigModel();
  40. $verify_config = $config_model->getOrderVerifyConfig($this->site_id, $this->app_module)[ 'data' ][ 'value' ];
  41. $this->assign('verify_config', $verify_config);
  42. // 公众号配置查询
  43. $wechat_config = ( new WechatConfig() )->getWechatConfig($this->site_id)[ 'data' ][ 'value' ];
  44. $this->assign('wechat_config', $wechat_config);
  45. // 小程序配置查询
  46. $weapp_config = ( new WeappConfig() )->getWeappConfig($this->site_id)[ 'data' ][ 'value' ];
  47. $this->assign('weapp_config', $weapp_config);
  48. // 牛云短信余额查询
  49. if (addon_is_exit('niusms', $this->site_id)) {
  50. $sms_config = ( new NiuSmsConfig() )->getSmsConfig($this->site_id)[ 'data' ];
  51. if ($sms_config[ 'is_use' ]) {
  52. $account_info = ( new NiuSms() )->getChildAccountInfo([
  53. 'username' => $sms_config[ 'value' ][ 'username' ],
  54. ]);
  55. $this->assign('sms_num', $account_info[ 'data' ][ 'balance' ] ?? 0);
  56. }
  57. }
  58. // 支付宝小程序
  59. $aliapp_is_exit = addon_is_exit('aliapp', $this->site_id);
  60. if ($aliapp_is_exit) {
  61. $aliapp_config = ( new AliappConfig() )->getAliappConfig($this->site_id)[ 'data' ][ 'value' ];
  62. $this->assign('aliapp_config', $aliapp_config);
  63. }
  64. $this->assign('aliapp_is_exit', $aliapp_is_exit);
  65. return $this->fetch("message/lists");
  66. }
  67. /**
  68. * 编辑短信模板(跳转)
  69. */
  70. public function editSmsMessage()
  71. {
  72. $keywords = input("keywords", '');
  73. $sms_model = new Sms();
  74. $edit_data_result = $sms_model->doEditSmsMessage();
  75. if (empty($edit_data_result[ "data" ][ 0 ]))
  76. $this->error("没有开启的短信方式!");
  77. $edit_data = $edit_data_result[ "data" ][ 0 ];
  78. $edit_url = $edit_data[ "shop_url" ];
  79. $this->redirect(addon_url($edit_url, [ "keywords" => $keywords ]));
  80. }
  81. /**
  82. * 短信管理
  83. */
  84. public function sms()
  85. {
  86. $sms_model = new Sms();
  87. $list = $sms_model->getSmsType();
  88. if (request()->isAjax()) {
  89. return $list;
  90. } else {
  91. $this->forthMenu();
  92. $list = $list[ 'data' ];
  93. if (count($list) == 1) {
  94. foreach ($list as $k => $v) {
  95. if ($v[ 'sms_type' ] == 'niusms') {
  96. $this->redirect(addon_url("niusms://shop/sms/index"));
  97. }
  98. }
  99. }
  100. return $this->fetch("message/sms");
  101. }
  102. }
  103. /**
  104. * 短信记录
  105. */
  106. public function smsRecords()
  107. {
  108. if (request()->isAjax()) {
  109. $sms_model = new Sms();
  110. $page = input('page', 1);
  111. $page_size = input('page_size', PAGE_LIST_ROWS);
  112. $search_text = input('search_text', '');
  113. $status = input('status', 'all');
  114. $condition = [ [ 'site_id', '=', $this->site_id ] ];
  115. if (!empty($search_text)) {
  116. $condition[] = [ "keywords_name", "like", "%" . $search_text . "%" ];
  117. }
  118. if (!empty($status) && $status != 'all') {
  119. if ($status == -1) {
  120. $condition[] = [ 'status', 'not in', [ 0, 1, '' ] ];
  121. } else {
  122. $condition[] = [ 'status', '=', $status - 1 ];
  123. }
  124. }
  125. $list = $sms_model->getSmsRecordsPageList($condition, $page, $page_size);
  126. return $list;
  127. } else {
  128. $this->forthMenu();
  129. $sms_data = [
  130. 'total_num' => 0,
  131. 'sms_num' => 0,
  132. 'sms_used_num' => 0
  133. ];
  134. $this->assign('sms_data', $sms_data);
  135. return $this->fetch("message/smsrecords");
  136. }
  137. }
  138. /**
  139. * 删除短信记录
  140. */
  141. public function deleteSmsRecords()
  142. {
  143. if (request()->isAjax()) {
  144. $ids = input("ids", "");
  145. $sms_model = new Sms();
  146. $condition = array (
  147. [ "id", "in", $ids ]
  148. );
  149. $result = $sms_model->deleteSmsRecords($condition);
  150. return $result;
  151. }
  152. }
  153. /**
  154. * 编辑短信模板(跳转)
  155. */
  156. public function editEmailMessage()
  157. {
  158. $message_model = new MessageModel();
  159. $keywords = input("keywords", "");
  160. $info_result = $message_model->getMessageInfo($this->site_id, $keywords);
  161. $info = $info_result[ "data" ];
  162. if (request()->isAjax()) {
  163. if (empty($info))
  164. return error(-1, "不存在的模板信息!");
  165. $email_title = input("email_title", '');//邮件标题
  166. $email_content = input("email_content", '');//邮件内容
  167. $email_is_open = input("email_is_open", 0);//邮件开关
  168. $data = array (
  169. 'email_title' => $email_title,
  170. 'email_content' => $email_content,
  171. "email_is_open" => $email_is_open,
  172. );
  173. $condition = array (
  174. [ "keywords", "=", $keywords ],
  175. [ 'site_id', '=', $this->site_id ],
  176. [ 'app_module', '=', $this->app_module ]
  177. );
  178. $this->addLog("编辑邮箱模板:" . $keywords);
  179. $res = $message_model->editMessage($data, $condition);
  180. return $res;
  181. } else {
  182. if (empty($info))
  183. $this->error("不存在的模板信息!");
  184. $email_title = $info[ "email_title" ];//邮件标题
  185. $email_content = $info[ "email_content" ];//邮件内容
  186. $email_is_open = $info[ "email_is_open" ];//邮件开关
  187. $this->assign("email_title", $email_title);
  188. $this->assign("email_content", $email_content);
  189. $this->assign("email_is_open", $email_is_open);
  190. $this->assign("keywords", $keywords);
  191. //模板变量
  192. $message_variable_list = $info[ "message_json_array" ];
  193. $this->assign("message_variable_list", $message_variable_list);
  194. return $this->fetch("message/edit_email_message");
  195. }
  196. }
  197. /**
  198. * 消息通知时间设置
  199. */
  200. public function remindTimeSetting()
  201. {
  202. if (request()->isAjax()) {
  203. $keyword = input('keyword', '');
  204. $hour = input('hour', 24);
  205. $config_model = new OrderConfigModel();
  206. $data = $config_model->getOrderVerifyConfig($this->site_id, $this->app_module)[ 'data' ][ 'value' ];
  207. $data[ $keyword ] = $hour;
  208. return $config_model->setOrderVerifyConfig($data, $this->site_id, $this->app_module);
  209. } else {
  210. return $this->fetch("message/lists");
  211. }
  212. }
  213. }