|
|
@@ -0,0 +1,107 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Http\Controllers\Api;
|
|
|
+
|
|
|
+use App\Unit;
|
|
|
+use App\User;
|
|
|
+use App\Waybill;
|
|
|
+use Illuminate\Http\Request;
|
|
|
+use App\Http\Controllers\Controller;
|
|
|
+use Illuminate\Support\Facades\Auth;
|
|
|
+use Illuminate\Support\Facades\Hash;
|
|
|
+use Illuminate\Support\Facades\Validator;
|
|
|
+
|
|
|
+class WxController extends Controller
|
|
|
+{
|
|
|
+ public function index(Request $request){
|
|
|
+ $carrierArr=[];
|
|
|
+ $carriersName=[];
|
|
|
+ $api_token=$request->input('api_token');
|
|
|
+ $user=User::with('carriers')->where('api_token',$api_token)->first();
|
|
|
+ if ($user){
|
|
|
+ foreach ($user->carriers as $carrier){
|
|
|
+ array_push($carrierArr, $carrier->id);
|
|
|
+ array_push($carriersName, $carrier->name);
|
|
|
+ }
|
|
|
+ $count=Waybill::select('id')->whereIn('carrier_id',$carrierArr)->whereDate('created_at',date("Y-m-d "))->count();
|
|
|
+ $waybill=Waybill::orderBy('created_at','DESC')->select('created_at','waybill_number','wms_bill_number','carrier_bill')
|
|
|
+ ->whereIn('carrier_id',$carrierArr)->where('status','!=','已完结')->where('status','!=','无模型')->get();
|
|
|
+ return ['waybill'=>$waybill,'carriersName'=>$carriersName,'count'=>$count];
|
|
|
+ }
|
|
|
+ return ['exception'=>'出错了!'];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function show(Request $request){
|
|
|
+ $units_name=[];
|
|
|
+ $waybill_number=$request->input('waybill_number');
|
|
|
+ $waybill=Waybill::select('id','waybill_number','wms_bill_number','owner_id','origination','destination','recipient','recipient_mobile',
|
|
|
+ 'carrier_weight','carrier_weight_unit_id','carrier_weight_other','carrier_weight_unit_id_other','pick_up_fee','carrier_bill')
|
|
|
+ ->where('waybill_number',$waybill_number)->first();
|
|
|
+ $units=Unit::select('name')->get();
|
|
|
+ foreach ($units as $unit){
|
|
|
+ array_push($units_name, $unit->name);
|
|
|
+ }
|
|
|
+ return ['waybill'=>$waybill,'units_name'=>$units_name];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function update(Request $request){
|
|
|
+ $id=$request->input('id');
|
|
|
+ $validator=Validator::make($request->input(),[
|
|
|
+ 'carrier_bill'=>"required|max:50|unique:waybills,carrier_bill,$id",
|
|
|
+ 'pick_up_fee'=>'nullable|min:0|numeric|max:999999',
|
|
|
+ 'carrier_weight'=>'required|min:0|numeric|max:999999',
|
|
|
+ 'carrier_weight_unit_name'=>'required_with:carrier_weight',
|
|
|
+ 'carrier_weight_other'=>'nullable|min:0|numeric|max:999999',
|
|
|
+ 'carrier_weight_unit_other_name'=>'required_with:carrier_weight_other',
|
|
|
+ ],[
|
|
|
+ 'required'=>':attribute 为必填项',
|
|
|
+ 'alpha_num'=>':attribute 应为字母或数字',
|
|
|
+ 'max'=>':attribute 字符过多或输入值过大',
|
|
|
+ 'min'=>':attribute 不得为负',
|
|
|
+ 'numeric'=>':attribute 应为数字',
|
|
|
+ 'unique'=>':attribute 已存在',
|
|
|
+ 'required_with'=>':attribute 未填',
|
|
|
+ ],[
|
|
|
+ 'carrier_bill'=>'承运商单号',
|
|
|
+ 'pick_up_fee'=>'提货费',
|
|
|
+ 'carrier_weight'=>'计数一',
|
|
|
+ 'carrier_weight_unit_id'=>'计数单位一',
|
|
|
+ 'carrier_weight_other'=>'计数二',
|
|
|
+ 'carrier_weight_unit_other_name'=>'计数单位二',
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ //将返回错误循环组装成字符串
|
|
|
+ $arr = [];
|
|
|
+ foreach ($validator->getMessageBag()->toArray() as $k=>$error){
|
|
|
+ array_push($arr, $error[0]);
|
|
|
+ }
|
|
|
+ return [
|
|
|
+ 'success' => false,
|
|
|
+ 'errors' => $arr
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $unit=Unit::where('name',$request->input('carrier_weight_unit_name'))->first();
|
|
|
+ $unit_other=Unit::where('name',$request->input('carrier_weight_unit_other_name'))->first();
|
|
|
+ $waybill=Waybill::find($id);
|
|
|
+ $carrier_bill=$request->input('carrier_bill');
|
|
|
+ $pick_up_fee=$request->input('pick_up_fee');
|
|
|
+ $carrier_weight=$request->input('carrier_weight');
|
|
|
+ $carrier_weight_unit_id=$unit->id;
|
|
|
+ $carrier_weight_other=$request->input('carrier_weight_other');
|
|
|
+ if ($unit_other){
|
|
|
+ $carrier_weight_unit_id_other=$unit_other->id;
|
|
|
+ $waybill->carrier_weight_unit_id_other=$carrier_weight_unit_id_other;
|
|
|
+ }
|
|
|
+ $waybill->carrier_bill=$carrier_bill;
|
|
|
+ if($pick_up_fee)$waybill->pick_up_fee=$pick_up_fee;
|
|
|
+ $waybill->carrier_weight=$carrier_weight;
|
|
|
+ $waybill->carrier_weight_unit_id=$carrier_weight_unit_id;
|
|
|
+ $waybill->carrier_weight_other=$carrier_weight_other;
|
|
|
+
|
|
|
+ if ($waybill->save()){
|
|
|
+ $this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
|
|
|
+ return ['success'=>true];
|
|
|
+ }
|
|
|
+ else return ['success'=>false];
|
|
|
+ }
|
|
|
+}
|