TestController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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\Order;
  10. use App\Package;
  11. use App\Rejected;
  12. use App\RejectedBill;
  13. use App\RejectedBillItem;
  14. use App\Unit;
  15. use App\User;
  16. use App\UserToken;
  17. use App\Waybill;
  18. use App\OraccleBasCustomer;
  19. use App\WMSReflectReceive;
  20. use Carbon\Carbon;
  21. use Endroid\QrCode\Response\QrCodeResponse;
  22. use Illuminate\Http\Request;
  23. use Illuminate\Support\Facades\DB;
  24. use function PHPSTORM_META\map;
  25. use Zttp\Zttp;
  26. class TestController extends Controller
  27. {
  28. private $data=[];
  29. public function __construct()
  30. {
  31. $this->data["active_test"]="active";
  32. }
  33. public function method(Request $request,$method)
  34. {
  35. return call_user_func([$this, $method],$request);
  36. }
  37. function packageFromLog(Request $request){ //x $packagesBatch=Package::where('batch_number',$batch_number)->first();
  38. ini_set('max_execution_time',2500);
  39. ini_set('memory_limit','1526M');
  40. $uploaded=0;
  41. $count=DB::table('logs')->where('operation','like',"%PackageController::new_%" )
  42. ->where('created_at','>',"2020-06-08 15:46:00")
  43. ->where('created_at','<',"2020-06-08 15:47:00")
  44. ->where('type',"request_new_")
  45. ->count();
  46. $requests=DB::table('logs')->where('operation','like',"%PackageController::new_%" )
  47. ->where('created_at','>',"2020-06-08 15:46:00")
  48. ->where('created_at','<',"2020-06-08 15:47:00")
  49. ->where('type',"request_new_")
  50. ->get();
  51. $requests->each(function($request)use(&$uploaded){
  52. $requestJson=json_decode($request->description,true);
  53. $response = Zttp::withHeaders([ 'content-type' => 'application/json',
  54. ])->post('https://was.baoshi56.com/api/thirdPart/flux/package/new',
  55. $requestJson
  56. );
  57. if($response->json()&&$response->json()['response']&&$response->json()['response']['flag']=='Y')
  58. $uploaded+=1;
  59. });
  60. dd($uploaded.'/'.$count);
  61. }
  62. function t2(Request $request){ //x $packagesBatch=Package::where('batch_number',$batch_number)->first();
  63. $uploaded=0;
  64. $count=DB::table('logs')->where('operation','like',"%PackageController::new_%" )
  65. ->where('created_at','>',"2020-06-03 14:02:00")
  66. ->where('created_at','<',"2020-06-03 15:05:00")
  67. ->where('type',"request_new_")
  68. ->where('description','like',"%W200603000117%")
  69. ->count();
  70. $requests=DB::table('logs')->where('operation','like',"%PackageController::new_%" )
  71. ->where('created_at','>',"2020-06-03 14:02:00")
  72. ->where('created_at','<',"2020-06-03 15:05:00")
  73. ->where('description','like',"%W200603000117%")
  74. ->where('type',"request_new_")
  75. ->get();
  76. $requests->each(function($request)use(&$uploaded){
  77. $requestJson=json_decode($request->description,true);
  78. $response = Zttp::withHeaders([ 'content-type' => 'application/json',
  79. ])->post('https://was.baoshi56.com/api/thirdPart/flux/package/new',
  80. $requestJson
  81. );
  82. if($response->json()&&$response->json()['response']&&$response->json()['response']['flag']=='Y')
  83. $uploaded+=1;
  84. });
  85. dd($uploaded.'/'.$count);
  86. }
  87. function tj(Request $request){
  88. $waybills=Waybill::where('created_at','like','%2020-05-25%')->orWhere('created_at','like','%2020-05-30%')->get();
  89. $controller=(new WaybillController());
  90. $waybills->each(function ($waybill)use($controller){
  91. $controller->accomplishToWMS($waybill);
  92. });
  93. dd($waybills->count());
  94. }
  95. function injectJS(Request $request){
  96. $items=RejectedBillItem::whereHas('rejectedBill',function($query){
  97. return $query->where('id_owner',2);
  98. })->where('created_at','>','2019-12-23 18:11:00')->where('created_at','<','2019-12-24 11:25:00')->get();
  99. (new RejectedBillItemController())->collectionsToPackConfirm($items);
  100. }
  101. public function tj2(Request $request)
  102. {
  103. $rejected = Rejected::find(10);
  104. $rejectedJianshang=new \App\Http\Controllers\api\jianshang\RejectedController();
  105. dd( $rejectedJianshang->sendRejected($rejected));
  106. }
  107. public function excelIt()
  108. {
  109. $excel=new ExcelController();
  110. return $excel->makeExcel();
  111. }
  112. public function featureIt()
  113. {
  114. LogisticNumberFeatureController::loadRecentRejectedsToFeatures(5,2500);
  115. }
  116. public function newSku()
  117. {
  118. $url='http://bswcs/api/sorting/flux/newSku';
  119. $response = Zttp::post($url, [
  120. 'request'=>[
  121. [
  122. "SKU"=> "1234567890",
  123. "NAME"=> "瑞士莲**巧克力",
  124. "Alternate_SKU1"=> "1122334455",
  125. "GrossWeight"=> "1.2",
  126. "Cube"=> "0.75",
  127. "SKULength"=> "0.25",
  128. "SKUWidth"=> "0.15",
  129. "SKUHigh"=> "0.05"
  130. ],
  131. [
  132. "SKU"=> "1234567892",
  133. "NAME"=> "跳跳饼",
  134. "Alternate_SKU1"=> "",
  135. "GrossWeight"=> "1.3",
  136. "Cube"=> "0.75",
  137. "SKULength"=> "0.25",
  138. "SKUWidth"=> "0.15",
  139. "SKUHigh"=> "0.25"
  140. ],
  141. ]
  142. ]);
  143. return $response->json();
  144. }
  145. public function changePackage(){
  146. $packages=Package::where('delivery_number','<>',null)->where('logistic_id',null)->get();
  147. dd($packages);
  148. $packages=Package::whereRaw('delivery_number IS NOT NULL AND logistic_id IS NULL')->get();
  149. $logistics=Logistic::get();
  150. $packages->each(function ($package)use($logistics){
  151. $logistics->each(function ($logistic)use($package){
  152. if ($package->WMSReflectPackage->CarrierID==$logistic->code){
  153. $package->logistic_id=$logistic->id;
  154. return;
  155. }
  156. });
  157. });
  158. return "OK";
  159. }
  160. public function tNull(){
  161. }
  162. public function deletePackageAuthority()
  163. {
  164. $authorities=Authority::where('name','like','%包裹信息%')->get();
  165. $authorities->each(function ($authority){
  166. $authority->delete();
  167. });
  168. }
  169. public function test1(){
  170. $waybills=Waybill::select('id','wms_bill_number')->get();
  171. foreach ($waybills as $waybill){
  172. $orders=WMSWaybillOrder::where('OrderNo',$waybill->wms_bill_number)->get();
  173. if (count($orders)>0){
  174. $warehouseWeight=0;
  175. $sign=false;
  176. foreach ($orders as $order){
  177. $warehouseWeight+=$order->Cubic;
  178. if ($order->Cubic==0)$sign=true;
  179. }
  180. if ($sign)unset($warehouseWeight);
  181. }
  182. $waybill=Waybill::find($waybill->id);
  183. if (isset($warehouseWeight)){
  184. if ($waybill){
  185. $waybill->warehouse_weight=$warehouseWeight;
  186. }
  187. }else{
  188. $waybill->warehouse_weight=null;
  189. $waybill->warehouse_weight_unit_id=null;
  190. }
  191. $result+=$temp[$arr[$i]];
  192. if ($sign)$sign=false;
  193. }
  194. if($result<1 || $result>3999)$result=0;
  195. return $result;
  196. }
  197. public function test3()
  198. {
  199. $strs=["auibh","aopk","bikon"];
  200. if (!$strs[0])return "";
  201. $len=strlen($strs[0]);
  202. for ($i=1;$i<count($strs);$i++){
  203. if ($len<1)break;
  204. for ($j=0;$j<$len;$j++){
  205. if ($strs[$i][$j]!=$strs[0][$j]){
  206. if ($j==0)return "";
  207. break;
  208. }
  209. $sum=$j+1;
  210. }
  211. $len=isset($sum)?$sum:0;
  212. }
  213. return substr($strs[0],0,$len);
  214. }
  215. public function test4(){
  216. $s="{([{()()[]{}}])[{()()[}]{}}](){[]}";
  217. $map = [
  218. ")" => "(",
  219. "}" => "{",
  220. "]" => "[",
  221. ];
  222. $len = strlen($s);
  223. $stack = [];
  224. if ($len%2!=0)dd(false);
  225. //s中出现map的key则弹出,没有出现则入栈
  226. for ($i =0; $i<$len; $i++) {
  227. var_dump("data:".$s[$i]);
  228. if (isset($map[$s[$i]])){
  229. //s中出现map的key:如果能找到对应的map的值 (,{,[ 则说明有配对,则弹出
  230. if (isset($stack) && $stack[0] == $map[$s[$i]]) {
  231. array_shift($stack);
  232. } else { //仅找到后面的一部分,说明是不匹配的
  233. dd(false);
  234. }
  235. var_dump("value1:".$map[$s[$i]]);
  236. var_dump($stack);
  237. } else {
  238. array_unshift($stack, $s[$i]);
  239. var_dump("value2:".$s[$i]);
  240. var_dump($stack);
  241. }
  242. }
  243. if (count($stack) > 0) {
  244. dd(false);
  245. }
  246. dd(true);
  247. //利用栈的先进后出 一个正确的括号组对应都为1对1或N对N
  248. // 先进后出“([{”入栈,")]}"出栈,轮询到出栈元素去映射栈顶,符合出栈,不符合直接返回
  249. //依次轮询 如果映射正确那么最后栈为空栈 否则返回false
  250. /*
  251. $r=[];
  252. $sTemp=["("=>1,"["=>2,"{"=>3,")"=>-1,"]"=>-2,"}"=>-3];
  253. for ($i=0;$i<strlen($s);$i++){
  254. if ($i!=strlen($s)-1){
  255. if (($sTemp[$s[$i]]+$sTemp[$s[$i+1]])==0){
  256. $i++;
  257. var_dump($s[$i],$i);
  258. continue;
  259. }
  260. }
  261. array_push($r,$sTemp[$s[$i]]);
  262. }
  263. $sum=count($r);
  264. if ($sum==0)return "a";
  265. if ($sum%2!=0)return "b";
  266. $svg=$sum/2;
  267. for ($i=0;$i<$svg;$i++){
  268. if ($r[$i]>0&&$r[$i]+$r[$sum-1-$i]!=0)return "b";
  269. }
  270. return "a";*/
  271. }
  272. }