TestController.php 14 KB

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