|
@@ -3,9 +3,12 @@
|
|
|
use App\Http\Requests\Admin\Custom as Request;
|
|
|
use App\Models\City;
|
|
|
use App\Models\Custom as Model;
|
|
|
+use App\Models\CustomAddr;
|
|
|
use App\Models\CustomScore;
|
|
|
use Illuminate\Support\Carbon;
|
|
|
use App\Models\WeiBan\Follow as WeiBanFollow;
|
|
|
+use App\Models\FilesManager;
|
|
|
+use App\Models\WeiBan\External as WeiBanExternal;
|
|
|
|
|
|
/**
|
|
|
* 客户管理
|
|
@@ -164,5 +167,52 @@ class Custom extends Auth{
|
|
|
return json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 表格导入
|
|
|
+ *
|
|
|
+ * */
|
|
|
+ public function import_execl( Request $request,Model $Model,FilesManager $FilesManager,City $City,CustomAddr $CustomAddr,WeiBanExternal $WeiBanExternal){
|
|
|
+ // 验证参数
|
|
|
+ $request->scene('import_execl')->validate();
|
|
|
+ // 获取表格信息
|
|
|
+ $file = request()->file('custom_file');
|
|
|
+ // 返回结果
|
|
|
+ $sheetList = $FilesManager->excelToCustom($file);
|
|
|
+ // 如果不存在结果
|
|
|
+ if( isset($sheetList['error']) ) return json_send(['code'=>'error','msg'=>$sheetList['error']]);
|
|
|
+ // 循环表格数据
|
|
|
+ foreach ($sheetList as $value) {
|
|
|
+ // 获取城市ID
|
|
|
+ $value['city_id'] = 0;
|
|
|
+ // 存在城市名称,查询城市ID
|
|
|
+ if( $value['contact_city'] ) {
|
|
|
+ // 获取城市ID
|
|
|
+ $value['city_id'] = (int) $City->getIdByName($value['contact_city']);
|
|
|
+ // 如果城市不存在的话
|
|
|
+ if ( !$value['city_id'] ) return json_send(['code'=>'error','msg'=>$value['contact_city'].' => 未找到匹配的城市,请核对城市全称']);
|
|
|
+ }
|
|
|
+ // 获取手机号,查询是否用客户
|
|
|
+ $custom = $Model->getOneByPhone($value['phone']);
|
|
|
+ // 组装数据
|
|
|
+ $data = ['weiban_extid'=>$value['weiban_extid'],'username'=>$value['username']];
|
|
|
+ // 如果客户不存在
|
|
|
+ if( !$custom ) $data['phone'] = $value['phone'];
|
|
|
+ // 如果存在城市ID,才修改城市
|
|
|
+ if( $value['city_id'] ) $data['city_id'] = $value['city_id'];
|
|
|
+ // 如果存在手机号
|
|
|
+ $uid = $custom ? $Model->edit($custom['uid'],$data) : $Model->add($data);
|
|
|
+ // 如果客户存在
|
|
|
+ if( !$uid ) return json_send(['code'=>'error','msg'=>$value['username'].'【'.$value['phone'].'】'.'用户创建或者更新失败']);
|
|
|
+ // 存在详细地址,才创建地址库
|
|
|
+ if( $value['contact_name'] && $value['contact_phone'] && $value['contact_province'] && $value['contact_city'] && $value['contact_area'] && $value['contact_addr'] ) {
|
|
|
+ // 收件地址是否存在
|
|
|
+ $oldAddr = $CustomAddr->query()->where([['custom_uid','=',$uid]])->first();
|
|
|
+ // 如果不存在地址
|
|
|
+ if( !$oldAddr ) $CustomAddr->add(['custom_uid'=>$uid,'contact_name'=>$value['contact_name'],'contact_shop'=>$value['contact_shop'],'contact_phone'=>$value['contact_phone'],'contact_province'=>$value['contact_province'],'contact_city'=>$value['contact_city'],'contact_area'=>$value['contact_area'],'contact_addr'=>$value['contact_addr']]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 提示成功
|
|
|
+ return json_send(['code'=>'success','msg'=>'批量导入成功','path'=>'']);
|
|
|
+ }
|
|
|
|
|
|
}
|