WaybillsController.php 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Http\Controllers\Api\thirdPart\flux\WaybillController;
  4. use App\User;
  5. use App\WaybillAuditLog;
  6. use App\WaybillPriceModel;
  7. use App\Carrier;
  8. use App\CarType;
  9. use App\City;
  10. use App\Exports\Export;
  11. use App\Owner;
  12. use App\Unit;
  13. use App\Waybill;
  14. use App\WaybillPayoff;
  15. use App\WaybillFinancialExcepted;
  16. use App\WaybillFinancialSnapshot;
  17. use Carbon\Carbon;
  18. use Illuminate\Http\Request;
  19. use Illuminate\Support\Facades\Auth;
  20. use Illuminate\Support\Facades\DB;
  21. use Illuminate\Support\Facades\Gate;
  22. use Illuminate\Support\Facades\Validator;
  23. use Maatwebsite\Excel\Facades\Excel;
  24. use Ramsey\Uuid\Uuid;
  25. class WaybillsController extends Controller
  26. {
  27. //超15天精确查询抽离 column前提:数据库字段名必须与request内字段名一致
  28. public function preciseQuery(string $column,Request $request,$waybills){
  29. $today=Carbon::now()->subDays(15);
  30. $waybillsTem=clone $waybills;
  31. $waybillsTem=$waybillsTem->where($column,'like','%'.$request->input($column).'%')->where('created_at','>',$today->format('Y-m-d'));
  32. if($waybillsTem->count()==0
  33. ||$waybillsTem->first()[$column]==$request->input($column)){
  34. $waybills=$waybills->where($column,$request->input($column));
  35. }else{
  36. $waybills=$waybillsTem;
  37. }
  38. return $waybills;
  39. }
  40. public function conditionQuery(Request $request,$waybills){
  41. if ($request->input('exportType')&&$request->input('exportType')==1){
  42. $checkData=explode(',',$request->input('checkData'));
  43. $waybills=$waybills->whereIn("id",$checkData)->get();
  44. $excel=$this->deliveringExport($waybills);
  45. return $excel;
  46. }
  47. if ($request->input('waybill_number')){
  48. $waybills=$this->preciseQuery("waybill_number",$request,$waybills);
  49. }
  50. if ($request->input('carrier_bill')){
  51. $waybills=$this->preciseQuery("carrier_bill",$request,$waybills);
  52. }
  53. if ($request->input('carrier_id')){
  54. $waybills=$waybills->where('carrier_id','=',$request->input('carrier_id'));
  55. }
  56. if ($request->input('owners')){
  57. $owners=array_values(json_decode($request->input('owners'),true));
  58. $waybills=$waybills->whereIn('owner_id',$owners);
  59. }
  60. if ($request->input('owner_id')){
  61. $waybills=$waybills->where('owner_id','=',$request->input('owner_id'));
  62. }
  63. if ($request->input('wms_bill_number')){
  64. $waybills=$this->preciseQuery("wms_bill_number",$request,$waybills);
  65. }
  66. if ($request->input('origination')){
  67. $waybills=$this->preciseQuery("origination",$request,$waybills);
  68. }
  69. if ($request->input('destination')){
  70. $waybills=$this->preciseQuery("destination",$request,$waybills);
  71. }
  72. if ($request->input('created_at_start')){
  73. $created_at_start=$request->input('created_at_start')." 00:00:00";
  74. $waybills=$waybills->where('created_at','>=',$created_at_start);
  75. }
  76. if ($request->input('created_at_end')){
  77. $created_at_end=$request->input('created_at_end')." 23:59:59";
  78. $waybills=$waybills->where('created_at','<=',$created_at_end);
  79. }
  80. if ($request->input('status')){
  81. $waybills=$waybills->where('status',$request->input('status'));
  82. }
  83. if ($request->input('exportType')&&$request->input('exportType')==2){
  84. $waybills=$waybills->get();
  85. $excel=$this->deliveringExport($waybills);
  86. return $excel;
  87. }
  88. else $waybills=$waybills->paginate($request->input('paginate')?$request->input('paginate'):50);
  89. if (!$waybills&&$request->input('waybill_number')){
  90. $waybills=Waybill::with(['owner', 'waybillAuditLogs' => function ($query) {
  91. return $query->with('user');
  92. }])->orderBy('id','DESC')->where('type','专线')->where('waybill_number',$request->input('waybill_number'))
  93. ->paginate($request->input('paginate')?$request->input('paginate'):50);
  94. }
  95. return $waybills;
  96. }
  97. public function index(Request $request)
  98. {
  99. if(!Gate::allows('运输管理-查询')){ return redirect(url('/')); }
  100. $data=$request->input();
  101. if ($data != null ) {
  102. $waybills=Waybill::with(['owner','wmsCommodities','waybillAuditLogs' => function ($query) {
  103. return $query->with('user');
  104. }])->orderBy('id','DESC');
  105. $waybills=$this->conditionQuery($request,$waybills);
  106. $carries = Carrier::get();
  107. $owners = Owner::get();
  108. return view('waybill.index', ['waybills' => $waybills, 'carriers' => $carries, 'owners' => $owners,'filterData'=>$data,'uriType'=>'']);
  109. } else {
  110. $waybills = Waybill::with(['owner','waybillAuditLogs' => function ($query) {
  111. return $query->with('user');
  112. }])->orderBy('id', 'DESC')->paginate(50);
  113. $carries = Carrier::get();
  114. $owners = Owner::get();
  115. return view('waybill.index', ['waybills' => $waybills, 'carriers' => $carries, 'owners' => $owners,'filterData'=>$data,'uriType'=>'']);
  116. }
  117. }
  118. public function indexZF(Request $request){
  119. if(!Gate::allows('运输管理-查询')){ return redirect(url('/')); }
  120. $data=$request->input();
  121. if ($data != null ) {
  122. $waybills=Waybill::with(['owner','wmsCommodities', 'waybillAuditLogs' => function ($query) {
  123. return $query->with('user');
  124. }])->orderBy('id','DESC')->where('type','直发车');
  125. $waybills=$this->conditionQuery($request,$waybills);
  126. $carries = Carrier::get();
  127. $owners = Owner::get();
  128. return view('waybill.index', ['waybills' => $waybills, 'carriers' => $carries, 'owners' => $owners,'filterData'=>$data,'uriType'=>'ZF']);
  129. } else {
  130. $waybills = Waybill::with(['owner','wmsCommodities', 'waybillAuditLogs' => function ($query) {
  131. return $query->with('user');
  132. }])->where('type','直发车')->orderBy('id', 'DESC')->paginate(50);
  133. $carries = Carrier::get();
  134. $owners = Owner::get();
  135. return view('waybill.index', ['waybills' => $waybills, 'carriers' => $carries, 'owners' => $owners,'filterData'=>$data,'uriType'=>'ZF']);
  136. }
  137. }
  138. public function indexZX(Request $request){
  139. if(!Gate::allows('运输管理-查询')){ return redirect(url('/')); }
  140. $data=$request->input();
  141. if ($data != null ) {
  142. $waybills=Waybill::with(['owner','wmsCommodities', 'waybillAuditLogs' => function ($query) {
  143. return $query->with('user');
  144. }])->orderBy('id','DESC')->where('type','专线');
  145. $waybills=$this->conditionQuery($request,$waybills);
  146. $carries = Carrier::get();
  147. $owners = Owner::get();
  148. return view('waybill.index', ['waybills' => $waybills, 'carriers' => $carries, 'owners' => $owners,'filterData'=>$data,'uriType'=>'ZX']);
  149. } else {
  150. $waybills = Waybill::with(['owner','wmsCommodities', 'waybillAuditLogs' => function ($query) {
  151. return $query->with('user');
  152. }])->where('type','专线')->orderBy('id', 'DESC')->paginate(50);
  153. $carries = Carrier::get();
  154. $owners = Owner::get();
  155. return view('waybill.index', ['waybills' => $waybills, 'carriers' => $carries, 'owners' => $owners,'filterData'=>$data,'uriType'=>'ZX']);
  156. }
  157. }
  158. public function create()
  159. {
  160. if(!Gate::allows('运输管理-录入')){ return redirect(url('/')); }
  161. $owners=Owner::get();
  162. return view('waybill.create',['owners'=>$owners]);
  163. }
  164. public function createZF()
  165. {
  166. if(!Gate::allows('运输管理-录入')){ return redirect(url('/')); }
  167. $owners=Owner::get();
  168. return view('waybill.create',['owners'=>$owners,'type'=>'直发车']);
  169. }
  170. public function createZX()
  171. {
  172. if(!Gate::allows('运输管理-录入')){ return redirect(url('/')); }
  173. $owners=Owner::get();
  174. return view('waybill.create',['owners'=>$owners,'type'=>'专线']);
  175. }
  176. public function store(Request $request)
  177. {
  178. if(!Gate::allows('运输管理-录入')){ return redirect(url('/')); }
  179. $id=false;
  180. $this->validatorWaybill($request,$id)->validate();
  181. $data=$request->input();
  182. $waybill=new Waybill([
  183. 'type'=>$data['type'],
  184. 'status'=>'未审核',
  185. 'waybill_number'=>Uuid::uuid1(),
  186. 'owner_id'=>$data['owner_id'],
  187. 'wms_bill_number'=>$data['wms_bill_number'],
  188. 'origination'=>$data['origination'],
  189. 'destination'=>$data['destination'],
  190. 'recipient'=>$data['recipient'],
  191. 'recipient_mobile'=>$data['recipient_mobile'],
  192. 'charge'=>$data['charge'],
  193. 'ordering_remark'=>$data['ordering_remark']
  194. ]);
  195. if (isset($data['collect_fee'])&&$data['collect_fee']>0)$waybill->collect_fee=$data['collect_fee'];
  196. $waybill->save();
  197. $number_id=$waybill->id;
  198. if ($data['type']=='直发车'){
  199. $waybill_number='BSZF'.date ("ymd").str_pad($number_id>99999?$number_id%99999:$number_id,4,"0",STR_PAD_LEFT);
  200. $waybill->waybill_number=$waybill_number;
  201. $waybill->update();
  202. }else{
  203. $waybill_number='BSZX'.date ("ymd").str_pad($number_id>99999?$number_id%99999:$number_id,4,"0",STR_PAD_LEFT);
  204. $waybill->waybill_number=$waybill_number;
  205. $waybill->update();
  206. }
  207. $this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
  208. return redirect('waybill/index')->with('successTip','新运单“'.$waybill_number.'”录入成功');
  209. }
  210. public function edit($id)
  211. {
  212. if(!Gate::allows('运输管理-编辑')){ return redirect(url('/')); }
  213. $waybill=Waybill::find($id);
  214. $carriers=Carrier::get();
  215. $cities=City::get();
  216. $units=Unit::get();
  217. $carTypes=CarType::get();
  218. return view('waybill/edit',['waybill'=>$waybill,'carriers'=>$carriers,'cities'=>$cities,'units'=>$units,'carTypes'=>$carTypes]);
  219. }
  220. public function update(Request $request, $id)
  221. {
  222. if(!Gate::allows('运输管理-调度')){ return redirect(url('/')); }
  223. $waybill=Waybill::find($id);
  224. if (!$waybill['warehouse_weight']&&$waybill['warehouse_weight_unit_id']){
  225. unset($waybill['warehouse_weight_unit_id']);
  226. }
  227. if (!$waybill['warehouse_weight_other']&&$waybill['warehouse_weight_unit_id_other']){
  228. unset($waybill['warehouse_weight_unit_id_other']);
  229. }
  230. if (!$waybill['carrier_weight']&&$waybill['carrier_weight_unit_id']){
  231. unset($waybill['carrier_weight_unit_id']);
  232. }
  233. if (!$waybill['carrier_weight_other']&&$waybill['carrier_weight_unit_id_other']){
  234. unset($waybill['carrier_weight_unit_id_other']);
  235. }
  236. $this->validatorWaybillDispatch($request,$id)->validate();
  237. $data=$request->input();
  238. $total_receivable=0;
  239. $waybill->fill($data);
  240. if ($waybill->save()){
  241. if ($waybill->type=="直发车"){
  242. if ($waybill->charge)$total_receivable=($waybill->charge);
  243. elseif ($waybill->collect_fee)$total_receivable=($waybill->collect_fee);
  244. $total_expense=($waybill->fee)+($waybill->other_fee)-($waybill->collect_fee);
  245. }else {
  246. $waybillPriceModel_id=$request->input('waybillPriceModel');
  247. if ($waybillPriceModel_id){
  248. $carrier_weight=$request->input('carrier_weight');
  249. $waybillPriceModel=WaybillPriceModel::find($waybillPriceModel_id);
  250. $carrier=Carrier::find($waybill->carrier_id);
  251. if ($carrier_weight<$waybillPriceModel->initial_weight){
  252. $fee=(($waybillPriceModel->unit_price)*($waybillPriceModel->initial_weight))+$carrier->delivery_fee;
  253. }else{
  254. $fee=(($waybillPriceModel->unit_price)*$carrier_weight)+$carrier->delivery_fee;
  255. }
  256. if ($waybillPriceModel->base_fee&&$fee<$waybillPriceModel->base_fee){
  257. $fee=$waybillPriceModel->base_fee;
  258. }
  259. $waybill->fee=$fee;
  260. $waybill->waybill_price_model_id=$waybillPriceModel_id;
  261. }
  262. $waybill->save();
  263. if ($waybill->charge)$total_receivable=($waybill->charge);
  264. elseif($waybill->collect_fee) {
  265. $total_receivable=($waybill->collect_fee);
  266. }
  267. $total_expense=($waybill->pick_up_fee)+($waybill->other_fee)+($waybill->fee);
  268. }
  269. if ($total_receivable>0){
  270. $waybillPayoff=WaybillPayoff::where('waybill_id','=',$id)->first();
  271. if ($waybillPayoff){
  272. $waybillPayoff->waybill_id=$id;
  273. $waybillPayoff->total_expense=$total_expense;
  274. $waybillPayoff->total_receivable=$total_receivable;
  275. $waybillPayoff->gross_margin=$total_receivable-$total_expense;
  276. $waybillPayoff->gross_profit_rate=(($total_receivable-$total_expense)/$total_receivable);
  277. $waybillPayoff->save();
  278. }else{
  279. WaybillPayoff::create([
  280. 'waybill_id'=>$id,
  281. 'total_expense'=>$total_expense,
  282. 'total_receivable'=>$total_receivable,
  283. 'gross_margin'=>$total_receivable-$total_expense,
  284. 'gross_profit_rate'=>(($total_receivable-$total_expense)/$total_receivable),
  285. ]);
  286. };
  287. }
  288. $this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
  289. return redirect('waybill/index')->with('successTip','运单“'.$waybill->waybill_number.'”调度成功');
  290. }
  291. }
  292. public function checkWaybillPriceModel($carrier_id,$destination_city_id,$carrier_weight,$carrier_weight_unit_id){
  293. //确保承运商计数与计数单位为一个数组且长度2
  294. if(!$carrier_id)return false;
  295. if(!$destination_city_id)return false;
  296. if(!$carrier_weight)return false;
  297. if(!$carrier_weight_unit_id)return false;
  298. //多个计数标准,计算价格,取最贵
  299. if ($carrier_weight[0]&&$carrier_weight[1]&&$carrier_weight_unit_id[0]&&$carrier_weight_unit_id[1]){
  300. //城市价格区间不为空
  301. $waybillPriceModelOne=WaybillPriceModel::where('carrier_id',$carrier_id)->where('city_id',$destination_city_id)
  302. ->where('range_min','<',$carrier_weight[0])->where('range_max','>=',$carrier_weight[0])
  303. ->where('unit_id',$carrier_weight_unit_id[0])->first();
  304. $waybillPriceModelTwo=WaybillPriceModel::where('carrier_id',$carrier_id)->where('city_id',$destination_city_id)
  305. ->where('range_min','<',$carrier_weight[1])->where('range_max','>=',$carrier_weight[1])
  306. ->where('unit_id',$carrier_weight_unit_id[1])->first();
  307. if ($waybillPriceModelOne&&$waybillPriceModelTwo){
  308. if ($waybillPriceModelOne->unit_price*$carrier_weight[0]>=$waybillPriceModelTwo->unit_price*$carrier_weight[1]){
  309. return $waybillPriceModelOne->id;
  310. }else{
  311. return $waybillPriceModelTwo->id;
  312. }
  313. }
  314. if ($waybillPriceModelOne)return $waybillPriceModelOne->id;
  315. if ($waybillPriceModelTwo)return $waybillPriceModelTwo->id;
  316. //价格区间为空
  317. $waybillPriceModelRangeOne=WaybillPriceModel::whereRaw('carrier_id = ? AND city_id = ? AND unit_id = ? AND range_max IS NULL',[$carrier_id,$destination_city_id,$carrier_weight_unit_id[0]])->first();
  318. $waybillPriceModelRangeTwo=WaybillPriceModel::whereRaw('carrier_id = ? AND city_id = ? AND unit_id = ? AND range_max IS NULL',[$carrier_id,$destination_city_id,$carrier_weight_unit_id[1]])->first();
  319. if ($waybillPriceModelRangeOne&&$waybillPriceModelRangeTwo){
  320. if ($waybillPriceModelRangeOne->unit_price*$carrier_weight[0]>=$waybillPriceModelRangeTwo->unit_price*$carrier_weight[1]){
  321. return $waybillPriceModelRangeOne->id;
  322. }else{
  323. return $waybillPriceModelRangeTwo->id;
  324. }
  325. }
  326. if ($waybillPriceModelRangeOne)return $waybillPriceModelRangeOne->id;
  327. if ($waybillPriceModelRangeTwo)return $waybillPriceModelRangeTwo->id;
  328. //城市为空
  329. $city=City::where('id',$destination_city_id)->select('province_id')->first();
  330. $waybillPriceModelProvinceOne=WaybillPriceModel::whereRaw('carrier_id = ? AND province_id = ? AND unit_id = ? AND range_max >= ? AND range_min < ? AND city_id IS NULL',
  331. [$carrier_id,$city->province_id,$carrier_weight_unit_id[0],$carrier_weight[0],$carrier_weight[0]])->first();
  332. $waybillPriceModelProvinceTwo=WaybillPriceModel::whereRaw('carrier_id = ? AND province_id = ? AND unit_id = ? AND range_max >= ? AND range_min < ? AND city_id IS NULL',
  333. [$carrier_id,$city->province_id,$carrier_weight_unit_id[1],$carrier_weight[1],$carrier_weight[1]])->first();
  334. if ($waybillPriceModelProvinceOne&&$waybillPriceModelProvinceTwo){
  335. if ($waybillPriceModelProvinceOne->unit_price*$carrier_weight[0]>=$waybillPriceModelProvinceTwo->unit_price*$carrier_weight[1]){
  336. return $waybillPriceModelProvinceOne->id;
  337. }else{
  338. return $waybillPriceModelProvinceTwo->id;
  339. }
  340. }
  341. if ($waybillPriceModelProvinceOne)return $waybillPriceModelProvinceOne->id;
  342. if ($waybillPriceModelProvinceTwo)return $waybillPriceModelProvinceTwo->id;
  343. //城市价格区间都为空
  344. $waybillPriceModelProvinceRangeOne=WaybillPriceModel::whereRaw('carrier_id = ? AND province_id = ? AND unit_id = ? AND range_max IS NULL AND city_id IS NULL',
  345. [$carrier_id,$city->province_id,$carrier_weight_unit_id[0]])->first();
  346. $waybillPriceModelProvinceRangeTwo=WaybillPriceModel::whereRaw('carrier_id = ? AND province_id = ? AND unit_id = ? AND range_max IS NULL AND city_id IS NULL',
  347. [$carrier_id,$city->province_id,$carrier_weight_unit_id[1]])->first();
  348. if ($waybillPriceModelProvinceRangeOne&&$waybillPriceModelProvinceRangeTwo){
  349. if ($waybillPriceModelProvinceRangeOne->unit_price*$carrier_weight[0]>=$waybillPriceModelProvinceRangeTwo->unit_price*$carrier_weight[1]){
  350. return $waybillPriceModelProvinceRangeOne->id;
  351. }else{
  352. return $waybillPriceModelProvinceRangeOne->id;
  353. }
  354. }
  355. if ($waybillPriceModelProvinceRangeOne)return $waybillPriceModelProvinceRangeOne->id;
  356. if ($waybillPriceModelProvinceRangeOne)return $waybillPriceModelProvinceRangeOne->id;
  357. };
  358. for ($i=0;$i<count($carrier_weight);$i++){
  359. if ($carrier_weight[$i]&&$carrier_weight_unit_id[$i]){
  360. //城市价格区间不为空
  361. $waybillPriceModel=WaybillPriceModel::where('carrier_id',$carrier_id)->where('city_id',$destination_city_id)
  362. ->where('range_min','<',$carrier_weight[$i])->where('range_max','>=',$carrier_weight[$i])
  363. ->where('unit_id',$carrier_weight_unit_id[$i])->first();
  364. if($waybillPriceModel)return $waybillPriceModel->id;
  365. //价格区间为空
  366. $waybillPriceModelRange=WaybillPriceModel::whereRaw('carrier_id = ? AND city_id = ? AND unit_id = ? AND range_max IS NULL',[$carrier_id,$destination_city_id,$carrier_weight_unit_id[$i]])->first();
  367. if ($waybillPriceModelRange){ return $waybillPriceModelRange->id;}
  368. //城市为空
  369. $city=City::where('id',$destination_city_id)->select('province_id')->first();
  370. $waybillPriceModelProvince=WaybillPriceModel::whereRaw('carrier_id = ? AND province_id = ? AND unit_id = ? AND range_max >= ? AND range_min < ? AND city_id IS NULL',
  371. [$carrier_id,$city->province_id,$carrier_weight_unit_id[$i],$carrier_weight[$i],$carrier_weight[$i]])->first();
  372. if ($waybillPriceModelProvince){return $waybillPriceModelProvince->id;}
  373. //城市价格区间都为空
  374. $waybillPriceModelProvinceRange=WaybillPriceModel::whereRaw('carrier_id = ? AND province_id = ? AND unit_id = ? AND range_max IS NULL AND city_id IS NULL',
  375. [$carrier_id,$city->province_id,$carrier_weight_unit_id[$i]])->first();
  376. if ($waybillPriceModelProvinceRange){return $waybillPriceModelProvinceRange->id;}
  377. }
  378. }
  379. return false;
  380. }
  381. /*三层条件:无优先级,找到第一个直接返回
  382. * 无论是否为KG||T,计数单位一为KG,计数单位一为T,计数单位二为KG,计数单位二为T
  383. * 计数一与计数二同时存在取最贵价格:
  384. * 计数一存在,二不存在:
  385. * 计数二存在,一不存在:
  386. * 城市价格区间不为空,城市价格区间都为空,城市为空,价格区间为空
  387. * */
  388. public function isWaybillPriceModel(Request $request){
  389. $carrier_id=$request->input('carrier_id');
  390. $destination_city_id=$request->input('destination_city_id');
  391. $carrier_weight=$request->input('carrier_weight');
  392. $carrier_weight_unit_id=$request->input('carrier_weight_unit_id');
  393. $validatorData=["carrier_id"=>$carrier_id,"destination_city_id"=>$destination_city_id,
  394. 'carrier_weight'=>$carrier_weight[0],"carrier_weight_unit_id"=>$carrier_weight_unit_id[0],
  395. "carrier_weight_other"=>$carrier_weight[1],"carrier_weight_unit_id_other"=>$carrier_weight_unit_id[1]];
  396. $errors=Validator::make($validatorData,[
  397. 'carrier_id'=>'required|integer',
  398. 'destination_city_id'=>'required|integer',
  399. 'carrier_weight'=>'nullable|min:0|numeric|max:999999',
  400. 'carrier_weight_unit_id'=>'required_with:carrier_weight',
  401. 'carrier_weight_other'=>'nullable|min:0|numeric|max:999999',
  402. 'carrier_weight_unit_id_other'=>'required_with:carrier_weight_other',
  403. ],[
  404. 'required'=>':attribute 为必填项',
  405. 'max'=>':attribute 字符过多或输入值过大',
  406. 'min'=>':attribute 不得为负',
  407. 'numeric'=>':attribute 应为数字',
  408. 'unique'=>':attribute 已存在',
  409. 'required_with'=>':attribute 未填',
  410. 'integer'=>':attribute 必须为数字',
  411. ],[
  412. 'carrier_weight'=>'承运商计数(抛)',
  413. 'carrier_id'=>'承运商',
  414. 'destination_city_id'=>'目的市',
  415. 'carrier_weight_unit_id'=>'承运商计数单位',
  416. 'carrier_weight_other'=>'承运商计数二',
  417. 'carrier_weight_unit_id_other'=>'承运商计数单位二',
  418. ])->errors();
  419. if (count($errors)>0)return ['error'=>$errors];
  420. $result=$this->checkWaybillPriceModel($carrier_id,$destination_city_id,$carrier_weight,$carrier_weight_unit_id);
  421. if (!$result){
  422. //单位为kg,T时
  423. $unitKG=Unit::where('name','kg')->first();
  424. $unitT=Unit::where('name','T')->first();
  425. if ($carrier_weight_unit_id[0]==$unitKG->id){
  426. $carrier_weight_unit_id[0]=$unitT->id;
  427. $carrier_weight[0]=$carrier_weight[0]/1000;
  428. $result=$this->checkWaybillPriceModel($carrier_id,$destination_city_id,$carrier_weight,$carrier_weight_unit_id);
  429. if ($result)return ['success'=>$result];
  430. }
  431. if ($carrier_weight_unit_id[1]==$unitKG->id){
  432. $carrier_weight_unit_id[1]=$unitT->id;
  433. $carrier_weight[1]=$carrier_weight[1]/1000;
  434. $result=$this->checkWaybillPriceModel($carrier_id,$destination_city_id,$carrier_weight,$carrier_weight_unit_id);
  435. if ($result)return ['success'=>$result];
  436. }
  437. if ($carrier_weight_unit_id[0]==$unitT->id){
  438. $carrier_weight_unit_id[0]=$unitKG->id;
  439. $carrier_weight[0]=$carrier_weight[0]*1000;
  440. $result=$this->checkWaybillPriceModel($carrier_id,$destination_city_id,$carrier_weight,$carrier_weight_unit_id);
  441. if ($result)return ['success'=>$result];
  442. }
  443. if ($carrier_weight_unit_id[1]==$unitT->id){
  444. $carrier_weight_unit_id[1]=$unitKG->id;
  445. $carrier_weight[1]=$carrier_weight[1]*1000;
  446. $result=$this->checkWaybillPriceModel($carrier_id,$destination_city_id,$carrier_weight,$carrier_weight_unit_id);
  447. if ($result)return ['success'=>$result];
  448. }
  449. }
  450. return ['success'=>$result];
  451. }
  452. public function waybillUpdate(Request $request, $id){
  453. if(!Gate::allows('运输管理-编辑')){ return redirect(url('/')); }
  454. $this->validatorWaybill($request,$id)->validate();
  455. $data=$request->input();
  456. $waybill=Waybill::find($id);
  457. $waybill->fill($data);
  458. if ($waybill->save()){
  459. $this->log(__METHOD__,__FUNCTION__,json_encode($waybill),Auth::user()['id']);
  460. return redirect('waybill/index')->with('successTip','运单“'.$waybill->waybill_number.'”修改成功');
  461. }
  462. }
  463. public function waybillAudit(Request $request){
  464. if(!Gate::allows('运输管理-运单审核')){ return redirect(url('/')); }
  465. $id=$request->input('id');
  466. $waybill=Waybill::find($id);
  467. $isAudit=WaybillAuditLog::whereRaw('waybill_id = ? and audit_stage = ?',[$id,"运单阶段"])->first();
  468. if (empty($isAudit)){
  469. $waybillAuditLog=new WaybillAuditLog([
  470. 'waybill_id'=>$id,
  471. 'audit_stage'=>'运单阶段',
  472. 'user_id'=>Auth::id(),
  473. ]);
  474. $waybillAuditLog->save();
  475. $waybillAuditLog['user']=Auth::user();
  476. $waybill->status='已审核';
  477. $result=$waybill->save();
  478. $this->log(__METHOD__,__FUNCTION__,json_encode($waybill),Auth::user()['id']);
  479. return ['success'=>$result,'status'=>$waybill->status,'waybillAuditLog'=>$waybillAuditLog];
  480. }
  481. return ['exception'=>'请勿重复审核!'];
  482. }
  483. public function waybillEdit($id){
  484. if(!Gate::allows('运输管理-编辑')){ return redirect(url('/')); }
  485. $waybill=Waybill::find($id);
  486. $owners=Owner::get();
  487. return view('waybill.waybillEdit',['waybill'=>$waybill,'owners'=>$owners]);
  488. }
  489. public function waybillRetreatAudit(Request $request){
  490. if(!Gate::allows('运输管理-调度')){ return redirect(url('/')); }
  491. $id=$request->input('id');
  492. $waybill=Waybill::find($id);
  493. WaybillAuditLog::whereRaw('waybill_id = ? and audit_stage = ?',[$id,"运单阶段"])->delete();
  494. $waybill->status='待重审';
  495. $result=$waybill->save();
  496. $this->log(__METHOD__,__FUNCTION__,json_encode($waybill),Auth::user()['id']);
  497. return ['success'=>$result,'status'=>$waybill->status];
  498. }
  499. public function waybillEndAudit(Request $request){
  500. if(!Gate::allows('运输管理-调度审核')){ return redirect(url('/')); }
  501. $id=$request->input('id');
  502. $waybill=Waybill::find($id);
  503. if (!$waybill->charge&&!$waybill->collect_fee)return ['exception'=>'收费或到付费用未填!'];
  504. if ($waybill->charge==0&&$waybill->collect_fee==0)return ['exception'=>'收费与到付费用都为0!'];
  505. if ($waybill->type=='专线'){
  506. if (!$waybill->carrier_weight||$waybill->carrier_weight==0)return ['exception'=>'承运商计重未填或为0!'];
  507. if (!$waybill->carrier_weight_unit_id)return ['exception'=>'承运商计重单位未选!'];
  508. }
  509. $isAudit=WaybillAuditLog::whereRaw('waybill_id = ? and audit_stage = ?',[$id,"调度阶段"])->first();
  510. if (empty($isAudit)){
  511. $waybillAuditLog=new WaybillAuditLog([
  512. 'waybill_id'=>$id,
  513. 'audit_stage'=>'调度阶段',
  514. 'user_id'=>Auth::id(),
  515. ]);
  516. $waybillAuditLog->save();
  517. $waybillAuditLog['user']=Auth::user();
  518. if ($waybill->waybill_price_model_id||$waybill->type=='直发车'){
  519. $waybill->status='已完结';
  520. $result=$waybill->save();
  521. $waybillPayoff=WaybillPayoff::where('waybill_id','=',$id)->first();
  522. $waybillPayoff->load(["waybill"]);
  523. $waybillPayoff->waybill->load(["owner","carrier","origination_city","destination_city","carType","waybillAuditLogs"]);
  524. $waybillPayoff->waybill->waybillAuditLogs->load(["user"]);
  525. $waybillPayoffJson=json_encode($waybillPayoff,JSON_UNESCAPED_UNICODE);
  526. WaybillFinancialSnapshot::create([
  527. 'waybill_id'=>$id,
  528. 'json_content'=>$waybillPayoffJson,
  529. ]);
  530. }else{
  531. $waybill->status='无模型';
  532. $result=$waybill->save();
  533. $waybillPayoff=WaybillPayoff::where('waybill_id','=',$id)->first();
  534. if ($waybillPayoff){
  535. $waybillPayoff->load(["waybill"]);
  536. $waybillPayoff->waybill->load(["owner","carrier","origination_city","destination_city","carType","waybillAuditLogs"]);
  537. $waybillPayoff->waybill->waybillAuditLogs->load(["user"]);
  538. $waybillPayoffJson=json_encode($waybillPayoff,JSON_UNESCAPED_UNICODE);
  539. WaybillFinancialExcepted::create([
  540. 'waybill_id'=>$id,
  541. 'json_content'=>$waybillPayoffJson,
  542. ]);
  543. }
  544. }
  545. $this->log(__METHOD__,__FUNCTION__,$waybillPayoffJson,Auth::user()['id']);
  546. return ['success'=>$result,'status'=>$waybill->status,'waybillAuditLog'=>$waybillAuditLog];
  547. }
  548. return ['exception'=>'请勿重复审核!'];
  549. }
  550. public function waybillExport($id,Request $request){
  551. if(!Gate::allows('运输管理-查询')){ return '没有权限'; }
  552. if ($id==-1){
  553. $id=[];
  554. $today=Carbon::now()->subDays(15);
  555. ini_set('max_execution_time',2500);
  556. ini_set('memory_limit','1526M');
  557. $waybills=Waybill::select('id');
  558. if ($request->input('waybill_number')){
  559. $waybills =$waybills->where('waybill_number','like','%'.$request->input('waybill_number').'%')->where('created_at','>',$today->format('Y-m-d'));
  560. }
  561. if ($request->input('carrier_bill')){
  562. $waybills=$waybills->where('carrier_bill','like','%'.$request->input('carrier_bill').'%')->where('created_at','>',$today->format('Y-m-d'));
  563. }
  564. if ($request->input('carrier_id')){
  565. $waybills=$waybills->where('carrier_id','=',$request->input('carrier_id'));
  566. }
  567. if ($request->input('owner_id')){
  568. $waybills=$waybills->where('owner_id','=',$request->input('owner_id'));
  569. }
  570. if ($request->input('wms_bill_number')){
  571. $waybills=$waybills->where('wms_bill_number','like','$'.$request->input('wms_bill_number').'%')->where('created_at','>',$today->format('Y-m-d'));
  572. }
  573. if ($request->input('created_at_start')){
  574. $waybills=$waybills->where('created_at','>',$request->input('created_at_start'));
  575. }
  576. if ($request->input('created_at_end')){
  577. $waybills=$waybills->where('created_at','<',$request->input('created_at_end'));
  578. }
  579. if ($request->input('status')){
  580. $waybills=$waybills->where('status',$request->input('status'));
  581. }
  582. $waybills=$waybills->get();
  583. foreach ($waybills as $waybill){
  584. array_push($id,$waybill->id);
  585. }
  586. }else $id = explode( ',',$id);
  587. if (!$id)return ;
  588. $row=[[
  589. 'type'=>'运单类型',
  590. 'owner'=>'货主',
  591. 'source_bill'=>'上游单号',
  592. 'wms_bill_number'=>'wms订单号',
  593. 'waybill_number'=>'运单号',
  594. 'origination'=>'始发地',
  595. 'destination'=>'目的地',
  596. 'carrier'=>'承运商',
  597. 'carrier_bill'=>'承运商单号',
  598. 'warehouse_weight'=>'仓库计数(抛)',
  599. 'carrier_weight'=>'承运商计数(抛)',
  600. 'warehouse_weight_other'=>'仓库计重',
  601. 'carrier_weight_other'=>'承运商计重',
  602. 'fee'=>'运费(元)',
  603. 'pick_up_fee'=>'提货费(元)',
  604. 'other_fee'=>'其他费用(元)',
  605. 'dispatch_remark'=>'调度备注',
  606. 'created_at'=>'创建时间'
  607. ]];
  608. $feeVisible=true;
  609. if(!Gate::allows('运输管理-可见费用项')){
  610. $feeVisible=false;
  611. unset($row[0]['fee'],$row[0]['pick_up_fee'],$row[0]['other_fee'],$row[0]['collect_fee']);
  612. }
  613. $list=[];
  614. for ($i=0; $i<count($id);$i++){
  615. $waybill=Waybill::with(['owner', 'waybillAuditLogs' => function ($query) {
  616. return $query->with('user');
  617. }])->find($id[$i]);
  618. foreach ($waybill->waybillAuditLogs as $waybillAuditLog){
  619. if ($waybillAuditLog->audit_stage=="运单阶段"){
  620. $waybillAuditor=$waybillAuditLog->user->name;
  621. }else{
  622. $waybillAuditor='';
  623. }
  624. if ($waybillAuditLog->audit_stage=="调度阶段"){
  625. $dispatchAuditor=$waybillAuditLog->user->name;
  626. }else{
  627. $dispatchAuditor='';
  628. }
  629. };
  630. $w=[
  631. 'type'=>isset($waybill->type)?$waybill->type:'',
  632. 'waybill_number'=>isset($waybill->waybill_number)?$waybill->waybill_number:'',
  633. 'owner'=>isset($waybill->owner->name)?$waybill->owner->name:'',
  634. 'source_bill'=>isset($waybill->source_bill)?$waybill->source_bill:'',
  635. 'wms_bill_number'=>isset($waybill->wms_bill_number)?$waybill->wms_bill_number:'',
  636. 'origination'=>isset($waybill->origination)?$waybill->origination:'',
  637. 'destination'=>isset($waybill->destination)?$waybill->destination:'',
  638. 'recipient'=>isset($waybill->recipient)?$waybill->recipient:'',
  639. 'recipient_mobile'=>isset($waybill->recipient_mobile)?$waybill->recipient_mobile:'',
  640. //'charge'=>isset($waybill->charge)?$waybill->charge:'',
  641. //'ordering_remark'=>isset($waybill->ordering_remark)?$waybill->ordering_remark:'',
  642. 'carrier'=>isset($waybill->carrier_name)?$waybill->carrier_name:'',
  643. 'carrier_bill'=>isset($waybill->carrier_bill)?$waybill->carrier_bill:'',
  644. //'origination_city'=>isset($waybill->origination_city_name)?$waybill->origination_city_name:'',
  645. //'destination_city'=>isset($waybill->destination_city_name)?$waybill->destination_city_name:'',
  646. 'warehouse_weight'=>isset($waybill->warehouse_weight)?$waybill->warehouse_weight.' '.(isset($waybill->warehouse_weight_unit_name)?$waybill->warehouse_weight_unit_name:''):'',
  647. 'warehouse_weight_other'=>isset($waybill->warehouse_weight_other)?$waybill->warehouse_weight_other.' '.(isset($waybill->warehouse_weight_unit_other_name)?$waybill->warehouse_weight_unit_other_name:''):'',
  648. 'carrier_weight'=>isset($waybill->carrier_weight)?$waybill->carrier_weight.' '.(isset($waybill->carrier_weight_unit_name)?$waybill->carrier_weight_unit_name:''):'',
  649. 'carrier_weight_other'=>isset($waybill->carrier_weight_other)?$waybill->carrier_weight_other.' '.(isset($waybill->carrier_weight_unit_other_name)?$waybill->carrier_weight_unit_other_name:''):'',
  650. //'carType'=>isset($waybill->carType->name)?$waybill->carType->name.($waybill->carType->length.'米'):'',
  651. //'car_owner_info'=>isset($waybill->car_owner_info)?$waybill->car_owner_info:'',
  652. 'fee'=>isset($waybill->fee)?$waybill->fee:'',
  653. 'pick_up_fee'=>isset($waybill->pick_up_fee)?$waybill->pick_up_fee:'',
  654. 'other_fee'=>isset($waybill->other_fee)?$waybill->other_fee:'',
  655. //'collect_fee'=>isset($waybill->collect_fee)?$waybill->collect_fee:'',
  656. 'dispatch_remark'=>isset($waybill->dispatch_remark)?$waybill->dispatch_remark:'',
  657. //'waybillAuditor'=>isset($waybillAuditor)?$waybillAuditor:'',
  658. //'dispatchAuditor'=>isset($dispatchAuditor)?$dispatchAuditor:'',
  659. 'created_at'=>isset($waybill->created_at)?$waybill->created_at:''
  660. ];
  661. if(!$feeVisible){
  662. unset($w['fee'],$w['pick_up_fee'],$w['other_fee'],$w['collect_fee']);
  663. }
  664. $list[$i]=$w;
  665. }
  666. $this->log(__METHOD__,__FUNCTION__,json_encode($waybill),Auth::user()['id']);
  667. return Excel::download(new Export($row,$list), date('Y:m:d ') . '运单列表.xlsx');
  668. }
  669. public function deliveringExport($waybills){
  670. ini_set('max_execution_time',2500);
  671. ini_set('memory_limit','1526M');
  672. $row=[[
  673. 'created_at'=>"日期",
  674. 'carrier_name'=>"承运商",
  675. 'waybill_number'=>"宝时运单号",
  676. 'origination'=>"提货仓",
  677. 'owner_name'=>"货主",
  678. 'warehouse_weight_other'=>"预估重量",
  679. 'warehouse_weight'=>"预估体积",
  680. 'status'=>"状态",
  681. 'carrier_bill'=>"专线运单号",
  682. 'inquire_tel'=>"查件电话",
  683. 'amount'=>"件数",
  684. 'carrier_weight_other'=>"重量",
  685. 'carrier_weight'=>"体积",
  686. ]];
  687. $list=[];
  688. foreach ($waybills as $waybill){
  689. $w=[
  690. 'created_at'=>$waybill->created_at,
  691. 'carrier_name'=>$waybill->carrier_name,
  692. 'waybill_number'=>$waybill->waybill_number,
  693. 'origination'=>$waybill->origination,
  694. 'owner_name'=>$waybill->owner_name,
  695. 'warehouse_weight_other'=>$waybill->warehouse_weight_other,
  696. 'warehouse_weight'=>$waybill->warehouse_weight,
  697. 'status'=>$waybill->status=="已完结"?"已完成":$waybill->carrier_bill?"已提交":"待提交",
  698. 'carrier_bill'=>$waybill->carrier_bill,
  699. 'inquire_tel'=>$waybill->inquire_tel,
  700. 'amount'=>$waybill->amount,
  701. 'carrier_weight_other'=>$waybill->carrier_weight_other,
  702. 'carrier_weight'=>$waybill->carrier_weight,
  703. ];
  704. array_push($list,$w);
  705. }
  706. return Excel::download(new Export($row,$list), date('Y:m:d ') . '发运列表.xlsx');
  707. }
  708. //发运
  709. public function delivering(Request $request){
  710. if (!Auth::user())return view('exception.404',['error'=>'登录已过期']);
  711. if (Auth::user()->isSuperAdmin())$waybills=Waybill::orderBy('id','DESC');
  712. else{
  713. $carriersUsers=DB::table('carrier_user')->where('user_id',Auth::id())->get();
  714. $carrierIds=array_column($carriersUsers->toArray(),'carrier_id');
  715. $waybills=Waybill::orderBy('id','DESC')->whereIn("carrier_id",$carrierIds);
  716. }
  717. if ($request->input('exportType')){
  718. return $this->conditionQuery($request,$waybills);
  719. }
  720. $waybills=$this->conditionQuery($request,$waybills);
  721. return view('waybill.delivering',compact('waybills'));
  722. }
  723. //承运商提交
  724. public function storeCarrierBill(Request $request){
  725. $errors=Validator::make($request->input(),[
  726. 'id'=>'required|integer',
  727. 'carrier_bill'=>'required',
  728. 'inquire_tel'=>'nullable',
  729. 'amount'=>'nullable|integer',
  730. 'carrier_weight'=>'required_without:carrier_weight_other|nullable|numeric',
  731. 'carrier_weight_other'=>'required_without:carrier_weight|nullable|numeric',
  732. ],[
  733. 'required'=>':attribute 为必填项',
  734. 'integer'=>':attribute 应为整数',
  735. 'numeric'=>':attribute 应为数字',
  736. 'required_with'=>':attribute 重量与体积至少存在一项',
  737. ],[
  738. 'carrier_bill'=>'专线运单号',
  739. 'inquire_tel'=>'查件电话',
  740. 'amount'=>'件数',
  741. 'carrier_weight'=>'体积',
  742. 'carrier_weight_other'=>'重量',
  743. ])->errors();
  744. if (count($errors)>0)return ["errors"=>$errors];
  745. $waybill=Waybill::find($request->input('id'));
  746. if (!$waybill)return ["error"=>"未找到该运单!"];
  747. $waybill->fill($request->input());
  748. $waybill->update();
  749. return $waybill;
  750. }
  751. protected function validatorWaybill(Request $request,$id){
  752. if ($id){$wms_bill_number=$id;};
  753. $validator=Validator::make($request->input(),[
  754. 'owner_id'=>'required',
  755. 'wms_bill_number'=>['nullable','max:50',isset($wms_bill_number)?"unique:waybills,wms_bill_number,$wms_bill_number":'unique:waybills,wms_bill_number'],
  756. 'origination'=>'required|max:255',
  757. 'destination'=>'required|max:255',
  758. 'recipient'=>'required|max:50',
  759. 'recipient_mobile'=>['required','regex:/^(\d{7,11})|(1[3|4|5|7|8][0-9]\d{4,8})$/'],
  760. 'charge'=>'nullable|min:0|max:999999|numeric',
  761. 'collect_fee'=>'nullable|min:0|numeric',
  762. ],[
  763. 'required'=>':attribute 为必填项',
  764. 'alpha_num'=>':attribute 应为字母或数字',
  765. 'max'=>':attribute 字符过多或输入值过大',
  766. 'regex'=>':attribute 输入有误',
  767. 'integer'=>':attribute 应为整数',
  768. 'min'=>':attribute 不得为负',
  769. 'numeric'=>':attribute 应为数字',
  770. 'unique'=>':attribute 已存在',
  771. ],[
  772. 'owner_id'=>'货主',
  773. 'wms_bill_number'=>'WMS单号',
  774. 'origination'=>'始发地',
  775. 'destination'=>'目的地',
  776. 'recipient'=>'收件人',
  777. 'recipient_mobile'=>'收件人电话',
  778. 'charge'=>'收费',
  779. 'collect_fee'=>'到付金额',
  780. ]);
  781. return $validator;
  782. }
  783. protected function validatorWaybillDispatch(Request $request,$id){
  784. if ($request->input('type')=='直发车'){
  785. $validator=Validator::make($request->input(),[
  786. 'carrier_bill'=>"nullable|max:50|unique:waybills,carrier_bill,$id",
  787. 'fee'=>'required|min:0|numeric|max:999999',
  788. 'other_fee'=>'nullable|min:0|numeric|max:999999',
  789. 'charge'=>'nullable|min:0|numeric|max:999999',
  790. 'mileage'=>'nullable|numeric',
  791. 'amount'=>'nullable|numeric',
  792. ],[
  793. 'required'=>':attribute 为必填项',
  794. 'alpha_num'=>':attribute 应为字母或数字',
  795. 'max'=>':attribute 字符过多或输入值过大',
  796. 'min'=>':attribute 不得为负',
  797. 'numeric'=>':attribute 应为数字',
  798. 'unique'=>':attribute 已存在',
  799. ],[
  800. 'carrier_bill'=>'承运商单号',
  801. 'fee'=>'运费',
  802. 'other_fee'=>'其他费用',
  803. 'charge'=>'收费',
  804. 'mileage'=>'里程数',
  805. 'amount'=>'计数',
  806. ]);
  807. return $validator;
  808. }else if ($request->input('type')=='专线'){
  809. return $this->validatorWaybillZX($request,$id);
  810. }else{
  811. return false;
  812. }
  813. }
  814. protected function validatorWaybillZX(Request $request,$id){
  815. $validator=Validator::make($request->input(),[
  816. 'carrier_bill'=>"nullable|max:50|unique:waybills,carrier_bill,$id",
  817. 'pick_up_fee'=>'nullable|min:0|numeric|max:999999',
  818. 'other_fee'=>'nullable|min:0|numeric|max:999999',
  819. 'carrier_id'=>'required|integer',
  820. 'destination_city_id'=>'required|integer',
  821. 'warehouse_weight'=>'nullable|min:0|numeric|max:999999',
  822. 'warehouse_weight_unit_id'=>'required_with:warehouse_weight|nullable|integer',
  823. 'warehouse_weight_other'=>'nullable|min:0|numeric|max:999999',
  824. 'warehouse_weight_unit_id_other'=>'required_with:warehouse_weight_other|nullable|integer',
  825. 'charge'=>'nullable|min:0|numeric|max:999999',
  826. 'carrier_weight'=>'nullable|min:0|numeric|max:999999',
  827. 'carrier_weight_unit_id'=>'required_with:carrier_weight',
  828. 'carrier_weight_other'=>'nullable|min:0|numeric|max:999999',
  829. 'carrier_weight_unit_id_other'=>'required_with:carrier_weight_other',
  830. ],[
  831. 'required'=>':attribute 为必填项',
  832. 'alpha_num'=>':attribute 应为字母或数字',
  833. 'max'=>':attribute 字符过多或输入值过大',
  834. 'min'=>':attribute 不得为负',
  835. 'numeric'=>':attribute 应为数字',
  836. 'unique'=>':attribute 已存在',
  837. 'required_with'=>':attribute 未填',
  838. 'integer'=>':attribute 必须为数字',
  839. ],[
  840. 'carrier_bill'=>'承运商单号',
  841. 'warehouse_weight'=>'仓库计数(抛)',
  842. 'carrier_weight'=>'承运商计数(抛)',
  843. 'pick_up_fee'=>'提货费',
  844. 'other_fee'=>'其他费用',
  845. 'carrier_id'=>'承运商',
  846. 'destination_city_id'=>'目的市',
  847. 'carrier_weight_unit_id'=>'承运商计数单位',
  848. 'charge'=>'收费',
  849. 'warehouse_weight_unit_id'=>'仓库计数单位',
  850. 'warehouse_weight_other'=>'仓库计数二',
  851. 'carrier_weight_other'=>'承运商计数二',
  852. 'warehouse_weight_unit_id_other'=>'仓库技数单位二',
  853. 'carrier_weight_unit_id_other'=>'承运商计数单位二',
  854. ]);
  855. return $validator;
  856. }
  857. public function addCounty(Request $request){
  858. $rule =[
  859. 'destination_city' => ['required', 'string','unique:cities,name'],
  860. ];
  861. $messages=[
  862. 'destination_city.required'=>'市/县不能为空',
  863. 'destination_city.string'=>'市/县必须是字符串',
  864. 'destination_city.unique'=>'市/县已存在',
  865. ];
  866. $validator = Validator::make($request->all(),$rule,$messages);
  867. if ($validator->fails()) {
  868. return $validator->errors();
  869. }
  870. $city=new City([
  871. 'name'=>$request->input('destination_city'),
  872. 'type'=>3,
  873. ]);
  874. $city->save();
  875. return $city;
  876. }
  877. }