You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
3.3 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://doc.hyperf.io
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace App\Controller\v3;
  12. use App\Constants\v3\ErrorCode;
  13. use App\Exception\ErrorCodeException;
  14. use App\Constants\v3\OrderState;
  15. use App\Model\v3\OrderMain;
  16. use App\Request\v3\UserRequest;
  17. use Hyperf\Di\Annotation\Inject;
  18. use App\Controller\BaseController;
  19. use App\Service\v3\Interfaces\CouponRecServiceInterface;
  20. use App\Request\v3\CouponReceiveRequest;
  21. class CouponController extends BaseController
  22. {
  23. /**
  24. * @Inject
  25. * @var CouponRecServiceInterface
  26. */
  27. protected $couponRecService;
  28. /**
  29. * 获取用户可领取优惠卷接口
  30. */
  31. public function getSystemCouponUserList()
  32. {
  33. }
  34. //统计用户
  35. public function userCouponAccount()
  36. {
  37. }
  38. /**
  39. * 用户领取优惠卷
  40. */
  41. public function userReceiveCoupon()
  42. {
  43. }
  44. /**
  45. * 获取用户已经领取的优惠卷列表
  46. */
  47. public function getUserReceiveCouponList()
  48. {
  49. }
  50. /**
  51. * 获取用户当前订单可用的优惠券列表
  52. * 按分类(1订单 等优惠)分组返回
  53. */
  54. public function getListByUser(UserRequest $request)
  55. {
  56. $userId = $this->request->input('user_id');
  57. $page = $this->request->input('page');
  58. $pagesize = $this->request->input('pagesize');
  59. $type = $this->request->input('type','1');
  60. /**
  61. * $type unused 未使用 used 已使用 expired已失效
  62. */
  63. $res['coupon_list'] = $this->couponRecService->getListByUser($userId,$type,$page,$pagesize);
  64. $res['statistics'] = $this->couponRecService->statistics($userId);
  65. return $this->success($res);
  66. }
  67. public function getAvailableListByNewUser()
  68. {
  69. $userId = $this->request->input("user_id", 0);
  70. $receiveType = $this->request->input("receive_type", 0);
  71. $newUserCheck = OrderMain::query()
  72. ->where('user_id',$userId)
  73. ->whereIn('state',OrderState::CAN_DEL)
  74. ->whereIn('state',OrderState::REFUND)
  75. ->exists();
  76. if($newUserCheck){
  77. return $this->success(
  78. [
  79. 'status' => 'error',
  80. 'message' => '不是新用户无法领券',
  81. 'text'=>'关注懒族菜市微信公众号,更多精彩活动一手掌握!'
  82. ]
  83. );
  84. }
  85. $res = $this->couponRecService->getAvailableList($userId,$receiveType);
  86. return $this->success($res);
  87. }
  88. /**
  89. * 用户领取优惠卷
  90. */
  91. public function Receive(CouponReceiveRequest $request)
  92. {
  93. $userId = $this->request->input("user_id", 0);
  94. $receiveType = $this->request->input("receive_type", 0);
  95. $ids = $this->request->input("ids", '');
  96. $res = $this->couponRecService->receive($userId,$receiveType,$ids);
  97. if(!empty($res['success'])){
  98. return $this->success([
  99. 'status' => 'ok',
  100. 'message' => '红包领取成功,请到“我的-红包”中查看']
  101. );
  102. }else{
  103. throw new ErrorCodeException(ErrorCode::COUPON_RECEIVE_FAILURE);
  104. }
  105. }
  106. }