StoreBargainController.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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\api\controller\v1\activity;
  12. use app\services\activity\bargain\StoreBargainServices;
  13. use app\services\activity\bargain\StoreBargainUserHelpServices;
  14. use app\services\activity\bargain\StoreBargainUserServices;
  15. use app\Request;
  16. use app\services\user\UserServices;
  17. /**
  18. * 砍价商品类
  19. * Class StoreBargainController
  20. * @package app\api\controller\activity
  21. */
  22. class StoreBargainController
  23. {
  24. protected $services;
  25. public function __construct(StoreBargainServices $services)
  26. {
  27. $this->services = $services;
  28. }
  29. /**
  30. * 砍价列表顶部图
  31. * @return mixed
  32. */
  33. public function config()
  34. {
  35. $lovely = sys_data('routine_lovely') ?? [];//banner图
  36. $info = $lovely[2] ?? [];
  37. return app('json')->success($info);
  38. }
  39. /**
  40. * 砍价商品列表
  41. * @param Request $request
  42. * @return mixed
  43. */
  44. public function lst(Request $request)
  45. {
  46. $bargainList = $this->services->getBargainList();
  47. return app('json')->success(get_thumb_water($bargainList));
  48. }
  49. /**
  50. * 砍价详情和当前登录人信息
  51. * @param Request $request
  52. * @param $id
  53. * @return mixed
  54. * @throws \think\db\exception\DataNotFoundException
  55. * @throws \think\db\exception\DbException
  56. * @throws \think\db\exception\ModelNotFoundException
  57. */
  58. public function detail(Request $request, $id)
  59. {
  60. list($bargainUid) = $request->getMore([
  61. ['bargainUid', 0]
  62. ], true);
  63. $data = $this->services->getBargain($request, $id, (int)$bargainUid);
  64. return app('json')->success($data);
  65. }
  66. /**
  67. * 砍价 观看/分享/参与次数
  68. * @param Request $request
  69. * @return mixed
  70. */
  71. public function share(Request $request)
  72. {
  73. /** @var StoreBargainUserHelpServices $bargainUserHelpService */
  74. $bargainUserHelpService = app()->make(StoreBargainUserHelpServices::class);
  75. list($bargainId) = $request->postMore([['bargainId', 0]], true);
  76. $data['lookCount'] = $this->services->sum([], 'look');//TODO 观看人数
  77. $data['userCount'] = $bargainUserHelpService->count([]);//TODO 参与人数
  78. if (!$bargainId) return app('json')->success($data);
  79. $this->services->addBargain($bargainId, 'share');
  80. $data['shareCount'] = $this->services->sum([], 'share');//TODO 分享人数
  81. return app('json')->success($data);
  82. }
  83. /**
  84. * 砍价开启
  85. * @param Request $request
  86. * @return mixed
  87. * @throws \think\db\exception\DataNotFoundException
  88. * @throws \think\db\exception\DbException
  89. * @throws \think\db\exception\ModelNotFoundException
  90. */
  91. public function start(Request $request)
  92. {
  93. list($bargainId) = $request->postMore([
  94. ['bargainId', 0]
  95. ], true);
  96. return app('json')->success($this->services->setBargain($request->uid(), $bargainId));
  97. }
  98. /**
  99. * 砍价 帮助好友砍价
  100. * @param Request $request
  101. * @return mixed
  102. * @throws \think\db\exception\DataNotFoundException
  103. * @throws \think\db\exception\DbException
  104. * @throws \think\db\exception\ModelNotFoundException
  105. */
  106. public function help(Request $request)
  107. {
  108. list($bargainId, $bargainUserUid) = $request->postMore([
  109. ['bargainId', 0],
  110. ['bargainUserUid', 0]
  111. ], true);
  112. return app('json')->success($this->services->setHelpBargain($request->uid(), $bargainId, $bargainUserUid));
  113. }
  114. /**
  115. * 砍价 砍价帮
  116. * @param Request $request
  117. * @return mixed
  118. */
  119. public function help_list(Request $request)
  120. {
  121. list($bargainId, $bargainUserUid) = $request->postMore([
  122. ['bargainId', 0],
  123. ['bargainUserUid', 0],
  124. ], true);
  125. /** @var StoreBargainUserServices $bargainUser */
  126. $bargainUser = app()->make(StoreBargainUserServices::class);
  127. $bargainUserTableId = $bargainUser->getBargainUserTableId($bargainId, $bargainUserUid);
  128. /** @var StoreBargainUserHelpServices $bargainUserHelp */
  129. $bargainUserHelp = app()->make(StoreBargainUserHelpServices::class);
  130. [$page, $limit] = $this->services->getPageValue();
  131. $storeBargainUserHelp = $bargainUserHelp->getHelpList($bargainUserTableId, $page, $limit);
  132. return app('json')->success($storeBargainUserHelp);
  133. }
  134. /**
  135. * 砍价 开启砍价用户信息
  136. * @param Request $request
  137. * @return mixed
  138. */
  139. public function start_user(Request $request)
  140. {
  141. list($bargainId, $bargainUserUid) = $request->postMore([
  142. ['bargainId', 0],
  143. ['bargainUserUid', 0],
  144. ], true);
  145. if (!$bargainId || !$bargainUserUid) return app('json')->fail(100100);
  146. /** @var UserServices $userServices */
  147. $userServices = app()->make(UserServices::class);
  148. $userInfo = $userServices->getUserInfo((int)$bargainUserUid);
  149. if (!$userInfo) {
  150. return app('json')->fail(410044);
  151. }
  152. return app('json')->success(['nickname' => $userInfo['nickname'], 'avatar' => $userInfo['avatar']]);
  153. }
  154. /**
  155. * 砍价列表(已参与)
  156. * @param Request $request
  157. * @return mixed
  158. */
  159. public function user_list(Request $request)
  160. {
  161. $uid = $request->uid();
  162. /** @var StoreBargainUserServices $bargainUser */
  163. $bargainUser = app()->make(StoreBargainUserServices::class);
  164. $bargainUser->editBargainUserStatus($uid);// TODO 判断过期砍价活动
  165. $list = $bargainUser->getBargainUserAll($uid);
  166. if (count($list)) return app('json')->success(get_thumb_water($list));
  167. else return app('json')->success([]);
  168. }
  169. /**
  170. * 砍价取消
  171. * @param Request $request
  172. * @return mixed
  173. */
  174. public function user_cancel(Request $request)
  175. {
  176. list($bargainId) = $request->postMore([['bargainId', 0]], true);
  177. if (!$bargainId) return app('json')->fail(100100);
  178. /** @var StoreBargainUserServices $bargainUser */
  179. $bargainUser = app()->make(StoreBargainUserServices::class);
  180. $res = $bargainUser->cancelBargain($bargainId, $request->uid());
  181. if ($res) return app('json')->success(100019);
  182. else return app('json')->success(100020);
  183. }
  184. /**
  185. * 砍价海报
  186. * @param Request $request
  187. * @return mixed
  188. * @throws \think\db\exception\DataNotFoundException
  189. * @throws \think\db\exception\DbException
  190. * @throws \think\db\exception\ModelNotFoundException
  191. */
  192. public function poster(Request $request)
  193. {
  194. [$bargainId, $from] = $request->postMore([
  195. ['bargainId', ''],
  196. ['from', 'wechat']
  197. ], true);
  198. $posterUrl = $this->services->poster($bargainId, $request->user(), $from);
  199. if ($posterUrl) {
  200. return app('json')->success(['url' => $posterUrl]);
  201. } else {
  202. return app('json')->fail(410172);
  203. }
  204. }
  205. /**
  206. * 获取分享海报信息
  207. * @param Request $request
  208. * @return mixed
  209. * @throws \think\db\exception\DataNotFoundException
  210. * @throws \think\db\exception\DbException
  211. * @throws \think\db\exception\ModelNotFoundException
  212. */
  213. public function posterInfo(Request $request, $bargainId)
  214. {
  215. return app('json')->success($this->services->posterInfo((int)$bargainId, $request->user()));
  216. }
  217. }