verify_sign(); // 验证参数 $request->scene('get_list')->validate(); // 检查登录 $uid = $this->getUid(); // 获取客户信息 $custom = $uid ? $Custom->getOne($uid) : []; // 接收参数 $name = request('name',''); $limit = request('limit',10); // 显示 $map = [['status','=','0'],['stock','>',0]]; // 分类ID if( $name ) $map[] = ['name','like','%'.$name.'%']; // 是否有城市 $wherIn = empty($custom['city_id']) ? [1] : [1,$custom['city_id']]; // 获取分页信息 $Paginator = $Model->query() ->join('product_city','product_city.product_id','=','product.id') ->where($map) ->whereIn('product_city.city_id',$wherIn) ->groupBy('product_id') ->orderBy('product.sort') ->orderBy('product.id') ->paginate($limit,['product.id','product.sort','product.name','product.thumb','product.spec','product.price','product.market_price','product.stock']); // 获取数据 $data['total'] = $Paginator->total(); $data['current_page'] = $Paginator->currentPage(); $data['per_page'] = $Paginator->perPage(); $data['last_page'] = $Paginator->lastPage(); $data['data'] = $Paginator->items(); $time = time(); // 处理请求 foreach ( $data['data'] as $key => $value ) { // 处理数据 $value['thumb'] = path_compat($value['thumb']); $regimentWhere = [ ['status','=',1], ['start_time','<=',$time], ['end_time','>=',$time], ['product_id','=',$value['id']] ]; $regiment = $RegimentActive::query()->where($regimentWhere)->first(); if ( $regiment ){ $value['regiment_number'] = $regiment['number']; $value['regiment_id'] = $regiment['id']; $value['regiment_title'] = $regiment['number'].'人团'; }else{ $value['regiment_id'] = null; } // 重组数据 $data['data'][$key] = $value; } // 返回结果 return json_send(['code'=>'success','msg'=>'获取成功','data'=>$data]); } /** * 获取产品列表 /api/product/get_detail * * @param int $id 产品id * * */ public function get_detail(Request $request,Model $Model,ProductPhoto $ProductPhoto,Business $Business,ProductAttr $ProductAttr,ProductSpec $ProductSpec,ProductSkus $ProductSkus,RegimentActive $RegimentActive,Regiment $Regiment ){ // 接口验签 // $this->verify_sign(); // 验证参数 $request->scene('get_detail')->validate(); // 检查登录 // $uid = $this->checkLogin(); // 接收参数 $id = request('id',0); // 显示 $map[] = ['status','=','0']; // 查询 $data = $Model->query()->where($map)->find($id,['id','name','thumb','stock','spec','poster','price','business_id','market_price']); // 如果没有数据 if( !$data ) return json_send(['code'=>'error','msg'=>'产品已下架','data'=>['error'=>'产品已下架或不存在']]); // 转数组 $data = $data->toArray(); // 处理数据 $data['thumb'] = path_compat($data['thumb']); $data['poster'] = $data['poster'] ? path_compat($data['poster']) : ''; $data['description'] = $Model->getDesc($id); $data['business_info'] = $Business->getOne($data['business_id']); $data['photo_list'] = $ProductPhoto->getListByProductId($id); // 缩略图处理 foreach ($data['photo_list'] as $key => $value) { $value['thumb'] = path_compat($value['thumb']); $data['photo_list'][$key] = $value; } // 主图追加进去 if( $data['photo_list'] ) array_unshift($data['photo_list'],['id'=>0,'sort'=>0,'thumb'=>$data['thumb']]); // 获取产品属性 $attr = $ProductAttr->getListByProductId($id); // 规格属性 $specAttr = []; // 获取数据 foreach ($attr as $value) { // 默认未选中 $value['active'] = 0; $specAttr[$value['spec_id']]['spec_id'] = $value['spec_id']; $specAttr[$value['spec_id']]['spec_name'] = $ProductSpec->getOne($value['spec_id'],'name'); $specAttr[$value['spec_id']]['attr_list'][] = $value; } // 获取规格详情数据 $data['product_attr'] = array_values($specAttr); // 获取SKU数据 $data['product_sku'] = $ProductSkus->getListByProductId($id); // 获取数据 foreach ($data['product_sku'] as $key=>$value) { // 默认未选中 $value['sku_thumb'] = $value['sku_thumb'] ? path_compat($value['sku_thumb']) : ''; $data['product_sku'][$key]= $value; } // 手机号 if( isset($data['business_info']['phone']) ) unset($data['business_info']['phone']); if( isset($data['business_info']['logopic']) ) $data['business_info']['logopic'] = path_compat($data['business_info']['logopic']); //拼团数据 $time = time(); $regimentWhere = [ ['status','=',1], ['start_time','<=',$time], ['end_time','>=',$time], ['product_id','=',$data['id']] ]; $regimentActive = $RegimentActive::query() ->where($regimentWhere) ->first(); $data['regiment_list'] = []; $data['automatic_info'] = []; if ( $regimentActive ){ $data['regiment_number'] = $regimentActive['number']; $data['regiment_active_id'] = $regimentActive['id']; $data['regiment_price'] = $regimentActive['regiment_price']; $data['regiment_quota'] = $regimentActive['quota']; $data['regiment_active'] = $regimentActive; $data['automatic_info'] = []; if ($regimentActive['automatic'] == 1){ $data['regiment_title'] = '多人团'; $automaticInfo = $Regiment::query()->where([['status','=',1],['active_id','=',$regimentActive['id']],['start_time','<=',$time],['end_time','>=',$time]])->first(); $data['automatic_info'] = $automaticInfo; $data['regiment_type'] = 1; }else{ $data['regiment_title'] = $regimentActive['number'].'人团'; $data['regiment_type'] = 2; $regiment = $Regiment::query() ->join('custom','custom.uid','=','regiment.custom_uid') ->where([['regiment.product_id','=',$data['id']],['regiment.status','=',1],['regiment.start_time','<=',$time],['regiment.end_time','>=',$time]]) ->select(['regiment.*','custom.username','custom.userpic']) ->get(); if ($regiment){ foreach ($regiment as &$value) { $value['userpic'] = $value['userpic'] ? path_compat($value['userpic']) : ''; } $data['regiment_list'] = $regiment; } } }else{ $data['regiment_active_id'] = null; $data['regiment_type'] = 0; } // 返回结果 return json_send(['code'=>'success','msg'=>'获取成功','data'=>$data]); } /** * 获取产品列表 /api/product/get_sku * * @param int $id 产品id * * */ public function get_sku(Request $request,ProductAttr $ProductAttr,ProductSpec $ProductSpec,ProductSkus $ProductSkus ){ // 接口验签 // $this->verify_sign(); // 验证参数 $request->scene('get_sku')->validate(); // 检查登录 $uid = $this->checkLogin(); // 接收参数 $id = request('id',0); // 获取产品属性 $attr = $ProductAttr->getListByProductId($id); // 规格属性 $specAttr = []; // 获取数据 foreach ($attr as $value) { // 默认未选中 $value['active'] = 0; $specAttr[$value['spec_id']]['spec_id'] = $value['spec_id']; $specAttr[$value['spec_id']]['spec_name'] = $ProductSpec->getOne($value['spec_id'],'name'); $specAttr[$value['spec_id']]['attr_list'][] = $value; } // 获取规格详情数据 $data['product_attr'] = $specAttr; // 获取SKU数据 $data['product_sku'] = $ProductSkus->getListByProductId($id); // 返回结果 return json_send(['code'=>'success','msg'=>'获取成功','data'=>$data]); } }