TestController.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  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\CalculationArrivedManNumJob;
  18. use App\Jobs\OrderCreateInstantBill;
  19. use App\Jobs\OrderCreateWaybill;
  20. use App\Jobs\SettlementBillReportJob;
  21. use App\Jobs\StoreCreateInstantBill;
  22. use App\Jobs\TestJob;
  23. use App\Jobs\WeightUpdateInstantBill;
  24. use App\LaborCompanyDispatch;
  25. use App\LaborReport;
  26. use App\LaborReportStatus;
  27. use App\Logistic;
  28. use App\MaterialBox;
  29. use App\MaterialBoxModel;
  30. use App\Notifications\RoutineNotification;
  31. use App\OracleDOCASNHeader;
  32. use App\OracleDOCOrderHeader;
  33. use App\OracleDocOrderPackingSummary;
  34. use App\Order;
  35. use App\OrderBin;
  36. use App\OrderIssue;
  37. use App\OrderIssueProcessLog;
  38. use App\OrderPackage;
  39. use App\Owner;
  40. use App\OwnerAreaReport;
  41. use App\OwnerFeeDetail;
  42. use App\OwnerFeeDetailLogistic;
  43. use App\OwnerFeeExpress;
  44. use App\OwnerFeeLogistic;
  45. use App\OwnerFeeOperation;
  46. use App\OwnerFeeOperationDetail;
  47. use App\OwnerFeeStorage;
  48. use App\OwnerPriceExpress;
  49. use App\OwnerPriceOperation;
  50. use App\OrderPackageCountingRecord;
  51. use App\ProcurementCheckSheet;
  52. use App\RejectedBill;
  53. use App\SeeLog;
  54. use App\Services\AuthorityService;
  55. use App\Services\BatchService;
  56. use App\Services\CacheShelfService;
  57. use App\Services\ForeignHaiRoboticsService;
  58. use App\Services\NotificationService;
  59. use App\Services\OrderPackageReceivedSyncService;
  60. use App\Services\OrderPackageService;
  61. use App\Services\OrderService;
  62. use App\Services\OwnerFeeTotalService;
  63. use App\Services\OwnerLogisticFeeReportService;
  64. use App\Services\OwnerPriceOperationService;
  65. use App\Services\OwnerStoreFeeReportService;
  66. use App\Services\OwnerStoreOutFeeReportService;
  67. use App\Services\ReviewService;
  68. use App\Services\StationService;
  69. use App\Services\StorageService;
  70. use App\Services\StoreService;
  71. use App\Station;
  72. use App\StationTask;
  73. use App\StationTaskMaterialBox;
  74. use App\Store;
  75. use App\StoreItem;
  76. use App\TaskTransaction;
  77. use App\Unit;
  78. use App\User;
  79. use App\UserDetail;
  80. use App\UserDutyCheck;
  81. use App\ValueStore;
  82. use App\Waybill;
  83. use App\WorkOrder;
  84. use Carbon\Carbon;
  85. use Carbon\CarbonPeriod;
  86. use Decimal\Decimal;
  87. use Doctrine\DBAL\Exception;
  88. use Firebase\JWT\JWT;
  89. use Illuminate\Database\Eloquent\Builder;
  90. use Illuminate\Database\Eloquent\Collection;
  91. use Illuminate\Database\Eloquent\HigherOrderBuilderProxy;
  92. use Illuminate\Foundation\Http\FormRequest;
  93. use Illuminate\Http\Request;
  94. use Illuminate\Support\Facades\Broadcast;
  95. use Illuminate\Support\Facades\Cache;
  96. use Illuminate\Support\Facades\Auth;
  97. use Illuminate\Support\Facades\Cookie;
  98. use Illuminate\Support\Facades\DB;
  99. use Illuminate\Support\Facades\Http;
  100. use Illuminate\Support\Facades\Log;
  101. use Illuminate\Support\Facades\Notification;
  102. use Illuminate\Support\Facades\URL;
  103. use Illuminate\Support\Facades\Validator;
  104. use Illuminate\Support\Str;
  105. use Laravel\Horizon\Events\JobFailed;
  106. use Monolog\Handler\IFTTTHandler;
  107. use phpDocumentor\Reflection\Types\Resource_;
  108. use PhpOffice\PhpSpreadsheet\Calculation\Web\Service;
  109. use Ramsey\Uuid\Uuid;
  110. use Symfony\Component\ErrorHandler\Error\FatalError;
  111. class TestController extends Controller
  112. {
  113. use AsyncResponse, ErrorPush, Database;
  114. const ASNREFERENCE_2 = 'ASNREFERENCE2';
  115. public function __construct()
  116. {
  117. $this->data["active_test"] = "active";
  118. }
  119. public function method(Request $request, $method)
  120. {
  121. try {
  122. return call_user_func([$this, $method], $request);
  123. }catch (\BadMethodCallException $e){
  124. dd("方法不存在");
  125. }
  126. }
  127. /**
  128. * @param $wave
  129. * @return string
  130. */
  131. private function wms_status($wave): string
  132. {
  133. switch ($wave->wavestatus) {
  134. case 00:
  135. $wms_status = '创建';
  136. break;
  137. case 40:
  138. $wms_status = '部分收货';
  139. break;
  140. case 90:
  141. $wms_status = '取消';
  142. break;
  143. case 99:
  144. $wms_status = '完成';
  145. break;
  146. case 62:
  147. $wms_status = '部分装箱';
  148. break;
  149. default:
  150. $wms_status = (string)$wave->wavestatus;
  151. }
  152. return $wms_status;
  153. }
  154. public function assignBatch()
  155. {
  156. $code = \request("code");
  157. $batches = Batch::query()->where("code",$code)->get();
  158. if (!$batches->count()){
  159. $wave = DB::connection("oracle")->selectOne(DB::raw("select * from DOC_WAVE_HEADER where WAVENO = ?"),[$code]);
  160. if (!$wave){
  161. dd("FLUX无波次");
  162. }
  163. $owner = app("OwnerService")->codeGetOwner($wave->customerid);
  164. $obj = [
  165. "wms_status" => $this->wms_status($wave),
  166. "wms_type"=>$wave->descr,
  167. "created_at"=>date("Y-m-d H:i:s"),
  168. "wms_created_at"=>$wave->addtime,
  169. "updated_at"=>$wave->edittime,
  170. "owner_id"=>$owner->id,
  171. ];
  172. $wave = Batch::query()->where("code",$code)->first();
  173. if (!$wave){
  174. $obj["code"] = $code;
  175. $wave = Batch::query()->create($obj);
  176. }else{
  177. Batch::query()->where("code",$code)->update($obj);
  178. }
  179. $ordernos = array_column(DB::connection("oracle")->select(DB::raw("select orderno from DOC_WAVE_DETAILS where WAVENO = ?"),[$code]),"orderno");
  180. Order::query()->whereIn("code",$ordernos)->update([
  181. "batch_id"=>$wave->id
  182. ]);
  183. Order::query()->with(["batch","bin"])->whereIn("code",$ordernos)->get()->each(function ($order){
  184. if (!$order->bin){
  185. $bin = DB::connection("oracle")->selectOne(DB::raw("select seqno from DOC_WAVE_DETAILS where waveno = ? and orderno = ?"),[$order->batch->code,$order->code]);
  186. if ($bin){
  187. OrderBin::query()->create([
  188. 'order_id' => $order->id,
  189. 'number' => $bin->seqno,
  190. ]);
  191. }
  192. }
  193. });
  194. $batches = Batch::query()->where("code",$code)->get();
  195. }
  196. app("BatchService")->assignTasks($batches);
  197. }
  198. public function test()
  199. {
  200. $st = '[{"taskMode":1,"bins":[{"taskCode":"102876_1632099648.1379","binCode":"IDE0000686","fromLocCode":"BIN-IN1","toLocCode":""}],"groupCode":"_1632099648.1379","priority":10,"sequenceFlag":1}]';
  201. $st = json_decode($st,true);
  202. $st[0]["sequenceFlag"] = 0;
  203. dd(json_encode($st));
  204. $order = Order::query()->find(4367620);
  205. $s = new OrderService();
  206. $s->createInstantBill($order);
  207. }
  208. public function update_order_packages_is_manual_update()
  209. {
  210. $descriptions = Log::query()
  211. ->select('description')
  212. ->whereBetween('created_at', ['2021-08-31 10:30:00', '2021-08-31 10:35:00'])
  213. ->where('class', 'like', 'https://was.baoshi56.com/package/logistic/batchUpdate%')->pluck('description');
  214. foreach ($descriptions as $description) {
  215. $description = substr($description, 9);
  216. $description = \Illuminate\Support\Str::before($description, "}");
  217. $obj = json_decode($description . '}', true);
  218. OrderPackage::query()
  219. ->whereIn('logistic_number', $obj['logistic_numbers'])
  220. ->update([
  221. 'status' => '无',
  222. 'is_manual_update' => false,
  223. ]);
  224. }
  225. }
  226. public function testUpdateInv()
  227. {
  228. ini_set('max_execution_time', 0);
  229. ini_set('memory_limit', '4096M');
  230. $sql = <<<sql
  231. select FMLOTNUM,FMLOCATION,PLANTOLOCATION,CREATE_TRANSACTIONID,SKU,CUSTOMERID from TSK_TASKLISTS
  232. where CUSTOMERID=?
  233. AND FMLOCATION= ?
  234. AND OPENWHO = ?
  235. AND TASKPROCESS = ?
  236. AND DOCTYPE = ?
  237. AND TASKTYPE = ?
  238. AND LOTATT05=?
  239. AND LOTATT08=?
  240. AND PLANTOID = ?
  241. and OPENTIME>=TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')
  242. and OPENTIME<=TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')
  243. sql;
  244. $CUSTOMERID = 'JIANSHANG';
  245. $FMLOCATION = 'STAGEWH02';
  246. $OPENWHO = 'WCS';
  247. $TASKPROCESS = '00';
  248. $DOCTYPE = 'ASN';
  249. $TASKTYPE = 'PA';
  250. $LOTATT05 = 'MJ-CP';
  251. $LOTATT08 = 'ZP';
  252. $PLANTOID = '*';
  253. $traceid = 'JIANSHANG03';
  254. $start = '2021-09-02 23:59:59';
  255. $end = '2021-09-03 11:10:00';
  256. $res = DB::connection("oracle")->select(DB::raw($sql),
  257. [$CUSTOMERID, $FMLOCATION, $OPENWHO, $TASKPROCESS, $DOCTYPE, $TASKTYPE, $LOTATT05, $LOTATT08, $PLANTOID, $start, $end]);
  258. $resItems = array_chunk($res, 200);
  259. foreach ($resItems as $res) {
  260. DB::connection("oracle")->beginTransaction();
  261. try {
  262. foreach ($res as $re) {
  263. DB::connection("oracle")->table('INV_LOT_LOC_ID')
  264. ->where([
  265. 'LOTNUM' => $re->fmlotnum,
  266. 'LOCATIONID' => $re->fmlocation,
  267. 'CUSTOMERID' => $re->customerid,
  268. 'sku' => $re->sku,
  269. 'TRACEID' => '*',
  270. ])
  271. ->update([
  272. 'TRACEID' => $traceid,
  273. 'EDITWHO' => 'WCS_',
  274. ]);
  275. if ($re->fmlocation != $re->plantolocation) {
  276. DB::connection("oracle")->table('INV_LOT_LOC_ID')
  277. ->where([
  278. 'LOTNUM' => $re->fmlotnum,
  279. 'LOCATIONID' => $re->plantolocation,
  280. 'CUSTOMERID' => $re->customerid,
  281. 'sku' => $re->sku,
  282. 'TRACEID' => '*',
  283. ])
  284. ->update([
  285. 'TRACEID' => $traceid,
  286. 'EDITWHO' => 'WCS_',
  287. ]);
  288. }
  289. DB::connection("oracle")->commit();
  290. }
  291. dd(true);
  292. } catch (\Exception $e) {
  293. DB::connection("oracle")->rollBack();
  294. dd($e->getMessage());
  295. }
  296. }
  297. }
  298. /**
  299. * 重置15天内的数据
  300. */
  301. public function order_packages_init()
  302. {
  303. OrderPackage::query()
  304. ->whereBetween('created_at', [now()->subDays(15), now()])
  305. ->update([
  306. 'is_delay_deliver' => 0,
  307. 'sync_routes_flag' => 0,
  308. 'status' => 1,
  309. 'exception_status' => 0,
  310. ]);
  311. OrderPackage::query()
  312. ->whereBetween('created_at', [now()->subDays(15), now()])
  313. ->whereNotNull('received_at')
  314. ->update([
  315. 'status' => 7,
  316. ]);
  317. }
  318. public function syncOrderPackage(){
  319. ini_set('memory_limit','500M');
  320. ini_set('max_execution_time', 0);
  321. $orderPackingSummary = OracleDocOrderPackingSummary::query()
  322. ->where('editTime','>=','2021-09-11 12:00:00')
  323. ->where('editTime','<=','2021-09-12 12:40:00')
  324. ->get();
  325. $orderPackingSummary_chunk = $orderPackingSummary->chunk(200);
  326. foreach ($orderPackingSummary_chunk as $orderPackingSummarys) {
  327. foreach ($orderPackingSummarys as $orderPackingSummary) {
  328. $orderPackage = OrderPackage::query()->where('logistic_number',$orderPackingSummary->traceid)->first();
  329. $orderPackage->update([
  330. 'uploaded_to_wms'=> true,
  331. 'weight'=>$orderPackingSummary->grossweight,
  332. 'length'=>$orderPackingSummary->length,
  333. 'width'=>$orderPackingSummary->width,
  334. 'height'=>$orderPackingSummary->height,
  335. 'weighed_at'=>$orderPackingSummary->edittime
  336. ]);
  337. dispatch(new WeightUpdateInstantBill($orderPackage));
  338. }
  339. }
  340. return ['success' => true];
  341. }
  342. public function collectUpload()
  343. {
  344. /** @var OrderPackageService $service */
  345. $service = app('OrderPackageService');
  346. return $service->collectUpload([
  347. '75601803541125'
  348. ]);
  349. }
  350. public function init_在途异常()
  351. {
  352. $logistic_numbers = OrderPackage::query()
  353. ->select('logistic_number')
  354. ->where('exception_status', 5)
  355. ->where('created_at', '>=', now()->subDays(20)->toDateTimeString())
  356. ->pluck('logistic_number');
  357. /** @var OrderPackageReceivedSyncService $service */
  358. $service = app('OrderPackageReceivedSyncService');
  359. $service->syncLogisticRoute(false, $logistic_numbers);
  360. // $logistic_numbers = OrderPackage::query()
  361. // ->select(['logistic_number', 'order_id', 'id'])
  362. // ->whereIn('order_id', function ($query) {
  363. // $query->from('orders')->selectRaw('id')->whereIn('logistic_id', function ($builder) {
  364. // $builder->from('logistics')->selectRaw('id')->where('type', '=', '快递')->whereNotIn('belong_company', ['顺丰', '中通', '韵达', '圆通', '京东']);
  365. // });
  366. // })
  367. // ->where('exception_status', 5)
  368. // ->where('created_at', '>=', now()->subDays(20)->toDateTimeString())
  369. // ->pluck('logistic_number');
  370. // $service->syncLogisticRouteByAliJiSu($logistic_numbers);
  371. }
  372. public function store()
  373. {
  374. ini_set('max_execution_time', 0);
  375. ini_set('memory_limit', '1024M');
  376. // $now = Carbon::now();
  377. // $startDate = $this->getDate();
  378. $startDate = '2021-09-25 13:23:14';
  379. $diffDay = 1; // 天数
  380. for($i = 0;$i<=$diffDay;$i++){
  381. $endDate = Carbon::parse($startDate)->addDays(1)->toDateTimeString();
  382. $doc_asn_headers = $this->getDocAsnHeader($startDate,$endDate);
  383. // if (count($doc_asn_headers)>0){
  384. // $this->syncStores($doc_asn_headers);
  385. // $this->syncDate($endDate);
  386. // }
  387. dump($startDate,$endDate);
  388. $startDate = $endDate;
  389. }
  390. $this->clearCache();
  391. // ValueStore::query()->updateOrCreate([
  392. // 'name' => 'last_asn_sync_task_end_at',
  393. // ], [
  394. // 'name' => 'last_asn_sync_task_end_at',
  395. // 'value' => $now,
  396. // ]);
  397. }
  398. public function getDocAsnHeader($startDate,$endDate)
  399. {
  400. return OracleDOCASNHeader::query()
  401. ->with(['asnType', 'asnStatus'])
  402. ->select('asnno','asnstatus','asntype','addtime','edittime','customerid','notes','warehouseid','asnreference3','asnreference2')
  403. ->where('EditTime', '>=', $startDate)
  404. ->where('EditTime', '<=', $endDate)
  405. ->whereColumn('EditTime', '<>', 'addTime')
  406. ->orderByDesc('EditTime')
  407. ->get();
  408. }
  409. public function getDate(){
  410. return ValueStore::query()->where('name','asn_last_updated_sync_at')->value('value');
  411. }
  412. public function syncStores($doc_asn_headers){
  413. $service = new StoreService();
  414. $service->createStore($doc_asn_headers,"update");
  415. $service->updateStore($doc_asn_headers);
  416. $service->createStoreRejected($doc_asn_headers);
  417. unset($doc_asn_headers);
  418. }
  419. public function syncDate($date)
  420. {
  421. // 同步更新时间
  422. ValueStore::query()->updateOrCreate([
  423. 'name' => 'asn_last_updated_sync_at',
  424. ], [
  425. 'name' => 'asn_last_updated_sync_at',
  426. 'value' => $date,
  427. ]);
  428. }
  429. public function clearCache()
  430. {
  431. $service = new StoreService();
  432. $update_set = config('sync.asn_sync.cache_prefix.update_set');
  433. $update_keys = config('sync.asn_sync.cache_prefix.update_keys');
  434. $service->deleteCacheKey($update_set, $update_keys);
  435. // 清空保存 ans 号的栈
  436. // 清除 更新时间 开始 结束
  437. }
  438. public function updateStoreItem()
  439. {
  440. ini_set('max_execution_time', 0);
  441. ini_set('memory_limit', '1024M');
  442. $storeIds = Store::query()
  443. ->where('updated_at', '>=', '2021-09-25 13:21:26')
  444. ->whereColumn('updated_at', '<>', 'created_at')
  445. ->pluck('id');
  446. $storeItemMaxIds = StoreItem::query()
  447. ->selectRaw('max(id) as max_id')
  448. ->whereIn('store_id', $storeIds)
  449. ->groupBy(['store_id', 'asn_line_code'])
  450. ->get();
  451. // dd($storeItemMaxIds->count());
  452. $storeItems = StoreItem::query()
  453. ->whereIn('store_id', $storeIds)
  454. ->whereNotIn('id', $storeItemMaxIds)
  455. ->delete();
  456. }
  457. public function init_SettlementBillReportTask()
  458. {
  459. $this->dispatch(new SettlementBillReportJob('2021-09-01',[]));
  460. }
  461. public function test2(){
  462. $source_file ="E:\OneDrive\桌面\工作目录\文件库\\5.jpg";
  463. $img = ImageCreateFromJpeg($source_file);
  464. imagecolortransparent($img);//将某个颜色设置成透明色
  465. imagecolorstotal($img);
  466. header('Content-type:image/jpeg');
  467. imagejpeg($img);
  468. //dd($this->run('E:\OneDrive\桌面\工作目录\文件库\5.jpg', 'E:\OneDrive\桌面\工作目录\文件库\6.jpg'));
  469. }
  470. const FILE_NOT_FOUND = '-1';
  471. const FILE_EXTNAME_ILLEGAL = '-2';
  472. public function run($src1, $src2) {
  473. if(!is_file($src1) || !is_file($src2)) exit(self::FILE_NOT_FOUND);
  474. $hash1 = $this->getHashValue($src1);
  475. $hash2 = $this->getHashValue($src2);
  476. if(strlen($hash1) !== strlen($hash2)) return false;
  477. $count = 0;
  478. $len = strlen($hash1);
  479. for($i = 0; $i < $len; $i++) if($hash1[$i] !== $hash2[$i]){
  480. $count++;
  481. }
  482. dd($count);
  483. return $count <= 10 ? true : false;
  484. }
  485. public function getImage($file) {
  486. $extname = pathinfo($file, PATHINFO_EXTENSION);
  487. if(!in_array($extname, ['jpg','jpeg','png','gif'])) exit(self::FILE_EXTNAME_ILLEGAL);
  488. $img = call_user_func('imagecreatefrom'. ( $extname == 'jpg' ? 'jpeg' : $extname ) , $file);
  489. return $img;
  490. }
  491. public function getHashValue($file) {
  492. $w = 32;
  493. $h = 32;
  494. $img = imagecreatetruecolor($w, $h);
  495. list($src_w, $src_h) = getimagesize($file);
  496. $src = $this->getImage($file);
  497. imagecopyresampled($img, $src, 0, 0, 0, 0, $w, $h, $src_w, $src_h);
  498. imagedestroy($src);
  499. $total = 0;
  500. $array = array();
  501. for( $y = 0; $y < $h; $y++) {
  502. for ($x = 0; $x < $w; $x++) {
  503. $rgb = imagecolorat($img, $x, $y);
  504. $gray = $rgb & 0xFF;
  505. /*dump([
  506. ($rgb >> 8) & 0xFF,
  507. ($rgb >> 16) & 0xFF,
  508. $rgb & 0xFF,
  509. ]);*/
  510. if(!isset($array[$y])) $array[$y] = array();
  511. $array[$y][$x] = $gray;
  512. $total += $gray;
  513. }
  514. }
  515. imagedestroy($img);
  516. $average = intval($total / ($w * $h * 2));
  517. $hash = '';
  518. for($y = 0; $y < $h; $y++) {
  519. for($x = 0; $x < $w; $x++) {
  520. $hash .= ($array[$y][$x] >= $average) ? '1' : '0';
  521. }
  522. }
  523. dump($hash);
  524. return $hash;
  525. }
  526. public function sortTransferStatus()
  527. {
  528. $orderPackage = OrderPackage::query()->where('logistic_number','75601831068018')->first();
  529. app('OrderPackageService')->sortOrderPackageTransferStatus($orderPackage);
  530. dd($orderPackage);
  531. }
  532. public function clear_work_space()
  533. {
  534. \App\LaborApply::query()->truncate();
  535. LaborCompanyDispatch::query()->truncate();
  536. \App\LaborCompanyDispatchDetail::query()->truncate();
  537. }
  538. public function calculationArrivedManNum()
  539. {
  540. $this->dispatch(new CalculationArrivedManNumJob(\Illuminate\Support\Carbon::parse(now()->toDateString())));
  541. }
  542. }