ソースを参照

【Add】产品人群限定

liuxiangxin 6 ヶ月 前
コミット
5f0e5e53b9

+ 47 - 4
app/Http/Controllers/Admin/Product.php

@@ -2,7 +2,6 @@
 
 use App\Http\Requests\Admin\Product as Request;
 use App\Models\AdminHistory;
-use App\Models\AdminUser;
 use App\Models\Business;
 use App\Models\City;
 use App\Models\OrdersProduct;
@@ -16,6 +15,7 @@ use App\Models\Product\Skus as ProductSkus;
 use App\Models\Product\City as ProductCity;
 use App\Models\ProductPhoto;
 use Illuminate\Support\Facades\DB;
+use App\Models\WeiBan\Tags as WeiBanTags;
 
 /**
  * 产品管理
@@ -111,7 +111,7 @@ class Product extends Auth{
 	 * 添加
 	 * 
 	 * */
-	public function add( Request $request, Model $Model,ProductPhoto $ProductPhoto,Producer $Producer,Business $Business,ProductType $ProductType,ProductSpec $ProductSpec,ProductAttr $ProductAttr,ProductSkus $ProductSkus,City $City,ProductCity $ProductCity){
+	public function add( Request $request, Model $Model,WeiBanTags $WeiBanTags,ProductPhoto $ProductPhoto,Producer $Producer,Business $Business,ProductType $ProductType,ProductSpec $ProductSpec,ProductAttr $ProductAttr,ProductSkus $ProductSkus,City $City,ProductCity $ProductCity){
 		if( request()->isMethod('post') ){
 			// 验证参数
 			$request->scene('add')->validate();
@@ -137,6 +137,10 @@ class Product extends Auth{
 			$skuList				= request('sku',[]);
 			$cityIds				= request('city_ids',[]);
 			$photoList				= request('photo_list',[]);
+			$tagScope				= request('tag_scope',[]);
+			$data['tag_scope']		= implode(',',$tagScope);
+			$tagExclude				= request('tag_exclude',[]);
+			$data['tag_exclude']	= implode(',',$tagExclude);
 			// 循环
 			foreach ($photoList as $key => $value) {
 				if( !$value )		unset($photoList[$key]);
@@ -286,8 +290,17 @@ class Product extends Auth{
 		$cityList				= $City->getCityList();
 		$businessList 			= $Business->getList();
 		$producerList			= $Producer->getList();
+		// 标签列表
+		$tagData				= $WeiBanTags->query()->groupBy('group')->groupBy('name')->get(['group','name'])->toArray();
+		// 标签列表
+		$tagList				= [];
+		// 循环数据
+		foreach ($tagData as $value) {
+			$tagList[$value['group']][] = $value['name'];
+		}
 		// 分配数据
 		$this->assign('crumbs','新增');
+		$this->assign('tagList',$tagList);
 		$this->assign('typeList',$typeList);
 		$this->assign('cityList',$cityList);
 		$this->assign('businessList',$businessList);
@@ -300,7 +313,7 @@ class Product extends Auth{
 	 * 编辑
 	 * 
 	 * */
-	public function edit( Request $request, Model $Model,ProductPhoto $ProductPhoto,Producer $Producer,Business $Business,ProductType $ProductType,ProductSpec $ProductSpec,ProductAttr $ProductAttr,ProductSkus $ProductSkus,City $City,ProductCity $ProductCity){
+	public function edit( Request $request, Model $Model,WeiBanTags $WeiBanTags,ProductPhoto $ProductPhoto,Producer $Producer,Business $Business,ProductType $ProductType,ProductSpec $ProductSpec,ProductAttr $ProductAttr,ProductSkus $ProductSkus,City $City,ProductCity $ProductCity){
 		if(request()->isMethod('post')){
 			// 验证参数
 			$request->scene('edit')->validate();
@@ -326,6 +339,10 @@ class Product extends Auth{
 			$skuList				= request('sku',[]);
 			$cityIds				= request('city_ids',[]);
 			$photoList				= request('photo_list',[]);
+			$tagScope				= request('tag_scope',[]);
+			$data['tag_scope']		= implode(',',$tagScope);
+			$tagExclude				= request('tag_exclude',[]);
+			$data['tag_exclude']	= implode(',',$tagExclude);
 			// 循环
 			foreach ($photoList as $key => $value) {
 				if( !$value )		unset($photoList[$key]);
@@ -469,6 +486,8 @@ class Product extends Auth{
 		$oldData					= $oldData->toArray();
 		$oldData['description']		= $Model->getDesc($id);
 		$oldData['city_ids']		= $ProductCity->getListByProductId($id);
+		$oldData['tag_scope']		= explode(',',$oldData['tag_scope']);
+		$oldData['tag_exclude']		= explode(',',$oldData['tag_exclude']);
 		$photoList					= $ProductPhoto->getListByProductId($id);
 		// 获取产品属性
 		$attrList					= $ProductAttr->getListByProductId($id);
@@ -501,7 +520,16 @@ class Product extends Auth{
 		$cityList				= $City->getCityList();
 		$businessList 			= $Business->getList();
 		$producerList			= $Producer->getList();
+		// 标签列表
+		$tagData					= $WeiBanTags->query()->groupBy('group')->groupBy('name')->get(['group','name'])->toArray();
+		// 标签列表
+		$tagList					= [];
+		// 循环数据
+		foreach ($tagData as $value) {
+			$tagList[$value['group']][] = $value['name'];
+		}
 		// 分配数据
+		$this->assign('tagList',$tagList);
 		$this->assign('typeList',$typeList);
 		$this->assign('cityList',$cityList);
 		$this->assign('businessList',$businessList);
@@ -520,7 +548,7 @@ class Product extends Auth{
 	 * 编辑
 	 * 
 	 * */
-	public function copy( Request $request, Model $Model,ProductPhoto $ProductPhoto,Producer $Producer,Business $Business,ProductType $ProductType,ProductSpec $ProductSpec,ProductAttr $ProductAttr,ProductSkus $ProductSkus,City $City,ProductCity $ProductCity){
+	public function copy( Request $request, Model $Model,WeiBanTags $WeiBanTags,ProductPhoto $ProductPhoto,Producer $Producer,Business $Business,ProductType $ProductType,ProductSpec $ProductSpec,ProductAttr $ProductAttr,ProductSkus $ProductSkus,City $City,ProductCity $ProductCity){
 		if( request()->isMethod('post') ){
 			// 验证参数
 			$request->scene('add')->validate();
@@ -544,6 +572,10 @@ class Product extends Auth{
 			$skuList				= request('sku',[]);
 			$cityIds				= request('city_ids',[]);
 			$photoList				= request('photo_list',[]);
+			$tagScope				= request('tag_scope',[]);
+			$data['tag_scope']		= implode(',',$tagScope);
+			$tagExclude				= request('tag_exclude',[]);
+			$data['tag_exclude']	= implode(',',$tagExclude);
 			// 循环
 			foreach ($photoList as $key => $value) {
 				if( !$value )		unset($photoList[$key]);
@@ -689,6 +721,8 @@ class Product extends Auth{
 		$oldData					= $oldData->toArray();
 		$oldData['description']		= $Model->getDesc($id);
 		$oldData['city_ids']		= $ProductCity->getListByProductId($id);
+		$oldData['tag_scope']		= explode(',',$oldData['tag_scope']);
+		$oldData['tag_exclude']		= explode(',',$oldData['tag_exclude']);
 		$photoList					= $ProductPhoto->getListByProductId($id);
 		// 获取产品属性
 		$attrList					= $ProductAttr->getListByProductId($id);
@@ -716,12 +750,21 @@ class Product extends Auth{
 			// 重组
 			$skuList[$key]			= $value;
 		}
+		// 标签列表
+		$tagData					= $WeiBanTags->query()->groupBy('group')->groupBy('name')->get(['group','name'])->toArray();
+		// 标签列表
+		$tagList					= [];
+		// 循环数据
+		foreach ($tagData as $value) {
+			$tagList[$value['group']][] = $value['name'];
+		}
 		// 获取类型数据
 		$typeList				= $ProductType->getList();
 		$cityList				= $City->getCityList();
 		$businessList 			= $Business->getList();
 		$producerList			= $Producer->getList();
 		// 分配数据
+		$this->assign('tagList',$tagList);
 		$this->assign('typeList',$typeList);
 		$this->assign('cityList',$cityList);
 		$this->assign('businessList',$businessList);

+ 46 - 9
app/Http/Controllers/Api/Orders.php

@@ -15,6 +15,7 @@ use App\Models\OrdersAddr;
 use App\Models\OrdersProduct;
 use App\Models\ShopCart;
 use Illuminate\Support\Facades\DB;
+use App\Models\WeiBan\Tags as WeiBanTags;
 
 /**
  * 订单接口
@@ -28,7 +29,7 @@ class Orders extends Api{
 	 * 创建订单						 	/api/orders/create
 	 * 
 	 * */
-	public function create(Request $request,Custom $Custom,City $City,Model $Model,OrdersAddr $OrdersAddr,OrdersProduct $OrdersProduct,Product $Product,ProductSkus $ProductSkus,CustomCoupon $CustomCoupon,ShopCart $ShopCart,CustomAddr $CustomAddr,CustomScore $CustomScore){
+	public function create(Request $request,Custom $Custom,City $City,Model $Model,WeiBanTags $WeiBanTags,OrdersAddr $OrdersAddr,OrdersProduct $OrdersProduct,Product $Product,ProductSkus $ProductSkus,CustomCoupon $CustomCoupon,ShopCart $ShopCart,CustomAddr $CustomAddr,CustomScore $CustomScore){
 		// 接口验签
 		// $this->verify_sign();
 		// 验证参数
@@ -38,23 +39,33 @@ class Orders extends Api{
 		// 接收参数
 		$isCart							= request('is_cart',0);
 		$productList					= request('product_list','[]');
-		$customCouponId					= request('custom_coupon_id',1);
-		$addr							= $CustomAddr->getOne(request('addr_id',0));
+		$customCouponId					= request('custom_coupon_id',0);
+		$addrId							= request('addr_id',0);
+		// 如果不存在数据
+		if( !$addrId )					return json_send(['code'=>'error','msg'=>'请选择收货地址','data'=>['error'=>'请选择收货地址']]);
+		// 解码购买信息
+		$buyList						= json_decode($productList,true);
+		// 如果不存在数据
+		if( empty($buyList) )			return json_send(['code'=>'error','msg'=>'没有需下单的产品','data'=>['error'=>'产品列表为空']]);
+		// 选择地址
+		$addr							= $CustomAddr->getOne($addrId);
 		// 如果不存在数据
 		if( !$addr )					return json_send(['code'=>'error','msg'=>'地址有误,请核对','data'=>['error'=>'没有找到对应的地址']]);
 		// 重组数据
 		$addr							= ['contact_name'=>$addr['contact_name'],'contact_shop'=>$addr['contact_shop'],'contact_phone'=>$addr['contact_phone'],'contact_province'=>$addr['contact_province'],'contact_city'=>$addr['contact_city'],'contact_area'=>$addr['contact_area'],'contact_addr'=>$addr['contact_addr']];
 		// 获取客户城市ID
-		$cityId							= (int) $Custom->getValue($uid,'city_id');
+		$custom							= $Custom->getOne($uid);
+		// 如果不存在的话
+		if( !$custom )					return json_send(['code'=>'no_login','msg'=>'用户不存在,请重新登录','data'=>['error'=>'用户不存在,请重新登录']]);
+		// 如果不存在的话
+		if( !$custom['city_id'] )		return json_send(['code'=>'error','msg'=>'请选择所在城市后下单','data'=>['error'=>'请选择所在城市后下单']]);
+		// 获取城市ID
+		$cityId							= $custom['city_id'];
 		$cityName						= $City->getOne($cityId,'name');
 		$pid 							= $City->getOne($cityId,'pid');
 		$province						= $City->getOne($pid,'name');
 		// 判断选择的城市名称是不是一致
 		if( $cityName != $addr['contact_city'] ) return json_send(['code'=>'error','msg'=>'收货地址请选择'.$province.'/'.$cityName,'data'=>['error'=>'收货地址需与您所选城市一致']]);
-		// 解码购买信息
-		$buyList						= json_decode($productList,true);
-		// 如果不存在数据
-		if( empty($buyList) )			return json_send(['code'=>'error','msg'=>'没有需下单的产品','data'=>['error'=>'产品列表为空']]);
 		// 商品购买数量
 		$buyNum							= [];
 		// 循环购买信息
@@ -62,6 +73,8 @@ class Orders extends Api{
 			// 获取每个商品的总量
 			$buyNum[$value['product_id']] = isset($buyNum[$value['product_id']]) ? ($buyNum[$value['product_id']] + $value['buy_num']) : $value['buy_num'];
 		}
+		// 查询用户标签
+		$tags							= $WeiBanTags->getListByWeibanExtid($custom['weiban_extid']);
 		// 查询产品信息
 		$productList					= $Product->getListByIds(array_column($buyList,'product_id'));
 		$skusList						= $ProductSkus->getListByIds(array_column($buyList,'product_skuid'));
@@ -76,7 +89,31 @@ class Orders extends Api{
 			// 如果产品不存在
 			if( empty($productList[$buyInfo['product_id']]) )	return json_send(['code'=>'error','msg'=>'产品不存在或已下架','data'=>['error'=>'产品不存在或已下架=>'.$buyInfo['product_id']]]);
 			// 获取产信息
-			$productInfo 				= $productList[$buyInfo['product_id']];
+			$productInfo 					= $productList[$buyInfo['product_id']];
+			// 判断是不是可以参与
+			if( $productInfo['tag_scope'] ) {
+				// 解析数组
+				$productInfo['tag_scope']	= explode(',',$productInfo['tag_scope']);
+				// 标签范围限定时,默认不能参与
+				$allowJoin 					= 0;
+				// 判断标签是不是存在
+				foreach ($tags as $value) 	{
+					// 标签范围内,允许参加
+					if( in_array($value['name'],$productInfo['tag_scope']) )  $allowJoin = 1;
+				}
+				// 如果不能参与
+				if( !$allowJoin )	return json_send(['code'=>'error','msg'=>'不在 '.$productInfo['product_name'].' 参与范围','data'=>['error'=>'不在标签范围内']]);
+			}
+			// 判断是不是可以参与
+			if( $productInfo['tag_exclude'] ) {
+				// 解析数组
+				$productInfo['tag_exclude']	= explode(',',$productInfo['tag_exclude']);
+				// 判断标签是不是存在
+				foreach ($tags as $value) 	{
+					// 标签排除范围内,不允许参加
+					if( in_array($value['name'],$productInfo['tag_exclude']) )  return json_send(['code'=>'error','msg'=>'不在 '.$productInfo['product_name'].' 可参与范围','data'=>['error'=>'用户在标签排除范围']]);
+				}
+			}
 			// 如果产品限购
 			if( $productInfo['quota'] )	{
 				// 是否在限购时间,当前时间大于开始时间,并且小于结束时间

+ 1 - 1
app/Models/Product.php

@@ -160,7 +160,7 @@ class Product extends Model
     public function getListByIds($productIds)
     {
         // 写入数据表
-        $data				    = $this->query()->whereIn('id',$productIds)->where([['status','=',0]])->get(['id','name as product_name','thumb as product_thumb','spec as sku_attr_names','price','stock','status','business_id','quota','quota_start','quota_end'])->toArray();
+        $data				    = $this->query()->whereIn('id',$productIds)->where([['status','=',0]])->get(['id','name as product_name','thumb as product_thumb','spec as sku_attr_names','price','stock','status','business_id','quota','quota_start','quota_end','tag_scope','tag_exclude'])->toArray();
         // 列表
         $list                   = [];
         // 循环处理

+ 24 - 0
resources/views/admin/product/add.blade.php

@@ -134,6 +134,30 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 			@endforeach
 		</select>
 	</div>
+	<div class="form-group col-sm-2">
+		<label class="control-label">标签范围(标签存在延迟,请慎用)</label>
+		<select name="tag_scope[]" class="form-control selectpicker" data-max-options="10" data-live-search="true" data-live-search-placeholder="搜索标签" data-none-results-text="未搜索到 {0}" title="选择标签" multiple>
+			@foreach ($tagList as $group=>$tags)
+			<optgroup label="{{$group}}">
+				@foreach ($tags as $tag)
+				<option value="{{$tag}}" >{{$tag}}</option>
+				@endforeach
+			</optgroup>
+			@endforeach
+		</select>
+	</div>
+	<div class="form-group col-sm-2">
+		<label class="control-label">标签排除(标签存在延迟,请慎用)</label>
+		<select name="tag_exclude[]" class="form-control selectpicker" data-max-options="10" data-live-search="true" data-live-search-placeholder="搜索标签" data-none-results-text="未搜索到 {0}" title="选择标签" multiple>
+			@foreach ($tagList as $group=>$tags)
+			<optgroup label="{{$group}}">
+				@foreach ($tags as $tag)
+				<option value="{{$tag}}" >{{$tag}}</option>
+				@endforeach
+			</optgroup>
+			@endforeach
+		</select>
+	</div>
 	<div class="form-group col-sm-12" id="add_spec">
 		
 	</div>

+ 34 - 1
resources/views/admin/product/copy.blade.php

@@ -126,6 +126,30 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 			@endforeach
 		</select>
 	</div>
+	<div class="form-group col-sm-2">
+		<label class="control-label">标签范围(标签存在延迟,请慎用)</label>
+		<select name="tag_scope[]" class="form-control selectpicker" data-max-options="10" data-live-search="true" data-live-search-placeholder="搜索标签" data-none-results-text="未搜索到 {0}" title="选择标签" multiple>
+			@foreach ($tagList as $group=>$tags)
+			<optgroup label="{{$group}}">
+				@foreach ($tags as $tag)
+				<option value="{{$tag}}"  @if(in_array($tag,$oldData['tag_scope'])) selected @endif >{{$tag}}</option>
+				@endforeach
+			</optgroup>
+			@endforeach
+		</select>
+	</div>
+	<div class="form-group col-sm-2">
+		<label class="control-label">标签排除(标签存在延迟,请慎用)</label>
+		<select name="tag_exclude[]" class="form-control selectpicker" data-max-options="10" data-live-search="true" data-live-search-placeholder="搜索标签" data-none-results-text="未搜索到 {0}" title="选择标签" multiple>
+			@foreach ($tagList as $group=>$tags)
+			<optgroup label="{{$group}}">
+				@foreach ($tags as $tag)
+				<option value="{{$tag}}"  @if(in_array($tag,$oldData['tag_exclude'])) selected @endif >{{$tag}}</option>
+				@endforeach
+			</optgroup>
+			@endforeach
+		</select>
+	</div>
 	<div class="form-group col-sm-12" id="add_spec">
 		@foreach ($specList as $spec)
 		<div class="form-group col-sm-12">
@@ -204,6 +228,7 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 							@foreach ($specList as $value)
 							<th>{{$value['name']}}</th>
 							@endforeach
+							<th>配图</th>
 							<th>价格</th>
 							<th>库存</th>
 							<th>是否上架</th>
@@ -211,11 +236,19 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 						</tr>
 					</thead>
 					<tbody>
-						@foreach ($skuList as $value)
+						@foreach ($skuList as $key=>$value)
 						<tr>
 							@foreach (explode(',',$value['attr_ids']) as $v)
 							<td>{{$v}}</td>
 							@endforeach
+							<td>
+								<div id="sku_thumb{{$key}}">
+									<a id="sku_thumb-image{{$key}}" href="#" data-toggle="image" class="img-thumb">
+										<img src="{{path_compat($value['sku_thumb']??'')}}" height="30" />
+									</a>
+									<input type="hidden" name="sku[{{$value['attr_names']}}][sku_thumb]" laceholder="缩略图" value="{{$value['sku_thumb']??''}}" id="input-sku_thumb{{$key}}" />
+								</div>
+							</td>
 							<td><input type="text" name="sku[{{$value['attr_ids']}}][price]" placeholder="价格" value="{{$value['price']}}"></td>
 							<td><input type="number" name="sku[{{$value['attr_ids']}}][stock]" placeholder="库存"  value="{{$value['stock']}}"></td>
 							<td>

+ 25 - 0
resources/views/admin/product/edit.blade.php

@@ -134,6 +134,30 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 			@endforeach
 		</select>
 	</div>
+	<div class="form-group col-sm-2">
+		<label class="control-label">标签范围(标签存在延迟,请慎用)</label>
+		<select name="tag_scope[]" class="form-control selectpicker" data-max-options="10" data-live-search="true" data-live-search-placeholder="搜索标签" data-none-results-text="未搜索到 {0}" title="选择标签" multiple>
+			@foreach ($tagList as $group=>$tags)
+			<optgroup label="{{$group}}">
+				@foreach ($tags as $tag)
+				<option value="{{$tag}}"  @if(in_array($tag,$oldData['tag_scope'])) selected @endif >{{$tag}}</option>
+				@endforeach
+			</optgroup>
+			@endforeach
+		</select>
+	</div>
+	<div class="form-group col-sm-2">
+		<label class="control-label">标签排除(标签存在延迟,请慎用)</label>
+		<select name="tag_exclude[]" class="form-control selectpicker" data-max-options="10" data-live-search="true" data-live-search-placeholder="搜索标签" data-none-results-text="未搜索到 {0}" title="选择标签" multiple>
+			@foreach ($tagList as $group=>$tags)
+			<optgroup label="{{$group}}">
+				@foreach ($tags as $tag)
+				<option value="{{$tag}}"  @if(in_array($tag,$oldData['tag_exclude'])) selected @endif >{{$tag}}</option>
+				@endforeach
+			</optgroup>
+			@endforeach
+		</select>
+	</div>
 	<div class="form-group col-sm-12" id="add_spec">
 		@foreach ($specList as $spec)
 		<div class="form-group col-sm-12">
@@ -212,6 +236,7 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 							@foreach ($specList as $value)
 							<th>{{$value['name']}}</th>
 							@endforeach
+							<th>配图</th>
 							<th>价格</th>
 							<th>库存</th>
 							<th>是否上架</th>