TestController.php 15 KB

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