TestController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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. $a = "2021-09-13 00:00:00";
  138. dd(mb_substr($a,0,10));
  139. $models = app("MaterialBoxModelService")->getModelSortedByOwner(null);
  140. foreach ($models as $model){
  141. $box = app("MaterialBoxService")->getAnEmptyBox($model,[],2);
  142. dd($box);
  143. if ($box)return $box;
  144. }
  145. dd();
  146. TaskTransaction::query()->where("id",">=",280)->delete();
  147. /*$a= new StorageService();
  148. $a->clearTask(["HAIB1-01-01"]);
  149. $task = StationTaskMaterialBox::query()->find(90233);
  150. $station = Station::query()->find(11);
  151. $foreignHaiRoboticsService = new ForeignHaiRoboticsService();
  152. $foreignHaiRoboticsService->putBinToStore_fromCacheShelf($task, $station);
  153. dd(1);*/
  154. /*$batchService = new BatchService();
  155. $batches = Batch::query()->where("id",171829)->get();
  156. $batchService->assignTasks($batches);
  157. dd();*/
  158. /*TaskTransaction::query()->where("id",">=",277)->delete();
  159. StationTaskMaterialBox::query()->whereIn("id",[89685,89686,89687])->delete();
  160. app("CacheShelfService")->_stationCacheLightOff("HAIB1-01-01");//灭灯
  161. app("CacheShelfService")->_stationCacheLightOff("HAIB1-02-01");//灭灯
  162. dd(1);*/
  163. Station::query()->where("station_type_id", 5)->update(["status" => 1]);
  164. Cache::forget("CACHE_SHELF_AVAILABLE");
  165. $station = ["HAIB1-01-01", "HAIB1-02-01"];
  166. $material = ["IDE0001824", "IDE0001740", "IDE0002710"];
  167. Station::query()->whereIn("code", $station)->update(["status" => 0]);
  168. $stations = Station::query()->whereIn("code", $station)->get();
  169. $materials = MaterialBox::query()->whereIn("code", $material)->get();
  170. $dateTime = date("Y-m-d H:i:s");
  171. $task1 = StationTaskMaterialBox::query()->create([
  172. 'station_id' => $stations[0]->id,
  173. 'material_box_id' => $materials[0]->id,
  174. 'station_task_batch_id' => 1,
  175. 'status' => '待处理'
  176. ]);
  177. $task2 = StationTaskMaterialBox::query()->create([
  178. 'station_id' => $stations[1]->id,
  179. 'material_box_id' => $materials[1]->id,
  180. 'station_task_batch_id' => 1,
  181. 'status' => '待处理'
  182. ]);
  183. $task3 = StationTaskMaterialBox::query()->create([
  184. 'station_id' => 6,
  185. 'material_box_id' => $materials[2]->id,
  186. 'station_task_batch_id' => 1,
  187. 'status' => '待处理'
  188. ]);
  189. TaskTransaction::query()->insert([[
  190. "doc_code" => "test",
  191. "bar_code" => "test",
  192. "to_station_id" => $stations[0]->id,
  193. "material_box_id" => $materials[0]->id,
  194. "task_id" => $task1->id,
  195. "commodity_id" => 505012,//XUNI03
  196. "amount" => 1,
  197. "type" => "出库",
  198. "status" => 0,
  199. "mark" => 2,
  200. "bin_number" => 1,
  201. "created_at" => $dateTime,
  202. "updated_at" => $dateTime,
  203. ], [
  204. "doc_code" => "test",
  205. "bar_code" => "test",
  206. "to_station_id" => $stations[1]->id,
  207. "material_box_id" => $materials[1]->id,
  208. "task_id" => $task2->id,
  209. "commodity_id" => 505012,//XUNI03
  210. "amount" => 1,
  211. "type" => "出库",
  212. "status" => 0,
  213. "mark" => 2,
  214. "bin_number" => 1,
  215. "created_at" => $dateTime,
  216. "updated_at" => $dateTime,
  217. ], [
  218. "doc_code" => "test",
  219. "bar_code" => "test",
  220. "to_station_id" => 6,
  221. "material_box_id" => $materials[2]->id,
  222. "task_id" => $task3->id,
  223. "commodity_id" => 505012,//XUNI03
  224. "amount" => 1,
  225. "type" => "出库",
  226. "status" => 3,
  227. "mark" => 2,
  228. "bin_number" => 1,
  229. "created_at" => $dateTime,
  230. "updated_at" => $dateTime,
  231. ]]);
  232. $foreignHaiRoboticsService = new ForeignHaiRoboticsService();
  233. $toLocation = collect($station);
  234. $taskMaterialBoxes = collect([$task1, $task2]);
  235. $foreignHaiRoboticsService->
  236. fetchGroup_multiLocation($toLocation, $taskMaterialBoxes, '', '立架出至缓存架', 20, false);
  237. foreach ($toLocation as $index => $value) {
  238. app("CacheShelfService")->lightUp($value, '3', '0', ["title" => "机器人取箱中,禁止操作"]);
  239. Cache::forever("CACHE_SHELF_OCCUPANCY_{$stations[$index]->id}", true);
  240. }
  241. app("StationService")->locationOccupyMulti($toLocation->toArray());
  242. }
  243. public function update_order_packages_is_manual_update()
  244. {
  245. $descriptions = Log::query()
  246. ->select('description')
  247. ->whereBetween('created_at', ['2021-08-31 10:30:00', '2021-08-31 10:35:00'])
  248. ->where('class', 'like', 'https://was.baoshi56.com/package/logistic/batchUpdate%')->pluck('description');
  249. foreach ($descriptions as $description) {
  250. $description = substr($description, 9);
  251. $description = \Illuminate\Support\Str::before($description, "}");
  252. $obj = json_decode($description . '}', true);
  253. OrderPackage::query()
  254. ->whereIn('logistic_number', $obj['logistic_numbers'])
  255. ->update([
  256. 'status' => '无',
  257. 'is_manual_update' => false,
  258. ]);
  259. }
  260. }
  261. public function testUpdateInv()
  262. {
  263. ini_set('max_execution_time', 0);
  264. ini_set('memory_limit', '4096M');
  265. $sql = <<<sql
  266. select FMLOTNUM,FMLOCATION,PLANTOLOCATION,CREATE_TRANSACTIONID,SKU,CUSTOMERID from TSK_TASKLISTS
  267. where CUSTOMERID=?
  268. AND FMLOCATION= ?
  269. AND OPENWHO = ?
  270. AND TASKPROCESS = ?
  271. AND DOCTYPE = ?
  272. AND TASKTYPE = ?
  273. AND LOTATT05=?
  274. AND LOTATT08=?
  275. AND PLANTOID = ?
  276. and OPENTIME>=TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')
  277. and OPENTIME<=TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')
  278. sql;
  279. $CUSTOMERID = 'JIANSHANG';
  280. $FMLOCATION = 'STAGEWH02';
  281. $OPENWHO = 'WCS';
  282. $TASKPROCESS = '00';
  283. $DOCTYPE = 'ASN';
  284. $TASKTYPE = 'PA';
  285. $LOTATT05 = 'MJ-CP';
  286. $LOTATT08 = 'ZP';
  287. $PLANTOID = '*';
  288. $traceid = 'JIANSHANG03';
  289. $start = '2021-09-02 23:59:59';
  290. $end = '2021-09-03 11:10:00';
  291. $res = DB::connection("oracle")->select(DB::raw($sql),
  292. [$CUSTOMERID, $FMLOCATION, $OPENWHO, $TASKPROCESS, $DOCTYPE, $TASKTYPE, $LOTATT05, $LOTATT08, $PLANTOID, $start, $end]);
  293. $resItems = array_chunk($res, 200);
  294. foreach ($resItems as $res) {
  295. DB::connection("oracle")->beginTransaction();
  296. try {
  297. foreach ($res as $re) {
  298. DB::connection("oracle")->table('INV_LOT_LOC_ID')
  299. ->where([
  300. 'LOTNUM' => $re->fmlotnum,
  301. 'LOCATIONID' => $re->fmlocation,
  302. 'CUSTOMERID' => $re->customerid,
  303. 'sku' => $re->sku,
  304. 'TRACEID' => '*',
  305. ])
  306. ->update([
  307. 'TRACEID' => $traceid,
  308. 'EDITWHO' => 'WCS_',
  309. ]);
  310. if ($re->fmlocation != $re->plantolocation) {
  311. DB::connection("oracle")->table('INV_LOT_LOC_ID')
  312. ->where([
  313. 'LOTNUM' => $re->fmlotnum,
  314. 'LOCATIONID' => $re->plantolocation,
  315. 'CUSTOMERID' => $re->customerid,
  316. 'sku' => $re->sku,
  317. 'TRACEID' => '*',
  318. ])
  319. ->update([
  320. 'TRACEID' => $traceid,
  321. 'EDITWHO' => 'WCS_',
  322. ]);
  323. }
  324. DB::connection("oracle")->commit();
  325. }
  326. dd(true);
  327. } catch (\Exception $e) {
  328. DB::connection("oracle")->rollBack();
  329. dd($e->getMessage());
  330. }
  331. }
  332. }
  333. /**
  334. * 重置15天内的数据
  335. */
  336. public function order_packages_init()
  337. {
  338. OrderPackage::query()
  339. ->whereBetween('created_at', [now()->subDays(15), now()])
  340. ->update([
  341. 'is_delay_deliver' => 0,
  342. 'sync_routes_flag' => 0,
  343. 'status' => 1,
  344. 'exception_status' => 0,
  345. ]);
  346. OrderPackage::query()
  347. ->whereBetween('created_at', [now()->subDays(15), now()])
  348. ->whereNotNull('received_at')
  349. ->update([
  350. 'status' => 7,
  351. ]);
  352. }
  353. public function syncOrderPackage(){
  354. ini_set('memory_limit','500M');
  355. ini_set('max_execution_time', 0);
  356. $orderPackingSummary = OracleDocOrderPackingSummary::query()
  357. ->where('editTime','>=','2021-09-11 12:00:00')
  358. ->where('editTime','<=','2021-09-12 12:40:00')
  359. ->get();
  360. $orderPackingSummary_chunk = $orderPackingSummary->chunk(200);
  361. foreach ($orderPackingSummary_chunk as $orderPackingSummarys) {
  362. foreach ($orderPackingSummarys as $orderPackingSummary) {
  363. $orderPackage = OrderPackage::query()->where('logistic_number',$orderPackingSummary->traceid)->first();
  364. $orderPackage->update([
  365. 'uploaded_to_wms'=> true,
  366. 'weight'=>$orderPackingSummary->grossweight,
  367. 'length'=>$orderPackingSummary->length,
  368. 'width'=>$orderPackingSummary->width,
  369. 'height'=>$orderPackingSummary->height,
  370. 'weighed_at'=>$orderPackingSummary->edittime
  371. ]);
  372. dispatch(new WeightUpdateInstantBill($orderPackage));
  373. }
  374. }
  375. return ['success' => true];
  376. }
  377. }