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.

109 lines
3.1 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 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;
  12. use App\Model\CouponUserRecType;
  13. use App\Model\Coupon;
  14. use App\Model\CouponRec;
  15. use Hyperf\DbConnection\Db;
  16. class CouponController extends BaseController
  17. {
  18. /**
  19. * 获取用户可领取优惠卷接口
  20. */
  21. public function getSystemCouponUserList(){
  22. $user_id = $this->request->input('user_id');
  23. $receive_type = $this->request->input('receive_type');
  24. $c_ids = CouponUserRecType::where('receive_type',$receive_type)->pluck('system_coupon_user_id');
  25. $nowTime = time();
  26. $cr_ids = CouponRec::where('user_id',$user_id)->pluck('system_coupon_user_id');
  27. $ids = array_merge($c_ids->toArray(),$cr_ids->toArray());
  28. $ids = collect($ids)->unique();
  29. $c = Coupon::where('start_time','<=',$nowTime)
  30. ->where('end_time','>',$nowTime)
  31. ->whereRaw('inventory_use < inventory')
  32. ->whereIn('id',$ids)
  33. ->orderBy('weigh','desc')
  34. ->limit(4)
  35. ->get();
  36. return $this->success(['not_reveive'=>$c]);
  37. }
  38. public function userCouponAccount()
  39. {
  40. $user_id = $this->request->input('user_id');
  41. $nowTime = time();
  42. $userCouponCount = DB::table('ims_system_coupon_user_receive')
  43. ->leftJoin('ims_system_coupon_user', 'ims_system_coupon_user_receive.system_coupon_user_id', '=', 'ims_system_coupon_user.id')
  44. ->count();
  45. // $userCouponCount = CouponRec::with('coupon')->where('user_id',$user_id)->where('usable_start_time','<=',$nowTime)
  46. // ->where('usable_end_time','>',$nowTime)->count();
  47. return $this->success(['total'=>$userCouponCount]);
  48. }
  49. /**
  50. * 获取用户当前订单可用的优惠券列表
  51. * 按分类(1订单 等优惠)分组返回
  52. */
  53. public function getUserAvailableCoupons()
  54. {
  55. $userId = $this->request->input("user_id");
  56. $receiveType = $this->request->input("receive_type");
  57. $ids = $this->request->input("ids");
  58. }
  59. /**
  60. * 获取用户已经领取的优惠卷列表
  61. */
  62. public function getUserReceiveCouponList()
  63. {
  64. $userId = $this->request->input("user_id");
  65. $nowTime = time();
  66. $couponIds = CouponRec::where('user_id',$userId)
  67. ->whereIn('status',[0,1])
  68. ->orderBy('receive_time','desc')
  69. ->get()
  70. ->pluck('system_coupon_user_id');
  71. $not_expired = [];
  72. $expired = [];
  73. $couponIds = $couponIds->toArray();
  74. $coupons = Coupon::orderByRaw('FIELD(id, '.implode(", " , $couponIds).')')->get();
  75. foreach ($coupons as $key => $coupon) {
  76. if($coupon->usable_end_time < $nowTime){
  77. $expired[] = $coupon;
  78. }else{
  79. $not_expired[] = $coupon;
  80. }
  81. }
  82. $ret = ['not_expired'=>$not_expired,'expired'=>$expired];
  83. return $this->success($ret);
  84. }
  85. }