TestController.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Authority;
  4. use App\Batch;
  5. use App\Commodity;
  6. use App\CommodityMaterialBoxModel;
  7. use App\Components\AsyncResponse;
  8. use App\Components\Database;
  9. use App\Components\ErrorPush;
  10. use App\ErrorTemp;
  11. use App\Feature;
  12. use App\Http\ApiControllers\LoginController;
  13. use App\Http\Requests\AndroidGateRequest;
  14. use App\Http\Requests\OrderDelivering;
  15. use App\Jobs\BatchTaskJob;
  16. use App\Jobs\CacheShelfTaskJob;
  17. use App\Jobs\OrderCreateInstantBill;
  18. use App\Jobs\OrderCreateWaybill;
  19. use App\Jobs\SettlementBillReportJob;
  20. use App\Jobs\StoreCreateInstantBill;
  21. use App\Jobs\TestJob;
  22. use App\Jobs\WeightUpdateInstantBill;
  23. use App\LaborCompanyDispatch;
  24. use App\LaborReport;
  25. use App\LaborReportStatus;
  26. use App\MaterialBox;
  27. use App\MaterialBoxModel;
  28. use App\Notifications\RoutineNotification;
  29. use App\OracleDOCASNHeader;
  30. use App\OracleDOCOrderHeader;
  31. use App\OracleDocOrderPackingSummary;
  32. use App\Order;
  33. use App\OrderBin;
  34. use App\OrderIssue;
  35. use App\OrderIssueProcessLog;
  36. use App\OrderPackage;
  37. use App\Owner;
  38. use App\OwnerAreaReport;
  39. use App\OwnerFeeDetail;
  40. use App\OwnerFeeDetailLogistic;
  41. use App\OwnerFeeExpress;
  42. use App\OwnerFeeLogistic;
  43. use App\OwnerFeeOperation;
  44. use App\OwnerFeeOperationDetail;
  45. use App\OwnerFeeStorage;
  46. use App\OwnerPriceOperation;
  47. use App\OrderPackageCountingRecord;
  48. use App\ProcurementCheckSheet;
  49. use App\RejectedBill;
  50. use App\SeeLog;
  51. use App\Services\AuthorityService;
  52. use App\Services\BatchService;
  53. use App\Services\CacheShelfService;
  54. use App\Services\ForeignHaiRoboticsService;
  55. use App\Services\NotificationService;
  56. use App\Services\OrderPackageReceivedSyncService;
  57. use App\Services\OrderPackageService;
  58. use App\Services\OrderService;
  59. use App\Services\OwnerFeeTotalService;
  60. use App\Services\OwnerLogisticFeeReportService;
  61. use App\Services\OwnerPriceOperationService;
  62. use App\Services\OwnerStoreFeeReportService;
  63. use App\Services\OwnerStoreOutFeeReportService;
  64. use App\Services\ReviewService;
  65. use App\Services\StationService;
  66. use App\Services\StorageService;
  67. use App\Services\StoreService;
  68. use App\Station;
  69. use App\StationTask;
  70. use App\StationTaskMaterialBox;
  71. use App\Store;
  72. use App\StoreItem;
  73. use App\TaskTransaction;
  74. use App\Unit;
  75. use App\User;
  76. use App\UserDetail;
  77. use App\UserDutyCheck;
  78. use App\ValueStore;
  79. use App\Waybill;
  80. use App\WorkOrder;
  81. use Carbon\Carbon;
  82. use Carbon\CarbonPeriod;
  83. use Decimal\Decimal;
  84. use Doctrine\DBAL\Exception;
  85. use Firebase\JWT\JWT;
  86. use Illuminate\Database\Eloquent\Collection;
  87. use Illuminate\Database\Eloquent\HigherOrderBuilderProxy;
  88. use Illuminate\Foundation\Http\FormRequest;
  89. use Illuminate\Http\Request;
  90. use Illuminate\Support\Facades\Broadcast;
  91. use Illuminate\Support\Facades\Cache;
  92. use Illuminate\Support\Facades\Auth;
  93. use Illuminate\Support\Facades\Cookie;
  94. use Illuminate\Support\Facades\DB;
  95. use Illuminate\Support\Facades\Http;
  96. use Illuminate\Support\Facades\Log;
  97. use Illuminate\Support\Facades\Notification;
  98. use Illuminate\Support\Facades\URL;
  99. use Illuminate\Support\Facades\Validator;
  100. use Illuminate\Support\Str;
  101. use Laravel\Horizon\Events\JobFailed;
  102. use Monolog\Handler\IFTTTHandler;
  103. use phpDocumentor\Reflection\Types\Resource_;
  104. use PhpOffice\PhpSpreadsheet\Calculation\Web\Service;
  105. use Ramsey\Uuid\Uuid;
  106. use Symfony\Component\ErrorHandler\Error\FatalError;
  107. class TestController extends Controller
  108. {
  109. use AsyncResponse, ErrorPush, Database;
  110. const ASNREFERENCE_2 = 'ASNREFERENCE2';
  111. public function __construct()
  112. {
  113. $this->data["active_test"] = "active";
  114. }
  115. public function method(Request $request, $method)
  116. {
  117. try {
  118. return call_user_func([$this, $method], $request);
  119. }catch (\BadMethodCallException $e){
  120. dd("方法不存在");
  121. }
  122. }
  123. /**
  124. * @param $wave
  125. * @return string
  126. */
  127. private function wms_status($wave): string
  128. {
  129. switch ($wave->wavestatus) {
  130. case 00:
  131. $wms_status = '创建';
  132. break;
  133. case 40:
  134. $wms_status = '部分收货';
  135. break;
  136. case 90:
  137. $wms_status = '取消';
  138. break;
  139. case 99:
  140. $wms_status = '完成';
  141. break;
  142. case 62:
  143. $wms_status = '部分装箱';
  144. break;
  145. default:
  146. $wms_status = (string)$wave->wavestatus;
  147. }
  148. return $wms_status;
  149. }
  150. public function assignBatch()
  151. {
  152. $code = \request("code");
  153. $batches = Batch::query()->where("code",$code)->get();
  154. if (!$batches->count()){
  155. $wave = DB::connection("oracle")->selectOne(DB::raw("select * from DOC_WAVE_HEADER where WAVENO = ?"),[$code]);
  156. if (!$wave){
  157. dd("FLUX无波次");
  158. }
  159. $owner = app("OwnerService")->codeGetOwner($wave->customerid);
  160. $obj = [
  161. "wms_status" => $this->wms_status($wave),
  162. "wms_type"=>$wave->descr,
  163. "created_at"=>date("Y-m-d H:i:s"),
  164. "wms_created_at"=>$wave->addtime,
  165. "updated_at"=>$wave->edittime,
  166. "owner_id"=>$owner->id,
  167. ];
  168. $wave = Batch::query()->where("code",$code)->first();
  169. if (!$wave){
  170. $obj["code"] = $code;
  171. $wave = Batch::query()->create($obj);
  172. }else{
  173. Batch::query()->where("code",$code)->update($obj);
  174. }
  175. $ordernos = array_column(DB::connection("oracle")->select(DB::raw("select orderno from DOC_WAVE_DETAILS where WAVENO = ?"),[$code]),"orderno");
  176. Order::query()->whereIn("code",$ordernos)->update([
  177. "batch_id"=>$wave->id
  178. ]);
  179. Order::query()->with(["batch","bin"])->whereIn("code",$ordernos)->get()->each(function ($order){
  180. if (!$order->bin){
  181. $bin = DB::connection("oracle")->selectOne(DB::raw("select seqno from DOC_WAVE_DETAILS where waveno = ? and orderno = ?"),[$order->batch->code,$order->code]);
  182. if ($bin){
  183. OrderBin::query()->create([
  184. 'order_id' => $order->id,
  185. 'number' => $bin->seqno,
  186. ]);
  187. }
  188. }
  189. });
  190. $batches = Batch::query()->where("code",$code)->get();
  191. }
  192. app("BatchService")->assignTasks($batches);
  193. }
  194. public function test()
  195. {
  196. $ids = [];
  197. $sql = <<<sql
  198. select id from orders where owner_id = 396
  199. and wms_status = '订单完成'
  200. and wms_edittime>='2021-09-01 00:00:00' and wms_edittime<'2021-10-01 00:00:00' and id not in
  201. (select outer_id from owner_fee_details where owner_id = 396 and created_at>='2021-09-01 00:00:00' and created_at<'2021-10-01 00:00:00'
  202. and outer_table_name = 'orders')
  203. sql;
  204. foreach (DB::select(DB::raw($sql)) as $order){
  205. $ids[] = $order->id;
  206. }
  207. $orders = Order::query()->whereIn("id",$ids)->get();
  208. dispatch(new OrderCreateInstantBill($orders));
  209. return;
  210. //中通接口请求body
  211. $collectUploadDTOS = [[
  212. 'billCode' => "75811463670235",
  213. 'weight' => 0,
  214. 'appId' => $appId,
  215. 'importDate' => now()->toDateTimeString(),
  216. ]];
  217. $body = json_encode([
  218. 'collectUploadDTOS' => $collectUploadDTOS,
  219. ], JSON_UNESCAPED_UNICODE);
  220. $data_digest = base64_encode(md5($body . $appSecret, TRUE));
  221. $headers = [
  222. 'Content-Type' => 'application/json; charset=UTF-8',
  223. 'x-companyid' => $xAppKey,
  224. 'x-datadigest' => $data_digest,
  225. ];
  226. dd(Http::withHeaders($headers)->withBody($body, 'application/json')->post($url)->body());
  227. $stores = Store::query()->whereIn("id",[490692,492252,492405,493259,491290,491758,492252,492989,493522,
  228. 496079,490702,491173,491780,493522,488622,490891,491020,491173,493308,489448,491020,491184,493573,493977,
  229. 496105,492086,493714,493977,496118,492593,492592,492591,492590,493011,493979,490721,492192,493429,493978,
  230. 496106,490721,491460,493165,496114,489319,489436,490703,491190,493957,496115,496114,489436,491147,
  231. 491695,492395,490711,491461,491695,492079,494533,496099,496096,490711,491458,491797,492244,
  232. 492422,496098,496097,496100,491458,491798,493572,493752,490443,491457,492394,493531,493572,491687,
  233. 492394,492968,493782,490431,490994,493782,488570,489103,490616,490994,493966,489862,490616,
  234. 490629,495645,490629,491455,488793])->get();
  235. $this->dispatch(new StoreCreateInstantBill($stores));
  236. dd(1);
  237. /** @var StationTaskMaterialBox $stationTaskMaterialBox */
  238. $stationTaskMaterialBox = app("StorageService")->createWarehousingTask($stationService->getStation_byType('立库')["id"],$station->materialBox->id);
  239. app("CacheShelfService")->lightUp($station->code,'3','0',['title'=>"等待机器人拿走,请勿操作"]);
  240. Cache::forever("CACHE_SHELF_OCCUPANCY_{$station->id}",true);
  241. dd($ForeignHaiRoboticsService->putBinToStore_fromCacheShelf($stationTaskMaterialBox, $station));
  242. $user = Auth::user();
  243. $remark = "zengjunlj";
  244. $ownerName = 'zengjunlj' ?? '';
  245. $clientCode = 'zengjunljljlj' ?? '';
  246. $msg = $user["name"]."建立了新工单<br/>".$ownerName.":".$clientCode."<br/>".$remark;
  247. NotificationService::SingleRegister($msg,$clientCode,"订单管理-问题件");
  248. dd(1);
  249. $seeLog = SeeLog::query()->find(9);
  250. Notification::send(Auth::user(),new RoutineNotification($seeLog->toArray()));
  251. dd(1);
  252. Broadcast::channel('notification', function ($user, $id) {
  253. return (int) $user->id === (int) $id;
  254. });
  255. dd(1);
  256. Notification::send(Auth::user(),new RoutineNotification($seeLog->toArray()));
  257. dd(1);
  258. $username = config('database.connections.oracle.username');
  259. $password = config('database.connections.oracle.password');
  260. $host = config('database.connections.oracle.host');
  261. $service_name = config('database.connections.oracle.service_name');
  262. $conn = oci_connect($username, $password, $host . '/' . $service_name,"utf8");
  263. $sql = <<<sql
  264. BEGIN
  265. SPSO_HardAllocation_Process('WH01','Allocation','By OrderNO',
  266. null,'SO21090100007','0',null,
  267. 'zhouzhendong',:CODE);
  268. END;
  269. sql;
  270. $stmt = oci_parse($conn, $sql);
  271. $code = "";
  272. oci_bind_by_name($stmt, ':CODE', $code,300);
  273. oci_execute($stmt);
  274. oci_close($conn);
  275. dd($code);
  276. //
  277. $no = "SO21090900001";
  278. $db = DB::connection("oracle");
  279. //$order = $db->selectOne(DB::raw("select * from DOC_ORDER_HEADER where orderno = ?"),[$no]);
  280. dd($db->select($sql,[
  281. ]));
  282. $db->select("CALL SPSO_HardAllocation_Process(?,'Allocation','By OrderNO',null,?,'0',null,'zhouzhendong',@code)",[
  283. $order->warehouseid,$no
  284. ]);
  285. //SPSO_HardAllocation_Process
  286. dd($db->selectOne("select @code"));
  287. $date = "2021-09-14 15:47:00";
  288. dispatch(new TestJob("1"))->delay(Carbon::parse($date));
  289. dispatch(new TestJob("2"))->delay(Carbon::parse($date));
  290. dispatch(new TestJob("3"))->delay(Carbon::parse($date));
  291. dispatch(new TestJob("4"))->delay(Carbon::parse($date));
  292. dispatch(new TestJob("5"))->delay(Carbon::parse($date));
  293. dispatch(new TestJob("6"))->delay(Carbon::parse($date));
  294. dispatch(new TestJob("7"))->delay(Carbon::parse($date));
  295. dispatch(new TestJob("8"))->delay(Carbon::parse($date));
  296. dispatch(new TestJob("9"))->delay(Carbon::parse($date));
  297. dispatch(new TestJob("10"))->delay(Carbon::parse($date));
  298. dd(1);
  299. Station::query()->where("station_type_id", 5)->update(["status" => 1]);
  300. Cache::forget("CACHE_SHELF_AVAILABLE");
  301. $station = ["HAIB1-01-01", "HAIB1-02-01"];
  302. $material = ["IDE0001824", "IDE0001740", "IDE0002710"];
  303. Station::query()->whereIn("code", $station)->update(["status" => 0]);
  304. $stations = Station::query()->whereIn("code", $station)->get();
  305. $materials = MaterialBox::query()->whereIn("code", $material)->get();
  306. $dateTime = date("Y-m-d H:i:s");
  307. $task1 = StationTaskMaterialBox::query()->create([
  308. 'station_id' => $stations[0]->id,
  309. 'material_box_id' => $materials[0]->id,
  310. 'station_task_batch_id' => 1,
  311. 'status' => '待处理'
  312. ]);
  313. $task2 = StationTaskMaterialBox::query()->create([
  314. 'station_id' => $stations[1]->id,
  315. 'material_box_id' => $materials[1]->id,
  316. 'station_task_batch_id' => 1,
  317. 'status' => '待处理'
  318. ]);
  319. $task3 = StationTaskMaterialBox::query()->create([
  320. 'station_id' => 6,
  321. 'material_box_id' => $materials[2]->id,
  322. 'station_task_batch_id' => 1,
  323. 'status' => '待处理'
  324. ]);
  325. TaskTransaction::query()->insert([[
  326. "doc_code" => "test",
  327. "bar_code" => "test",
  328. "to_station_id" => $stations[0]->id,
  329. "material_box_id" => $materials[0]->id,
  330. "task_id" => $task1->id,
  331. "commodity_id" => 505012,//XUNI03
  332. "amount" => 1,
  333. "type" => "出库",
  334. "status" => 0,
  335. "mark" => 2,
  336. "bin_number" => 1,
  337. "created_at" => $dateTime,
  338. "updated_at" => $dateTime,
  339. ], [
  340. "doc_code" => "test",
  341. "bar_code" => "test",
  342. "to_station_id" => $stations[1]->id,
  343. "material_box_id" => $materials[1]->id,
  344. "task_id" => $task2->id,
  345. "commodity_id" => 505012,//XUNI03
  346. "amount" => 1,
  347. "type" => "出库",
  348. "status" => 0,
  349. "mark" => 2,
  350. "bin_number" => 1,
  351. "created_at" => $dateTime,
  352. "updated_at" => $dateTime,
  353. ], [
  354. "doc_code" => "test",
  355. "bar_code" => "test",
  356. "to_station_id" => 6,
  357. "material_box_id" => $materials[2]->id,
  358. "task_id" => $task3->id,
  359. "commodity_id" => 505012,//XUNI03
  360. "amount" => 1,
  361. "type" => "出库",
  362. "status" => 3,
  363. "mark" => 2,
  364. "bin_number" => 1,
  365. "created_at" => $dateTime,
  366. "updated_at" => $dateTime,
  367. ]]);
  368. $foreignHaiRoboticsService = new ForeignHaiRoboticsService();
  369. $toLocation = collect($station);
  370. $taskMaterialBoxes = collect([$task1, $task2]);
  371. $foreignHaiRoboticsService->
  372. fetchGroup_multiLocation($toLocation, $taskMaterialBoxes, '', '立架出至缓存架', 20, false);
  373. foreach ($toLocation as $index => $value) {
  374. app("CacheShelfService")->lightUp($value, '3', '0', ["title" => "机器人取箱中,禁止操作"]);
  375. Cache::forever("CACHE_SHELF_OCCUPANCY_{$stations[$index]->id}", true);
  376. }
  377. app("StationService")->locationOccupyMulti($toLocation->toArray());
  378. }
  379. public function update_order_packages_is_manual_update()
  380. {
  381. $descriptions = Log::query()
  382. ->select('description')
  383. ->whereBetween('created_at', ['2021-08-31 10:30:00', '2021-08-31 10:35:00'])
  384. ->where('class', 'like', 'https://was.baoshi56.com/package/logistic/batchUpdate%')->pluck('description');
  385. foreach ($descriptions as $description) {
  386. $description = substr($description, 9);
  387. $description = \Illuminate\Support\Str::before($description, "}");
  388. $obj = json_decode($description . '}', true);
  389. OrderPackage::query()
  390. ->whereIn('logistic_number', $obj['logistic_numbers'])
  391. ->update([
  392. 'status' => '无',
  393. 'is_manual_update' => false,
  394. ]);
  395. }
  396. }
  397. public function testUpdateInv()
  398. {
  399. ini_set('max_execution_time', 0);
  400. ini_set('memory_limit', '4096M');
  401. $sql = <<<sql
  402. select FMLOTNUM,FMLOCATION,PLANTOLOCATION,CREATE_TRANSACTIONID,SKU,CUSTOMERID from TSK_TASKLISTS
  403. where CUSTOMERID=?
  404. AND FMLOCATION= ?
  405. AND OPENWHO = ?
  406. AND TASKPROCESS = ?
  407. AND DOCTYPE = ?
  408. AND TASKTYPE = ?
  409. AND LOTATT05=?
  410. AND LOTATT08=?
  411. AND PLANTOID = ?
  412. and OPENTIME>=TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')
  413. and OPENTIME<=TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')
  414. sql;
  415. $CUSTOMERID = 'JIANSHANG';
  416. $FMLOCATION = 'STAGEWH02';
  417. $OPENWHO = 'WCS';
  418. $TASKPROCESS = '00';
  419. $DOCTYPE = 'ASN';
  420. $TASKTYPE = 'PA';
  421. $LOTATT05 = 'MJ-CP';
  422. $LOTATT08 = 'ZP';
  423. $PLANTOID = '*';
  424. $traceid = 'JIANSHANG03';
  425. $start = '2021-09-02 23:59:59';
  426. $end = '2021-09-03 11:10:00';
  427. $res = DB::connection("oracle")->select(DB::raw($sql),
  428. [$CUSTOMERID, $FMLOCATION, $OPENWHO, $TASKPROCESS, $DOCTYPE, $TASKTYPE, $LOTATT05, $LOTATT08, $PLANTOID, $start, $end]);
  429. $resItems = array_chunk($res, 200);
  430. foreach ($resItems as $res) {
  431. DB::connection("oracle")->beginTransaction();
  432. try {
  433. foreach ($res as $re) {
  434. DB::connection("oracle")->table('INV_LOT_LOC_ID')
  435. ->where([
  436. 'LOTNUM' => $re->fmlotnum,
  437. 'LOCATIONID' => $re->fmlocation,
  438. 'CUSTOMERID' => $re->customerid,
  439. 'sku' => $re->sku,
  440. 'TRACEID' => '*',
  441. ])
  442. ->update([
  443. 'TRACEID' => $traceid,
  444. 'EDITWHO' => 'WCS_',
  445. ]);
  446. if ($re->fmlocation != $re->plantolocation) {
  447. DB::connection("oracle")->table('INV_LOT_LOC_ID')
  448. ->where([
  449. 'LOTNUM' => $re->fmlotnum,
  450. 'LOCATIONID' => $re->plantolocation,
  451. 'CUSTOMERID' => $re->customerid,
  452. 'sku' => $re->sku,
  453. 'TRACEID' => '*',
  454. ])
  455. ->update([
  456. 'TRACEID' => $traceid,
  457. 'EDITWHO' => 'WCS_',
  458. ]);
  459. }
  460. DB::connection("oracle")->commit();
  461. }
  462. dd(true);
  463. } catch (\Exception $e) {
  464. DB::connection("oracle")->rollBack();
  465. dd($e->getMessage());
  466. }
  467. }
  468. }
  469. /**
  470. * 重置15天内的数据
  471. */
  472. public function order_packages_init()
  473. {
  474. OrderPackage::query()
  475. ->whereBetween('created_at', [now()->subDays(15), now()])
  476. ->update([
  477. 'is_delay_deliver' => 0,
  478. 'sync_routes_flag' => 0,
  479. 'status' => 1,
  480. 'exception_status' => 0,
  481. ]);
  482. OrderPackage::query()
  483. ->whereBetween('created_at', [now()->subDays(15), now()])
  484. ->whereNotNull('received_at')
  485. ->update([
  486. 'status' => 7,
  487. ]);
  488. }
  489. public function syncOrderPackage(){
  490. ini_set('memory_limit','500M');
  491. ini_set('max_execution_time', 0);
  492. $orderPackingSummary = OracleDocOrderPackingSummary::query()
  493. ->where('editTime','>=','2021-09-11 12:00:00')
  494. ->where('editTime','<=','2021-09-12 12:40:00')
  495. ->get();
  496. $orderPackingSummary_chunk = $orderPackingSummary->chunk(200);
  497. foreach ($orderPackingSummary_chunk as $orderPackingSummarys) {
  498. foreach ($orderPackingSummarys as $orderPackingSummary) {
  499. $orderPackage = OrderPackage::query()->where('logistic_number',$orderPackingSummary->traceid)->first();
  500. $orderPackage->update([
  501. 'uploaded_to_wms'=> true,
  502. 'weight'=>$orderPackingSummary->grossweight,
  503. 'length'=>$orderPackingSummary->length,
  504. 'width'=>$orderPackingSummary->width,
  505. 'height'=>$orderPackingSummary->height,
  506. 'weighed_at'=>$orderPackingSummary->edittime
  507. ]);
  508. dispatch(new WeightUpdateInstantBill($orderPackage));
  509. }
  510. }
  511. return ['success' => true];
  512. }
  513. public function collectUpload()
  514. {
  515. /** @var OrderPackageService $service */
  516. $service = app('OrderPackageService');
  517. return $service->collectUpload([
  518. '75601803541125'
  519. ]);
  520. }
  521. public function init_在途异常()
  522. {
  523. $logistic_numbers = OrderPackage::query()
  524. ->select('logistic_number')
  525. ->where('exception_status', 5)
  526. ->where('created_at', '>=', now()->subDays(20)->toDateTimeString())
  527. ->pluck('logistic_number');
  528. /** @var OrderPackageReceivedSyncService $service */
  529. $service = app('OrderPackageReceivedSyncService');
  530. $service->syncLogisticRoute(false, $logistic_numbers);
  531. // $logistic_numbers = OrderPackage::query()
  532. // ->select(['logistic_number', 'order_id', 'id'])
  533. // ->whereIn('order_id', function ($query) {
  534. // $query->from('orders')->selectRaw('id')->whereIn('logistic_id', function ($builder) {
  535. // $builder->from('logistics')->selectRaw('id')->where('type', '=', '快递')->whereNotIn('belong_company', ['顺丰', '中通', '韵达', '圆通', '京东']);
  536. // });
  537. // })
  538. // ->where('exception_status', 5)
  539. // ->where('created_at', '>=', now()->subDays(20)->toDateTimeString())
  540. // ->pluck('logistic_number');
  541. // $service->syncLogisticRouteByAliJiSu($logistic_numbers);
  542. }
  543. public function store()
  544. {
  545. ini_set('max_execution_time', 0);
  546. ini_set('memory_limit', '1024M');
  547. // $now = Carbon::now();
  548. // $startDate = $this->getDate();
  549. $startDate = '2021-09-25 13:23:14';
  550. $diffDay = 1; // 天数
  551. for($i = 0;$i<=$diffDay;$i++){
  552. $endDate = Carbon::parse($startDate)->addDays(1)->toDateTimeString();
  553. $doc_asn_headers = $this->getDocAsnHeader($startDate,$endDate);
  554. // if (count($doc_asn_headers)>0){
  555. // $this->syncStores($doc_asn_headers);
  556. // $this->syncDate($endDate);
  557. // }
  558. dump($startDate,$endDate);
  559. $startDate = $endDate;
  560. }
  561. $this->clearCache();
  562. // ValueStore::query()->updateOrCreate([
  563. // 'name' => 'last_asn_sync_task_end_at',
  564. // ], [
  565. // 'name' => 'last_asn_sync_task_end_at',
  566. // 'value' => $now,
  567. // ]);
  568. }
  569. public function getDocAsnHeader($startDate,$endDate)
  570. {
  571. return OracleDOCASNHeader::query()
  572. ->with(['asnType', 'asnStatus'])
  573. ->select('asnno','asnstatus','asntype','addtime','edittime','customerid','notes','warehouseid','asnreference3','asnreference2')
  574. ->where('EditTime', '>=', $startDate)
  575. ->where('EditTime', '<=', $endDate)
  576. ->whereColumn('EditTime', '<>', 'addTime')
  577. ->orderByDesc('EditTime')
  578. ->get();
  579. }
  580. public function getDate(){
  581. return ValueStore::query()->where('name','asn_last_updated_sync_at')->value('value');
  582. }
  583. public function syncStores($doc_asn_headers){
  584. $service = new StoreService();
  585. $service->createStore($doc_asn_headers,"update");
  586. $service->updateStore($doc_asn_headers);
  587. $service->createStoreRejected($doc_asn_headers);
  588. unset($doc_asn_headers);
  589. }
  590. public function syncDate($date)
  591. {
  592. // 同步更新时间
  593. ValueStore::query()->updateOrCreate([
  594. 'name' => 'asn_last_updated_sync_at',
  595. ], [
  596. 'name' => 'asn_last_updated_sync_at',
  597. 'value' => $date,
  598. ]);
  599. }
  600. public function clearCache()
  601. {
  602. $service = new StoreService();
  603. $update_set = config('sync.asn_sync.cache_prefix.update_set');
  604. $update_keys = config('sync.asn_sync.cache_prefix.update_keys');
  605. $service->deleteCacheKey($update_set, $update_keys);
  606. // 清空保存 ans 号的栈
  607. // 清除 更新时间 开始 结束
  608. }
  609. public function updateStoreItem()
  610. {
  611. ini_set('max_execution_time', 0);
  612. ini_set('memory_limit', '1024M');
  613. $storeIds = Store::query()
  614. ->where('updated_at', '>=', '2021-09-25 13:21:26')
  615. ->whereColumn('updated_at', '<>', 'created_at')
  616. ->pluck('id');
  617. $storeItemMaxIds = StoreItem::query()
  618. ->selectRaw('max(id) as max_id')
  619. ->whereIn('store_id', $storeIds)
  620. ->groupBy(['store_id', 'asn_line_code'])
  621. ->get();
  622. // dd($storeItemMaxIds->count());
  623. $storeItems = StoreItem::query()
  624. ->whereIn('store_id', $storeIds)
  625. ->whereNotIn('id', $storeItemMaxIds)
  626. ->delete();
  627. }
  628. public function init_SettlementBillReportTask()
  629. {
  630. $this->dispatch(new SettlementBillReportJob('2021-09-01',[]));
  631. }
  632. public function test2(){
  633. $source_file ="E:\OneDrive\桌面\工作目录\文件库\\5.jpg";
  634. $img = ImageCreateFromJpeg($source_file);
  635. imagecolortransparent($img);//将某个颜色设置成透明色
  636. imagecolorstotal($img);
  637. header('Content-type:image/jpeg');
  638. imagejpeg($img);
  639. //dd($this->run('E:\OneDrive\桌面\工作目录\文件库\5.jpg', 'E:\OneDrive\桌面\工作目录\文件库\6.jpg'));
  640. }
  641. const FILE_NOT_FOUND = '-1';
  642. const FILE_EXTNAME_ILLEGAL = '-2';
  643. public function run($src1, $src2) {
  644. if(!is_file($src1) || !is_file($src2)) exit(self::FILE_NOT_FOUND);
  645. $hash1 = $this->getHashValue($src1);
  646. $hash2 = $this->getHashValue($src2);
  647. if(strlen($hash1) !== strlen($hash2)) return false;
  648. $count = 0;
  649. $len = strlen($hash1);
  650. for($i = 0; $i < $len; $i++) if($hash1[$i] !== $hash2[$i]){
  651. $count++;
  652. }
  653. dd($count);
  654. return $count <= 10 ? true : false;
  655. }
  656. public function getImage($file) {
  657. $extname = pathinfo($file, PATHINFO_EXTENSION);
  658. if(!in_array($extname, ['jpg','jpeg','png','gif'])) exit(self::FILE_EXTNAME_ILLEGAL);
  659. $img = call_user_func('imagecreatefrom'. ( $extname == 'jpg' ? 'jpeg' : $extname ) , $file);
  660. return $img;
  661. }
  662. public function getHashValue($file) {
  663. $w = 32;
  664. $h = 32;
  665. $img = imagecreatetruecolor($w, $h);
  666. list($src_w, $src_h) = getimagesize($file);
  667. $src = $this->getImage($file);
  668. imagecopyresampled($img, $src, 0, 0, 0, 0, $w, $h, $src_w, $src_h);
  669. imagedestroy($src);
  670. $total = 0;
  671. $array = array();
  672. for( $y = 0; $y < $h; $y++) {
  673. for ($x = 0; $x < $w; $x++) {
  674. $rgb = imagecolorat($img, $x, $y);
  675. $gray = $rgb & 0xFF;
  676. /*dump([
  677. ($rgb >> 8) & 0xFF,
  678. ($rgb >> 16) & 0xFF,
  679. $rgb & 0xFF,
  680. ]);*/
  681. if(!isset($array[$y])) $array[$y] = array();
  682. $array[$y][$x] = $gray;
  683. $total += $gray;
  684. }
  685. }
  686. imagedestroy($img);
  687. $average = intval($total / ($w * $h * 2));
  688. $hash = '';
  689. for($y = 0; $y < $h; $y++) {
  690. for($x = 0; $x < $w; $x++) {
  691. $hash .= ($array[$y][$x] >= $average) ? '1' : '0';
  692. }
  693. }
  694. dump($hash);
  695. return $hash;
  696. }
  697. public function sortTransferStatus()
  698. {
  699. $orderPackage = OrderPackage::query()->where('logistic_number','75601831068018')->first();
  700. app('OrderPackageService')->sortOrderPackageTransferStatus($orderPackage);
  701. dd($orderPackage);
  702. }
  703. public function clear_work_space()
  704. {
  705. \App\LaborApply::query()->truncate();
  706. LaborCompanyDispatch::query()->truncate();
  707. \App\LaborCompanyDispatchDetail::query()->truncate();
  708. }
  709. }