TestController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Batch;
  4. use App\Components\AsyncResponse;
  5. use App\Components\Database;
  6. use App\Components\ErrorPush;
  7. use App\Http\Controllers\api\thirdPart\syrius\units\StorageTypeAttribute;
  8. use App\Observers\WaybillObserver;
  9. use App\Order;
  10. use App\OrderBin;
  11. use App\RejectedBill;
  12. use App\Services\RejectedBillService;
  13. use App\Services\WorkOrderService;
  14. use App\Waybill;
  15. use App\WorkOrder;
  16. use Illuminate\Database\Eloquent\Model;
  17. use Illuminate\Http\Request;
  18. use Illuminate\Support\Facades\Auth;
  19. use Illuminate\Support\Facades\DB;
  20. class TestController extends Controller
  21. {
  22. use AsyncResponse, ErrorPush, Database;
  23. const ASNREFERENCE_2 = 'ASNREFERENCE2';
  24. public function __construct()
  25. {
  26. $this->data["active_test"] = "active";
  27. }
  28. public function method(Request $request, $method)
  29. {
  30. try {
  31. return call_user_func([$this, $method], $request);
  32. }catch (\BadMethodCallException $e){
  33. dd("方法不存在");
  34. }
  35. }
  36. public function test1(\Closure $c,string $a){
  37. dd($c($a));
  38. }
  39. private function paramDefault(&$waybill):array
  40. {
  41. $update = [];
  42. if (!$waybill->order_type){
  43. $update["order_type"] = $waybill->order_type = Waybill::ORDER_TYPE_DEFAULT;
  44. }
  45. if (!$waybill->transport_type){
  46. $update["transport_type"] = $waybill->transport_type = "JZKH";
  47. }
  48. if (!$waybill->cargo_name){
  49. $update["cargo_name"] = $waybill->cargo_name = "补货";
  50. }
  51. if (!$waybill->total_number){
  52. $update["total_number"] = $waybill->total_number = 1;
  53. }
  54. if (!$waybill->total_weight){
  55. $update["total_weight"] = $waybill->total_weight = 1;
  56. }
  57. if (!$waybill->package_service){
  58. $update["package_service"] = $waybill->package_service = '托膜';
  59. }
  60. if (!$waybill->deliveryType){
  61. $update["deliveryType_id"] = $waybill->deliveryType_id = 3;
  62. }
  63. if (!$waybill->pay_type){
  64. $update["pay_type"] = $waybill->pay_type = Waybill::PAY_TYPE_DEFAULT;
  65. }
  66. if (!$waybill->back_sign_bill){
  67. $update["back_sign_bill"] = $waybill->back_sign_bill = Waybill::BACK_SIGN_BILL_DEFAULT;
  68. }
  69. return $update;
  70. }
  71. /**
  72. * @param Model|\stdClass $waybill
  73. */
  74. private function formatWaybillData($waybill):array
  75. {
  76. $waybill->loadMissing([
  77. "order.shop","owner","order.warehouse.province","order.warehouse.city","order.warehouse.county"
  78. ]);
  79. $date = date('Y-m-d H:i:s', $waybill->deliver_at ? strtotime($waybill->deliver_at) : now()->getTimestamp());
  80. $data = [
  81. 'logisticID' => config('api_logistic.DB.prod.sign').date("YmdHis").mt_rand(1000, 9999).$waybill->order->id,
  82. 'custOrderNo' => $waybill->order->client_code ?? '',
  83. 'needTraceInfo' => config('api_logistic.DB.prod.needTraceInfo'),
  84. 'companyCode' => config('api_logistic.DB.prod.company_code'),
  85. 'orderType' => $waybill->order_type,
  86. 'transportType' => $waybill->transport_type,
  87. 'customerCode' => config('api_logistic.DB.prod.customer_Code'),
  88. 'sender' => [
  89. 'companyName' => '宝时物流',
  90. 'businessNetworkNo' => '',
  91. 'name' => '宝时物流',
  92. 'mobile' => '',
  93. 'phone' => '021-6316561',
  94. 'province' => $waybill->order->warehouse->province->name ?? '',
  95. 'city' => $waybill->order->warehouse->city->name ?? '',
  96. 'country' => $waybill->order->warehouse->county->name ?? '',
  97. 'town' => '',
  98. 'address' => $waybill->order->warehouse->address ?? '',
  99. ],
  100. 'receiver' => [
  101. 'toNetworkNo' => '',
  102. 'name' => $waybill->order->consignee_name ?? '',
  103. 'phone' => $waybill->order->consignee_phone ?? '',
  104. 'mobile' => $waybill->order->consignee_phone ?? '',
  105. 'province' => $waybill->order->province ?? '',
  106. 'city' => $waybill->order->city ?? "",
  107. 'county' => $waybill->order->district ?? '',
  108. 'town' => '',
  109. 'address' => $waybill->order->address ?? '',
  110. 'companyName' => ''
  111. ],
  112. 'packageInfo' => [
  113. 'cargoName' => $waybill->cargo_name ?? '',
  114. 'totalNumber' => $waybill->total_number ?? '',
  115. 'totalWeight' => $waybill->total_weight ?? '',
  116. 'totalVolume' => '',
  117. 'packageService' => $waybill->package_service ?? '',
  118. 'deliveryType' => $waybill->deliveryType_id,
  119. ],
  120. 'gmtCommit' => $date,
  121. 'payType' => $waybill->pay_type,
  122. 'addServices' => [
  123. 'insuranceValue' => '',
  124. 'codType' => '',
  125. 'reciveLoanAccount' => '',
  126. 'accountName' => '',
  127. 'codValue' => '',
  128. 'backSignBill' => $waybill->back_sign_bill
  129. ],
  130. 'smsNotify' => config('api_logistic.DB.prod.smsNotify'),
  131. 'sendStartTime' => $date,
  132. 'sendEndTime' => date('Y-m-d ', $waybill->deliver_at ? strtotime($waybill->deliver_at) : now()->getTimestamp()).'23:59:59',
  133. 'originalWaybillNumber' => $waybill->wms_bill_number ?? '',
  134. 'remark' => $waybill->dispatch_remark ?? '',
  135. 'isOut' => 'N',
  136. 'passwordSigning' => config('api_logistic.DB.prod.passwordSigning'),
  137. 'isdispatched' => '',
  138. 'ispresaleorder'=> '',
  139. 'isCenterDelivery' => '',
  140. // 'orderExtendFields' => [
  141. // 'value' => '',
  142. // 'key' => ''
  143. // ]
  144. ];
  145. $param = json_encode($data);
  146. $timestamp = (integer)getMillisecond();
  147. return ["params"=>$param,"timestamp"=>$timestamp,
  148. "digest"=>base64_encode(md5($param.config('api_logistic.DB.prod.app_key').$timestamp)),
  149. "companyCode" => config('api_logistic.DB.prod.company_code')];
  150. }
  151. public function test(Request $request)
  152. {
  153. $waybill = Waybill::query()->where("waybill_number","BSDB2112284814")
  154. ->first();
  155. $waybill->load("order");
  156. if (!$waybill->order){
  157. dd("德邦单号获取失败1");
  158. return;
  159. }
  160. $update = $this->paramDefault($waybill);
  161. $waybill->update($update);
  162. $bill = app('DbOpenService')->getDbOrderNo($waybill);
  163. if (!$bill || $bill["result"]=="false"){
  164. dd($bill);
  165. return;
  166. }
  167. $waybill->update([
  168. "carrier_bill"=>$bill['mailNo'],
  169. "waybill_number"=>$bill['mailNo'],
  170. "station_no"=>$bill['stationNo'],
  171. "arrived_org_simple_name"=>$bill['arrivedOrgSimpleName'],
  172. "much_higher_delivery"=>$bill['muchHigherDelivery'],
  173. ]);
  174. if (!app("WaybillService")->notifyFlux($waybill)){
  175. dd("德邦单号回传FLUX失败");
  176. return;
  177. }
  178. dd(1);
  179. $c = "test";
  180. $a = function ($b)use($c){
  181. return $b.$c;
  182. };
  183. $this->test1($a,"a");
  184. dd(2);
  185. $w = Waybill::query()->get();
  186. foreach ($w->chunk(50) as $a){
  187. dd($a);
  188. }
  189. $path = '';
  190. $id = 252;
  191. $file = fopen($path, "r");
  192. $user=array();
  193. $i=0;
  194. //输出文本中所有的行,直到文件结束为止。
  195. while(! feof($file)){
  196. $user[$i]= trim(fgets($file));//fgets()函数从文件指针中读取一行
  197. $i++;
  198. }
  199. fclose($file);
  200. foreach ($user as $item){
  201. $arr = explode(",",$item);
  202. if (count($arr)!=2){
  203. dump($item);
  204. continue;
  205. }
  206. DB::table("details")->insert([
  207. "name" => $arr[0],
  208. "size" => $arr[1],
  209. "created_at" => date("Y-m-d H:i:s"),
  210. "updated_at" => date("Y-m-d H:i:s"),
  211. "header_id" => $id
  212. ]);
  213. }
  214. }
  215. public function test123(){
  216. $rejected_bill = RejectedBill::query()->find(2);
  217. $service = new WorkOrderService();
  218. $service->syncWorkOrder($rejected_bill);
  219. }
  220. public function assignBatch($code)
  221. {
  222. $batches = Batch::query()->where("code",$code)->get();
  223. if (!$batches->count()){
  224. $wave = DB::connection("oracle")->selectOne(DB::raw("select * from DOC_WAVE_HEADER where WAVENO = ?"),[$code]);
  225. if (!$wave){
  226. dd("FLUX无波次");
  227. }
  228. $owner = app("OwnerService")->codeGetOwner($wave->customerid);
  229. $obj = [
  230. "wms_status" => $this->wms_status($wave),
  231. "wms_type"=>$wave->descr,
  232. "created_at"=>date("Y-m-d H:i:s"),
  233. "wms_created_at"=>$wave->addtime,
  234. "updated_at"=>$wave->edittime,
  235. "owner_id"=>$owner->id,
  236. ];
  237. $wave = Batch::query()->where("code",$code)->first();
  238. if (!$wave){
  239. $obj["code"] = $code;
  240. $wave = Batch::query()->create($obj);
  241. }else{
  242. Batch::query()->where("code",$code)->update($obj);
  243. }
  244. $ordernos = array_column(DB::connection("oracle")->select(DB::raw("select orderno from DOC_WAVE_DETAILS where WAVENO = ?"),[$code]),"orderno");
  245. Order::query()->whereIn("code",$ordernos)->update([
  246. "batch_id"=>$wave->id
  247. ]);
  248. Order::query()->with(["batch","bin"])->whereIn("code",$ordernos)->get()->each(function ($order){
  249. if (!$order->bin){
  250. $bin = DB::connection("oracle")->selectOne(DB::raw("select seqno from DOC_WAVE_DETAILS where waveno = ? and orderno = ?"),[$order->batch->code,$order->code]);
  251. if ($bin){
  252. OrderBin::query()->create([
  253. 'order_id' => $order->id,
  254. 'number' => $bin->seqno,
  255. ]);
  256. }
  257. }
  258. });
  259. $batches = Batch::query()->where("code",$code)->get();
  260. }
  261. app("BatchService")->assignTasks($batches);
  262. }
  263. public function testRequest(Request $request){
  264. return json_encode($request->header(),JSON_UNESCAPED_UNICODE) ;
  265. }
  266. public function syncWorkOrder(){
  267. WorkOrder::query()
  268. ->where('work_order_status','1')
  269. ->where('bao_shi_tag', 1)
  270. ->update(['bao_shi_tag' => 3]);
  271. WorkOrder::query()
  272. ->whereIn('status',[1,4] )
  273. ->where('work_order_status','<>','1')
  274. ->update(['bao_shi_tag' => 2]);
  275. WorkOrder::query()
  276. ->where('work_order_status','1')
  277. ->where('owner_tag', 1)
  278. ->update(['owner_tag' => 3]);
  279. WorkOrder::query()
  280. ->whereIn('status',[2,6] )
  281. ->where('work_order_status','<>','1')
  282. ->update(['bao_shi_tag' => 2]);
  283. WorkOrder::query()
  284. ->where('work_order_status','1')
  285. ->where('logistic_tag', 1)
  286. ->update(['logistic_tag' => 3]);
  287. WorkOrder::query()
  288. ->whereIn('status',[3] )
  289. ->where('work_order_status','<>','1')
  290. ->update(['logistic_tag' => 2]);
  291. }
  292. public function baoHandler(){
  293. // dd(Auth::id());
  294. $service = new WorkOrderService();
  295. $service->timingTask();
  296. }
  297. }