TestController.php 15 KB

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