获取源码可搜索体验小程序: 海哇
@源码地址来源: https://minglisoft.cn/honghu/business.html
package com.honghu.cloud.controller;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.honghu.cloud.bean.LiveBaby;
import com.honghu.cloud.bean.LiveOrder;
import com.honghu.cloud.dto.AccessoryDto;
import com.honghu.cloud.dto.GoodsClassDto;
import com.honghu.cloud.dto.GoodsDto;
import com.honghu.cloud.dto.OrderFormDto;
import com.honghu.cloud.feign.AccessoryFeignClient;
import com.honghu.cloud.feign.GoodsClassFeignClient;
import com.honghu.cloud.feign.GoodsFeignClient;
import com.honghu.cloud.feign.OrderFormFeignClient;
import com.honghu.cloud.service.ILiveOrderService;
import com.honghu.cloud.service.LiveBabyService;
import com.honghu.cloud.util.CommUtil;
/**
* 直播间订单控制器
* @author Administrator
*
*/
@RestController
@RequestMapping(value="/liveOrder")
public class LiveOrderController {
@源码地址来源: https://minglisoft.cn/honghu/business.html
@Autowired
private ILiveOrderService liveOrderService;
@Autowired
private OrderFormFeignClient orderformfeignclient;
@Autowired
private GoodsFeignClient goodsFeignClient;
@Autowired
private GoodsClassFeignClient goodsClassFeignClient;
@Autowired
private AccessoryFeignClient accessoryFeignClient;
@Autowired
private LiveBabyService liveBabyService;
/**
* 创建直播商品订单快照
* @param order
* @param localPath
* @param buyer
*/
@RequestMapping(value = "/apiForFeign/createLiveOrder", method = RequestMethod.POST)
public void createLiveOrder(@RequestBody OrderFormDto order) {
List<Map> goods_maps = queryGoodsInfo(order.getGoods_info());
for (Map obj : goods_maps) {
String liveroom_id = CommUtil.null2String(obj.get("liveroom_id"));
if (StringUtils.isEmpty(liveroom_id)||liveroom_id.equals("-1")) {
continue; // 如果直播房间号为空,不继续, 只存有直播的商品
}
String goods_id = CommUtil.null2String(obj.get("goods_id"));
GoodsDto goods = goodsFeignClient.selectByPrimaryKey(CommUtil.null2Long(goods_id));
HashMap<String, Object> params = new HashMap<>();
params.put("goods_id", obj.get("goods_id"));
params.put("live_id", liveroom_id);
List<LiveBaby> queryPages = liveBabyService.queryPages(params);
if (queryPages.size()!=0&&queryPages.get(0).getPay_status()!=null&& queryPages.get(0).getPay_status()==0) {//若该直播商品不是已购状态,将此商品修改成已购状态
queryPages.get(0).setPay_status(1);
liveBabyService.updateById(queryPages.get(0));
}
String goods_name = CommUtil.null2String(obj.get("goods_name"));
String goods_price = CommUtil.null2String(obj.get("goods_price"));
String goods_all_price = CommUtil.null2String(obj.get("goods_all_price"));
String goods_gsp_val = CommUtil.null2String(obj.get("goods_gsp_val"));
String goods_count = CommUtil.null2String(obj.get("goods_count"));
String Good_pack_details = goods.getPack_details();
String Good_service = goods.getGoods_service();
String goods_cod = CommUtil.null2String(Integer.valueOf(goods.getGoods_cod()));//不支持货到付款
LiveOrder liveorder = new LiveOrder();
liveorder.setAll_price(BigDecimal.valueOf(CommUtil.null2Double(goods_all_price)));
liveorder.setGood_id(goods_id);
liveorder.setLiveroom_id(CommUtil.null2Long(liveroom_id));
liveorder.setOrder_id(CommUtil.null2String(order.getId()));
liveorder.setGood_name(goods_name);
liveorder.setGood_price(goods_price);
liveorder.setGood_info(goods_gsp_val);
liveorder.setOrder_status(10);
liveorder.setDeleteStatus(0);
liveorder.setAddTime(new Date());
liveorder.setGood_num(goods_count);
liveorder.setGood_pack_details(Good_pack_details);
liveorder.setGoods_service(Good_service);
liveorder.setUser_id(CommUtil.null2Long(order.getUser_id()));
liveorder.setGood_cod(goods_cod);
liveorder.setOrder_id(CommUtil.null2String(order.getId()));
if ((goods.getDelivery_area() != null) && (!"".equals(goods.getDelivery_area()))) {
String good_add = goods.getDelivery_area();
liveorder.setAddress(good_add);
} else {
liveorder.setAddress("无发货地址");
}
if (goods.getGoods_store_id() != null) {
liveorder.setStore_id(goods.getGoods_store_id());
}
GoodsClassDto goods_goodsclass = goodsClassFeignClient.selectByPrimaryKey(goods.getGc_id());
liveorder.setGc(goods_goodsclass.getClassName());
liveorder.setGood_source(String.valueOf(goods.getGoods_type()));
if (goods.getActivity_status() == 2) {
liveorder.setActivity_status("1");
}
if (goods.getGroup_buy() == 2) {
liveorder.setActivity_status("2");
}
if ((goods.getBuyGift_id() != null) && (goods.getOrder_enough_give_status() == 1)) {
liveorder.setActivity_status("3");
}
AccessoryDto main_img=null;
if (goods.getGoods_main_photo_id()!=null) {
main_img = accessoryFeignClient.selectByPrimaryKey(goods.getGoods_main_photo_id());
}
if (main_img != null) {
liveorder.setGood_mian_img(
main_img.getPath() + "/" + main_img.getName() + "_small." + main_img.getExt());
} else {
liveorder.setGood_mian_img(null);
}
this.liveOrderService.saveEntity(liveorder);
if (order.getChild_order_detail() != null) {
List<Map> child_maps = queryGoodsInfo(order.getChild_order_detail());
for (Map c_map : child_maps) {
OrderFormDto c_order = this.orderformfeignclient
.selectByPrimaryKey(CommUtil.null2Long(c_map.get("order_id")));
createLiveOrder(c_order);
}
}
}
}
/**
* 把商品json转换成map
* @param json
* @return
*/
public List<Map> queryGoodsInfo(String json) {
List<Map> map_list = Lists.newArrayList();
if ((json != null) && (!json.equals(""))) {
map_list = JSON.parseArray(json, Map.class);
}
return map_list;
}
/**
* 创建直播商品订单快照
* @param order
* @param localPath
* @param buyer
*/
@RequestMapping(value = "/apiForFeign/updateLiveOrder", method = RequestMethod.POST)
public void updateLiveOrder(@RequestBody OrderFormDto order) {
String payment_mark = order.getPayment_mark();
String payment_name = order.getPayment_name();
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("order_id", order.getId());
hashMap.put("payment_mark", payment_mark);
hashMap.put("payment_name", payment_name);
hashMap.put("order_status", 20);
liveOrderService.updatePay(hashMap);
}
}
@源码地址来源: https://minglisoft.cn/honghu/business.html
@源码地址来源: https://minglisoft.cn/honghu/business.html