TestController.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. class TestController extends Controller
  100. {
  101. use AsyncResponse, ErrorPush;
  102. const ASNREFERENCE_2 = 'ASNREFERENCE2';
  103. public function __construct()
  104. {
  105. $this->data["active_test"] = "active";
  106. }
  107. public function method(Request $request, $method)
  108. {
  109. return call_user_func([$this, $method], $request);
  110. }
  111. public function test()
  112. {
  113. $area = OwnerAreaReport::query()->find(398);
  114. if (!$area->ownerStoragePriceModel)dd("error");
  115. //信息提取模板
  116. $GLOBALS["FEE_INFO"] = [
  117. "area_id" =>$area->id,
  118. "counting_type" =>$area->ownerStoragePriceModel->counting_type,
  119. "using_type" =>$area->ownerStoragePriceModel->using_type,
  120. "fee_description" =>"",
  121. "total_fee" =>0,
  122. "tax_rate" =>0,
  123. ];
  124. list($money,$taxFee) = app('OwnerStoragePriceModelService')
  125. ->calculationAmount($area->ownerStoragePriceModel,$area->accounting_area,$area->owner_id,$area->counting_month);
  126. dd($money,$taxFee);
  127. dd(Notification::send(User::query()->where("name","zhouzhendong")->get(),new RoutineNotification(SeeLog::query()->first()->toArray())));
  128. $user = Auth::user();
  129. $remark = "zengjunlj";
  130. $ownerName = 'zengjunlj' ?? '';
  131. $clientCode = 'zengjunljljlj' ?? '';
  132. $msg = $user["name"]."建立了新工单<br/>".$ownerName.":".$clientCode."<br/>".$remark;
  133. NotificationService::SingleRegister($msg,$clientCode,"订单管理-问题件");
  134. dd(1);
  135. $seeLog = SeeLog::query()->find(9);
  136. Notification::send(Auth::user(),new RoutineNotification($seeLog->toArray()));
  137. dd(1);
  138. Broadcast::channel('notification', function ($user, $id) {
  139. return (int) $user->id === (int) $id;
  140. });
  141. dd(1);
  142. Notification::send(Auth::user(),new RoutineNotification($seeLog->toArray()));
  143. dd(1);
  144. $username = config('database.connections.oracle.username');
  145. $password = config('database.connections.oracle.password');
  146. $host = config('database.connections.oracle.host');
  147. $service_name = config('database.connections.oracle.service_name');
  148. $conn = oci_connect($username, $password, $host . '/' . $service_name,"utf8");
  149. $sql = <<<sql
  150. BEGIN
  151. SPSO_HardAllocation_Process('WH01','Allocation','By OrderNO',
  152. null,'SO21090100007','0',null,
  153. 'zhouzhendong',:CODE);
  154. END;
  155. sql;
  156. $stmt = oci_parse($conn, $sql);
  157. $code = "";
  158. oci_bind_by_name($stmt, ':CODE', $code,300);
  159. oci_execute($stmt);
  160. oci_close($conn);
  161. dd($code);
  162. //
  163. $no = "SO21090900001";
  164. $db = DB::connection("oracle");
  165. //$order = $db->selectOne(DB::raw("select * from DOC_ORDER_HEADER where orderno = ?"),[$no]);
  166. dd($db->select($sql,[
  167. ]));
  168. $db->select("CALL SPSO_HardAllocation_Process(?,'Allocation','By OrderNO',null,?,'0',null,'zhouzhendong',@code)",[
  169. $order->warehouseid,$no
  170. ]);
  171. //SPSO_HardAllocation_Process
  172. dd($db->selectOne("select @code"));
  173. $date = "2021-09-14 15:47:00";
  174. dispatch(new TestJob("1"))->delay(Carbon::parse($date));
  175. dispatch(new TestJob("2"))->delay(Carbon::parse($date));
  176. dispatch(new TestJob("3"))->delay(Carbon::parse($date));
  177. dispatch(new TestJob("4"))->delay(Carbon::parse($date));
  178. dispatch(new TestJob("5"))->delay(Carbon::parse($date));
  179. dispatch(new TestJob("6"))->delay(Carbon::parse($date));
  180. dispatch(new TestJob("7"))->delay(Carbon::parse($date));
  181. dispatch(new TestJob("8"))->delay(Carbon::parse($date));
  182. dispatch(new TestJob("9"))->delay(Carbon::parse($date));
  183. dispatch(new TestJob("10"))->delay(Carbon::parse($date));
  184. dd(1);
  185. Station::query()->where("station_type_id", 5)->update(["status" => 1]);
  186. Cache::forget("CACHE_SHELF_AVAILABLE");
  187. $station = ["HAIB1-01-01", "HAIB1-02-01"];
  188. $material = ["IDE0001824", "IDE0001740", "IDE0002710"];
  189. Station::query()->whereIn("code", $station)->update(["status" => 0]);
  190. $stations = Station::query()->whereIn("code", $station)->get();
  191. $materials = MaterialBox::query()->whereIn("code", $material)->get();
  192. $dateTime = date("Y-m-d H:i:s");
  193. $task1 = StationTaskMaterialBox::query()->create([
  194. 'station_id' => $stations[0]->id,
  195. 'material_box_id' => $materials[0]->id,
  196. 'station_task_batch_id' => 1,
  197. 'status' => '待处理'
  198. ]);
  199. $task2 = StationTaskMaterialBox::query()->create([
  200. 'station_id' => $stations[1]->id,
  201. 'material_box_id' => $materials[1]->id,
  202. 'station_task_batch_id' => 1,
  203. 'status' => '待处理'
  204. ]);
  205. $task3 = StationTaskMaterialBox::query()->create([
  206. 'station_id' => 6,
  207. 'material_box_id' => $materials[2]->id,
  208. 'station_task_batch_id' => 1,
  209. 'status' => '待处理'
  210. ]);
  211. TaskTransaction::query()->insert([[
  212. "doc_code" => "test",
  213. "bar_code" => "test",
  214. "to_station_id" => $stations[0]->id,
  215. "material_box_id" => $materials[0]->id,
  216. "task_id" => $task1->id,
  217. "commodity_id" => 505012,//XUNI03
  218. "amount" => 1,
  219. "type" => "出库",
  220. "status" => 0,
  221. "mark" => 2,
  222. "bin_number" => 1,
  223. "created_at" => $dateTime,
  224. "updated_at" => $dateTime,
  225. ], [
  226. "doc_code" => "test",
  227. "bar_code" => "test",
  228. "to_station_id" => $stations[1]->id,
  229. "material_box_id" => $materials[1]->id,
  230. "task_id" => $task2->id,
  231. "commodity_id" => 505012,//XUNI03
  232. "amount" => 1,
  233. "type" => "出库",
  234. "status" => 0,
  235. "mark" => 2,
  236. "bin_number" => 1,
  237. "created_at" => $dateTime,
  238. "updated_at" => $dateTime,
  239. ], [
  240. "doc_code" => "test",
  241. "bar_code" => "test",
  242. "to_station_id" => 6,
  243. "material_box_id" => $materials[2]->id,
  244. "task_id" => $task3->id,
  245. "commodity_id" => 505012,//XUNI03
  246. "amount" => 1,
  247. "type" => "出库",
  248. "status" => 3,
  249. "mark" => 2,
  250. "bin_number" => 1,
  251. "created_at" => $dateTime,
  252. "updated_at" => $dateTime,
  253. ]]);
  254. $foreignHaiRoboticsService = new ForeignHaiRoboticsService();
  255. $toLocation = collect($station);
  256. $taskMaterialBoxes = collect([$task1, $task2]);
  257. $foreignHaiRoboticsService->
  258. fetchGroup_multiLocation($toLocation, $taskMaterialBoxes, '', '立架出至缓存架', 20, false);
  259. foreach ($toLocation as $index => $value) {
  260. app("CacheShelfService")->lightUp($value, '3', '0', ["title" => "机器人取箱中,禁止操作"]);
  261. Cache::forever("CACHE_SHELF_OCCUPANCY_{$stations[$index]->id}", true);
  262. }
  263. app("StationService")->locationOccupyMulti($toLocation->toArray());
  264. }
  265. public function update_order_packages_is_manual_update()
  266. {
  267. $descriptions = Log::query()
  268. ->select('description')
  269. ->whereBetween('created_at', ['2021-08-31 10:30:00', '2021-08-31 10:35:00'])
  270. ->where('class', 'like', 'https://was.baoshi56.com/package/logistic/batchUpdate%')->pluck('description');
  271. foreach ($descriptions as $description) {
  272. $description = substr($description, 9);
  273. $description = \Illuminate\Support\Str::before($description, "}");
  274. $obj = json_decode($description . '}', true);
  275. OrderPackage::query()
  276. ->whereIn('logistic_number', $obj['logistic_numbers'])
  277. ->update([
  278. 'status' => '无',
  279. 'is_manual_update' => false,
  280. ]);
  281. }
  282. }
  283. public function testUpdateInv()
  284. {
  285. ini_set('max_execution_time', 0);
  286. ini_set('memory_limit', '4096M');
  287. $sql = <<<sql
  288. select FMLOTNUM,FMLOCATION,PLANTOLOCATION,CREATE_TRANSACTIONID,SKU,CUSTOMERID from TSK_TASKLISTS
  289. where CUSTOMERID=?
  290. AND FMLOCATION= ?
  291. AND OPENWHO = ?
  292. AND TASKPROCESS = ?
  293. AND DOCTYPE = ?
  294. AND TASKTYPE = ?
  295. AND LOTATT05=?
  296. AND LOTATT08=?
  297. AND PLANTOID = ?
  298. and OPENTIME>=TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')
  299. and OPENTIME<=TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')
  300. sql;
  301. $CUSTOMERID = 'JIANSHANG';
  302. $FMLOCATION = 'STAGEWH02';
  303. $OPENWHO = 'WCS';
  304. $TASKPROCESS = '00';
  305. $DOCTYPE = 'ASN';
  306. $TASKTYPE = 'PA';
  307. $LOTATT05 = 'MJ-CP';
  308. $LOTATT08 = 'ZP';
  309. $PLANTOID = '*';
  310. $traceid = 'JIANSHANG03';
  311. $start = '2021-09-02 23:59:59';
  312. $end = '2021-09-03 11:10:00';
  313. $res = DB::connection("oracle")->select(DB::raw($sql),
  314. [$CUSTOMERID, $FMLOCATION, $OPENWHO, $TASKPROCESS, $DOCTYPE, $TASKTYPE, $LOTATT05, $LOTATT08, $PLANTOID, $start, $end]);
  315. $resItems = array_chunk($res, 200);
  316. foreach ($resItems as $res) {
  317. DB::connection("oracle")->beginTransaction();
  318. try {
  319. foreach ($res as $re) {
  320. DB::connection("oracle")->table('INV_LOT_LOC_ID')
  321. ->where([
  322. 'LOTNUM' => $re->fmlotnum,
  323. 'LOCATIONID' => $re->fmlocation,
  324. 'CUSTOMERID' => $re->customerid,
  325. 'sku' => $re->sku,
  326. 'TRACEID' => '*',
  327. ])
  328. ->update([
  329. 'TRACEID' => $traceid,
  330. 'EDITWHO' => 'WCS_',
  331. ]);
  332. if ($re->fmlocation != $re->plantolocation) {
  333. DB::connection("oracle")->table('INV_LOT_LOC_ID')
  334. ->where([
  335. 'LOTNUM' => $re->fmlotnum,
  336. 'LOCATIONID' => $re->plantolocation,
  337. 'CUSTOMERID' => $re->customerid,
  338. 'sku' => $re->sku,
  339. 'TRACEID' => '*',
  340. ])
  341. ->update([
  342. 'TRACEID' => $traceid,
  343. 'EDITWHO' => 'WCS_',
  344. ]);
  345. }
  346. DB::connection("oracle")->commit();
  347. }
  348. dd(true);
  349. } catch (\Exception $e) {
  350. DB::connection("oracle")->rollBack();
  351. dd($e->getMessage());
  352. }
  353. }
  354. }
  355. /**
  356. * 重置15天内的数据
  357. */
  358. public function order_packages_init()
  359. {
  360. OrderPackage::query()
  361. ->whereBetween('created_at', [now()->subDays(15), now()])
  362. ->update([
  363. 'is_delay_deliver' => 0,
  364. 'sync_routes_flag' => 0,
  365. 'status' => 1,
  366. 'exception_status' => 0,
  367. ]);
  368. OrderPackage::query()
  369. ->whereBetween('created_at', [now()->subDays(15), now()])
  370. ->whereNotNull('received_at')
  371. ->update([
  372. 'status' => 7,
  373. ]);
  374. }
  375. public function syncOrderPackage(){
  376. ini_set('memory_limit','500M');
  377. ini_set('max_execution_time', 0);
  378. $orderPackingSummary = OracleDocOrderPackingSummary::query()
  379. ->where('editTime','>=','2021-09-11 12:00:00')
  380. ->where('editTime','<=','2021-09-12 12:40:00')
  381. ->get();
  382. $orderPackingSummary_chunk = $orderPackingSummary->chunk(200);
  383. foreach ($orderPackingSummary_chunk as $orderPackingSummarys) {
  384. foreach ($orderPackingSummarys as $orderPackingSummary) {
  385. $orderPackage = OrderPackage::query()->where('logistic_number',$orderPackingSummary->traceid)->first();
  386. $orderPackage->update([
  387. 'uploaded_to_wms'=> true,
  388. 'weight'=>$orderPackingSummary->grossweight,
  389. 'length'=>$orderPackingSummary->length,
  390. 'width'=>$orderPackingSummary->width,
  391. 'height'=>$orderPackingSummary->height,
  392. 'weighed_at'=>$orderPackingSummary->edittime
  393. ]);
  394. dispatch(new WeightUpdateInstantBill($orderPackage));
  395. }
  396. }
  397. return ['success' => true];
  398. }
  399. public function collectUpload()
  400. {
  401. /** @var OrderPackageService $service */
  402. $service = app('OrderPackageService');
  403. return $service->collectUpload([
  404. '75803656098638',
  405. '75803656098612'
  406. ]);
  407. }
  408. public function testStr(){
  409. $order = factory(Order::class)->create();
  410. }
  411. }