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