TestController.php 11 KB

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