StoreCouponsController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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\store;
  12. use app\Request;
  13. use app\services\activity\coupon\StoreCouponIssueServices;
  14. /**
  15. * 优惠券类
  16. * Class StoreCouponsController
  17. * @package app\api\controller\store
  18. */
  19. class StoreCouponsController
  20. {
  21. protected $services;
  22. public function __construct(StoreCouponIssueServices $services)
  23. {
  24. $this->services = $services;
  25. }
  26. /**
  27. * 可领取优惠券列表
  28. * @param Request $request
  29. * @return mixed
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\DbException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. */
  34. public function lst(Request $request)
  35. {
  36. $where = $request->getMore([
  37. ['type', 0],
  38. ['product_id', 0],
  39. ['num', 0]
  40. ]);
  41. if ($request->getFromType() == 'pc') $where['type'] = -1;
  42. return app('json')->success($this->services->getIssueCouponList($request->uid(), $where)['list']);
  43. }
  44. /**
  45. * 领取优惠券
  46. * @param Request $request
  47. * @return mixed
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\DbException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. */
  52. public function receive(Request $request)
  53. {
  54. list($couponId) = $request->getMore([
  55. ['couponId', 0]
  56. ], true);
  57. if (!$couponId || !is_numeric($couponId)) return app('json')->fail(100100);
  58. /** @var StoreCouponIssueServices $couponIssueService */
  59. $couponIssueService = app()->make(StoreCouponIssueServices::class);
  60. $couponIssueService->issueUserCoupon($couponId, $request->user(), true);
  61. return app('json')->success(410319);
  62. }
  63. /**
  64. * 用户已领取优惠券
  65. * @param Request $request
  66. * @param $types
  67. * @return mixed
  68. */
  69. public function user(Request $request, $types)
  70. {
  71. $uid = (int)$request->uid();
  72. return app('json')->success($this->services->getUserCouponList($uid, $types));
  73. }
  74. /**
  75. * 优惠券 订单获取
  76. * @param Request $request
  77. * @param StoreCouponIssueServices $service
  78. * @param $cartId
  79. * @param $new
  80. * @param $shippingType
  81. * @return mixed
  82. * @throws \Psr\SimpleCache\InvalidArgumentException
  83. * @throws \think\db\exception\DataNotFoundException
  84. * @throws \think\db\exception\DbException
  85. * @throws \think\db\exception\ModelNotFoundException
  86. */
  87. public function order(Request $request, StoreCouponIssueServices $service, $cartId, $new, $shippingType)
  88. {
  89. return app('json')->success($service->beUsableCouponList((int)$request->uid(), $cartId, !!$new, (int)$shippingType));
  90. }
  91. }