TestController.php 12 KB

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