CouponCode = model('coupon.Code'); } public function load() { $coupon_no = input('param.coupon_no'); if (empty($coupon_no)) { $this->output(1, '券号不能为空'); } $Coupon = model('Coupon'); $coupon = $Coupon->where(['no' => $coupon_no])->find(); if (!$coupon) { $this->output(1, '未找到券'); } $quantity = input('param.quantity'); $quantity = intval($quantity); if ($quantity <= 0) { $this->output(1, '数量不能小于0'); } $member_id = input('param.userId'); $list = $this->CouponCode->where(['coupon_id' => $coupon['id'], 'state' => 0])->limit($quantity)->select(); if (count($list) < $quantity) { $this->output(1, '券码不足'); } $data = []; $time = $this->request->time(); $domain = $this->request->domain(); foreach ($list as $key => $value) { $data[$key]['id'] = $value['id']; $data[$key]['cname'] = $coupon['cname']; $data[$key]['type'] = $coupon['type']['name']; $data[$key]['no'] = $value['no']; $data[$key]['secret'] = $value['secret']; if (!empty($value['qrcode'])) { $value['qrcode'] = $domain . $value['qrcode']; } $data[$key]['qrcode'] = $value['qrcode']; if (!empty($value['barcode'])) { $value['barcode'] = $domain . $value['barcode']; } $data[$key]['barcode'] = $value['barcode']; $data[$key]['url'] = $value['url']; $data[$key]['state'] = $value['state']; $expire_time = $value['expire_time']; list($startdate, $enddate) = explode('~', $expire_time); $data[$key]['start_time'] = strtotime($startdate); $data[$key]['end_time'] = strtotime($enddate); $this->CouponCode->where(['id' => $value['id']])->update(['state' => 1, 'sale_time' => $time, 'member_id' => $member_id]); } $this->output(0, '加载成功', $data); } public function check() { $coupon_no = input('param.coupon_no'); if (empty($coupon_no)) { $this->output(1, '券号不能为空'); } $Coupon = model('Coupon'); $coupon = $Coupon->where(['no' => $coupon_no])->find(); if (!$coupon) { $this->output(1, '未找到券'); } $quantity = input('param.quantity'); $quantity = intval($quantity); if ($quantity <= 0) { $this->output(1, '数量不能小于0'); } $list = $this->CouponCode->where(['coupon_id' => $coupon['id'], 'state' => 0])->limit($quantity)->select(); if (count($list) < $quantity) { $this->output(1, '券码不足'); } $this->output(0, '券码充足'); } }