java版b2b2c多商家入駐微信小程序商城源碼Spring Cloud+Spring Boot+mybatis+security+uniapp+直播帶貨+VR全景+前後端分離微服務商城源碼

@源碼地址來源: https://minglisoft.cn/honghu/business.html
/**
 * Copyright &copy; 2012-2017 <a href="http://minglisoft.cn">HongHu</a> All rights reserved.
 */
package com.honghu.cloud.controller;
 
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.honghu.cloud.bean.FootPoint;
import com.honghu.cloud.bean.User;
import com.honghu.cloud.code.ResponseCode;
import com.honghu.cloud.common.page.Page;
import com.honghu.cloud.dto.GoodsClassDto;
import com.honghu.cloud.dto.GoodsDto;
import com.honghu.cloud.dto.SysConfigDto;
import com.honghu.cloud.dto.UserDto;
import com.honghu.cloud.feign.GoodsClassFeignClient;
import com.honghu.cloud.feign.GoodsFeignClient;
import com.honghu.cloud.feign.SysConfigFeignClient;
import com.honghu.cloud.service.IFootPointService;
import com.honghu.cloud.service.IUserService;
import com.honghu.cloud.tools.QueryTools;
import com.honghu.cloud.tools.SecurityUserHolder;
import com.honghu.cloud.utils.CommUtil;
 
import net.sf.json.JSONObject;
 
/**
 * 用戶足跡Controller
 * @author Administrator
 *
 */
@RestController
@RequestMapping(value = "/footPoint")
public class FootPointController {
 
	@Autowired
	private SysConfigFeignClient sysConfigFeignClient;
	@Autowired
	private IFootPointService footPointService;
	@Autowired
	private  GoodsFeignClient goodsFeignClient;
	@Autowired
	private GoodsClassFeignClient  goodsClassFeignClient;
	@Autowired
	private QueryTools queryTools;
	@Autowired
	private IUserService userService;
	
