Przeglądaj źródła

【Mod】微伴ID不存在的统一提示

liuxiangxin 5 miesięcy temu
rodzic
commit
6061b86657
1 zmienionych plików z 29 dodań i 15 usunięć
  1. 29 15
      app/Http/Controllers/Admin/CustomScore.php

+ 29 - 15
app/Http/Controllers/Admin/CustomScore.php

@@ -154,10 +154,18 @@ class CustomScore extends Auth{
 		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();
+		// 未知用户
+		$noUsers							= [];
 		// 循环列表
 		foreach ($sheetList as $key=>$value) 		{
 			// 如果查询不到数据
-			if( empty($uidList[$value['weiban_extid']]) )   return json_send(['code'=>'error','msg'=>$value['weiban_extid'].'不在系统内']);
+			if( empty($uidList[$value['weiban_extid']]) )   {
+				// 判断
+				$noUsers[]					= $value['weiban_extid'];
+				$noUsers[]					= $value['weiban_extid'];
+				unset($sheetList[$key]);
+				continue;
+			}
 			// 获取客户ID
 			$value['custom_uid']			= $uidList[$value['weiban_extid']];
 			// 重组
@@ -165,22 +173,28 @@ class CustomScore extends Auth{
 		}
 		// 组合数据,写入订单表,子表
 		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']]);
+		// 错误信息
+		try {
+			// 循环表格数据
+			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'=>($noUsers? ' 以下不存用户<br/>'.implode('<br/>',$noUsers) : '批量导入成功'),'path'=>'']);
+		} catch (\Throwable $th) {
+			// 提示成功
+			return								json_send(['code'=>'success','msg'=>'批量导入失败','path'=>'','data'=>['error'=>$th->getMessage()]]);
 		}
-		// 提交事务
-		DB::commit();
-		// 提示成功
-		return								json_send(['code'=>'success','msg'=>'批量导入成功','path'=>'']);
 	}
 
 }