获取源码可搜索体验小程序: 海哇
@源码地址来源: https://minglisoft.cn/honghu/business.html
package com.honghu.cloud.controller;
import java.util.ArrayList;
import java.util.HashMap;
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.CrossOrigin;
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.code.ResponseCode;
import com.honghu.cloud.code.ResponseVO;
import com.honghu.cloud.dto.ModularClassDto;
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.tools.QueryTools;
import com.honghu.cloud.util.CommUtil;
import net.sf.json.JSONObject;
/**
* 商品控制器
* @author Administrator
*
*/
@SuppressWarnings({"rawtypes","unchecked"})
@RestController
@RequestMapping(value = "/liveUserGoods")
/*@CrossOrigin(origins = "*", maxAge = 3600, methods = { RequestMethod.GET, RequestMethod.POST,RequestMethod.OPTIONS ,RequestMethod.DELETE,
RequestMethod.PUT })*/
public class UserLiveGoodsController{
@Autowired
private GoodsFeignClient goodsFeignClient;
@Autowired
private QueryTools queryTools;
@Autowired
private UserFeignClient userFeignClient;
@Autowired
private SysConfigFeignClient sysConfigFeignClient;
@Autowired
private ModularClassFeignClient modularClassFeignClient;
/**
* 主播添加的商品
* @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);
}else{
ModularClassDto ModularClassDto = modularClassFeignClient.selectByStoreId(user.getStore_id());
if (ModularClassDto == null || ModularClassDto.isTimely()) {//为附近配送不添加到我的商品里面
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);
}
/**
* 大厅商品
* @param json
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/hallGoodsApp", method = RequestMethod.POST)
public ResponseVO hallGoods(@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 userName = json.optString("userName"); //用户userName
if(StringUtils.isEmpty(userName)){
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_USERNAME_ISNULL, null); //用户userName不能为空
}
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);
maps.put("hall_goods", 1);
maps.put("uid", user.getId());
maps.put("liveUserAdd", "yes");
maps.put("is_distribution", "yes");
Map<String, Object> resultMap = goodsFeignClient.getQueryPageList(maps);
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, resultMap);
}
/**
* 添加商品
* @param json
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/userLiveGoodsAddApp", method = RequestMethod.POST)
public ResponseVO user_live_goods_add(@RequestBody JSONObject json) {
Long goods_id = json.optLong("goods_id"); //商品编号
String userName = json.optString("userName"); //用户userName
if(StringUtils.isEmpty(userName)){
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_USERNAME_ISNULL, null); //用户userName不能为空
}
if(goods_id == null || goods_id <=0){
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_GOODS_ID_ISNULL, null); //商品编号不能为空
}
UserDto user = userFeignClient.selectByUserName(userName); //用户
if(user==null){
return ResponseCode.buildEnumResponseVO(ResponseCode.USER_DOES_NOT_EXIST, null); //用户不存在
}
Long user_id = user.getId();
Integer count = goodsFeignClient.findUserLiveGoods(user_id, goods_id);
if(count != null && count > 0 ){
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_GOODS_ADD_REPEAT_ISNULL, null); //重复添加数据
}
Map<String, Object> params = new HashMap<String,Object>();
params.put("uid", user_id);
params.put("goods_id", goods_id);
goodsFeignClient.addUserLiveGoods(params);
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, null);
}
/**
* 移除商品
* @param json
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/userLiveGoodsDelApp", method = RequestMethod.POST)
public ResponseVO user_live_goods_del(@RequestBody JSONObject json) {
Long goods_id = json.optLong("goods_id"); //商品编号
String userName = json.optString("userName"); //用户userName
if(StringUtils.isEmpty(userName)){
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_USERNAME_ISNULL, null); //用户userName不能为空
}
if(goods_id == null || goods_id <=0){
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_GOODS_ID_ISNULL, null); //商品编号不能为空
}
UserDto user = userFeignClient.selectByUserName(userName); //用户
if(user==null){
return ResponseCode.buildEnumResponseVO(ResponseCode.USER_DOES_NOT_EXIST, null); //用户不存在
}
Long user_id = user.getId();
Map<String, Object> params = new HashMap<String,Object>();
params.put("uid", CommUtil.null2Long(user_id));
params.put("goods_id", CommUtil.null2Long(goods_id));
goodsFeignClient.delUserLiveGoods(params);
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, null);
}
}
@源码地址来源: https://minglisoft.cn/honghu/business.html
@源码地址来源: https://minglisoft.cn/honghu/business.html