TestController.php 27 KB

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