CouponsApi.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace app\ebapi\controller;
  3. use app\ebapi\model\store\StoreCouponIssue;
  4. use app\ebapi\model\store\StoreCouponUser;
  5. use service\JsonService;
  6. /**
  7. * 小程序优惠券api接口
  8. * Class CouponsApi
  9. * @package app\ebapi\controller
  10. *
  11. */
  12. class CouponsApi extends AuthController
  13. {
  14. /**
  15. * 获取用户优惠券
  16. * @return \think\response\Json
  17. */
  18. public function get_use_coupons($types='')
  19. {
  20. switch ($types){
  21. case 0:case '':
  22. $list= StoreCouponUser::getUserAllCoupon($this->userInfo['uid']);
  23. break;
  24. case 1:
  25. $list=StoreCouponUser::getUserValidCoupon($this->userInfo['uid']);
  26. break;
  27. case 2:
  28. $list=StoreCouponUser::getUserAlreadyUsedCoupon($this->userInfo['uid']);
  29. break;
  30. default:
  31. $list=StoreCouponUser::getUserBeOverdueCoupon($this->userInfo['uid']);
  32. break;
  33. }
  34. foreach ($list as &$v){
  35. $v['add_time'] = date('Y/m/d',$v['add_time']);
  36. $v['end_time'] = date('Y/m/d',$v['end_time']);
  37. }
  38. return JsonService::successful($list);
  39. }
  40. /**
  41. * 获取用户优惠券
  42. * @return \think\response\Json
  43. */
  44. public function get_use_coupon(){
  45. return JsonService::successful('',StoreCouponUser::getUserAllCoupon($this->userInfo['uid']));
  46. }
  47. /**
  48. * 获取可以使用的优惠券
  49. * @param int $totalPrice
  50. * @return \think\response\Json
  51. */
  52. public function get_use_coupon_order($totalPrice = 0)
  53. {
  54. return JsonService::successful(StoreCouponUser::beUsableCouponList($this->userInfo['uid'],$totalPrice));
  55. }
  56. /**
  57. * 领取优惠券
  58. * @param string $couponId
  59. * @return \think\response\Json
  60. */
  61. public function user_get_coupon($couponId = '')
  62. {
  63. if(!$couponId || !is_numeric($couponId)) return JsonService::fail('参数错误!');
  64. if(StoreCouponIssue::issueUserCoupon($couponId,$this->userInfo['uid'])){
  65. return JsonService::successful('领取成功');
  66. }else{
  67. return JsonService::fail(StoreCouponIssue::getErrorInfo('领取失败!'));
  68. }
  69. }
  70. /**
  71. * 获取一条优惠券
  72. * @param int $couponId
  73. * @return \think\response\Json
  74. */
  75. public function get_coupon_rope($couponId = 0){
  76. if(!$couponId) return JsonService::fail('参数错误');
  77. $couponUser = StoreCouponUser::validAddressWhere()->where('id',$couponId)->where('uid',$this->userInfo['uid'])->find();
  78. return JsonService::successful($couponUser);
  79. }
  80. /**
  81. * 获取 可以领取的优惠券
  82. * @param int $limit
  83. * @return \think\response\Json
  84. */
  85. public function get_issue_coupon_list($limit = 2,$page=0)
  86. {
  87. return JsonService::successful(StoreCouponIssue::getIssueCouponList($this->uid,$limit,$page));
  88. }
  89. }