TestController.php 28 KB

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