TestController.php 12 KB

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