TestController.php 12 KB

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