TestController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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. dd(app("MenuService")->getVisibleFunctionList());
  133. $url = 'denied';
  134. header('Location: /'.$url,true,302);
  135. die();
  136. TaskTransaction::query()->where("id",">=",280)->delete();
  137. /*$a= new StorageService();
  138. $a->clearTask(["HAIB1-01-01"]);
  139. $task = StationTaskMaterialBox::query()->find(90233);
  140. $station = Station::query()->find(11);
  141. $foreignHaiRoboticsService = new ForeignHaiRoboticsService();
  142. $foreignHaiRoboticsService->putBinToStore_fromCacheShelf($task, $station);
  143. dd(1);*/
  144. /*$batchService = new BatchService();
  145. $batches = Batch::query()->where("id",171829)->get();
  146. $batchService->assignTasks($batches);
  147. dd();*/
  148. /*TaskTransaction::query()->where("id",">=",277)->delete();
  149. StationTaskMaterialBox::query()->whereIn("id",[89685,89686,89687])->delete();
  150. app("CacheShelfService")->_stationCacheLightOff("HAIB1-01-01");//灭灯
  151. app("CacheShelfService")->_stationCacheLightOff("HAIB1-02-01");//灭灯
  152. dd(1);*/
  153. Station::query()->where("station_type_id",5)->update(["status"=>1]);
  154. Cache::forget("CACHE_SHELF_AVAILABLE");
  155. $station = ["HAIB1-01-01","HAIB1-02-01"];
  156. $material = ["IDE0001824","IDE0001740","IDE0002710"];
  157. Station::query()->whereIn("code",$station)->update(["status"=>0]);
  158. $stations = Station::query()->whereIn("code",$station)->get();
  159. $materials = MaterialBox::query()->whereIn("code",$material)->get();
  160. $dateTime = date("Y-m-d H:i:s");
  161. $task1 = StationTaskMaterialBox::query()->create([
  162. 'station_id'=>$stations[0]->id,
  163. 'material_box_id'=>$materials[0]->id,
  164. 'station_task_batch_id'=>1,
  165. 'status'=>'待处理'
  166. ]);
  167. $task2=StationTaskMaterialBox::query()->create([
  168. 'station_id'=>$stations[1]->id,
  169. 'material_box_id'=>$materials[1]->id,
  170. 'station_task_batch_id'=>1,
  171. 'status'=>'待处理'
  172. ]);
  173. $task3=StationTaskMaterialBox::query()->create([
  174. 'station_id'=>6,
  175. 'material_box_id'=>$materials[2]->id,
  176. 'station_task_batch_id'=>1,
  177. 'status'=>'待处理'
  178. ]);
  179. TaskTransaction::query()->insert([[
  180. "doc_code" => "test",
  181. "bar_code" => "test",
  182. "to_station_id" => $stations[0]->id,
  183. "material_box_id" => $materials[0]->id,
  184. "task_id" => $task1->id,
  185. "commodity_id" => 505012,//XUNI03
  186. "amount" => 1,
  187. "type" => "出库",
  188. "status" => 0,
  189. "mark" => 2,
  190. "bin_number"=>1,
  191. "created_at"=>$dateTime,
  192. "updated_at"=>$dateTime,
  193. ],[
  194. "doc_code" => "test",
  195. "bar_code" => "test",
  196. "to_station_id" => $stations[1]->id,
  197. "material_box_id" => $materials[1]->id,
  198. "task_id" => $task2->id,
  199. "commodity_id" => 505012,//XUNI03
  200. "amount" => 1,
  201. "type" => "出库",
  202. "status" => 0,
  203. "mark" => 2,
  204. "bin_number"=>1,
  205. "created_at"=>$dateTime,
  206. "updated_at"=>$dateTime,
  207. ],[
  208. "doc_code" => "test",
  209. "bar_code" => "test",
  210. "to_station_id" => 6,
  211. "material_box_id" => $materials[2]->id,
  212. "task_id" => $task3->id,
  213. "commodity_id" => 505012,//XUNI03
  214. "amount" => 1,
  215. "type" => "出库",
  216. "status" => 3,
  217. "mark" => 2,
  218. "bin_number"=>1,
  219. "created_at"=>$dateTime,
  220. "updated_at"=>$dateTime,
  221. ]]);
  222. $foreignHaiRoboticsService = new ForeignHaiRoboticsService();
  223. $toLocation = collect($station);
  224. $taskMaterialBoxes = collect([$task1,$task2]);
  225. $foreignHaiRoboticsService->
  226. fetchGroup_multiLocation($toLocation, $taskMaterialBoxes, '', '立架出至缓存架',20,false);
  227. foreach ($toLocation as $index=>$value){
  228. app("CacheShelfService")->lightUp($value,'3','0',["title"=>"机器人取箱中,禁止操作"]);
  229. Cache::forever("CACHE_SHELF_OCCUPANCY_{$stations[$index]->id}",true);
  230. }
  231. app("StationService")->locationOccupyMulti($toLocation->toArray());
  232. }
  233. public function update_order_packages_is_manual_update()
  234. {
  235. $descriptions = Log::query()
  236. ->select('description')
  237. ->whereBetween('created_at', ['2021-08-31 10:30:00', '2021-08-31 10:35:00'])
  238. ->where('class', 'like', 'https://was.baoshi56.com/package/logistic/batchUpdate%')->pluck('description');
  239. foreach ($descriptions as $description) {
  240. $description = substr($description, 9);
  241. $description = \Illuminate\Support\Str::before($description, "}");
  242. $obj = json_decode($description . '}', true);
  243. OrderPackage::query()
  244. ->whereIn('logistic_number', $obj['logistic_numbers'])
  245. ->update([
  246. 'status' => '无',
  247. 'is_manual_update' => false,
  248. ]);
  249. }
  250. }
  251. public function updateWorkOrder(){
  252. $items = WorkOrder::query()->with('order.owner')->get();
  253. $params = [];
  254. $items->each(function($item)use(&$params){
  255. if ($item->order){
  256. $owner_id = $item->order->owner_id;
  257. $params[] = [
  258. 'id' => $item->id,
  259. 'order_id' => $item->order->id,
  260. 'owner_id' => $owner_id,
  261. ];
  262. $item->owner_id = $owner_id;
  263. $item->save();
  264. }
  265. });
  266. }
  267. public function testUpdateInv()
  268. {
  269. ini_set('max_execution_time', 0);
  270. ini_set('memory_limit', '4096M');
  271. $sql = <<<sql
  272. select FMLOTNUM,FMLOCATION,PLANTOLOCATION,CREATE_TRANSACTIONID,SKU,CUSTOMERID from TSK_TASKLISTS
  273. where CUSTOMERID=?
  274. AND FMLOCATION= ?
  275. AND OPENWHO = ?
  276. AND TASKPROCESS = ?
  277. AND DOCTYPE = ?
  278. AND TASKTYPE = ?
  279. AND LOTATT05=?
  280. AND LOTATT08=?
  281. AND PLANTOID = ?
  282. and OPENTIME>=TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')
  283. and OPENTIME<=TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')
  284. sql;
  285. $CUSTOMERID = 'JIANSHANG';
  286. $FMLOCATION = 'STAGEWH02';
  287. $OPENWHO = 'WCS';
  288. $TASKPROCESS = '00';
  289. $DOCTYPE = 'ASN';
  290. $TASKTYPE = 'PA';
  291. $LOTATT05 = 'MJ-CP';
  292. $LOTATT08 = 'ZP';
  293. $PLANTOID = '*';
  294. $traceid = 'JIANSHANG03';
  295. $start = '2021-09-02 23:59:59';
  296. $end = '2021-09-03 11:10:00';
  297. $res = DB::connection("oracle")->select(DB::raw($sql),
  298. [$CUSTOMERID, $FMLOCATION, $OPENWHO, $TASKPROCESS, $DOCTYPE, $TASKTYPE, $LOTATT05, $LOTATT08, $PLANTOID, $start, $end]);
  299. $resItems = array_chunk($res, 200);
  300. foreach ($resItems as $res) {
  301. DB::connection("oracle")->beginTransaction();
  302. try {
  303. foreach ($res as $re) {
  304. DB::connection("oracle")->table('INV_LOT_LOC_ID')
  305. ->where([
  306. 'LOTNUM' => $re->fmlotnum,
  307. 'LOCATIONID' => $re->fmlocation,
  308. 'CUSTOMERID' => $re->customerid,
  309. 'sku' => $re->sku,
  310. 'TRACEID' => '*',
  311. ])
  312. ->update([
  313. 'TRACEID' => $traceid,
  314. 'EDITWHO' => 'WCS_',
  315. ]);
  316. if ($re->fmlocation != $re->plantolocation) {
  317. DB::connection("oracle")->table('INV_LOT_LOC_ID')
  318. ->where([
  319. 'LOTNUM' => $re->fmlotnum,
  320. 'LOCATIONID' => $re->plantolocation,
  321. 'CUSTOMERID' => $re->customerid,
  322. 'sku' => $re->sku,
  323. 'TRACEID' => '*',
  324. ])
  325. ->update([
  326. 'TRACEID' => $traceid,
  327. 'EDITWHO' => 'WCS_',
  328. ]);
  329. }
  330. DB::connection("oracle")->commit();
  331. }
  332. dd(true);
  333. } catch (\Exception $e) {
  334. DB::connection("oracle")->rollBack();
  335. dd($e->getMessage());
  336. }
  337. }
  338. }
  339. public function testDocOrder()
  340. {
  341. $now=Carbon::now()->toDateTimeString();
  342. $before=Carbon::now()->subMinutes(30)->toDateTimeString();
  343. // dd($now,$before);
  344. $orders=OracleDOCOrderHeader::query()
  345. ->whereIn('sostatus',['40','50','60','61'])
  346. // ->where('edittime','>=',$before)
  347. // ->where('edittime','<=',$now)
  348. ->whereNotNull('soreference5')
  349. ->where('manualflag','N')
  350. ->whereIn('customerid',['BAOSHI']) //指定货主
  351. ->where('releasestatus','!=','H')
  352. ->get();
  353. // ->update(['manualflag'=>'N','edittime'=>$now]);
  354. dd($orders);
  355. }
  356. }