Эх сурвалжийг харах

【Mod】修复微伴客户同步问题,修改banner可以跳转小程序添加客服页面以及城市

liuxiangxin 7 сар өмнө
parent
commit
11c4362bb7

+ 1 - 0
app/Facades/Servers/WeiBan/OpenApi.php

@@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Facade;
  * @method static string getAccessToken()                                                                   获取凭证
  * @method static array  getUserList(int $limit,int $offset,int $startTime=0,string $source='remark')       获取用户列表
  * @method static array  getUserDetail(string $id)                                                          获取用户详情
+ * @method static array  getUserListByPhone($phone)                                                         通过手机获取用户列表
  * 
  * 
  * @see \App\Servers\WeiBan\OpenApi

+ 4 - 0
app/Http/Controllers/Admin/Custom.php

@@ -110,6 +110,10 @@ class Custom extends Auth{
 		if(request()->isMethod('post')){
 			// 验证参数
 			$request->scene('edit')->validate();
+			// 如果用户不存在
+			if( !$oldData )			return json_send(['code'=>'error','msg'=>'用户不存在']);
+			// 转数组
+			$oldData				= $oldData->toArray();
 			// 接收数据
 			$data['username']		= request('username','');
 			$data['phone']			= request('phone','');

+ 1 - 1
app/Http/Controllers/Admin/OrdersBanner.php

@@ -15,7 +15,7 @@ class OrdersBanner extends Auth{
 	protected function _initialize(){
 		parent::_initialize();
 		$this->assign('breadcrumb1','营销管理');
-		$this->assign('breadcrumb2','首页轮播');
+		$this->assign('breadcrumb2','下单活动');
 	}
 	
 	/**

+ 19 - 4
app/Http/Controllers/Api/Custom.php

@@ -1,5 +1,6 @@
 <?php namespace App\Http\Controllers\Api;
 
+use App\Facades\Servers\WeiBan\OpenApi;
 use App\Http\Controllers\Api\Api;
 use App\Models\Custom as Model;
 use App\Models\WeiBan\Qrcode as WeiBanQrcode;
@@ -36,8 +37,20 @@ class Custom extends Api{
 		if( !$custom['weiban_extid'] )	{
 			// 通过手机号查询注册的账号
 			$custom['weiban_extid'] 	= (string) $WeiBanFollow->query()->where([['phone_number','=',$custom['phone']]])->value('weiban_extid');
-			// 如果存在的话,修正
-			if( $custom['weiban_extid'] ) $Model->edit($custom['uid'],['weiban_extid'=>$custom['weiban_extid']]);
+			// 不存在,通过接口获取数据
+			if( !$custom['weiban_extid'] ) {
+				// 获取用户列表
+				$userList 				= OpenApi::getUserListByPhone($custom['phone']);
+				// 如果有的话
+				if( $userList )			{
+					// 获取第一个
+					$extUser			= array_shift($userList);
+					// 获取对应的ID
+					$custom['weiban_extid'] = empty($extUser['id']) ? '' : $extUser['id'];
+				}
+			}
+			// 存在则修正
+			if( $custom['weiban_extid'] )	$Model->edit($custom['uid'],['weiban_extid'=>$custom['weiban_extid']]);
 		}
 		// 头像
 		$custom['uid']					= Hashids::encodeHex($custom['uid']);
@@ -45,6 +58,8 @@ class Custom extends Api{
 		$custom['userpic']				= $custom['userpic'] ? path_compat($custom['userpic']) : '';
 		// 手机号
 		$custom['phone']				= hide_phone($custom['phone']);
+		// 二维码
+		$followQrcode					= $WeiBanQrcode->getFollowQrcode();
 		// 所需数组组合,如果没有关联企微,获取二维码,已添加好友的不验证
 		$custom							= [
 											'uid'=>$custom['uid'],
@@ -52,9 +67,9 @@ class Custom extends Api{
 											'userpic'=>$custom['userpic'],
 											'phone'=>$custom['phone'],
 											'company_id'=>1, // 无需验证资质
-											'show_price'=>($custom['weiban_extid']?1:0), // 用于判断是否显示价格
+											'show_price'=>$custom['city_id']?1:0, // 是否选择了城市处理
 											'city_id'=>(string)$City->getOne($custom['city_id'],'name'),
-											'follow_qrcode'=>($custom['weiban_extid'] ? '' : $WeiBanQrcode->getFollowQrcode())
+											'follow_qrcode'=>$followQrcode,
 										];
 		// 返回结果
 		return							json_send(['code'=>'success','msg'=>'获取成功','data'=>$custom]);

+ 1 - 1
app/Http/Controllers/Api/Product.php

@@ -95,7 +95,7 @@ class Product extends Api{
 		$data						= $data->toArray();
 		// 处理数据
 		$data['thumb'] 				= path_compat($data['thumb']);
-		$data['poster'] 			= path_compat($data['poster']);
+		$data['poster'] 			= $data['poster'] ? path_compat($data['poster']) : '';
 		$data['description'] 		= $Model->getDesc($id);
 		$data['business_info'] 		= $Business->getOne($data['business_id']);
 		// 获取产品属性

+ 34 - 0
app/Servers/WeiBan/OpenApi.php

@@ -99,6 +99,40 @@ class OpenApi
         return                              ['total'=>$result['total'],'user_list'=>$result['external_user_list']];
     }
 
+
+    /**
+     * 获取手机号用户
+     * 
+     * @param       string      $phone     手机号
+     * 
+     */
+    public function getUserListByPhone($phone){
+        // 获取调用凭证
+        $accessToken                        = $this->getAccessToken();
+        // 如果没有返回
+        if( !$accessToken )                 return [];
+        // 参数
+        $param                              = ['phone_number'=>$phone,'access_token'=>$accessToken];
+        // 组装接口
+        $url                                = $this->domain.'/open-api/external_user/list';
+        // 调用接口
+        $result                             = Curl::to($url)->withData($param)->asJson(true)->get();
+        // 如果没有返回
+        if( !isset($result['errcode']) )    {
+            Log::error('weiban_openai/external_user_list','未获取到用户列表');
+            return                          [];
+        }
+        // 如果是凭证错误,递归
+        if( $result['errcode'] == '10001' ) return $this->getUserListByPhone($phone);
+        // 调用失败
+        if( $result['errcode'] != 0 )       {
+            Log::error('weiban_openai/external_user_list',$result['errcode'].'=>'.$result['errmsg']);
+            return                          [];
+        }
+        // 返回结果
+        return                              $result['external_user_list'];
+    }
+
     /**
      * 获取用户详情
      * 

+ 1 - 1
resources/views/admin/banner/add.blade.php

@@ -19,7 +19,7 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 	</div>
 	<div class="form-group col-sm-5">
 		<label class="control-label">跳转链接</label>
-		<input class="form-control" type="url" placeholder="跳转链接" maxlength="120" name="link_url" value="" />
+		<input class="form-control" type="text" placeholder="跳转链接,/pages/user/follow 添加客服路径" maxlength="120" name="link_url" value="" />
 	</div>
 	<div class="form-group col-sm-5">
 		<label class="control-label">显示城市</label>

+ 1 - 1
resources/views/admin/banner/edit.blade.php

@@ -19,7 +19,7 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 	</div>
 	<div class="form-group col-sm-5">
 		<label class="control-label">跳转链接</label>
-		<input class="form-control" type="url" placeholder="跳转链接" maxlength="120" name="link_url" value="{{$oldData['link_url']}}" />
+		<input class="form-control" type="text" placeholder="跳转链接 '/pages/user/follow' 添加客服路径" maxlength="120" name="link_url" value="{{$oldData['link_url']}}" />
 	</div>
 	<div class="form-group col-sm-5">
 		<label class="control-label">服务城市</label>

+ 3 - 3
resources/views/admin/orders_banner/add.blade.php

@@ -19,9 +19,9 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 	</div>
 	<div class="form-group col-sm-5">
 		<label class="control-label">跳转链接</label>
-		<input class="form-control" type="url" placeholder="跳转链接" maxlength="120" name="link_url" value="" />
+		<input class="form-control" type="text" placeholder="跳转链接 /pages/user/follow 添加客服路径" maxlength="120" name="link_url" value="" />
 	</div>
-	<!-- <div class="form-group col-sm-5">
+	<div class="form-group col-sm-5">
 		<label class="control-label">显示城市</label>
 		<select name="city_ids[]" class="form-control selectpicker" data-live-search="true" data-live-search-placeholder="搜索城市" data-none-results-text="未搜索到 {0}" title="选择城市" multiple>
 			@foreach ($cityList as $group)
@@ -32,7 +32,7 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 			</optgroup>
 			@endforeach
 		</select>
-	</div> -->
+	</div>
 	<div class="form-group col-sm-12">
 		@csrf
 		<input id="send" type="submit" value="提交" class="btn btn-primary btn-block" />

+ 3 - 3
resources/views/admin/orders_banner/edit.blade.php

@@ -19,9 +19,9 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 	</div>
 	<div class="form-group col-sm-5">
 		<label class="control-label">跳转链接</label>
-		<input class="form-control" type="url" placeholder="跳转链接" maxlength="120" name="link_url" value="{{$oldData['link_url']}}" />
+		<input class="form-control" type="text" placeholder="跳转链接 /pages/user/follow 添加客服路径" maxlength="120" name="link_url" value="{{$oldData['link_url']}}" />
 	</div>
-	<!-- <div class="form-group col-sm-5">
+	<div class="form-group col-sm-5">
 		<label class="control-label">服务城市</label>
 		<select name="city_ids[]" class="form-control selectpicker" data-live-search="true" data-live-search-placeholder="搜索城市" data-none-results-text="未搜索到 {0}" title="选择城市" multiple>
 			@foreach ($cityList as $group)
@@ -32,7 +32,7 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 			</optgroup>
 			@endforeach
 		</select>
-	</div> -->
+	</div>
 	<div class="form-group col-sm-12">
 		@csrf
 		<input type="hidden" name="id" value="{{$oldData['id']}}" />