WechatNoticeController.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Author: 芸众商城 www.yunzshop.com
  4. * Date: 2017/11/8
  5. * Time: 上午11:04
  6. */
  7. namespace app\backend\modules\setting\controllers;
  8. use app\common\components\BaseController;
  9. use app\common\helpers\Url;
  10. use app\common\services\notice\WechatApi;
  11. use app\common\models\TemplateMessageDefault;
  12. use app\common\models\notice\MessageTemp;
  13. class WechatNoticeController extends BaseController
  14. {
  15. private $WechatApiModel;
  16. private $list;
  17. private $industry_text;
  18. public function preAction()
  19. {
  20. parent::preAction(); // TODO: Change the autogenerated stub
  21. $this->WechatApiModel = new WechatApi();
  22. $this->list = $this->WechatApiModel->getTmpList();
  23. $this->industry_text = $this->WechatApiModel->getIndustryText($this->WechatApiModel->getIndustry());
  24. }
  25. public function index()
  26. {
  27. if(request()->ajax()){
  28. return $this->successJson('请求成功',[
  29. 'industry_text' => $this->industry_text,
  30. 'list' => $this->list['template_list'],
  31. ]);
  32. }
  33. return view('setting.wechat-notice.wechat_tmp_list');
  34. }
  35. public function returnJson()
  36. {
  37. return $this->successJson('获取公众号模板列表成功', ['tmp_list' => $this->list['template_list']]);
  38. }
  39. public function addTmp()
  40. {
  41. if (!request()->templateidshort) {
  42. return $this->errorJson('请填写模板编码');
  43. }
  44. $ret = $this->WechatApiModel->getTmpByTemplateIdShort(request()->templateidshort);
  45. if ($ret['status'] == 0) {
  46. return $this->errorJson($ret['msg']);
  47. } else {
  48. return $this->successJson($ret['msg'], []);
  49. }
  50. }
  51. public function del()
  52. {
  53. $tmp_id = request()->id;
  54. if (is_array($tmp_id)) {
  55. foreach ($tmp_id as $id) {
  56. $this->WechatApiModel->delTmpByTemplateId($id);
  57. TemplateMessageDefault::delData($id);//删除微信消息模版
  58. MessageTemp::delTempDataByTempId($id);//删除默认消息模版
  59. }
  60. } else {
  61. $this->WechatApiModel->delTmpByTemplateId($tmp_id);
  62. TemplateMessageDefault::delData($tmp_id);//删除消息模版
  63. MessageTemp::delTempDataByTempId($tmp_id);//删除默认消息模版
  64. }
  65. return $this->successJson('删除成功');
  66. }
  67. public function see()
  68. {
  69. $tmp = '';
  70. $list = $this->WechatApiModel->getTmpList();
  71. foreach ($list['template_list'] as $temp) {
  72. while ($temp['template_id'] == request()->tmp_id) {
  73. $tmp = $temp;
  74. break;
  75. }
  76. }
  77. return view('setting.wechat-notice.wechat-see', [
  78. 'template' => $tmp
  79. ])->render();
  80. }
  81. }