| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- <?php
- namespace App\Http\Controllers;
- use App\Batch;
- use App\Components\AsyncResponse;
- use App\Components\Database;
- use App\Components\ErrorPush;
- use App\Http\Controllers\api\thirdPart\syrius\units\StorageTypeAttribute;
- use App\Observers\WaybillObserver;
- use App\Order;
- use App\OrderBin;
- use App\RejectedBill;
- use App\Services\RejectedBillService;
- use App\Services\WorkOrderService;
- use App\Waybill;
- use App\WorkOrder;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\DB;
- class TestController extends Controller
- {
- use AsyncResponse, ErrorPush, Database;
- const ASNREFERENCE_2 = 'ASNREFERENCE2';
- public function __construct()
- {
- $this->data["active_test"] = "active";
- }
- public function method(Request $request, $method)
- {
- try {
- return call_user_func([$this, $method], $request);
- }catch (\BadMethodCallException $e){
- dd("方法不存在");
- }
- }
- public function test1(\Closure $c,string $a){
- dd($c($a));
- }
- private function paramDefault(&$waybill):array
- {
- $update = [];
- if (!$waybill->order_type){
- $update["order_type"] = $waybill->order_type = Waybill::ORDER_TYPE_DEFAULT;
- }
- if (!$waybill->transport_type){
- $update["transport_type"] = $waybill->transport_type = "JZKH";
- }
- if (!$waybill->cargo_name){
- $update["cargo_name"] = $waybill->cargo_name = "补货";
- }
- if (!$waybill->total_number){
- $update["total_number"] = $waybill->total_number = 1;
- }
- if (!$waybill->total_weight){
- $update["total_weight"] = $waybill->total_weight = 1;
- }
- if (!$waybill->package_service){
- $update["package_service"] = $waybill->package_service = '托膜';
- }
- if (!$waybill->deliveryType){
- $update["deliveryType_id"] = $waybill->deliveryType_id = 3;
- }
- if (!$waybill->pay_type){
- $update["pay_type"] = $waybill->pay_type = Waybill::PAY_TYPE_DEFAULT;
- }
- if (!$waybill->back_sign_bill){
- $update["back_sign_bill"] = $waybill->back_sign_bill = Waybill::BACK_SIGN_BILL_DEFAULT;
- }
- return $update;
- }
- /**
- * @param Model|\stdClass $waybill
- */
- private function formatWaybillData($waybill):array
- {
- $waybill->loadMissing([
- "order.shop","owner","order.warehouse.province","order.warehouse.city","order.warehouse.county"
- ]);
- $date = date('Y-m-d H:i:s', $waybill->deliver_at ? strtotime($waybill->deliver_at) : now()->getTimestamp());
- $data = [
- 'logisticID' => config('api_logistic.DB.prod.sign').date("YmdHis").mt_rand(1000, 9999).$waybill->order->id,
- 'custOrderNo' => $waybill->order->client_code ?? '',
- 'needTraceInfo' => config('api_logistic.DB.prod.needTraceInfo'),
- 'companyCode' => config('api_logistic.DB.prod.company_code'),
- 'orderType' => $waybill->order_type,
- 'transportType' => $waybill->transport_type,
- 'customerCode' => config('api_logistic.DB.prod.customer_Code'),
- 'sender' => [
- 'companyName' => '宝时物流',
- 'businessNetworkNo' => '',
- 'name' => '宝时物流',
- 'mobile' => '',
- 'phone' => '021-6316561',
- 'province' => $waybill->order->warehouse->province->name ?? '',
- 'city' => $waybill->order->warehouse->city->name ?? '',
- 'country' => $waybill->order->warehouse->county->name ?? '',
- 'town' => '',
- 'address' => $waybill->order->warehouse->address ?? '',
- ],
- 'receiver' => [
- 'toNetworkNo' => '',
- 'name' => $waybill->order->consignee_name ?? '',
- 'phone' => $waybill->order->consignee_phone ?? '',
- 'mobile' => $waybill->order->consignee_phone ?? '',
- 'province' => $waybill->order->province ?? '',
- 'city' => $waybill->order->city ?? "",
- 'county' => $waybill->order->district ?? '',
- 'town' => '',
- 'address' => $waybill->order->address ?? '',
- 'companyName' => ''
- ],
- 'packageInfo' => [
- 'cargoName' => $waybill->cargo_name ?? '',
- 'totalNumber' => $waybill->total_number ?? '',
- 'totalWeight' => $waybill->total_weight ?? '',
- 'totalVolume' => '',
- 'packageService' => $waybill->package_service ?? '',
- 'deliveryType' => $waybill->deliveryType_id,
- ],
- 'gmtCommit' => $date,
- 'payType' => $waybill->pay_type,
- 'addServices' => [
- 'insuranceValue' => '',
- 'codType' => '',
- 'reciveLoanAccount' => '',
- 'accountName' => '',
- 'codValue' => '',
- 'backSignBill' => $waybill->back_sign_bill
- ],
- 'smsNotify' => config('api_logistic.DB.prod.smsNotify'),
- 'sendStartTime' => $date,
- 'sendEndTime' => date('Y-m-d ', $waybill->deliver_at ? strtotime($waybill->deliver_at) : now()->getTimestamp()).'23:59:59',
- 'originalWaybillNumber' => $waybill->wms_bill_number ?? '',
- 'remark' => $waybill->dispatch_remark ?? '',
- 'isOut' => 'N',
- 'passwordSigning' => config('api_logistic.DB.prod.passwordSigning'),
- 'isdispatched' => '',
- 'ispresaleorder'=> '',
- 'isCenterDelivery' => '',
- // 'orderExtendFields' => [
- // 'value' => '',
- // 'key' => ''
- // ]
- ];
- $param = json_encode($data);
- $timestamp = (integer)getMillisecond();
- return ["params"=>$param,"timestamp"=>$timestamp,
- "digest"=>base64_encode(md5($param.config('api_logistic.DB.prod.app_key').$timestamp)),
- "companyCode" => config('api_logistic.DB.prod.company_code')];
- }
- public function test(Request $request)
- {
- $waybill = Waybill::query()->where("waybill_number","BSDB2112284814")
- ->first();
- $waybill->load("order");
- if (!$waybill->order){
- dd("德邦单号获取失败1");
- return;
- }
- $update = $this->paramDefault($waybill);
- $waybill->update($update);
- $bill = app('DbOpenService')->getDbOrderNo($waybill);
- if (!$bill || $bill["result"]=="false"){
- dd($bill);
- return;
- }
- $waybill->update([
- "carrier_bill"=>$bill['mailNo'],
- "waybill_number"=>$bill['mailNo'],
- "station_no"=>$bill['stationNo'],
- "arrived_org_simple_name"=>$bill['arrivedOrgSimpleName'],
- "much_higher_delivery"=>$bill['muchHigherDelivery'],
- ]);
- if (!app("WaybillService")->notifyFlux($waybill)){
- dd("德邦单号回传FLUX失败");
- return;
- }
- dd(1);
- $c = "test";
- $a = function ($b)use($c){
- return $b.$c;
- };
- $this->test1($a,"a");
- dd(2);
- $w = Waybill::query()->get();
- foreach ($w->chunk(50) as $a){
- dd($a);
- }
- $path = '';
- $id = 252;
- $file = fopen($path, "r");
- $user=array();
- $i=0;
- //输出文本中所有的行,直到文件结束为止。
- while(! feof($file)){
- $user[$i]= trim(fgets($file));//fgets()函数从文件指针中读取一行
- $i++;
- }
- fclose($file);
- foreach ($user as $item){
- $arr = explode(",",$item);
- if (count($arr)!=2){
- dump($item);
- continue;
- }
- DB::table("details")->insert([
- "name" => $arr[0],
- "size" => $arr[1],
- "created_at" => date("Y-m-d H:i:s"),
- "updated_at" => date("Y-m-d H:i:s"),
- "header_id" => $id
- ]);
- }
- }
- public function test123(){
- $rejected_bill = RejectedBill::query()->find(2);
- $service = new WorkOrderService();
- $service->syncWorkOrder($rejected_bill);
- }
- public function assignBatch($code)
- {
- $batches = Batch::query()->where("code",$code)->get();
- if (!$batches->count()){
- $wave = DB::connection("oracle")->selectOne(DB::raw("select * from DOC_WAVE_HEADER where WAVENO = ?"),[$code]);
- if (!$wave){
- dd("FLUX无波次");
- }
- $owner = app("OwnerService")->codeGetOwner($wave->customerid);
- $obj = [
- "wms_status" => $this->wms_status($wave),
- "wms_type"=>$wave->descr,
- "created_at"=>date("Y-m-d H:i:s"),
- "wms_created_at"=>$wave->addtime,
- "updated_at"=>$wave->edittime,
- "owner_id"=>$owner->id,
- ];
- $wave = Batch::query()->where("code",$code)->first();
- if (!$wave){
- $obj["code"] = $code;
- $wave = Batch::query()->create($obj);
- }else{
- Batch::query()->where("code",$code)->update($obj);
- }
- $ordernos = array_column(DB::connection("oracle")->select(DB::raw("select orderno from DOC_WAVE_DETAILS where WAVENO = ?"),[$code]),"orderno");
- Order::query()->whereIn("code",$ordernos)->update([
- "batch_id"=>$wave->id
- ]);
- Order::query()->with(["batch","bin"])->whereIn("code",$ordernos)->get()->each(function ($order){
- if (!$order->bin){
- $bin = DB::connection("oracle")->selectOne(DB::raw("select seqno from DOC_WAVE_DETAILS where waveno = ? and orderno = ?"),[$order->batch->code,$order->code]);
- if ($bin){
- OrderBin::query()->create([
- 'order_id' => $order->id,
- 'number' => $bin->seqno,
- ]);
- }
- }
- });
- $batches = Batch::query()->where("code",$code)->get();
- }
- app("BatchService")->assignTasks($batches);
- }
- public function testRequest(Request $request){
- return json_encode($request->header(),JSON_UNESCAPED_UNICODE) ;
- }
- public function syncWorkOrder(){
- WorkOrder::query()
- ->where('work_order_status','1')
- ->where('bao_shi_tag', 1)
- ->update(['bao_shi_tag' => 3]);
- WorkOrder::query()
- ->whereIn('status',[1,4] )
- ->where('work_order_status','<>','1')
- ->update(['bao_shi_tag' => 2]);
- WorkOrder::query()
- ->where('work_order_status','1')
- ->where('owner_tag', 1)
- ->update(['owner_tag' => 3]);
- WorkOrder::query()
- ->whereIn('status',[2,6] )
- ->where('work_order_status','<>','1')
- ->update(['bao_shi_tag' => 2]);
- WorkOrder::query()
- ->where('work_order_status','1')
- ->where('logistic_tag', 1)
- ->update(['logistic_tag' => 3]);
- WorkOrder::query()
- ->whereIn('status',[3] )
- ->where('work_order_status','<>','1')
- ->update(['logistic_tag' => 2]);
- }
- public function baoHandler(){
- // dd(Auth::id());
- $service = new WorkOrderService();
- $service->timingTask();
- }
- }
|