	/**
	 * 查詢用戶足跡
	 * @param params
	 * @return
	 */
	@RequestMapping(value = "/apiForFeign/queryPageList", method = RequestMethod.POST)
	public List<FootPoint> queryPageList(@RequestParam("params") Map<String, Object> params) {
		return footPointService.queryPageList(params);
	}
	
	
	/**
	 * 保存用戶足跡
	 * @param obj
	 */
	@RequestMapping(value = "/apiForFeign/saveEntity", method = RequestMethod.POST)
	public void saveEntity(@RequestParam("obj") FootPoint obj) {
		footPointService.saveEntity(obj);
	}
	
	
	@RequestMapping(value = "/apiForFeign/updateById", method = RequestMethod.POST)
	public void updateById(@RequestParam("obj") FootPoint obj) {
		footPointService.updateById(obj);
	}
	
	
	/**
	 * 記錄用戶足跡
	 * @param congelationDto
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	@RequestMapping(value = "/apiForFeign/recordFootPoint", method = RequestMethod.POST)
	public boolean recordFootPoint(@RequestParam ("user_id") long user_id ,@RequestParam ("goods_id") long goods_id,HttpServletRequest request) {
		//
		User user = userService.selectByPrimaryKey(user_id);
		
		GoodsDto obj = goodsFeignClient.selectByPrimaryKey(goods_id);
		//通過商品id查詢商品分類, (待修改) 
		GoodsClassDto goodsClass = goodsClassFeignClient.selectByPrimaryKey(obj.getGc_id());
		
		Map<String, Object> params = Maps.newHashMap();
		params.put("fp_date",CommUtil.formatDate(CommUtil.formatShortDate(new Date())));
		params.put("fp_user_id", user.getId());
		List<FootPoint> fps = this.footPointService.queryPageList(params);
		
		SysConfigDto sysConfig = sysConfigFeignClient.getSysConfig();
		String url = CommUtil.getURL(request);
		if (!"".equals(CommUtil.null2String(sysConfig.getImageWebServer()))) {
			url = sysConfig.getImageWebServer();
		}
		
		String goods_main_photo = url + "/" + sysConfig.getGoodsImage().getPath() + "/" + sysConfig.getGoodsImage().getName();
		
		if (obj.getGoods_main_photo() != null) {
			goods_main_photo = url 
					+ "/" + obj.getGoods_main_photo().getPath() + "/"
					+ obj.getGoods_main_photo().getName() + "_small."
					+ obj.getGoods_main_photo().getExt();
		}
		if (fps.size() == 0) {
			FootPoint fp = new FootPoint();
			fp.setAddTime(new Date());
			fp.setFp_date(new Date());
			fp.setFp_user_id(user.getId());
			fp.setFp_user_name(user.getUsername());
			fp.setFp_goods_count(1);
			Map<String, Object> map = Maps.newHashMap();
			map.put("goods_id", obj.getId());
			map.put("goods_name", obj.getGoods_name());
			map.put("goods_dis_money", obj.getDis_money());
			map.put("goods_sale", Integer.valueOf(obj.getGoods_salenum()));
			map.put("goods_time", CommUtil.formatLongDate(new Date()));
			map.put("goods_img_path", goods_main_photo);
			map.put("goods_price", obj.getGoods_current_price());
			map.put("goods_class_id", CommUtil.null2Long(obj.getGc_id()));
			map.put("goods_class_name",CommUtil.null2String(goodsClass.getClassName()));
			List<Map> list = Lists.newArrayList();
			list.add(map);
			fp.setFp_goods_content(JSON.toJSONString(list));
			this.footPointService.saveEntity(fp);
			return true;
		} else {
			FootPoint fp = (FootPoint) fps.get(0);
			List<Map> list = JSON.parseArray(fp.getFp_goods_content(),Map.class);
			boolean add = true;
			for (Map map : list) {
				if (CommUtil.null2Long(map.get("goods_id")).equals(obj.getId())) {
					add = false;
				}
			}
			if (add) {
				Map<String, Object> map = Maps.newHashMap();
				map.put("goods_id", obj.getId());
				map.put("goods_dis_money", obj.getDis_money());
				map.put("goods_name", obj.getGoods_name());
				map.put("goods_sale", obj.getGoods_salenum());
				map.put("goods_time", CommUtil.formatLongDate(new Date()));
				map.put("goods_img_path", goods_main_photo);
				map.put("goods_price", obj.getGoods_current_price());
				map.put("goods_class_id",CommUtil.null2Long(obj.getGc_id()));
				map.put("goods_class_name",CommUtil.null2String(goodsClass.getClassName()));
				list.add(0, map);
				fp.setFp_goods_count(list.size());
				fp.setFp_goods_content(JSON.toJSONString(list));
				this.footPointService.updateById(fp);
			}
			return add;
		}
	}
	
	
	/**
	 * 用戶中心足跡
	 * @param request
	 * @param response
	 * @param currentPage
	 * @param orderBy
	 * @param orderType
	 * @return
	 */
	@RequestMapping(value="/buyer/foot_point", method = RequestMethod.POST)
	public Map<String, Object> foot_point(HttpServletRequest request, HttpServletResponse response) {
		
		Map<String, Object> result = new HashMap<String, Object>();
		UserDto user = SecurityUserHolder.getCurrentUser(request);
		if (user != null) {
			Map<String,Object> maps= queryTools.getParams("1", "addTime", "desc");
	        maps.put("fp_user_id", user.getId());
	        
			Page<FootPoint> pList = this.footPointService.list(maps);
			result.put("objs", pList.getResult());
			result.put("totalPage", Integer.valueOf(pList.getPages()));
		} else {
			return ResponseCode.buildEnumMap(ResponseCode.UNLOGIN_ERROR, null);
		}
		return ResponseCode.buildSuccessMap(result);
	}
	
	
	/**
	 * 足跡刪除
	 * @param request
	 * @param response
	 * @param date
	 * @param goods_id
	 */
	@SuppressWarnings({"rawtypes" })
	@RequestMapping(value="/buyer/foot_point_remove", method = RequestMethod.POST)
	public Map<String, Object> foot_point_remove(HttpServletRequest request,
			HttpServletResponse response, @RequestBody JSONObject json) {
		String date = json.optString("date");
		String id = json.optString("id");
		
		
		boolean ret = false;
		if ((CommUtil.null2String(date).equals(""))
				&& (CommUtil.null2String(id).equals(""))) {
			Map<String, Object> params = Maps.newHashMap();
			params.put("fp_user_id", SecurityUserHolder.getCurrentUser(request)
					.getId());
			
			List<FootPoint> fps = this.footPointService.queryPageList(params);
			
			for (FootPoint fp : fps) {
				this.footPointService.deleteById(fp.getId());
			}
			ret = true;
		}
		if ((!CommUtil.null2String(date).equals(""))
				&& (CommUtil.null2String(id).equals(""))) {
			Map<String, Object> params = Maps.newHashMap();
			params.put("fp_date", CommUtil.formatDate(date));
			params.put("fp_user_id", SecurityUserHolder.getCurrentUser(request).getId());
			
			List<FootPoint> fps = this.footPointService.queryPageList(params);
			
			for (FootPoint fp : fps) {
				this.footPointService.deleteById(fp.getId());
			}
			ret = true;
		}
		if ((!CommUtil.null2String(date).equals(""))
				&& (!CommUtil.null2String(id).equals(""))) {
			Map<String, Object> params = Maps.newHashMap();
			params.put("fp_date", CommUtil.formatDate(date));
			params.put("fp_user_id", SecurityUserHolder.getCurrentUser(request)
					.getId());
			
			List<FootPoint> fps = this.footPointService.queryPageList(params);
			
			for (FootPoint fp : fps) {
				List<Map> list = JSON.parseArray(fp.getFp_goods_content(),
						Map.class);
				for (Map map : list) {
					if (CommUtil.null2String(map.get("goods_id")).equals(
							id)) {
						list.remove(map);
						break;
					}
				}
				fp.setFp_goods_content(JSON.toJSONString(list));
				fp.setFp_goods_count(list.size());
				this.footPointService.updateById(fp);
			}
			ret = true;
		}
		
		if(ret){
			return ResponseCode.buildSuccessMap("刪除成功");
		}else{
			return ResponseCode.buildCodeMap("20001", "刪除失敗", null);
		}
	}	
	
	/**
	 * 足跡下拉加載
	 * @param request
	 * @param response
	 * @param goods_id
	 * @param currentPage
	 * @param orderBy
	 * @param orderType
	 * @return
	 */
	@RequestMapping(value="/buyer/foot_point_ajax", method = RequestMethod.POST)
	public Map<String, Object> foot_point_ajax(HttpServletRequest request,
			HttpServletResponse response, @RequestBody JSONObject json) {
		String currentPage = json.optString("currentPage");
		String orderBy = json.optString("orderBy");
		String orderType = json.optString("orderType");
		
		
		Map<String, Object> result = new HashMap<String, Object>();
		User user = userService.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
		
		Map<String,Object> maps= queryTools.getParams(currentPage, orderBy, orderType);
        maps.put("fp_user_id", user.getId());
        
		Page<FootPoint> pList = this.footPointService.list(maps);
		result.put("objs", pList.getResult());
		result.put("totalPage", Integer.valueOf(pList.getPages()));
		// result.put("footPointTools", this.footPointTools);
		return ResponseCode.buildSuccessMap(result);
	}
}
@源碼地址來源: https://minglisoft.cn/honghu/business.html

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章