Kaynağa Gözat

修改订单

jun 4 ay önce
ebeveyn
işleme
a8d5d889ed
1 değiştirilmiş dosya ile 575 ekleme ve 575 silme
  1. 575 575
      app/Http/Controllers/Admin/Orders.php

+ 575 - 575
app/Http/Controllers/Admin/Orders.php

@@ -28,53 +28,53 @@ use Intervention\Image\Gd\Font;
  *
  */
 class Orders extends Auth{
-	
-	protected function _initialize(){
-		parent::_initialize();
-		$this->assign('breadcrumb1','销售管理');
-		$this->assign('breadcrumb2','订单管理');
-	}
 
-	/**
-	 * 首页列表
-	 * 
-	 * */
+    protected function _initialize(){
+        parent::_initialize();
+        $this->assign('breadcrumb1','销售管理');
+        $this->assign('breadcrumb2','订单管理');
+    }
+
+    /**
+     * 首页列表
+     *
+     * */
     public function index(Model $Model,OrdersProduct $OrdersProduct,Product $Product,Custom $Custom,Business $Business){
-		// 接受参数
-		$code					= request('order_code','');
-		$orders_other			= request('orders_other',0);
-		$productCode			= request('product_code','');
-		$phone					= request('phone','');
-		$customCode				= request('custom_code','');
-		$productName			= request('product_name','');
-		$province				= request('contact_province','');
-		$city					= request('contact_city','');
-		$area					= request('contact_area','');
-		$status					= request('status',0);
-		$startTime				= request('start_time','');
-		$endTime				= request('end_time','');
-		$is_regiment			= request('is_regiment','');
+        // 接受参数
+        $code					= request('order_code','');
+        $orders_other			= request('orders_other',0);
+        $productCode			= request('product_code','');
+        $phone					= request('phone','');
+        $customCode				= request('custom_code','');
+        $productName			= request('product_name','');
+        $province				= request('contact_province','');
+        $city					= request('contact_city','');
+        $area					= request('contact_area','');
+        $status					= request('status',0);
+        $startTime				= request('start_time','');
+        $endTime				= request('end_time','');
+        $is_regiment			= request('is_regiment','');
         $businessId				= request('business_id','');
-		// 编码转ID
-		$id						= $code ? $Model->codeToId($code) : 0;
-		$productId				= $productCode ? $Product->codeToId($productCode) : 0;
-		$uid					= $customCode ? $Custom->codeToId($customCode) : 0;
-		// 查询条件
-		$map 					= [];
-		// 编码ID
-		if( $id )				$map[] = ['orders_product.order_id','=',$id];
-		// 编码ID
-		if( $orders_other )		$map[] = $orders_other == 1 ? ['orders_product.product_id','>',0] : ['orders_product.product_id','=',0];
-		if( $uid )				$map[] = ['custom.uid','=',$uid];
-		if( $productId )		$map[] = ['orders_product.product_id','=',$productId];
-		if( $productName )		$map[] = ['orders_product.product_name','LIKE','%'.$productName.'%'];
-		if( $phone )			$map[] = ['orders_addr.contact_phone','=',$phone];
-		if( $province )			$map[] = ['orders_addr.contact_province','LIKE','%'.$province.'%'];
-		if( $city )				$map[] = ['orders_addr.contact_city','LIKE','%'.$city.'%'];
-		if( $area )				$map[] = ['orders_addr.contact_area','LIKE','%'.$area.'%'];
-		if( $startTime )		$map[] = ['orders_product.insert_time','>=',strtotime($startTime)];
-		if( $endTime )			$map[] = ['orders_product.insert_time','<=',strtotime($endTime)];
-		if( $status )			$map[] = ['orders_product.status','=',$status];
+        // 编码转ID
+        $id						= $code ? $Model->codeToId($code) : 0;
+        $productId				= $productCode ? $Product->codeToId($productCode) : 0;
+        $uid					= $customCode ? $Custom->codeToId($customCode) : 0;
+        // 查询条件
+        $map 					= [];
+        // 编码ID
+        if( $id )				$map[] = ['orders_product.order_id','=',$id];
+        // 编码ID
+        if( $orders_other )		$map[] = $orders_other == 1 ? ['orders_product.product_id','>',0] : ['orders_product.product_id','=',0];
+        if( $uid )				$map[] = ['custom.uid','=',$uid];
+        if( $productId )		$map[] = ['orders_product.product_id','=',$productId];
+        if( $productName )		$map[] = ['orders_product.product_name','LIKE','%'.$productName.'%'];
+        if( $phone )			$map[] = ['orders_addr.contact_phone','=',$phone];
+        if( $province )			$map[] = ['orders_addr.contact_province','LIKE','%'.$province.'%'];
+        if( $city )				$map[] = ['orders_addr.contact_city','LIKE','%'.$city.'%'];
+        if( $area )				$map[] = ['orders_addr.contact_area','LIKE','%'.$area.'%'];
+        if( $startTime )		$map[] = ['orders_product.insert_time','>=',strtotime($startTime)];
+        if( $endTime )			$map[] = ['orders_product.insert_time','<=',strtotime($endTime)];
+        if( $status )			$map[] = ['orders_product.status','=',$status];
         if( $businessId )		$map[] = ['orders_product.business_id','=',$id];
         if($is_regiment){
             if( $is_regiment == 1)		$map[] = ['orders.regiment_id','>',0];
@@ -90,329 +90,329 @@ class Orders extends Auth{
                 $shopIds       = $Business::query()->where('leader_uid',$session['admin_uid'])->pluck('id')->toArray();
             }
         }
-		// 查询数据
-		$list					= $OrdersProduct->query()
-									->join('custom','orders_product.custom_uid','=','custom.uid')
-									->join('orders_addr','orders_addr.order_id','=','orders_product.order_id')
-									->leftJoin('orders','orders.id','=','orders_product.order_id');
+        // 查询数据
+        $list					= $OrdersProduct->query()
+            ->join('custom','orders_product.custom_uid','=','custom.uid')
+            ->join('orders_addr','orders_addr.order_id','=','orders_product.order_id')
+            ->leftJoin('orders','orders.id','=','orders_product.order_id');
         if (isset($shopIds))    $list   =   $list->whereIn('orders_product.business_id',$shopIds);
         $list                   = $list->where($map)
-									->orderByDesc('id')
-									->select([
-										'orders_product.*','custom.username as custom_name','orders.regiment_id as regiment_id',
-										'orders_addr.contact_name','orders_addr.contact_shop','orders_addr.contact_phone','orders_addr.contact_province','orders_addr.contact_city','orders_addr.contact_area','orders_addr.contact_addr'
-									])
-									->paginate(request('limit',config('page_num',10)))->appends(request()->all());
-		// 循环处理数据
-		foreach ($list as $key => $value) {
-			// id转编号
-			$value['order_code']	= $Model->idToCode($value['order_id']);
-			$value['custom_code']	= $Custom->idToCode($value['custom_uid']);
-			$value['state']			= $Model->getState($value['status'],'state');
+            ->orderByDesc('id')
+            ->select([
+                'orders_product.*','custom.username as custom_name','orders.regiment_id as regiment_id',
+                'orders_addr.contact_name','orders_addr.contact_shop','orders_addr.contact_phone','orders_addr.contact_province','orders_addr.contact_city','orders_addr.contact_area','orders_addr.contact_addr'
+            ])
+            ->paginate(request('limit',config('page_num',10)))->appends(request()->all());
+        // 循环处理数据
+        foreach ($list as $key => $value) {
+            // id转编号
+            $value['order_code']	= $Model->idToCode($value['order_id']);
+            $value['custom_code']	= $Custom->idToCode($value['custom_uid']);
+            $value['state']			= $Model->getState($value['status'],'state');
             $value['business_name']= Business::query()->where('id',$value['business_id'])->value('name');
-			$value['product_code']	= $value['product_id'] ? $Product->idToCode($value['product_id']) : '— —';
-			// 重组
-			$list[$key]				= $value;
-		}
+            $value['product_code']	= $value['product_id'] ? $Product->idToCode($value['product_id']) : '— —';
+            // 重组
+            $list[$key]				= $value;
+        }
         $businessList 			    = $Business->getList();
-		// 分配数据
-		$this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
-		$this->assign('list', $list);
+        // 分配数据
+        $this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
+        $this->assign('list', $list);
         $this->assign('businessList',$businessList);
-		// 加载模板
-		return						$this->fetch();
+        // 加载模板
+        return						$this->fetch();
     }
 
 
-	/**
-	 * 首页列表
-	 * 
-	 * */
+    /**
+     * 首页列表
+     *
+     * */
     public function detail(Model $Model,AdminUser $AdminUser,OrdersProduct $OrdersProduct,Product $Product,Custom $Custom,OrdersAddr $OrdersAddr,Receipt $Receipt){
-		// 接受参数
-		$id						= request('order_id','');
-		// 查询数据
-		$order					= $Model->query()->find($id);
-		// 查询不到订单
-		if( !$order	)			return $this->error('订单数据不存在');
-		// id转编号
-		$order['order_code']	= $Model->idToCode($order['id']);
-		$order['custom_code']	= $Custom->idToCode($order['custom_uid']);
-		$order['custom_name']	= $Custom->getValue($order['custom_uid'],'username');
-		$order['state']			= $Model->getState($order['status'],'state');
-		// 查询子订单数据
-		$orderItems				= $OrdersProduct->query()->where([['order_id','=',$id]])->select(['id as item_id','order_id','product_id','buy_num','pay_total','is_rebate','sku_attr_names as product_spec','product_name','product_thumb'])->get()->toArray();
-		// 地址
-		$orderAddr				= $OrdersAddr->query()->where([['order_id','=',$id]])->first(['contact_name','contact_phone','contact_province','contact_city','contact_area','contact_addr','contact_shop']);
-		// 审核记录
-		$orderReceipt			= $Receipt->query()->where([['order_id','=',$id]])->orderByDesc('id')->get()->toArray();
-		// 循环数据
-		foreach ($orderItems as $key => $value) {
-			$value['product_code']	= $Product->idToCode($value['product_id']);
-			$orderItems[$key]  = $value;
-		}
-		// 循环数据
-		foreach ($orderReceipt as $key => $value) {
-			// 操作人员
-			$value['admin_name']= $AdminUser->getOne($value['admin_uid'],'username');
-			$value['image']		= path_compat($value['image']);
-			$orderReceipt[$key] = $value;
-		}
-		// 积分
-		$score					= $orderReceipt ? max(array_column($orderReceipt,'give_score')) : 0;
-		// 恭喜
-		$shopName				= $orderAddr['contact_shop'] ? $orderAddr['contact_shop'] : $order['custom_name'];
-		// 结果
-		$shareImage				= $this->getShareImage($shopName,$score);
-		// 分配数据
-		$this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
-		$this->assign('order', $order);
-		$this->assign('orderAddr', $orderAddr);
-		$this->assign('orderItems', $orderItems);
-		$this->assign('orderReceipt', $orderReceipt);
-		$this->assign('shareImage', $shareImage);
-		// 加载模板
-		return						$this->fetch();
+        // 接受参数
+        $id						= request('order_id','');
+        // 查询数据
+        $order					= $Model->query()->find($id);
+        // 查询不到订单
+        if( !$order	)			return $this->error('订单数据不存在');
+        // id转编号
+        $order['order_code']	= $Model->idToCode($order['id']);
+        $order['custom_code']	= $Custom->idToCode($order['custom_uid']);
+        $order['custom_name']	= $Custom->getValue($order['custom_uid'],'username');
+        $order['state']			= $Model->getState($order['status'],'state');
+        // 查询子订单数据
+        $orderItems				= $OrdersProduct->query()->where([['order_id','=',$id]])->select(['id as item_id','order_id','product_id','buy_num','pay_total','is_rebate','sku_attr_names as product_spec','product_name','product_thumb'])->get()->toArray();
+        // 地址
+        $orderAddr				= $OrdersAddr->query()->where([['order_id','=',$id]])->first(['contact_name','contact_phone','contact_province','contact_city','contact_area','contact_addr','contact_shop']);
+        // 审核记录
+        $orderReceipt			= $Receipt->query()->where([['order_id','=',$id]])->orderByDesc('id')->get()->toArray();
+        // 循环数据
+        foreach ($orderItems as $key => $value) {
+            $value['product_code']	= $Product->idToCode($value['product_id']);
+            $orderItems[$key]  = $value;
+        }
+        // 循环数据
+        foreach ($orderReceipt as $key => $value) {
+            // 操作人员
+            $value['admin_name']= $AdminUser->getOne($value['admin_uid'],'username');
+            $value['image']		= path_compat($value['image']);
+            $orderReceipt[$key] = $value;
+        }
+        // 积分
+        $score					= $orderReceipt ? max(array_column($orderReceipt,'give_score')) : 0;
+        // 恭喜
+        $shopName				= $orderAddr['contact_shop'] ? $orderAddr['contact_shop'] : $order['custom_name'];
+        // 结果
+        $shareImage				= $this->getShareImage($shopName,$score);
+        // 分配数据
+        $this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
+        $this->assign('order', $order);
+        $this->assign('orderAddr', $orderAddr);
+        $this->assign('orderItems', $orderItems);
+        $this->assign('orderReceipt', $orderReceipt);
+        $this->assign('shareImage', $shareImage);
+        // 加载模板
+        return						$this->fetch();
     }
 
 
-	/**
-	 * 状态
-	 * 
-	 * */
-	public function set_status( Request $request, Model $Model,OrdersProduct $OrdersProduct,CustomScore $CustomScore){
-		// 验证参数
-		$request->scene('set_status')->validate();
-		// 接收参数
-		$id				= request('id',0);
-		$status			= request('status',0);
-		// 获取产品和数量
-		$oldData 		= $Model->query()->find($id,['id','order_score','custom_uid','insert_time']);
-		// 如果用户不存在
-		if( !$oldData )	return json_send(['code'=>'error','msg'=>'订单不存在']);
-		// 组合数据,写入订单表,子表
-		DB::beginTransaction();
-		try{
-			// 查询数据
-			$result			= $Model->setOrderStatus($id,$status,$OrdersProduct);
-			// 提示新增失败
-			if( isset($result['error']) )	{
-				// 回退数据
-				DB::rollBack();
-				// 提示信息
-				return		json_send(['code'=>'error','msg'=>$result['error'],'data'=>['error'=>$result['error']]]);
-			}
-			if( $status == 4 ){
-				// 取消积分
-				if( $oldData['order_score'] > 0 ) {
-					// 如果扣减失败
-					$result 	= $CustomScore->trade($oldData['custom_uid'],$oldData['id'],($oldData['order_score']*-1),6,1);
-					// 提示新增失败
-					if( isset($result['error']) )	{
-						// 回退数据
-						DB::rollBack();
-						// 提示信息
-						return json_send(['code'=>'error','msg'=>'取消赠送积分失败','data'=>['error'=>$result['error']]]);
-					}
-				}
-				// 取消关联订单
-				$result			= $Model->cancelRelate($oldData['insert_time'],$oldData['custom_uid'],$OrdersProduct,$CustomScore);
-				// 提示新增失败
-				if( isset($result['error']) )	{
-					// 回退数据
-					DB::rollBack();
-					// 提示信息
-					return		json_send(['code'=>'error','msg'=>'取消关联订单失败','data'=>['error'=>$result['error']]]);
-				}
-			}
-			// 提交数据
-			DB::commit();
-			// 告知结果
-			return			json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
-			// 返回结果
-		} catch (\Throwable $th) {
-			// 回退数据
-			DB::rollBack();
-			// 下单失败提示
-			return			json_send(['code'=>'error','msg'=>'设置失败','data'=>['error'=>$th->getMessage().$th->getLine()]]);
-		}
-	}
-	
+    /**
+     * 状态
+     *
+     * */
+    public function set_status( Request $request, Model $Model,OrdersProduct $OrdersProduct,CustomScore $CustomScore){
+        // 验证参数
+        $request->scene('set_status')->validate();
+        // 接收参数
+        $id				= request('id',0);
+        $status			= request('status',0);
+        // 获取产品和数量
+        $oldData 		= $Model->query()->find($id,['id','order_score','custom_uid','insert_time']);
+        // 如果用户不存在
+        if( !$oldData )	return json_send(['code'=>'error','msg'=>'订单不存在']);
+        // 组合数据,写入订单表,子表
+        DB::beginTransaction();
+        try{
+            // 查询数据
+            $result			= $Model->setOrderStatus($id,$status,$OrdersProduct);
+            // 提示新增失败
+            if( isset($result['error']) )	{
+                // 回退数据
+                DB::rollBack();
+                // 提示信息
+                return		json_send(['code'=>'error','msg'=>$result['error'],'data'=>['error'=>$result['error']]]);
+            }
+            if( $status == 4 ){
+                // 取消积分
+                if( $oldData['order_score'] > 0 ) {
+                    // 如果扣减失败
+                    $result 	= $CustomScore->trade($oldData['custom_uid'],$oldData['id'],($oldData['order_score']*-1),6,1);
+                    // 提示新增失败
+                    if( isset($result['error']) )	{
+                        // 回退数据
+                        DB::rollBack();
+                        // 提示信息
+                        return json_send(['code'=>'error','msg'=>'取消赠送积分失败','data'=>['error'=>$result['error']]]);
+                    }
+                }
+                // 取消关联订单
+                $result			= $Model->cancelRelate($oldData['insert_time'],$oldData['custom_uid'],$OrdersProduct,$CustomScore);
+                // 提示新增失败
+                if( isset($result['error']) )	{
+                    // 回退数据
+                    DB::rollBack();
+                    // 提示信息
+                    return		json_send(['code'=>'error','msg'=>'取消关联订单失败','data'=>['error'=>$result['error']]]);
+                }
+            }
+            // 提交数据
+            DB::commit();
+            // 告知结果
+            return			json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
+            // 返回结果
+        } catch (\Throwable $th) {
+            // 回退数据
+            DB::rollBack();
+            // 下单失败提示
+            return			json_send(['code'=>'error','msg'=>'设置失败','data'=>['error'=>$th->getMessage().$th->getLine()]]);
+        }
+    }
+
 
-	/**
-	 * 表格导入
-	 * 
-	 * */
-	public function import_execl( Request $request,Model $Model,Custom $Custom,OrdersAddr $OrdersAddr,OrdersProduct $OrdersProduct, FilesManager $FilesManager,CustomAddr $CustomAddr){
-		// 验证参数
-		$request->scene('import_execl')->validate();
-		// 获取表格信息
-		$file								= request()->file('order_file');
-		// 返回结果
-		$sheetList							= $FilesManager->excelToOrder($file);
-		// 如果不存在结果
-		if( isset($sheetList['error']) )	return json_send(['code'=>'error','msg'=>$sheetList['error']]);
-		// 订单列表
-		$orderList							= [];
-		// 当前时间
-		$time								= time();
-		// 循环表格数据
-		foreach ($sheetList as $value) 		{
-			// 状态更改
-			$value['status']				= $Model->getWeibanStatus($value['status']);
-			// 客户手机号
-			$orderList[$value['weizan_orderid']]['custom']				= ['phone'=>$value['contact_phone'],'username'=>$value['buyer_nick']];
-			// 组合成订单的收件地址
-			$orderList[$value['weizan_orderid']]['contact']				= [
-																			'contact_name'=>trim($value['contact_name']),
-																			'contact_phone'=>trim($value['contact_phone']),
-																			'contact_province'=>trim($value['contact_province']),
-																			'contact_city'=>trim($value['contact_city']),
-																			'contact_area'=>trim($value['contact_area']),
-																			'contact_addr'=>trim($value['contact_addr'])
-																		];
-			
-			// 组合成订单的收件地址
-			$orderList[$value['weizan_orderid']]['product'][]			= [
-																			'status'=>$value['status'],
-																			'product_name'=>$value['product_name'],
-																			'sku_attr_names'=>$value['sku_attr_names'],
-																			'buy_num'=>$value['buy_num'],
-																			'pay_total'=>$value['pay_total'],
-																			'price_total'=>$value['pay_total'],
-																			'insert_time'=>$value['insert_time'],
-																			'update_time'=>$time,
-																		];
-			// 组合成订单的需要的数据
-			if( !isset($orderList[$value['weizan_orderid']]['order']) )	$orderList[$value['weizan_orderid']]['order'] = ['weizan_orderid'=>$value['weizan_orderid'],'status'=>$value['status'],'pay_total'=>0,'price_total'=>0,'insert_time'=>$value['insert_time']];
-			// 价格
-			$orderList[$value['weizan_orderid']]['order']['pay_total']  = $orderList[$value['weizan_orderid']]['order']['pay_total'] + $value['pay_total'];
-			$orderList[$value['weizan_orderid']]['order']['price_total']  = $orderList[$value['weizan_orderid']]['order']['pay_total'];
-		}
-		// 新增地址
-		$newAddrList						= [];
-		// 要更新的订单子表
-		$orderProduct						= [];
-		// 循环订单列表
-		foreach ($orderList as $value) 		{
-			// 获取手机号,查询是否用客户
-			$custom							= $Custom->getOneByPhone($value['custom']['phone']);
-			// 如果存在手机号
-			$uid							= $custom ? $custom['uid'] : $Custom->add($value['custom']);
-			// 如果客户存在
-			if( !$uid )						return json_send(['code'=>'error','msg'=>$value['custom']['username'].'【'.$value['custom']['phone'].'】'.'无法创建用户']);
-			// 通过订单号查询是否存在系统订单
-			$orderId						= $Model->query()->where([['weizan_orderid','=',$value['order']['weizan_orderid']]])->value('id');
-			// 客户ID
-			$value['order']['custom_uid'] 	= $uid;
-			// 存在订单获取订单ID,不存在则新增
-			$orderId						= $orderId ? $Model->edit($orderId,$value['order']) : $Model->add($value['order']);
-			// 如果客户存在
-			if( !$orderId )					return json_send(['code'=>'error','msg'=>$orderId.'订单写入失败']);
-			// 联系地址
-			$contact						= $value['contact'];
-			// 存在详细地址,才创建地址库
-			if( $contact['contact_name'] && $contact['contact_phone'] && $contact['contact_province'] && $contact['contact_city'] && $contact['contact_area'] && $contact['contact_addr'] )	{
-				// 收件地址是否存在
-				$oldAddr					= $CustomAddr->query()->where([['custom_uid','=',$uid]])->first();
-				// 如果不存在地址
-				if( !$oldAddr )				$CustomAddr->add(['custom_uid'=>$uid,'contact_name'=>$contact['contact_name'],'contact_phone'=>$contact['contact_phone'],'contact_province'=>$contact['contact_province'],'contact_city'=>$contact['contact_city'],'contact_area'=>$contact['contact_area'],'contact_addr'=>$contact['contact_addr']]);
-			}
-			// 订单地址库
-			$addrId							= $OrdersAddr->query()->where([['order_id','=',$orderId]])->value('id');
-			// 订单ID
-			$value['contact']['order_id']	= $orderId;
-			// 订单地址ID
-			$value['contact']['id'] 		= (int)$addrId;
-			// 不存在地址的话
-			$newAddrList[] 					= $value['contact'];
-			// 循环子订单
-			foreach ( $value['product'] as 	$product ) {
-				// 数据结果
-				$product['order_id']		= $orderId;
-				$product['custom_uid']		= $uid;
-				$product['id']				= (int) $OrdersProduct->query()->where([['order_id','=',$orderId],'product_name'=>$product['product_name'],'sku_attr_names'=>$product['sku_attr_names']])->value('id');
-				$orderProduct[]				= $product;
-			}
-		}
-		// 新地址写入
-		$OrdersProduct->query()->upsert($orderProduct,'id',['product_name','sku_attr_names','buy_num','pay_total','price_total','update_time']);
-		// 新地址写入
-		$OrdersAddr->query()->upsert($newAddrList,'id',['contact_name','contact_phone','contact_province','contact_city','contact_area','contact_addr']);
-		// 提示成功
-		return								json_send(['code'=>'success','msg'=>'订单导入成功','path'=>'']);
-	}
+    /**
+     * 表格导入
+     *
+     * */
+    public function import_execl( Request $request,Model $Model,Custom $Custom,OrdersAddr $OrdersAddr,OrdersProduct $OrdersProduct, FilesManager $FilesManager,CustomAddr $CustomAddr){
+        // 验证参数
+        $request->scene('import_execl')->validate();
+        // 获取表格信息
+        $file								= request()->file('order_file');
+        // 返回结果
+        $sheetList							= $FilesManager->excelToOrder($file);
+        // 如果不存在结果
+        if( isset($sheetList['error']) )	return json_send(['code'=>'error','msg'=>$sheetList['error']]);
+        // 订单列表
+        $orderList							= [];
+        // 当前时间
+        $time								= time();
+        // 循环表格数据
+        foreach ($sheetList as $value) 		{
+            // 状态更改
+            $value['status']				= $Model->getWeibanStatus($value['status']);
+            // 客户手机号
+            $orderList[$value['weizan_orderid']]['custom']				= ['phone'=>$value['contact_phone'],'username'=>$value['buyer_nick']];
+            // 组合成订单的收件地址
+            $orderList[$value['weizan_orderid']]['contact']				= [
+                'contact_name'=>trim($value['contact_name']),
+                'contact_phone'=>trim($value['contact_phone']),
+                'contact_province'=>trim($value['contact_province']),
+                'contact_city'=>trim($value['contact_city']),
+                'contact_area'=>trim($value['contact_area']),
+                'contact_addr'=>trim($value['contact_addr'])
+            ];
 
-	/**
-	 * 批量修改状态
-	 * 
-	 * */
-	public function import_execl_status( Request $request,Model $Model,OrdersProduct $OrdersProduct,FilesManager $FilesManager){
-		// 验证参数
-		$request->scene('import_execl_status')->validate();
-		// 获取表格信息
-		$file								= request()->file('order_file');
-		// 返回结果
-		$sheetList							= $FilesManager->excelToOrderStatus($file);
-		// 如果不存在结果
-		if( isset($sheetList['error']) )	return json_send(['code'=>'error','msg'=>$sheetList['error']]);
-		// 循环表格数据
-		foreach ($sheetList as $key=>$value) 		{
-			// 客户ID
-			$orderId						= $Model->codeToId($value['order_code']);
-			// 如果客户ID有误
-			if( !$orderId )					return json_send(['code'=>'error','msg'=>$value['order_code'].'编码有误']);
-			// 订单状态
-			$status							= $Model->getWeibanStatus($value['status']);
-			// 状态提示
-			if( $status < 0 )				return json_send(['code'=>'error','msg'=>$value['order_code'].'状态有误']);
-			// 修改数据
-			$result							= $Model->setOrderStatus($orderId,$status,$OrdersProduct);
-			// 提示
-			if( isset($result['error'])	)	return json_send(['code'=>'error','msg'=>$value['order_code'].$result['error']]);
-		}
-		// 提示成功
-		return								json_send(['code'=>'success','msg'=>'订单导入成功','path'=>'']);
-	}
+            // 组合成订单的收件地址
+            $orderList[$value['weizan_orderid']]['product'][]			= [
+                'status'=>$value['status'],
+                'product_name'=>$value['product_name'],
+                'sku_attr_names'=>$value['sku_attr_names'],
+                'buy_num'=>$value['buy_num'],
+                'pay_total'=>$value['pay_total'],
+                'price_total'=>$value['pay_total'],
+                'insert_time'=>$value['insert_time'],
+                'update_time'=>$time,
+            ];
+            // 组合成订单的需要的数据
+            if( !isset($orderList[$value['weizan_orderid']]['order']) )	$orderList[$value['weizan_orderid']]['order'] = ['weizan_orderid'=>$value['weizan_orderid'],'status'=>$value['status'],'pay_total'=>0,'price_total'=>0,'insert_time'=>$value['insert_time']];
+            // 价格
+            $orderList[$value['weizan_orderid']]['order']['pay_total']  = $orderList[$value['weizan_orderid']]['order']['pay_total'] + $value['pay_total'];
+            $orderList[$value['weizan_orderid']]['order']['price_total']  = $orderList[$value['weizan_orderid']]['order']['pay_total'];
+        }
+        // 新增地址
+        $newAddrList						= [];
+        // 要更新的订单子表
+        $orderProduct						= [];
+        // 循环订单列表
+        foreach ($orderList as $value) 		{
+            // 获取手机号,查询是否用客户
+            $custom							= $Custom->getOneByPhone($value['custom']['phone']);
+            // 如果存在手机号
+            $uid							= $custom ? $custom['uid'] : $Custom->add($value['custom']);
+            // 如果客户存在
+            if( !$uid )						return json_send(['code'=>'error','msg'=>$value['custom']['username'].'【'.$value['custom']['phone'].'】'.'无法创建用户']);
+            // 通过订单号查询是否存在系统订单
+            $orderId						= $Model->query()->where([['weizan_orderid','=',$value['order']['weizan_orderid']]])->value('id');
+            // 客户ID
+            $value['order']['custom_uid'] 	= $uid;
+            // 存在订单获取订单ID,不存在则新增
+            $orderId						= $orderId ? $Model->edit($orderId,$value['order']) : $Model->add($value['order']);
+            // 如果客户存在
+            if( !$orderId )					return json_send(['code'=>'error','msg'=>$orderId.'订单写入失败']);
+            // 联系地址
+            $contact						= $value['contact'];
+            // 存在详细地址,才创建地址库
+            if( $contact['contact_name'] && $contact['contact_phone'] && $contact['contact_province'] && $contact['contact_city'] && $contact['contact_area'] && $contact['contact_addr'] )	{
+                // 收件地址是否存在
+                $oldAddr					= $CustomAddr->query()->where([['custom_uid','=',$uid]])->first();
+                // 如果不存在地址
+                if( !$oldAddr )				$CustomAddr->add(['custom_uid'=>$uid,'contact_name'=>$contact['contact_name'],'contact_phone'=>$contact['contact_phone'],'contact_province'=>$contact['contact_province'],'contact_city'=>$contact['contact_city'],'contact_area'=>$contact['contact_area'],'contact_addr'=>$contact['contact_addr']]);
+            }
+            // 订单地址库
+            $addrId							= $OrdersAddr->query()->where([['order_id','=',$orderId]])->value('id');
+            // 订单ID
+            $value['contact']['order_id']	= $orderId;
+            // 订单地址ID
+            $value['contact']['id'] 		= (int)$addrId;
+            // 不存在地址的话
+            $newAddrList[] 					= $value['contact'];
+            // 循环子订单
+            foreach ( $value['product'] as 	$product ) {
+                // 数据结果
+                $product['order_id']		= $orderId;
+                $product['custom_uid']		= $uid;
+                $product['id']				= (int) $OrdersProduct->query()->where([['order_id','=',$orderId],'product_name'=>$product['product_name'],'sku_attr_names'=>$product['sku_attr_names']])->value('id');
+                $orderProduct[]				= $product;
+            }
+        }
+        // 新地址写入
+        $OrdersProduct->query()->upsert($orderProduct,'id',['product_name','sku_attr_names','buy_num','pay_total','price_total','update_time']);
+        // 新地址写入
+        $OrdersAddr->query()->upsert($newAddrList,'id',['contact_name','contact_phone','contact_province','contact_city','contact_area','contact_addr']);
+        // 提示成功
+        return								json_send(['code'=>'success','msg'=>'订单导入成功','path'=>'']);
+    }
 
-	/**
-	 * 导出表格导入
-	 * 
-	 * */
-	public function down_excel(Model $Model,OrdersProduct $OrdersProduct,Product $Product,Custom $Custom,Business $Business){
-		// 接受参数
-		$code					= request('order_code','');
-		$productCode			= request('product_code','');
-		$orders_other			= request('orders_other',0);
-		$customCode				= request('custom_code','');
-		$productName			= request('product_name','');
-		$phone					= request('phone','');
-		$province				= request('contact_province','');
-		$city					= request('contact_city','');
-		$area					= request('contact_area','');
-		$status					= request('status',0);
-		$startTime				= request('start_time','');
-		$endTime				= request('end_time','');
-		// 编码转ID
-		$id						= $code ? $Model->codeToId($code) : 0;
-		$productId				= $productCode ? $Product->codeToId($productCode) : 0;
-		$uid					= $customCode ? $Custom->codeToId($customCode) : 0;
-		// 查询条件
-		$map 					= [];
-		// 编码ID
-		if( $id )				$map[] = ['orders_product.order_id','=',$id];
-		if( $uid )				$map[] = ['custom.uid','=',$uid];
-		// 编码ID
-		if( $orders_other )		$map[] = $orders_other == 1 ? ['orders_product.product_id','>',0] : ['orders_product.product_id','=',0];
-		if( $productId )		$map[] = ['orders_product.product_id','=',$productId];
-		if( $productName )		$map[] = ['orders_product.product_name','=',$productName];
-		if( $phone )			$map[] = ['orders_addr.contact_phone','=',$phone];
-		if( $province )			$map[] = ['orders_addr.contact_province','LIKE','%'.$province.'%'];
-		if( $city )				$map[] = ['orders_addr.contact_city','LIKE','%'.$city.'%'];
-		if( $area )				$map[] = ['orders_addr.contact_area','LIKE','%'.$area.'%'];
-		if( $startTime )		$map[] = ['orders_product.insert_time','>=',strtotime($startTime)];
-		if( $endTime )			$map[] = ['orders_product.insert_time','<=',strtotime($endTime)];
-		if( $status )			$map[] = ['orders_product.status','=',$status];
+    /**
+     * 批量修改状态
+     *
+     * */
+    public function import_execl_status( Request $request,Model $Model,OrdersProduct $OrdersProduct,FilesManager $FilesManager){
+        // 验证参数
+        $request->scene('import_execl_status')->validate();
+        // 获取表格信息
+        $file								= request()->file('order_file');
+        // 返回结果
+        $sheetList							= $FilesManager->excelToOrderStatus($file);
+        // 如果不存在结果
+        if( isset($sheetList['error']) )	return json_send(['code'=>'error','msg'=>$sheetList['error']]);
+        // 循环表格数据
+        foreach ($sheetList as $key=>$value) 		{
+            // 客户ID
+            $orderId						= $Model->codeToId($value['order_code']);
+            // 如果客户ID有误
+            if( !$orderId )					return json_send(['code'=>'error','msg'=>$value['order_code'].'编码有误']);
+            // 订单状态
+            $status							= $Model->getWeibanStatus($value['status']);
+            // 状态提示
+            if( $status < 0 )				return json_send(['code'=>'error','msg'=>$value['order_code'].'状态有误']);
+            // 修改数据
+            $result							= $Model->setOrderStatus($orderId,$status,$OrdersProduct);
+            // 提示
+            if( isset($result['error'])	)	return json_send(['code'=>'error','msg'=>$value['order_code'].$result['error']]);
+        }
+        // 提示成功
+        return								json_send(['code'=>'success','msg'=>'订单导入成功','path'=>'']);
+    }
+
+    /**
+     * 导出表格导入
+     *
+     * */
+    public function down_excel(Model $Model,OrdersProduct $OrdersProduct,Product $Product,Custom $Custom,Business $Business){
+        // 接受参数
+        $code					= request('order_code','');
+        $productCode			= request('product_code','');
+        $orders_other			= request('orders_other',0);
+        $customCode				= request('custom_code','');
+        $productName			= request('product_name','');
+        $phone					= request('phone','');
+        $province				= request('contact_province','');
+        $city					= request('contact_city','');
+        $area					= request('contact_area','');
+        $status					= request('status',0);
+        $startTime				= request('start_time','');
+        $endTime				= request('end_time','');
+        // 编码转ID
+        $id						= $code ? $Model->codeToId($code) : 0;
+        $productId				= $productCode ? $Product->codeToId($productCode) : 0;
+        $uid					= $customCode ? $Custom->codeToId($customCode) : 0;
+        // 查询条件
+        $map 					= [];
+        // 编码ID
+        if( $id )				$map[] = ['orders_product.order_id','=',$id];
+        if( $uid )				$map[] = ['custom.uid','=',$uid];
+        // 编码ID
+        if( $orders_other )		$map[] = $orders_other == 1 ? ['orders_product.product_id','>',0] : ['orders_product.product_id','=',0];
+        if( $productId )		$map[] = ['orders_product.product_id','=',$productId];
+        if( $productName )		$map[] = ['orders_product.product_name','=',$productName];
+        if( $phone )			$map[] = ['orders_addr.contact_phone','=',$phone];
+        if( $province )			$map[] = ['orders_addr.contact_province','LIKE','%'.$province.'%'];
+        if( $city )				$map[] = ['orders_addr.contact_city','LIKE','%'.$city.'%'];
+        if( $area )				$map[] = ['orders_addr.contact_area','LIKE','%'.$area.'%'];
+        if( $startTime )		$map[] = ['orders_product.insert_time','>=',strtotime($startTime)];
+        if( $endTime )			$map[] = ['orders_product.insert_time','<=',strtotime($endTime)];
+        if( $status )			$map[] = ['orders_product.status','=',$status];
         $session                = session('userRule');
         if ($session){
             $map[] = ['orders_product.company_id','=',$session['company_id']];
@@ -423,237 +423,237 @@ class Orders extends Auth{
                 $shopIds       = $Business::query()->where('leader_uid',$session['admin_uid'])->pluck('id')->toArray();
             }
         }
-		// 查询数据
-		$list					= $OrdersProduct->query()
-									->join('custom','orders_product.custom_uid','=','custom.uid')
-									->join('orders_addr','orders_addr.order_id','=','orders_product.order_id');
+        // 查询数据
+        $list					= $OrdersProduct->query()
+            ->join('custom','orders_product.custom_uid','=','custom.uid')
+            ->join('orders_addr','orders_addr.order_id','=','orders_product.order_id');
         if (isset($shopIds))    $list->whereIn('orders_product.business_id',$shopIds);
         $list                   = $list->where($map)
-									->orderByDesc('orders_product.id')
-									->select([
-										'orders_product.id as id',
-										'orders_product.order_id',
-										'orders_product.custom_uid',
-										'orders_product.product_id',
-										'orders_product.product_name',
-										'orders_product.sku_attr_names as product_spec',
-										'orders_product.product_thumb',
-										'orders_product.buy_num',
-										'orders_product.price_total',
-										'orders_product.coupon_total',
-										'orders_product.pay_total',
-										'orders_product.status',
-										'orders_product.insert_time',
-										'custom.username as custom_name','custom.weiban_extid as weiban_extid',
-										'orders_addr.contact_name','orders_addr.contact_shop','orders_addr.contact_phone','orders_addr.contact_province','orders_addr.contact_city','orders_addr.contact_area','orders_addr.contact_addr'
-									])->get()->toArray();
-		// 返回结果
-		$data						= [];
-		// 循环处理数据
-		foreach ($list as $value) {
-			// id转编号
-			$value['order_id']		= $Model->idToCode($value['order_id']);
-			$value['status']		= $Model->getState($value['status'],'state');
-			$value['custom_uid']	= $Custom->idToCode($value['custom_uid']);
-			$value['product_price']	= $value['buy_num'] ? ($value['price_total'] / $value['buy_num']) : $value['buy_num'];
-			$value['pay_price']		= $value['buy_num'] ? ($value['pay_total'] / $value['buy_num']) : $value['buy_num'];
-			// 重组
-			$data[$value['order_id']]['order_id'] = $value['order_id'];
-			$data[$value['order_id']]['custom_uid'] = $value['custom_uid'];
-			$data[$value['order_id']]['custom_name'] = $value['custom_name'];
-			$data[$value['order_id']]['weiban_extid'] = $value['weiban_extid'];
-			$data[$value['order_id']]['status'] = $value['status'];
-			$data[$value['order_id']]['insert_time'] = $value['insert_time'];
-			// 地址
-			$data[$value['order_id']]['contact_name'] = $value['contact_name'];
-			$data[$value['order_id']]['contact_phone'] = $value['contact_phone'];
-			$data[$value['order_id']]['contact_province'] = $value['contact_province'];
-			$data[$value['order_id']]['contact_city'] = $value['contact_city'];
-			$data[$value['order_id']]['contact_area'] = $value['contact_area'];
-			$data[$value['order_id']]['contact_addr'] = $value['contact_addr'] .($value['contact_shop'] ? '【'.$value['contact_shop'].'】' : '');
-			// 子订单
-			$data[$value['order_id']]['product'][] 	  = ['product_id'=>$value['product_id'] ? $Product->idToCode($value['product_id']) : '— —','product_name'=>$value['product_name'],'product_spec'=>$value['product_spec'],'product_thumb'=>$value['product_thumb'],'product_price'=>$value['product_price'],'pay_price'=>$value['pay_price'],'buy_num'=>$value['buy_num'],'pay_total'=>$value['pay_total'],'price_total'=>$value['price_total'],'coupon_total'=>$value['coupon_total']];
-		}
+            ->orderByDesc('orders_product.id')
+            ->select([
+                'orders_product.id as id',
+                'orders_product.order_id',
+                'orders_product.custom_uid',
+                'orders_product.product_id',
+                'orders_product.product_name',
+                'orders_product.sku_attr_names as product_spec',
+                'orders_product.product_thumb',
+                'orders_product.buy_num',
+                'orders_product.price_total',
+                'orders_product.coupon_total',
+                'orders_product.pay_total',
+                'orders_product.status',
+                'orders_product.insert_time',
+                'custom.username as custom_name','custom.weiban_extid as weiban_extid',
+                'orders_addr.contact_name','orders_addr.contact_shop','orders_addr.contact_phone','orders_addr.contact_province','orders_addr.contact_city','orders_addr.contact_area','orders_addr.contact_addr'
+            ])->get()->toArray();
+        // 返回结果
+        $data						= [];
+        // 循环处理数据
+        foreach ($list as $value) {
+            // id转编号
+            $value['order_id']		= $Model->idToCode($value['order_id']);
+            $value['status']		= $Model->getState($value['status'],'state');
+            $value['custom_uid']	= $Custom->idToCode($value['custom_uid']);
+            $value['product_price']	= $value['buy_num'] ? ($value['price_total'] / $value['buy_num']) : $value['buy_num'];
+            $value['pay_price']		= $value['buy_num'] ? ($value['pay_total'] / $value['buy_num']) : $value['buy_num'];
+            // 重组
+            $data[$value['order_id']]['order_id'] = $value['order_id'];
+            $data[$value['order_id']]['custom_uid'] = $value['custom_uid'];
+            $data[$value['order_id']]['custom_name'] = $value['custom_name'];
+            $data[$value['order_id']]['weiban_extid'] = $value['weiban_extid'];
+            $data[$value['order_id']]['status'] = $value['status'];
+            $data[$value['order_id']]['insert_time'] = $value['insert_time'];
+            // 地址
+            $data[$value['order_id']]['contact_name'] = $value['contact_name'];
+            $data[$value['order_id']]['contact_phone'] = $value['contact_phone'];
+            $data[$value['order_id']]['contact_province'] = $value['contact_province'];
+            $data[$value['order_id']]['contact_city'] = $value['contact_city'];
+            $data[$value['order_id']]['contact_area'] = $value['contact_area'];
+            $data[$value['order_id']]['contact_addr'] = $value['contact_addr'] .($value['contact_shop'] ? '【'.$value['contact_shop'].'】' : '');
+            // 子订单
+            $data[$value['order_id']]['product'][] 	  = ['product_id'=>$value['product_id'] ? $Product->idToCode($value['product_id']) : '— —','product_name'=>$value['product_name'],'product_spec'=>$value['product_spec'],'product_thumb'=>$value['product_thumb'],'product_price'=>$value['product_price'],'pay_price'=>$value['pay_price'],'buy_num'=>$value['buy_num'],'pay_total'=>$value['pay_total'],'price_total'=>$value['price_total'],'coupon_total'=>$value['coupon_total']];
+        }
 
-		try {
-			// 去下载
-			$this->toDown($data);
-		} catch (\Throwable $th) {
-			echo $th->getMessage();
-		}
-		
-	}
+        try {
+            // 去下载
+            $this->toDown($data);
+        } catch (\Throwable $th) {
+            echo $th->getMessage();
+        }
+
+    }
 
 
-	/**
-	 * 去下载
-	 */
-	private function  toDown($data){
-		// 创建新的电子表格对象
-		$spreadsheet			= new Spreadsheet();
-		// 设置合并单元格的行和列,例如合并A1到B2的单元格
-		$sheet					= $this->setStyle($spreadsheet);
-		// 从第二行写入
-		$row					= 2;
-		// 循环写入
-		foreach ($data as $value) {
-			// 循环产品
-			foreach ($value['product'] as $v) {
-				// 单元格内容写入
-				$sheet->setCellValue('A'.$row, $value['order_id']);
-				$sheet->setCellValue('B'.$row, $value['custom_uid']);
-				//避免 = + - 识别成公式
-				$sheet->setCellValueExplicit('C'.$row, $value['custom_name'],DataType::TYPE_STRING);
-				$sheet->setCellValue('D'.$row, $value['status']);
-				$sheet->setCellValue('E'.$row, $value['contact_name']);
-				$sheet->setCellValue('F'.$row, $value['contact_phone']);
-				$sheet->setCellValue('G'.$row, $value['contact_province']);
-				$sheet->setCellValue('H'.$row, $value['contact_city']);
-				$sheet->setCellValue('I'.$row, $value['contact_area']);
-				$sheet->setCellValue('J'.$row, $value['contact_addr']);
-				$sheet->setCellValue('K'.$row, $v['product_id']);
-				$sheet->setCellValue('L'.$row, $v['product_name']);
-				$sheet->setCellValue('M'.$row, $v['product_spec']);
-				$sheet->setCellValue('N'.$row, $v['product_price']);
-				$sheet->setCellValue('O'.$row, $v['pay_price']);
-				$sheet->setCellValue('P'.$row, $v['buy_num']);
-				$sheet->setCellValue('Q'.$row, $v['coupon_total']);
-				$sheet->setCellValue('R'.$row, $v['pay_total']);
-				$sheet->setCellValue('S'.$row, $value['weiban_extid']);
-				$sheet->setCellValue('T'.$row, date('Y-m-d H:i:s',$value['insert_time']));
-				// 函数自增
-				$row++;
-			}
-		}
-		// 创建内容
-		$writer 				= IOFactory::createWriter($spreadsheet, 'Xlsx');
-		header('Pragma: public');
-		header('Content-type:application/vnd.ms-excel');
-		header('Content-Disposition: inline;filename=下载订单.xlsx');
-		// 输出数据流
-		return $writer->save('php://output');
-	}
+    /**
+     * 去下载
+     */
+    private function  toDown($data){
+        // 创建新的电子表格对象
+        $spreadsheet			= new Spreadsheet();
+        // 设置合并单元格的行和列,例如合并A1到B2的单元格
+        $sheet					= $this->setStyle($spreadsheet);
+        // 从第二行写入
+        $row					= 2;
+        // 循环写入
+        foreach ($data as $value) {
+            // 循环产品
+            foreach ($value['product'] as $v) {
+                // 单元格内容写入
+                $sheet->setCellValue('A'.$row, $value['order_id']);
+                $sheet->setCellValue('B'.$row, $value['custom_uid']);
+                //避免 = + - 识别成公式
+                $sheet->setCellValueExplicit('C'.$row, $value['custom_name'],DataType::TYPE_STRING);
+                $sheet->setCellValue('D'.$row, $value['status']);
+                $sheet->setCellValue('E'.$row, $value['contact_name']);
+                $sheet->setCellValue('F'.$row, $value['contact_phone']);
+                $sheet->setCellValue('G'.$row, $value['contact_province']);
+                $sheet->setCellValue('H'.$row, $value['contact_city']);
+                $sheet->setCellValue('I'.$row, $value['contact_area']);
+                $sheet->setCellValue('J'.$row, $value['contact_addr']);
+                $sheet->setCellValue('K'.$row, $v['product_id']);
+                $sheet->setCellValue('L'.$row, $v['product_name']);
+                $sheet->setCellValue('M'.$row, $v['product_spec']);
+                $sheet->setCellValue('N'.$row, $v['product_price']);
+                $sheet->setCellValue('O'.$row, $v['pay_price']);
+                $sheet->setCellValue('P'.$row, $v['buy_num']);
+                $sheet->setCellValue('Q'.$row, $v['coupon_total']);
+                $sheet->setCellValue('R'.$row, $v['pay_total']);
+                $sheet->setCellValue('S'.$row, $value['weiban_extid']);
+                $sheet->setCellValue('T'.$row, date('Y-m-d H:i:s',$value['insert_time']));
+                // 函数自增
+                $row++;
+            }
+        }
+        // 创建内容
+        $writer 				= IOFactory::createWriter($spreadsheet, 'Xlsx');
+        header('Pragma: public');
+        header('Content-type:application/vnd.ms-excel');
+        header('Content-Disposition: inline;filename=下载订单.xlsx');
+        // 输出数据流
+        return $writer->save('php://output');
+    }
 
-	/**
-	 * 设置表格样式
-	 * 
-	 */
-	private function setStyle(Spreadsheet $spreadsheet){
-		// 选择当前活动的工作表
-		$sheet					= $spreadsheet->getActiveSheet();
-		// 宽
-		$sheet->getColumnDimension('A')->setWidth(15);
-		$sheet->getColumnDimension('B')->setWidth(15);
-		$sheet->getColumnDimension('C')->setWidth(15);
-		$sheet->getColumnDimension('D')->setWidth(15);
-		$sheet->getColumnDimension('E')->setWidth(15);
-		$sheet->getColumnDimension('F')->setWidth(15);
-		$sheet->getColumnDimension('G')->setWidth(15);
-		$sheet->getColumnDimension('H')->setWidth(15);
-		$sheet->getColumnDimension('I')->setWidth(15);
-		$sheet->getColumnDimension('J')->setWidth(50);
-		$sheet->getColumnDimension('K')->setWidth(20);
-		$sheet->getColumnDimension('L')->setWidth(80);
-		$sheet->getColumnDimension('M')->setWidth(80);
-		$sheet->getColumnDimension('N')->setWidth(10);
-		$sheet->getColumnDimension('O')->setWidth(10);
-		$sheet->getColumnDimension('P')->setWidth(10);
-		$sheet->getColumnDimension('Q')->setWidth(10);
-		$sheet->getColumnDimension('R')->setWidth(10);
-		$sheet->getColumnDimension('S')->setWidth(50);
-		$sheet->getColumnDimension('T')->setWidth(20);
-		// 默认高度
-		$sheet->getDefaultRowDimension()->setRowHeight(18);
-		// 加粗第一行
-		$sheet->getStyle('A:T')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
-		$sheet->getStyle('A1:T1')->getFont()->setBold(true);
-		$sheet->getStyle('A1:T1')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setARGB('FF00FF00'); // ARGB颜色代码,例如绿色
-		// 设置表格标题
-		$sheet
-		->setCellValue('A1', '订单ID')
-		->setCellValue('B1', '客户ID')
-		->setCellValue('C1', '客户昵称')
-		->setCellValue('D1', '订单状态')
-		->setCellValue('E1', '收货人')
-		->setCellValue('F1', '收货人手机号')
-		->setCellValue('G1', '省')
-		->setCellValue('H1', '市')
-		->setCellValue('I1', '区县')
-		->setCellValue('J1', '收货地址')
-		->setCellValue('K1', '产品编码')
-		->setCellValue('L1', '产品名称')
-		->setCellValue('M1', '产品规格')
-		->setCellValue('N1', '产品单价')
-		->setCellValue('O1', '折后单价')
-		->setCellValue('P1', '产品数量')
-		->setCellValue('Q1', '优惠金额')
-		->setCellValue('R1', '产品金额')
-		->setCellValue('S1', '微伴ID')
-		->setCellValue('T1', '下单时间');
-		// 返回结果
-		return 					$sheet;
-	}
+    /**
+     * 设置表格样式
+     *
+     */
+    private function setStyle(Spreadsheet $spreadsheet){
+        // 选择当前活动的工作表
+        $sheet					= $spreadsheet->getActiveSheet();
+        // 宽
+        $sheet->getColumnDimension('A')->setWidth(15);
+        $sheet->getColumnDimension('B')->setWidth(15);
+        $sheet->getColumnDimension('C')->setWidth(15);
+        $sheet->getColumnDimension('D')->setWidth(15);
+        $sheet->getColumnDimension('E')->setWidth(15);
+        $sheet->getColumnDimension('F')->setWidth(15);
+        $sheet->getColumnDimension('G')->setWidth(15);
+        $sheet->getColumnDimension('H')->setWidth(15);
+        $sheet->getColumnDimension('I')->setWidth(15);
+        $sheet->getColumnDimension('J')->setWidth(50);
+        $sheet->getColumnDimension('K')->setWidth(20);
+        $sheet->getColumnDimension('L')->setWidth(80);
+        $sheet->getColumnDimension('M')->setWidth(80);
+        $sheet->getColumnDimension('N')->setWidth(10);
+        $sheet->getColumnDimension('O')->setWidth(10);
+        $sheet->getColumnDimension('P')->setWidth(10);
+        $sheet->getColumnDimension('Q')->setWidth(10);
+        $sheet->getColumnDimension('R')->setWidth(10);
+        $sheet->getColumnDimension('S')->setWidth(50);
+        $sheet->getColumnDimension('T')->setWidth(20);
+        // 默认高度
+        $sheet->getDefaultRowDimension()->setRowHeight(18);
+        // 加粗第一行
+        $sheet->getStyle('A:T')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
+        $sheet->getStyle('A1:T1')->getFont()->setBold(true);
+        $sheet->getStyle('A1:T1')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setARGB('FF00FF00'); // ARGB颜色代码,例如绿色
+        // 设置表格标题
+        $sheet
+            ->setCellValue('A1', '订单ID')
+            ->setCellValue('B1', '客户ID')
+            ->setCellValue('C1', '客户昵称')
+            ->setCellValue('D1', '订单状态')
+            ->setCellValue('E1', '收货人')
+            ->setCellValue('F1', '收货人手机号')
+            ->setCellValue('G1', '省')
+            ->setCellValue('H1', '市')
+            ->setCellValue('I1', '区县')
+            ->setCellValue('J1', '收货地址')
+            ->setCellValue('K1', '产品编码')
+            ->setCellValue('L1', '产品名称')
+            ->setCellValue('M1', '产品规格')
+            ->setCellValue('N1', '产品单价')
+            ->setCellValue('O1', '折后单价')
+            ->setCellValue('P1', '产品数量')
+            ->setCellValue('Q1', '优惠金额')
+            ->setCellValue('R1', '产品金额')
+            ->setCellValue('S1', '微伴ID')
+            ->setCellValue('T1', '下单时间');
+        // 返回结果
+        return 					$sheet;
+    }
 
-	/**
-	 * 分享图片
-	 * 
-	 */
-	private function getShareImage($shopName,$score=0){
-		// 尝试执行
-		try {
-			// 加载图片
-			$image		= Image::make(public_path('uploads/images/default/').'order_receipt_share.jpg');
-			// 加载图片
-			$qrcode		= Image::make(public_path('uploads/images/default/').'mp_qrcode.jpg')->resize(100,100);
-			// 设置文字样式(字体、大小、颜色等)
-			$fontPath	= public_path().'/fonts/msyh14.ttf';// 指定字体文件路径
-			// 文本
-			$score 		= $score ? '即将获得'.$score.'积分' : '';
+    /**
+     * 分享图片
+     *
+     */
+    private function getShareImage($shopName,$score=0){
+        // 尝试执行
+        try {
+            // 加载图片
+            $image		= Image::make(public_path('uploads/images/default/').'order_receipt_share.jpg');
+            // 加载图片
+            $qrcode		= Image::make(public_path('uploads/images/default/').'mp_qrcode.jpg')->resize(100,100);
+            // 设置文字样式(字体、大小、颜色等)
+            $fontPath	= public_path().'/fonts/msyh14.ttf';// 指定字体文件路径
+            // 文本
+            $score 		= $score ? '即将获得'.$score.'积分' : '';
 
-			// 给图片写入文字
-			$image->text('恭喜 '.$shopName, 240,60,function (Font $font) use ($fontPath) {
-				$font->file($fontPath);		// 字体文件地址
-				$font->size(24);			// 字体大小
-				$font->color('#FFFFFF');
-				$font->align('center');
-			});
+            // 给图片写入文字
+            $image->text('恭喜 '.$shopName, 240,60,function (Font $font) use ($fontPath) {
+                $font->file($fontPath);		// 字体文件地址
+                $font->size(24);			// 字体大小
+                $font->color('#FFFFFF');
+                $font->align('center');
+            });
 
-			// 给图片写入文字
-			$image->text('完成了一笔订单', 240,100,function (Font $font) use ($fontPath) {
-				$font->file($fontPath);		// 字体文件地址
-				$font->size(24);			// 字体大小
-				$font->color('#FFFFFF');
-				$font->align('center');
-			});
-			// 是否有积分
-			if( $score ){
-				// 给图片写入文字
-				$image->text($score, 240,140,function (Font $font) use ($fontPath) {
-					$font->file($fontPath);		// 字体文件地址
-					$font->size(24);			// 字体大小
-					$font->color('#FFFFFF');
-					$font->align('center');
-				});
-			}
-			// 给图片写入文字
-			$image->text('你也来试试吧', 240,$score?180:140,function (Font $font) use ($fontPath) {
-				$font->file($fontPath);		// 字体文件地址
-				$font->size(24);			// 字体大小
-				$font->color('#FFFFFF');
-				$font->align('center');
-			});
-			// 插入图片
-			$image->insert($qrcode,'bottom-right',10,10);
-			// 转码成字符串
-			$image		= $image->encode('jpg', 90)->__toString();
-			// 转base64
-			$base64		= 'data:image/jpg;base64,' . base64_encode($image);
+            // 给图片写入文字
+            $image->text('完成了一笔订单', 240,100,function (Font $font) use ($fontPath) {
+                $font->file($fontPath);		// 字体文件地址
+                $font->size(24);			// 字体大小
+                $font->color('#FFFFFF');
+                $font->align('center');
+            });
+            // 是否有积分
+            if( $score ){
+                // 给图片写入文字
+                $image->text($score, 240,140,function (Font $font) use ($fontPath) {
+                    $font->file($fontPath);		// 字体文件地址
+                    $font->size(24);			// 字体大小
+                    $font->color('#FFFFFF');
+                    $font->align('center');
+                });
+            }
+            // 给图片写入文字
+            $image->text('你也来试试吧', 240,$score?180:140,function (Font $font) use ($fontPath) {
+                $font->file($fontPath);		// 字体文件地址
+                $font->size(24);			// 字体大小
+                $font->color('#FFFFFF');
+                $font->align('center');
+            });
+            // 插入图片
+            $image->insert($qrcode,'bottom-right',10,10);
+            // 转码成字符串
+            $image		= $image->encode('jpg', 90)->__toString();
+            // 转base64
+            $base64		= 'data:image/jpg;base64,' . base64_encode($image);
 
-			return		$base64;
-		} catch (\Throwable $th) {
-			// 返回路径
-			return 			'';
-		}
-	}
+            return		$base64;
+        } catch (\Throwable $th) {
+            // 返回路径
+            return 			'';
+        }
+    }
 
-}
+}