WaybillController.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Services\CarTypeService;
  4. use App\Services\CityService;
  5. use App\Services\LogisticService;
  6. use App\Services\OwnerService;
  7. use App\Services\UnitService;
  8. use App\Services\WaybillPayoffService;
  9. use App\Services\WaybillPriceModelService;
  10. use App\Services\WaybillService;
  11. use App\UploadFile;
  12. use App\WaybillAuditLog;
  13. use App\WaybillOnTop;
  14. use App\WaybillPriceModel;
  15. use App\City;
  16. use App\Owner;
  17. use App\Unit;
  18. use App\Waybill;
  19. use App\WaybillPayoff;
  20. use App\WaybillFinancialExcepted;
  21. use App\WaybillFinancialSnapshot;
  22. use Carbon\Carbon;
  23. use Exception;
  24. use Illuminate\Database\Eloquent\Builder;
  25. use Illuminate\Database\Eloquent\Collection;
  26. use Illuminate\Http\Request;
  27. use Illuminate\Support\Facades\Auth;
  28. use Illuminate\Support\Facades\DB;
  29. use Illuminate\Support\Facades\Gate;
  30. use Illuminate\Support\Facades\Http;
  31. use Illuminate\Support\Facades\Validator;
  32. use Intervention\Image\Facades\Image;
  33. use Ramsey\Uuid\Uuid;
  34. class WaybillController extends Controller
  35. {
  36. public function __construct()
  37. {
  38. app()->singleton('waybillService',WaybillService::class);
  39. }
  40. /**
  41. * @param Request $request
  42. * @param OwnerService $ownerService
  43. * @param LogisticService $logisticService
  44. * @return void
  45. */
  46. public function index(Request $request,OwnerService $ownerService,LogisticService $logisticService)
  47. {
  48. if(!Gate::allows('运输管理-查询')){ return view("waybill.authorityMenu"); }
  49. $paginateParams = $request->input();
  50. $waybills=app('waybillService')->paginate($request->input());
  51. return view('waybill.index', [
  52. 'waybills' => $waybills,
  53. 'logistics' => $logisticService->getSelection(["id","name"],"物流"),
  54. 'owners' => $ownerService->getIntersectPermitting(),
  55. 'paginateParams'=>$paginateParams,
  56. 'uriType'=>$request->uriType??'']);
  57. }
  58. public function create(Request $request,OwnerService $ownerService)
  59. {
  60. if(!Gate::allows('运输管理-录入')){ return redirect(url('/')); }
  61. $type=$request->type ?? "";
  62. if ($type==='ZF')$type='直发车';
  63. if ($type==='ZX')$type='专线';
  64. return view('waybill.create',['owners'=>$ownerService->getIntersectPermitting(),'type'=>$type]);
  65. }
  66. public function store(Request $request)
  67. {
  68. if(!Gate::allows('运输管理-录入')){ return redirect(url('/')); }
  69. $id=false;
  70. $this->validatorWaybill($request,$id)->validate();
  71. /** @var WaybillService */
  72. $waybill=app('waybillService')->store($request);
  73. app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
  74. return redirect('waybill/index')->with('successTip','新运单“'.$waybill->waybill_number.'”录入成功');
  75. }
  76. public function edit($id,LogisticService $logisticService,CarTypeService $carTypeService,
  77. CityService $cityService,UnitService $unitService)
  78. {
  79. if(!Gate::allows('运输管理-编辑')){ return redirect(url('/')); }
  80. /** @var WaybillService */
  81. $waybill = app('waybillService')->find($id);
  82. if (!$waybill)return view("exception.default",["code"=>"500","message"=>"数据已被删除或丢失"]);
  83. if ($waybill->deliver_at){
  84. $waybill->deliver_at_date=Carbon::parse($waybill->deliver_at)->format('Y-m-d');
  85. $waybill->deliver_at_time=Carbon::parse($waybill->deliver_at)->format('H:i:s');
  86. }
  87. $cities=$cityService->getSelection();
  88. $units=$unitService->getSelection();
  89. $carTypes=$carTypeService->getSelection();
  90. return view('waybill/edit',['waybill'=>$waybill,'logistics'=>$logisticService->getSelection(["id","name"],"物流"),'cities'=>$cities,'units'=>$units,'carTypes'=>$carTypes]);
  91. }
  92. public function update(Request $request, $id,WaybillPriceModelService $waybillPriceModelService,
  93. LogisticService $logisticService,WaybillPayoffService $waybillPayoffService)
  94. {
  95. if(!Gate::allows('运输管理-调度')){ return redirect(url('/')); }
  96. if (!$request->warehouse_weight && $request->warehouse_weight_unit_id){
  97. $request->offsetUnset('warehouse_weight_unit_id');
  98. }
  99. if (!$request->warehouse_weight_other && $request->warehouse_weight_unit_id_other){
  100. $request->offsetUnset('warehouse_weight_unit_id_other');
  101. }
  102. if (!$request->carrier_weight && $request->carrier_weight_unit_id){
  103. $request->offsetUnset('carrier_weight_unit_id');
  104. }
  105. if (!$request->carrier_weight_other && $request->carrier_weight_unit_id_other){
  106. $request->offsetUnset('carrier_weight_unit_id_other');
  107. }
  108. $this->validatorWaybillDispatch($request,$id)->validate();
  109. $waybillPayoffParam = [];
  110. $waybillPayoffParam['total_receivable']=0;
  111. /** @var WaybillService */
  112. $waybill = app('waybillService')->update($request,$id);
  113. if ($waybill->type=="直发车"){
  114. if ($waybill->charge)$waybillPayoffParam['total_receivable'] = ($waybill->charge);
  115. elseif ($waybill->collect_fee)$waybillPayoffParam['total_receivable'] = ($waybill->collect_fee);
  116. $waybillPayoffParam['total_expense'] = ($waybill->fee)+($waybill->other_fee)-($waybill->collect_fee);
  117. }else {
  118. $waybillPriceModel_id=$request->input('waybillPriceModel');
  119. if ($waybillPriceModel_id){
  120. $carrier_weight=$request->input('carrier_weight');
  121. $waybillPriceModel=$waybillPriceModelService->find($waybillPriceModel_id);
  122. $logistic=$logisticService->find($waybill->logistic_id);
  123. if ($carrier_weight<$waybillPriceModel->initial_weight){
  124. $fee=(($waybillPriceModel->unit_price)*($waybillPriceModel->initial_weight))+$logistic->delivery_fee;
  125. }else{
  126. $fee=(($waybillPriceModel->unit_price)*$carrier_weight)+$logistic->delivery_fee;
  127. }
  128. if ($waybillPriceModel->base_fee&&$fee<$waybillPriceModel->base_fee){
  129. $fee=$waybillPriceModel->base_fee;
  130. }
  131. $waybill->fee=$fee;
  132. $waybill->waybill_price_model_id=$waybillPriceModel_id;
  133. }
  134. $waybill->save();
  135. if ($waybill->charge)$waybillPayoffParam['total_receivable'] = ($waybill->charge);
  136. elseif($waybill->collect_fee) {
  137. $waybillPayoffParam['total_receivable'] = $waybill->collect_fee;
  138. }
  139. $waybillPayoffParam['total_expense'] = ($waybill->pick_up_fee)+($waybill->other_fee)+($waybill->fee);
  140. }
  141. if ($waybillPayoffParam['total_receivable'] > 0){
  142. $waybillPayoffParam['waybill_id'] = $id;
  143. $waybillPayoffParam['gross_margin'] = $waybillPayoffParam['total_receivable'] - $waybillPayoffParam['total_expense'];
  144. $waybillPayoffParam['gross_profit_rate'] = $waybillPayoffParam['gross_margin']/$waybillPayoffParam['total_receivable'];
  145. $waybillPayoffService->updateOrCreate($waybillPayoffParam);
  146. }
  147. app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
  148. return redirect('waybill/index')->with('successTip','运单“'.$waybill->waybill_number.'”调度成功');
  149. }
  150. public function checkWaybillPriceModel($logistic_id,$destination_city_id,$carrier_weight,$carrier_weight_unit_id){
  151. //确保承运商计数与计数单位为一个数组且长度2
  152. if(!$logistic_id)return false;
  153. if(!$destination_city_id)return false;
  154. if(!$carrier_weight)return false;
  155. if(!$carrier_weight_unit_id)return false;
  156. //多个计数标准,计算价格,取最贵
  157. if ($carrier_weight[0]&&$carrier_weight[1]&&$carrier_weight_unit_id[0]&&$carrier_weight_unit_id[1]){
  158. //城市价格区间不为空
  159. $waybillPriceModelOne=WaybillPriceModel::query()->where('logistic_id',$logistic_id)->where('city_id',$destination_city_id)
  160. ->where('range_min','<',$carrier_weight[0])->where('range_max','>=',$carrier_weight[0])
  161. ->where('unit_id',$carrier_weight_unit_id[0])->first();
  162. $waybillPriceModelTwo=WaybillPriceModel::query()->where('logistic_id',$logistic_id)->where('city_id',$destination_city_id)
  163. ->where('range_min','<',$carrier_weight[1])->where('range_max','>=',$carrier_weight[1])
  164. ->where('unit_id',$carrier_weight_unit_id[1])->first();
  165. if ($waybillPriceModelOne&&$waybillPriceModelTwo){
  166. if ($waybillPriceModelOne->unit_price*$carrier_weight[0]>=$waybillPriceModelTwo->unit_price*$carrier_weight[1]){
  167. return $waybillPriceModelOne->id;
  168. }else{
  169. return $waybillPriceModelTwo->id;
  170. }
  171. }
  172. if ($waybillPriceModelOne)return $waybillPriceModelOne->id;
  173. if ($waybillPriceModelTwo)return $waybillPriceModelTwo->id;
  174. //价格区间为空
  175. $waybillPriceModelRangeOne=WaybillPriceModel::query()->whereRaw('logistic_id = ? AND city_id = ? AND unit_id = ? AND range_max IS NULL',[$logistic_id,$destination_city_id,$carrier_weight_unit_id[0]])->first();
  176. $waybillPriceModelRangeTwo=WaybillPriceModel::query()->whereRaw('logistic_id = ? AND city_id = ? AND unit_id = ? AND range_max IS NULL',[$logistic_id,$destination_city_id,$carrier_weight_unit_id[1]])->first();
  177. if ($waybillPriceModelRangeOne&&$waybillPriceModelRangeTwo){
  178. if ($waybillPriceModelRangeOne->unit_price*$carrier_weight[0]>=$waybillPriceModelRangeTwo->unit_price*$carrier_weight[1]){
  179. return $waybillPriceModelRangeOne->id;
  180. }else{
  181. return $waybillPriceModelRangeTwo->id;
  182. }
  183. }
  184. if ($waybillPriceModelRangeOne)return $waybillPriceModelRangeOne->id;
  185. if ($waybillPriceModelRangeTwo)return $waybillPriceModelRangeTwo->id;
  186. //城市为空
  187. $city=City::query()->where('id',$destination_city_id)->select('province_id')->first();
  188. $waybillPriceModelProvinceOne=WaybillPriceModel::query()->whereRaw('logistic_id = ? AND province_id = ? AND unit_id = ? AND range_max >= ? AND range_min < ? AND city_id IS NULL',
  189. [$logistic_id,$city->province_id,$carrier_weight_unit_id[0],$carrier_weight[0],$carrier_weight[0]])->first();
  190. $waybillPriceModelProvinceTwo=WaybillPriceModel::query()->whereRaw('logistic_id = ? AND province_id = ? AND unit_id = ? AND range_max >= ? AND range_min < ? AND city_id IS NULL',
  191. [$logistic_id,$city->province_id,$carrier_weight_unit_id[1],$carrier_weight[1],$carrier_weight[1]])->first();
  192. if ($waybillPriceModelProvinceOne&&$waybillPriceModelProvinceTwo){
  193. if ($waybillPriceModelProvinceOne->unit_price*$carrier_weight[0]>=$waybillPriceModelProvinceTwo->unit_price*$carrier_weight[1]){
  194. return $waybillPriceModelProvinceOne->id;
  195. }else{
  196. return $waybillPriceModelProvinceTwo->id;
  197. }
  198. }
  199. if ($waybillPriceModelProvinceOne)return $waybillPriceModelProvinceOne->id;
  200. if ($waybillPriceModelProvinceTwo)return $waybillPriceModelProvinceTwo->id;
  201. //城市价格区间都为空
  202. $waybillPriceModelProvinceRangeOne=WaybillPriceModel::query()->whereRaw('logistic_id = ? AND province_id = ? AND unit_id = ? AND range_max IS NULL AND city_id IS NULL',
  203. [$logistic_id,$city->province_id,$carrier_weight_unit_id[0]])->first();
  204. $waybillPriceModelProvinceRangeTwo=WaybillPriceModel::query()->whereRaw('logistic_id = ? AND province_id = ? AND unit_id = ? AND range_max IS NULL AND city_id IS NULL',
  205. [$logistic_id,$city->province_id,$carrier_weight_unit_id[1]])->first();
  206. if ($waybillPriceModelProvinceRangeOne&&$waybillPriceModelProvinceRangeTwo){
  207. if ($waybillPriceModelProvinceRangeOne->unit_price*$carrier_weight[0]>=$waybillPriceModelProvinceRangeTwo->unit_price*$carrier_weight[1]){
  208. return $waybillPriceModelProvinceRangeOne->id;
  209. }else{
  210. return $waybillPriceModelProvinceRangeOne->id;
  211. }
  212. }
  213. if ($waybillPriceModelProvinceRangeOne)return $waybillPriceModelProvinceRangeOne->id;
  214. if ($waybillPriceModelProvinceRangeTwo)return $waybillPriceModelProvinceRangeTwo->id;
  215. };
  216. for ($i=0;$i<count($carrier_weight);$i++){
  217. if ($carrier_weight[$i]&&$carrier_weight_unit_id[$i]){
  218. //城市价格区间不为空
  219. $waybillPriceModel=WaybillPriceModel::query()->where('logistic_id',$logistic_id)->where('city_id',$destination_city_id)
  220. ->where('range_min','<',$carrier_weight[$i])->where('range_max','>=',$carrier_weight[$i])
  221. ->where('unit_id',$carrier_weight_unit_id[$i])->first();
  222. if($waybillPriceModel)return $waybillPriceModel->id;
  223. //价格区间为空
  224. $waybillPriceModelRange=WaybillPriceModel::query()->whereRaw('logistic_id = ? AND city_id = ? AND unit_id = ? AND range_max IS NULL',[$logistic_id,$destination_city_id,$carrier_weight_unit_id[$i]])->first();
  225. if ($waybillPriceModelRange){ return $waybillPriceModelRange->id;}
  226. //城市为空
  227. $city=City::where('id',$destination_city_id)->select('province_id')->first();
  228. $waybillPriceModelProvince=WaybillPriceModel::query()->whereRaw('logistic_id = ? AND province_id = ? AND unit_id = ? AND range_max >= ? AND range_min < ? AND city_id IS NULL',
  229. [$logistic_id,$city->province_id,$carrier_weight_unit_id[$i],$carrier_weight[$i],$carrier_weight[$i]])->first();
  230. if ($waybillPriceModelProvince){return $waybillPriceModelProvince->id;}
  231. //城市价格区间都为空
  232. $waybillPriceModelProvinceRange=WaybillPriceModel::query()->whereRaw('logistic_id = ? AND province_id = ? AND unit_id = ? AND range_max IS NULL AND city_id IS NULL',
  233. [$logistic_id,$city->province_id,$carrier_weight_unit_id[$i]])->first();
  234. if ($waybillPriceModelProvinceRange){return $waybillPriceModelProvinceRange->id;}
  235. }
  236. }
  237. return false;
  238. }
  239. /*三层条件:无优先级,找到第一个直接返回
  240. * 无论是否为KG||T,计数单位一为KG,计数单位一为T,计数单位二为KG,计数单位二为T
  241. * 计数一与计数二同时存在取最贵价格:
  242. * 计数一存在,二不存在:
  243. * 计数二存在,一不存在:
  244. * 城市价格区间不为空,城市价格区间都为空,城市为空,价格区间为空
  245. * */
  246. public function isWaybillPriceModel(Request $request){
  247. $logistic_id=$request->input('logistic_id');
  248. $destination_city_id=$request->input('destination_city_id');
  249. $carrier_weight=$request->input('carrier_weight');
  250. $carrier_weight_unit_id=$request->input('carrier_weight_unit_id');
  251. $validatorData=["logistic_id"=>$logistic_id,"destination_city_id"=>$destination_city_id,
  252. 'carrier_weight'=>$carrier_weight[0],"carrier_weight_unit_id"=>$carrier_weight_unit_id[0],
  253. "carrier_weight_other"=>$carrier_weight[1],"carrier_weight_unit_id_other"=>$carrier_weight_unit_id[1]];
  254. $errors=Validator::make($validatorData,[
  255. 'logistic_id'=>'required|integer',
  256. 'destination_city_id'=>'required|integer',
  257. 'carrier_weight'=>'nullable|min:0|numeric|max:999999',
  258. 'carrier_weight_unit_id'=>'required_with:carrier_weight',
  259. 'carrier_weight_other'=>'nullable|min:0|numeric|max:999999',
  260. 'carrier_weight_unit_id_other'=>'required_with:carrier_weight_other',
  261. ],[
  262. 'required'=>':attribute 为必填项',
  263. 'max'=>':attribute 字符过多或输入值过大',
  264. 'min'=>':attribute 不得为负',
  265. 'numeric'=>':attribute 应为数字',
  266. 'unique'=>':attribute 已存在',
  267. 'required_with'=>':attribute 未填',
  268. 'integer'=>':attribute 必须为数字',
  269. ],[
  270. 'carrier_weight'=>'承运商计数(抛)',
  271. 'logistic_id'=>'承运商',
  272. 'destination_city_id'=>'目的市',
  273. 'carrier_weight_unit_id'=>'承运商计数单位',
  274. 'carrier_weight_other'=>'承运商计数二',
  275. 'carrier_weight_unit_id_other'=>'承运商计数单位二',
  276. ])->errors();
  277. if (count($errors)>0)return ['error'=>$errors];
  278. $result=$this->checkWaybillPriceModel($logistic_id,$destination_city_id,$carrier_weight,$carrier_weight_unit_id);
  279. if (!$result){
  280. //单位为kg,T时
  281. $unitKG=Unit::query()->where('name','kg')->first();
  282. $unitT=Unit::query()->where('name','T')->first();
  283. if ($carrier_weight_unit_id[0]==$unitKG->id){
  284. $carrier_weight_unit_id[0]=$unitT->id;
  285. $carrier_weight[0]=$carrier_weight[0]/1000;
  286. $result=$this->checkWaybillPriceModel($logistic_id,$destination_city_id,$carrier_weight,$carrier_weight_unit_id);
  287. if ($result)return ['success'=>$result];
  288. }
  289. if ($carrier_weight_unit_id[1]==$unitKG->id){
  290. $carrier_weight_unit_id[1]=$unitT->id;
  291. $carrier_weight[1]=$carrier_weight[1]/1000;
  292. $result=$this->checkWaybillPriceModel($logistic_id,$destination_city_id,$carrier_weight,$carrier_weight_unit_id);
  293. if ($result)return ['success'=>$result];
  294. }
  295. if ($carrier_weight_unit_id[0]==$unitT->id){
  296. $carrier_weight_unit_id[0]=$unitKG->id;
  297. $carrier_weight[0]=$carrier_weight[0]*1000;
  298. $result=$this->checkWaybillPriceModel($logistic_id,$destination_city_id,$carrier_weight,$carrier_weight_unit_id);
  299. if ($result)return ['success'=>$result];
  300. }
  301. if ($carrier_weight_unit_id[1]==$unitT->id){
  302. $carrier_weight_unit_id[1]=$unitKG->id;
  303. $carrier_weight[1]=$carrier_weight[1]*1000;
  304. $result=$this->checkWaybillPriceModel($logistic_id,$destination_city_id,$carrier_weight,$carrier_weight_unit_id);
  305. if ($result)return ['success'=>$result];
  306. }
  307. }
  308. return ['success'=>$result];
  309. }
  310. public function waybillUpdate(Request $request, $id){
  311. if(!Gate::allows('运输管理-编辑')){ return redirect(url('/')); }
  312. $this->validatorWaybill($request,$id)->validate();
  313. $data=$request->input();
  314. $waybill=app('waybillService')->find($id);
  315. $waybill->fill($data);
  316. if ($waybill->save()){
  317. app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($waybill),Auth::user()['id']);
  318. return redirect('waybill/index')->with('successTip','运单“'.$waybill->waybill_number.'”修改成功');
  319. }
  320. }
  321. public function waybillAudit(Request $request){
  322. if(!Gate::allows('运输管理-运单审核')){ return redirect(url('/')); }
  323. $id=$request->input('id');
  324. $waybill=app('waybillService')->find($id);
  325. $isAudit=WaybillAuditLog::whereRaw('waybill_id = ? and audit_stage = ?',[$id,"运单阶段"])->first();
  326. if (empty($isAudit)){
  327. $waybillAuditLog=new WaybillAuditLog([
  328. 'waybill_id'=>$id,
  329. 'audit_stage'=>'运单阶段',
  330. 'user_id'=>Auth::id(),
  331. ]);
  332. $waybillAuditLog->save();
  333. $waybillAuditLog['user']=Auth::user();
  334. $waybill->status='已审核';
  335. $result=$waybill->save();
  336. app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($waybill),Auth::user()['id']);
  337. return ['success'=>$result,'status'=>$waybill->status,'waybillAuditLog'=>$waybillAuditLog];
  338. }
  339. return ['exception'=>'请勿重复审核!'];
  340. }
  341. public function waybillEdit($id){
  342. if(!Gate::allows('运输管理-编辑')){ return redirect(url('/')); }
  343. $waybill=app('waybillService')->find($id);
  344. $owners=Owner::get();
  345. return view('waybill.waybillEdit',['waybill'=>$waybill,'owners'=>$owners]);
  346. }
  347. public function waybillRetreatAudit(Request $request){
  348. if(!Gate::allows('运输管理-调度')){ return redirect(url('/')); }
  349. $id=$request->input('id');
  350. $waybill=app('waybillService')->find($id);
  351. WaybillAuditLog::whereRaw('waybill_id = ? and audit_stage = ?',[$id,"运单阶段"])->delete();
  352. $waybill->status='待重审';
  353. $result=$waybill->save();
  354. app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($waybill),Auth::user()['id']);
  355. return ['success'=>$result,'status'=>$waybill->status];
  356. }
  357. public function waybillEndAudit(Request $request){
  358. if(!Gate::allows('运输管理-调度审核')){ return redirect(url('/')); }
  359. $id=$request->input('id');
  360. $waybill=Waybill::query()->with(["owner","logistic","originationCity","destinationCity","carType",'priceModel',"amountUnit",
  361. "warehouseWeightUnit","carrierWeightUnit","warehouseWeightUnitOther","carrierWeightUnitOther"])->find($id);
  362. if (!$waybill->charge&&!$waybill->collect_fee)return ['exception'=>'收费或到付费用未填!'];
  363. if ($waybill->charge==0&&$waybill->collect_fee==0)return ['exception'=>'收费与到付费用都为0!'];
  364. if ($waybill->type=='专线'){
  365. if (!$waybill->carrier_weight_other||$waybill->carrier_weight_other==0)return ['exception'=>'承运商计重未填或为0!'];
  366. if (!$waybill->carrier_weight_unit_id_other)return ['exception'=>'承运商计重单位未选!'];
  367. }
  368. $isAudit=WaybillAuditLog::query()->whereRaw('waybill_id = ? and audit_stage = ?',[$id,"调度阶段"])->first();
  369. if (empty($isAudit)){
  370. $waybillAuditLog=new WaybillAuditLog([
  371. 'waybill_id'=>$id,
  372. 'audit_stage'=>'调度阶段',
  373. 'user_id'=>Auth::id(),
  374. ]);
  375. $waybillAuditLog->save();
  376. $waybillAuditLog['user']=Auth::user();
  377. if ($waybill->waybill_price_model_id||$waybill->type=='直发车'){
  378. $waybill->status='已完结';
  379. $result=$waybill->save();
  380. $waybillPayoff=WaybillPayoff::query()->where('waybill_id','=',$id)->first();
  381. $waybillPayoffJson=json_encode($this->createReportData($waybill,$waybillPayoff),JSON_UNESCAPED_UNICODE);
  382. WaybillFinancialSnapshot::query()->create([
  383. 'waybill_id'=>$id,
  384. 'json_content'=>$waybillPayoffJson,
  385. ]);
  386. }else{
  387. $waybill->status='无模型';
  388. $result=$waybill->save();
  389. $waybillPayoff=WaybillPayoff::query()->where('waybill_id','=',$id)->first();
  390. if ($waybillPayoff){
  391. $waybillPayoffJson=json_encode($this->createReportData($waybill,$waybillPayoff),JSON_UNESCAPED_UNICODE);
  392. WaybillFinancialExcepted::query()->create([
  393. 'waybill_id'=>$id,
  394. 'json_content'=>$waybillPayoffJson,
  395. ]);
  396. }
  397. }
  398. app('LogService')->log(__METHOD__,__FUNCTION__,$waybillPayoffJson,Auth::id());
  399. return ['success'=>$result,'status'=>$waybill->status,'waybillAuditLog'=>$waybillAuditLog];
  400. }
  401. return ['exception'=>'请勿重复审核!'];
  402. }
  403. //生成报表数据
  404. private function createReportData($waybill,$waybillPayoff){
  405. return [
  406. "type"=>$waybill->type,
  407. "waybill_number"=>$waybill->waybill_number,
  408. "owner_name"=>$waybill->owner ? $waybill->owner->name : null,
  409. "wms_bill_number"=>$waybill->wms_bill_number,
  410. "source_bill"=>$waybill->source_bill,
  411. "origination"=>$waybill->origination,
  412. "destination"=>$waybill->destination,
  413. "recipient"=>$waybill->recipient,
  414. "recipient_mobile"=>$waybill->recipient_mobile,
  415. "charge"=>$waybill->charge,
  416. "collect_fee"=>$waybill->collect_fee,
  417. "ordering_remark"=>$waybill->ordering_remark,
  418. "carrier_name"=>$waybill->logistic ? $waybill->logistic->name : null,
  419. "carrier_bill"=>$waybill->carrier_bill,
  420. "origination_city_name"=>$waybill->originationCity ? $waybill->originationCity->name : null,
  421. "destination_city_name"=>$waybill->destinationCity ? $waybill->destinationCity->name : null,
  422. "warehouse_weight"=>$waybill->warehouse_weight.($waybill->warehouseWeightUnit ? $waybill->warehouseWeightUnit->name : ''),
  423. "carrier_weight"=>$waybill->carrier_weight.($waybill->carrierWeightUnit ? $waybill->carrierWeightUnit->name : ''),
  424. "warehouse_weight_other"=>$waybill->warehouse_weight_other.($waybill->warehouseWeightUnitOther ? $waybill->warehouseWeightUnitOther->name : ''),
  425. "carrier_weight_other"=>$waybill->carrier_weight_other.($waybill->carrierWeightUnitOther ? $waybill->carrierWeightUnitOther->name : ''),
  426. "car_type_name"=>$waybill->carType ? $waybill->carType->name : null,
  427. "fee"=>$waybill->fee,
  428. "pick_up_fee"=>$waybill->pick_up_fee,
  429. "other_fee"=>$waybill->other_fee,
  430. "dispatch_remark"=>$waybill->dispatch_remark,
  431. "price_model_range_min"=>$waybill->priceModel ? $waybill->priceModel->range_min : null,
  432. "price_model_range_max"=>$waybill->priceModel ? $waybill->priceModel->range_max : null,
  433. "price_model_unit_price"=>$waybill->priceModel ? $waybill->priceModel->unit_price : null,
  434. "price_model_base_fee"=>$waybill->priceModel ? $waybill->priceModel->base_fee : null,
  435. "price_model_initial_weight"=>$waybill->priceModel ? $waybill->priceModel->initial_weight : null,
  436. "car_owner_info"=>$waybill->car_owner_info,
  437. "status"=>$waybill->status,
  438. "mileage"=>$waybill->mileage,
  439. 'amount'=>$waybill->amount.($waybill->amountUnit ? $waybill->amountUnit->name : ''),
  440. "inquire_tel"=>$waybill->inquire_tel,
  441. "other_charge"=>$waybill->other_charge,
  442. "other_charge_remark"=>$waybill->other_charge_remark,
  443. "deliver_at"=>$waybill->deliver_at,
  444. "created_at"=>$waybill->created_at,
  445. "auditLog_user_name"=>Auth::user()['name'],
  446. "total_expense"=>$waybillPayoff->total_expense,
  447. "total_receivable"=>$waybillPayoff->total_receivable,
  448. "gross_margin"=>$waybillPayoff->gross_margin,
  449. "gross_profit_rate"=>$waybillPayoff->gross_profit_rate,
  450. ];
  451. }
  452. public function upload(Request $request){
  453. if(!Gate::allows('运输管理-图片上传')){ return '没有权限'; }
  454. $file=$request->file('file');
  455. $waybill_number=$request->input('waybill_number');
  456. $waybill=Waybill::query()->where('waybill_number',$waybill_number)->first();
  457. if (!$waybill){
  458. return ['success'=>false,'error'=>"未找到该运单!"];
  459. }
  460. if ($waybill->upload_file_url){
  461. return ['success'=>false,'error'=>"该运单已存在照片!"];
  462. }
  463. if (!$file){
  464. return ['success'=>false,'error'=>"照片不得为空!"];
  465. }
  466. if (!$file->isValid()){
  467. return ['success'=>false,'error'=>"找不到照片!"];
  468. }
  469. $tmpFile = $file->getRealPath();
  470. if (! is_uploaded_file($tmpFile)) {
  471. return ['success'=>false,'error'=>"文件错误!"];
  472. }
  473. $fileExtension=$file->getClientOriginalExtension();
  474. // 5.存储, 生成一个随机文件名
  475. $fileName = date('ymd').'-'.Uuid::uuid1();//thumbnail common bulky
  476. $thumbnailName=storage_path('app/public/files/'.$fileName.'-thumbnail.'.$fileExtension);
  477. $commonName=storage_path('app/public/files/'.$fileName.'-common.'.$fileExtension);
  478. $bulkyName=storage_path('app/public/files/'.$fileName.'-bulky.'.$fileExtension);
  479. $result=move_uploaded_file ($tmpFile ,$bulkyName);
  480. if ($result){
  481. $img=Image::make($bulkyName);
  482. if ($img->height() > $img->width())
  483. $img->heighten(250)->save($commonName);
  484. else $img->widen(250)->save($commonName);
  485. $img->heighten(28)->save($thumbnailName);
  486. $uploadFile=new UploadFile([
  487. "table_name"=>"waybills",
  488. "table_id"=>$waybill->id,
  489. "url"=>'/files/'.$fileName,
  490. "type"=>$fileExtension,
  491. ]);
  492. if ($uploadFile->save())
  493. app('LogService')->log(__METHOD__,'图片上传',json_encode($request),Auth::user()['id']);
  494. $uploadFile->url=asset('/storage'.$uploadFile->url);
  495. return ['success'=>true,'data'=>$uploadFile];
  496. }
  497. return ['success'=>false,'error'=>"图片保存失败!"];
  498. }
  499. //删除照片
  500. public function deleteImg(Request $request){
  501. if(!Gate::allows('运输管理-图片删除')){ return '没有权限'; }
  502. $ids=$request->input('ids');
  503. $uploadFiles=UploadFile::where('table_name','waybills')->whereIn('table_id',$ids)->get();
  504. foreach ($uploadFiles as $uploadFile){
  505. $bulky=storage_path('app/public/'.$uploadFile->url.'-bulky.'.$uploadFile->type);
  506. $common=storage_path('app/public/'.$uploadFile->url.'-common.'.$uploadFile->type);
  507. $thumbnail=storage_path('app/public/'.$uploadFile->url.'-thumbnail.'.$uploadFile->type);
  508. if (file_exists($bulky) && file_exists($common) && file_exists($thumbnail)){
  509. unlink($bulky);unlink($common);unlink($thumbnail);
  510. }
  511. }
  512. UploadFile::where('table_name','waybills')->whereIn('table_id',$ids)->delete();
  513. app('LogService')->log(__METHOD__,'图片删除',json_encode($request),Auth::user()['id']);
  514. return ['success'=>true];
  515. }
  516. public function export(Request $request){
  517. if(!Gate::allows('运输管理-查询')){ return '没有权限'; }
  518. if ($request->checkAllSign){
  519. $param = $request->input();
  520. unset($param['checkAllSign']);
  521. $sql = app('waybillService')->getSql($param);
  522. }else $sql = app('waybillService')->getSql(['id'=>$request->data]);
  523. $post = Http::post(config('go.export.url'),['type'=>'waybill','sql'=>$sql]);
  524. if ($post->status() == 500){
  525. throw new Exception($post->header("Msg"));
  526. }
  527. return response($post,200, [
  528. "Content-type"=>"application/octet-stream",
  529. "Content-Disposition"=>"attachment; filename=运单列表-".date('ymdHis').'.xlsx',
  530. ]);
  531. }
  532. public function deliveringExport(Request $request){
  533. if ($request->checkAllSign){
  534. $param = $request->input();
  535. unset($param['checkAllSign']);
  536. $sql = app('waybillService')->getDeliveringSql($param);
  537. }else{
  538. $sql = app('waybillService')->getDeliveringSql(['id'=>$request->data]);
  539. }
  540. $post = Http::post(config('go.export.url'),['type'=>'waybillDelivering','sql'=>$sql]);
  541. if ($post->status() == 500){
  542. throw new Exception($post->header("Msg"));
  543. }
  544. return response($post,200, [
  545. "Content-type"=>"application/octet-stream",
  546. "Content-Disposition"=>"attachment; filename=发运列表-".date('ymdHis').'.xlsx',
  547. ]);
  548. }
  549. //发运
  550. public function delivering(Request $request){
  551. if (!Auth::user())return view('exception.login');
  552. $waybills= app('waybillService')->paginate($request->input());
  553. if (!Auth::user()->isSuperAdmin()){
  554. $carriersUsers=DB::table('carrier_user')->where('user_id',Auth::id())->get();
  555. $carrierIds=array_column($carriersUsers->toArray(),'logistic_id');
  556. $waybills=$waybills->whereIn("logistic_id",$carrierIds);
  557. }
  558. return view('waybill.delivering',compact('waybills'));
  559. }
  560. //承运商提交
  561. public function storeCarrierBill(Request $request){
  562. $errors=Validator::make($request->input(),[
  563. 'id'=>'required|integer',
  564. 'carrier_bill'=>'required',
  565. 'inquire_tel'=>'nullable',
  566. 'amount'=>'nullable|integer',
  567. 'carrier_weight'=>'required_without:carrier_weight_other|nullable|numeric',
  568. 'carrier_weight_other'=>'required_without:carrier_weight|nullable|numeric',
  569. ],[
  570. 'required'=>':attribute 为必填项',
  571. 'integer'=>':attribute 应为整数',
  572. 'numeric'=>':attribute 应为数字',
  573. 'required_with'=>':attribute 重量与体积至少存在一项',
  574. ],[
  575. 'carrier_bill'=>'专线运单号',
  576. 'inquire_tel'=>'查件电话',
  577. 'amount'=>'件数',
  578. 'carrier_weight'=>'体积',
  579. 'carrier_weight_other'=>'重量',
  580. ])->errors();
  581. if (count($errors)>0)return ["errors"=>$errors];
  582. $waybill=Waybill::query()->find($request->input('id'));
  583. if (!$waybill)return ["error"=>"未找到该运单!"];
  584. $waybill->fill($request->input());
  585. $waybill->update();
  586. return $waybill;
  587. }
  588. protected function validatorWaybill(Request $request,$id){
  589. if ($id){$wms_bill_number=$id;};
  590. $validator=Validator::make($request->input(),[
  591. 'owner_id'=>'required',
  592. 'wms_bill_number'=>['nullable','max:50',isset($wms_bill_number)?"unique:waybills,wms_bill_number,$wms_bill_number":'unique:waybills,wms_bill_number'],
  593. 'origination'=>'required|max:255',
  594. 'destination'=>'required|max:255',
  595. 'recipient'=>'required|max:50',
  596. 'recipient_mobile'=>['required','regex:/^(\d{7,11})|(1[3|4|5|7|8][0-9]\d{4,8})$/'],
  597. 'charge'=>'nullable|min:0|max:999999|numeric',
  598. 'collect_fee'=>'nullable|min:0|numeric',
  599. ],[
  600. 'required'=>':attribute 为必填项',
  601. 'alpha_num'=>':attribute 应为字母或数字',
  602. 'max'=>':attribute 字符过多或输入值过大',
  603. 'regex'=>':attribute 输入有误',
  604. 'integer'=>':attribute 应为整数',
  605. 'min'=>':attribute 不得为负',
  606. 'numeric'=>':attribute 应为数字',
  607. 'unique'=>':attribute 已存在',
  608. ],[
  609. 'owner_id'=>'货主',
  610. 'wms_bill_number'=>'WMS单号',
  611. 'origination'=>'始发地',
  612. 'destination'=>'目的地',
  613. 'recipient'=>'收件人',
  614. 'recipient_mobile'=>'收件人电话',
  615. 'charge'=>'收费',
  616. 'collect_fee'=>'到付金额',
  617. ]);
  618. return $validator;
  619. }
  620. protected function validatorWaybillDispatch(Request $request,$id){
  621. $rule=[
  622. 'logistic_id'=>'required|integer',
  623. 'carrier_bill'=>"sometimes|nullable|max:50|unique:waybills,carrier_bill,$id",
  624. 'fee'=>'sometimes|nullable|min:0|numeric|max:999999',
  625. 'other_fee'=>'sometimes|nullable|min:0|numeric|max:999999',
  626. 'charge'=>'sometimes|nullable|min:0|numeric|max:999999',
  627. 'mileage'=>'nullable|numeric|min:0',
  628. 'amount'=>'nullable|numeric|min:0',
  629. 'amount_unit_id'=>'required',
  630. 'origination_city_id'=>'sometimes|required|integer',
  631. 'destination_city_id'=>'sometimes|required|integer',
  632. 'warehouse_weight_other'=>'sometimes|nullable|min:0|numeric|max:999999',
  633. 'warehouse_weight_unit_id_other'=>'sometimes|required_with:warehouse_weight_other|nullable|integer',
  634. 'pick_up_fee'=>'sometimes|nullable|min:0|numeric|max:999999',
  635. 'warehouse_weight'=>'sometimes|nullable|min:0|numeric|max:999999',
  636. 'warehouse_weight_unit_id'=>'sometimes|required_with:warehouse_weight|nullable|integer',
  637. 'carrier_weight'=>'sometimes|nullable|min:0|numeric|max:999999',
  638. 'carrier_weight_unit_id'=>'sometimes|required_with:carrier_weight',
  639. 'carrier_weight_other'=>'sometimes|nullable|min:0|numeric|max:999999',
  640. 'carrier_weight_unit_id_other'=>'sometimes|required_with:carrier_weight_other',
  641. ];
  642. if ($request->type == '专线'){
  643. $rule['origination_city_id']='required|integer';
  644. $rule['destination_city_id']='required|integer';
  645. }
  646. $validator=Validator::make($request->input(),$rule,[
  647. 'required'=>':attribute 为必填项',
  648. 'alpha_num'=>':attribute 应为字母或数字',
  649. 'max'=>':attribute 字符过多或输入值过大',
  650. 'min'=>':attribute 不得为负',
  651. 'numeric'=>':attribute 应为数字',
  652. 'unique'=>':attribute 已存在',
  653. 'required_with'=>':attribute 未填',
  654. 'integer'=>':attribute 必须为数字',
  655. ],[
  656. 'logistic_id'=>'承运商',
  657. 'carrier_bill'=>'承运商单号',
  658. 'fee'=>'运费',
  659. 'other_fee'=>'其他费用',
  660. 'charge'=>'收费',
  661. 'mileage'=>'里程数',
  662. 'amount'=>'计数',
  663. 'amount_unit_id'=>'计数单位',
  664. 'warehouse_weight'=>'仓库计数(抛)',
  665. 'carrier_weight'=>'承运商计数(抛)',
  666. 'pick_up_fee'=>'提货费',
  667. 'destination_city_id'=>'目的市',
  668. 'carrier_weight_unit_id'=>'承运商计数单位',
  669. 'warehouse_weight_unit_id'=>'仓库计数单位',
  670. 'warehouse_weight_other'=>'仓库计数二',
  671. 'carrier_weight_other'=>'承运商计数二',
  672. 'warehouse_weight_unit_id_other'=>'仓库技数单位二',
  673. 'carrier_weight_unit_id_other'=>'承运商计数单位二',
  674. ]);
  675. return $validator;
  676. }
  677. public function addCounty(Request $request){
  678. if ($request->destination_city =='undefined')$request->offsetUnset('destination_city');
  679. $rule =[
  680. 'destination_city' => ['required', 'string','unique:cities,name'],
  681. ];
  682. $messages=[
  683. 'destination_city.required'=>'市/县不能为空',
  684. 'destination_city.string'=>'市/县必须是字符串',
  685. 'destination_city.unique'=>'市/县已存在',
  686. ];
  687. $validator = Validator::make($request->all(),$rule,$messages);
  688. if ($validator->fails()) {
  689. return $validator->errors();
  690. }
  691. $city=new City([
  692. 'name'=>$request->input('destination_city'),
  693. 'type'=>3,
  694. ]);
  695. $city->save();
  696. return $city;
  697. }
  698. // 运单删除 软删除
  699. public function destroy(int $id){
  700. if(!GAte::allows('运输管理-删除')){return['success'=>0,'status'=>'没有权限'];}
  701. if(is_null($id)){return ['success'=>'0','status'=>'传入id为空'];}
  702. $result = Waybill::where('id',$id)->delete();
  703. return ['success'=>$result,'status'=>$result];
  704. }
  705. // 回收站
  706. public function recycle(Request $request){
  707. if(!Gate::allows('运输管理-删除')){return redirect('/');}
  708. $paginate = $request->input('paginate')??50;
  709. /** @var Collection $waybills */
  710. $waybills = Waybill::query()->with(['owner','logistic','amountUnit','warehouseWeightUnit','carrierWeightUnit',
  711. 'warehouseWeightUnitOther','carrierWeightUnitOther','carType','waybillAuditLogs' => function ($query) {
  712. /** @var Builder $query */
  713. $query->with('user');
  714. }])->orderBy('deleted_at', 'DESC')->withTrashed()->whereNotNull('deleted_at')->paginate(50);
  715. $total = $waybills->count();
  716. $paginateParams = [];
  717. $paginateParams['paginate'] = $paginate;
  718. return view('waybill.recycle',compact('waybills','total','paginateParams'));
  719. }
  720. // 软删除恢复
  721. public function apiRestoreSelected(Request $request){
  722. if(!Gate::allows('运输管理-删除')){return ['success'=>'false','fail_info'=>'没有权限'];}
  723. $ids = $request->input('ids')??'';
  724. if($ids == ''){return ['success'=>'false','fail_info'=>'没有可恢复对象'];}
  725. $waybills = Waybill::withTrashed()->whereIn('id',$ids)->get();
  726. $waybills->each(function (Waybill $waybill){
  727. $waybill->restore();
  728. });
  729. app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
  730. return ['success'=>'true','waybills'=>$waybills];
  731. }
  732. // 修改运费
  733. public function changeFee(Request $request){
  734. if(!Gate::allows('运输管理-运费')){return ['success'=>'false','fail_info'=>'没有权限'];}
  735. $wayBillId = $request->input('id');
  736. $waybillFee = $request->input('fee');
  737. if(is_null($wayBillId) or is_null($waybillFee)){
  738. return ['success'=>'false','fail_info'=>'参数异常'];
  739. }
  740. $result = Waybill::where('id',$wayBillId)->update(['fee'=>$waybillFee]);
  741. app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
  742. return ['success'=>$result,'status'=>$result];
  743. }
  744. // 修改运输收费
  745. public function changeCharge(Request $request){
  746. if(!Gate::allows('运输管理-运单编辑')){return ['success'=>'false','fail_info'=>'没有权限'];}
  747. $wayBillId = $request->id;
  748. $waybillCharge = $request->input('charge');
  749. if(is_null($wayBillId) or is_null($waybillCharge)){
  750. return ['success'=>'false','fail_info'=>'参数异常'];
  751. }
  752. $result = Waybill::where('id',$wayBillId)->update(['charge'=>$waybillCharge]);
  753. app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
  754. return ['success'=>$result,'status'=>$result];
  755. }
  756. // 置顶
  757. public function waybillOnTop(Request $request){
  758. $id = $request->input('id');
  759. $detail = $request->input('detail');
  760. if(!Gate::allows('运输管理-置顶')){return ['success'=>'false','fail_info'=>'没有权限'];}
  761. if(is_null($id)){
  762. return ['success'=>'false','fail_info'=>'传参错误'];
  763. }
  764. $wayontop = WaybillOnTop::withTrashed()->where('waybill_id',$id);
  765. if(count($wayontop->get()) == 0){
  766. $wayontop = WaybillOnTop::create(['waybill_id'=>$id,'remark'=>$detail]);
  767. $result = $wayontop->save();
  768. }else{
  769. $result = WaybillOnTop::withTrashed()->where('waybill_id',$id)->restore();
  770. }
  771. return ['success'=>$result,'status'=>$result];
  772. }
  773. // 取消置顶
  774. public function cancelOnTop(Request $request){
  775. $id = $request->input('id');
  776. if(!Gate::allows('运输管理-置顶')){return ['success'=>'false','fail_info'=>'没有权限'];}
  777. if(is_null($id)){
  778. return ['success'=>'false','fail_info'=>'传参错误'];
  779. }
  780. $result = WaybillOnTop::where('waybill_id',$id)->forceDelete();
  781. return ['success'=>$result,'status'=>$result];
  782. }
  783. //同步刷新仓库计重
  784. public function refreshWaveHouseWeight(Request $request){
  785. $wms_bill_number=$request->input('wms_bill_number');
  786. if(is_null($wms_bill_number)) return ['success'=>false,'fail_info'=>'传参错误'];
  787. $waybills=DB::connection('oracle')->table('DOC_ORDER_DETAILS')->where('orderno',$wms_bill_number)->get();
  788. if($waybills->isEmpty()) return ['success'=>false,'fail_info'=>'传参错误'];
  789. $warehouseWeight=0;
  790. foreach ($waybills as $waybill){
  791. if ($waybill->grossweight) $warehouseWeight += $waybill->grossweight;
  792. if (!$waybill->grossweight&& $waybill->netweight) $warehouseWeight +=$waybill->netweight;
  793. }
  794. $warehouseWeight=round($warehouseWeight,2);
  795. $waybill=Waybill::where('wms_bill_number',$wms_bill_number)->first();
  796. if ($warehouseWeight!=0){
  797. if ($waybill['warehouse_weight_other']!=$warehouseWeight){
  798. $waybill['warehouse_weight_other']=$warehouseWeight;
  799. $waybill->update();
  800. app('LogService')->log(__METHOD__,'刷新仓库计重'.__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
  801. }
  802. }else{
  803. $warehouseWeight=$waybill['warehouse_weight_other'];
  804. }
  805. return ['success'=>true,'warehouseWeight'=>$warehouseWeight];
  806. }
  807. }