package com.weiit.web.api.controller;
import com.github.binarywang.wxpay.util.SignUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.weiit.core.entity.E;
import com.weiit.core.entity.FormMap;
import com.weiit.resource.common.utils.RedisUtil;
import com.weiit.resource.common.utils.WeiitUtil;
import com.weiit.web.api.service.*;
import com.weiit.web.base.FrontController;
import com.weiit.web.common.ApiResponseCode;
import com.weiit.web.common.Constants;
import com.weiit.web.common.RedisKey;
import com.weiit.web.util.DateUtil;
import com.weiit.web.weixinopen.util.XMLUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.RandomUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;
/**
* 订单接口
*
* @author tangjian
* @version 1.0
* @date:2018年5月7日 上午2:01:43
* @company http://www.wei-it.com
*/
@Controller
@RequestMapping(value = "/api/order")
public class OrderController extends FrontController {
@Resource
private OrderService orderService;
@Resource
UserService userService;
@Resource
PlatformService platformService;
@Resource
ProductService productService;
@Resource
RedisUtil redisUtil;
@Resource
MessageService messageService;
@Resource
IntegralService integralService;
/**
* 订单确认接口
*
* @return
* @throws Exception
* 参数有cart_ids,address_id,payment_type,remark,express_type,express_money, coupon_id(用户优惠券表的id) 优惠券ID ,pay_price
*/
@ResponseBody
@RequestMapping(value = "/addOrder", method = RequestMethod.POST)
public String addOrder(@RequestHeader("token") String token) throws Exception {
logger.info("【商品】提交订单,orderController-addOrder");
FormMap formMap = getFormMap();
if (formMap.get("user_id") != null) {
//核对订单信息,重新计算总额
double sum = 0;
double payPrice = 0;
List<E> cartList = orderService.selectUserCartList(formMap);
if (cartList == null && cartList.size()==0) {
return toJsonAPI("", "创建订单失败,购物车为空", "1006");
}
for (E cart : cartList) {
sum = sum + cart.getDouble("smarket_price") * cart.getInt("count");
payPrice = payPrice + cart.getDouble("sale_price") * cart.getInt("count");
}
formMap.put("order_num", Constants.ORDER_SHOP + System.currentTimeMillis() + StringUtils.leftPad(formMap.getStr("user_id"), 8, RandomUtils.nextInt(1000000) + ""));
formMap.put("total_price", sum);
//计算优惠金额
double coupon_price =0.0;
//表示有优惠券抵扣 小程序传undifined
if(!StringUtils.isEmpty(formMap.getStr("coupon_id")) && !formMap.getStr("coupon_id").equals("undefined")){
E coupon=orderService.selectUserCouponById(formMap);
if (coupon==null){
return toJsonAPI("", "创建订单失败,优惠券不在使用时间", "1005");
}else if(coupon.getInt("state")==-1){
return toJsonAPI("", "创建订单失败,优惠券已过期", "1005");
}else if(coupon.getInt("state")==1){
return toJsonAPI("", "创建订单失败,优惠券已使用", "1005");
}
//都是可用优惠券 不用判断 无条件或是满减
//通用商品 若有售后问题打包退回
if (coupon.getInt("product_range_type")==1){
//指定金额
if(coupon.getInt("type")==1){
coupon_price=coupon.getDouble("coupon_price");
for (E cart : cartList) {
//销售金额 -优惠金额*(销售金额/支付金额)= 商品的实际支付金额(售后的退款金额)
double salePrice = cart.getDouble("sale_price") * cart.getInt("count");
cart.set("coupon_pay",salePrice-calcPayPrice(salePrice,payPrice,coupon_price));
cart.set("pay_price",calcPayPrice(salePrice,payPrice,coupon_price));
}
}
//打折
else if(coupon.getInt("type")==2) {
coupon_price= getDoubleValue(new BigDecimal(payPrice).multiply(new BigDecimal(10).subtract(new BigDecimal(coupon.getStr("coupon_discount"))).divide(new BigDecimal(10))));
for (E cart : cartList) {
//销售金额 -优惠金额*(销售金额/支付金额)= 商品的实际支付金额(售后的退款金额)
double salePrice = cart.getDouble("sale_price") * cart.getInt("count");
cart.set("coupon_pay",getDoubleValue(new BigDecimal(salePrice).multiply(new BigDecimal(10-coupon.getInt("coupon_discount"))).divide(new BigDecimal(10))));
cart.set("pay_price",getDoubleValue(new BigDecimal(salePrice).multiply(new BigDecimal(coupon.getInt("coupon_discount"))).divide(new BigDecimal(10))));
}
}
}//指定商品
else if (coupon.getInt("product_range_type")==2){
String [] product_ids = coupon.getStr("product_ids").split(",");
//指定金额
boolean flag = false;
if(coupon.getInt("type")==1){
coupon_price=coupon.getDouble("coupon_price");
for(String productId:product_ids){
for (E cart : cartList) {
if (cart.getStr("product_id").equals(productId)){
//
cart.set("coupon_pay",coupon_price);
//未测精度缺失
cart.set("pay_price",cart.getDouble("sale_price") * cart.getInt("count")-coupon_price);
flag=true;
break;
}
}
if (flag){
break;
}
}
}else if(coupon.getInt("type")==2) {//打折
double temp_price =0.0;
for(String productId:product_ids){
for (E cart : cartList) {
if (cart.getStr("product_id").equals(productId)){
temp_price+=cart.getDouble("sale_price") * cart.getInt("count");
//该件商品的支付金额 方便售后退货
cart.set("coupon_pay",getDoubleValue(new BigDecimal(cart.getDouble("sale_price") * cart.getInt("count")).multiply(new BigDecimal(10-coupon.getInt("coupon_discount")).divide(new BigDecimal(10)))));
cart.set("pay_price",getDoubleValue(new BigDecimal(cart.getDouble("sale_price") * cart.getInt("count")).multiply(new BigDecimal(coupon.getInt("coupon_discount")).divide(new BigDecimal(10)))));
}
}
}
coup
没有合适的资源?快使用搜索试试~ 我知道了~
SaaS微信小程序电商生成小程序源码.rar
共2000个文件
js:497个
java:402个
jsp:238个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 171 浏览量
2024-04-25
14:25:55
上传
评论
收藏 35.53MB RAR 举报
温馨提示
SaaS微信小程序电商生成小程序源码.rarSaaS微信小程序电商生成小程序源码.rarSaaS微信小程序电商生成小程序源码.rar
资源推荐
资源详情
资源评论
收起资源包目录
SaaS微信小程序电商生成小程序源码.rar (2000个子文件)
components.min.css 328KB
components.min.css 328KB
index.css 193KB
bootstrap.min.css 119KB
bootstrap.min.css 119KB
core.min.css 118KB
core.min.css 118KB
login.min.css 111KB
login.min.css 111KB
neditor.css 72KB
neditor.css 72KB
neditor.min.css 58KB
neditor.min.css 58KB
styles.css 47KB
styles.css 47KB
iconfont.css 43KB
colors.min.css 37KB
colors.min.css 37KB
jquery-ui.min.css 31KB
font-awesome.min.css 30KB
buttoniconex.css 25KB
buttoniconex.css 25KB
styles.min.css 23KB
styles.min.css 23KB
video-js.css 21KB
video-js.css 21KB
image.css 19KB
image.css 19KB
video.css 15KB
video.css 15KB
attachment.css 14KB
attachment.css 14KB
video-js.min.css 11KB
video-js.min.css 11KB
menu.css 8KB
menu.css 8KB
main.css 8KB
main.css 8KB
style.css 8KB
shCoreDefault.css 7KB
shCoreDefault.css 7KB
demo.css 6KB
demo.css 6KB
iconfont.css 6KB
scrawl.css 6KB
scrawl.css 6KB
reset.css 5KB
reset.css 5KB
validationEngine.jquery.css 4KB
validationEngine.jquery.css 4KB
index.css 4KB
login.css 4KB
jquery.pagewalkthrough.css 3KB
codemirror.css 3KB
codemirror.css 3KB
reset.css 3KB
music.css 3KB
music.css 3KB
charts.css 3KB
charts.css 3KB
background.css 3KB
background.css 3KB
wangEditor-1.1.0-min.css 2KB
user.css 2KB
user.css 2KB
dialogbase.css 2KB
dialogbase.css 2KB
emotion.css 2KB
emotion.css 2KB
edittable.css 1KB
edittable.css 1KB
template.css 1KB
template.css 1KB
webuploader.css 515B
webuploader.css 515B
help.css 389B
help.css 389B
iframe.css 87B
iframe.css 87B
icomoon.eot 213KB
fontawesome-webfont.eot 59KB
iconfont.eot 25KB
iconfont.eot 25KB
glyphicons-halflings-regular.eot 20KB
vjs.eot 3KB
UEditorSnapscreen.exe 508KB
wface.gif 49KB
jxface2.gif 40KB
yface.gif 28KB
bface.gif 27KB
icons.gif 20KB
file-icons.gif 20KB
file-icons.gif 20KB
tface.gif 19KB
fface.gif 18KB
cface.gif 8KB
icons-all.gif 4KB
upload.gif 2KB
videologo.gif 2KB
cancelbutton.gif 1KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
依星net188.com
- 粉丝: 7851
- 资源: 2094
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功