LiveGoods.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. $error = false;
  71. foreach ($goods_info as $goods) {
  72. $this->validate($goods, \app\adminapi\validate\marketing\LiveGoodsValidate::class, 'save');
  73. if (!preg_match('/.*(\.png|\.jpg|\.jpeg|\.gif)$/', $goods['image']) && strpos(strtolower($goods['image']), "phar://") !== false) {
  74. $error = true;
  75. }
  76. }
  77. if ($error) return app('json')->fail(40137);
  78. $this->services->add($goods_info);
  79. return app('json')->success(100000);
  80. }
  81. /**
  82. * 商品详情
  83. * @param $id
  84. * @return mixed
  85. */
  86. public function detail($id)
  87. {
  88. if (!$id) return app('json')->fail(100100);
  89. $goods = $this->services->get($id, ['*'], ['product']);
  90. return app('json')->success($goods ? $goods->toArray() : []);
  91. }
  92. /**
  93. * 同步直播商品
  94. * @return mixed
  95. */
  96. public function syncGoods()
  97. {
  98. $this->services->syncGoodStatus();
  99. return app('json')->success(100038);
  100. }
  101. /**
  102. * 重新提交审核
  103. * @param $id
  104. * @return mixed
  105. * @throws \think\db\exception\DataNotFoundException
  106. * @throws \think\db\exception\DbException
  107. * @throws \think\db\exception\ModelNotFoundException
  108. */
  109. public function audit($id)
  110. {
  111. if (!$id) return app('json')->fail(100100);
  112. $this->services->audit((int)$id);
  113. return app('json')->success(100014);
  114. }
  115. /**
  116. * 撤回审核
  117. * @param $id
  118. * @return mixed
  119. * @throws \think\db\exception\DataNotFoundException
  120. * @throws \think\db\exception\DbException
  121. * @throws \think\db\exception\ModelNotFoundException
  122. */
  123. public function resetAudit($id)
  124. {
  125. if (!$id) return app('json')->fail(100100);
  126. $this->services->resetAudit((int)$id);
  127. return app('json')->success(100014);
  128. }
  129. /**
  130. * 设置状态
  131. * @param int $id
  132. * @param $is_show
  133. * @return mixed
  134. */
  135. public function setShow(int $id, $is_show)
  136. {
  137. if (!$id) return app('json')->fail(100100);
  138. return app('json')->success($this->services->isShow($id, $is_show));
  139. }
  140. /**
  141. * 删除商品
  142. * @param $id
  143. * @return mixed
  144. * @throws \think\db\exception\DataNotFoundException
  145. * @throws \think\db\exception\DbException
  146. * @throws \think\db\exception\ModelNotFoundException
  147. */
  148. public function delete($id)
  149. {
  150. if (!$id) return app('json')->fail(100100);
  151. $this->services->delete($id);
  152. return app('json')->success(100002);
  153. }
  154. }