Vip.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. $params = $this->request->param();
  20. $user_id = $this->auth->id;
  21. $query = Db::name('vip_coupon_user')
  22. ->field(['id','coupon_no','type','name','info','end_time','use_frequency_day','use_frequency_times','status','create_time'])
  23. ->where('user_id',$user_id);
  24. if (!empty($params['type'])){
  25. $query->where('type',$params['type']);
  26. }
  27. $list = $query->whereIn('status',[1,2])
  28. ->order('id desc')
  29. ->autopage()
  30. ->select();
  31. foreach ($list as $key=>$val){
  32. $list[$key]['end_time_text'] = date('Y-m-d H:i',$val['end_time']);
  33. $list[$key]['create_time_text'] = date('Y-m-d H:i',$val['create_time']);
  34. }
  35. $this->success('success', $list);
  36. }
  37. // 使用抵扣券
  38. public function coupon_use()
  39. {
  40. $user_id = $this->auth->id;
  41. $params = $this->request->param();
  42. if (empty($params['coupon_id'])){
  43. $this->error('请选择要使用的抵扣券');
  44. }
  45. $info = Db::name('vip_coupon_user')
  46. ->where('id',$params['coupon_id'])
  47. ->where('user_id',$user_id)
  48. ->whereIn('status',[1,2])
  49. ->find();
  50. if (!$info){
  51. $this->error('不存在的券');
  52. }
  53. if ($info['status'] != 1){
  54. $this->error('券已使用');
  55. }
  56. if (!Db::name('vip_coupon_user')->where(['id'=>$params['coupon_id'],'status'=>1])->update(['status'=>2,'use_time' => time()])){
  57. $this->error('操作失败');
  58. }
  59. $this->error('使用成功');
  60. }
  61. }