|
|
@@ -125,6 +125,7 @@ use Carbon\CarbonPeriod;
|
|
|
use ChangeColumnOrderIdToOrderIssues;
|
|
|
use Doctrine\DBAL\Query\QueryBuilder;
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
+use Illuminate\Database\Eloquent\Model;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
use Illuminate\Http\Request;
|
|
|
@@ -158,8 +159,54 @@ class TestController extends Controller
|
|
|
|
|
|
public function test()
|
|
|
{
|
|
|
+ $a = [[1,2,3]];
|
|
|
+ dd(array_unshift($a,["code","name","type"]),$a);
|
|
|
return view("test");
|
|
|
}
|
|
|
+ public function handle()
|
|
|
+ {
|
|
|
+ $carriers = DB::connection("oracle")->select(DB::raw("SELECT CUSTOMERID,CUSTOMER_TYPE,DESCR_C,CASE DESCR_E WHEN 'WL' THEN '物流' ELSE '快递' END AS TYPE FROM BAS_CUSTOMER WHERE CUSTOMER_TYPE = 'CA'"));
|
|
|
+ $logistics = Logistic::query()->whereIn("code",array_column($carriers,"customerid"))->get();
|
|
|
+ $changes = diff($carriers,$logistics,"code",["code"=>"customerid","name"=>"descr_c","type"=>"type"]);
|
|
|
+ dd($changes);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function diff($array1,$array2,$identification,$mapping):array
|
|
|
+ {
|
|
|
+ $changes = [
|
|
|
+ 'attached' => [], 'detached' => [], 'updated' => [],
|
|
|
+ ];
|
|
|
+ $map = [];
|
|
|
+ foreach ($array2 as $item){
|
|
|
+ if (is_array($item))$map[$item[$identification]] = $item;
|
|
|
+ else $map[$item->$identification] = json_decode($item,true);
|
|
|
+ }
|
|
|
+ foreach ($array1 as $item){
|
|
|
+ /** @var \stdClass|array|Model $item */
|
|
|
+ if (!is_array($item) && !is_subclass_of($item,Model::class))$item = (array)$item;
|
|
|
+ if (!isset($map[$item[$mapping[$identification]]])){
|
|
|
+ $obj = [];
|
|
|
+ foreach ($mapping as $column2=>$column1)$obj[$column2] = $item[$column1];
|
|
|
+ $changes['attached'][] = $obj;continue;
|
|
|
+ }
|
|
|
+ $sign = false;
|
|
|
+ $obj = [];
|
|
|
+ foreach ($mapping as $column2=>$column1){
|
|
|
+ $obj[$column2] = $item[$column1];
|
|
|
+ if ($map[$item[$mapping[$identification]]][$column2] != $item[$column1])$sign = true;
|
|
|
+ }
|
|
|
+ if ($sign)$changes['updated'][] = $obj;
|
|
|
+ unset($map[$item[$mapping[$identification]]]);
|
|
|
+ }
|
|
|
+ //返回列表跟返回KEY
|
|
|
+ /*foreach ($map as $item){
|
|
|
+ $obj = [];
|
|
|
+ foreach ($mapping as $column2=>$column1)$obj[$column2] = $item[$column2];
|
|
|
+ $changes['detached'][] = $obj;
|
|
|
+ }*/
|
|
|
+ if ($map)$changes['detached'][] = array_keys($map);
|
|
|
+ return $changes;
|
|
|
+ }
|
|
|
public function assignBatch(){
|
|
|
$batches = collect([
|
|
|
[
|