TestController.php 14 KB

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