Bläddra i källkod

【Add】产品省份查询

liuxiangxin 2 månader sedan
förälder
incheckning
09ab61c6c0

+ 15 - 3
app/Http/Controllers/Admin/Product.php

@@ -45,7 +45,20 @@ class Product extends Auth{
 		$status					= request('status');
 		$startTime				= request('start_time','');
 		$businessId				= request('business_id','');
+		$provinceId				= request('province_id','');
 		$cityIds				= request('city_ids',[]);
+		$cityList				= $City->getCityList();
+		// 如果存在省份ID
+		if( $provinceId )		{
+			// 循环城市列表
+			foreach ($cityList as $group) {
+				// 如果省份ID对的上
+				if( $group['id'] == $provinceId){
+					// 获取下面的城市ID
+					$cityIds = array_merge($cityIds,array_column($group['city'],'id'));
+				}
+			}
+		}
 		// 编码转ID
 		$id						= $code ? $Model->codeToId($code) : 0;
 		// 查询条件
@@ -64,8 +77,8 @@ class Product extends Auth{
 		// 数据类型
 		$shopIds				= ($session['menu_type'] == 1 && $session['data_type'] == 2)  ? Business::query()->where('leader_uid',$session['admin_uid'])->pluck('id')->toArray() : [];
 		// 查询数据
-		$list					= $Model->query()->join('product_city','product_city.product_id','=','product.id');
-		if( $cityIds )			$list = $list->whereIn('product_city.city_id',$cityIds);
+		$list					= $Model->query();
+		if( $cityIds )			$list = $list->join('product_city','product_city.product_id','=','product.id')->whereIn('product_city.city_id',$cityIds);
         if( $shopIds )			$list = $list->whereIn('product.business_id',$shopIds);
         $list 					= $list->groupBy('product.id')
 								->where($map)
@@ -102,7 +115,6 @@ class Product extends Auth{
 			$list[$key]			  	= $value;
 		}
 		// 获取列表
-		$cityList					= $City->getCityList();
         $businessList 			    = $Business->getListByAdmin();
 		// 分配数据
 		$this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');

+ 8 - 0
resources/views/admin/product/index.blade.php

@@ -25,6 +25,14 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 			<option value="4" @if (request('status') === '4' ) selected="selected" @endif >已结束</option>
 		</select>
 	</div>
+	<div class="form-group col col-lg-2 col-md-2 col-sm-2 col-xs-12">
+		<select name="province_id" class="form-control" >
+			<option value="" >选择省份</option>
+			@foreach ($cityList as $group)
+				<option value="{{$group['id']}}" @if ( $group['id'] == request('province_id',0) ) selected="selected" @endif >{{$group['name']}}</option>
+			@endforeach
+		</select>
+	</div>
 	<div class="form-group col col-lg-2 col-md-2 col-sm-2 col-xs-12">
 		<select name="city_ids[]" class="form-control selectpicker" data-max-options="20" data-live-search="true" data-live-search-placeholder="搜索城市" data-none-results-text="未搜索到 {0}" title="选择城市" multiple>
 			@foreach ($cityList as $group)