TestController.php 20 KB

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