Selaa lähdekoodia

【Add】小程序添加地址优化

liuxiangxin 4 kuukautta sitten
vanhempi
sitoutus
74cb0b5560

+ 0 - 7
app/Http/Controllers/Api/Custom.php

@@ -62,8 +62,6 @@ class Custom extends Api{
 		$followQrcode					= $custom['weiban_extid'] ?  ['thumb'=>'','link_url'=>''] : $WeiBanQrcode->getFollowQrcode($custom['city_id']);
 		// 城市ID换城市名
 		$cityName						= (string) $City->getOne($custom['city_id'],'name');
-		$pid 							= (int) $City->getOne($custom['city_id'],'pid');
-		$province						= (string)($pid ? $City->getOne($pid,'name') : '');
 		// 所需数组组合
 		$custom							= [
 											'uid'=>$custom['uid'],
@@ -74,11 +72,6 @@ class Custom extends Api{
 											'company_id'=>1, // 无需验证资质
 											'show_price'=>$cityName?1:0, // 是否选择了城市处理
 											'city_id'=>$cityName,
-											'city_info'=>[
-												'city_id'=>$custom['city_id'],
-												'city_name'=>$cityName,
-												'province_name'=>$province,
-											],
 											'follow_qrcode'=>$followQrcode['thumb'],
 											'follow_linkurl'=>$followQrcode['link_url'],
 										];

+ 68 - 0
app/Http/Controllers/Api/CustomAddr.php

@@ -5,6 +5,7 @@ use App\Models\CustomAddr as Model;
 use App\Http\Requests\Api\CustomAddr as Request;
 use App\Models\City;
 use App\Models\Custom;
+use App\Models\WeiBan\Follow as WeiBanFollow;
 
 /**
  * 客户地址
@@ -173,5 +174,72 @@ class CustomAddr extends Api{
 		return							json_send(['code'=>'success','msg'=>'保存成功','data'=>['id'=>$id]]);
 	}
 	
+	/**
+	 * 获取用户地址信息	/api/custom_addr/get_remark_addr
+	 * 
+	 */
+	public function get_remark_addr(Custom $Custom,City $City,WeiBanFollow $WeiBanFollow){
+		// 接口验签
+		// $this->verify_sign();
+		// 检查登录
+		$uid							= $this->checkLogin();
+		// 获取客户城市ID
+		$custom							= $Custom->getOne($uid);
+		// 数据组合
+		$data							= ['contact_province'=>'','contact_city'=>'','contact_area'=>'','contact_addr'=>'','contact_name'=>'','contact_shop'=>'','contact_phone'=>'','shop_type'=>1];
+		// 如果不存在用户信息
+		if( !$custom )					return json_send(['code'=>'success','msg'=>'获取成功','data'=>$data]);
+		// 省份
+        $data['contact_phone']       	= $custom['phone'];
+        // 获取用户城市信息
+        $city                       	= $City->getOne($custom['city_id']);
+        // 如果有城市信息
+        if( !$city )                	return json_send(['code'=>'success','msg'=>'获取成功','data'=>$data]);
+        // 获取上级城市/省份
+        $parentCity 		            = $City->getOne($city['pid']);
+        // 如果上级是省辖,获取省份
+        if( isset($parentCity['name']) && $parentCity['name'] == '直辖县级' )  $parentCity = $City->getOne($parentCity['pid']);
+        // 如果有获取到省份信息
+        if( !$parentCity )          	return json_send(['code'=>'success','msg'=>'获取成功','data'=>$data]);
+        // 省份
+        $data['contact_province']       = $parentCity['name'];
+        // 省份
+        $data['contact_city']           = $city['name'];
+        // 如果用户没有绑定对应的微伴账号
+		if( !$custom['weiban_extid'] )	return json_send(['code'=>'success','msg'=>'获取成功','data'=>$data]);
+		// 获取客服对应的备注等信息
+		$follow							= $WeiBanFollow->getListByWeibanExtid($custom['weiban_extid']);
+		// 获取备注列表
+		$remark							= array_filter(array_column($follow,'remark'),function($value) {return !empty($value);});
+		// 获取备注列表
+		$contactShop					= array_filter(array_column($follow,'remark_corp_name'),function($value) {return !empty($value);});
+		// 如果有备注信息
+		if( isset($remark[0]) )			$data['contact_name']	= $remark[0];
+		// 如果有备注信息
+		if( isset($contactShop[0]) )	$data['contact_shop']	= $contactShop[0];
+		// 返回结果
+		return							json_send(['code'=>'success','msg'=>'获取成功','data'=>$data]);
+	}
+
+	/**
+	 * 获取可能性地址	/api/custom_addr/get_guess_addr
+	 * 
+	 */
+	public function get_guess_addr(Request $request,Model $Model){
+		// 接口验签
+		// $this->verify_sign();
+		// 检查登录
+		$uid							= $this->checkLogin();
+		// 接收参数
+		$request->scene('get_guess_addr')->validate();
+		// 接收参数
+		$contactShop					= request('contact_shop','');
+		// 获取参数
+		$map							= [['contact_shop','LIKE','%'.$contactShop.'%']];
+		// 查询
+		$list							= $Model->query()->where($map)->limit('20')->get(['contact_province','contact_city','contact_area','contact_addr','contact_shop','shop_type'])->toArray();
+		// 返回结果
+		return							json_send(['code'=>'success','msg'=>'获取成功','data'=>$list]);
+	}
 
 }

+ 3 - 0
app/Http/Requests/Api/CustomAddr.php

@@ -27,6 +27,7 @@ class CustomAddr extends BaseRequest
             'contact_addr'          => 'required|max:64',
             // 备注
             'contact_name'          => 'required|max:20',
+            'contact_shop'          => 'required|max:20',
             'contact_phone'         => 'required|phone',
         ];
     }
@@ -37,6 +38,7 @@ class CustomAddr extends BaseRequest
         'edit'                  => ['id','contact_province','contact_city','contact_area','contact_name','contact_phone'],
         'del'                   => ['id'],
         'set_default'           => ['id'],
+        'get_guess_addr'        => ['contact_shop'],
 	];
 
     /**
@@ -56,6 +58,7 @@ class CustomAddr extends BaseRequest
             'contact_area.max'   	    => '区县超长啦',
             'contact_addr.max'   	    => '地址超长啦',
             'contact_name.required'   	=> '请填写收件人',
+            'contact_shop.required'   	=> '请填写终端名称',
             'contact_phone.required'    => '请填写收件人手机号',
             'contact_phone.phone'       => '请填写正确的手机号',
             'id.required'               => '请选择地址',

+ 4 - 1
routes/api.php

@@ -86,7 +86,10 @@ Route::any('custom_addr/del',[\App\Http\Controllers\Api\CustomAddr::class,'del']
 Route::any('custom_addr/get_list',[\App\Http\Controllers\Api\CustomAddr::class,'get_list']);
 // 列表
 Route::any('custom_addr/set_default',[\App\Http\Controllers\Api\CustomAddr::class,'set_default']);
-
+// 列表
+Route::any('custom_addr/get_remark_addr',[\App\Http\Controllers\Api\CustomAddr::class,'get_remark_addr']);
+// 列表
+Route::any('custom_addr/get_guess_addr',[\App\Http\Controllers\Api\CustomAddr::class,'get_guess_addr']);
 
 // 积分信息
 Route::any('custom_score/get_info',[\App\Http\Controllers\Api\CustomScore::class,'get_info']);