TestController.php 15 KB

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