Coupon.php 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace addons\shopro\controller\user;
  3. use think\helper\Str;
  4. use addons\shopro\controller\Common;
  5. use app\admin\model\shopro\user\Coupon as UserCouponModel;
  6. class Coupon extends Common
  7. {
  8. protected $noNeedLogin = [];
  9. protected $noNeedRight = ['*'];
  10. public function index()
  11. {
  12. $user = auth_user();
  13. $type = $this->request->param('type', 'can_use'); // 优惠券类型:geted=已领取,can_use=可用,cannot_use=暂不可用,used=已使用,expired=已过期,invalid=已失效(包含已使用和已过期)
  14. $userCoupons = UserCouponModel::with('coupon')->where('user_id', $user->id);
  15. if (in_array($type, ['geted', 'can_use', 'cannot_use', 'used', 'expired', 'invalid'])) {
  16. $userCoupons = $userCoupons->{Str::camel($type)}();
  17. }
  18. $userCoupons = $userCoupons->order('id', 'desc')
  19. // ->paginate($this->request->param('list_rows', 10));
  20. ->autopage()->select();
  21. $this->success('获取成功', $userCoupons);
  22. }
  23. }