WechatNews.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 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. class WechatNews extends BaseController
  18. {
  19. /**
  20. * @var WechatNewsRepository
  21. */
  22. protected $repositories;
  23. /**
  24. * WechatNews constructor.
  25. * @param App $app
  26. * @param WechatNewsRepository $repository
  27. */
  28. public function __construct(App $app,WechatNewsRepository $repository)
  29. {
  30. parent::__construct($app);
  31. $this->repositories = $repository;
  32. }
  33. public function lst()
  34. {
  35. [$page, $limit] = $this->getPage();
  36. $where['cate_name'] = $this->request->param('cate_name');
  37. $result = $this->repositories->search($where, $page, $limit);
  38. return app('json')->success($result);
  39. }
  40. /**
  41. * 添加
  42. * @param WechatNewsValidate $validate
  43. * @return mixed
  44. * @author Qinii
  45. */
  46. public function create(WechatNewsValidate $validate)
  47. {
  48. $data =$this->checkParams($validate,true);
  49. $this->repositories->create($data,$this->request->merId(),$this->request->adminId());
  50. return app('json')->success('添加成功');
  51. }
  52. /**
  53. * 编辑
  54. * @param $id
  55. * @param WechatNewsValidate $validate
  56. * @return mixed
  57. * @author Qinii
  58. */
  59. public function update($id,WechatNewsValidate $validate)
  60. {
  61. $data =$this->checkParams($validate);
  62. if (!$this->repositories->merExists($this->request->merId(),$id))
  63. return app('json')->fail('数据不存在');
  64. $this->repositories->update($id,$data,$this->request->merId(),$this->request->adminId());
  65. return app('json')->success('编辑成功');
  66. }
  67. public function delete($id)
  68. {
  69. if (!$this->repositories->merExists($this->request->merId(),$id))
  70. return app('json')->fail('数据不存在');
  71. $this->repositories->delete($id,$this->request->merId());
  72. return app('json')->success('删除成功');
  73. }
  74. public function detail($id)
  75. {
  76. if (!$this->repositories->merExists($this->request->merId(),$id))
  77. return app('json')->fail('数据不存在');
  78. return app('json')->success($this->repositories->git($id,$this->request->merId()));
  79. }
  80. /**
  81. * 验证
  82. * @param WechatNewsValidate $validate
  83. * @param bool $isCreate
  84. * @return array
  85. * @author Qinii
  86. */
  87. public function checkParams(WechatNewsValidate $validate)
  88. {
  89. $data = $this->request->params(['status','data']);
  90. $validate->check($data);
  91. return $data;
  92. }
  93. }