ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

java版直播商城之直播间商品代码介绍Spring Cloud+SpringBoot+mybatis+uniapp b2b2c微服务商城

2022-01-14 09:05:50  阅读:158  来源: 互联网

标签:uniapp SpringBoot json user ResponseCode put null id 商城


 @源码地址来源: https://minglisoft.cn/honghu2/business.html

 

package com.honghu.cloud.controller;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import com.honghu.cloud.bean.LiveBaby;
import com.honghu.cloud.code.ResponseCode;
import com.honghu.cloud.code.ResponseVO;
import com.honghu.cloud.common.page.Page;
import com.honghu.cloud.dto.GoodsDto;
import com.honghu.cloud.dto.ModularClassDto;
import com.honghu.cloud.dto.SysConfigDto;
import com.honghu.cloud.dto.UserDto;
import com.honghu.cloud.feign.GoodsFeignClient;
import com.honghu.cloud.feign.ModularClassFeignClient;
import com.honghu.cloud.feign.SysConfigFeignClient;
import com.honghu.cloud.feign.UserFeignClient;
import com.honghu.cloud.service.LiveBabyService;
import com.honghu.cloud.tools.QueryTools;
import com.honghu.cloud.tools.SecurityUserHolder;
 
import net.sf.json.JSONObject;
 
/**
 * 直播间宝贝控制器
 * 
 * @author Administrator
 *
 */
@RestController
@RequestMapping(value="/liveBaby")
public class LiveBabyController {
     @源码地址来源: https://minglisoft.cn/honghu2/business.html
 
    @Autowired
    private LiveBabyService liveBabyService;
    @Autowired
    private GoodsFeignClient goodsFeignClient;
    @Autowired
	private SysConfigFeignClient sysConfigFeignClient;
    @Autowired
	private UserFeignClient userFeignClient;
    @Autowired
    private ModularClassFeignClient modularClassFeignClient;
    
