源码地址来源: https://minglisoft.cn/honghu2/business.html
package com.honghu.cloud.controller;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.honghu.cloud.bean.DaDaAppConfig;
import com.honghu.cloud.bean.DaDaService;
import com.honghu.cloud.bean.DadaApiResponse;
import com.honghu.cloud.bean.ShopAddModel;
import com.honghu.cloud.bean.Store;
import com.honghu.cloud.code.ResponseCode;
import com.honghu.cloud.dto.AreaDto;
import com.honghu.cloud.dto.CouponInfoDto;
import com.honghu.cloud.dto.EvaluateDto;
import com.honghu.cloud.dto.ExpressCompanyCommonDto;
import com.honghu.cloud.dto.ExpressCompanyDto;
import com.honghu.cloud.dto.ExpressInfoDto;
import com.honghu.cloud.dto.GoodsDto;
import com.honghu.cloud.dto.MessageDto;
import com.honghu.cloud.dto.OrderFormDto;
import com.honghu.cloud.dto.OrderFormLogDto;
import com.honghu.cloud.dto.RefundApplyFormDto;
import com.honghu.cloud.dto.ReturnGoodsLogDto;
import com.honghu.cloud.dto.ShipAddressDto;
import com.honghu.cloud.dto.SysConfigDto;
import com.honghu.cloud.dto.TransInfoDto;
import com.honghu.cloud.dto.UserDto;
import com.honghu.cloud.feign.AreaFeignClient;
import com.honghu.cloud.feign.CouponInfoFeignClient;
import com.honghu.cloud.feign.EvaluateFeignClient;
import com.honghu.cloud.feign.ExpressCompanyCommonFeignClient;
import com.honghu.cloud.feign.ExpressCompanyFeignClient;
import com.honghu.cloud.feign.ExpressInfoFeignClient;
import com.honghu.cloud.feign.GoodsFeignClient;
import com.honghu.cloud.feign.MessageFeignClient;
import com.honghu.cloud.feign.ModularClassFeignClient;
import com.honghu.cloud.feign.MsgToolsFeignClient;
import com.honghu.cloud.feign.OrderFormFeignClient;
import com.honghu.cloud.feign.OrderFormLogFeignClient;
import com.honghu.cloud.feign.OrderFormToolsFeignClient;
import com.honghu.cloud.feign.RefundApplyFormFeignClient;
import com.honghu.cloud.feign.ReturnGoodsLogFeignClient;
import com.honghu.cloud.feign.ShipAddressFeignClient;
import com.honghu.cloud.feign.ShipToolsFeignClient;
import com.honghu.cloud.feign.SysConfigFeignClient;
import com.honghu.cloud.feign.UserFeignClient;
import com.honghu.cloud.service.IStoreService;
import com.honghu.cloud.tools.DadaRequestClient;
import com.honghu.cloud.tools.JSONUtil;
import com.honghu.cloud.tools.QueryTools;
import com.honghu.cloud.tools.SecurityUserHolder;
import com.honghu.cloud.utils.CommUtil;
import com.honghu.cloud.utils.StringUtils;
import com.honghu.cloud.utils.tools.Md5Encrypt;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
@CrossOrigin(origins = "*", maxAge = 3600)
@Slf4j
@RestController
@RequestMapping(value = "/applet/storeOrder")
public class AppletStoreOrderController {
private final Logger logger = LoggerFactory.getLogger(AppletStoreOrderController.class);
@Autowired
private IStoreService storeService;
@Autowired
private OrderFormFeignClient orderFormFeignClient;
@Autowired
private UserFeignClient userFeignClient;
@Autowired
private GoodsFeignClient goodsFeignClient;
@Autowired
private QueryTools queryTools;
@Autowired
private RefundApplyFormFeignClient refundapplyformfeignclient;
@Autowired
private MessageFeignClient messagefeignclient;
@Autowired
private ReturnGoodsLogFeignClient returnGoodsLogFeignClient;
@Autowired
private ShipToolsFeignClient shipToolsFeignClient;
@Autowired
private OrderFormToolsFeignClient orderFormToolsFeignClient;
@Autowired
private OrderFormLogFeignClient orderFormLogFeignClient;
@Autowired
private MsgToolsFeignClient msgToolsFeignClient;
@Autowired
private ExpressCompanyCommonFeignClient companyCommonFeignClient;
@Autowired
private ShipAddressFeignClient shipAddressFeignClient;
@Autowired
private SysConfigFeignClient sysConfigFeignClient;
@Autowired
private ExpressInfoFeignClient expressInfoFeignClient;
@Autowired
private EvaluateFeignClient evaluateFeignClient;
@Autowired
private ExpressCompanyFeignClient expressCompanyFeignClient;
@Autowired
private ExpressCompanyCommonFeignClient expressCompanyCommonFeignClient;
@Autowired
private AreaFeignClient areaFeignClient;
@Autowired
private ModularClassFeignClient modularClassFeignClient;
@Autowired
private CouponInfoFeignClient couponInfoFeignClient;
/**
* 卖家订单列表
* @param request
* @param response
* @param currentPage
* @param order_status
* @param order_id
* @param beginTime
* @param endTime
* @param buyer_userName
* @return
*/
@RequestMapping( value = { "/order" } , method = RequestMethod.POST)
public Map<String,Object> order(HttpServletRequest request,
@RequestBody JSONObject json) {
String currentPage = json.optString("currentPage");
String order_status = json.optString("order_status");
String order_id = json.optString("order_id");
/*String beginTime = json.optString("beginTime");
String endTime = json.optString("endTime");*/
String order_id_userName = json.optString("order_id_userName");
Map<String,Object> maps= this.queryTools.getParams(currentPage,"addTime", "desc");
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
if(user.getStore_id() == null){
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store != null){
maps.put("store_id", store.getId());
}else{
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
/* maps.put("order_cat_no", 2);
*/ Map<String, Object> map = Maps.newHashMap();
if (!CommUtil.null2String(order_status).equals("")) {
if (order_status.equals("order_submit")) {//代付款
maps.put("order_status1", Integer.valueOf(10));
maps.put("order_status2", Integer.valueOf(16));
}
if (order_status.equals("order_pay")) { //代发货
maps.put("order_status1", Integer.valueOf(20));
maps.put("order_status2", Integer.valueOf(14));
}
if (order_status.equals("order_shipping")) {//待收货 已发货
//maps.put("order_status", Integer.valueOf(30));
maps.put("order_status_0", Integer.valueOf(30));
maps.put("order_status_1", Integer.valueOf(31));
maps.put("order_status_2", Integer.valueOf(32));
}
if (order_status.equals("order_evaluate")) {// 已收货 待评价
maps.put("order_status", Integer.valueOf(40));
}
if (order_status.equals("order_finish")) { //评论完
maps.put("order_status", Integer.valueOf(50));
}
if (order_status.equals("order_cancel")) {//订单取消
maps.put("order_status", Integer.valueOf(0));
}
if (order_status.equals("order_refund")) {//退款中
maps.put("order_status", Integer.valueOf(21));
}
}
if (!CommUtil.null2String(order_id).equals("")) {
maps.put("order_id_like", order_id);
}
/*if (!CommUtil.null2String(beginTime).equals("")) {
maps.put("add_Time_more_than_equal", CommUtil.formatDate(beginTime));
map.put("beginTime", beginTime);
}
if (!CommUtil.null2String(endTime).equals("")) {
String ends = endTime + " 23:59:59";
maps.put("add_Time_less_than_equal", CommUtil.formatDate(ends,"yyyy-MM-dd hh:mm:ss"));
map.put("endTime", endTime);
}*/
if (!CommUtil.null2String(order_id_userName).equals("")) {
maps.put("order_id_userName", order_id_userName);
}
Map<String, Object> list = this.orderFormFeignClient.list(maps);
map.putAll(list);
/*map.put("list", list);*/
map.put("order_id", order_id);
map.put("order_status", order_status == null ? "all" : order_status);
return ResponseCode.buildSuccessMap(map);
}
/**
* 卖家订单
* @param request
* @param response
* @param currentPage
* @param order_status
* @param order_id
* @param beginTime
* @param endTime
* @param buyer_userName
* @return
*/
@RequestMapping( value = { "/orderHome" } , method = RequestMethod.POST)
public Map<String,Object> orderHome(HttpServletRequest request) {
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
if(user.getStore_id() == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
Map<String, Object> map = Maps.newHashMap();
map.put("store_id", store.getId());
//代付款1
map.put("order_status1", Integer.valueOf(10));
map.put("order_status2", Integer.valueOf(16));
Integer order_submit = this.orderFormFeignClient.selectCount(map);
//代发货1
map.clear();
map.put("store_id", store.getId());
map.put("order_status", Integer.valueOf(20));
Integer order_pay = this.orderFormFeignClient.selectCount(map);
//待收货 已发货 1
map.clear();
map.put("store_id", store.getId());
map.put("order_status", Integer.valueOf(30));
Integer order_shipping = this.orderFormFeignClient.selectCount(map);
// 已收货 待评价1
map.clear();
map.put("store_id", store.getId());
map.put("order_status", Integer.valueOf(40));
Integer order_evaluate = this.orderFormFeignClient.selectCount(map);
//退款中1
map.clear();
map.put("store_id", store.getId());
map.put("refundStatus", 1);
Integer order_refund = this.orderFormFeignClient.selectCount(map);
map.put("selectCount_refund", order_refund);
map.clear();
map.put("store_id", user.getStore_id());
int selectCount = this.returnGoodsLogFeignClient.selectCount(map);
if(order_refund == null){
order_refund = 0;
}
order_refund = order_refund + selectCount;
map.clear();
map.put("order_submit", order_submit);
map.put("order_pay", order_pay);
map.put("order_shipping", order_shipping);
map.put("order_evaluate", order_evaluate);
map.put("order_refund", order_refund);
return ResponseCode.buildSuccessMap(map);
}
/**订单详情
* @param request
* @param json
* @return
*/
@RequestMapping(value = { "/order_view" } , method = RequestMethod.POST)
public Map<String , Object> order_view(HttpServletRequest request,
@RequestBody JSONObject json) {
String id = json.optString("id");
OrderFormDto obj = this.orderFormFeignClient
.selectByPrimaryKey(CommUtil.null2Long(id));
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(obj
.getStore_id()));
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
if(user.getStore_id() == null){
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
if (user.getStore_id().equals(store.getId())) {
Map<String , Object> maps = Maps.newHashMap();
if(obj.getOrder_status() == 10){
SysConfigDto sys = this.sysConfigFeignClient.getSysConfig();
Integer auto_order_cancel = sys.getAuto_order_cancel();
Date addTime = obj.getAddTime();
Date date = new Date();
/*System.out.println(((addTime.getTime() - date.getTime()) / (24 * 60 * 60 * 1000))/ 365 + "年");
System.out.println((addTime.getTime() - date.getTime()) / (24 * 60 * 60 * 1000) + "天");
System.out.println((((addTime.getTime() - date.getTime()) / (60 * 60 * 1000)) % 24) + "小时");
System.out.println((((addTime.getTime() - date.getTime()) / 1000) % 60) + "分钟");
System.out.println(((addTime.getTime() - date.getTime()) / (60 * 1000)) % 60 + "秒");*/
maps.put("obj", obj);
maps.put("second", (((addTime.getTime() - date.getTime()) / 1000)) + auto_order_cancel*60*60);
}
maps.put("obj", obj);
return ResponseCode.buildSuccessMap(maps);
} else {
return ResponseCode.buildEnumMap(ResponseCode.FAILURE, null);
}
}
/**
* 卖家取消订单
* @param request
* @param response
* @param id
* @param currentPage
* @return
*/
@RequestMapping(value ={ "/order_cancel" } ,method = RequestMethod.POST)
public Map<String , Object> order_cancel(HttpServletRequest request , @RequestBody JSONObject jsonv) {
String id = jsonv.optString("id");
if (SecurityUserHolder.getCurrentUserId(request)==null) {
return ResponseCode.buildCodeMap("1111", "userid为空", null);
}
UserDto seller = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
OrderFormDto obj = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
if(seller == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
if (seller.getParent_id()!=null) {
seller = this.userFeignClient.selectByPrimaryKey(seller.getParent_id());
}
//user = user.getParent_id() == null ? user : user.getParent();
if(seller.getStore_id() == null){
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
//System.out.println("---------user--getStore_id-------------"+seller
//.getStore_id());
Store store = this.storeService.selectByPrimaryKey(seller
.getStore_id());
//System.out.println("---------user---------------"+seller.getId());
//System.out.println("------------obj-------------"+obj.getId());
//System.out.println("---------seller---------------"+seller.getStore_id());
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
System.out.println("-----------store--------------"+store.getId());
if ((seller.getStore_id() != null)&& (CommUtil.null2String(obj.getStore_id()).equals(seller.getStore_id().toString()))) {
return ResponseCode.buildSuccessMap(obj);
} else {
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
}
/**
* 卖家取消订单保存
* @param request
* @param response
* @param id
* @param currentPage
* @return
*/
@RequestMapping(value ={ "/order_cancel_save" } ,method = RequestMethod.POST)
public Map<String , Object> order_cancel_save(HttpServletRequest request , @RequestBody JSONObject jsonv) {
String id = jsonv.optString("id");
String state_info = jsonv.optString("state_info");
String other_state_info = jsonv.optString("other_state_info");
UserDto seller = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
OrderFormDto obj = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
if(seller == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
if (seller.getParent_id()!=null) {
seller = this.userFeignClient.selectByPrimaryKey(seller.getParent_id());
}
//user = user.getParent_id() == null ? user : user.getParent();
if(seller.getStore_id() == null){
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(seller
.getStore_id()));
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
Date nowDate = new Date();
if ((seller.getStore_id() != null)&& (CommUtil.null2String(obj.getStore_id()).equals(seller.getStore_id().toString()))) {
obj.setOrder_status(0);
if ((obj.getCoupon_info() != null)
&& (!"".equals(obj.getCoupon_info()))) {
Map m = JSON.parseObject(obj.getCoupon_info());
CouponInfoDto cpInfo = this.couponInfoFeignClient.selectByPrimaryKey(CommUtil
.null2Long(m.get("couponinfo_id")));
if (cpInfo != null) {
if (nowDate.before(cpInfo.getEndDate())) {
cpInfo.setStatus(0);
} else {
cpInfo.setStatus(-1);
}
}
}
orderFormFeignClient.updateById(obj);
OrderFormLogDto ofl = new OrderFormLogDto();
ofl.setAddTime(new Date());
ofl.setLog_info("取消订单");
ofl.setLog_user_id(seller.getId());
ofl.setLog_user_name(seller.getUserName());
ofl.setOf_id(obj.getId());
if (state_info.equals("其他原因")) {
ofl.setState_info(other_state_info);
} else {
ofl.setState_info(state_info);
}
this.orderFormLogFeignClient.saveEntity(ofl);
/* UserDto buyer = this.userFeignClient.selectByPrimaryKey(CommUtil.null2Long(obj
.getUser_id()));
Map<String, Object> map = Maps.newHashMap();
map.put("buyer_id", buyer.getId().toString());
map.put("seller_id", store.getUser_id());
map.put("order_id", obj.getId());
String json = JSON.toJSONString(map);*/
/*if (obj.getOrder_form() == 0) {
try {
this.msgToolsFeignClient.sendEmailCharge(CommUtil.getURL(request),
"email_tobuyer_order_cancel_notify", buyer.getEmail(),
json, null, obj.getStore_id());
this.msgToolsFeignClient.sendSmsCharge(CommUtil.getURL(request),
"sms_tobuyer_order_cancel_notify", buyer.getMobile(),
json, null, obj.getStore_id());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
try {
this.msgToolsFeignClient.sendEmailFree(CommUtil.getURL(request),
"email_tobuyer_order_cancel_notify", buyer.getEmail(),
json, null);
this.msgToolsFeignClient.sendSmsFree(CommUtil.getURL(request),
"sms_tobuyer_order_cancel_notify", buyer.getMobile(),
json, null);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}*/
return ResponseCode.buildSuccessMap(null);
} else {
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
}
/**
* 订单退款申请单
* @param request
* @param response
* @param currentPage
* @param orderBy
* @param orderType
* @param status
* @return
*/
@RequestMapping(value = { "/refund_apply_form" } , method = RequestMethod.POST)
public Map<String,Object> refund_apply_form(HttpServletRequest request,
@RequestBody JSONObject json) {
String currentPage = json.optString("currentPage");
String orderType = json.optString("orderType");
String orderBy = json.optString("orderBy");
//状态 0:待审核 5:审核拒绝 10:审核通过待退款 15:已退款
String refundStatus = json.optString("refundStatus");
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
if(user.getStore_id() == null){
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
Map<String,Object> maps= this.queryTools.getParams(currentPage, orderBy, orderType);
if ((refundStatus == null) || (refundStatus.equals(""))) {
maps.put("refundStatus", CommUtil.null2Int(Integer.valueOf(0)));
} else {
maps.put("refundStatus", CommUtil.null2Int(Integer.valueOf(refundStatus)));
}
if(store != null){
maps.put("store_id", store.getId());
}else{
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
Map<String, Object> data = this.orderFormFeignClient.refundApplyFormList(maps);
data.put("refundStatus", refundStatus);
return ResponseCode.buildSuccessMap(data);
}
/**
* 订单退款申请单详情
* @param request
* @param response
* @param order_id
* @return
*/
@RequestMapping(value = { "/refund_orderform_view" } , method = RequestMethod.POST)
public Map<String,Object> refund_orderform_view(HttpServletRequest request, @RequestBody JSONObject json) {
Map<Object, Object> map = Maps.newHashMap();
map.put("reason","");
if (StringUtils.isBlank(json.optString("order_id"))) {
return ResponseCode.buildReturnMap(ResponseCode.PARAM_ERROR, null);
}
String apply_from_id = json.optString("apply_from_id");
if (StringUtils.isBlank(apply_from_id)) {
return ResponseCode.buildReturnMap(ResponseCode.PARAM_ERROR, null);
}
OrderFormDto obj = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(json.optString("order_id")));
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(obj.getStore_id()));
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
RefundApplyFormDto RefundApplyFormDto = refundapplyformfeignclient.selectByPrimaryKey(CommUtil.null2Long(apply_from_id));
if(RefundApplyFormDto!=null){
map.put("reason",RefundApplyFormDto.getReturn_content()); //退款原因
}
//user = user.getParent_id() == null ? user : user.getParent();
if(user.getStore_id() == null){
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.REQUEST_FORBIDDEN, null);
}
if(!user.getStore_id().equals(store.getId()) ||store.getStore_status()!=15){ //验证是否是当前商家 , 并且正常营业
return ResponseCode.buildReturnMap(ResponseCode.REQUEST_FORBIDDEN, null);
}
if (obj != null) {
String temp = obj.getSpecial_invoice();
if ((temp != null) && (!"".equals(temp))) {
Map of_va = JSON.parseObject(temp);
map.put("of_va", of_va);
}
}
map.put("obj", obj);
String queryExInfo = this.queryExInfo(obj.getExpress_info(), "express_company_name");
map.put("store", store);
map.put("express_company_name", queryExInfo);
//map.put("express_company_name", this.orderFormTools.queryExInfo(obj.getExpress_info(), "express_company_name"));
ReturnGoodsLogDto returnGoodsLogDto = returnGoodsLogFeignClient.selectByOrderId(obj.getId());
map.put("returnGoodsLogDto", returnGoodsLogDto);
return ResponseCode.buildSuccessMap(map);
}
public String queryExInfo(String json, String key) {
Map<String, Object> map = Maps.newHashMap();
if ((json != null) && (!json.equals(""))) {
map = JSON.parseObject(json);
}
return CommUtil.null2String(map.get(key));
}
/**
* 订单退款申请单审核
* @param request
* @param result
* @param apply_form_id
* @param currentPage
* @return
*/
@RequestMapping({ "/refund_audit" })
public Map<String, Object> refund_audit(HttpServletRequest request, @RequestBody JSONObject json) {
UserDto user = SecurityUserHolder.getCurrentUser(request);
Store store = null ;
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
RefundApplyFormDto refundApplyForm = this.refundapplyformfeignclient
.selectByPrimaryKey(CommUtil.null2Long(json.optString("apply_from_id")));
//TODO
//Store store = (user.getParent() == null ? user : user.getParent()).getStore();
if ((store != null) && (store.getId().toString().equals(refundApplyForm.getStore_id()))&&refundApplyForm.getOrder_form_id()!=null) {
OrderFormDto orderForm = this.orderFormFeignClient.selectByPrimaryKey(refundApplyForm.getOrder_form_id());
refundApplyForm.setAudit_date(new Date());
refundApplyForm.setAudit_user_name(user.getUserName());
if (StringUtils.isNotBlank(json.optString("result"))) {
refundApplyForm.setStatus(10);
this.refundapplyformfeignclient.updateById(refundApplyForm);
orderForm.setOrder_status(22);
this.orderFormFeignClient.updateById(orderForm);
MessageDto msg = new MessageDto();
String msg_content = "您订单号为:" + orderForm.getOrder_id() + "的订单退款申请已通过,我们会尽快将" + "退款金额打入您的预存款中。";
msg.setAddTime(new Date());
msg.setStatus(0);
msg.setType(0);
msg.setContent(msg_content);
//msg.setFromu(user);
//msg.setToUser(this.userFeignClient.selectByPrimaryKey(CommUtil.null2Long(orderForm.getUser_id())));
msg.setFromUser_id(user.getId());
msg.setToUser_id(CommUtil.null2Long(orderForm.getUser_id()));
this.messagefeignclient.saveEntity(msg);
} else {
refundApplyForm.setStatus(5);
this.refundapplyformfeignclient.updateById(refundApplyForm);
orderForm.setOrder_status(20);
this.orderFormFeignClient.updateById(orderForm);
MessageDto msg = new MessageDto();
String msg_content = "您订单号为:" + orderForm.getOrder_id() + "的订单退款申请未通过。";
msg.setAddTime(new Date());
msg.setStatus(0);
msg.setType(0);
msg.setContent(msg_content);
msg.setFromUser(user);
msg.setToUser_id(CommUtil.null2Long(orderForm.getUser_id()));
this.messagefeignclient.saveEntity(msg);
}
}else {
//店铺不存在, 或者登录用户不为该订单商铺
return ResponseCode.buildReturnMap(ResponseCode.REQUEST_FORBIDDEN, null);
}
return ResponseCode.buildSuccessMap(null);
}
/**
* 退货列表
* @param request
* @param response
* @param currentPage
* @param orderBy
* @param orderType
* @param name
* @param user_name
* @param return_service_id
* @return
*/
@RequestMapping(value = { "/return" } , method = RequestMethod.POST)
public Map<String, Object> seller_return(HttpServletRequest request,@RequestBody JSONObject json) {
String currentPage = json.optString("currentPage");
String orderBy = json.optString("orderBy");
String orderType = json.optString("orderType");
String name = json.optString("name");
String user_name = json.optString("user_name");
String return_service_id = json.optString("return_service_id");
Map<String,Object> maps= this.queryTools.getParams(currentPage, "addTime", "desc");
maps.put("goods_type", 1);
if ((user_name != null) && (!user_name.equals(""))) {
maps.put("user_name", user_name);
}
if ((name != null) && (!name.equals(""))) {
maps.put("goods_name_like", name);
}
if ((return_service_id != null) && (!return_service_id.equals(""))) {
maps.put("return_service_id", return_service_id);
}
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
//user = user.getParent_id() == null ? user : user.getParent();
if(user.getStore_id() == null){
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store != null){
maps.put("store_id", store.getId());
}else{
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
maps.put("store_id", user.getStore_id());
Map<String , Object> data = this.returnGoodsLogFeignClient.list(maps);
data.put("name", name);
data.put("user_name", user_name);
data.put("return_service_id", return_service_id);
data.put("store", store);
return ResponseCode.buildSuccessMap(data);
}
/**
* 退货详情数据
* @param request
* @param response
* @param currentPage
* @param id
* @return
*/
@RequestMapping(value = { "/return_check" } , method = RequestMethod.POST)
public Map<String, Object> return_check(HttpServletRequest request,
@RequestBody JSONObject json) {
String id = json.optString("id");
ReturnGoodsLogDto obj = this.returnGoodsLogFeignClient.selectByPrimaryKey(CommUtil
.null2Long(id));
Map<String, Object> map = Maps.newHashMap();
if (obj.getGoods_return_status().equals("7")) {
TransInfoDto transInfo = this.shipToolsFeignClient.query_Ordership_getData(CommUtil.null2String(obj.getId()));
map.put("transInfo", transInfo);
Map<String, Object> mapa = JSON.parseObject(obj
.getReturn_express_info());
//物流名称
map.put("express_company_name",mapa.get("express_company_name"));
}
map.put("obj", obj);
return ResponseCode.buildSuccessMap(map);
}
/**
* 退货订单 审核or拒绝
* @param request
* @param id
* @param goods_return_status
* @param self_address
*/
@RequestMapping( value = { "/return_check_save" } , method = RequestMethod.POST)
public Map<String , Object> return_check_saveEntity(HttpServletRequest request,@RequestBody JSONObject jsonv) {
String id = jsonv.optString("id");
/*String currentPage = jsonv.optString("currentPage");*/
/*String cmd = jsonv.optString("cmd");*/
// 退货商品状态 -2为超过退货时间未能输入退货物流 -1为申请被拒绝 1为可以退货 5为退货申请中 6为审核通过可进行退货 7为退货中 10为退货完成,等待退款,11为平台退款完成
String goods_return_status = jsonv.optString("goods_return_status");
// 收货时向买家发送的收货地址,买家通过此将货物发送给卖家
String self_address = jsonv.optString("self_address");
UserDto seller = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
// UserDto seller = this.userFeignClient.selectByPrimaryKey(445L);
if(seller == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
if (seller.getParent_id()!=null) {
seller = this.userFeignClient.selectByPrimaryKey(seller.getParent_id());
}
//user = user.getParent_id() == null ? user : user.getParent();
if(seller.getStore_id() == null){
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(seller
.getStore_id()));
// Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(62));
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
ReturnGoodsLogDto obj = this.returnGoodsLogFeignClient.selectByPrimaryKey(Long.valueOf(Long.parseLong(id)));
String message = "审核为未通过";
String code = "10001";
if ((seller.getStore_id() != null)&& (CommUtil.null2String(obj.getStore_id()).equals(seller.getStore_id().toString()))) {
obj.setGoods_return_status(goods_return_status);
obj.setSelf_address(self_address);
obj.setRefund_time(new Date()); //审核时间
this.returnGoodsLogFeignClient.updateById(obj);
UserDto user = this.userFeignClient.selectByPrimaryKey(obj.getUser_id());
String msg_content =null;
if (goods_return_status.equals("6")) {
message = "审核通过";
code = "10000";
msg_content = "退货申请审核通过,请在'退货/退款'-'查看返修/退换记录'中提交退货物流信息。";
} else {
/* OrderFormDto of = this.orderFormFeignClient.selectByPrimaryKey(Long.valueOf(obj.getReturn_order_id()));
of.setOrder_status(18); //申请未通过, 用户取消退款确认收货/人工仲裁
this.orderFormFeignClient.updateById(of);*/
message = "提交成功";
code = "10000";
msg_content = "订单号:" + obj.getReturn_service_id()
+ "退货申请审核未通过,请在'退货/退款'-'查看返修/退换记录'中提交退货物流信息。";
}
MessageDto msg = new MessageDto();
msg.setAddTime(new Date());
msg.setStatus(0);
msg.setType(0);
msg.setContent(msg_content);
msg.setFromUser(SecurityUserHolder.getCurrentUser(request));
msg.setToUser(user);
this.messagefeignclient.saveEntity(msg);
} else {
message = "信息有误";
code = "10001";
}
return ResponseCode.buildCodeMap(code,message, null);
}
/**
* 确认退货收货
* @param request
* @param response
* @param id
* @return
*/
@RequestMapping( value = { "/return_confirm" } , method = RequestMethod.POST)
public Map<String , Object> return_confirm(HttpServletRequest request , @RequestBody JSONObject jsonv) {
String id = jsonv.optString("id");
UserDto seller = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
ReturnGoodsLogDto obj = this.returnGoodsLogFeignClient.selectByPrimaryKey(Long.valueOf(Long.parseLong(id)));
if(seller == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
if (seller.getParent_id()!=null) {
seller = this.userFeignClient.selectByPrimaryKey(seller.getParent_id());
}
//user = user.getParent_id() == null ? user : user.getParent();
if(seller.getStore_id() == null){
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
// Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(seller
// .getStore_id()));
Store store = this.storeService.selectByPrimaryKey(seller.getStore_id());
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
if ((seller.getStore_id() != null)&& (CommUtil.null2String(obj.getStore_id()).equals(seller.getStore_id().toString()))) {
obj.setGoods_return_status("10");
this.returnGoodsLogFeignClient.updateById(obj);
}
return ResponseCode.buildSuccessMap(null);
}
/**
* 卖家调整订单费用
* @param request
* @param response
* @param id
* @param currentPage
* @return
*/
@RequestMapping(value = { "/order_fee" } , method = RequestMethod.POST)
public Map<String , Object> order_fee(HttpServletRequest request,
@RequestBody JSONObject json) {
String id = json.optString("id");
OrderFormDto obj = this.orderFormFeignClient
.selectByPrimaryKey(CommUtil.null2Long(id));
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(obj
.getStore_id()));
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
//user = user.getParent_id() == null ? user : user.getParent();
if(user.getStore_id() == null){
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
if (user.getStore_id().equals(store.getId())) {
return ResponseCode.buildSuccessMap(obj);
} else {
return ResponseCode.buildEnumMap(ResponseCode.FAILURE, null);
}
}
/**
* 卖家调整订单费用保存
* @param request
* @param response
* @param id
* @param currentPage
* @param goods_amount
* @param ship_price
* @param totalPrice
* @return
* @throws Exception
*/
@RequestMapping( value = { "/order_fee_save" } , method = RequestMethod.POST)
public Map<String, Object> order_fee_saveEntity(HttpServletRequest request,@RequestBody JSONObject jsonv)
{
String id = jsonv.optString("id");
String goods_amount = jsonv.optString("goods_amount"); //商品总价格
String ship_price = jsonv.optString("ship_price"); // 配送价格
String totalPrice = jsonv.optString("totalPrice"); // 订单总价格
OrderFormDto obj = this.orderFormFeignClient
.selectByPrimaryKey(CommUtil.null2Long(id));
if (CommUtil.null2Double(obj.getCommission_amount()) <= CommUtil
.null2Double(goods_amount)) {
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
if(user.getStore_id() == null){
return ResponseCode.buildReturnMap(ResponseCode.FAILURE,null);
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE,null);
}
//user = user.getParent_id() == null ? user : user.getParent();
if (user.getStore_id().toString().equals(store.getId().toString())) {
obj.setGoods_amount(BigDecimal.valueOf(CommUtil
.null2Double(goods_amount)));
obj.setShip_price(BigDecimal.valueOf(CommUtil
.null2Double(ship_price)));
obj.setTotalPrice(BigDecimal.valueOf(CommUtil
.null2Double(totalPrice)));
obj.setOperation_price_count(obj.getOperation_price_count() + 1);
this.orderFormFeignClient.updateById(obj);
OrderFormLogDto ofl = new OrderFormLogDto();
ofl.setAddTime(new Date());
ofl.setLog_info("调整订单费用");
ofl.setState_info("调整订单总金额为:" + totalPrice + ",调整运费金额为:"
+ ship_price);
ofl.setLog_user_id(SecurityUserHolder.getCurrentUser(request).getId());
ofl.setLog_user_name(SecurityUserHolder.getCurrentUser(request)
.getUserName());
ofl.setOf_id(obj.getId());
this.orderFormLogFeignClient.saveEntity(ofl);
/* UserDto buyer = this.userFeignClient.selectByPrimaryKey(CommUtil.null2Long(obj
.getUser_id()));
Map<String, Object> map = Maps.newHashMap();
map.put("buyer_id", buyer.getId().toString());
map.put("seller_id", store.getUser_id());
map.put("order_id", obj.getId());
String json = JSON.toJSONString(map);
if (obj.getOrder_form() == 0) {
this.msgToolsFeignClient.sendEmailCharge(CommUtil.getURL(request),
"email_tobuyer_order_update_fee_notify",
buyer.getEmail(), json, null, obj.getStore_id());
this.msgToolsFeignClient.sendSmsCharge(CommUtil.getURL(request),
"sms_tobuyer_order_fee_notify", buyer.getMobile(),
json, null, obj.getStore_id());
} else {
this.msgToolsFeignClient.sendEmailFree(CommUtil.getURL(request),
"email_tobuyer_order_update_fee_notify",
buyer.getEmail(), json, null);
this.msgToolsFeignClient.sendSmsFree(CommUtil.getURL(request),
"sms_tobuyer_order_fee_notify", buyer.getMobile(),
json, null);
}*/
}else{
return ResponseCode.buildReturnMap(ResponseCode.FAILURE,null);
}
}else{
return ResponseCode.buildReturnMap(ResponseCode.FAILURE,null);
}
return ResponseCode.buildSuccessMap(null);
}
/**
* 卖家发货
* @param request
* @param response
* @param id
* @param currentPage
* @param page_status
* @return
*/
@RequestMapping(value = { "/order_shipping" } , method = RequestMethod.POST)
public Map<String, Object> order_shipping(HttpServletRequest request,@RequestBody JSONObject json) {
String id = json.optString("id");
String page_status = json.optString("page_status");
OrderFormDto obj = this.orderFormFeignClient
.selectByPrimaryKey(CommUtil.null2Long(id));
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(obj
.getStore_id()));
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store1 = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store1 == null ||store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
//user = user.getParent_id() == null ? user : user.getParent();
if(user.getStore_id() == null){
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
Map<String, Object> map = Maps.newHashMap();
if (user.getStore_id().equals(store.getId())) {
map.put("obj", obj);
List<GoodsDto> list_goods = queryOfGoods(obj);
List<GoodsDto> deliveryGoods = Lists.newArrayList();
boolean physicalGoods = false;
for (GoodsDto g : list_goods) {
if (g.getGoods_choice_type() == 1) {
deliveryGoods.add(g);
} else {
physicalGoods = true;
}
}
Map<String, Object> params = Maps.newHashMap();
params.put("ecc_type", Integer.valueOf(0));
params.put("ecc_store_id", store.getId());
List<ExpressCompanyCommonDto> eccs = this.companyCommonFeignClient.queryPages(params);
params.clear();
params.put("sa_type", Integer.valueOf(0));
params.put("sa_user_id", user.getId());
params.put("orderBy", "obj.sa_default desc,obj.sa_sequence");
params.put("orderType", "asc");
List<ShipAddressDto> shipAddrs = this.shipAddressFeignClient.queryPages(params);
map.put("eccs", eccs);
map.put("shipAddrs", shipAddrs);
map.put("physicalGoods", Boolean.valueOf(physicalGoods));
map.put("deliveryGoods", deliveryGoods);
map.put("page_status", page_status);
//用改方法查询虚拟商品的数量
/*map.put("queryOfGoodsCount", this.queryOfGoodsCount);*/
} else {
return ResponseCode.buildEnumMap(ResponseCode.PARAM_ERROR, null);
}
return ResponseCode.buildSuccessMap(map);
}
/**
* 根据订单id和商品id查询该商品在该订单中的数量
* @param order_id
* @param goods_id
* @return
*/
public int queryOfGoodsCount(String order_id, String goods_id) {
int count = 0;
OrderFormDto of = this.orderFormFeignClient.selectByPrimaryKey(CommUtil
.null2Long(order_id));
List<Map> map_list = this.orderFormToolsFeignClient.queryGoodsInfo(of.getGoods_info());
for (Map map : map_list) {
if (CommUtil.null2String(map.get("goods_id")).equals(goods_id)) {
count = CommUtil.null2Int(map.get("goods_count"));
break;
}
}
if ((count == 0)
&& (!CommUtil.null2String(of.getChild_order_detail())
.equals(""))) { // 主订单无数量信息,继续从子订单中查询
List<Map> maps = this.orderFormToolsFeignClient.queryGoodsInfo(of.getChild_order_detail());
for (Map map : maps) {
OrderFormDto child_order = this.orderFormFeignClient
.selectByPrimaryKey(CommUtil.null2Long(map
.get("order_id")));
map_list.clear();
map_list = this.orderFormToolsFeignClient.queryGoodsInfo(child_order.getGoods_info());
for (Map map1 : map_list) {
if (CommUtil.null2String(map1.get("goods_id")).equals(
goods_id)) {
count = CommUtil.null2Int(map1.get("goods_count"));
break;
}
}
}
}
return count;
}
/**
* 根据订单id查询该订单中所有商品,包括子订单中的商品
* @param main_order
* @return
*/
public List<GoodsDto> queryOfGoods(OrderFormDto main_order) {
List<Map> map_list =this.orderFormToolsFeignClient.queryGoodsInfo(main_order.getGoods_info());
List<GoodsDto> goods_list = Lists.newArrayList();
for (Map map : map_list) {
GoodsDto goods = this.goodsFeignClient.selectByPrimaryKey(CommUtil
.null2Long(map.get("goods_id")));
if(goods != null){
goods_list.add(goods);
}
}
if (!CommUtil.null2String(main_order.getChild_order_detail())
.equals("")) {
List<Map> maps = this.orderFormToolsFeignClient.queryGoodsInfo(main_order.getChild_order_detail());
for (Map<String, Object> map : maps) {
OrderFormDto child_order = this.orderFormFeignClient
.selectByPrimaryKey(CommUtil.null2Long(map
.get("order_id")));
map_list.clear();
map_list =this.orderFormToolsFeignClient.queryGoodsInfo(child_order.getGoods_info());
for (Map map1 : map_list) {
GoodsDto good = this.goodsFeignClient.selectByPrimaryKey(CommUtil
.null2Long(map1.get("goods_id")));
goods_list.add(good);
}
}
}
return goods_list;
}
/**
* 卖家修改物流
* @param request
* @param response
* @param id
* @param currentPage
* @return
*/
@RequestMapping(value = { "/order_shipping_code" } , method = RequestMethod.POST)
public Map<String , Object> order_shipping_code(HttpServletRequest request,@RequestBody JSONObject json) {
String id = json.optString("id");
OrderFormDto obj = this.orderFormFeignClient
.selectByPrimaryKey(CommUtil.null2Long(id));
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(obj
.getStore_id()));
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
//user = user.getParent_id() == null ? user : user.getParent();
if(user.getStore_id() == null){
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
Store store1 = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store1 == null || store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
if (user.getStore_id().equals(store.getId())) {
return ResponseCode.buildSuccessMap(obj);
} else {
return ResponseCode.buildEnumMap(ResponseCode.FAILURE, null);
}
}
/**
* 卖家修改物流保存
* @param request
* @param response
* @param id
* @param currentPage
* @param shipCode
* @param state_info
* @return
*/
@RequestMapping(value = { "/order_shipping_code_save" } , method = RequestMethod.POST)
public Map<String , Object> order_shipping_code_saveEntity(HttpServletRequest request,@RequestBody JSONObject json) {
String id = json.optString("id");
String shipCode = json.optString("shipCode");
String state_info = json.optString("state_info");
OrderFormDto obj = this.orderFormFeignClient
.selectByPrimaryKey(CommUtil.null2Long(id));
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(obj
.getStore_id()));
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store1 = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store1 == null || store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
//user = user.getParent_id() == null ? user : user.getParent();
if(user.getStore_id() == null){
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
Map<String, Object> map = Maps.newHashMap();
if (user.getStore_id().equals(store.getId())) {
obj.setShipCode(shipCode);
this.orderFormFeignClient.updateById(obj);
OrderFormLogDto ofl = new OrderFormLogDto();
ofl.setAddTime(new Date());
ofl.setLog_info("修改物流信息");
ofl.setState_info(state_info);
ofl.setLog_user_id(SecurityUserHolder.getCurrentUser(request).getId());
ofl.setLog_user_name(SecurityUserHolder.getCurrentUser(request)
.getUserName());
ofl.setOf(obj);
this.orderFormLogFeignClient.saveEntity(ofl);
if (this.sysConfigFeignClient.getSysConfig().getKuaidi_type() == 1) {
JSONObject info = new JSONObject();
Map express_map = JSON.parseObject(obj.getExpress_info());
info.put("company", CommUtil.null2String(express_map
.get("express_company_mark")));
info.put("number", obj.getShipCode());
info.put("from", CommUtil.null2String(obj.getShip_addr()));
info.put("to", obj.getReceiver_area());
info.put("key", this.sysConfigFeignClient.getSysConfig()
.getKuaidi_id2());
JSONObject param_info = new JSONObject();
param_info.put("callbackurl", CommUtil.getURL(request)
+ "/kuaidi_callback?order_id=" + obj.getId()
+ "&orderType=0");
param_info.put("salt",
Md5Encrypt.md5(CommUtil.null2String(obj.getId()))
.substring(0, 16));
info.put("parameters", param_info);
try {
String result = Post(
"http://highapi.kuaidi.com/openapi-receive.html",
info.toString());
Map remap = JSON.parseObject(result);
if ("success".equals(CommUtil.null2String(remap
.get("message")))) {
ExpressInfoDto ei = new ExpressInfoDto();
ei.setAddTime(new Date());
ei.setOrder_id(obj.getId());
ei.setOrder_express_id(obj.getShipCode());
ei.setOrder_type(0);
Map ec_map = JSON.parseObject(CommUtil.null2String(obj
.getExpress_info()));
if (ec_map != null) {
ei.setOrder_express_name(CommUtil
.null2String(ec_map
.get("express_company_name")));
}
this.expressInfoFeignClient.saveEntity(ei);
System.out.println("订阅成功");
} else {
System.out.println("订阅失败");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
return ResponseCode.buildSuccessMap(null);
}
/**
* 快递Post请求
* @param url
* @param param
* @return
*/
@SuppressWarnings("resource")
public static String Post(String url, String param) {
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost method = new HttpPost(url);
StringEntity entity = new StringEntity(param, "utf-8");// 解决中文乱码问题
entity.setContentEncoding("UTF-8");
entity.setContentType("application/json");
method.setEntity(entity);
HttpResponse result = httpClient.execute(method);
// 请求结束,返回结果
return EntityUtils.toString(result.getEntity());
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
}
/**
* 卖家物流详情
* @param request
* @param response
* @param id
* @return
*/
@RequestMapping( value = { "/ship_view" } , method = RequestMethod.POST)
public Map<String , Object> order_ship_view(HttpServletRequest request,@RequestBody JSONObject json) {
String id = json.optString("id");
OrderFormDto obj = this.orderFormFeignClient
.selectByPrimaryKey(CommUtil.null2Long(id));
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(obj
.getStore_id()));
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store1 = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store1 == null || store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
//user = user.getParent_id() == null ? user : user.getParent();
if(user.getStore_id() == null){
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
Map<String, Object> map = Maps.newHashMap();
if (user.getStore_id().equals(store.getId())) {
map.put("obj", obj);
TransInfoDto transInfo = this.shipToolsFeignClient
.query_Ordership_getData(CommUtil.null2String(obj.getId()));
map.put("transInfo", transInfo);
return ResponseCode.buildSuccessMap(map);
} else {
return ResponseCode.buildEnumMap(ResponseCode.FAILURE, null);
}
}
/**
* 商品评价列表
* @param request
* @param response
* @param currentPage
* @param orderBy
* @param orderType
* @param status
* @return
*/
@RequestMapping({ "/evaluate_list" })
public Map<String , Object> evaluate_list(HttpServletRequest request,@RequestBody JSONObject json) {
String currentPage = json.getString("currentPage");
String orderBy = json.getString("orderBy");
String orderType = json.getString("orderType");
String status = json.getString("status");
String evaluate_buyer_val = json.getString("evaluate_buyer_val");
Map<String,Object> maps= this.queryTools.getParams(currentPage, orderBy, orderType);
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
maps.put("evaluate_goods_goods_store_id", store.getId());
maps.put("evaluate_status", 0);
maps.put("evaluate_type", "goods");
if ("yes".equals(status)) {
maps.put("reply_status", 1);
maps.put("status", status);
}
if ("no".equals(status)) {
maps.put("reply_status", 0);
maps.put("status", status);
}
//买家评价,评价类型,1为好评,0为中评,-1为差评
if(StringUtils.isNotBlank(evaluate_buyer_val)){
maps.put("evaluate_buyer_val", evaluate_buyer_val);
}
Map<String, Object> map = this.evaluateFeignClient.list(maps);
map.put("status", status);
return ResponseCode.buildSuccessMap(map);
}
/**
* 商品评价内容查看
* @param request
* @param response
* @param id
* @return
*/
@RequestMapping( value = { "/evaluate_info" } ,method = RequestMethod.POST)
public Map<String , Object> evaluate_info(HttpServletRequest request,@RequestBody JSONObject json) {
String id = json.optString("id");
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
EvaluateDto evl = this.evaluateFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
//TODO
if (evl != null){
OrderFormDto of = this.orderFormFeignClient.selectByPrimaryKey(evl.getOf_id());
UserDto euser = userFeignClient.selectByPrimaryKey(evl.getEvaluate_user_id());
if((of.getStore_id().equals(user.getStore_id()+""))) {
/*mv.addObject("evl", evl);*/
/*mv.addObject("imageTools", this.imageTools);*/
Map<String , Object> maps = Maps.newHashMap();
maps.put("evl", evl);
maps.put("euser", euser);
return ResponseCode.buildSuccessMap(maps);
} else {
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
}else{
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
}
/**
* 商品评价内容回复
* @param request
* @param response
* @param id
* @param reply
*/
@RequestMapping( value = { "/evaluate_reply_save" } , method = RequestMethod.POST)
public Map<String, Object> evaluate_reply_saveEntity(HttpServletRequest request,@RequestBody JSONObject json) {
String id = json.optString("id");
String reply = json.optString("reply");
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
EvaluateDto evl = this.evaluateFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
if (evl != null){
OrderFormDto of = this.orderFormFeignClient.selectByPrimaryKey(evl.getOf_id());
if((of.getStore_id().equals(user.getStore_id()+""))) {
/*mv.addObject("evl", evl);*/
/*mv.addObject("imageTools", this.imageTools);*/
evl.setReply(reply);
evl.setReply_status(1);
this.evaluateFeignClient.updateById(evl);
return ResponseCode.buildSuccessMap(evl);
} else {
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
}else{
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
}
/**
* 常用快递公司
* @param request
* @param response
* @param currentPage
* @param orderBy
* @param orderType
* @return
*/
@RequestMapping(value = { "/ecc_set" } ,method = RequestMethod.POST)
public Map<String , Object> ecc_set(HttpServletRequest request) {
Map<String, Object> params = Maps.newHashMap();
/*List<ExpressCompanyDto> ecs = this.expressCompanyFeignClient.queryPageList(params);*/
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildEnumMap(ResponseCode.TOKEN_EXPIRE, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store == null){
return ResponseCode.buildEnumMap(ResponseCode.NOTSTORE, null);
}
List<ExpressCompanyCommonDto> eccs = Lists.newArrayList();
if ((store != null) && (user.getUserRole().indexOf("SELLER") >= 0)) {
params.put("ecc_type", Integer.valueOf(0));
params.put("ecc_store_id", store.getId());
eccs = this.expressCompanyCommonFeignClient.queryPages(params);
}
/*mv.addObject("ecs", ecs);
mv.addObject("transportTools", this.transportTools);*/
return ResponseCode.buildSuccessMap(eccs);
}
// public int query_common_ec(HttpServletRequest request,String id) {
// int ret = 0;
// if (!CommUtil.null2String(id).equals("")) {
// Map<String, Object> params = Maps.newHashMap();
// UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
// .getCurrentUser(request).getId());
// if(user == null){
// return ret;
// }
// if (user.getParent_id()!=null) {
// user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
// }
// Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
// .getStore_id()));
// if(store == null){
// return ret;
// }
// List<ExpressCompanyCommonDto> eccs = Lists.newArrayList();
// if ((store != null) && (user.getUserRole().indexOf("SELLER") >= 0)) {
// params.put("ecc_type", Integer.valueOf(0));
// params.put("ecc_store_id", store.getId());
// eccs = this.expressCompanyCommon.queryPageList(params);
//
// for (ExpressCompanyCommonDto ecc : eccs) {
// if (ecc.getEcc_ec_id().equals(CommUtil.null2Long(id))) {
// ret = 1;
// }
// }
// } else {
// params.put("ecc_type", Integer.valueOf(1));
// eccs = this.expressCompanyCommon.queryPageList(params);
//
// for (ExpressCompanyCommonDto ecc : eccs) {
// if (ecc.getEcc_ec_id().equals(CommUtil.null2Long(id))) {
// ret = 1;
// }
// }
// }
// }
// return ret;
// }
/**
* 常用快递公司删除
* @param request
* @param response
* @param id
* @param currentPage
* @return
*/
@RequestMapping(value = { "/ecc_delete" } , method = RequestMethod.POST)
public Map<String, Object> ecc_deleteById(HttpServletRequest request,@RequestBody JSONObject json) {
String id = json.optString("id");
ExpressCompanyCommonDto ecc = this.expressCompanyCommonFeignClient
.selectByPrimaryKey(CommUtil.null2Long(id));
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.TOKEN_EXPIRE, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
if (ecc.getEcc_store_id().equals(store.getId())) {
this.expressCompanyCommonFeignClient.deleteById(CommUtil.null2Long(id));
return ResponseCode.buildSuccessMap(null);
}else{
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
}
/**
* 所有未选择的常用快递公司
* @param request
* @param response
* @param id
* @param currentPage
* @return
*/
@RequestMapping(value = { "/ecc_saveEntityView" } , method = RequestMethod.POST)
public Map<String, Object> ecc_saveEntityView(HttpServletRequest request,@RequestBody JSONObject json) {
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildEnumMap( ResponseCode.TOKEN_EXPIRE, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store == null){
return ResponseCode.buildEnumMap(ResponseCode.NOTSTORE,null);
}
Map<String, Object> params = Maps.newHashMap();
params.put("company_status", Integer.valueOf(0));
params.put("orderBy", "company_sequence");
params.put("orderType", "asc");
List<ExpressCompanyDto> excs = this.expressCompanyFeignClient.queryPages(params);
List<ExpressCompanyCommonDto> eccs = Lists.newArrayList();
List<ExpressCompanyDto> execs = Lists.newArrayList();
if ((store != null) && (user.getUserRole().indexOf("SELLER") >= 0)) {
params.clear();
params.put("ecc_type", Integer.valueOf(0));
params.put("ecc_store_id", store.getId());
eccs = this.expressCompanyCommonFeignClient.queryPages(params);
for (ExpressCompanyDto exc : excs) {
int i= 0;
for (ExpressCompanyCommonDto ecc : eccs) {
if (ecc.getEcc_ec_id().equals(CommUtil.null2Long(exc.getId()))) {
i=1;
break;
}
}
if(i == 0){
execs.add(exc);
}
}
}
return ResponseCode.buildSuccessMap(execs);
}
/**
* 常用快递公司添加
* @param request
* @param response
* @param id
* @param currentPage
* @return
*/
@RequestMapping(value = { "/ecc_saveEntity" } , method = RequestMethod.POST)
public Map<String, Object> ecc_saveEntity(HttpServletRequest request,@RequestBody JSONObject json) {
String ids = json.optString("ids");
String[] ec_ids= null;
if(ids != null){
ec_ids = ids.split(",");
}
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.TOKEN_EXPIRE, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
for (String ec_id : ec_ids) {
if (!CommUtil.null2String(ec_id).equals("")) {
ExpressCompanyDto ec = this.expressCompanyFeignClient.selectByPrimaryKey(CommUtil.null2Long(ec_id));
ExpressCompanyCommonDto ecc = new ExpressCompanyCommonDto();
ecc.setAddTime(new Date());
ecc.setEcc_code(ec.getCompany_mark());
ecc.setEcc_ec_id(ec.getId());
ecc.setEcc_name(ec.getCompany_name());
ecc.setEcc_store_id(store.getId());
ecc.setEcc_template(ec.getCompany_template());
ecc.setEcc_template_heigh(ec.getCompany_template_heigh());
ecc.setEcc_template_width(ec.getCompany_template_width());
ecc.setEcc_template_offset(ec.getCompany_template_offset());
ecc.setEcc_type(0);
ecc.setEcc_ec_type(ec.getCompany_type());
this.expressCompanyCommonFeignClient.saveEntity(ecc);
}
}
return ResponseCode.buildSuccessMap(null);
}
/**
* 发货地址列表
* @param request
* @param response
* @param currentPage
* @param orderBy
* @param orderType
* @return
*/
@RequestMapping(value = { "/ship_address" } ,method = RequestMethod.POST)
public Map<String,Object> ship_address(HttpServletRequest request,@RequestBody JSONObject json) {
String currentPage = json.optString("currentPage");
String orderBy = json.optString("orderBy");
String orderType = json.optString("orderType");
Map<String,Object> maps= this.queryTools.getParams(currentPage, orderBy, orderType);
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
List<Long> sa_user_ids = Lists.newArrayList();
sa_user_ids.add(user.getId());
if(user!=null && user.getParent_id()!=null){
UserDto userParent = this.userFeignClient.selectByPrimaryKey(user.getParent().getId());
sa_user_ids.add(userParent.getId());
List<UserDto> childs = userParent.getChilds();
for (UserDto uc : childs) {
sa_user_ids.add(uc.getId());
}
}
if(user!=null && user.getChilds()!=null && user.getChilds().size()>0){
List<UserDto> childs = user.getChilds();
for (UserDto uc : childs) {
sa_user_ids.add(uc.getId());
}
}
maps.put("sa_type", 0);
maps.put("sa_user_ids", sa_user_ids);
Map<String, Object> data = this.shipAddressFeignClient.list(maps);
HashMap<Object, Object> result = new HashMap<>();
result.put("data", data);
Store store = storeService.selectByPrimaryKey(user.getStore_id());
if (store!=null) {
List<Map> ms_list = Lists.newArrayList();
if (store.getStore_service_info() != null) {
ms_list = JSON.parseArray(store.getStore_service_info(),Map.class);
}
result.put("ms_list", ms_list);
if (store.getMc_id()!=null&&store.getMc_id()==22) {
result.put("scenic", 1); //为景点商品
}else{
result.put("scenic", 0); //普通商品
}
}
return ResponseCode.buildSuccessMap(result);
}
/**
* 新增发货地址的地区
* @param request
* @param response
* @param currentPage
* @return
*/
@RequestMapping(value = { "/ship_address_add" } , method = RequestMethod.POST)
public Map<String , Object> ship_address_add(HttpServletRequest request, @RequestBody JSONObject json) {
String parent_id = json.optString("parent_id");
Map<String, Object> maps = Maps.newHashMap();
if(StringUtils.isNotBlank(parent_id)){
maps.put("parent_id", parent_id);
}else{
maps.put("parent_id", -1);
}
/*List<AreaDto> areas = this.areaFeignClient.queryPageList(maps);*/
List<AreaDto> areas = this.areaFeignClient.queryPages(maps);
return ResponseCode.buildSuccessMap(areas);
}
/**
* 编辑发货地址
* @param request
* @param response
* @param id
* @param currentPage
* @return
*/
@RequestMapping(value = { "/ship_address_edit" } , method = RequestMethod.POST)
public Map<String , Object> ship_address_edit(HttpServletRequest request,@RequestBody JSONObject json) {
String id = json.optString("id");
ShipAddressDto obj = this.shipAddressFeignClient.selectByPrimaryKey(CommUtil
.null2Long(id));
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildEnumMap(ResponseCode.TOKEN_EXPIRE,null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store == null){
return ResponseCode.buildEnumMap(ResponseCode.NOTSTORE,null);
}
if ((obj != null) && (obj.getSa_user_id().equals(user.getId()))) {
Map<String, Object> maps = Maps.newHashMap();
AreaDto sa_area = this.areaFeignClient.selectByPrimaryKeyFullParent(obj.getSa_area_id());
obj.setSa_area_name(sa_area.getParent().getParent().getAreaName()+sa_area.getParent().getAreaName()+sa_area.getAreaName());
maps.put("obj", obj);
return ResponseCode.buildSuccessMap(maps);
} else {
return ResponseCode.buildEnumMap(ResponseCode.PARAM_ERROR, null);
}
}
/**
* 保存发货地址
* @param request
* @param response
* @param id
* @param currentPage
*/
@RequestMapping( value = { "/ship_address_save" } ,method = RequestMethod.POST)
public Map<String , Object> ship_address_saveEntity(HttpServletRequest request,@RequestBody ShipAddressDto shipaddress) {
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildEnumMap(ResponseCode.TOKEN_EXPIRE,null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store == null){
return ResponseCode.buildEnumMap(ResponseCode.NOTSTORE,null);
}
if(shipaddress == null){
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
if (StringUtils.isBlank(shipaddress.getId()+"")) {
shipaddress.setAddTime(new Date());
shipaddress.setDeleteStatus(0);
} else {
ShipAddressDto obj = this.shipAddressFeignClient.selectByPrimaryKey(shipaddress.getId());
shipaddress.setAddTime(obj.getAddTime());
shipaddress.setDeleteStatus(obj.getDeleteStatus());
}
//判断是不是第一个发货地址 如果是则设置成默认的
Map< String , Object> maps = Maps.newHashMap();
List<Long> sa_user_ids = Lists.newArrayList();
sa_user_ids.add(user.getId());
if(user!=null && user.getParent_id()!=null){
UserDto userParent = this.userFeignClient.selectByPrimaryKey(user.getParent().getId());
sa_user_ids.add(userParent.getId());
List<UserDto> childs = userParent.getChilds();
for (UserDto uc : childs) {
sa_user_ids.add(uc.getId());
}
}
if(user!=null && user.getChilds()!=null && user.getChilds().size()>0){
List<UserDto> childs = user.getChilds();
for (UserDto uc : childs) {
sa_user_ids.add(uc.getId());
}
}
maps.put("sa_type", 0);
maps.put("sa_user_ids", sa_user_ids);
List<ShipAddressDto> queryPages = this.shipAddressFeignClient.queryPages(maps);
if(queryPages.size()>0){
shipaddress.setSa_default(0);
}else{
shipaddress.setSa_default(1);
}
shipaddress.setStore_id(store.getId());
shipaddress.setSa_type(0);
shipaddress.setSa_user_id(SecurityUserHolder.getCurrentUser(request).getId());
shipaddress.setSa_user_name(SecurityUserHolder.getCurrentUser(request)
.getUsername());
// 根据行业 决定是否需要创建达达门店
if (modularClassFeignClient.selectByPrimaryKey(store.getMc_id()).isTimely()) { // 若为附近配送,
SysConfigDto sysConfig = sysConfigFeignClient.getSysConfig();
if (sysConfig.getDada_appkey()!=null&& sysConfig.getDada_appsecret()!=null) {
// 1.初始化配置(isOnline表示是否测试环境)
DaDaAppConfig appConfig = new DaDaAppConfig(store.getSource_id() + "", sysConfig.getDada_appkey(), sysConfig.getDada_appsecret());
// 2.初始化model
ShopAddModel shopAddModel = new ShopAddModel();
if (StringUtils.isBlank(shipaddress.getId()+"")) { //不存在走更新
// 根据实际信息来填写门店地址
String order_suffix = CommUtil.formatTime("yyyyMMddHHmmss", new Date());
shopAddModel.setOriginShopId(order_suffix + store.getId()); // 门店编码,可自定义,但必须唯一;若不填写,则系统自动生成
shipaddress.setShop_no(order_suffix + store.getId()); // 保存门店编码
}else{
shopAddModel.setOriginShopId(shipaddress.getShop_no());
}
shopAddModel.setStationName(shipaddress.getSa_name()); // 门店名称
shopAddModel.setBusiness(13); // 业务类型, 13 水果生鲜
AreaDto area = areaFeignClient.selectByPrimaryKeyFullParent(shipaddress.getSa_area_id());
// shipaddress
shopAddModel.setCityName(area.getParent().getAreaName()); // 城市名称
shopAddModel.setAreaName(area.getAreaName()); // 区域名称
shopAddModel.setStationAddress(shipaddress.getSa_addr()); // 详细地址
shopAddModel.setLng(BigDecimal.valueOf(shipaddress.getSa_lng())); // 经纬度
shopAddModel.setLat(BigDecimal.valueOf(shipaddress.getSa_lat()));
shopAddModel.setContactName(shipaddress.getSa_user());
shopAddModel.setPhone(shipaddress.getSa_telephone());
// 3.初始化service (门店新增比较特殊,是一个批量新增接口)
List<ShopAddModel> shopAddList = new ArrayList<ShopAddModel>();
shopAddList.add(shopAddModel);
String dadaUrl = null;
if (StringUtils.isBlank(shipaddress.getId()+"")) {
dadaUrl = "/api/shop/add";
} else {
// 更新门店信息
dadaUrl = "/api/shop/update";
}
DaDaService shopAddService = new DaDaService(dadaUrl, JSONUtil.toJson(shopAddList));
// 4.初始化客户端
DadaRequestClient dadaClient = new DadaRequestClient(shopAddService, appConfig);
DadaApiResponse callRpc = dadaClient.callRpc();
if (callRpc.getCode() != 0) { // 不成功 ,返回错误信息
return ResponseCode.buildCodeMap("100", callRpc.getMsg(), null);
}
}
}
if (StringUtils.isBlank(shipaddress.getId()+"")) {
this.shipAddressFeignClient.saveEntity(shipaddress);
} else {
this.shipAddressFeignClient.updateById(shipaddress);
}
return ResponseCode.buildSuccessMap(null);
}
/**
* 发货地址删除
* @param request
* @param response
* @param mulitId
* @param currentPage
* @return
*/
@RequestMapping(value = { "/ship_address_del" } , method = RequestMethod.POST)
public Map<String , Object> ship_address_del(HttpServletRequest request,@RequestBody JSONObject json) {
String id = json.optString("id");
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.TOKEN_EXPIRE, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
if (StringUtils.isNotBlank(id)) {
ShipAddressDto obj = this.shipAddressFeignClient.selectByPrimaryKey(CommUtil
.null2Long(id));
if ((obj != null) && (obj.getSa_type() == 0)
&& (obj.getSa_user_id().equals(user.getId()))) {
this.shipAddressFeignClient.deleteById(obj.getId());
}
}
return ResponseCode.buildSuccessMap(null);
}
/**
* 设置默认发货地址
* @param request
* @param response
* @param id
* @param currentPage
* @return
*/
@RequestMapping( value = { "/ship_address_default" } , method = RequestMethod.POST)
public Map<String , Object> ship_address_default(HttpServletRequest request, @RequestBody JSONObject json) {
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.TOKEN_EXPIRE, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
Map<String, Object> params = Maps.newHashMap();
params.put("sa_default", Integer.valueOf(1));
params.put("sa_user_id", user.getId());
List<ShipAddressDto> sa_list = this.shipAddressFeignClient.queryPages(params);
for (ShipAddressDto sa : sa_list) {
sa.setSa_default(0);
this.shipAddressFeignClient.updateById(sa);
}
String id = json.optString("id");
ShipAddressDto obj = this.shipAddressFeignClient.selectByPrimaryKey(CommUtil
.null2Long(id));
if (obj.getSa_user_id().equals(user.getId())) {
obj.setSa_default(1);
this.shipAddressFeignClient.updateById(obj);
}
return ResponseCode.buildSuccessMap(null);
}
/**
* 设置修改收货地址
* @param request
* @param response
* @param id
* @param currentPage
* @return
*/
@RequestMapping(value = { "/upShippingAddress" } , method = RequestMethod.POST)
public Map<String , Object> upShippingAddress(HttpServletRequest request,
@RequestBody JSONObject json) {
String id = json.optString("id");
OrderFormDto obj = this.orderFormFeignClient
.selectByPrimaryKey(CommUtil.null2Long(id));
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(obj
.getStore_id()));
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
//user = user.getParent_id() == null ? user : user.getParent();
if(user.getStore_id() == null){
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
if (user.getStore_id().equals(store.getId())) {
return ResponseCode.buildSuccessMap(obj);
} else {
return ResponseCode.buildEnumMap(ResponseCode.FAILURE, null);
}
}
/**
* 设置修改收货地址保存
* @param request
* @param response
* @param id
* @param currentPage
* @return
*/
@RequestMapping(value = { "/upShippingAddress_save" } , method = RequestMethod.POST)
public Map<String , Object> upShippingAddress_save(HttpServletRequest request,
@RequestBody JSONObject json) {
String id = json.optString("id");
String receiver_name = json.optString("receiver_name");// 收货人姓名,确认订单后,将买家的收货地址所有信息添加到订单中,该订单与买家收货地址没有任何关联
String receiver_area = json.optString("receiver_area");// 收货人地区,例如:福建省厦门市海沧区
String receiver_area_info = json.optString("receiver_area_info");// 收货人详细地址,例如:凌空二街56-1号,4单元2楼1号
//String receiver_zip = json.optString("receiver_zip");// 收货人邮政编码
String receiver_telephone = json.optString("receiver_telephone");// 收货人联系电话
String receiver_mobile = json.optString("receiver_mobile");// 收货人手机号码
String lat = json.optString("lat");// 经纬度
String lng = json.optString("lng");//
OrderFormDto obj = this.orderFormFeignClient
.selectByPrimaryKey(CommUtil.null2Long(id));
if(obj == null){
return ResponseCode.buildReturnMap(ResponseCode.PARAM_ERROR, null);
}
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(obj
.getStore_id()));
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
//user = user.getParent_id() == null ? user : user.getParent();
if(user.getStore_id() == null){
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
if (CommUtil.null2String(user.getStore_id()).equals(CommUtil.null2String(store.getId()))) {
obj.setReceiver_Name(receiver_name);
obj.setReceiver_area(receiver_area);
obj.setReceiver_area_info(receiver_area_info);
//obj.setReceiver_zip(receiver_zip);
obj.setReceiver_telephone(receiver_telephone);
obj.setReceiver_mobile(receiver_mobile);
if (StringUtils.isNotBlank(lat)&&StringUtils.isNotBlank(lng)) {
obj.setUser_lat(CommUtil.null2Double(lat));
obj.setUser_lng(CommUtil.null2Double(lng));
}
orderFormFeignClient.updateById(obj);
return ResponseCode.buildSuccessMap(obj);
} else {
return ResponseCode.buildEnumMap(ResponseCode.FAILURE, null);
}
}
}
源码地址来源: https://minglisoft.cn/honghu2/business.html