TemplateMessage.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\wechat;
  12. use think\App;
  13. use crmeb\basic\BaseController;
  14. use app\validate\admin\TemplateMessageValidate;
  15. use app\common\repositories\wechat\TemplateMessageRepository;
  16. class TemplateMessage extends BaseController
  17. {
  18. /**
  19. * @var TemplateMessageRepository
  20. */
  21. protected $repository;
  22. /**
  23. * TemplateMessage constructor.
  24. * @param App $app
  25. * @param TemplateMessageRepository $repository
  26. */
  27. public function __construct(App $app, TemplateMessageRepository $repository)
  28. {
  29. parent::__construct($app);
  30. $this->repository = $repository;
  31. }
  32. /**
  33. * TODO
  34. * @return mixed
  35. * @author Qinii
  36. * @day 2020-06-18
  37. */
  38. public function lst()
  39. {
  40. [$page,$limit] = $this->getPage();
  41. $where = $this->request->params(['status','keyword']);
  42. $where['type'] = 1;
  43. return app('json')->success($this->repository->getList($where,$page,$limit));
  44. }
  45. /**
  46. * TODO
  47. * @return mixed
  48. * @author Qinii
  49. * @day 2020-06-18
  50. */
  51. public function minList()
  52. {
  53. [$page,$limit] = $this->getPage();
  54. $where = $this->request->params(['status','keyword']);
  55. $where['type'] = 0;
  56. return app('json')->success($this->repository->getList($where,$page,$limit));
  57. }
  58. /**
  59. * TODO
  60. * @return mixed
  61. * @author Qinii
  62. * @day 2020-06-18
  63. */
  64. public function createForm()
  65. {
  66. return app('json')->success(formToData($this->repository->form(null,1)));
  67. }
  68. /**
  69. * TODO
  70. * @param $type
  71. * @return mixed
  72. * @author Qinii
  73. * @day 2020-06-19
  74. */
  75. public function createMinForm()
  76. {
  77. return app('json')->success(formToData($this->repository->form(null,0)));
  78. }
  79. /**
  80. * TODO
  81. * @param TemplateMessageValidate $validate
  82. * @return mixed
  83. * @author Qinii
  84. * @day 2020-06-18
  85. */
  86. public function create(TemplateMessageValidate $validate)
  87. {
  88. $data = $this->chekcParams($validate);
  89. $this->repository->create($data);
  90. return app('json')->success('添加成功');
  91. }
  92. /**
  93. * TODO
  94. * @param $id
  95. * @return mixed
  96. * @author Qinii
  97. * @day 2020-06-18
  98. */
  99. public function updateForm($id)
  100. {
  101. if(!$this->repository->getWhereCount(['template_id' => $id]))
  102. return app('json')->fail('数据不存在');
  103. return app('json')->success(formToData($this->repository->updateForm($id)));
  104. }
  105. /**
  106. * TODO
  107. * @param $id
  108. * @return mixed
  109. * @author Qinii
  110. * @day 2020-06-18
  111. */
  112. public function update($id)
  113. {
  114. $data = $this->request->params(['tempid','status']);
  115. if(!$data['tempid'])
  116. return app('json')->fail('请填写模板ID');
  117. if(!$this->repository->getWhereCount(['template_id' => $id]))
  118. return app('json')->fail('数据不存在');
  119. $this->repository->update($id,$data);
  120. return app('json')->success('编辑成功');
  121. }
  122. /**
  123. * TODO
  124. * @param $id
  125. * @return mixed
  126. * @author Qinii
  127. * @day 2020-06-18
  128. */
  129. public function delete($id)
  130. {
  131. if(!$this->repository->getWhereCount(['template_id' => $id]))
  132. return app('json')->fail('数据不存在');
  133. $this->repository->delete($id);
  134. return app('json')->success('删除成功');
  135. }
  136. /**
  137. * TODO
  138. * @param $id
  139. * @return mixed
  140. * @author Qinii
  141. * @day 2020-06-19
  142. */
  143. public function switchStatus($id)
  144. {
  145. $status = $this->request->param('status',0) == 1 ? 1:0;
  146. if(!$this->repository->getWhereCount(['template_id' => $id]))
  147. return app('json')->fail('数据不存在');
  148. $this->repository->update($id,['status' => $status]);
  149. return app('json')->success('修改成功');
  150. }
  151. /**
  152. * TODO
  153. * @param TemplateMessageValidate $validate
  154. * @return array
  155. * @author Qinii
  156. * @day 2020-06-18
  157. */
  158. public function chekcParams(TemplateMessageValidate $validate)
  159. {
  160. $data = $this->request->params(['tempkey','name','tempid','status','content','type']);
  161. $validate->check($data);
  162. return $data;
  163. }
  164. }