WechatNews.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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 crmeb\basic\BaseController;
  13. use app\common\repositories\wechat\WechatNewsRepository;
  14. use app\validate\admin\WechatNewsValidate;
  15. use think\App;
  16. use think\Request;
  17. /**
  18. * Class WechatNews
  19. * app\controller\admin\wechat
  20. * 微信图文
  21. */
  22. class WechatNews extends BaseController
  23. {
  24. /**
  25. * @var WechatNewsRepository
  26. */
  27. protected $repositories;
  28. /**
  29. * WechatNews constructor.
  30. * @param App $app
  31. * @param WechatNewsRepository $repository
  32. */
  33. public function __construct(App $app, WechatNewsRepository $repository)
  34. {
  35. parent::__construct($app);
  36. $this->repositories = $repository;
  37. }
  38. /**
  39. * 列表
  40. * @return \think\response\Json
  41. * @author Qinii
  42. */
  43. public function lst()
  44. {
  45. [$page, $limit] = $this->getPage();
  46. $where['cate_name'] = $this->request->param('cate_name');
  47. $result = $this->repositories->search($where, $page, $limit);
  48. return app('json')->success($result);
  49. }
  50. /**
  51. * 添加
  52. * @param WechatNewsValidate $validate
  53. * @return mixed
  54. * @author Qinii
  55. */
  56. public function create(WechatNewsValidate $validate)
  57. {
  58. $data = $this->checkParams($validate, true);
  59. $this->repositories->create($data, $this->request->merId(), $this->request->adminId());
  60. return app('json')->success('添加成功');
  61. }
  62. /**
  63. * 编辑
  64. * @param $id
  65. * @param WechatNewsValidate $validate
  66. * @return mixed
  67. * @author Qinii
  68. */
  69. public function update($id, WechatNewsValidate $validate)
  70. {
  71. $data = $this->checkParams($validate);
  72. if (!$this->repositories->merExists($this->request->merId(), $id))
  73. return app('json')->fail('数据不存在');
  74. $this->repositories->update($id, $data, $this->request->merId(), $this->request->adminId());
  75. return app('json')->success('编辑成功');
  76. }
  77. /**
  78. * 删除
  79. * @param $id
  80. * @return mixed
  81. * @author Qinii
  82. */
  83. public function delete($id)
  84. {
  85. if (!$this->repositories->merExists($this->request->merId(), $id))
  86. return app('json')->fail('数据不存在');
  87. $this->repositories->delete($id, $this->request->merId());
  88. return app('json')->success('删除成功');
  89. }
  90. /**
  91. * 详情
  92. * @param $id
  93. * @return mixed
  94. * @author Qinii
  95. */
  96. public function detail($id)
  97. {
  98. if (!$this->repositories->merExists($this->request->merId(), $id))
  99. return app('json')->fail('数据不存在');
  100. return app('json')->success($this->repositories->git($id, $this->request->merId()));
  101. }
  102. /**
  103. * 验证
  104. * @param WechatNewsValidate $validate
  105. * @param bool $isCreate
  106. * @return array
  107. * @author Qinii
  108. */
  109. public function checkParams(WechatNewsValidate $validate)
  110. {
  111. $data = $this->request->params([['status',1], 'data']);
  112. $validate->check($data);
  113. return $data;
  114. }
  115. }