|  | @@ -2,6 +2,7 @@
 | 
	
		
			
				|  |  |  namespace app\common\service;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  use addons\epay\library\Service;
 | 
	
		
			
				|  |  | +use fast\Random;
 | 
	
		
			
				|  |  |  use think\Db;
 | 
	
		
			
				|  |  |  use think\Exception;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -188,7 +189,16 @@ class OrderService
 | 
	
		
			
				|  |  |              $userCarWhere['id'] = $carId;
 | 
	
		
			
				|  |  |              $userCar = Db::name('user_car')->where($userCarWhere)->find();
 | 
	
		
			
				|  |  |              //生成订单
 | 
	
		
			
				|  |  | +            $checkCode[] = Random::alnum(8);
 | 
	
		
			
				|  |  | +            $orderService = new OrderService();//防重复
 | 
	
		
			
				|  |  | +            $checkCodeRes = $orderService->getCheckOrder($checkCode);
 | 
	
		
			
				|  |  | +            if ($checkCodeRes['status']) {
 | 
	
		
			
				|  |  | +                $checkCodeStr = isset($checkCodeRes['data'][0]) ? $checkCodeRes['data'][0] : '';
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                $checkCodeStr = Random::alnum(8);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |              $orderData = [
 | 
	
		
			
				|  |  | +                'check_code'      => $checkCodeStr,
 | 
	
		
			
				|  |  |                  'orderno'         => createUniqueNo('O', $userId),//订单号
 | 
	
		
			
				|  |  |                  'ordertype'       => 3,//类型:1=预约下单,2=在线下单,3=套餐订单
 | 
	
		
			
				|  |  |                  'company_id'      => $companyId,//门店ID
 | 
	
	
		
			
				|  | @@ -269,4 +279,66 @@ class OrderService
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return $result;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 查看是否重复-卡券
 | 
	
		
			
				|  |  | +     * @return void
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public function getCheckCoupons($checkCode=[])
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            if (!empty($checkCode)) {
 | 
	
		
			
				|  |  | +                $where['check_code'] = ['in', $checkCode];
 | 
	
		
			
				|  |  | +                $userCoupons = Db::name('user_coupon')->field('id,check_code')->where($where)->select();
 | 
	
		
			
				|  |  | +                if (!empty($userCoupons)) {
 | 
	
		
			
				|  |  | +                    $checkCodeDbArr = array_column($userCoupons,'check_code');
 | 
	
		
			
				|  |  | +                    foreach ($checkCode as $key => $code) {
 | 
	
		
			
				|  |  | +                        if (in_array($code,$checkCodeDbArr)) {
 | 
	
		
			
				|  |  | +                            $checkCode[$key] = Random::alnum(8);
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    $checkCodeRes = $this->getCheckCoupons($checkCode);
 | 
	
		
			
				|  |  | +                    if ($checkCodeRes['status']) {
 | 
	
		
			
				|  |  | +                        $checkCode = $checkCodeRes['data'];
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $result['data'] = $checkCode;
 | 
	
		
			
				|  |  | +        } catch (Exception $e) {
 | 
	
		
			
				|  |  | +            $result['status'] = 0;
 | 
	
		
			
				|  |  | +            $result['msg'] = $e->getMessage();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return $result;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 查看是否重复-订单
 | 
	
		
			
				|  |  | +     * @return void
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public function getCheckOrder($checkCode=[])
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            if (!empty($checkCode)) {
 | 
	
		
			
				|  |  | +                $where['check_code'] = ['in', $checkCode];
 | 
	
		
			
				|  |  | +                $userCoupons = Db::name('order')->field('id,check_code')->where($where)->select();
 | 
	
		
			
				|  |  | +                if (!empty($userCoupons)) {
 | 
	
		
			
				|  |  | +                    $checkCodeDbArr = array_column($userCoupons,'check_code');
 | 
	
		
			
				|  |  | +                    foreach ($checkCode as $key => $code) {
 | 
	
		
			
				|  |  | +                        if (in_array($code,$checkCodeDbArr)) {
 | 
	
		
			
				|  |  | +                            $checkCode[$key] = Random::alnum(8);
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    $checkCodeRes = $this->getCheckOrder($checkCode);
 | 
	
		
			
				|  |  | +                    if ($checkCodeRes['status']) {
 | 
	
		
			
				|  |  | +                        $checkCode = $checkCodeRes['data'];
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $result['data'] = $checkCode;
 | 
	
		
			
				|  |  | +        } catch (Exception $e) {
 | 
	
		
			
				|  |  | +            $result['status'] = 0;
 | 
	
		
			
				|  |  | +            $result['msg'] = $e->getMessage();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return $result;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |