|
@@ -5,6 +5,7 @@ use App\Models\Custom;
|
|
|
use App\Models\CustomScore as Model;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use App\Models\FilesManager;
|
|
|
+use App\Models\WeiBan\External as WeiBanExternal;
|
|
|
|
|
|
/**
|
|
|
* 客户管理
|
|
@@ -138,5 +139,48 @@ class CustomScore extends Auth{
|
|
|
return json_send(['code'=>'success','msg'=>'批量导入成功','path'=>'']);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 表格导入
|
|
|
+ *
|
|
|
+ * */
|
|
|
+ public function import_weiban( Request $request,Model $Model,Custom $Custom,FilesManager $FilesManager,WeiBanExternal $WeiBanExternal){
|
|
|
+ // 验证参数
|
|
|
+ $request->scene('import_execl')->validate();
|
|
|
+ // 获取表格信息
|
|
|
+ $file = request()->file('score_file');
|
|
|
+ // 返回结果
|
|
|
+ $sheetList = $FilesManager->weibanToScore($file);
|
|
|
+ // 如果不存在结果
|
|
|
+ if( isset($sheetList['error']) ) return json_send(['code'=>'error','msg'=>$sheetList['error']]);
|
|
|
+ // 通过微伴ID查询用户ID
|
|
|
+ $uidList = $WeiBanExternal->query()->whereIn('id',array_column($sheetList,'weiban_extid'))->pluck('custom_uid','id')->toArray();
|
|
|
+ // 循环列表
|
|
|
+ foreach ($sheetList as $key=>$value) {
|
|
|
+ // 如果查询不到数据
|
|
|
+ if( empty($uidList[$value['weiban_extid']]) ) return json_send(['code'=>'error','msg'=>$value['weiban_extid'].'不在系统内']);
|
|
|
+ // 获取客户ID
|
|
|
+ $value['custom_uid'] = $uidList[$value['weiban_extid']];
|
|
|
+ // 重组
|
|
|
+ $sheetList[$key] = $value;
|
|
|
+ }
|
|
|
+ // 组合数据,写入订单表,子表
|
|
|
+ DB::beginTransaction();
|
|
|
+ // 循环表格数据
|
|
|
+ foreach ($sheetList as $value) {
|
|
|
+ // 写入数据表
|
|
|
+ $payId = $Model->trade($value['custom_uid'],0,$value['score'],4,($value['score']>0?1:2),$value['description']);
|
|
|
+ // 如果操作失败
|
|
|
+ if( isset($payId['error']) ) {
|
|
|
+ // 回滚
|
|
|
+ DB::rollBack();
|
|
|
+ // 结果提示
|
|
|
+ return json_send(['code'=>'error','msg'=>$value['weiban_extid'].'=>'.$payId['error']]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 提交事务
|
|
|
+ DB::commit();
|
|
|
+ // 提示成功
|
|
|
+ return json_send(['code'=>'success','msg'=>'批量导入成功','path'=>'']);
|
|
|
+ }
|
|
|
|
|
|
}
|