TestController.php 13 KB

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