|
@@ -4,7 +4,6 @@ namespace App\Jobs;
|
|
|
|
|
|
use App\Facades\Servers\Logs\Log;
|
|
use App\Facades\Servers\Logs\Log;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Bus\Queueable;
|
|
-use Illuminate\Contracts\Queue\ShouldBeUnique;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
@@ -15,6 +14,8 @@ use App\Models\Custom;
|
|
use App\Models\WeiBan\External as WeiBanExternal;
|
|
use App\Models\WeiBan\External as WeiBanExternal;
|
|
use App\Models\WeiBan\Follow as WeiBanFollow;
|
|
use App\Models\WeiBan\Follow as WeiBanFollow;
|
|
use App\Models\WeiBan\Tags as WeiBanTags;
|
|
use App\Models\WeiBan\Tags as WeiBanTags;
|
|
|
|
+use App\Models\City;
|
|
|
|
+use App\Models\CustomAddr;
|
|
|
|
|
|
class WeiBanSync implements ShouldQueue
|
|
class WeiBanSync implements ShouldQueue
|
|
{
|
|
{
|
|
@@ -98,6 +99,8 @@ class WeiBanSync implements ShouldQueue
|
|
$extUser = ['id'=>$extUser['id'],'name'=>$extUser['name'],'avatar'=>str_ireplace('http://','https://',(string)$extUser['avatar']),'gender'=>$extUser['gender'],'type'=>$extUser['type'],'corp_name'=>(string)$extUser['corp_name'],'corp_full_name'=>(string)$extUser['corp_full_name'],'insert_time'=>$extUser['created_at'],'update_time'=>time(),'custom_uid'=>0];
|
|
$extUser = ['id'=>$extUser['id'],'name'=>$extUser['name'],'avatar'=>str_ireplace('http://','https://',(string)$extUser['avatar']),'gender'=>$extUser['gender'],'type'=>$extUser['type'],'corp_name'=>(string)$extUser['corp_name'],'corp_full_name'=>(string)$extUser['corp_full_name'],'insert_time'=>$extUser['created_at'],'update_time'=>time(),'custom_uid'=>0];
|
|
// 手机号
|
|
// 手机号
|
|
$phone = '';
|
|
$phone = '';
|
|
|
|
+ // 标签处理
|
|
|
|
+ $staffId = '';
|
|
// 循环跟进客服
|
|
// 循环跟进客服
|
|
foreach ( $followList as $follow ) {
|
|
foreach ( $followList as $follow ) {
|
|
// 标签处理
|
|
// 标签处理
|
|
@@ -115,6 +118,13 @@ class WeiBanSync implements ShouldQueue
|
|
if( $oldExtUser ) $extUser['custom_uid'] = ($oldExtUser->custom_uid);
|
|
if( $oldExtUser ) $extUser['custom_uid'] = ($oldExtUser->custom_uid);
|
|
// 存在手机号,才创建账号
|
|
// 存在手机号,才创建账号
|
|
if( $phone ) $extUser['custom_uid'] = $this->customHandle($phone,$extUser,$Custom);
|
|
if( $phone ) $extUser['custom_uid'] = $this->customHandle($phone,$extUser,$Custom);
|
|
|
|
+ // 需要有客服,如果存在的旧账号但是 没有关联客户UID 还存在系统客户UID可关联
|
|
|
|
+ if( $staffId && isset($oldExtUser['custom_uid']) && empty($oldExtUser['custom_uid']) && $extUser['custom_uid'] ){
|
|
|
|
+ // 城市标签
|
|
|
|
+ $this->cityTags($extUser,$staffId,$Custom);
|
|
|
|
+ // 终端标签
|
|
|
|
+ $this->shopTypeTag($staffId,$extUser);
|
|
|
|
+ }
|
|
// 新增或者修改
|
|
// 新增或者修改
|
|
$External->query()->upsert($extUser,'id',['name','avatar','gender','type','corp_name','corp_full_name','status','custom_uid','update_time']);
|
|
$External->query()->upsert($extUser,'id',['name','avatar','gender','type','corp_name','corp_full_name','status','custom_uid','update_time']);
|
|
}
|
|
}
|
|
@@ -162,7 +172,6 @@ class WeiBanSync implements ShouldQueue
|
|
return $uid;
|
|
return $uid;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 客服处理
|
|
* 客服处理
|
|
*/
|
|
*/
|
|
@@ -195,5 +204,73 @@ class WeiBanSync implements ShouldQueue
|
|
$followId ? $Follow->edit($followId,$follow) : $Follow->add($follow);
|
|
$followId ? $Follow->edit($followId,$follow) : $Follow->add($follow);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 城市标签
|
|
|
|
+ */
|
|
|
|
+ private function cityTags($extUser,$staffId,Custom $Custom){
|
|
|
|
+ // 实例化
|
|
|
|
+ $City = New City();
|
|
|
|
+ // 获取城市ID
|
|
|
|
+ $cityId = $Custom->getValue($extUser['custom_uid'],'city_id');
|
|
|
|
+ // 如果有城市
|
|
|
|
+ if( !$cityId ) return ['info'=>'请先设置城市'];
|
|
|
|
+ // 获取用户城市信息
|
|
|
|
+ $city = $City->getOne($cityId);
|
|
|
|
+ // 如果有城市信息
|
|
|
|
+ if( !$city ) return ['info'=>'未查询到城市'];
|
|
|
|
+ // 获取上级城市/省份
|
|
|
|
+ $parentCity = $City->getOne($city['pid']);
|
|
|
|
+ // 如果上级是省辖,获取省份
|
|
|
|
+ if( isset($parentCity['name']) && $parentCity['name'] == '直辖县级' ) $parentCity = $City->getOne($parentCity['pid']);
|
|
|
|
+ // 如果有获取到省份信息
|
|
|
|
+ if( !$parentCity ) return ['info'=>'未查询到省份'];
|
|
|
|
+ // 省份
|
|
|
|
+ $province = str_ireplace(['自治区','壮族','回族','维吾尔','特别行政区','省'],'',$parentCity['name']);
|
|
|
|
+ // 省份
|
|
|
|
+ $cityName = str_ireplace(['自治州','自治县','蒙古','蒙古族','回族','藏族','维吾尔','苗族','彝族','壮族','布依族','朝鲜族','满族','侗族','瑶族','白族','土家族','哈尼族','哈萨克','傣族','黎族','傈僳族','佤族','畲族','拉祜族','水族','东乡族','纳西族','景颇族','柯尔克孜','土族','达斡尔族','仫佬族','羌族','布朗族','撒拉族','毛南族','仡佬族','锡伯','阿昌族','普米族','塔吉克','怒族','鄂温克族','德昂族','保安族','裕固族','塔塔尔','独龙族'],'',$city['name']);
|
|
|
|
+ // 打省份标签
|
|
|
|
+ if( !$province ) return ['info'=>'暂无省份数据'];
|
|
|
|
+ // 打省份标签
|
|
|
|
+ if( !$cityName ) return ['info'=>'暂无城市数据'];
|
|
|
|
+ // 打省份标签
|
|
|
|
+ $result['province'] = OpenApi::addTag($staffId,$extUser['id'],'省份',$province);
|
|
|
|
+ // 打城市标签
|
|
|
|
+ $result['cityNname'] = OpenApi::addTag($staffId,$extUser['id'],$province,$cityName);
|
|
|
|
+ // 返回结果
|
|
|
|
+ return ['success'=>'返回结果','result'=>$result];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 终端类型标签
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ public function shopTypeTag($staffId,$extUser){
|
|
|
|
+ // 地址模型
|
|
|
|
+ $Addr = New CustomAddr();
|
|
|
|
+ // 打终端类型标签
|
|
|
|
+ $shopType = (int) $Addr->query()->where([['custom_uid','=',$extUser['custom_uid']],['shop_type','>',0]])->value('shop_type');
|
|
|
|
+ // 如果有地址信息
|
|
|
|
+ switch ($shopType) {
|
|
|
|
+ case '1':
|
|
|
|
+ $shopType = '单店';
|
|
|
|
+ break;
|
|
|
|
+ case '3':
|
|
|
|
+ $shopType = '连锁';
|
|
|
|
+ break;
|
|
|
|
+ case '4':
|
|
|
|
+ $shopType = '第三终端';
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ $shopType = '';
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ // 没有数据,直接结束
|
|
|
|
+ if( !$shopType ) return ['info'=>'没有终端类型标签'];
|
|
|
|
+ // 如果有终端类型
|
|
|
|
+ $result = OpenApi::addTag($staffId,$extUser['id'],'企业类型',$shopType);
|
|
|
|
+ // 数据返回
|
|
|
|
+ return ['success'=>'返回结果','result'=>$result];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|