Commit 151019ec by 郑云飞

定时任务 拼团失败退款 完成

parent 327439c0
...@@ -80,6 +80,21 @@ public class WxController { ...@@ -80,6 +80,21 @@ public class WxController {
return "ok"; return "ok";
} }
/**
* 微信退款
*
* @param request
* @return
*/
@RequestMapping(value = "/wxPay", method = RequestMethod.POST)
public Result wxRefund(Integer userId, Integer orderId, HttpServletRequest request) {
try {
return wxService.wxRefund(userId, orderId, request);
} catch (Exception e) {
return new Result(103);
}
}
// @RequestMapping(value = "/asd", method = {RequestMethod.POST, RequestMethod.GET}) // @RequestMapping(value = "/asd", method = {RequestMethod.POST, RequestMethod.GET})
......
...@@ -43,7 +43,7 @@ public class GroupAreaController { ...@@ -43,7 +43,7 @@ public class GroupAreaController {
GroupArea area = groupAreaService.findById(areaId); GroupArea area = groupAreaService.findById(areaId);
model.addAttribute("obj", area); model.addAttribute("obj", area);
} }
return "/groupArea/addOrEdit"; return "groupArea/addOrEdit";
} }
/** /**
......
...@@ -3,9 +3,10 @@ package com.yunniu.farming.webadmin.controller; ...@@ -3,9 +3,10 @@ package com.yunniu.farming.webadmin.controller;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunniu.farming.common.plugin.PageInfo; import com.yunniu.farming.common.plugin.PageInfo;
import com.yunniu.farming.result.Result; import com.yunniu.farming.result.Result;
import com.yunniu.farming.util.COSUtil;
import com.yunniu.farming.util.FileUtil;
import com.yunniu.farming.webadmin.model.GroupArea; import com.yunniu.farming.webadmin.model.GroupArea;
import com.yunniu.farming.webadmin.model.GroupBuy; import com.yunniu.farming.webadmin.model.GroupBuy;
import com.yunniu.farming.webadmin.model.Product; import com.yunniu.farming.webadmin.model.Product;
...@@ -15,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -15,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -55,7 +57,7 @@ public class GroupBuyController { ...@@ -55,7 +57,7 @@ public class GroupBuyController {
} }
List<GroupArea> areas = groupAreaService.findList(); List<GroupArea> areas = groupAreaService.findList();
model.addAttribute("areaList", areas); model.addAttribute("areaList", areas);
return "/groupBuy/addOrEdit"; return "groupBuy/addOrEdit";
} }
/** /**
...@@ -127,6 +129,9 @@ public class GroupBuyController { ...@@ -127,6 +129,9 @@ public class GroupBuyController {
if (ObjectUtils.isEmpty(item.getGroupSize())){ if (ObjectUtils.isEmpty(item.getGroupSize())){
return Result.error("最低起送人数不能为空"); return Result.error("最低起送人数不能为空");
} }
if (StringUtils.isEmpty(item.getGroupBuyPic())){
return Result.error("图片不能为空");
}
if (CollectionUtils.isEmpty(item.getAreaIdList())){ if (CollectionUtils.isEmpty(item.getAreaIdList())){
return Result.error("配送小区不能为空"); return Result.error("配送小区不能为空");
} }
...@@ -188,5 +193,25 @@ public class GroupBuyController { ...@@ -188,5 +193,25 @@ public class GroupBuyController {
return Result.success(rmap); return Result.success(rmap);
} }
@RequestMapping(value = "uploads")
@ResponseBody
public Map<String, Object> uploads(@RequestParam(value = "upfile", required = false) MultipartFile upfile)
throws Exception {
Map<String, Object> rs = new HashMap<String, Object>();
try {
if (!upfile.isEmpty()) {
String path = FileUtil.saveFile(upfile, "group");
String url = COSUtil.uploadFileByPath(path);
rs.put("state", "SUCCESS");// UEDITOR的规则:不为SUCCESS则显示state的内容
rs.put("url", url); // 能访问到你如今图片的路径
}
} catch (Exception e) {
e.printStackTrace();
rs.put("state", e.getMessage());
rs.put("url", "");
rs.put("title", "");
rs.put("original", "");
}
return rs;
}
} }
...@@ -50,7 +50,7 @@ public class GroupOrderController { ...@@ -50,7 +50,7 @@ public class GroupOrderController {
GroupOrder order = groupOrderService.findById(id); GroupOrder order = groupOrderService.findById(id);
model.addAttribute("obj", order); model.addAttribute("obj", order);
} }
return "/groupOrder/detail"; return "groupOrder/detail";
} }
@RequestMapping(value = "/findPageList", method = RequestMethod.POST) @RequestMapping(value = "/findPageList", method = RequestMethod.POST)
......
...@@ -3,12 +3,20 @@ package com.yunniu.farming.webadmin.controller; ...@@ -3,12 +3,20 @@ package com.yunniu.farming.webadmin.controller;
import cn.hutool.core.lang.WeightRandom;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yunniu.farming.util.DateTools; import com.yunniu.farming.util.DateTools;
import com.yunniu.farming.webadmin.dao.CustomerDao; import com.yunniu.farming.webadmin.dao.CustomerDao;
import com.yunniu.farming.webadmin.dao.GroupOrderDao;
import com.yunniu.farming.webadmin.dao.OrderMainDao;
import com.yunniu.farming.webadmin.model.Customer; import com.yunniu.farming.webadmin.model.Customer;
import com.yunniu.farming.webadmin.model.GroupOrder;
import com.yunniu.farming.webadmin.model.OrderMain;
import com.yunniu.farming.webadmin.service.WxService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
...@@ -20,6 +28,12 @@ public class TaskJob { ...@@ -20,6 +28,12 @@ public class TaskJob {
@Autowired @Autowired
private CustomerDao customerDao; private CustomerDao customerDao;
@Autowired
private GroupOrderDao groupOrderDao;
@Autowired
private OrderMainDao orderMainDao;
@Autowired
private WxService wxService;
//定时任务 //定时任务
@Scheduled(cron = "0 0 0 * * ? ") // 每天凌晨零点零分零秒 @Scheduled(cron = "0 0 0 * * ? ") // 每天凌晨零点零分零秒
...@@ -47,6 +61,32 @@ public class TaskJob { ...@@ -47,6 +61,32 @@ public class TaskJob {
} }
} }
/**
* 定时修改团购订单状态
*/
@Scheduled(cron = "59 59 23 * * ? ")
@Transactional(rollbackFor = Exception.class)
public void successGroup() throws Exception{
// 查询待成团并到期的团购订单
List<GroupOrder> orders = groupOrderDao.getList();
orders.forEach(order -> {
// 查询已支付成功订单
List<OrderMain> orderMains = orderMainDao.selectByGroupOrderId(order.getId());
// 订单数小于成团数 拼团失败 进行退款
if (order.getGroupSize() < orderMains.size()){
order.setGroupStatus("4");
// 循环退款
orderMains.forEach(orderMain -> {
try {
wxService.wxRefund(orderMain.getCustomerid(), orderMain.getId(), null);
} catch (Exception e) {
e.printStackTrace();
}
});
}
});
}
//改变会员用户状态 //改变会员用户状态
public void updateUserVipStatus(Customer user){ public void updateUserVipStatus(Customer user){
......
...@@ -2,6 +2,7 @@ package com.yunniu.farming.webadmin.dao; ...@@ -2,6 +2,7 @@ package com.yunniu.farming.webadmin.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunniu.farming.webadmin.model.GroupBuyProduct; import com.yunniu.farming.webadmin.model.GroupBuyProduct;
import com.yunniu.farming.webadmin.model.Product;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -15,4 +16,6 @@ import java.util.List; ...@@ -15,4 +16,6 @@ import java.util.List;
@Mapper @Mapper
public interface GroupBuyProductDao extends BaseMapper<GroupBuyProduct> { public interface GroupBuyProductDao extends BaseMapper<GroupBuyProduct> {
int insertBath(@Param("products") List<GroupBuyProduct> products, @Param("id") Long id); int insertBath(@Param("products") List<GroupBuyProduct> products, @Param("id") Long id);
List<Product> getList(Long id);
} }
package com.yunniu.farming.webadmin.dao; package com.yunniu.farming.webadmin.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunniu.farming.webadmin.model.GroupBuy;
import com.yunniu.farming.webadmin.model.GroupOrder; import com.yunniu.farming.webadmin.model.GroupOrder;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
...@@ -17,4 +18,10 @@ public interface GroupOrderDao extends BaseMapper<GroupOrder> { ...@@ -17,4 +18,10 @@ public interface GroupOrderDao extends BaseMapper<GroupOrder> {
List<GroupOrder> findPageList(GroupOrder item); List<GroupOrder> findPageList(GroupOrder item);
GroupOrder detailById(Long id); GroupOrder detailById(Long id);
List<GroupOrder> getList();
GroupBuy getGroupBuy(Long groupOrderId);
int updateStatus(Long groupOrderId);
} }
...@@ -18,4 +18,6 @@ public interface OrderMainDao extends BaseMapper<OrderMain> { ...@@ -18,4 +18,6 @@ public interface OrderMainDao extends BaseMapper<OrderMain> {
Double countOrderMoney(OrderMain orderMain); Double countOrderMoney(OrderMain orderMain);
List<OrderMain> getPageListByGroupOrderId(OrderMain item); List<OrderMain> getPageListByGroupOrderId(OrderMain item);
List<OrderMain> selectByGroupOrderId(Long id);
} }
...@@ -50,6 +50,8 @@ public class GroupBuy { ...@@ -50,6 +50,8 @@ public class GroupBuy {
@JsonFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern = "yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd")
private Date startTime; private Date startTime;
@TableField(exist = false)
private String startDate;
/** /**
* 拼团结束时间 * 拼团结束时间
...@@ -57,6 +59,9 @@ public class GroupBuy { ...@@ -57,6 +59,9 @@ public class GroupBuy {
@JsonFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern = "yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd")
private Date endTime; private Date endTime;
@TableField(exist = false)
private String endDate;
/** /**
* 团购状态:1 待发布,2待生效,3已生效,4已结束,5已删除 * 团购状态:1 待发布,2待生效,3已生效,4已结束,5已删除
...@@ -125,6 +130,9 @@ public class GroupBuy { ...@@ -125,6 +130,9 @@ public class GroupBuy {
private List<GroupBuyProduct> products; private List<GroupBuyProduct> products;
@TableField(exist = false) @TableField(exist = false)
private String productList;
@TableField(exist = false)
private List<GroupArea> areas; private List<GroupArea> areas;
@TableField(exist = false) @TableField(exist = false)
...@@ -139,4 +147,8 @@ public class GroupBuy { ...@@ -139,4 +147,8 @@ public class GroupBuy {
@TableField(exist = false) @TableField(exist = false)
private String startAndEndTime; private String startAndEndTime;
@TableField(exist = false)
@JsonInclude(JsonInclude.Include.NON_NULL)
private String[] goodsImgArr;
} }
...@@ -91,5 +91,6 @@ public class Product { ...@@ -91,5 +91,6 @@ public class Product {
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
private Date ddef10; private Date ddef10;
@TableField(exist = false)
private BigDecimal productPrice;
} }
\ No newline at end of file
...@@ -15,4 +15,5 @@ public interface WxService { ...@@ -15,4 +15,5 @@ public interface WxService {
void notify(HttpServletRequest request, HttpServletResponse response) throws IOException, JDOMException; void notify(HttpServletRequest request, HttpServletResponse response) throws IOException, JDOMException;
Result wxRefund(Integer userId, Integer orderId, HttpServletRequest request) throws Exception;
} }
...@@ -19,7 +19,11 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -19,7 +19,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* @author zyf * @author zyf
...@@ -60,24 +64,16 @@ public class GroupBuyServiceimpl implements GroupBuyService { ...@@ -60,24 +64,16 @@ public class GroupBuyServiceimpl implements GroupBuyService {
public Result addOrEdit(GroupBuy item) { public Result addOrEdit(GroupBuy item) {
// 判断是否为新增 // 判断是否为新增
if (ObjectUtils.isEmpty(item.getId())) { if (ObjectUtils.isEmpty(item.getId())) {
String imgArr = item.getGroupBuyPic();
String pics = "";
if (StringUtils.isNotEmpty(imgArr)) {
if (imgArr.startsWith("data:image")) {
String suffix = imgArr.substring(imgArr.indexOf("/") + 1, imgArr.indexOf(";"));
String realpath = FileUtil.BasePath + "/group/" + UUIDUtils.getUUID() + "." + suffix;
String url = COSUtil.uploadFileByPath(realpath);
pics = url;
}
}
if ("".equals(pics)) {
return Result.error("图片不能为空!");
}
item.setGroupBuyPic(pics);
// 设置小区id集合的值 // 设置小区id集合的值
item.setAreaIds(JSON.toJSONString(item.getAreaIdList())); item.setAreaIds(JSON.toJSONString(item.getAreaIdList()));
item.setGroupStatus(3); item.setGroupStatus(3);
Calendar cal = Calendar.getInstance();
cal.setTime(item.getEndTime());
cal.set(Calendar.HOUR_OF_DAY, 23); //时
cal.set(Calendar.MINUTE, 59); //分
cal.set(Calendar.SECOND, 59); //秒
cal.set(Calendar.MILLISECOND, 0); //毫秒
item.setEndTime(cal.getTime());
// 保存活动基础信息 // 保存活动基础信息
this.mapper.insert(item); this.mapper.insert(item);
// 判断活动商品是否有值 // 判断活动商品是否有值
...@@ -103,11 +99,12 @@ public class GroupBuyServiceimpl implements GroupBuyService { ...@@ -103,11 +99,12 @@ public class GroupBuyServiceimpl implements GroupBuyService {
public GroupBuy findById(Long id) { public GroupBuy findById(Long id) {
// 团购基础信息 // 团购基础信息
GroupBuy groupBuy = this.mapper.selectById(id); GroupBuy groupBuy = this.mapper.selectById(id);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
groupBuy.setStartDate(formatter.format(groupBuy.getStartTime()));
groupBuy.setEndDate(formatter.format(groupBuy.getEndTime()));
// 团购商品 // 团购商品
List<GroupBuyProduct> products = groupBuyProductDao.selectList(Wrappers.<GroupBuyProduct>lambdaQuery() List<Product> products = groupBuyProductDao.getList(id);
.eq(GroupBuyProduct::getGroupBuyId, id) groupBuy.setProductList(JSON.toJSONString(products));
.eq(GroupBuyProduct::getStatus, 0));
groupBuy.setProducts(products);
// 团购小区 // 团购小区
String areaIds = groupBuy.getAreaIds(); String areaIds = groupBuy.getAreaIds();
if (StringUtils.isNotEmpty(areaIds)) { if (StringUtils.isNotEmpty(areaIds)) {
...@@ -117,6 +114,7 @@ public class GroupBuyServiceimpl implements GroupBuyService { ...@@ -117,6 +114,7 @@ public class GroupBuyServiceimpl implements GroupBuyService {
.in(GroupArea::getId, areaIdList) .in(GroupArea::getId, areaIdList)
.eq(GroupArea::getAreaStatus, 0)); .eq(GroupArea::getAreaStatus, 0));
groupBuy.setAreas(groupAreas); groupBuy.setAreas(groupAreas);
groupBuy.setAreaIdList(areaIdList);
} }
} }
return groupBuy; return groupBuy;
......
...@@ -127,4 +127,20 @@ public class GroupOrderServiceImpl implements GroupOrderService { ...@@ -127,4 +127,20 @@ public class GroupOrderServiceImpl implements GroupOrderService {
public List<OrderSub> productList(OrderSub item) { public List<OrderSub> productList(OrderSub item) {
return orderSubDao.getPageListByOrderMianId(item); return orderSubDao.getPageListByOrderMianId(item);
} }
/**
* 支付成功后判断团购订单是否成团
* @param curOrder
*/
public void isSuccess(OrderMain curOrder) {
GroupBuy groupBuy = orderDao.getGroupBuy(curOrder.getGroupOrderId());
Long count = orderMainDao.selectCount(Wrappers.<OrderMain>lambdaQuery()
.eq(OrderMain::getGroupOrderId, curOrder.getGroupOrderId())
.eq(OrderMain::getIpaystatus, 1)
.isNull(OrderMain::getIrefundstatus));
if (groupBuy.getGroupSize() <= count) {
orderDao.updateStatus(curOrder.getGroupOrderId());
}
}
} }
...@@ -7,12 +7,14 @@ import com.yunniu.farming.util.StringHelper; ...@@ -7,12 +7,14 @@ import com.yunniu.farming.util.StringHelper;
import com.yunniu.farming.util.UrlUtil; import com.yunniu.farming.util.UrlUtil;
import com.yunniu.farming.webadmin.dao.*; import com.yunniu.farming.webadmin.dao.*;
import com.yunniu.farming.webadmin.model.*; import com.yunniu.farming.webadmin.model.*;
import com.yunniu.farming.webadmin.service.GroupOrderService;
import com.yunniu.farming.webadmin.service.WxService; import com.yunniu.farming.webadmin.service.WxService;
import com.yunniu.farming.util.UUIDUtils; import com.yunniu.farming.util.UUIDUtils;
import com.yunniu.farming.wx.WxConfigUtil; import com.yunniu.farming.wx.WxConfigUtil;
import com.yunniu.farming.wx.WxUtil; import com.yunniu.farming.wx.WxUtil;
import com.yunniu.farming.wx.XMLUtil; import com.yunniu.farming.wx.XMLUtil;
import org.jdom.JDOMException; import org.jdom.JDOMException;
import org.osgi.framework.ServiceException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -38,6 +40,9 @@ public class WxServiceImpl implements WxService { ...@@ -38,6 +40,9 @@ public class WxServiceImpl implements WxService {
@Autowired @Autowired
private IntegralrecDao integralrecDao; private IntegralrecDao integralrecDao;
@Autowired
private GroupOrderServiceImpl groupOrderService;
// @Autowired // @Autowired
...@@ -207,7 +212,56 @@ public class WxServiceImpl implements WxService { ...@@ -207,7 +212,56 @@ public class WxServiceImpl implements WxService {
out.close(); out.close();
} }
/**
* 退款
* @param userId
* @param orderId
* @param request
* @return
*/
@Override
public Result wxRefund(Integer userId, Integer orderId, HttpServletRequest request) throws Exception {
OrderMain order = orderMainDao.selectByPrimaryKey(orderId);
if (order == null || !order.getCustomerid().equals(userId)) {
return new Result(102);
}
order.setSdef1("R" + StringHelper.getOrderno()); // 退款单号
order.setSrefundreason("拼团失败"); // 退款理由
order.setIrefundstatus(0);
order.setTrefundtime(new Date());
orderMainDao.updateById(order);
double tradeMoney = order.getDactmoney();
DecimalFormat decimalFormat = new DecimalFormat("###################");
SortedMap<Object, Object> parameters = new TreeMap<Object, Object>();
parameters.put("appid", WxConfigUtil.APPID); // 应用APPID
parameters.put("mch_id", WxConfigUtil.MCH_ID); // 微信支付分配的商户号
parameters.put("nonce_str", WxUtil.generateNonceStr()); // 随机字符串,不长于32位
parameters.put("sign_type", WxConfigUtil.MD5); // 签名类型
parameters.put("out_trade_no", order.getSorderno()); // 商户订单号
parameters.put("refund_fee_type", "CNY"); // 默认人民币:CNY
parameters.put("total_fee", decimalFormat.format(tradeMoney * 100)); // 订单总金额
parameters.put("refund_fee", decimalFormat.format(tradeMoney * 100)); // 订单总金额
//parameters.put("profit_sharing", "Y");
// 用户端实际ip
parameters.put("notify_url", WxConfigUtil.notify_url); // 接收微信支付异步通知回调地址
System.out.println("sign=====" + parameters);
// 设置签名
String sign = WxUtil.createSignMD5(parameters);
System.out.println("sign=====" + sign);
parameters.put("sign", sign);
// 封装请求参数结束
String requestXML = WxUtil.getRequestXml(parameters);
System.out.println(requestXML);
// 调用统一下单接口
String result = WxUtil.httpsRequest(WxConfigUtil.REFUND_ORDER_URL, "POST", requestXML);
System.out.println(result);
Map<String, String> map = XMLUtil.doXMLParse(result);
if (!"SUCCESS".equals(map.get("result_code"))){
throw new ServiceException("退款失败:" + map.get("return_msg"));
}
return new Result();
}
/** /**
...@@ -224,9 +278,10 @@ public class WxServiceImpl implements WxService { ...@@ -224,9 +278,10 @@ public class WxServiceImpl implements WxService {
//购买商品订单 //购买商品订单
if(curOrder.getItype() != null && curOrder.getItype() == OrderMain.ITYPE_TAKE){ if(curOrder.getItype() != null && curOrder.getItype() == OrderMain.ITYPE_TAKE){
this.oderMainServiceImpl.handleCommProuctOrder(curOrder); this.oderMainServiceImpl.handleCommProuctOrder(curOrder);
}else if(curOrder.getItype() != null && curOrder.getItype() == OrderMain.ITYPE_GROUP){
this.oderMainServiceImpl.handleCommProuctOrder(curOrder);
this.groupOrderService.isSuccess(curOrder);
} }
} }
......
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yunniu.farming.webadmin.dao.GroupBuyProductDao"> <mapper namespace="com.yunniu.farming.webadmin.dao.GroupBuyProductDao">
<insert id="insertBath"> <insert id="insertBath">
insert into group_buy_product insert into group_buy_product
(group_buy_id, product_id, product_name, (group_buy_id, product_id, product_name,
product_sduction, product_price,`status`, create_by) product_sduction, product_price, `status`, create_by)
values values
<foreach collection="products" index="index" item="item" separator=","> <foreach collection="products" index="index" item="item" separator=",">
( (#{id,jdbcType=BIGINT}, #{item.productId}, #{item.productName},
#{id,jdbcType=BIGINT}, #{item.productId}, #{item.productName}, #{item.productSduction}, #{item.productPrice}, 0, #{item.createBy})
#{item.productSduction}, #{item.productPrice}, 0, #{item.createBy}
)
</foreach> </foreach>
</insert> </insert>
<select id="getList" resultType="com.yunniu.farming.webadmin.model.Product">
select gbp.product_price,
p.id,
p.sshortpic,
p.sname,
p.sduction,
p.sunit,
p.doldprice,
p.dsaleprice,
dc.sname as catalogName
from group_buy_product gbp
left join product p on gbp.product_id = p.id
left join doc_catalog dc on p.catalogid = dc.id
where gbp.group_buy_id = #{id,jdbcType=BIGINT}
and gbp.status = 0
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -44,4 +44,24 @@ ...@@ -44,4 +44,24 @@
left join order_main om on go.id = om.group_order_id and om.ipaystatus = 1 left join order_main om on go.id = om.group_order_id and om.ipaystatus = 1
where go.id = #{id,jdbcType=BIGINT} where go.id = #{id,jdbcType=BIGINT}
</select> </select>
<select id="getList" resultType="com.yunniu.farming.webadmin.model.GroupOrder">
select go.*,
gb.group_size
from group_order go
left join group_buy gb on go.group_buy_id = gb.id
where go.group_status = 0
and gb.end_time &lt;= now()
</select>
<select id="getGroupBuy" resultType="com.yunniu.farming.webadmin.model.GroupBuy">
select gb.*
from group_order go
left join group_buy gb on go.group_buy_id = gb.id
where go.id = #{groupOrderId,jdbcType=BIGINT}
</select>
<update id="updateStatus">
update group_order set group_status = 1 where id = #{groupOrderId,jdbcType=BIGINT}
</update>
</mapper> </mapper>
\ No newline at end of file
...@@ -312,4 +312,10 @@ ...@@ -312,4 +312,10 @@
left join customer c on om.customerid = c.id left join customer c on om.customerid = c.id
where om.group_order_id = #{id,jdbcType=BIGINT} where om.group_order_id = #{id,jdbcType=BIGINT}
</select> </select>
<select id="selectByGroupOrderId" resultMap="BaseResultMap">
select *
from order_main
where group_order_id = #{id,jdbcType=BIGINT} and ipaystatus = 1
</select>
</mapper> </mapper>
...@@ -194,7 +194,6 @@ ...@@ -194,7 +194,6 @@
//监听行工具事件 //监听行工具事件
table.on('tool(tableId)', function (obj) { table.on('tool(tableId)', function (obj) {
var data = obj.data; var data = obj.data;
//console.log(obj)
if (obj.event === 'del') { if (obj.event === 'del') {
layer.confirm('删除后无法撤销,确定继续吗?', function (index) { layer.confirm('删除后无法撤销,确定继续吗?', function (index) {
$.ajax({ $.ajax({
......
...@@ -50,11 +50,11 @@ ...@@ -50,11 +50,11 @@
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label"><span style="color: red">*</span>团购活动有效期</label> <label class="layui-form-label"><span style="color: red">*</span>团购活动有效期</label>
<div class="layui-input-inline"> <div class="layui-input-inline">
<input type="date" class="layui-input" name="startTime" id="startTime" th:value="${obj.startTime}"> <input type="date" class="layui-input" name="startDate" id="startDate" th:value="${obj.startDate}" required="required">
</div> </div>
<label class="layui-form-label"></label> <label class="layui-form-label"></label>
<div class="layui-input-inline"> <div class="layui-input-inline">
<input type="date" class="layui-input" name="endTime" id="endTime" th:value="${obj.endTime}"> <input type="date" class="layui-input" name="endDate" id="endDate" th:value="${obj.endDate}" required="required">
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
</div> </div>
<label class="layui-form-label">简介</label> <label class="layui-form-label">简介</label>
<div class="layui-input-inline"> <div class="layui-input-inline">
<input type="number" step="1" class="layui-input" name="groupBlurb" id="groupBlurb" <input type="text" class="layui-input" name="groupBlurb" id="groupBlurb"
th:value="${obj.groupBlurb}"> th:value="${obj.groupBlurb}">
</div> </div>
</div> </div>
...@@ -77,18 +77,15 @@ ...@@ -77,18 +77,15 @@
<span style="color: red">*</span>团购图片 <span style="color: red">*</span>团购图片
</label> </label>
<div class="layui-input-inline" style="width: 700px"> <div class="layui-input-inline" style="width: 700px">
<div class="main"> <div class="layui-upload">
<div id="showimg"> <button type="button" class="layui-btn" id="uploadBtn"
<ul id="showui"> lay-data="{acceptMime: 'image/jpg, image/png, image/gif, image/bmp, image/jpeg'}">上传图片
</ul> </button>
<div id="showinput"> <div class="layui-upload-list">
</div> <img class="layui-upload-img" id="previewImg">
<p id="uploadText"></p>
<span style="color: red">图片建议500*250px</span>
</div> </div>
<br>
<a class="layui-btn layui-btn" onclick="uploadImg()"><i class="layui-icon layui-icon-add-1"></i>选择图片</a>
<input style="display: none" type="file" id="upgteimg" value=""
accept="image/jpg,image/jpeg,image/png,image/bmp" multiple/>
<br><span style="color: red">图片建议500*250px</span>
</div> </div>
</div> </div>
</div> </div>
...@@ -128,6 +125,13 @@ ...@@ -128,6 +125,13 @@
<script type="text/html" id="priceTpl"> <script type="text/html" id="priceTpl">
<input type="text" name="productPrice" value="{{d.productPrice}}" lay-event="editPrice"> <input type="text" name="productPrice" value="{{d.productPrice}}" lay-event="editPrice">
</script> </script>
<script type="text/html" id="sshortpic">
{{#if (d.sshortpic !=null && d.sshortpic !='') { }}
<img src="{{d.sshortpic }}">
{{# }else if(d.sshortpic ==null || d.sshortpic ==''){ }}
<span></span>
{{# } }}
</script>
<script type="text/javascript" th:src="@{/js/upload_img/js/updateimg.js}"></script> <script type="text/javascript" th:src="@{/js/upload_img/js/updateimg.js}"></script>
<script> <script>
...@@ -145,30 +149,63 @@ ...@@ -145,30 +149,63 @@
return this._bkGetActionUrl.call(this, action); return this._bkGetActionUrl.call(this, action);
} }
} }
var groupBuyPic;
layui.use('upload', function () {
var upload = layui.upload;
//执行实例
upload.render({
elem: '#uploadBtn', //绑定元素
url: 'uploads', //上传接口
accept: 'images', //允许上传的文件类型,这里只允许上传图片
exts: 'jpg|png|gif|bmp|jpeg', //允许上传的图片后缀名
size: 1024 * 10, //限制文件大小,单位 KB
acceptMime: 'image/jpg, image/png, image/gif, image/bmp, image/jpeg',
field: 'upfile',
before: function (obj) { //上传前回调
//预读本地文件示例,不支持ie8
obj.preview(function (index, file, result) {
$('#previewImg').attr('src', result); //预览图片
});
},
done: function (res) { //上传完毕回调
if (res.state === "SUCCESS") { //上传成功
$('#uploadText').text('上传成功');
groupBuyPic = res.url;
} else { //上传失败
$('#uploadText').text('上传失败');
}
},
error: function () { //请求异常回调
$('#uploadText').text('网络异常');
}
});
});
var selectedData = [];
$(function () {
if (id) {
// getGoodsInfo(goodsId);
showImg('[[${obj.groupBuyTitle}]]');
}
});
var field; var field;
var selectedData = [];
layui.use(['table'], function () { layui.use(['table'], function () {
var table = layui.table; var table = layui.table;
$(function () {
if (id) {
console.log("===========================",'[[${obj}]]')
showPic('[[${obj.groupBuyPic}]]');
showTable('[[${obj.productList}]]');
console.log(111111111,selectedData)
renderTable();
}
});
window.addEventListener('message', function (event) { window.addEventListener('message', function (event) {
console.log(event); console.log(event);
selectedData = event.data; selectedData = event.data;
renderTable(); renderTable();
}, false); }, false);
// table.on('selectedData', function (data) {
// selectedData = data;
// renderTable();
// });
function renderTable() { function renderTable() {
table.render({ table.render({
elem: '#tableId', elem: '#tableId',
data: selectedData, data: selectedData,
...@@ -177,14 +214,14 @@ ...@@ -177,14 +214,14 @@
cols: [ cols: [
[ [
{field: 'id', title: '编码'}, {field: 'id', title: '编码'},
{field: 'sshortpic', title: '头图'}, {field: 'sshortpic', title: '头图', toolbar: '#sshortpic'},
{field: 'sname', title: '名称'}, {field: 'sname', title: '名称'},
{field: 'catalogName', title: '分类'}, {field: 'catalogName', title: '分类'},
{field: 'doldprice', title: '原价'}, {field: 'doldprice', title: '原价'},
{field: 'dsaleprice', title: '售价'}, {field: 'dsaleprice', title: '售价'},
{ {
field: 'productPrice', title: '价格', templet: function (d) { field: 'productPrice', title: '价格', templet: function (d) {
return '<input type="text" class="layui-input" value="' + d.dsaleprice + '" onchange="updateProductPrice(' + d.id + ', this.value)">'; return '<input type="text" class="layui-input" value="' + d.productPrice + '" onchange="updateProductPrice(' + d.id + ', this.value)">';
} }
}, },
{field: '', width: 100, title: '操作', toolbar: '#table-handle', fixed: 'right'} {field: '', width: 100, title: '操作', toolbar: '#table-handle', fixed: 'right'}
...@@ -195,7 +232,6 @@ ...@@ -195,7 +232,6 @@
//头工具栏事件 //头工具栏事件
table.on('toolbar(tableId)', function (obj) { table.on('toolbar(tableId)', function (obj) {
console.log(obj)
switch (obj.event) { switch (obj.event) {
case 'add': case 'add':
var w = ($(window).width() * 0.9); var w = ($(window).width() * 0.9);
...@@ -223,7 +259,6 @@ ...@@ -223,7 +259,6 @@
//监听行工具事件 //监听行工具事件
table.on('tool(tableId)', function (obj) { table.on('tool(tableId)', function (obj) {
var data = obj.data; var data = obj.data;
console.log(11111111111111111, obj)
if (obj.event === 'del') { if (obj.event === 'del') {
var oldData = table.cache["tableId"]; var oldData = table.cache["tableId"];
oldData.splice(obj.tr.data('index'), 1); oldData.splice(obj.tr.data('index'), 1);
...@@ -246,6 +281,7 @@ ...@@ -246,6 +281,7 @@
} }
function save() { function save() {
console.log(11111111111, groupBuyPic);
if ($("#formId input[name='groupBuyTitle']").val() == '') { if ($("#formId input[name='groupBuyTitle']").val() == '') {
layer.msg("活动标题不能为空!"); layer.msg("活动标题不能为空!");
return false; return false;
...@@ -256,15 +292,17 @@ ...@@ -256,15 +292,17 @@
return false; return false;
} }
if ($("#formId input[name='startTime']").val() == '') { if ($("#formId input[name='startDate']").val() == '') {
layer.msg("开始时间不能为空!"); layer.msg("开始时间不能为空!");
return false; return false;
} }
if ($("#formId input[name='endTime']").val() == '') { if ($("#formId input[name='endDate']").val() == '') {
layer.msg("结束时间不能为空!"); layer.msg("结束时间不能为空!");
return false; return false;
} }
var startTime = $("#formId input[name='startDate']").val();
var endTime = $("#formId input[name='endDate']").val();
if (!$("#areaIdList").val()) { if (!$("#areaIdList").val()) {
layer.msg("配送小区不能为空!"); layer.msg("配送小区不能为空!");
...@@ -300,14 +338,12 @@ ...@@ -300,14 +338,12 @@
products.push(product); products.push(product);
} }
// 打印目标数组 // 打印目标数组
console.log(JSON.stringify(products));
console.log(JSON.stringify(areaIdList));
formdata.append("groupDetail", content); formdata.append("groupDetail", content);
var goodsImgArr = [dataArr.length]; var goodsImgArr = [dataArr.length];
for (var i = 0; i < dataArr.length; i++) { for (var i = 0; i < dataArr.length; i++) {
goodsImgArr[i] = dataArr[i].base64; goodsImgArr[i] = dataArr[i].base64;
} }
formdata.append("groupBuyPic", goodsImgArr[0]); // formdata.append("goodsImgArr", goodsImgArr);
formdata.append("id", id); formdata.append("id", id);
var groupBuy = JSON.stringify( var groupBuy = JSON.stringify(
...@@ -316,11 +352,14 @@ ...@@ -316,11 +352,14 @@
return data; return data;
}, {}) }, {})
); );
// console.log(" ====================== ",typeof groupBuy, groupBuy); console.log(products)
groupBuy = JSON.parse(groupBuy) groupBuy = JSON.parse(groupBuy)
groupBuy.areaIdList = areaIdList; groupBuy.areaIdList = areaIdList;
groupBuy.products = products; groupBuy.products = products;
console.log(11111111, groupBuy) groupBuy.goodsImgArr = goodsImgArr;
groupBuy.groupBuyPic = groupBuyPic;
groupBuy.startTime = startTime;
groupBuy.endTime = endTime;
$.ajax({ $.ajax({
url: "addOrUpdate", url: "addOrUpdate",
data: JSON.stringify(groupBuy), data: JSON.stringify(groupBuy),
...@@ -360,10 +399,16 @@ ...@@ -360,10 +399,16 @@
showui.replaceChild(li); showui.replaceChild(li);
} }
function showPic(groupPic) {
$('#previewImg').attr('src', groupPic);
}
function showTable(products) {
console.log(44444444444, products)
const newStr = products.replace(/&quot;/g, '"');
console.log(3333333333, newStr)
selectedData = JSON.parse(newStr)
console.log(222222222, selectedData)
function uploadImg() {
$("#showui").children().remove()
$("#upgteimg").click();
} }
layui.use('form', function () { layui.use('form', function () {
......
...@@ -259,7 +259,6 @@ ...@@ -259,7 +259,6 @@
//监听行工具事件 //监听行工具事件
table.on('tool(tableId)', function (obj) { table.on('tool(tableId)', function (obj) {
var data = obj.data; var data = obj.data;
//console.log(obj)
if (obj.event === 'del') { if (obj.event === 'del') {
layer.confirm('删除后无法撤销,确定继续吗?', function (index) { layer.confirm('删除后无法撤销,确定继续吗?', function (index) {
$.ajax({ $.ajax({
......
...@@ -106,7 +106,6 @@ ...@@ -106,7 +106,6 @@
form.on('submit(The-search)', function (data) { form.on('submit(The-search)', function (data) {
field = data.field; field = data.field;
//执行重载 //执行重载
// console.log(field)
table.reload('tableId', { table.reload('tableId', {
where: field where: field
, page: { , page: {
...@@ -230,7 +229,6 @@ ...@@ -230,7 +229,6 @@
var data = obj.data; var data = obj.data;
var id = data.userId; var id = data.userId;
var name = data.userName; var name = data.userName;
//console.log(obj)
//启用 //启用
if (obj.event === 'distributor') { if (obj.event === 'distributor') {
layer.confirm('确定更改' + name + '状态吗?', function (index) { layer.confirm('确定更改' + name + '状态吗?', function (index) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment