WaybillsController.php 46 KB

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