TestController.php 13 KB

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