TestController.php 13 KB

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