Vip.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\PayOrderModel;
  5. use app\common\model\Wallet;
  6. use app\utils\CurlUtil;
  7. use think\Db;
  8. use addons\epay\library\Service;
  9. /**
  10. * 充值配置与充值订单
  11. */
  12. class Vip extends Api
  13. {
  14. protected $noNeedLogin = [];
  15. protected $noNeedRight = ['*'];
  16. // VIP抵扣券
  17. public function coupon()
  18. {
  19. $user_id = $this->auth->id;
  20. $list = Db::name('vip_coupon_user')
  21. ->field(['id','coupon_no','type','name','info','end_time','use_frequency_day','use_frequency_times','status','create_time'])
  22. ->where('user_id',$user_id)
  23. ->whereIn('status',[1,2])
  24. ->order('id desc')
  25. ->autopage()
  26. ->select();
  27. foreach ($list as $key=>$val){
  28. $list[$key]['end_time_text'] = date('Y-m-d H:i',$val['end_time']);
  29. $list[$key]['create_time_text'] = date('Y-m-d H:i',$val['create_time']);
  30. }
  31. $this->success('success', $list);
  32. }
  33. // 使用抵扣券
  34. public function coupon_use()
  35. {
  36. $user_id = $this->auth->id;
  37. $params = $this->request->param();
  38. if (empty($params['coupon_id'])){
  39. $this->error('请选择要使用的抵扣券');
  40. }
  41. $info = Db::name('vip_coupon_user')
  42. ->where('id',$params['coupon_id'])
  43. ->where('user_id',$user_id)
  44. ->whereIn('status',[1,2])
  45. ->find();
  46. if (!$info){
  47. $this->error('不存在的券');
  48. }
  49. if ($info['status'] != 1){
  50. $this->error('券已使用');
  51. }
  52. if (!Db::name('vip_coupon_user')->where(['id'=>$params['coupon_id'],'status'=>1])->update(['status'=>2])){
  53. $this->error('操作失败');
  54. }
  55. $this->error('使用成功');
  56. }
  57. }