TestController.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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\ErrorPush;
  9. use App\ErrorTemp;
  10. use App\Feature;
  11. use App\Http\ApiControllers\LoginController;
  12. use App\Http\Requests\OrderDelivering;
  13. use App\Jobs\BatchTaskJob;
  14. use App\Jobs\CacheShelfTaskJob;
  15. use App\Jobs\OrderCreateInstantBill;
  16. use App\Jobs\OrderCreateWaybill;
  17. use App\Jobs\SettlementBillReportTask;
  18. use App\Jobs\StoreCreateInstantBill;
  19. use App\Jobs\TestJob;
  20. use App\Jobs\WeightUpdateInstantBill;
  21. use App\LaborReport;
  22. use App\LaborReportStatus;
  23. use App\MaterialBox;
  24. use App\MaterialBoxModel;
  25. use App\Notifications\RoutineNotification;
  26. use App\OracleDOCASNHeader;
  27. use App\OracleDOCOrderHeader;
  28. use App\OracleDocOrderPackingSummary;
  29. use App\Order;
  30. use App\OrderIssue;
  31. use App\OrderIssueProcessLog;
  32. use App\OrderPackage;
  33. use App\Owner;
  34. use App\OwnerAreaReport;
  35. use App\OwnerFeeDetail;
  36. use App\OwnerFeeDetailLogistic;
  37. use App\OwnerFeeExpress;
  38. use App\OwnerFeeLogistic;
  39. use App\OwnerFeeOperation;
  40. use App\OwnerFeeOperationDetail;
  41. use App\OwnerFeeStorage;
  42. use App\OwnerPriceOperation;
  43. use App\OrderPackageCountingRecord;
  44. use App\ProcurementCheckSheet;
  45. use App\RejectedBill;
  46. use App\SeeLog;
  47. use App\Services\BatchService;
  48. use App\Services\CacheShelfService;
  49. use App\Services\ForeignHaiRoboticsService;
  50. use App\Services\NotificationService;
  51. use App\Services\OrderPackageReceivedSyncService;
  52. use App\Services\OrderPackageService;
  53. use App\Services\OrderService;
  54. use App\Services\OwnerFeeTotalService;
  55. use App\Services\OwnerLogisticFeeReportService;
  56. use App\Services\OwnerPriceOperationService;
  57. use App\Services\OwnerStoreFeeReportService;
  58. use App\Services\OwnerStoreOutFeeReportService;
  59. use App\Services\ReviewService;
  60. use App\Services\StationService;
  61. use App\Services\StorageService;
  62. use App\Services\StoreService;
  63. use App\Station;
  64. use App\StationTask;
  65. use App\StationTaskMaterialBox;
  66. use App\Store;
  67. use App\TaskTransaction;
  68. use App\Unit;
  69. use App\User;
  70. use App\UserDetail;
  71. use App\UserDutyCheck;
  72. use App\ValueStore;
  73. use App\Waybill;
  74. use App\WorkOrder;
  75. use Carbon\Carbon;
  76. use Carbon\CarbonPeriod;
  77. use Decimal\Decimal;
  78. use Doctrine\DBAL\Exception;
  79. use Firebase\JWT\JWT;
  80. use Illuminate\Database\Eloquent\Collection;
  81. use Illuminate\Database\Eloquent\HigherOrderBuilderProxy;
  82. use Illuminate\Foundation\Http\FormRequest;
  83. use Illuminate\Http\Request;
  84. use Illuminate\Support\Facades\Broadcast;
  85. use Illuminate\Support\Facades\Cache;
  86. use Illuminate\Support\Facades\Auth;
  87. use Illuminate\Support\Facades\Cookie;
  88. use Illuminate\Support\Facades\DB;
  89. use Illuminate\Support\Facades\Http;
  90. use Illuminate\Support\Facades\Log;
  91. use Illuminate\Support\Facades\Notification;
  92. use Illuminate\Support\Facades\URL;
  93. use Illuminate\Support\Facades\Validator;
  94. use Illuminate\Support\Str;
  95. use Laravel\Horizon\Events\JobFailed;
  96. use Monolog\Handler\IFTTTHandler;
  97. use phpDocumentor\Reflection\Types\Resource_;
  98. use PhpOffice\PhpSpreadsheet\Calculation\Web\Service;
  99. use Symfony\Component\ErrorHandler\Error\FatalError;
  100. class TestController extends Controller
  101. {
  102. use AsyncResponse, ErrorPush;
  103. const ASNREFERENCE_2 = 'ASNREFERENCE2';
  104. public function __construct()
  105. {
  106. $this->data["active_test"] = "active";
  107. }
  108. public function method(Request $request, $method)
  109. {
  110. try {
  111. return call_user_func([$this, $method], $request);
  112. }catch (\BadMethodCallException $e){
  113. dd("方法不存在");
  114. }
  115. }
  116. public function test1()
  117. {
  118. try {
  119. $b = DB::connection("oracle")->select("SELECT * FROM DOC_ORDER_HEADER");
  120. dump(count($b));
  121. }catch (\Exception $e){
  122. dd($e);
  123. }catch (\Error $e1){
  124. dd($e1);
  125. }
  126. dd(round(memory_get_peak_usage() / 1024 / 1024, 2));
  127. }
  128. public function test()
  129. {
  130. $b = [];
  131. for ($i=0;$i<100000;$i++){
  132. $b[] = $i;
  133. }
  134. dd(round(memory_get_peak_usage() / 1024 / 1024, 2));
  135. $area = OwnerAreaReport::query()->find(398);
  136. if (!$area->ownerStoragePriceModel)dd("error");
  137. //信息提取模板
  138. $GLOBALS["FEE_INFO"] = [
  139. "area_id" =>$area->id,
  140. "counting_type" =>$area->ownerStoragePriceModel->counting_type,
  141. "using_type" =>$area->ownerStoragePriceModel->using_type,
  142. "fee_description" =>"",
  143. "total_fee" =>0,
  144. "tax_rate" =>0,
  145. ];
  146. list($money,$taxFee) = app('OwnerStoragePriceModelService')
  147. ->calculationAmount($area->ownerStoragePriceModel,$area->accounting_area,$area->owner_id,$area->counting_month);
  148. dd($money,$taxFee);
  149. dd(Notification::send(User::query()->where("name","zhouzhendong")->get(),new RoutineNotification(SeeLog::query()->first()->toArray())));
  150. $user = Auth::user();
  151. $remark = "zengjunlj";
  152. $ownerName = 'zengjunlj' ?? '';
  153. $clientCode = 'zengjunljljlj' ?? '';
  154. $msg = $user["name"]."建立了新工单<br/>".$ownerName.":".$clientCode."<br/>".$remark;
  155. NotificationService::SingleRegister($msg,$clientCode,"订单管理-问题件");
  156. dd(1);
  157. $seeLog = SeeLog::query()->find(9);
  158. Notification::send(Auth::user(),new RoutineNotification($seeLog->toArray()));
  159. dd(1);
  160. Broadcast::channel('notification', function ($user, $id) {
  161. return (int) $user->id === (int) $id;
  162. });
  163. dd(1);
  164. Notification::send(Auth::user(),new RoutineNotification($seeLog->toArray()));
  165. dd(1);
  166. $username = config('database.connections.oracle.username');
  167. $password = config('database.connections.oracle.password');
  168. $host = config('database.connections.oracle.host');
  169. $service_name = config('database.connections.oracle.service_name');
  170. $conn = oci_connect($username, $password, $host . '/' . $service_name,"utf8");
  171. $sql = <<<sql
  172. BEGIN
  173. SPSO_HardAllocation_Process('WH01','Allocation','By OrderNO',
  174. null,'SO21090100007','0',null,
  175. 'zhouzhendong',:CODE);
  176. END;
  177. sql;
  178. $stmt = oci_parse($conn, $sql);
  179. $code = "";
  180. oci_bind_by_name($stmt, ':CODE', $code,300);
  181. oci_execute($stmt);
  182. oci_close($conn);
  183. dd($code);
  184. //
  185. $no = "SO21090900001";
  186. $db = DB::connection("oracle");
  187. //$order = $db->selectOne(DB::raw("select * from DOC_ORDER_HEADER where orderno = ?"),[$no]);
  188. dd($db->select($sql,[
  189. ]));
  190. $db->select("CALL SPSO_HardAllocation_Process(?,'Allocation','By OrderNO',null,?,'0',null,'zhouzhendong',@code)",[
  191. $order->warehouseid,$no
  192. ]);
  193. //SPSO_HardAllocation_Process
  194. dd($db->selectOne("select @code"));
  195. $date = "2021-09-14 15:47:00";
  196. dispatch(new TestJob("1"))->delay(Carbon::parse($date));
  197. dispatch(new TestJob("2"))->delay(Carbon::parse($date));
  198. dispatch(new TestJob("3"))->delay(Carbon::parse($date));
  199. dispatch(new TestJob("4"))->delay(Carbon::parse($date));
  200. dispatch(new TestJob("5"))->delay(Carbon::parse($date));
  201. dispatch(new TestJob("6"))->delay(Carbon::parse($date));
  202. dispatch(new TestJob("7"))->delay(Carbon::parse($date));
  203. dispatch(new TestJob("8"))->delay(Carbon::parse($date));
  204. dispatch(new TestJob("9"))->delay(Carbon::parse($date));
  205. dispatch(new TestJob("10"))->delay(Carbon::parse($date));
  206. dd(1);
  207. Station::query()->where("station_type_id", 5)->update(["status" => 1]);
  208. Cache::forget("CACHE_SHELF_AVAILABLE");
  209. $station = ["HAIB1-01-01", "HAIB1-02-01"];
  210. $material = ["IDE0001824", "IDE0001740", "IDE0002710"];
  211. Station::query()->whereIn("code", $station)->update(["status" => 0]);
  212. $stations = Station::query()->whereIn("code", $station)->get();
  213. $materials = MaterialBox::query()->whereIn("code", $material)->get();
  214. $dateTime = date("Y-m-d H:i:s");
  215. $task1 = StationTaskMaterialBox::query()->create([
  216. 'station_id' => $stations[0]->id,
  217. 'material_box_id' => $materials[0]->id,
  218. 'station_task_batch_id' => 1,
  219. 'status' => '待处理'
  220. ]);
  221. $task2 = StationTaskMaterialBox::query()->create([
  222. 'station_id' => $stations[1]->id,
  223. 'material_box_id' => $materials[1]->id,
  224. 'station_task_batch_id' => 1,
  225. 'status' => '待处理'
  226. ]);
  227. $task3 = StationTaskMaterialBox::query()->create([
  228. 'station_id' => 6,
  229. 'material_box_id' => $materials[2]->id,
  230. 'station_task_batch_id' => 1,
  231. 'status' => '待处理'
  232. ]);
  233. TaskTransaction::query()->insert([[
  234. "doc_code" => "test",
  235. "bar_code" => "test",
  236. "to_station_id" => $stations[0]->id,
  237. "material_box_id" => $materials[0]->id,
  238. "task_id" => $task1->id,
  239. "commodity_id" => 505012,//XUNI03
  240. "amount" => 1,
  241. "type" => "出库",
  242. "status" => 0,
  243. "mark" => 2,
  244. "bin_number" => 1,
  245. "created_at" => $dateTime,
  246. "updated_at" => $dateTime,
  247. ], [
  248. "doc_code" => "test",
  249. "bar_code" => "test",
  250. "to_station_id" => $stations[1]->id,
  251. "material_box_id" => $materials[1]->id,
  252. "task_id" => $task2->id,
  253. "commodity_id" => 505012,//XUNI03
  254. "amount" => 1,
  255. "type" => "出库",
  256. "status" => 0,
  257. "mark" => 2,
  258. "bin_number" => 1,
  259. "created_at" => $dateTime,
  260. "updated_at" => $dateTime,
  261. ], [
  262. "doc_code" => "test",
  263. "bar_code" => "test",
  264. "to_station_id" => 6,
  265. "material_box_id" => $materials[2]->id,
  266. "task_id" => $task3->id,
  267. "commodity_id" => 505012,//XUNI03
  268. "amount" => 1,
  269. "type" => "出库",
  270. "status" => 3,
  271. "mark" => 2,
  272. "bin_number" => 1,
  273. "created_at" => $dateTime,
  274. "updated_at" => $dateTime,
  275. ]]);
  276. $foreignHaiRoboticsService = new ForeignHaiRoboticsService();
  277. $toLocation = collect($station);
  278. $taskMaterialBoxes = collect([$task1, $task2]);
  279. $foreignHaiRoboticsService->
  280. fetchGroup_multiLocation($toLocation, $taskMaterialBoxes, '', '立架出至缓存架', 20, false);
  281. foreach ($toLocation as $index => $value) {
  282. app("CacheShelfService")->lightUp($value, '3', '0', ["title" => "机器人取箱中,禁止操作"]);
  283. Cache::forever("CACHE_SHELF_OCCUPANCY_{$stations[$index]->id}", true);
  284. }
  285. app("StationService")->locationOccupyMulti($toLocation->toArray());
  286. }
  287. public function update_order_packages_is_manual_update()
  288. {
  289. $descriptions = Log::query()
  290. ->select('description')
  291. ->whereBetween('created_at', ['2021-08-31 10:30:00', '2021-08-31 10:35:00'])
  292. ->where('class', 'like', 'https://was.baoshi56.com/package/logistic/batchUpdate%')->pluck('description');
  293. foreach ($descriptions as $description) {
  294. $description = substr($description, 9);
  295. $description = \Illuminate\Support\Str::before($description, "}");
  296. $obj = json_decode($description . '}', true);
  297. OrderPackage::query()
  298. ->whereIn('logistic_number', $obj['logistic_numbers'])
  299. ->update([
  300. 'status' => '无',
  301. 'is_manual_update' => false,
  302. ]);
  303. }
  304. }
  305. public function testUpdateInv()
  306. {
  307. ini_set('max_execution_time', 0);
  308. ini_set('memory_limit', '4096M');
  309. $sql = <<<sql
  310. select FMLOTNUM,FMLOCATION,PLANTOLOCATION,CREATE_TRANSACTIONID,SKU,CUSTOMERID from TSK_TASKLISTS
  311. where CUSTOMERID=?
  312. AND FMLOCATION= ?
  313. AND OPENWHO = ?
  314. AND TASKPROCESS = ?
  315. AND DOCTYPE = ?
  316. AND TASKTYPE = ?
  317. AND LOTATT05=?
  318. AND LOTATT08=?
  319. AND PLANTOID = ?
  320. and OPENTIME>=TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')
  321. and OPENTIME<=TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')
  322. sql;
  323. $CUSTOMERID = 'JIANSHANG';
  324. $FMLOCATION = 'STAGEWH02';
  325. $OPENWHO = 'WCS';
  326. $TASKPROCESS = '00';
  327. $DOCTYPE = 'ASN';
  328. $TASKTYPE = 'PA';
  329. $LOTATT05 = 'MJ-CP';
  330. $LOTATT08 = 'ZP';
  331. $PLANTOID = '*';
  332. $traceid = 'JIANSHANG03';
  333. $start = '2021-09-02 23:59:59';
  334. $end = '2021-09-03 11:10:00';
  335. $res = DB::connection("oracle")->select(DB::raw($sql),
  336. [$CUSTOMERID, $FMLOCATION, $OPENWHO, $TASKPROCESS, $DOCTYPE, $TASKTYPE, $LOTATT05, $LOTATT08, $PLANTOID, $start, $end]);
  337. $resItems = array_chunk($res, 200);
  338. foreach ($resItems as $res) {
  339. DB::connection("oracle")->beginTransaction();
  340. try {
  341. foreach ($res as $re) {
  342. DB::connection("oracle")->table('INV_LOT_LOC_ID')
  343. ->where([
  344. 'LOTNUM' => $re->fmlotnum,
  345. 'LOCATIONID' => $re->fmlocation,
  346. 'CUSTOMERID' => $re->customerid,
  347. 'sku' => $re->sku,
  348. 'TRACEID' => '*',
  349. ])
  350. ->update([
  351. 'TRACEID' => $traceid,
  352. 'EDITWHO' => 'WCS_',
  353. ]);
  354. if ($re->fmlocation != $re->plantolocation) {
  355. DB::connection("oracle")->table('INV_LOT_LOC_ID')
  356. ->where([
  357. 'LOTNUM' => $re->fmlotnum,
  358. 'LOCATIONID' => $re->plantolocation,
  359. 'CUSTOMERID' => $re->customerid,
  360. 'sku' => $re->sku,
  361. 'TRACEID' => '*',
  362. ])
  363. ->update([
  364. 'TRACEID' => $traceid,
  365. 'EDITWHO' => 'WCS_',
  366. ]);
  367. }
  368. DB::connection("oracle")->commit();
  369. }
  370. dd(true);
  371. } catch (\Exception $e) {
  372. DB::connection("oracle")->rollBack();
  373. dd($e->getMessage());
  374. }
  375. }
  376. }
  377. /**
  378. * 重置15天内的数据
  379. */
  380. public function order_packages_init()
  381. {
  382. OrderPackage::query()
  383. ->whereBetween('created_at', [now()->subDays(15), now()])
  384. ->update([
  385. 'is_delay_deliver' => 0,
  386. 'sync_routes_flag' => 0,
  387. 'status' => 1,
  388. 'exception_status' => 0,
  389. ]);
  390. OrderPackage::query()
  391. ->whereBetween('created_at', [now()->subDays(15), now()])
  392. ->whereNotNull('received_at')
  393. ->update([
  394. 'status' => 7,
  395. ]);
  396. }
  397. public function syncOrderPackage(){
  398. ini_set('memory_limit','500M');
  399. ini_set('max_execution_time', 0);
  400. $orderPackingSummary = OracleDocOrderPackingSummary::query()
  401. ->where('editTime','>=','2021-09-11 12:00:00')
  402. ->where('editTime','<=','2021-09-12 12:40:00')
  403. ->get();
  404. $orderPackingSummary_chunk = $orderPackingSummary->chunk(200);
  405. foreach ($orderPackingSummary_chunk as $orderPackingSummarys) {
  406. foreach ($orderPackingSummarys as $orderPackingSummary) {
  407. $orderPackage = OrderPackage::query()->where('logistic_number',$orderPackingSummary->traceid)->first();
  408. $orderPackage->update([
  409. 'uploaded_to_wms'=> true,
  410. 'weight'=>$orderPackingSummary->grossweight,
  411. 'length'=>$orderPackingSummary->length,
  412. 'width'=>$orderPackingSummary->width,
  413. 'height'=>$orderPackingSummary->height,
  414. 'weighed_at'=>$orderPackingSummary->edittime
  415. ]);
  416. dispatch(new WeightUpdateInstantBill($orderPackage));
  417. }
  418. }
  419. return ['success' => true];
  420. }
  421. public function collectUpload()
  422. {
  423. /** @var OrderPackageService $service */
  424. $service = app('OrderPackageService');
  425. return $service->collectUpload([
  426. '75803656098638',
  427. '75803656098612'
  428. ]);
  429. }
  430. public function teset12313(){
  431. dd(route("discharge.storeApi"));
  432. }
  433. }