TestController.php 12 KB

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