TestController.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 tj(Request $request)
  92. {
  93. $waybills = Waybill::where('created_at', 'like', '%2020-05-25%')->orWhere('created_at', 'like', '%2020-05-30%')->get();
  94. $controller = (new WaybillController());
  95. $waybills->each(function ($waybill) use ($controller) {
  96. $controller->accomplishToWMS($waybill);
  97. });
  98. dd($waybills->count());
  99. }
  100. function injectJS(Request $request)
  101. {
  102. $items = RejectedBillItem::whereHas('rejectedBill', function ($query) {
  103. return $query->where('id_owner', 2);
  104. })->where('created_at', '>', '2019-12-23 18:11:00')->where('created_at', '<', '2019-12-24 11:25:00')->get();
  105. (new RejectedBillItemController())->collectionsToPackConfirm($items);
  106. }
  107. public function tj2(Request $request)
  108. {
  109. $rejected = Rejected::find(10);
  110. $rejectedJianshang = new \App\Http\Controllers\api\jianshang\RejectedController();
  111. dd($rejectedJianshang->sendRejected($rejected));
  112. }
  113. public function excelIt()
  114. {
  115. $excel = new ExcelController();
  116. return $excel->makeExcel();
  117. }
  118. public function featureIt()
  119. {
  120. LogisticNumberFeatureController::loadRecentRejectedsToFeatures(5, 2500);
  121. }
  122. public function newSku()
  123. {
  124. $url = 'http://bswcs/api/sorting/flux/newSku';
  125. $response = Zttp::post($url, [
  126. 'request' => [
  127. [
  128. "SKU" => "1234567890",
  129. "NAME" => "瑞士莲**巧克力",
  130. "Alternate_SKU1" => "1122334455",
  131. "GrossWeight" => "1.2",
  132. "Cube" => "0.75",
  133. "SKULength" => "0.25",
  134. "SKUWidth" => "0.15",
  135. "SKUHigh" => "0.05"
  136. ],
  137. [
  138. "SKU" => "1234567892",
  139. "NAME" => "跳跳饼",
  140. "Alternate_SKU1" => "",
  141. "GrossWeight" => "1.3",
  142. "Cube" => "0.75",
  143. "SKULength" => "0.25",
  144. "SKUWidth" => "0.15",
  145. "SKUHigh" => "0.25"
  146. ],
  147. ]
  148. ]);
  149. return $response->json();
  150. }
  151. public function changePackage()
  152. {
  153. $packages = Package::where('delivery_number', '<>', null)->where('logistic_id', null)->get();
  154. dd($packages);
  155. $packages = Package::whereRaw('delivery_number IS NOT NULL AND logistic_id IS NULL')->get();
  156. $logistics = Logistic::get();
  157. $packages->each(function ($package) use ($logistics) {
  158. $logistics->each(function ($logistic) use ($package) {
  159. if ($package->WMSReflectPackage->CarrierID == $logistic->code) {
  160. $package->logistic_id = $logistic->id;
  161. return;
  162. }
  163. });
  164. });
  165. return "OK";
  166. }
  167. public function tNull()
  168. {
  169. }
  170. public function deletePackageAuthority()
  171. {
  172. $authorities = Authority::where('name', 'like', '%包裹信息%')->get();
  173. $authorities->each(function ($authority) {
  174. $authority->delete();
  175. });
  176. }
  177. /*1*/
  178. function test()
  179. {/**/
  180. $data=[];
  181. $data['destination_city_id']=1;
  182. $data['destination']="陕西省零鲁区鲱鱼大街404号260";
  183. $waybill=Waybill::find(1);
  184. if ($data['destination_city_id'] && $waybill->destination_city_id != $data['destination_city_id']){
  185. $city=City::find($data['destination_city_id']);
  186. if ($city && (mb_strpos($data['destination'],$city->name)===false || mb_strpos($data['destination'],$city->province_name)===false)){
  187. if (mb_strpos($data['destination'],$city->name)===false && mb_strpos($data['destination'],$city->province_name)===false){
  188. $data['destination']=$city->province_name.$city->name.$data['destination'];
  189. goto sign;
  190. }
  191. if (mb_strpos($data['destination'],$city->province_name)===false){
  192. $data['destination']=$city->province_name.$data['destination'];
  193. }
  194. if (mb_strpos($data['destination'],$city->name)===false){var_dump(3);
  195. $province_name=$city->province_name;
  196. $start_index=mb_strpos($data['destination'],$city->province_name.'省');
  197. if ($start_index===false)$start_index=mb_strpos($data['destination'],$city->province_name);
  198. else $province_name=$province_name.'省';
  199. $strBefore=mb_substr($data['destination'],$start_index,mb_strlen($province_name));
  200. $strAfter=mb_substr($data['destination'],$start_index+mb_strlen($province_name));
  201. $data['destination']=$strBefore.$city->name.$strAfter;
  202. }
  203. }
  204. }
  205. sign:
  206. }
  207. }