| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 | 
							- <?php
 
- namespace app\api\controller\coupon;
 
- use app\api\controller\Api;
 
- /**
 
-  *    券码
 
-  */
 
- class Code extends Api
 
- {
 
-     protected $CouponCode = null;
 
-     protected function init()
 
-     {
 
-         parent::init();
 
-         $this->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, '券码充足');
 
-     }
 
- }
 
 
  |