123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\model\PayOrderModel;
- use app\common\model\Wallet;
- use app\utils\CurlUtil;
- use think\Db;
- use addons\epay\library\Service;
- /**
- * 充值配置与充值订单
- */
- class Vip extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
- // VIP抵扣券
- public function coupon()
- {
- $params = $this->request->param();
- $user_id = $this->auth->id;
- $query = Db::name('vip_coupon_user')
- ->field(['id', 'coupon_no', 'type', 'name', 'info', 'end_time', 'use_frequency_day', 'use_frequency_times', 'status', 'create_time'])
- ->where('user_id', $user_id);
- if (!empty($params['type'])) {
- $query->where('type', $params['type']);
- }
- if (!empty($params['status'])) {
- $params['status'] == 1 && $query->where('status', $params['status'])->where('end_time','>', time());
- $params['status'] == 2 && $query->where('status', $params['status']);
- $params['status'] == 3 && $query->where('status', 1)->where('end_time','<=', time());
- }else{
- $query->whereIn('status', [1, 2]);
- }
- $list = $query->order('id desc')
- ->autopage()
- ->select();
- foreach ($list as $key => $val) {
- $list[$key]['end_time_text'] = date('Y-m-d H:i', $val['end_time']);
- $list[$key]['create_time_text'] = date('Y-m-d H:i', $val['create_time']);
- }
- $this->success('success', $list);
- }
- // 使用抵扣券
- public function coupon_use()
- {
- $user_id = $this->auth->id;
- $params = $this->request->param();
- if (empty($params['coupon_id'])) {
- $this->error('请选择要使用的抵扣券');
- }
- $info = Db::name('vip_coupon_user')
- ->where('id', $params['coupon_id'])
- ->where('user_id', $user_id)
- ->whereIn('status', [1, 2])
- ->find();
- if (!$info) {
- $this->error('不存在的券');
- }
- if ($info['status'] != 1) {
- $this->error('券已使用');
- }
- if (!Db::name('vip_coupon_user')->where(['id' => $params['coupon_id'], 'status' => 1])->update(['status' => 2, 'use_time' => time()])) {
- $this->error('操作失败');
- }
- $this->success('使用成功');
- }
- }
|