    /**
     * 直播宝贝列表数据查询
     * @param request
     * @param json	
     * 		currentPage:当前页数
     * 		pageSize:每页大小
     * 		type:  查询类【all-全部,yes-已播,not-未播    pay-已购】
     * @return
     */
    @RequestMapping("/getLiveBabyAll_bak")
    public ResponseVO getLiveBabyAll_bak(@RequestBody JSONObject json) {
    	String currentPage = json.optString("currentPage");			//当前页数
    	String pageSize = json.optString("pageSize");			    //每页大小
    	String type = json.optString("type");						//查询方式
    	String userName = json.optString("userName");			    //用户名
    	if(StringUtils.isEmpty(userName)){
    		return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_USERNAME_ISNULL, null);	//用户userName不能为空
    	}
    	if(StringUtils.isEmpty(type)){
    		return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_GOODS_TYPE_ISNULL, null);	//直播间宝贝类型不能为空
    	}
    	UserDto user = userFeignClient.selectByUserName(userName);
    	if(user == null){
    		return ResponseCode.buildEnumResponseVO(ResponseCode.USER_DOES_NOT_EXIST, null);	//用户不存在
    	}
    	if(user.getStore_id() == null){
    		return ResponseCode.buildEnumResponseVO(ResponseCode.STORE_ISNULL, null);	//你未开通店铺
    	}
    	Map<String, Object> paraMap = new HashMap<String, Object>();
    	paraMap.put("currentPage", currentPage);
    	paraMap.put("pageSize", pageSize);
    	paraMap.put("goods_store_id", user.getStore_id());   			//商品所属店铺编号
    	paraMap.put("goods_status", 0);		//商品状态标识
    	if(type.equals("not")){
    		paraMap.put("live_user_id", user.getUserName()); 					//主播用户编号
		}
		if(type.equals("yes")){
			paraMap.put("live_creater_id", user.getUserName()); 				//主播用户编号
		}
		if(type.equals("pay")){
			paraMap.put("pay_status", 1); 								//是否已购,0为未购买,1为已购
			paraMap.put("live_creater_id", user.getUserName()); 				//主播用户编号
		}
		Map<String, Object> resultMap = goodsFeignClient.getQueryPageList(paraMap);	//查询店铺商品列表
		return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, resultMap);	//请求成功、结果处理成功
    }
    
    
    
    
    /**
     * 直播宝贝列表数据查询
     * @param request
     * @param json	
     * 		currentPage:当前页数
     * 		pageSize:每页大小
     * 		type:  查询类【all-全部,yes-已播,not-未播    pay-已购】
     * @return
     */
    @RequestMapping("/getLiveBabyAll_bak_new")
    public ResponseVO getLiveBabyAll_bak_new(@RequestBody JSONObject json,HttpServletRequest request) {
    	String currentPage = json.optString("currentPage");			//当前页数
    	String pageSize = json.optString("pageSize");			    //每页大小
    	String type = json.optString("type");						//查询方式
    	String tokenStr = request.getHeader("token");
		Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
		if(user_id == null){
			return ResponseCode.buildEnumResponseVO(ResponseCode.TOKEN_EXPIRE, null); 
		}
		UserDto user = userFeignClient.selectByPrimaryKey(user_id);
		if(user == null){
			// 用户不存在
			return ResponseCode.buildEnumResponseVO(ResponseCode.USER_NOT_EXISTS_ERROR, null);
		}
    	if(StringUtils.isEmpty(type)){
    		return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_GOODS_TYPE_ISNULL, null);	//直播间宝贝类型不能为空
    	}
    	if(user.getStore_id() == null){
    		return ResponseCode.buildEnumResponseVO(ResponseCode.STORE_ISNULL, null);	//你未开通店铺
    	}
    	Map<String, Object> paraMap = new HashMap<String, Object>();
    	paraMap.put("currentPage", currentPage);
    	paraMap.put("pageSize", pageSize);
    	paraMap.put("goods_store_id", user.getStore_id());   			//商品所属店铺编号
    	paraMap.put("goods_status", 0);		//商品状态标识
    	if(type.equals("not")){
    		paraMap.put("live_user_id", user.getUserName()); 					//主播用户编号
		}
		if(type.equals("yes")){
			paraMap.put("live_creater_id", user.getUserName()); 				//主播用户编号
		}
		if(type.equals("pay")){
			paraMap.put("pay_status", 1); 								//是否已购,0为未购买,1为已购
			paraMap.put("live_creater_id", user.getUserName()); 				//主播用户编号
		}
		
		
 
		Map<String, Object> resultMap = goodsFeignClient.getQueryPageList(paraMap);	//查询店铺商品列表
		return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, resultMap);	//请求成功、结果处理成功
    }
    
    
    /**
     * 直播宝贝列表数据查询
     * @param request
     * @param json	
     * 		currentPage:当前页数
     * 		pageSize:每页大小
     * 		type:  查询类【all-全部,yes-已播,not-未播    pay-已购】
     * @return
     */
    @RequestMapping("/getLiveBabyAll")
    public ResponseVO getLiveBabyAll(@RequestBody JSONObject json) {
    	String currentPage = json.optString("currentPage");			//当前页数
    	String pageSize = json.optString("pageSize");			    //每页大小
    	String type = json.optString("type");						//查询方式
    	String userName = json.optString("userName");			    //用户名
    	if(StringUtils.isEmpty(userName)){
    		return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_USERNAME_ISNULL, null);	//用户userName不能为空
    	}
    	if(StringUtils.isEmpty(type)){
    		return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_GOODS_TYPE_ISNULL, null);	//直播间宝贝类型不能为空
    	}
    	UserDto user = userFeignClient.selectByUserName(userName);
    	if(user == null){
    		return ResponseCode.buildEnumResponseVO(ResponseCode.USER_DOES_NOT_EXIST, null);	//用户不存在
    	}
    	if(user.getStore_id() == null){
    		return ResponseCode.buildEnumResponseVO(ResponseCode.STORE_ISNULL, null);	//你未开通店铺
    	}
    	
    	Map<String, Object> paraMap = new HashMap<String, Object>();
    	paraMap.put("currentPage", currentPage);
    	paraMap.put("pageSize", pageSize);
    	paraMap.put("goods_status", 0);		//商品状态标识
    	paraMap.put("live_uid", user.getId()); 	
    	if(type.equals("not")){
    		
		}
		if(type.equals("yes")){
			
		}
		if(type.equals("pay")){
			paraMap.put("pay_status", 1); 	
			//是否已购,0为未购买,1为已购
			
		}
		Map<String, Object> resultMap = goodsFeignClient.getQueryPageList(paraMap);	//查询店铺商品列表
		return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, resultMap);	//请求成功、结果处理成功
    }
    
    
    /**
     * 直播宝贝列表数据查询
     * @param request
     * @param json	
     * 		currentPage:当前页数
     * 		pageSize:每页大小
     * 		type:  查询类【all-全部,yes-已播,not-未播    pay-已购】
     * @return
     */
    @RequestMapping("/getLiveBabyAll_new")
	public ResponseVO getLiveBabyAll_new(@RequestBody JSONObject json, HttpServletRequest request) {
		String currentPage = json.optString("currentPage"); // 当前页数
		String pageSize = json.optString("pageSize"); // 每页大小
		String type = json.optString("type"); // 查询方式
		String tokenStr = request.getHeader("token");
		Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
		if (user_id == null) {
			return ResponseCode.buildEnumResponseVO(ResponseCode.TOKEN_EXPIRE, null);
		}
		UserDto user = userFeignClient.selectByPrimaryKey(user_id);
		if (user == null) {
			// 用户不存在
			return ResponseCode.buildEnumResponseVO(ResponseCode.USER_NOT_EXISTS_ERROR, null);
		}
		if (StringUtils.isEmpty(type)) {
			return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_GOODS_TYPE_ISNULL, null); // 直播间宝贝类型不能为空
		}
		
 
		Map<String, Object> paraMap = new HashMap<String, Object>();
		paraMap.put("currentPage", currentPage);
		paraMap.put("pageSize", pageSize);
		paraMap.put("goods_status", 0); // 商品状态标识
 
		boolean seleteStore = false;
		if (user.getStore_id() != null) { // 查询是否是特殊行业的店,
			ModularClassDto modularClassDto = modularClassFeignClient.selectByStoreId(user.getStore_id());
			if (modularClassDto != null && !modularClassDto.isTimely()) {
				seleteStore = true;
			}
		}
		if (type.equals("yes") && seleteStore) {
			if (user.getStore_id() == null) {
				return ResponseCode.buildEnumResponseVO(ResponseCode.STORE_ISNULL, null); // 你未开通店铺
			}
			paraMap.put("and_store_goods", user.getId()); // 店铺商品
		} else if (type.equals("all") && seleteStore) {
			paraMap.put("or_store_goods", user.getId()); // 查全部
			paraMap.put("live_uid", user.getId());
		} else if (type.equals("all") && !seleteStore) {
			paraMap.put("live_uid", user.getId()); // 查询中间表 , 但是店铺为特殊行业 ,不查店铺
		} else if (type.equals("yes") && !seleteStore) {
			return ResponseCode.buildEnumResponseVO(ResponseCode.STORE_ISNEARBY, null); // 店铺为特殊行业暂无法添加
		}
 
		Map<String, Object> resultMap = goodsFeignClient.getQueryPageList(paraMap); // 查询店铺商品列表
		return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, resultMap); // 请求成功、结果处理成功
	}
    
    
    /**
     * 直播间宝贝列表数据查询
     * @param params
     */
    @RequestMapping("/getLiveGoodsList")   
    public ResponseVO getLiveGoodsList(@RequestBody JSONObject json) {
    	String currentPage = json.optString("currentPage");			//当前页数
    	String pageSize = json.optString("pageSize");			    // 每页大小
    	String live_id = json.optString("live_id");			    	//主播间编号
    	if(StringUtils.isEmpty(live_id)){
    		return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_ID_ISNULL, null);			//直播间ID不能为空
    	}
    	
    	Map<String ,Object>  params = new HashMap<String, Object>();
    	params.put("currentPage",currentPage);
    	params.put("pageSize",pageSize);
    	params.put("live_id",live_id);
    	
    	Page<GoodsDto> page = liveBabyService.getLiveGoodsList(params);
    	List<Map<String, Object>> result = new LinkedList<Map<String, Object>>();
    	SysConfigDto sysConfigDto=sysConfigFeignClient.getSysConfig();
    	for (GoodsDto obj : page.getResult()) {
    		 Map<String,Object> goods = new HashMap<String, Object>();
    		 goods.put("id", obj.getId());									//商品编号
    		 if(null!=sysConfigDto && null != obj.getGoods_main_photo()){
    			 goods.put("BigPicture",sysConfigDto.getImageWebServer()+"/"+
    					 obj.getGoods_main_photo().getPath()+"/"+obj.getGoods_main_photo().getName());	//商品主图片访问路径
    			
    		 }else{
    			 goods.put("BigPicture",null);	//商品主图片访问路径
    		 }
    		 goods.put("goods_name", obj.getGoods_name());					//商品名称
    		 goods.put("store_price", obj.getStore_price());				//商品店铺价格
    		 goods.put("dis_money", obj.getDis_money());					//商品分销收益(具体的金额)
    		 goods.put("goods_inventory",obj.getGoods_inventory());			//商品库存数量
    		 goods.put("smallProgram", "");									//小程序访问路径
    		 result.add(goods);                                             //迭加商品到list集合中
		}
    	
    	Map<String ,Object> resultMap = new HashMap<String, Object>();
    	resultMap.put("currentPage", page.getCurrentPage());
		resultMap.put("pages", page.getPages());
		resultMap.put("pageSize", page.getPageSize());
		resultMap.put("result", result);
		resultMap.put("rowCount", page.getRowCount());
		return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, resultMap);			//请求成功、结果处理成功
    }
    
    
    
    
    /**
     * 直播宝贝数据查询
     * @param id
     * @return
     */
    @RequestMapping("/livebaby")
    public LiveBaby findUserById(@RequestBody JSONObject json) {
    	Long id = json.optLong("id");
        return liveBabyService.selectByPrimaryKey(id);
    }
 
    /**
     * 添加直播宝贝数据
     * @param liveBaby
     */
    @RequestMapping("/add_livebaby")
    public LiveBaby add_livebaby(@RequestBody JSONObject json) {
    	JSONObject obj = JSONObject.fromObject(json);
    	LiveBaby liveBaby = (LiveBaby)JSONObject.toBean(obj,LiveBaby.class);
    	liveBabyService.addLiveBaby(liveBaby);;
        return liveBaby;
    }
    
    
	/**
	 * vr添加商品
	 * @param json
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/myLiveGoodsApp", method = RequestMethod.POST)
	public ResponseVO myLiveGoods(@RequestBody JSONObject json, HttpServletRequest request, HttpServletResponse response) {
		String currentPage = json.optString("currentPage"); 
		Integer pageSize = json.optInt("pageSize");			    //数据长度
		String orderBy = json.optString("orderBy");					//排序字段(默认添加的时间)
		String orderType = json.optString("orderType");				//排序方式(倒序)
		String type = json.optString("type"); 						//hall_goods 大厅商品   store_goods 店铺商品  
		String userName = json.optString("userName");			//用户userName
		
		if(StringUtils.isEmpty(userName)){
    		return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_USERNAME_ISNULL, null);			//用户userName不能为空
    	}
		
		if(StringUtils.isEmpty(type)){
			return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_USER_GOODS_TYPE_ISNULL, null);			//用户我的商品类型不能为空
		}
		
		UserDto user = userFeignClient.selectByUserName(userName);			//用户
    	if(user==null){
    		return ResponseCode.buildEnumResponseVO(ResponseCode.USER_DOES_NOT_EXIST, null);	//用户不存在
    	}
		
		Map<String,Object> maps= QueryTools.getParams(currentPage, pageSize, orderBy, orderType);
		maps.put("goods_status", 0);
		
		if(StringUtils.equals(type, "hall_goods")){
			maps.put("live_uid", user.getId());
			if(user.getStore_id() != null){
				maps.put("no_goods_store_id", user.getStore_id());
			}
		}
		Map<String, Object> resultMap = new HashMap<String, Object>();
		if(StringUtils.equals(type, "store_goods")){
			maps.put("goods_store_id", user.getStore_id());
			if(user.getStore_id() == null){
				resultMap.put("currentPage", 0);
				resultMap.put("pages", 0);
				resultMap.put("pageSize", 12);
				List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
				resultMap.put("result", list);
				resultMap.put("rowCount", 0);
				return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, resultMap);
			}
		}
		resultMap = goodsFeignClient.getQueryPageList(maps);
		return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, resultMap);
	}
}
 @源码地址来源: https://minglisoft.cn/honghu2/business.html

标签:uniapp,SpringBoot,json,user,ResponseCode,put,null,id,商城
来源: https://blog.csdn.net/m0_61571842/article/details/122486793

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有