TestController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. $waybills=Waybill::all();
  43. $controller=(new WaybillController());
  44. $waybills->each(function ($waybill)use($controller){
  45. $controller->accomplishToWMS($waybill);
  46. });
  47. }
  48. function tj(Request $request){
  49. $waybills=Waybill::where('created_at','like','%2020-05-25%')->orWhere('created_at','like','%2020-05-30%')->get();
  50. $controller=(new WaybillController());
  51. $waybills->each(function ($waybill)use($controller){
  52. $controller->accomplishToWMS($waybill);
  53. });
  54. dd($waybills->count());
  55. }
  56. function injectJS(Request $request){
  57. $items=RejectedBillItem::whereHas('rejectedBill',function($query){
  58. return $query->where('id_owner',2);
  59. })->where('created_at','>','2019-12-23 18:11:00')->where('created_at','<','2019-12-24 11:25:00')->get();
  60. (new RejectedBillItemController())->collectionsToPackConfirm($items);
  61. }
  62. public function tj2(Request $request)
  63. {
  64. $rejected = Rejected::find(10);
  65. $rejectedJianshang=new \App\Http\Controllers\api\jianshang\RejectedController();
  66. dd( $rejectedJianshang->sendRejected($rejected));
  67. }
  68. public function excelIt()
  69. {
  70. $excel=new ExcelController();
  71. return $excel->makeExcel();
  72. }
  73. public function featureIt()
  74. {
  75. LogisticNumberFeatureController::loadRecentRejectedsToFeatures(5,2500);
  76. }
  77. public function newSku()
  78. {
  79. $url='http://bswcs/api/sorting/flux/newSku';
  80. $response = Zttp::post($url, [
  81. 'request'=>[
  82. [
  83. "SKU"=> "1234567890",
  84. "NAME"=> "瑞士莲**巧克力",
  85. "Alternate_SKU1"=> "1122334455",
  86. "GrossWeight"=> "1.2",
  87. "Cube"=> "0.75",
  88. "SKULength"=> "0.25",
  89. "SKUWidth"=> "0.15",
  90. "SKUHigh"=> "0.05"
  91. ],
  92. [
  93. "SKU"=> "1234567892",
  94. "NAME"=> "跳跳饼",
  95. "Alternate_SKU1"=> "",
  96. "GrossWeight"=> "1.3",
  97. "Cube"=> "0.75",
  98. "SKULength"=> "0.25",
  99. "SKUWidth"=> "0.15",
  100. "SKUHigh"=> "0.25"
  101. ],
  102. ]
  103. ]);
  104. return $response->json();
  105. }
  106. public function changePackage(){
  107. $packages=Package::where('delivery_number','<>',null)->where('logistic_id',null)->get();
  108. dd($packages);
  109. $packages=Package::whereRaw('delivery_number IS NOT NULL AND logistic_id IS NULL')->get();
  110. $logistics=Logistic::get();
  111. $packages->each(function ($package)use($logistics){
  112. $logistics->each(function ($logistic)use($package){
  113. if ($package->WMSReflectPackage->CarrierID==$logistic->code){
  114. $package->logistic_id=$logistic->id;
  115. return;
  116. }
  117. });
  118. });
  119. return "OK";
  120. }
  121. public function tNull(){
  122. }
  123. public function deletePackageAuthority()
  124. {
  125. $authorities=Authority::where('name','like','%包裹信息%')->get();
  126. $authorities->each(function ($authority){
  127. $authority->delete();
  128. });
  129. }
  130. public function test3()
  131. {
  132. $strs=["auibh","aopk","bikon"];
  133. if (!$strs[0])return "";
  134. $len=strlen($strs[0]);
  135. for ($i=1;$i<count($strs);$i++){
  136. if ($len<1)break;
  137. for ($j=0;$j<$len;$j++){
  138. if ($strs[$i][$j]!=$strs[0][$j]){
  139. if ($j==0)return "";
  140. break;
  141. }
  142. $sum=$j+1;
  143. }
  144. $len=isset($sum)?$sum:0;
  145. }
  146. return substr($strs[0],0,$len);
  147. }
  148. public function test4(){
  149. $s="{([{()()[]{}}])[{()()[}]{}}](){[]}";
  150. $map = [
  151. ")" => "(",
  152. "}" => "{",
  153. "]" => "[",
  154. ];
  155. $len = strlen($s);
  156. $stack = [];
  157. if ($len%2!=0)dd(false);
  158. //s中出现map的key则弹出,没有出现则入栈
  159. for ($i =0; $i<$len; $i++) {
  160. var_dump("data:".$s[$i]);
  161. if (isset($map[$s[$i]])){
  162. //s中出现map的key:如果能找到对应的map的值 (,{,[ 则说明有配对,则弹出
  163. if (isset($stack) && $stack[0] == $map[$s[$i]]) {
  164. array_shift($stack);
  165. } else { //仅找到后面的一部分,说明是不匹配的
  166. dd(false);
  167. }
  168. var_dump("value1:".$map[$s[$i]]);
  169. var_dump($stack);
  170. } else {
  171. array_unshift($stack, $s[$i]);
  172. var_dump("value2:".$s[$i]);
  173. var_dump($stack);
  174. }
  175. }
  176. if (count($stack) > 0) {
  177. dd(false);
  178. }
  179. dd(true);
  180. //利用栈的先进后出 一个正确的括号组对应都为1对1或N对N
  181. // 先进后出“([{”入栈,")]}"出栈,轮询到出栈元素去映射栈顶,符合出栈,不符合直接返回
  182. //依次轮询 如果映射正确那么最后栈为空栈 否则返回false
  183. }
  184. function test5(Request $request){
  185. $page=$request->input('page')??1;
  186. $date_start=$request->input('date_start');
  187. $date_end=$request->input('date_end');
  188. $sql='select * from (select result.*,rownum rn from (';
  189. $sql.=' select customer.Descr_C 货主, 库位, sku.SKU 产品编码, sku.ALTERNATE_SKU1 产品条码, ';
  190. $sql.=' sku.Descr_C 商品名称, lot.LotAtt05 属性仓, lot.LotAtt08 质量状态, lot.LotAtt02 失效日期, ';
  191. $sql.=' lot.LotAtt04 批号 ';
  192. $sql.=' , sum(移出数量)移出数量, sum(移入数量)移入数量 ';
  193. $sql.=' , storeStatus.QTY 在库数量, storeStatus.QtyAllocated 占用数量,count(1) over () as sum from ';
  194. $sql.=' (select FMLotNum,FMSKU,TOCustomerID,0 as 移出数量, sum(TOQty_Each) as 移入数量, TOLocation as 库位 ';
  195. $sql.=" from ACT_Transaction_Log where TransactionType='PA' ";
  196. if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
  197. if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
  198. if (!$date_start && !$date_end)$sql .= " and addtime >'".date('Y-m-d H:i:s',strtotime("-1 day"))."' ";
  199. $sql.=' group by TOCustomerID, TOLocation, TOCustomerID,FMSKU,FMLotNum union all ';
  200. $sql.=' select FMLotNum,FMSKU,TOCustomerID,sum(FMQty_Each) as 移出数量, 0 as 移入数量, FMLOCATION as 库位 ';
  201. $sql.=" from ACT_Transaction_Log where TransactionType='SO' ";
  202. if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
  203. if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
  204. if (!$date_start && !$date_end)$sql .= " and addtime >'".date('Y-m-d H:i:s',strtotime("-1 day"))."' ";
  205. $sql.=' group by FMCustomerID, FMLocation, TOCustomerID,FMSKU,FMLotNum union all ';
  206. $sql.=' select FMLotNum,FMSKU,TOCustomerID,sum(FMQty_Each) as 移出数量,0 as 移入数量, FMLocation as 库位 ';
  207. $sql.=" from ACT_Transaction_Log where TransactionType='MV' ";
  208. if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
  209. if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
  210. if (!$date_start && !$date_end)$sql .= " and addtime >'".date('Y-m-d H:i:s',strtotime("-1 day"))."' ";
  211. $sql.=' group by FMLocation,TOCustomerID,FMSKU,FMLotNum union all ';
  212. $sql.=' select FMLotNum,FMSKU,TOCustomerID,0 as 移出数量,sum(TOQty_Each)as 移入数量, TOLocation as 库位 ';
  213. $sql.=" from ACT_Transaction_Log where TransactionType='MV' ";
  214. if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
  215. if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
  216. if (!$date_start && !$date_end)$sql .= " and addtime >'".date('Y-m-d H:i:s',strtotime("-1 day"))."' ";
  217. $sql.=' group by TOLocation,TOCustomerID,FMSKU,FMLotNum)stockLog ';
  218. $sql.=' left join BAS_Customer customer on customer.CustomerID=stockLog.TOCUSTOMERID ';
  219. $sql.=' left join BAS_SKU sku on sku.SKU=stockLog.FMSKU ';
  220. $sql.=' left join INV_LOT_ATT lot on lot.LOTNUM=stockLog.FMLOTNUM ';
  221. $sql.=' left join INV_LOT_LOC_ID storeStatus on storeStatus.LOTNUM=stockLog.FMLOTNUM ';;
  222. $sql.=' and storeStatus.LocationID=stockLog.库位 where ROWNUM<=50 ';
  223. $sql.=' group by 库位,customer.Descr_C,sku.SKU,sku.ALTERNATE_SKU1 ';
  224. $sql.=' ,sku.Descr_C,FMLotNum,lot.LotAtt05,lot.LotAtt08,lot.LotAtt02,lot.LotAtt04 ';
  225. $sql.=' , storeStatus.QTY, storeStatus.QtyAllocated ';
  226. $sql.=' )result) where rn>0';
  227. $oracleActTransactingLogs1=DB::connection('oracle')->select($sql);
  228. unset($sql);
  229. $sql='select * from (select result.*,rownum rn from (';
  230. $sql.=' select customer.Descr_C 货主, 库位, sku.SKU 产品编码, sku.ALTERNATE_SKU1 产品条码, ';
  231. $sql.=' sku.Descr_C 商品名称, lot.LotAtt05 属性仓, lot.LotAtt08 质量状态, lot.LotAtt02 失效日期, ';
  232. $sql.=' lot.LotAtt04 批号 ';
  233. $sql.=' , sum(移出数量)移出数量, sum(移入数量)移入数量 ';
  234. $sql.=' , storeStatus.QTY 在库数量, storeStatus.QtyAllocated 占用数量,count(1) over () as sum from ';
  235. $sql.=' (select FMLotNum,FMSKU,TOCustomerID,0 as 移出数量, sum(TOQty_Each) as 移入数量, TOLocation as 库位 ';
  236. $sql.=" from ACT_Transaction_Log where TransactionType='PA' ";
  237. if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
  238. if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
  239. if (!$date_start && !$date_end)$sql .= " and addtime >'".date('Y-m-d H:i:s',strtotime("-1 day"))."' ";
  240. $sql.=' group by TOCustomerID, TOLocation, TOCustomerID,FMSKU,FMLotNum union all ';
  241. $sql.=' select FMLotNum,FMSKU,TOCustomerID,sum(FMQty_Each) as 移出数量, 0 as 移入数量, FMLOCATION as 库位 ';
  242. $sql.=" from ACT_Transaction_Log where TransactionType='SO' ";
  243. if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
  244. if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
  245. if (!$date_start && !$date_end)$sql .= " and addtime >'".date('Y-m-d H:i:s',strtotime("-1 day"))."' ";
  246. $sql.=' group by FMCustomerID, FMLocation, TOCustomerID,FMSKU,FMLotNum union all ';
  247. $sql.=' select FMLotNum,FMSKU,TOCustomerID,sum(FMQty_Each) as 移出数量,0 as 移入数量, FMLocation as 库位 ';
  248. $sql.=" from ACT_Transaction_Log where TransactionType='MV' ";
  249. if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
  250. if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
  251. if (!$date_start && !$date_end)$sql .= " and addtime >'".date('Y-m-d H:i:s',strtotime("-1 day"))."' ";
  252. $sql.=' group by FMLocation,TOCustomerID,FMSKU,FMLotNum union all ';
  253. $sql.=' select FMLotNum,FMSKU,TOCustomerID,0 as 移出数量,sum(TOQty_Each)as 移入数量, TOLocation as 库位 ';
  254. $sql.=" from ACT_Transaction_Log where TransactionType='MV' ";
  255. if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
  256. if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
  257. if (!$date_start && !$date_end)$sql .= " and addtime >'".date('Y-m-d H:i:s',strtotime("-1 day"))."' ";
  258. $sql.=' group by TOLocation,TOCustomerID,FMSKU,FMLotNum)stockLog ';
  259. $sql.=' left join BAS_Customer customer on customer.CustomerID=stockLog.TOCUSTOMERID ';
  260. $sql.=' left join BAS_SKU sku on sku.SKU=stockLog.FMSKU ';
  261. $sql.=' left join INV_LOT_ATT lot on lot.LOTNUM=stockLog.FMLOTNUM ';
  262. $sql.=' left join INV_LOT_LOC_ID storeStatus on storeStatus.LOTNUM=stockLog.FMLOTNUM ';;
  263. $sql.=' and storeStatus.LocationID=stockLog.库位 where ROWNUM<=500 ';
  264. $sql.=' group by 库位,customer.Descr_C,sku.SKU,sku.ALTERNATE_SKU1 ';
  265. $sql.=' ,sku.Descr_C,FMLotNum,lot.LotAtt05,lot.LotAtt08,lot.LotAtt02,lot.LotAtt04 ';
  266. $sql.=' , storeStatus.QTY, storeStatus.QtyAllocated ';
  267. $sql.=' )result) where rn>50';
  268. $oracleActTransactingLogs2=DB::connection('oracle')->select($sql);
  269. $oracleActTransactingLogs1=json_encode($oracleActTransactingLogs1);
  270. $oracleActTransactingLogs2=json_encode($oracleActTransactingLogs2);
  271. $oracleActTransactingLogs1=json_decode($oracleActTransactingLogs1,true);
  272. $oracleActTransactingLogs2=json_decode($oracleActTransactingLogs2,true);
  273. foreach ($oracleActTransactingLogs1 as $oracleActTransactingLog1){
  274. foreach ($oracleActTransactingLogs2 as $oracleActTransactingLog2){
  275. if ($oracleActTransactingLog1['产品编码']==$oracleActTransactingLog2['产品编码']){
  276. /*if ($oracleActTransactingLog1['产品编码']=='6206100971005')*/var_dump(['oracleActTransactingLog1'=>$oracleActTransactingLog1,'oracleActTransactingLog2'=>$oracleActTransactingLog2]);
  277. }
  278. }
  279. }
  280. }
  281. }