TestController.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Authority;
  4. use App\Batch;
  5. use App\Commodity;
  6. use App\CommodityBarcode;
  7. use App\CommodityMaterialBoxModel;
  8. use App\Components\AsyncResponse;
  9. use App\Components\Database;
  10. use App\Components\ErrorPush;
  11. use App\ErrorTemp;
  12. use App\Feature;
  13. use App\Http\ApiControllers\LoginController;
  14. use App\Http\Controllers\api\thirdPart\haochuang\SortingController;
  15. use App\Http\Controllers\api\thirdPart\syrius\beans\StorageTypeCell;
  16. use App\Http\Controllers\api\thirdPart\syrius\beans\StorageTypeRelation;
  17. use App\Http\Controllers\api\thirdPart\syrius\beans\Task;
  18. use App\Http\Controllers\api\thirdPart\syrius\beans\TaskItem;
  19. use App\Http\Controllers\api\thirdPart\syrius\producer\StorageTypeController;
  20. use App\Http\Controllers\api\thirdPart\syrius\units\Signature;
  21. use App\Http\Controllers\api\thirdPart\syrius\units\StorageTypeAttribute;
  22. use App\Http\Requests\AndroidGateRequest;
  23. use App\Http\Requests\OrderDelivering;
  24. use App\Jobs\BatchTaskJob;
  25. use App\Jobs\BroadcastBatchToZhengCangJob;
  26. use App\Jobs\CacheShelfTaskJob;
  27. use App\Jobs\OrderCreateInstantBill;
  28. use App\Jobs\OrderCreateWaybill;
  29. use App\Jobs\SettlementBillReportJob;
  30. use App\Jobs\StoreCreateInstantBill;
  31. use App\Jobs\TestJob;
  32. use App\Jobs\WeightUpdateInstantBill;
  33. use App\LaborCompanyDispatch;
  34. use App\LaborReport;
  35. use App\LaborReportStatus;
  36. use App\Logistic;
  37. use App\MaterialBox;
  38. use App\MaterialBoxModel;
  39. use App\Notifications\RoutineNotification;
  40. use App\OracleDOCASNHeader;
  41. use App\OracleDOCOrderHeader;
  42. use App\OracleDocOrderPackingSummary;
  43. use App\OracleDOCWaveDetails;
  44. use App\Order;
  45. use App\OrderBin;
  46. use App\OrderCommodity;
  47. use App\OrderIssue;
  48. use App\OrderIssueProcessLog;
  49. use App\OrderPackage;
  50. use App\Owner;
  51. use App\OwnerAreaReport;
  52. use App\OwnerBillReport;
  53. use App\OwnerFeeDetail;
  54. use App\OwnerFeeDetailLogistic;
  55. use App\OwnerFeeExpress;
  56. use App\OwnerFeeLogistic;
  57. use App\OwnerFeeOperation;
  58. use App\OwnerFeeOperationDetail;
  59. use App\OwnerFeeStorage;
  60. use App\OwnerPriceExpress;
  61. use App\OwnerPriceOperation;
  62. use App\OrderPackageCountingRecord;
  63. use App\OwnerReport;
  64. use App\ProcurementCheckSheet;
  65. use App\RejectedBill;
  66. use App\SeeLog;
  67. use App\Services\AuthorityService;
  68. use App\Services\BatchService;
  69. use App\Services\CacheShelfService;
  70. use App\Services\common\BatchUpdateService;
  71. use App\Services\ForeignHaiRoboticsService;
  72. use App\Services\ForeignZhenCangService;
  73. use App\Services\LogisticService;
  74. use App\Services\LogService;
  75. use App\Services\NotificationService;
  76. use App\Services\OracleDOCOrderHeaderService;
  77. use App\Services\OrderPackageCommoditiesService;
  78. use App\Services\OrderPackageReceivedSyncService;
  79. use App\Services\OrderPackageService;
  80. use App\Services\OrderService;
  81. use App\Services\OwnerFeeTotalService;
  82. use App\Services\OwnerLogisticFeeReportService;
  83. use App\Services\OwnerPriceOperationService;
  84. use App\Services\OwnerService;
  85. use App\Services\OwnerStoreFeeReportService;
  86. use App\Services\OwnerStoreOutFeeReportService;
  87. use App\Services\ReplenishmentService;
  88. use App\Services\ReviewService;
  89. use App\Services\StationService;
  90. use App\Services\StorageService;
  91. use App\Services\StoreService;
  92. use App\Services\SyriusTaskService;
  93. use App\SortingStation;
  94. use App\Station;
  95. use App\StationTask;
  96. use App\StationTaskMaterialBox;
  97. use App\Store;
  98. use App\StoreItem;
  99. use App\TaskTransaction;
  100. use App\Unit;
  101. use App\User;
  102. use App\UserDetail;
  103. use App\UserDutyCheck;
  104. use App\ValueStore;
  105. use App\Waybill;
  106. use App\WorkOrder;
  107. use Carbon\Carbon;
  108. use Carbon\CarbonPeriod;
  109. use Decimal\Decimal;
  110. use Doctrine\DBAL\Driver\AbstractDB2Driver;
  111. use Doctrine\DBAL\Exception;
  112. use Firebase\JWT\ExpiredException;
  113. use Firebase\JWT\JWT;
  114. use Illuminate\Database\Eloquent\Builder;
  115. use Illuminate\Database\Eloquent\Collection;
  116. use Illuminate\Database\Eloquent\HigherOrderBuilderProxy;
  117. use Illuminate\Database\QueryException;
  118. use Illuminate\Foundation\Http\FormRequest;
  119. use Illuminate\Http\Request;
  120. use Illuminate\Support\Facades\Broadcast;
  121. use Illuminate\Support\Facades\Cache;
  122. use Illuminate\Support\Facades\Auth;
  123. use Illuminate\Support\Facades\Cookie;
  124. use Illuminate\Support\Facades\DB;
  125. use Illuminate\Support\Facades\Http;
  126. use Illuminate\Support\Facades\Log;
  127. use Illuminate\Support\Facades\Notification;
  128. use Illuminate\Support\Facades\URL;
  129. use Illuminate\Support\Facades\Validator;
  130. use Illuminate\Support\Str;
  131. use Laravel\Horizon\Events\JobFailed;
  132. use Monolog\Handler\IFTTTHandler;
  133. use phpDocumentor\Reflection\Types\Resource_;
  134. use PhpOffice\PhpSpreadsheet\Calculation\Web\Service;
  135. use Ramsey\Uuid\Uuid;
  136. use Symfony\Component\ErrorHandler\Error\FatalError;
  137. class TestController extends Controller
  138. {
  139. use AsyncResponse, ErrorPush, Database;
  140. const ASNREFERENCE_2 = 'ASNREFERENCE2';
  141. public function __construct()
  142. {
  143. $this->data["active_test"] = "active";
  144. }
  145. public function method(Request $request, $method)
  146. {
  147. try {
  148. return call_user_func([$this, $method], $request);
  149. }catch (\BadMethodCallException $e){
  150. dd("方法不存在");
  151. }
  152. }
  153. /**
  154. * @param $wave
  155. * @return string
  156. */
  157. private function wms_status($wave): string
  158. {
  159. switch ($wave->wavestatus) {
  160. case 00:
  161. $wms_status = '创建';
  162. break;
  163. case 40:
  164. $wms_status = '部分收货';
  165. break;
  166. case 90:
  167. $wms_status = '取消';
  168. break;
  169. case 99:
  170. $wms_status = '完成';
  171. break;
  172. case 62:
  173. $wms_status = '部分装箱';
  174. break;
  175. default:
  176. $wms_status = (string)$wave->wavestatus;
  177. }
  178. return $wms_status;
  179. }
  180. public function assignBatch()
  181. {
  182. $code = \request("code");
  183. $batches = Batch::query()->where("code",$code)->get();
  184. if (!$batches->count()){
  185. $wave = DB::connection("oracle")->selectOne(DB::raw("select * from DOC_WAVE_HEADER where WAVENO = ?"),[$code]);
  186. if (!$wave){
  187. dd("FLUX无波次");
  188. }
  189. $owner = app("OwnerService")->codeGetOwner($wave->customerid);
  190. $obj = [
  191. "wms_status" => $this->wms_status($wave),
  192. "wms_type"=>$wave->descr,
  193. "created_at"=>date("Y-m-d H:i:s"),
  194. "wms_created_at"=>$wave->addtime,
  195. "updated_at"=>$wave->edittime,
  196. "owner_id"=>$owner->id,
  197. ];
  198. $wave = Batch::query()->where("code",$code)->first();
  199. if (!$wave){
  200. $obj["code"] = $code;
  201. $wave = Batch::query()->create($obj);
  202. }else{
  203. Batch::query()->where("code",$code)->update($obj);
  204. }
  205. $ordernos = array_column(DB::connection("oracle")->select(DB::raw("select orderno from DOC_WAVE_DETAILS where WAVENO = ?"),[$code]),"orderno");
  206. Order::query()->whereIn("code",$ordernos)->update([
  207. "batch_id"=>$wave->id
  208. ]);
  209. Order::query()->with(["batch","bin"])->whereIn("code",$ordernos)->get()->each(function ($order){
  210. if (!$order->bin){
  211. $bin = DB::connection("oracle")->selectOne(DB::raw("select seqno from DOC_WAVE_DETAILS where waveno = ? and orderno = ?"),[$order->batch->code,$order->code]);
  212. if ($bin){
  213. OrderBin::query()->create([
  214. 'order_id' => $order->id,
  215. 'number' => $bin->seqno,
  216. ]);
  217. }
  218. }
  219. });
  220. $batches = Batch::query()->where("code",$code)->get();
  221. }
  222. app("BatchService")->assignTasks($batches);
  223. }
  224. private function i3()
  225. {
  226. $taskItem = new TaskItem();
  227. $taskItem->name = "测试衣服商品名3";
  228. $taskItem->barcode = "TEST-014";
  229. $taskItem->quantity = (int)1;
  230. $taskItem->binLocations = [
  231. "G04-039-1",
  232. ];
  233. $taskItem->attributes = [
  234. "orderLineNo" => "1",
  235. "skuLineNo" => "1",
  236. "sku" => "TEST3",
  237. "lotNum" => "LOT1792011",
  238. "logisticNumber"=> "极兔",
  239. ];
  240. return (array)$taskItem->get();
  241. }
  242. private function i2()
  243. {
  244. $taskItem = new TaskItem();
  245. $taskItem->name = "测试衣服商品名2";
  246. $taskItem->barcode = "TEST-013";
  247. $taskItem->quantity = (int)1;
  248. $taskItem->binLocations = [
  249. "G04-056-1",
  250. ];
  251. $taskItem->attributes = [
  252. "orderLineNo" => "1",
  253. "skuLineNo" => "1",
  254. "sku" => "TEST1",
  255. "lotNum" => "LOT179201",
  256. "logisticNumber"=> "圆通",
  257. ];
  258. return (array)$taskItem->get();
  259. }
  260. private function i1()
  261. {
  262. $taskItem = new TaskItem();
  263. $taskItem->name = "测试衣服 商品名";
  264. $taskItem->barcode = "TEST-012";
  265. $taskItem->quantity = (int)1;
  266. $taskItem->binLocations = [
  267. "G04-046-0",
  268. ];
  269. $taskItem->attributes = [
  270. "orderLineNo" => "1",
  271. "skuLineNo" => "1",
  272. "sku" => "TEST",
  273. "lotNum" => "LOT17920",
  274. "logisticNumber"=> "顺丰",
  275. ];
  276. return (array)$taskItem->get();
  277. }
  278. private function t1()
  279. {
  280. $task = new Task();
  281. $task->id = "TEST0010";
  282. $task->batchId = "WTEST0002";
  283. $task->warehouseId = "101";
  284. $task->attributes = [
  285. "customer" => "幼岚",
  286. ];
  287. $task->type = Task::TOTAL_PICKING;
  288. $task->storages = [["type"=>"1A_container"]];
  289. $task->items = [
  290. $this->i1(),
  291. $this->i2(),
  292. $this->i3(),
  293. ];
  294. return $task->get();
  295. }
  296. use Signature;
  297. private static $delayedHour = 48;
  298. function process(Request $request): array
  299. {
  300. $station_id = $request->input('station_id');
  301. $batch_id = $request->input('batch_id');
  302. $childIndex = null;
  303. $arr = explode('-',$batch_id);
  304. if (count($arr)==2){
  305. $batch_id = $arr[0];
  306. $childIndex = (int)$arr[1];
  307. }
  308. $s = new SortingController();
  309. // 同步orderCommodity
  310. $s->syncOrder($batch_id);
  311. /** @var Batch|\stdClass $batch */
  312. $batch=Batch::query()->where('code',$batch_id)->orderBy('id','desc')->first();
  313. $data=[
  314. 'result'=>'success',
  315. 'station_id'=>$station_id,
  316. 'batch_id'=>$batch_id,
  317. 'orders'=>[]
  318. ];
  319. if ($childIndex!==null && $batch->split_size){
  320. $start = (($childIndex-1)*$batch->split_size)+1;
  321. $end = $childIndex*$batch->split_size;
  322. $sql = <<<SQL
  323. SELECT ORDERNO
  324. FROM (SELECT T.ORDERNO, ROWNUM AS NO
  325. FROM (SELECT ORDERNO FROM DOC_WAVE_DETAILS WHERE WAVENO = '{$batch_id}' ORDER BY SEQNO) T)
  326. WHERE NO BETWEEN {$start} AND {$end}
  327. SQL;
  328. $waves = DB::connection("oracle")->select(DB::raw($sql));
  329. $codes = array_column($waves,'orderno');
  330. $orders = Order::query()->whereIn("code",$codes)->get();
  331. }else $orders = $batch->orders()->get();
  332. $ordersSorted=$orders->sortBy(function(Order $order){
  333. return $order->bin()->first()['number'];
  334. });
  335. $ordersSorted->each(function(Order $order)use(&$data,$request){
  336. if($order['status']=='取消')return;
  337. $orderData=[
  338. 'order_id'=>$order['code'],
  339. 'owner'=>$order->owner()->first()['code'],
  340. 'status'=>$order['status']=='未处理'?'available':$order['status'],
  341. 'created_at'=>$order['created_at']->toDateTimeString(),
  342. 'bin'=>(function()use($order){
  343. $bin=$order->bin()->first()['number']??'';
  344. if(!$bin){
  345. $bin=OracleDOCWaveDetails::query()->where('orderno', 'SO201230003574')->get('seqno')->first()['seqno']??'';
  346. dump('BIN 缺失');
  347. return $bin;
  348. }
  349. return $bin;
  350. })(),
  351. 'barcodes'=>[]
  352. ];
  353. $order->orderCommodities()->each(function(OrderCommodity $orderCommodity)use(&$orderData,$request){
  354. $commodity=$orderCommodity->commodity()->first();
  355. if(!$commodity){
  356. dump("没订单");
  357. return;
  358. }
  359. $barcodeStr=$commodity->barcodes()->get()->map(function(CommodityBarcode $barcode){
  360. return $barcode['code'];
  361. })->filter(function($code){
  362. return $code&&(!preg_match('/[\x{4e00}-\x{9fa5}]/u',$code));
  363. })->join(',');
  364. $orderData['barcodes'][]=[
  365. 'id'=>$orderCommodity['id']??'',
  366. 'barcode_id'=>$barcodeStr??'',
  367. 'name'=>$commodity['name']??'',
  368. 'sku'=>$commodity['sku']??'',
  369. 'amount'=>$orderCommodity['amount']??'',
  370. 'location'=>$orderCommodity['location']??'',
  371. ];
  372. });
  373. $data['orders'][]=$orderData;
  374. });
  375. return $data;
  376. }
  377. public function test(Request $request)
  378. {
  379. dd((int)ceil(101/8));
  380. $codes = ['W123','W124'];
  381. $no = "";
  382. foreach ($codes as $code){
  383. $no .= "'".$code."',";
  384. }
  385. $no = rtrim($no,',');
  386. $sql = <<<SQL
  387. SELECT WAVENO,COUNT(*) count from DOC_WAVE_DETAILS WHERE WAVENO IN ({$no}) GROUP BY WAVENO
  388. SQL;
  389. dd($sql);
  390. $code = 'W211108000002';
  391. $batch = null;
  392. if (!$code || !$batch = Batch::query()->select("id","split_size")->where("code",$code)->first())$this->error("无记录");
  393. $sql = <<<SQL
  394. SELECT a.ORDERNO,a.QTY,s.ALTERNATE_SKU1 FROM ACT_ALLOCATION_DETAILS a
  395. LEFT JOIN DOC_ORDER_HEADER o ON a.ORDERNO = o.ORDERNO
  396. LEFT JOIN DOC_WAVE_DETAILS w ON o.ORDERNO = w.ORDERNO
  397. LEFT JOIN BAS_SKU s ON a.SKU = s.SKU
  398. WHERE w.WAVENO = '{$code}' ORDER BY w.SEQNO
  399. SQL;
  400. $orders = DB::connection("oracle")->select(DB::raw($sql));
  401. $result = [];
  402. $currentList = [];
  403. $slowPointer = 0;
  404. $nodeSign = "";
  405. foreach ($orders as $order){
  406. if ($order->orderno!=$nodeSign){
  407. if ($slowPointer==$batch->split_size){
  408. $result[] = $currentList;
  409. $currentList = [];
  410. $slowPointer = 0;
  411. }
  412. $slowPointer++;
  413. $nodeSign = $order->orderno;
  414. }
  415. $currentList[] = ["barcode"=>$order->alternate_sku1,"qty"=>$order->qty];
  416. }
  417. if ($currentList)$result[] = $currentList;
  418. dd($result);
  419. $request->offsetSet("station_id",'123456789');
  420. dd($this->process($request));
  421. echo 'Now memory_get_usage: ' . memory_get_usage() . '<br />';
  422. $t1 = microtime(true);
  423. // ... 执行代码 ...
  424. $t2 = microtime(true);
  425. echo '耗时'.round($t2-$t1,3).'秒<br>';
  426. echo 'Now memory_get_usage: ' . memory_get_usage() . '<br />';
  427. return;
  428. $a = new \App\Http\Controllers\api\thirdPart\syrius\producer\OrderController();
  429. dd($a->createOrder($this->t1())->body());
  430. }
  431. public function test1()
  432. {
  433. $a = new \App\Http\Controllers\api\thirdPart\syrius\producer\OrderController();
  434. dd($a->createOrder($this->t2())->body());
  435. }
  436. public function init_labor_company_dispatch()
  437. {
  438. $dispatches = LaborCompanyDispatch::all();
  439. foreach ($dispatches as $dispatch) {
  440. $dispatch->warehouse_id = $dispatch->laborCompany->warehouse_id ?? null;
  441. $dispatch->save();
  442. }
  443. }
  444. private function t2()
  445. {
  446. $task = new Task();
  447. $task->id = "TEST0004";
  448. #$task->batchId = "WTEST0001";
  449. $task->warehouseId = "101";
  450. $task->type = Task::PUTAWAY;
  451. $task->attributes = [
  452. "customer" => "幼岚",
  453. ];
  454. $task->storages = [["serialNo"=>"1635055429594424"]];
  455. $task->items = [
  456. $this->p1(),
  457. $this->p2(),
  458. ];
  459. return $task->get();
  460. }
  461. private function p1()
  462. {
  463. $taskItem = new TaskItem();
  464. $taskItem->name = "测试衣服商品名2";
  465. $taskItem->barcode = "TEST-013";
  466. $taskItem->quantity = (int)1;
  467. $taskItem->binLocations = [
  468. "G11-133-1",
  469. ];
  470. $taskItem->attributes = [
  471. "storageSerialNo"=>"1635055429594424",
  472. "orderLineNo" => "1",
  473. "skuLineNo" => "1",
  474. "sku" => "TEST1",
  475. "lotNum" => "LOT179201",
  476. "logisticNumber"=> "圆通",
  477. ];
  478. return (array)$taskItem->get();
  479. }
  480. private function p2()
  481. {
  482. $taskItem = new TaskItem();
  483. $taskItem->name = "测试衣服 商品名";
  484. $taskItem->barcode = "TEST-012";
  485. $taskItem->quantity = (int)1;
  486. $taskItem->binLocations = [
  487. "G11-099-1",
  488. ];
  489. $taskItem->attributes = [
  490. "storageSerialNo"=>"1635055429594424",
  491. "orderLineNo" => "1",
  492. "skuLineNo" => "1",
  493. "sku" => "TEST",
  494. "lotNum" => "LOT17920",
  495. "logisticNumber"=> "顺丰",
  496. ];
  497. return (array)$taskItem->get();
  498. }
  499. public function update_order_packages_is_manual_update()
  500. {
  501. $descriptions = Log::query()
  502. ->select('description')
  503. ->whereBetween('created_at', ['2021-08-31 10:30:00', '2021-08-31 10:35:00'])
  504. ->where('class', 'like', 'https://was.baoshi56.com/package/logistic/batchUpdate%')->pluck('description');
  505. foreach ($descriptions as $description) {
  506. $description = substr($description, 9);
  507. $description = \Illuminate\Support\Str::before($description, "}");
  508. $obj = json_decode($description . '}', true);
  509. OrderPackage::query()
  510. ->whereIn('logistic_number', $obj['logistic_numbers'])
  511. ->update([
  512. 'status' => '无',
  513. 'is_manual_update' => false,
  514. ]);
  515. }
  516. }
  517. public function testUpdateInv()
  518. {
  519. ini_set('max_execution_time', 0);
  520. ini_set('memory_limit', '4096M');
  521. $sql = <<<sql
  522. select FMLOTNUM,FMLOCATION,PLANTOLOCATION,CREATE_TRANSACTIONID,SKU,CUSTOMERID from TSK_TASKLISTS
  523. where CUSTOMERID=?
  524. AND FMLOCATION= ?
  525. AND OPENWHO = ?
  526. AND TASKPROCESS = ?
  527. AND DOCTYPE = ?
  528. AND TASKTYPE = ?
  529. AND LOTATT05=?
  530. AND LOTATT08=?
  531. AND PLANTOID = ?
  532. and OPENTIME>=TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')
  533. and OPENTIME<=TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')
  534. sql;
  535. $CUSTOMERID = 'JIANSHANG';
  536. $FMLOCATION = 'STAGEWH02';
  537. $OPENWHO = 'WCS';
  538. $TASKPROCESS = '00';
  539. $DOCTYPE = 'ASN';
  540. $TASKTYPE = 'PA';
  541. $LOTATT05 = 'MJ-CP';
  542. $LOTATT08 = 'ZP';
  543. $PLANTOID = '*';
  544. $traceid = 'JIANSHANG03';
  545. $start = '2021-09-02 23:59:59';
  546. $end = '2021-09-03 11:10:00';
  547. $res = DB::connection("oracle")->select(DB::raw($sql),
  548. [$CUSTOMERID, $FMLOCATION, $OPENWHO, $TASKPROCESS, $DOCTYPE, $TASKTYPE, $LOTATT05, $LOTATT08, $PLANTOID, $start, $end]);
  549. $resItems = array_chunk($res, 200);
  550. foreach ($resItems as $res) {
  551. DB::connection("oracle")->beginTransaction();
  552. try {
  553. foreach ($res as $re) {
  554. DB::connection("oracle")->table('INV_LOT_LOC_ID')
  555. ->where([
  556. 'LOTNUM' => $re->fmlotnum,
  557. 'LOCATIONID' => $re->fmlocation,
  558. 'CUSTOMERID' => $re->customerid,
  559. 'sku' => $re->sku,
  560. 'TRACEID' => '*',
  561. ])
  562. ->update([
  563. 'TRACEID' => $traceid,
  564. 'EDITWHO' => 'WCS_',
  565. ]);
  566. if ($re->fmlocation != $re->plantolocation) {
  567. DB::connection("oracle")->table('INV_LOT_LOC_ID')
  568. ->where([
  569. 'LOTNUM' => $re->fmlotnum,
  570. 'LOCATIONID' => $re->plantolocation,
  571. 'CUSTOMERID' => $re->customerid,
  572. 'sku' => $re->sku,
  573. 'TRACEID' => '*',
  574. ])
  575. ->update([
  576. 'TRACEID' => $traceid,
  577. 'EDITWHO' => 'WCS_',
  578. ]);
  579. }
  580. DB::connection("oracle")->commit();
  581. }
  582. dd(true);
  583. } catch (\Exception $e) {
  584. DB::connection("oracle")->rollBack();
  585. dd($e->getMessage());
  586. }
  587. }
  588. }
  589. /**
  590. * 重置15天内的数据
  591. */
  592. public function order_packages_init()
  593. {
  594. OrderPackage::query()
  595. ->whereBetween('created_at', [now()->subDays(15), now()])
  596. ->update([
  597. 'is_delay_deliver' => 0,
  598. 'sync_routes_flag' => 0,
  599. 'status' => 1,
  600. 'exception_status' => 0,
  601. ]);
  602. OrderPackage::query()
  603. ->whereBetween('created_at', [now()->subDays(15), now()])
  604. ->whereNotNull('received_at')
  605. ->update([
  606. 'status' => 7,
  607. ]);
  608. }
  609. public function syncOrderPackage(){
  610. ini_set('memory_limit','500M');
  611. ini_set('max_execution_time', 0);
  612. $orderPackingSummary = OracleDocOrderPackingSummary::query()
  613. ->where('editTime','>=','2021-09-11 12:00:00')
  614. ->where('editTime','<=','2021-09-12 12:40:00')
  615. ->get();
  616. $orderPackingSummary_chunk = $orderPackingSummary->chunk(200);
  617. foreach ($orderPackingSummary_chunk as $orderPackingSummarys) {
  618. foreach ($orderPackingSummarys as $orderPackingSummary) {
  619. $orderPackage = OrderPackage::query()->where('logistic_number',$orderPackingSummary->traceid)->first();
  620. $orderPackage->update([
  621. 'uploaded_to_wms'=> true,
  622. 'weight'=>$orderPackingSummary->grossweight,
  623. 'length'=>$orderPackingSummary->length,
  624. 'width'=>$orderPackingSummary->width,
  625. 'height'=>$orderPackingSummary->height,
  626. 'weighed_at'=>$orderPackingSummary->edittime
  627. ]);
  628. dispatch(new WeightUpdateInstantBill($orderPackage));
  629. }
  630. }
  631. return ['success' => true];
  632. }
  633. public function collectUpload()
  634. {
  635. /** @var OrderPackageService $service */
  636. $service = app('OrderPackageService');
  637. return $service->collectUpload([
  638. '75601803541125'
  639. ]);
  640. }
  641. public function init_在途异常()
  642. {
  643. $logistic_numbers = OrderPackage::query()
  644. ->select('logistic_number')
  645. ->where('exception_status', 5)
  646. ->where('created_at', '>=', now()->subDays(20)->toDateTimeString())
  647. ->pluck('logistic_number');
  648. /** @var OrderPackageReceivedSyncService $service */
  649. $service = app('OrderPackageReceivedSyncService');
  650. $service->syncLogisticRoute(false, $logistic_numbers);
  651. // $logistic_numbers = OrderPackage::query()
  652. // ->select(['logistic_number', 'order_id', 'id'])
  653. // ->whereIn('order_id', function ($query) {
  654. // $query->from('orders')->selectRaw('id')->whereIn('logistic_id', function ($builder) {
  655. // $builder->from('logistics')->selectRaw('id')->where('type', '=', '快递')->whereNotIn('belong_company', ['顺丰', '中通', '韵达', '圆通', '京东']);
  656. // });
  657. // })
  658. // ->where('exception_status', 5)
  659. // ->where('created_at', '>=', now()->subDays(20)->toDateTimeString())
  660. // ->pluck('logistic_number');
  661. // $service->syncLogisticRouteByAliJiSu($logistic_numbers);
  662. }
  663. public function store()
  664. {
  665. ini_set('max_execution_time', 0);
  666. ini_set('memory_limit', '1024M');
  667. // $now = Carbon::now();
  668. // $startDate = $this->getDate();
  669. $startDate = '2021-09-25 13:23:14';
  670. $diffDay = 1; // 天数
  671. for($i = 0;$i<=$diffDay;$i++){
  672. $endDate = Carbon::parse($startDate)->addDays(1)->toDateTimeString();
  673. $doc_asn_headers = $this->getDocAsnHeader($startDate,$endDate);
  674. // if (count($doc_asn_headers)>0){
  675. // $this->syncStores($doc_asn_headers);
  676. // $this->syncDate($endDate);
  677. // }
  678. dump($startDate,$endDate);
  679. $startDate = $endDate;
  680. }
  681. $this->clearCache();
  682. // ValueStore::query()->updateOrCreate([
  683. // 'name' => 'last_asn_sync_task_end_at',
  684. // ], [
  685. // 'name' => 'last_asn_sync_task_end_at',
  686. // 'value' => $now,
  687. // ]);
  688. }
  689. public function getDocAsnHeader($startDate,$endDate)
  690. {
  691. return OracleDOCASNHeader::query()
  692. ->with(['asnType', 'asnStatus'])
  693. ->select('asnno','asnstatus','asntype','addtime','edittime','customerid','notes','warehouseid','asnreference3','asnreference2')
  694. ->where('EditTime', '>=', $startDate)
  695. ->where('EditTime', '<=', $endDate)
  696. ->whereColumn('EditTime', '<>', 'addTime')
  697. ->orderByDesc('EditTime')
  698. ->get();
  699. }
  700. public function getDate(){
  701. return ValueStore::query()->where('name','asn_last_updated_sync_at')->value('value');
  702. }
  703. public function syncStores($doc_asn_headers){
  704. $service = new StoreService();
  705. $service->createStore($doc_asn_headers,"update");
  706. $service->updateStore($doc_asn_headers);
  707. $service->createStoreRejected($doc_asn_headers);
  708. unset($doc_asn_headers);
  709. }
  710. public function syncDate($date)
  711. {
  712. // 同步更新时间
  713. ValueStore::query()->updateOrCreate([
  714. 'name' => 'asn_last_updated_sync_at',
  715. ], [
  716. 'name' => 'asn_last_updated_sync_at',
  717. 'value' => $date,
  718. ]);
  719. }
  720. public function clearCache()
  721. {
  722. $service = new StoreService();
  723. $update_set = config('sync.asn_sync.cache_prefix.update_set');
  724. $update_keys = config('sync.asn_sync.cache_prefix.update_keys');
  725. $service->deleteCacheKey($update_set, $update_keys);
  726. // 清空保存 ans 号的栈
  727. // 清除 更新时间 开始 结束
  728. }
  729. public function updateStoreItem()
  730. {
  731. ini_set('max_execution_time', 0);
  732. ini_set('memory_limit', '1024M');
  733. $storeIds = Store::query()
  734. ->where('updated_at', '>=', '2021-09-25 13:21:26')
  735. ->whereColumn('updated_at', '<>', 'created_at')
  736. ->pluck('id');
  737. $storeItemMaxIds = StoreItem::query()
  738. ->selectRaw('max(id) as max_id')
  739. ->whereIn('store_id', $storeIds)
  740. ->groupBy(['store_id', 'asn_line_code'])
  741. ->get();
  742. // dd($storeItemMaxIds->count());
  743. $storeItems = StoreItem::query()
  744. ->whereIn('store_id', $storeIds)
  745. ->whereNotIn('id', $storeItemMaxIds)
  746. ->delete();
  747. }
  748. public function init_SettlementBillReportTask()
  749. {
  750. $this->dispatch(new SettlementBillReportJob('2021-09-01',[]));
  751. }
  752. public function test2(){
  753. $source_file ="E:\OneDrive\桌面\工作目录\文件库\\5.jpg";
  754. $img = ImageCreateFromJpeg($source_file);
  755. imagecolortransparent($img);//将某个颜色设置成透明色
  756. imagecolorstotal($img);
  757. header('Content-type:image/jpeg');
  758. imagejpeg($img);
  759. //dd($this->run('E:\OneDrive\桌面\工作目录\文件库\5.jpg', 'E:\OneDrive\桌面\工作目录\文件库\6.jpg'));
  760. }
  761. const FILE_NOT_FOUND = '-1';
  762. const FILE_EXTNAME_ILLEGAL = '-2';
  763. public function run($src1, $src2) {
  764. if(!is_file($src1) || !is_file($src2)) exit(self::FILE_NOT_FOUND);
  765. $hash1 = $this->getHashValue($src1);
  766. $hash2 = $this->getHashValue($src2);
  767. if(strlen($hash1) !== strlen($hash2)) return false;
  768. $count = 0;
  769. $len = strlen($hash1);
  770. for($i = 0; $i < $len; $i++) if($hash1[$i] !== $hash2[$i]){
  771. $count++;
  772. }
  773. dd($count);
  774. return $count <= 10 ? true : false;
  775. }
  776. public function getImage($file) {
  777. $extname = pathinfo($file, PATHINFO_EXTENSION);
  778. if(!in_array($extname, ['jpg','jpeg','png','gif'])) exit(self::FILE_EXTNAME_ILLEGAL);
  779. $img = call_user_func('imagecreatefrom'. ( $extname == 'jpg' ? 'jpeg' : $extname ) , $file);
  780. return $img;
  781. }
  782. public function getHashValue($file) {
  783. $w = 32;
  784. $h = 32;
  785. $img = imagecreatetruecolor($w, $h);
  786. list($src_w, $src_h) = getimagesize($file);
  787. $src = $this->getImage($file);
  788. imagecopyresampled($img, $src, 0, 0, 0, 0, $w, $h, $src_w, $src_h);
  789. imagedestroy($src);
  790. $total = 0;
  791. $array = array();
  792. for( $y = 0; $y < $h; $y++) {
  793. for ($x = 0; $x < $w; $x++) {
  794. $rgb = imagecolorat($img, $x, $y);
  795. $gray = $rgb & 0xFF;
  796. /*dump([
  797. ($rgb >> 8) & 0xFF,
  798. ($rgb >> 16) & 0xFF,
  799. $rgb & 0xFF,
  800. ]);*/
  801. if(!isset($array[$y])) $array[$y] = array();
  802. $array[$y][$x] = $gray;
  803. $total += $gray;
  804. }
  805. }
  806. imagedestroy($img);
  807. $average = intval($total / ($w * $h * 2));
  808. $hash = '';
  809. for($y = 0; $y < $h; $y++) {
  810. for($x = 0; $x < $w; $x++) {
  811. $hash .= ($array[$y][$x] >= $average) ? '1' : '0';
  812. }
  813. }
  814. dump($hash);
  815. return $hash;
  816. }
  817. public function sortTransferStatus()
  818. {
  819. $orderPackage = OrderPackage::query()->where('logistic_number','75601831068018')->first();
  820. app('OrderPackageService')->sortOrderPackageTransferStatus($orderPackage);
  821. dd($orderPackage);
  822. }
  823. public function clear_work_space()
  824. {
  825. \App\LaborApply::query()->truncate();
  826. LaborCompanyDispatch::query()->truncate();
  827. \App\LaborCompanyDispatchDetail::query()->truncate();
  828. }
  829. public function testChange()
  830. {
  831. $last_start_key = config('sync.order_sync.cache_prefix.last_start_at');
  832. $last_end_key = config('sync.order_sync.cache_prefix.last_end_at');
  833. Cache::put($last_start_key,Carbon::make('2021-10-12 06:23:37'));
  834. Cache::put($last_end_key,Carbon::make('2021-10-12 06:23:38'));
  835. ValueStore::query()->where('name','order_last_created_sync_at')->update(['value' => '2021-10-12 06:23:37']);
  836. ValueStore::query()->where('name','order_last_updated_sync_at')->update(['value' => '2021-10-12 06:23:37']);
  837. ValueStore::query()->where('name','last_order_sync_task_start_at')->update(['value' => '2021-10-12 06:23:37']);
  838. ValueStore::query()->where('name','last_order_sync_task_end_at')->update(['value' => '2021-10-12 06:23:38']);
  839. }
  840. public function syncOrder()
  841. {
  842. $code = \request("code");
  843. $service = new OracleDOCOrderHeaderService();
  844. $orderService = new OrderService();
  845. $orderHeaders = $service->getQuery()->where('DOC_Order_Header.WaveNo',$code)->get();
  846. $orderService->syncOrderByWMSOrderHeaders($orderHeaders);
  847. app("OrderCommodityService")->syncOrderCommodity($orderHeaders);
  848. dd('同步完成');
  849. }
  850. public function test_sddgdfg()
  851. {
  852. /** @var OwnerStoreOutFeeReportService $service */
  853. $service = app('OwnerStoreOutFeeReportService');
  854. $service->recordReport(null, [2]);
  855. }
  856. public function testZhenCang()
  857. {
  858. $batches=Batch::query()->where('id',161071)->get();
  859. BroadcastBatchToZhengCangJob::dispatch($batches);
  860. }
  861. }