LiveGoods.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\marketing\live;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\activity\live\LiveGoodsServices;
  14. use think\facade\App;
  15. /**
  16. * 直播间商品
  17. * Class LiveGoods
  18. * @package app\controller\admin\store
  19. */
  20. class LiveGoods extends AuthController
  21. {
  22. /**
  23. * LiveGoods constructor.
  24. * @param App $app
  25. * @param LiveGoodsServices $services
  26. */
  27. public function __construct(App $app, LiveGoodsServices $services)
  28. {
  29. parent::__construct($app);
  30. $this->services = $services;
  31. }
  32. /**
  33. * 直播间商品列表
  34. * @return mixed
  35. */
  36. public function list()
  37. {
  38. $where = $this->request->postMore([
  39. ['kerword', ''],
  40. ['status', ''],
  41. ['is_show', ''],
  42. ['live_id', 0]
  43. ]);
  44. return app('json')->success($this->services->getList($where));
  45. }
  46. /**
  47. * 生成直播商品
  48. * @return mixed
  49. */
  50. public function create()
  51. {
  52. [$product_ids] = $this->request->postMore([
  53. ['product_id', []]
  54. ], true);
  55. return app('json')->success($this->services->create($product_ids));
  56. }
  57. /**
  58. * 上传直播商品
  59. * @return mixed
  60. * @throws \EasyWeChat\Core\Exceptions\InvalidArgumentException
  61. * @throws \think\db\exception\DataNotFoundException
  62. * @throws \think\db\exception\DbException
  63. * @throws \think\db\exception\ModelNotFoundException
  64. */
  65. public function add()
  66. {
  67. [$goods_info] = $this->request->postMore([
  68. ['goods_info', []]
  69. ], true);
  70. foreach ($goods_info as $goods) {
  71. $this->validate($goods, \app\adminapi\validate\marketing\LiveGoodsValidate::class, 'save');
  72. }
  73. $this->services->add($goods_info);
  74. return app('json')->success(100000);
  75. }
  76. /**
  77. * 商品详情
  78. * @param $id
  79. * @return mixed
  80. */
  81. public function detail($id)
  82. {
  83. if (!$id) return app('json')->fail(100100);
  84. $goods = $this->services->get($id, ['*'], ['product']);
  85. return app('json')->success($goods ? $goods->toArray() : []);
  86. }
  87. /**
  88. * 同步直播商品
  89. * @return mixed
  90. */
  91. public function syncGoods()
  92. {
  93. $this->services->syncGoodStatus();
  94. return app('json')->success(100038);
  95. }
  96. /**
  97. * 重新提交审核
  98. * @param $id
  99. * @return mixed
  100. * @throws \think\db\exception\DataNotFoundException
  101. * @throws \think\db\exception\DbException
  102. * @throws \think\db\exception\ModelNotFoundException
  103. */
  104. public function audit($id)
  105. {
  106. if (!$id) return app('json')->fail(100100);
  107. $this->services->audit((int)$id);
  108. return app('json')->success(100014);
  109. }
  110. /**
  111. * 撤回审核
  112. * @param $id
  113. * @return mixed
  114. * @throws \think\db\exception\DataNotFoundException
  115. * @throws \think\db\exception\DbException
  116. * @throws \think\db\exception\ModelNotFoundException
  117. */
  118. public function resetAudit($id)
  119. {
  120. if (!$id) return app('json')->fail(100100);
  121. $this->services->resetAudit((int)$id);
  122. return app('json')->success(100014);
  123. }
  124. /**
  125. * 设置状态
  126. * @param int $id
  127. * @param $is_show
  128. * @return mixed
  129. */
  130. public function setShow(int $id, $is_show)
  131. {
  132. if (!$id) return app('json')->fail(100100);
  133. return app('json')->success($this->services->isShow($id, $is_show));
  134. }
  135. /**
  136. * 删除商品
  137. * @param $id
  138. * @return mixed
  139. * @throws \think\db\exception\DataNotFoundException
  140. * @throws \think\db\exception\DbException
  141. * @throws \think\db\exception\ModelNotFoundException
  142. */
  143. public function delete($id)
  144. {
  145. if (!$id) return app('json')->fail(100100);
  146. $this->services->delete($id);
  147. return app('json')->success(100002);
  148. }
  149. }