Message.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\wechat\shop\controller;
  11. use addon\wechat\model\Config;
  12. use app\model\message\Message as MessageModel;
  13. use app\model\message\MessageTemplate as MessageTemplateModel;
  14. /**
  15. * 微信公众号模板消息
  16. */
  17. class Message extends BaseWechat
  18. {
  19. /**
  20. * 编辑模板消息
  21. * @return array|mixed|string
  22. */
  23. public function edit()
  24. {
  25. $message_model = new MessageModel();
  26. $keywords = input("keywords", "");
  27. $info_result = $message_model->getMessageInfo($this->site_id, $keywords);
  28. $info = $info_result["data"];
  29. $wechat_json_array = $info["wechat_json_array"];
  30. if (request()->isAjax()) {
  31. if (empty($info))
  32. return error("", "不存在的模板信息!");
  33. $wechat_is_open = input('wechat_is_open', 0);
  34. $bottomtext = input("bottomtext", "");
  35. $headtext = input("headtext", "");
  36. $bottomtextcolor = input("bottomtextcolor", "");
  37. $headtextcolor = input("headtextcolor", "");
  38. $wechat_json_array['headtext'] = $headtext;//头部标题
  39. $wechat_json_array['headtextcolor'] = $headtextcolor;//头部标题颜色
  40. $wechat_json_array['bottomtext'] = $bottomtext;//尾部描述
  41. $wechat_json_array['bottomtextcolor'] = $bottomtextcolor;//尾部描述颜色
  42. $data = array(
  43. 'wechat_json' => json_encode($wechat_json_array),
  44. );
  45. $condition = array(
  46. ["keywords", "=", $keywords]
  47. );
  48. $template_model = new MessageTemplateModel();
  49. $res = $template_model->editMessageTemplate($data, $condition);
  50. if ($res['code'] == 0) {
  51. $res = $message_model->editMessage(['wechat_is_open' => $wechat_is_open, 'site_id' => $this->site_id, 'keywords' => $keywords], [
  52. ["keywords", "=", $keywords],
  53. ['site_id', '=', $this->site_id],
  54. ]);
  55. }
  56. return $res;
  57. } else {
  58. if (empty($info))
  59. $this->error("不存在的模板信息!");
  60. $this->assign("keywords", $keywords);
  61. $this->assign("info", $wechat_json_array);
  62. $this->assign('wechat_is_open', $info['wechat_is_open']);
  63. return $this->fetch('message/edit');
  64. }
  65. }
  66. /**
  67. * 模板消息设置
  68. * @return array|mixed|\multitype
  69. */
  70. public function config()
  71. {
  72. $message_model = new MessageModel();
  73. if (request()->isAjax()) {
  74. $page = input('page', 1);
  75. $page_size = input('page_size', PAGE_LIST_ROWS);
  76. $condition = array(
  77. ["support_type", "like", '%wechat%'],
  78. );
  79. $list = $message_model->getMessagePageList($condition, $this->site_id, $page, $page_size);
  80. return $list;
  81. } else {
  82. $config_model = new Config();
  83. $config = $config_model->getTemplateMessageConfig($this->site_id);
  84. $this->assign('config', $config['data']['value']);
  85. return $this->fetch('message/config');
  86. }
  87. }
  88. /**
  89. * 微信模板消息状态设置
  90. */
  91. public function setWechatStatus()
  92. {
  93. $message_model = new MessageModel();
  94. if (request()->isAjax()) {
  95. $keywords = input("keywords", "");
  96. $wechat_is_open = input('wechat_is_open', 0);
  97. $res = $message_model->getWechatTemplateNo($keywords, $this->site_id, $wechat_is_open);
  98. return $res;
  99. }
  100. }
  101. /**
  102. * 获取模板编号
  103. */
  104. public function getWechatTemplateNo()
  105. {
  106. if (request()->isAjax()) {
  107. $keywords = input("keywords", "");
  108. $message_model = new MessageModel();
  109. $res = $message_model->getWechatTemplateNo($keywords, $this->site_id, -1);
  110. return $res;
  111. }
  112. }
  113. /**
  114. * @return \addon\wechat\model\multitype
  115. */
  116. public function messageConfig(){
  117. if (request()->isAjax()) {
  118. $is_jump_weapp = input("is_jump_weapp", 0);
  119. $config_model = new Config();
  120. $res = $config_model->setTemplateMessageConfig(['is_jump_weapp' => $is_jump_weapp], 1, $this->site_id);
  121. return $res;
  122. }
  123. }
  124. }