TestController.php 12 KB

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