TestController.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  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(AndroidGateRequest $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(AndroidGateRequest $request)
  195. {
  196. dd(Waybill::query()->with(["order:id,address","logistic:id,name","amountUnit:id,name"])
  197. ->select("id","order_id","logistic_id","amount_unit_id",
  198. "waybill_number","destination","recipient","recipient_mobile",
  199. "carrier_bill","warehouse_weight","carrier_weight","inquire_tel",
  200. "warehouse_weight_other","carrier_weight_other","amount","origination")
  201. ->paginate(15)->append(["carrier_name","amount_unit_name","remove_relation"])->toJson());
  202. $url = config('api_logistic.collectUpload.ZTO.prod.url');
  203. $xAppKey = config('api_logistic.collectUpload.ZTO.prod.x-appKey');
  204. $appSecret = config('api_logistic.collectUpload.ZTO.prod.appSecret');
  205. $appId = config('api_logistic.collectUpload.ZTO.prod.appId');
  206. dd(env('APP_ENV'));
  207. //中通接口请求body
  208. $collectUploadDTOS = [[
  209. 'billCode' => "75811463670235",
  210. 'weight' => 0,
  211. 'appId' => $appId,
  212. 'importDate' => now()->toDateTimeString(),
  213. ]];
  214. $body = json_encode([
  215. 'collectUploadDTOS' => $collectUploadDTOS,
  216. ], JSON_UNESCAPED_UNICODE);
  217. $data_digest = base64_encode(md5($body . $appSecret, TRUE));
  218. $headers = [
  219. 'Content-Type' => 'application/json; charset=UTF-8',
  220. 'x-companyid' => $xAppKey,
  221. 'x-datadigest' => $data_digest,
  222. ];
  223. dd(Http::withHeaders($headers)->withBody($body, 'application/json')->post($url)->body());
  224. $stores = Store::query()->whereIn("id",[490692,492252,492405,493259,491290,491758,492252,492989,493522,
  225. 496079,490702,491173,491780,493522,488622,490891,491020,491173,493308,489448,491020,491184,493573,493977,
  226. 496105,492086,493714,493977,496118,492593,492592,492591,492590,493011,493979,490721,492192,493429,493978,
  227. 496106,490721,491460,493165,496114,489319,489436,490703,491190,493957,496115,496114,489436,491147,
  228. 491695,492395,490711,491461,491695,492079,494533,496099,496096,490711,491458,491797,492244,
  229. 492422,496098,496097,496100,491458,491798,493572,493752,490443,491457,492394,493531,493572,491687,
  230. 492394,492968,493782,490431,490994,493782,488570,489103,490616,490994,493966,489862,490616,
  231. 490629,495645,490629,491455,488793])->get();
  232. $this->dispatch(new StoreCreateInstantBill($stores));
  233. dd(1);
  234. /** @var StationTaskMaterialBox $stationTaskMaterialBox */
  235. $stationTaskMaterialBox = app("StorageService")->createWarehousingTask($stationService->getStation_byType('立库')["id"],$station->materialBox->id);
  236. app("CacheShelfService")->lightUp($station->code,'3','0',['title'=>"等待机器人拿走,请勿操作"]);
  237. Cache::forever("CACHE_SHELF_OCCUPANCY_{$station->id}",true);
  238. dd($ForeignHaiRoboticsService->putBinToStore_fromCacheShelf($stationTaskMaterialBox, $station));
  239. $user = Auth::user();
  240. $remark = "zengjunlj";
  241. $ownerName = 'zengjunlj' ?? '';
  242. $clientCode = 'zengjunljljlj' ?? '';
  243. $msg = $user["name"]."建立了新工单<br/>".$ownerName.":".$clientCode."<br/>".$remark;
  244. NotificationService::SingleRegister($msg,$clientCode,"订单管理-问题件");
  245. dd(1);
  246. $seeLog = SeeLog::query()->find(9);
  247. Notification::send(Auth::user(),new RoutineNotification($seeLog->toArray()));
  248. dd(1);
  249. Broadcast::channel('notification', function ($user, $id) {
  250. return (int) $user->id === (int) $id;
  251. });
  252. dd(1);
  253. Notification::send(Auth::user(),new RoutineNotification($seeLog->toArray()));
  254. dd(1);
  255. $username = config('database.connections.oracle.username');
  256. $password = config('database.connections.oracle.password');
  257. $host = config('database.connections.oracle.host');
  258. $service_name = config('database.connections.oracle.service_name');
  259. $conn = oci_connect($username, $password, $host . '/' . $service_name,"utf8");
  260. $sql = <<<sql
  261. BEGIN
  262. SPSO_HardAllocation_Process('WH01','Allocation','By OrderNO',
  263. null,'SO21090100007','0',null,
  264. 'zhouzhendong',:CODE);
  265. END;
  266. sql;
  267. $stmt = oci_parse($conn, $sql);
  268. $code = "";
  269. oci_bind_by_name($stmt, ':CODE', $code,300);
  270. oci_execute($stmt);
  271. oci_close($conn);
  272. dd($code);
  273. //
  274. $no = "SO21090900001";
  275. $db = DB::connection("oracle");
  276. //$order = $db->selectOne(DB::raw("select * from DOC_ORDER_HEADER where orderno = ?"),[$no]);
  277. dd($db->select($sql,[
  278. ]));
  279. $db->select("CALL SPSO_HardAllocation_Process(?,'Allocation','By OrderNO',null,?,'0',null,'zhouzhendong',@code)",[
  280. $order->warehouseid,$no
  281. ]);
  282. //SPSO_HardAllocation_Process
  283. dd($db->selectOne("select @code"));
  284. $date = "2021-09-14 15:47:00";
  285. dispatch(new TestJob("1"))->delay(Carbon::parse($date));
  286. dispatch(new TestJob("2"))->delay(Carbon::parse($date));
  287. dispatch(new TestJob("3"))->delay(Carbon::parse($date));
  288. dispatch(new TestJob("4"))->delay(Carbon::parse($date));
  289. dispatch(new TestJob("5"))->delay(Carbon::parse($date));
  290. dispatch(new TestJob("6"))->delay(Carbon::parse($date));
  291. dispatch(new TestJob("7"))->delay(Carbon::parse($date));
  292. dispatch(new TestJob("8"))->delay(Carbon::parse($date));
  293. dispatch(new TestJob("9"))->delay(Carbon::parse($date));
  294. dispatch(new TestJob("10"))->delay(Carbon::parse($date));
  295. dd(1);
  296. Station::query()->where("station_type_id", 5)->update(["status" => 1]);
  297. Cache::forget("CACHE_SHELF_AVAILABLE");
  298. $station = ["HAIB1-01-01", "HAIB1-02-01"];
  299. $material = ["IDE0001824", "IDE0001740", "IDE0002710"];
  300. Station::query()->whereIn("code", $station)->update(["status" => 0]);
  301. $stations = Station::query()->whereIn("code", $station)->get();
  302. $materials = MaterialBox::query()->whereIn("code", $material)->get();
  303. $dateTime = date("Y-m-d H:i:s");
  304. $task1 = StationTaskMaterialBox::query()->create([
  305. 'station_id' => $stations[0]->id,
  306. 'material_box_id' => $materials[0]->id,
  307. 'station_task_batch_id' => 1,
  308. 'status' => '待处理'
  309. ]);
  310. $task2 = StationTaskMaterialBox::query()->create([
  311. 'station_id' => $stations[1]->id,
  312. 'material_box_id' => $materials[1]->id,
  313. 'station_task_batch_id' => 1,
  314. 'status' => '待处理'
  315. ]);
  316. $task3 = StationTaskMaterialBox::query()->create([
  317. 'station_id' => 6,
  318. 'material_box_id' => $materials[2]->id,
  319. 'station_task_batch_id' => 1,
  320. 'status' => '待处理'
  321. ]);
  322. TaskTransaction::query()->insert([[
  323. "doc_code" => "test",
  324. "bar_code" => "test",
  325. "to_station_id" => $stations[0]->id,
  326. "material_box_id" => $materials[0]->id,
  327. "task_id" => $task1->id,
  328. "commodity_id" => 505012,//XUNI03
  329. "amount" => 1,
  330. "type" => "出库",
  331. "status" => 0,
  332. "mark" => 2,
  333. "bin_number" => 1,
  334. "created_at" => $dateTime,
  335. "updated_at" => $dateTime,
  336. ], [
  337. "doc_code" => "test",
  338. "bar_code" => "test",
  339. "to_station_id" => $stations[1]->id,
  340. "material_box_id" => $materials[1]->id,
  341. "task_id" => $task2->id,
  342. "commodity_id" => 505012,//XUNI03
  343. "amount" => 1,
  344. "type" => "出库",
  345. "status" => 0,
  346. "mark" => 2,
  347. "bin_number" => 1,
  348. "created_at" => $dateTime,
  349. "updated_at" => $dateTime,
  350. ], [
  351. "doc_code" => "test",
  352. "bar_code" => "test",
  353. "to_station_id" => 6,
  354. "material_box_id" => $materials[2]->id,
  355. "task_id" => $task3->id,
  356. "commodity_id" => 505012,//XUNI03
  357. "amount" => 1,
  358. "type" => "出库",
  359. "status" => 3,
  360. "mark" => 2,
  361. "bin_number" => 1,
  362. "created_at" => $dateTime,
  363. "updated_at" => $dateTime,
  364. ]]);
  365. $foreignHaiRoboticsService = new ForeignHaiRoboticsService();
  366. $toLocation = collect($station);
  367. $taskMaterialBoxes = collect([$task1, $task2]);
  368. $foreignHaiRoboticsService->
  369. fetchGroup_multiLocation($toLocation, $taskMaterialBoxes, '', '立架出至缓存架', 20, false);
  370. foreach ($toLocation as $index => $value) {
  371. app("CacheShelfService")->lightUp($value, '3', '0', ["title" => "机器人取箱中,禁止操作"]);
  372. Cache::forever("CACHE_SHELF_OCCUPANCY_{$stations[$index]->id}", true);
  373. }
  374. app("StationService")->locationOccupyMulti($toLocation->toArray());
  375. }
  376. public function update_order_packages_is_manual_update()
  377. {
  378. $descriptions = Log::query()
  379. ->select('description')
  380. ->whereBetween('created_at', ['2021-08-31 10:30:00', '2021-08-31 10:35:00'])
  381. ->where('class', 'like', 'https://was.baoshi56.com/package/logistic/batchUpdate%')->pluck('description');
  382. foreach ($descriptions as $description) {
  383. $description = substr($description, 9);
  384. $description = \Illuminate\Support\Str::before($description, "}");
  385. $obj = json_decode($description . '}', true);
  386. OrderPackage::query()
  387. ->whereIn('logistic_number', $obj['logistic_numbers'])
  388. ->update([
  389. 'status' => '无',
  390. 'is_manual_update' => false,
  391. ]);
  392. }
  393. }
  394. public function testUpdateInv()
  395. {
  396. ini_set('max_execution_time', 0);
  397. ini_set('memory_limit', '4096M');
  398. $sql = <<<sql
  399. select FMLOTNUM,FMLOCATION,PLANTOLOCATION,CREATE_TRANSACTIONID,SKU,CUSTOMERID from TSK_TASKLISTS
  400. where CUSTOMERID=?
  401. AND FMLOCATION= ?
  402. AND OPENWHO = ?
  403. AND TASKPROCESS = ?
  404. AND DOCTYPE = ?
  405. AND TASKTYPE = ?
  406. AND LOTATT05=?
  407. AND LOTATT08=?
  408. AND PLANTOID = ?
  409. and OPENTIME>=TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')
  410. and OPENTIME<=TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')
  411. sql;
  412. $CUSTOMERID = 'JIANSHANG';
  413. $FMLOCATION = 'STAGEWH02';
  414. $OPENWHO = 'WCS';
  415. $TASKPROCESS = '00';
  416. $DOCTYPE = 'ASN';
  417. $TASKTYPE = 'PA';
  418. $LOTATT05 = 'MJ-CP';
  419. $LOTATT08 = 'ZP';
  420. $PLANTOID = '*';
  421. $traceid = 'JIANSHANG03';
  422. $start = '2021-09-02 23:59:59';
  423. $end = '2021-09-03 11:10:00';
  424. $res = DB::connection("oracle")->select(DB::raw($sql),
  425. [$CUSTOMERID, $FMLOCATION, $OPENWHO, $TASKPROCESS, $DOCTYPE, $TASKTYPE, $LOTATT05, $LOTATT08, $PLANTOID, $start, $end]);
  426. $resItems = array_chunk($res, 200);
  427. foreach ($resItems as $res) {
  428. DB::connection("oracle")->beginTransaction();
  429. try {
  430. foreach ($res as $re) {
  431. DB::connection("oracle")->table('INV_LOT_LOC_ID')
  432. ->where([
  433. 'LOTNUM' => $re->fmlotnum,
  434. 'LOCATIONID' => $re->fmlocation,
  435. 'CUSTOMERID' => $re->customerid,
  436. 'sku' => $re->sku,
  437. 'TRACEID' => '*',
  438. ])
  439. ->update([
  440. 'TRACEID' => $traceid,
  441. 'EDITWHO' => 'WCS_',
  442. ]);
  443. if ($re->fmlocation != $re->plantolocation) {
  444. DB::connection("oracle")->table('INV_LOT_LOC_ID')
  445. ->where([
  446. 'LOTNUM' => $re->fmlotnum,
  447. 'LOCATIONID' => $re->plantolocation,
  448. 'CUSTOMERID' => $re->customerid,
  449. 'sku' => $re->sku,
  450. 'TRACEID' => '*',
  451. ])
  452. ->update([
  453. 'TRACEID' => $traceid,
  454. 'EDITWHO' => 'WCS_',
  455. ]);
  456. }
  457. DB::connection("oracle")->commit();
  458. }
  459. dd(true);
  460. } catch (\Exception $e) {
  461. DB::connection("oracle")->rollBack();
  462. dd($e->getMessage());
  463. }
  464. }
  465. }
  466. /**
  467. * 重置15天内的数据
  468. */
  469. public function order_packages_init()
  470. {
  471. OrderPackage::query()
  472. ->whereBetween('created_at', [now()->subDays(15), now()])
  473. ->update([
  474. 'is_delay_deliver' => 0,
  475. 'sync_routes_flag' => 0,
  476. 'status' => 1,
  477. 'exception_status' => 0,
  478. ]);
  479. OrderPackage::query()
  480. ->whereBetween('created_at', [now()->subDays(15), now()])
  481. ->whereNotNull('received_at')
  482. ->update([
  483. 'status' => 7,
  484. ]);
  485. }
  486. public function syncOrderPackage(){
  487. ini_set('memory_limit','500M');
  488. ini_set('max_execution_time', 0);
  489. $orderPackingSummary = OracleDocOrderPackingSummary::query()
  490. ->where('editTime','>=','2021-09-11 12:00:00')
  491. ->where('editTime','<=','2021-09-12 12:40:00')
  492. ->get();
  493. $orderPackingSummary_chunk = $orderPackingSummary->chunk(200);
  494. foreach ($orderPackingSummary_chunk as $orderPackingSummarys) {
  495. foreach ($orderPackingSummarys as $orderPackingSummary) {
  496. $orderPackage = OrderPackage::query()->where('logistic_number',$orderPackingSummary->traceid)->first();
  497. $orderPackage->update([
  498. 'uploaded_to_wms'=> true,
  499. 'weight'=>$orderPackingSummary->grossweight,
  500. 'length'=>$orderPackingSummary->length,
  501. 'width'=>$orderPackingSummary->width,
  502. 'height'=>$orderPackingSummary->height,
  503. 'weighed_at'=>$orderPackingSummary->edittime
  504. ]);
  505. dispatch(new WeightUpdateInstantBill($orderPackage));
  506. }
  507. }
  508. return ['success' => true];
  509. }
  510. public function collectUpload()
  511. {
  512. /** @var OrderPackageService $service */
  513. $service = app('OrderPackageService');
  514. return $service->collectUpload([
  515. '75601803541125'
  516. ]);
  517. }
  518. public function init_在途异常()
  519. {
  520. $logistic_numbers = OrderPackage::query()
  521. ->select('logistic_number')
  522. ->where('exception_status', 5)
  523. ->where('created_at', '>=', now()->subDays(20)->toDateTimeString())
  524. ->pluck('logistic_number');
  525. /** @var OrderPackageReceivedSyncService $service */
  526. $service = app('OrderPackageReceivedSyncService');
  527. $service->syncLogisticRoute(false, $logistic_numbers);
  528. // $logistic_numbers = OrderPackage::query()
  529. // ->select(['logistic_number', 'order_id', 'id'])
  530. // ->whereIn('order_id', function ($query) {
  531. // $query->from('orders')->selectRaw('id')->whereIn('logistic_id', function ($builder) {
  532. // $builder->from('logistics')->selectRaw('id')->where('type', '=', '快递')->whereNotIn('belong_company', ['顺丰', '中通', '韵达', '圆通', '京东']);
  533. // });
  534. // })
  535. // ->where('exception_status', 5)
  536. // ->where('created_at', '>=', now()->subDays(20)->toDateTimeString())
  537. // ->pluck('logistic_number');
  538. // $service->syncLogisticRouteByAliJiSu($logistic_numbers);
  539. }
  540. public function store()
  541. {
  542. ini_set('max_execution_time', 0);
  543. ini_set('memory_limit', '1024M');
  544. // $now = Carbon::now();
  545. // $startDate = $this->getDate();
  546. $startDate = '2021-09-25 13:23:14';
  547. $diffDay = 1; // 天数
  548. for($i = 0;$i<=$diffDay;$i++){
  549. $endDate = Carbon::parse($startDate)->addDays(1)->toDateTimeString();
  550. $doc_asn_headers = $this->getDocAsnHeader($startDate,$endDate);
  551. // if (count($doc_asn_headers)>0){
  552. // $this->syncStores($doc_asn_headers);
  553. // $this->syncDate($endDate);
  554. // }
  555. dump($startDate,$endDate);
  556. $startDate = $endDate;
  557. }
  558. $this->clearCache();
  559. // ValueStore::query()->updateOrCreate([
  560. // 'name' => 'last_asn_sync_task_end_at',
  561. // ], [
  562. // 'name' => 'last_asn_sync_task_end_at',
  563. // 'value' => $now,
  564. // ]);
  565. }
  566. public function getDocAsnHeader($startDate,$endDate)
  567. {
  568. return OracleDOCASNHeader::query()
  569. ->with(['asnType', 'asnStatus'])
  570. ->select('asnno','asnstatus','asntype','addtime','edittime','customerid','notes','warehouseid','asnreference3','asnreference2')
  571. ->where('EditTime', '>=', $startDate)
  572. ->where('EditTime', '<=', $endDate)
  573. ->whereColumn('EditTime', '<>', 'addTime')
  574. ->orderByDesc('EditTime')
  575. ->get();
  576. }
  577. public function getDate(){
  578. return ValueStore::query()->where('name','asn_last_updated_sync_at')->value('value');
  579. }
  580. public function syncStores($doc_asn_headers){
  581. $service = new StoreService();
  582. $service->createStore($doc_asn_headers,"update");
  583. $service->updateStore($doc_asn_headers);
  584. $service->createStoreRejected($doc_asn_headers);
  585. unset($doc_asn_headers);
  586. }
  587. public function syncDate($date)
  588. {
  589. // 同步更新时间
  590. ValueStore::query()->updateOrCreate([
  591. 'name' => 'asn_last_updated_sync_at',
  592. ], [
  593. 'name' => 'asn_last_updated_sync_at',
  594. 'value' => $date,
  595. ]);
  596. }
  597. public function clearCache()
  598. {
  599. $service = new StoreService();
  600. $update_set = config('sync.asn_sync.cache_prefix.update_set');
  601. $update_keys = config('sync.asn_sync.cache_prefix.update_keys');
  602. $service->deleteCacheKey($update_set, $update_keys);
  603. // 清空保存 ans 号的栈
  604. // 清除 更新时间 开始 结束
  605. }
  606. public function updateStoreItem()
  607. {
  608. ini_set('max_execution_time', 0);
  609. ini_set('memory_limit', '1024M');
  610. $storeIds = Store::query()
  611. ->where('updated_at', '>=', '2021-09-25 13:21:26')
  612. ->whereColumn('updated_at', '<>', 'created_at')
  613. ->pluck('id');
  614. $storeItemMaxIds = StoreItem::query()
  615. ->selectRaw('max(id) as max_id')
  616. ->whereIn('store_id', $storeIds)
  617. ->groupBy(['store_id', 'asn_line_code'])
  618. ->get();
  619. // dd($storeItemMaxIds->count());
  620. $storeItems = StoreItem::query()
  621. ->whereIn('store_id', $storeIds)
  622. ->whereNotIn('id', $storeItemMaxIds)
  623. ->delete();
  624. }
  625. public function init_SettlementBillReportTask()
  626. {
  627. $this->dispatch(new SettlementBillReportJob('2021-08-01',[]));
  628. }
  629. public function test2(){
  630. $source_file ="E:\OneDrive\桌面\工作目录\文件库\\5.jpg";
  631. $img = ImageCreateFromJpeg($source_file);
  632. imagecolortransparent($img);//将某个颜色设置成透明色
  633. imagecolorstotal($img);
  634. header('Content-type:image/jpeg');
  635. imagejpeg($img);
  636. //dd($this->run('E:\OneDrive\桌面\工作目录\文件库\5.jpg', 'E:\OneDrive\桌面\工作目录\文件库\6.jpg'));
  637. }
  638. const FILE_NOT_FOUND = '-1';
  639. const FILE_EXTNAME_ILLEGAL = '-2';
  640. public function run($src1, $src2) {
  641. if(!is_file($src1) || !is_file($src2)) exit(self::FILE_NOT_FOUND);
  642. $hash1 = $this->getHashValue($src1);
  643. $hash2 = $this->getHashValue($src2);
  644. if(strlen($hash1) !== strlen($hash2)) return false;
  645. $count = 0;
  646. $len = strlen($hash1);
  647. for($i = 0; $i < $len; $i++) if($hash1[$i] !== $hash2[$i]){
  648. $count++;
  649. }
  650. dd($count);
  651. return $count <= 10 ? true : false;
  652. }
  653. public function getImage($file) {
  654. $extname = pathinfo($file, PATHINFO_EXTENSION);
  655. if(!in_array($extname, ['jpg','jpeg','png','gif'])) exit(self::FILE_EXTNAME_ILLEGAL);
  656. $img = call_user_func('imagecreatefrom'. ( $extname == 'jpg' ? 'jpeg' : $extname ) , $file);
  657. return $img;
  658. }
  659. public function getHashValue($file) {
  660. $w = 32;
  661. $h = 32;
  662. $img = imagecreatetruecolor($w, $h);
  663. list($src_w, $src_h) = getimagesize($file);
  664. $src = $this->getImage($file);
  665. imagecopyresampled($img, $src, 0, 0, 0, 0, $w, $h, $src_w, $src_h);
  666. imagedestroy($src);
  667. $total = 0;
  668. $array = array();
  669. for( $y = 0; $y < $h; $y++) {
  670. for ($x = 0; $x < $w; $x++) {
  671. $rgb = imagecolorat($img, $x, $y);
  672. $gray = $rgb & 0xFF;
  673. /*dump([
  674. ($rgb >> 8) & 0xFF,
  675. ($rgb >> 16) & 0xFF,
  676. $rgb & 0xFF,
  677. ]);*/
  678. if(!isset($array[$y])) $array[$y] = array();
  679. $array[$y][$x] = $gray;
  680. $total += $gray;
  681. }
  682. }
  683. imagedestroy($img);
  684. $average = intval($total / ($w * $h * 2));
  685. $hash = '';
  686. for($y = 0; $y < $h; $y++) {
  687. for($x = 0; $x < $w; $x++) {
  688. $hash .= ($array[$y][$x] >= $average) ? '1' : '0';
  689. }
  690. }
  691. dump($hash);
  692. return $hash;
  693. }
  694. public function sortTransferStatus()
  695. {
  696. $orderPackage = OrderPackage::query()->where('logistic_number','75601831068018')->first();
  697. app('OrderPackageService')->sortOrderPackageTransferStatus($orderPackage);
  698. dd($orderPackage);
  699. }
  700. public function clear_work_space()
  701. {
  702. \App\LaborApply::query()->truncate();
  703. LaborCompanyDispatch::query()->truncate();
  704. \App\LaborCompanyDispatchDetail::query()->truncate();
  705. }
  706. }