TestController.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Authority;
  4. use App\Batch;
  5. use App\Events\CancelOrder;
  6. use App\Events\WmsReceiveNewEvent;
  7. use App\Http\Controllers\Api\thirdPart\flux\WaybillController;
  8. use App\Logistic;
  9. use App\OracleActTransactionLog;
  10. use App\Order;
  11. use App\Package;
  12. use App\Rejected;
  13. use App\RejectedBill;
  14. use App\RejectedBillItem;
  15. use App\Unit;
  16. use App\User;
  17. use App\UserToken;
  18. use App\UserWorkgroup;
  19. use App\Waybill;
  20. use App\OraccleBasCustomer;
  21. use App\WMSReflectReceive;
  22. use Carbon\Carbon;
  23. use Endroid\QrCode\QrCode;
  24. use Endroid\QrCode\Response\QrCodeResponse;
  25. use Illuminate\Database\Query\JoinClause;
  26. use Illuminate\Http\Request;
  27. use Illuminate\Support\Facades\DB;
  28. use function PHPSTORM_META\map;
  29. use Zttp\Zttp;
  30. class TestController extends Controller
  31. {
  32. private $data=[];
  33. public function __construct()
  34. {
  35. $this->data["active_test"]="active";
  36. }
  37. public function method(Request $request,$method)
  38. {
  39. return call_user_func([$this, $method],$request);
  40. }
  41. function t1(Request $request){ //x $packagesBatch=Package::where('batch_number',$batch_number)->first();
  42. ini_set('max_execution_time',2500);
  43. ini_set('memory_limit','1526M');
  44. $uploaded=0;
  45. $count=DB::table('logs')->where('operation','like',"%PackageController::new_%" )
  46. ->where('created_at','>',"2020-06-03 14:02:00")
  47. ->where('created_at','<',"2020-06-03 15:05:00")
  48. ->where('type',"request_new_")
  49. ->count();
  50. $requests=DB::table('logs')->where('operation','like',"%PackageController::new_%" )
  51. ->where('created_at','>',"2020-06-03 14:02:00")
  52. ->where('created_at','<',"2020-06-03 15:05:00")
  53. ->where('type',"request_new_")
  54. ->get();
  55. $requests->each(function($request)use(&$uploaded){
  56. $requestJson=json_decode($request->description,true);
  57. $response = Zttp::withHeaders([ 'content-type' => 'application/json',
  58. ])->post('https://was.baoshi56.com/api/thirdPart/flux/package/new',
  59. $requestJson
  60. );
  61. if($response->json()&&$response->json()['response']&&$response->json()['response']['flag']=='Y')
  62. $uploaded+=1;
  63. });
  64. dd($uploaded.'/'.$count);
  65. }
  66. function t2(Request $request){ //x $packagesBatch=Package::where('batch_number',$batch_number)->first();
  67. $uploaded=0;
  68. $count=DB::table('logs')->where('operation','like',"%PackageController::new_%" )
  69. ->where('created_at','>',"2020-06-03 14:02:00")
  70. ->where('created_at','<',"2020-06-03 15:05:00")
  71. ->where('type',"request_new_")
  72. ->where('description','like',"%W200603000117%")
  73. ->count();
  74. $requests=DB::table('logs')->where('operation','like',"%PackageController::new_%" )
  75. ->where('created_at','>',"2020-06-03 14:02:00")
  76. ->where('created_at','<',"2020-06-03 15:05:00")
  77. ->where('description','like',"%W200603000117%")
  78. ->where('type',"request_new_")
  79. ->get();
  80. $requests->each(function($request)use(&$uploaded){
  81. $requestJson=json_decode($request->description,true);
  82. $response = Zttp::withHeaders([ 'content-type' => 'application/json',
  83. ])->post('https://was.baoshi56.com/api/thirdPart/flux/package/new',
  84. $requestJson
  85. );
  86. if($response->json()&&$response->json()['response']&&$response->json()['response']['flag']=='Y')
  87. $uploaded+=1;
  88. });
  89. dd($uploaded.'/'.$count);
  90. }
  91. function tj(Request $request){
  92. $waybills=Waybill::where('created_at','like','%2020-05-25%')->orWhere('created_at','like','%2020-05-30%')->get();
  93. $controller=(new WaybillController());
  94. $waybills->each(function ($waybill)use($controller){
  95. $controller->accomplishToWMS($waybill);
  96. });
  97. dd($waybills->count());
  98. }
  99. function injectJS(Request $request){
  100. $items=RejectedBillItem::whereHas('rejectedBill',function($query){
  101. return $query->where('id_owner',2);
  102. })->where('created_at','>','2019-12-23 18:11:00')->where('created_at','<','2019-12-24 11:25:00')->get();
  103. (new RejectedBillItemController())->collectionsToPackConfirm($items);
  104. }
  105. public function tj2(Request $request)
  106. {
  107. $rejected = Rejected::find(10);
  108. $rejectedJianshang=new \App\Http\Controllers\api\jianshang\RejectedController();
  109. dd( $rejectedJianshang->sendRejected($rejected));
  110. }
  111. public function excelIt()
  112. {
  113. $excel=new ExcelController();
  114. return $excel->makeExcel();
  115. }
  116. public function featureIt()
  117. {
  118. LogisticNumberFeatureController::loadRecentRejectedsToFeatures(5,2500);
  119. }
  120. public function newSku()
  121. {
  122. $url='http://bswcs/api/sorting/flux/newSku';
  123. $response = Zttp::post($url, [
  124. 'request'=>[
  125. [
  126. "SKU"=> "1234567890",
  127. "NAME"=> "瑞士莲**巧克力",
  128. "Alternate_SKU1"=> "1122334455",
  129. "GrossWeight"=> "1.2",
  130. "Cube"=> "0.75",
  131. "SKULength"=> "0.25",
  132. "SKUWidth"=> "0.15",
  133. "SKUHigh"=> "0.05"
  134. ],
  135. [
  136. "SKU"=> "1234567892",
  137. "NAME"=> "跳跳饼",
  138. "Alternate_SKU1"=> "",
  139. "GrossWeight"=> "1.3",
  140. "Cube"=> "0.75",
  141. "SKULength"=> "0.25",
  142. "SKUWidth"=> "0.15",
  143. "SKUHigh"=> "0.25"
  144. ],
  145. ]
  146. ]);
  147. return $response->json();
  148. }
  149. public function changePackage(){
  150. $packages=Package::where('delivery_number','<>',null)->where('logistic_id',null)->get();
  151. dd($packages);
  152. $packages=Package::whereRaw('delivery_number IS NOT NULL AND logistic_id IS NULL')->get();
  153. $logistics=Logistic::get();
  154. $packages->each(function ($package)use($logistics){
  155. $logistics->each(function ($logistic)use($package){
  156. if ($package->WMSReflectPackage->CarrierID==$logistic->code){
  157. $package->logistic_id=$logistic->id;
  158. return;
  159. }
  160. });
  161. });
  162. return "OK";
  163. }
  164. public function tNull(){
  165. }
  166. public function deletePackageAuthority()
  167. {
  168. $authorities=Authority::where('name','like','%包裹信息%')->get();
  169. $authorities->each(function ($authority){
  170. $authority->delete();
  171. });
  172. }
  173. public function test3()
  174. {
  175. $strs=["auibh","aopk","bikon"];
  176. if (!$strs[0])return "";
  177. $len=strlen($strs[0]);
  178. for ($i=1;$i<count($strs);$i++){
  179. if ($len<1)break;
  180. for ($j=0;$j<$len;$j++){
  181. if ($strs[$i][$j]!=$strs[0][$j]){
  182. if ($j==0)return "";
  183. break;
  184. }
  185. $sum=$j+1;
  186. }
  187. $len=isset($sum)?$sum:0;
  188. }
  189. return substr($strs[0],0,$len);
  190. }
  191. public function test4(){
  192. $s="{([{()()[]{}}])[{()()[}]{}}](){[]}";
  193. $map = [
  194. ")" => "(",
  195. "}" => "{",
  196. "]" => "[",
  197. ];
  198. $len = strlen($s);
  199. $stack = [];
  200. if ($len%2!=0)dd(false);
  201. //s中出现map的key则弹出,没有出现则入栈
  202. for ($i =0; $i<$len; $i++) {
  203. var_dump("data:".$s[$i]);
  204. if (isset($map[$s[$i]])){
  205. //s中出现map的key:如果能找到对应的map的值 (,{,[ 则说明有配对,则弹出
  206. if (isset($stack) && $stack[0] == $map[$s[$i]]) {
  207. array_shift($stack);
  208. } else { //仅找到后面的一部分,说明是不匹配的
  209. dd(false);
  210. }
  211. var_dump("value1:".$map[$s[$i]]);
  212. var_dump($stack);
  213. } else {
  214. array_unshift($stack, $s[$i]);
  215. var_dump("value2:".$s[$i]);
  216. var_dump($stack);
  217. }
  218. }
  219. if (count($stack) > 0) {
  220. dd(false);
  221. }
  222. dd(true);
  223. //利用栈的先进后出 一个正确的括号组对应都为1对1或N对N
  224. // 先进后出“([{”入栈,")]}"出栈,轮询到出栈元素去映射栈顶,符合出栈,不符合直接返回
  225. //依次轮询 如果映射正确那么最后栈为空栈 否则返回false
  226. }
  227. function test5(Request $request){
  228. $page=$request->input('page')??1;
  229. $date_start=$request->input('date_start');
  230. $date_end=$request->input('date_end');
  231. $sql='select * from (select result.*,rownum rn from (';
  232. $sql.=' select customer.Descr_C 货主, 库位, sku.SKU 产品编码, sku.ALTERNATE_SKU1 产品条码, ';
  233. $sql.=' sku.Descr_C 商品名称, lot.LotAtt05 属性仓, lot.LotAtt08 质量状态, lot.LotAtt02 失效日期, ';
  234. $sql.=' lot.LotAtt04 批号 ';
  235. $sql.=' , sum(移出数量)移出数量, sum(移入数量)移入数量 ';
  236. $sql.=' , storeStatus.QTY 在库数量, storeStatus.QtyAllocated 占用数量,count(1) over () as sum from ';
  237. $sql.=' (select FMLotNum,FMSKU,TOCustomerID,0 as 移出数量, sum(TOQty_Each) as 移入数量, TOLocation as 库位 ';
  238. $sql.=" from ACT_Transaction_Log where TransactionType='PA' ";
  239. if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
  240. if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
  241. if (!$date_start && !$date_end)$sql .= " and addtime >'".date('Y-m-d H:i:s',strtotime("-1 day"))."' ";
  242. $sql.=' group by TOCustomerID, TOLocation, TOCustomerID,FMSKU,FMLotNum union all ';
  243. $sql.=' select FMLotNum,FMSKU,TOCustomerID,sum(FMQty_Each) as 移出数量, 0 as 移入数量, FMLOCATION as 库位 ';
  244. $sql.=" from ACT_Transaction_Log where TransactionType='SO' ";
  245. if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
  246. if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
  247. if (!$date_start && !$date_end)$sql .= " and addtime >'".date('Y-m-d H:i:s',strtotime("-1 day"))."' ";
  248. $sql.=' group by FMCustomerID, FMLocation, TOCustomerID,FMSKU,FMLotNum union all ';
  249. $sql.=' select FMLotNum,FMSKU,TOCustomerID,sum(FMQty_Each) as 移出数量,0 as 移入数量, FMLocation as 库位 ';
  250. $sql.=" from ACT_Transaction_Log where TransactionType='MV' ";
  251. if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
  252. if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
  253. if (!$date_start && !$date_end)$sql .= " and addtime >'".date('Y-m-d H:i:s',strtotime("-1 day"))."' ";
  254. $sql.=' group by FMLocation,TOCustomerID,FMSKU,FMLotNum union all ';
  255. $sql.=' select FMLotNum,FMSKU,TOCustomerID,0 as 移出数量,sum(TOQty_Each)as 移入数量, TOLocation as 库位 ';
  256. $sql.=" from ACT_Transaction_Log where TransactionType='MV' ";
  257. if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
  258. if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
  259. if (!$date_start && !$date_end)$sql .= " and addtime >'".date('Y-m-d H:i:s',strtotime("-1 day"))."' ";
  260. $sql.=' group by TOLocation,TOCustomerID,FMSKU,FMLotNum)stockLog ';
  261. $sql.=' left join BAS_Customer customer on customer.CustomerID=stockLog.TOCUSTOMERID ';
  262. $sql.=' left join BAS_SKU sku on sku.SKU=stockLog.FMSKU ';
  263. $sql.=' left join INV_LOT_ATT lot on lot.LOTNUM=stockLog.FMLOTNUM ';
  264. $sql.=' left join INV_LOT_LOC_ID storeStatus on storeStatus.LOTNUM=stockLog.FMLOTNUM ';;
  265. $sql.=' and storeStatus.LocationID=stockLog.库位 where ROWNUM<=50 ';
  266. $sql.=' group by 库位,customer.Descr_C,sku.SKU,sku.ALTERNATE_SKU1 ';
  267. $sql.=' ,sku.Descr_C,FMLotNum,lot.LotAtt05,lot.LotAtt08,lot.LotAtt02,lot.LotAtt04 ';
  268. $sql.=' , storeStatus.QTY, storeStatus.QtyAllocated ';
  269. $sql.=' )result) where rn>0';
  270. $oracleActTransactingLogs1=DB::connection('oracle')->select($sql);
  271. unset($sql);
  272. $sql='select * from (select result.*,rownum rn from (';
  273. $sql.=' select customer.Descr_C 货主, 库位, sku.SKU 产品编码, sku.ALTERNATE_SKU1 产品条码, ';
  274. $sql.=' sku.Descr_C 商品名称, lot.LotAtt05 属性仓, lot.LotAtt08 质量状态, lot.LotAtt02 失效日期, ';
  275. $sql.=' lot.LotAtt04 批号 ';
  276. $sql.=' , sum(移出数量)移出数量, sum(移入数量)移入数量 ';
  277. $sql.=' , storeStatus.QTY 在库数量, storeStatus.QtyAllocated 占用数量,count(1) over () as sum from ';
  278. $sql.=' (select FMLotNum,FMSKU,TOCustomerID,0 as 移出数量, sum(TOQty_Each) as 移入数量, TOLocation as 库位 ';
  279. $sql.=" from ACT_Transaction_Log where TransactionType='PA' ";
  280. if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
  281. if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
  282. if (!$date_start && !$date_end)$sql .= " and addtime >'".date('Y-m-d H:i:s',strtotime("-1 day"))."' ";
  283. $sql.=' group by TOCustomerID, TOLocation, TOCustomerID,FMSKU,FMLotNum union all ';
  284. $sql.=' select FMLotNum,FMSKU,TOCustomerID,sum(FMQty_Each) as 移出数量, 0 as 移入数量, FMLOCATION as 库位 ';
  285. $sql.=" from ACT_Transaction_Log where TransactionType='SO' ";
  286. if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
  287. if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
  288. if (!$date_start && !$date_end)$sql .= " and addtime >'".date('Y-m-d H:i:s',strtotime("-1 day"))."' ";
  289. $sql.=' group by FMCustomerID, FMLocation, TOCustomerID,FMSKU,FMLotNum union all ';
  290. $sql.=' select FMLotNum,FMSKU,TOCustomerID,sum(FMQty_Each) as 移出数量,0 as 移入数量, FMLocation as 库位 ';
  291. $sql.=" from ACT_Transaction_Log where TransactionType='MV' ";
  292. if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
  293. if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
  294. if (!$date_start && !$date_end)$sql .= " and addtime >'".date('Y-m-d H:i:s',strtotime("-1 day"))."' ";
  295. $sql.=' group by FMLocation,TOCustomerID,FMSKU,FMLotNum union all ';
  296. $sql.=' select FMLotNum,FMSKU,TOCustomerID,0 as 移出数量,sum(TOQty_Each)as 移入数量, TOLocation as 库位 ';
  297. $sql.=" from ACT_Transaction_Log where TransactionType='MV' ";
  298. if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
  299. if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
  300. if (!$date_start && !$date_end)$sql .= " and addtime >'".date('Y-m-d H:i:s',strtotime("-1 day"))."' ";
  301. $sql.=' group by TOLocation,TOCustomerID,FMSKU,FMLotNum)stockLog ';
  302. $sql.=' left join BAS_Customer customer on customer.CustomerID=stockLog.TOCUSTOMERID ';
  303. $sql.=' left join BAS_SKU sku on sku.SKU=stockLog.FMSKU ';
  304. $sql.=' left join INV_LOT_ATT lot on lot.LOTNUM=stockLog.FMLOTNUM ';
  305. $sql.=' left join INV_LOT_LOC_ID storeStatus on storeStatus.LOTNUM=stockLog.FMLOTNUM ';;
  306. $sql.=' and storeStatus.LocationID=stockLog.库位 where ROWNUM<=500 ';
  307. $sql.=' group by 库位,customer.Descr_C,sku.SKU,sku.ALTERNATE_SKU1 ';
  308. $sql.=' ,sku.Descr_C,FMLotNum,lot.LotAtt05,lot.LotAtt08,lot.LotAtt02,lot.LotAtt04 ';
  309. $sql.=' , storeStatus.QTY, storeStatus.QtyAllocated ';
  310. $sql.=' )result) where rn>50';
  311. $oracleActTransactingLogs2=DB::connection('oracle')->select($sql);
  312. $oracleActTransactingLogs1=json_encode($oracleActTransactingLogs1);
  313. $oracleActTransactingLogs2=json_encode($oracleActTransactingLogs2);
  314. $oracleActTransactingLogs1=json_decode($oracleActTransactingLogs1,true);
  315. $oracleActTransactingLogs2=json_decode($oracleActTransactingLogs2,true);
  316. foreach ($oracleActTransactingLogs1 as $oracleActTransactingLog1){
  317. foreach ($oracleActTransactingLogs2 as $oracleActTransactingLog2){
  318. if ($oracleActTransactingLog1['产品编码']==$oracleActTransactingLog2['产品编码']){
  319. /*if ($oracleActTransactingLog1['产品编码']=='6206100971005')*/var_dump(['oracleActTransactingLog1'=>$oracleActTransactingLog1,'oracleActTransactingLog2'=>$oracleActTransactingLog2]);
  320. }
  321. }
  322. }
  323. }
  324. }