TestController.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Authority;
  4. use App\Batch;
  5. use App\City;
  6. use App\Events\CancelOrder;
  7. use App\Events\WmsReceiveNewEvent;
  8. use App\Http\Controllers\Api\thirdPart\flux\WaybillController;
  9. use App\Logistic;
  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\UploadFile;
  17. use App\User;
  18. use App\UserToken;
  19. use App\Waybill;
  20. use App\OraccleBasCustomer;
  21. use App\WMSReflectReceive;
  22. use Carbon\Carbon;
  23. use Endroid\QrCode\Response\QrCodeResponse;
  24. use Illuminate\Http\Request;
  25. use Illuminate\Support\Facades\DB;
  26. use function PHPSTORM_META\map;
  27. use Zttp\Zttp;
  28. class TestController extends Controller
  29. {
  30. private $data = [];
  31. public function __construct()
  32. {
  33. $this->data["active_test"] = "active";
  34. }
  35. public function method(Request $request, $method)
  36. {
  37. return call_user_func([$this, $method], $request);
  38. }
  39. function packageFromLog(Request $request)
  40. { //x $packagesBatch=Package::where('batch_number',$batch_number)->first();
  41. ini_set('max_execution_time', 2500);
  42. ini_set('memory_limit', '1526M');
  43. $uploaded = 0;
  44. $count = DB::table('logs')->where('operation', 'like', "%PackageController::new_%")
  45. ->where('created_at', '>', "2020-06-08 15:46:00")
  46. ->where('created_at', '<', "2020-06-08 15:47:00")
  47. ->where('type', "request_new_")
  48. ->count();
  49. $requests = DB::table('logs')->where('operation', 'like', "%PackageController::new_%")
  50. ->where('created_at', '>', "2020-06-08 15:46:00")
  51. ->where('created_at', '<', "2020-06-08 15:47:00")
  52. ->where('type', "request_new_")
  53. ->get();
  54. $requests->each(function ($request) use (&$uploaded) {
  55. $requestJson = json_decode($request->description, true);
  56. $response = Zttp::withHeaders(['content-type' => 'application/json',
  57. ])->post('https://was.baoshi56.com/api/thirdPart/flux/package/new',
  58. $requestJson
  59. );
  60. if ($response->json() && $response->json()['response'] && $response->json()['response']['flag'] == 'Y')
  61. $uploaded += 1;
  62. });
  63. dd($uploaded . '/' . $count);
  64. }
  65. function t2(Request $request)
  66. { //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 t1(Request $request)
  92. {
  93. $test=new TestController();
  94. dump(method_exists($test,'t1'));
  95. }
  96. function tj(Request $request)
  97. {
  98. $waybills = Waybill::where('created_at', 'like', '%2020-05-25%')->orWhere('created_at', 'like', '%2020-05-30%')->get();
  99. $controller = (new WaybillController());
  100. $waybills->each(function ($waybill) use ($controller) {
  101. $controller->accomplishToWMS($waybill);
  102. });
  103. dd($waybills->count());
  104. }
  105. function injectJS(Request $request)
  106. {
  107. $items = RejectedBillItem::whereHas('rejectedBill', function ($query) {
  108. return $query->where('id_owner', 2);
  109. })->where('created_at', '>', '2019-12-23 18:11:00')->where('created_at', '<', '2019-12-24 11:25:00')->get();
  110. (new RejectedBillItemController())->collectionsToPackConfirm($items);
  111. }
  112. public function tj2(Request $request)
  113. {
  114. $rejected = Rejected::find(10);
  115. $rejectedJianshang = new \App\Http\Controllers\api\jianshang\RejectedController();
  116. dd($rejectedJianshang->sendRejected($rejected));
  117. }
  118. public function excelIt()
  119. {
  120. $excel = new ExcelController();
  121. return $excel->makeExcel();
  122. }
  123. public function featureIt()
  124. {
  125. LogisticNumberFeatureController::loadRecentRejectedsToFeatures(5, 2500);
  126. }
  127. public function newSku()
  128. {
  129. $url = 'http://bswcs/api/sorting/flux/newSku';
  130. $response = Zttp::post($url, [
  131. 'request' => [
  132. [
  133. "SKU" => "1234567890",
  134. "NAME" => "瑞士莲**巧克力",
  135. "Alternate_SKU1" => "1122334455",
  136. "GrossWeight" => "1.2",
  137. "Cube" => "0.75",
  138. "SKULength" => "0.25",
  139. "SKUWidth" => "0.15",
  140. "SKUHigh" => "0.05"
  141. ],
  142. [
  143. "SKU" => "1234567892",
  144. "NAME" => "跳跳饼",
  145. "Alternate_SKU1" => "",
  146. "GrossWeight" => "1.3",
  147. "Cube" => "0.75",
  148. "SKULength" => "0.25",
  149. "SKUWidth" => "0.15",
  150. "SKUHigh" => "0.25"
  151. ],
  152. ]
  153. ]);
  154. return $response->json();
  155. }
  156. public function changePackage()
  157. {
  158. $packages = Package::where('delivery_number', '<>', null)->where('logistic_id', null)->get();
  159. dd($packages);
  160. $packages = Package::whereRaw('delivery_number IS NOT NULL AND logistic_id IS NULL')->get();
  161. $logistics = Logistic::get();
  162. $packages->each(function ($package) use ($logistics) {
  163. $logistics->each(function ($logistic) use ($package) {
  164. if ($package->WMSReflectPackage->CarrierID == $logistic->code) {
  165. $package->logistic_id = $logistic->id;
  166. return;
  167. }
  168. });
  169. });
  170. return "OK";
  171. }
  172. public function tNull()
  173. {
  174. }
  175. public function deletePackageAuthority()
  176. {
  177. $authorities = Authority::where('name', 'like', '%包裹信息%')->get();
  178. $authorities->each(function ($authority) {
  179. $authority->delete();
  180. });
  181. }
  182. /*1*/
  183. function test()
  184. {/**/
  185. $data=[];
  186. $data['destination_city_id']=1;
  187. $data['destination']="陕西省零鲁区鲱鱼大街404号260";
  188. $waybill=Waybill::find(1);
  189. if ($data['destination_city_id'] && $waybill->destination_city_id != $data['destination_city_id']){
  190. $city=City::find($data['destination_city_id']);
  191. if ($city && (mb_strpos($data['destination'],$city->name)===false || mb_strpos($data['destination'],$city->province_name)===false)){
  192. if (mb_strpos($data['destination'],$city->name)===false && mb_strpos($data['destination'],$city->province_name)===false){
  193. $data['destination']=$city->province_name.$city->name.$data['destination'];
  194. goto sign;
  195. }
  196. if (mb_strpos($data['destination'],$city->province_name)===false){
  197. $data['destination']=$city->province_name.$data['destination'];
  198. }
  199. if (mb_strpos($data['destination'],$city->name)===false){var_dump(3);
  200. $province_name=$city->province_name;
  201. $start_index=mb_strpos($data['destination'],$city->province_name.'省');
  202. if ($start_index===false)$start_index=mb_strpos($data['destination'],$city->province_name);
  203. else $province_name=$province_name.'省';
  204. $strBefore=mb_substr($data['destination'],$start_index,mb_strlen($province_name));
  205. $strAfter=mb_substr($data['destination'],$start_index+mb_strlen($province_name));
  206. $data['destination']=$strBefore.$city->name.$strAfter;
  207. }
  208. }
  209. }
  210. sign:
  211. }
  212. }