BroadcastGoods.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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\store;
  12. use app\common\repositories\store\broadcast\BroadcastGoodsRepository;
  13. use crmeb\basic\BaseController;
  14. use think\App;
  15. /**
  16. * 直播商品
  17. */
  18. class BroadcastGoods extends BaseController
  19. {
  20. protected $repository;
  21. public function __construct(App $app, BroadcastGoodsRepository $repository)
  22. {
  23. parent::__construct($app);
  24. $this->repository = $repository;
  25. }
  26. /**
  27. * 列表
  28. * @return \think\response\Json
  29. * @author Qinii
  30. */
  31. public function lst()
  32. {
  33. [$page, $limit] = $this->getPage();
  34. $where = $this->request->params(['keyword', 'status_tag', 'is_trader', 'mer_valid', 'broadcast_goods_id']);
  35. return app('json')->success($this->repository->adminList($where, $page, $limit));
  36. }
  37. /**
  38. * 详情
  39. * @param $id
  40. * @return \think\response\Json
  41. * @author Qinii
  42. */
  43. public function detail($id)
  44. {
  45. if (!$this->repository->exists($id))
  46. return app('json')->fail('数据不存在');
  47. return app('json')->success($this->repository->get($id)->append(['product'])->toArray());
  48. }
  49. /**
  50. * 申请表单
  51. * @param $id
  52. * @return \think\response\Json
  53. * @author Qinii
  54. */
  55. public function applyForm($id)
  56. {
  57. if (!$this->repository->exists($id))
  58. return app('json')->fail('数据不存在');
  59. return app('json')->success(formToData($this->repository->applyForm($id)));
  60. }
  61. /**
  62. * 申请
  63. * @param $id
  64. * @return \think\response\Json
  65. * @author Qinii
  66. */
  67. public function apply($id)
  68. {
  69. if (!$this->repository->exists($id))
  70. return app('json')->fail('数据不存在');
  71. [$status, $msg] = $this->request->params(['status', 'msg'], true);
  72. $status = $status == 1 ? 1 : -1;
  73. if ($status == -1 && !$msg)
  74. return app('json')->fail('请输入理由');
  75. $this->repository->apply($id, $status, $msg);
  76. return app('json')->success('操作成功');
  77. }
  78. /**
  79. * 显示状态
  80. * @param $id
  81. * @return \think\response\Json
  82. * @author Qinii
  83. */
  84. public function changeStatus($id)
  85. {
  86. $isShow = $this->request->param('is_show') == 1 ? 1 : 0;
  87. if (!$this->repository->exists($id))
  88. return app('json')->fail('数据不存在');
  89. $this->repository->isShow($id, $isShow, true);
  90. return app('json')->success('修改成功');
  91. }
  92. /**
  93. * 排序
  94. * @param $id
  95. * @return \think\response\Json
  96. * @author Qinii
  97. */
  98. public function sort($id)
  99. {
  100. $sort = (int)$this->request->param('sort');
  101. if (!$this->repository->exists($id))
  102. return app('json')->fail('数据不存在');
  103. $this->repository->change($id, compact('sort'));
  104. return app('json')->success('修改成功');
  105. }
  106. /**
  107. * 删除
  108. * @param $id
  109. * @return \think\response\Json
  110. * @author Qinii
  111. */
  112. public function delete($id)
  113. {
  114. if (!$this->repository->exists($id))
  115. return app('json')->fail('数据不存在');
  116. $this->repository->delete($id);
  117. return app('json')->success('删除成功');
  118. }
  119. }