BroadcastGoods.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020/7/30
  7. *
  8. *
  9. */
  10. namespace app\controller\admin\store;
  11. use app\common\repositories\store\broadcast\BroadcastGoodsRepository;
  12. use crmeb\basic\BaseController;
  13. use think\App;
  14. class BroadcastGoods extends BaseController
  15. {
  16. protected $repository;
  17. public function __construct(App $app, BroadcastGoodsRepository $repository)
  18. {
  19. parent::__construct($app);
  20. $this->repository = $repository;
  21. }
  22. public function lst()
  23. {
  24. [$page, $limit] = $this->getPage();
  25. $where = $this->request->params(['keyword', 'status_tag']);
  26. return app('json')->success($this->repository->adminList($where, $page, $limit));
  27. }
  28. public function detail($id)
  29. {
  30. if (!$this->repository->exists($id))
  31. return app('json')->fail('数据不存在');
  32. return app('json')->success($this->repository->get($id)->append(['product'])->toArray());
  33. }
  34. public function applyForm($id)
  35. {
  36. if (!$this->repository->exists($id))
  37. return app('json')->fail('数据不存在');
  38. return app('json')->success(formToData($this->repository->applyForm($id)));
  39. }
  40. public function apply($id)
  41. {
  42. if (!$this->repository->exists($id))
  43. return app('json')->fail('数据不存在');
  44. [$status, $msg] = $this->request->params(['status', 'msg'], true);
  45. $status = $status == 1 ? 1 : -1;
  46. if ($status == -1 && !$msg)
  47. return app('json')->fail('请输入理由');
  48. $this->repository->apply($id, $status, $msg);
  49. return app('json')->success('操作成功');
  50. }
  51. public function changeStatus($id)
  52. {
  53. $isShow = $this->request->param('is_show') == 1 ? 1 : 0;
  54. if (!$this->repository->exists($id))
  55. return app('json')->fail('数据不存在');
  56. $this->repository->isShow($id, $isShow, true);
  57. return app('json')->success('修改成功');
  58. }
  59. public function sort($id)
  60. {
  61. $sort = (int)$this->request->param('sort');
  62. if (!$this->repository->exists($id))
  63. return app('json')->fail('数据不存在');
  64. $this->repository->change($id, compact('sort'));
  65. return app('json')->success('修改成功');
  66. }
  67. public function delete($id)
  68. {
  69. if (!$this->repository->exists($id))
  70. return app('json')->fail('数据不存在');
  71. $this->repository->delete($id);
  72. return app('json')->success('删除成功');
  73. }
  74. }