TestController.php 10 KB

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