Commit 1d14efba by caiyt

修复bug及实现新增需求

parent 2b05019f
......@@ -117,8 +117,19 @@ public class AppController extends BaseController {
return getDataTable(couponVos);
}
@GetMapping("/homepage/coupon-count")
@ApiOperation("小程序首页查询用户可用优惠券数量")
public AjaxResult getUserAvailableCouponCnt(HttpServletRequest request) {
LoginUser loginUser = tokenService.getLoginUser(request);
if (loginUser == null) {
throw new ServiceException("请先登录");
}
int custAvailableCouponCnt = couponUserService.getCustAvailableCouponCnt(loginUser.getOpenId());
return AjaxResult.success(custAvailableCouponCnt);
}
@PostMapping("/order/coupon/fitable-count")
@ApiOperation("查询用户可用优惠券数量")
@ApiOperation("小程序下单页面查询用户可用优惠券数量")
public AjaxResult getUserAvailableCouponCnt(HttpServletRequest request, @RequestBody Order order) {
LoginUser loginUser = tokenService.getLoginUser(request);
if (loginUser == null) {
......@@ -137,6 +148,7 @@ public class AppController extends BaseController {
if (loginUser == null) {
throw new ServiceException("请先登录");
}
loginUser.setOpenId("oA0gy4x4bUZcULVYwsLI_EW901mg");
List<CouponVo> couponVos = couponUserService.listCustAvailableCoupon(loginUser.getOpenId(), null);
couponUserService.resovleCouponFitable(couponVos, order);
couponRuleService.translateUseLimit(couponVos);
......
......@@ -47,26 +47,26 @@ public class ApplicationController {
String key = jj.getString("key");
JSONObject location = jj.getJSONObject("location");
String s = stringRedisTemplate.opsForValue().get(key);
if(StringUtils.isEmpty(s)){
if (StringUtils.isEmpty(s)) {
throw new ServiceException("该二维码已经过期");
}
JSONObject info = JSONObject.parseObject(s);
String machineCode = info.getString("machineCode");
Machine machine = machineService.selectMachineByCode(machineCode);
Shop shop = shopService.selectShopById(machine.getShopId());
shop.setDistance(AppServiceImpl.GetDistance(Double.parseDouble(shop.getLng()),Double.parseDouble(shop.getLat()),Double.parseDouble(location.getString("lng")),Double.parseDouble(location.getString("lat"))));
info.put("shop",shop);
shop.setDistance(AppServiceImpl.getDistance(Double.parseDouble(shop.getLng()), Double.parseDouble(shop.getLat()), Double.parseDouble(location.getString("lng")), Double.parseDouble(location.getString("lat"))));
info.put("shop", shop);
String[] keys = key.split("_");
//推送数据给安卓
JSONObject jsonObject = new JSONObject();
jsonObject.put("action","QRCODE_VISITED");
jsonObject.put("timestamp",String.valueOf(System.currentTimeMillis()));
JSONObject jsonObject = new JSONObject();
jsonObject.put("action", "QRCODE_VISITED");
jsonObject.put("timestamp", String.valueOf(System.currentTimeMillis()));
JSONObject data = new JSONObject();
data.put("seqNo",key);
jsonObject.put("data",data);
jiGuangPushService.push(keys[0],jsonObject);
// stringRedisTemplate.delete(key);
return AjaxResult.success("处理成功",info.toJSONString());
data.put("seqNo", key);
jsonObject.put("data", data);
jiGuangPushService.push(keys[0], jsonObject);
// stringRedisTemplate.delete(key);
return AjaxResult.success("处理成功", info.toJSONString());
}
@RequestMapping("/jgRegister")
public AjaxResult jgRegister(@RequestParam String machineCode,@RequestParam String registerId){
......
......@@ -46,6 +46,10 @@ public class CustomerController extends BaseController {
throw new ServiceException("请先登录");
}
customer.setId(loginUser.getOpenId());
Assert.notNull(customer.getSendMsgFlag1(), "用户授权发送消息1未传递");
Assert.notNull(customer.getSendMsgFlag2(), "用户授权发送消息2未传递");
Assert.notNull(customer.getSendMsgFlag3(), "用户授权发送消息3未传递");
Assert.notNull(customer.getRememberFlag(), "记住标识未传递");
customerService.updateSendMsgFlag(customer);
return AjaxResult.success();
}
......
......@@ -5,36 +5,41 @@ import com.soss.common.core.controller.BaseController;
import com.soss.common.core.domain.AjaxResult;
import com.soss.common.core.page.TableDataInfo;
import com.soss.common.enums.BusinessType;
import com.soss.common.enums.SkuDeleteState;
import com.soss.common.exception.ServiceException;
import com.soss.system.domain.Goods;
import com.soss.system.domain.GoodsSku;
import com.soss.system.service.IGoodsService;
import com.soss.system.service.IGoodsSkuService;
import io.jsonwebtoken.lang.Assert;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Objects;
/**
* 商品Controller
*
*
* @author zxq
* @date 2022-04-28
*/
@RestController
@RequestMapping("/system/goods")
public class GoodsController extends BaseController
{
public class GoodsController extends BaseController {
@Autowired
private IGoodsService goodsService;
@Autowired
private IGoodsSkuService goodsSkuService;
/**
* 查询商品列表
*/
@PreAuthorize("@ss.hasPermi('system:goods:list')")
@GetMapping("/list")
public TableDataInfo list(Goods goods)
{
public TableDataInfo list(Goods goods) {
startPage();
List<Goods> list = goodsService.selectGoodsList(goods);
return getDataTable(list);
......@@ -118,4 +123,37 @@ public class GoodsController extends BaseController
public AjaxResult getGoodsSkuList(@PathVariable("goodsId") Long goodsId) {
return AjaxResult.success(goodsService.getGoodsSkus(goodsId));
}
/**
* 删除sku
*/
@PreAuthorize("@ss.hasPermi('system:goods:sku:delete')")
@GetMapping("/sku/delete/{id}")
@ApiOperation("删除sku")
public AjaxResult deleteSkuManual(@PathVariable("id") Long skuId) {
GoodsSku sku = goodsSkuService.selectGoodsSkuById(skuId);
Assert.notNull(sku, "未查询到匹配的sku记录[id=" + skuId + "]");
Assert.isTrue(Objects.equals(sku.getIsDeleted(), SkuDeleteState.NORMAL.getState()), "当前状态不允许做该操作");
Goods goods = goodsService.selectGoodsById(sku.getGoodsId());
Assert.notNull(goods, "未查询到sku匹配的商品信息");
Assert.isTrue(Objects.equals(goods.getState(), "4"), "需先下架商品之后才可删除");
sku.setIsDeleted(SkuDeleteState.DELETE_MANUAL.getState());
goodsSkuService.updateGoodsSku(sku);
return AjaxResult.success();
}
/**
* 恢复sku
*/
@PreAuthorize("@ss.hasPermi('system:goods:sku:recover')")
@GetMapping("/sku/recover/{id}")
@ApiOperation("恢复sku")
public AjaxResult recoverSku(@PathVariable("id") Long skuId) {
GoodsSku sku = goodsSkuService.selectGoodsSkuById(skuId);
Assert.notNull(sku, "未查询到匹配的sku记录[id=" + skuId + "]");
Assert.isTrue(Objects.equals(sku.getIsDeleted(), SkuDeleteState.DELETE_MANUAL.getState()), "当前状态不允许做该操作");
sku.setIsDeleted(SkuDeleteState.NORMAL.getState());
goodsSkuService.updateGoodsSku(sku);
return AjaxResult.success();
}
}
......@@ -15,6 +15,7 @@ import com.soss.system.domain.vo.CouponVo;
import com.soss.system.domain.vo.OrderQuery;
import com.soss.system.service.ICouponUserService;
import com.soss.system.service.impl.OrderServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.CollectionUtils;
......@@ -33,6 +34,7 @@ import java.util.Map;
* @date 2022-04-28
*/
@RestController
@Slf4j
@RequestMapping("/order")
public class OrderController extends BaseController {
@Autowired
......@@ -116,6 +118,8 @@ public class OrderController extends BaseController {
order.setCouponAmount(couponVo.getCouponAmount().negate());
order.setPaidAmount(order.getAmount().add(order.getCouponAmount()));
order.setCouponId(couponVo.getCouponId());
} else {
couponUserService.orderDetailCheckAndAssign(order.getOrderDetails());
}
AjaxResult ajaxResult = orderService.insertOrder(loginUser, order, couponUserId);
......@@ -123,6 +127,9 @@ public class OrderController extends BaseController {
return ajaxResult;
}
int amount = order.getPaidAmount().movePointRight(2).intValue();
if (amount == 0) {
return AjaxResult.success(order.getId());
}
Map payInfo = weixinService.pay(request, "hooloo", order.getOrderNo(), order.getUserId(), amount);
if (payInfo != null) {
payInfo.put("orderId", order.getId());
......@@ -138,6 +145,9 @@ public class OrderController extends BaseController {
order.setOrderNo(orderService.getOrderNo(order.getSource()));
orderService.updateOrder(order);
int amount = order.getPaidAmount().movePointRight(2).intValue();
if (amount == 0) {
return AjaxResult.success();
}
Map payInfo = weixinService.pay(request, "hooloo", order.getOrderNo(), order.getUserId(), amount);
if (payInfo != null) {
return AjaxResult.success(payInfo);
......
......@@ -11,18 +11,24 @@ import com.soss.common.exception.ServiceException;
import com.soss.common.utils.StringUtils;
import com.soss.framework.web.service.TokenService;
import com.soss.framework.web.service.WeixinServiceImpl;
import com.soss.system.domain.Goods;
import com.soss.system.domain.Order;
import com.soss.system.domain.OrderDetail;
import com.soss.system.domain.OrderRefund;
import com.soss.system.domain.vo.OrderQuery;
import com.soss.system.service.IGoodsService;
import com.soss.system.service.IOrderRefundService;
import com.soss.system.service.impl.OrderServiceImpl;
import io.jsonwebtoken.lang.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* 订单退款Controller
......@@ -42,6 +48,8 @@ public class OrderRefundController extends BaseController
private TokenService tokenService;
@Autowired
private OrderServiceImpl orderService;
@Autowired
private IGoodsService goodsService;
/**
* 查询订单退款列表
......@@ -71,7 +79,23 @@ public class OrderRefundController extends BaseController
@PreAuthorize("@ss.hasPermi('system:refund:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") String id) {
return AjaxResult.success(orderRefundService.selectOrderRefundById(id));
OrderRefund refund = orderRefundService.selectOrderRefundById(id);
Order order = refund.getOrder();
if (order == null) {
return AjaxResult.success(refund);
}
List<OrderDetail> orderDetails = order.getOrderDetails();
if (CollectionUtils.isEmpty(orderDetails)) {
return AjaxResult.success(refund);
}
List<Long> goodsIds = orderDetails.stream().map(OrderDetail::getGoodsId).collect(Collectors.toList());
List<Goods> goods = goodsService.selectGoodsByIds(goodsIds);
orderDetails.forEach(orderDetail -> goods.forEach(good -> {
if (Objects.equals(orderDetail.getGoodsId(), good.getId())) {
orderDetail.setGoods(good);
}
}));
return AjaxResult.success(refund);
}
/**
......@@ -95,10 +119,14 @@ public class OrderRefundController extends BaseController
if (obejct instanceof OrderRefund) {
OrderRefund orderRefund1 = (OrderRefund) obejct;
if (RefundState.PENDING.getState().equals(orderRefund1.getState())) {
int totalFee = orderRefund1.getTotalFee().movePointRight(2).intValue();
int refundAmount = orderRefund1.getRefundAmount().movePointRight(2).intValue();
weixinService.refund(orderRefund1.getOrderNo(), orderRefund1.getRefundNo(), totalFee, refundAmount);
orderRefund1.setState(RefundState.REFUNDING.getState());
if (refundAmount > 0) {
int totalFee = orderRefund1.getOrder().getPaidAmount().movePointRight(2).intValue();
weixinService.refund(orderRefund1.getOrderNo(), orderRefund1.getRefundNo(), totalFee, refundAmount);
orderRefund1.setState(RefundState.REFUNDING.getState());
} else {
orderRefund1.setState(RefundState.SUCCESS.getState());
}
orderRefundService.updateOrderRefund(orderRefund1);
}
}
......
......@@ -8,7 +8,9 @@ import com.soss.common.core.domain.AjaxResult;
import com.soss.common.core.page.TableDataInfo;
import com.soss.common.enums.BusinessType;
import com.soss.system.domain.Goods;
import com.soss.system.domain.GoodsCategory;
import com.soss.system.domain.Shop;
import com.soss.system.service.IGoodsService;
import com.soss.system.service.IShopService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -22,20 +24,21 @@ import java.util.Map;
/**
* 店铺Controller
*
*
* @author zxq
* @date 2022-04-28
*/
@RestController
@RequestMapping("/system/shop")
public class ShopController extends BaseController
{
public class ShopController extends BaseController {
@Autowired
private IShopService shopService;
@Autowired
private IGoodsService goodsService;
@GetMapping(value = "/turn")
public AjaxResult turn(@RequestParam Long shopId,@RequestParam Long goodsId, @RequestParam String pointer){
return AjaxResult.success(shopService.turn(shopId,goodsId,pointer));
public AjaxResult turn(@RequestParam Long shopId, @RequestParam Long goodsId, @RequestParam String pointer) {
return AjaxResult.success(shopService.turn(shopId, goodsId, pointer));
}
/**
......@@ -135,27 +138,29 @@ public class ShopController extends BaseController
return AjaxResult.success(shopService.addGoods(shopId,goodsIds));
}
@PostMapping(value = "/offGoods")
public AjaxResult offGoods(@RequestBody String body)
{
public AjaxResult offGoods(@RequestBody String body) {
JSONObject jsonObject = JSON.parseObject(body);
return AjaxResult.success(shopService.offGoods(jsonObject));
}
/**
* 获取店铺里面的商品信息,分类展示
*/
@GetMapping(value = "/getCategoryGoods")
public AjaxResult getCategoryGoods(long shopId)
{
return AjaxResult.success(shopService.getCategoryGoods(shopId));
public AjaxResult getCategoryGoods(long shopId) {
List<GoodsCategory> categoryGoods = shopService.getCategoryGoods(shopId);
for (GoodsCategory categoryGood : categoryGoods) {
goodsService.resolverCategoryName(categoryGood.getGoodsList());
}
return AjaxResult.success(categoryGoods);
}
/**
* 获取店铺里面商品对应的产品信息
*/
@GetMapping(value = "/getSkuByGoodsId")
public AjaxResult getSkuByGoodsId(long shopId,long goodsId)
{
return AjaxResult.success(shopService.getSkuByGoodsId(shopId,goodsId));
public AjaxResult getSkuByGoodsId(long shopId, long goodsId) {
return AjaxResult.success(shopService.getSkuByGoodsId(shopId, goodsId));
}
/**
......
......@@ -3,7 +3,13 @@ package com.soss.web.controller.coffee;
import com.alibaba.fastjson.JSONObject;
import com.soss.common.constant.Constants;
import com.soss.common.core.domain.AjaxResult;
import com.soss.common.core.domain.model.LoginUser;
import com.soss.common.utils.StringUtils;
import com.soss.framework.web.service.TokenService;
import com.soss.framework.web.service.WeixinServiceImpl;
import com.soss.system.domain.Customer;
import com.soss.system.domain.Shop;
import com.soss.system.service.ICustomerService;
import com.soss.system.service.impl.AppServiceImpl;
import com.soss.system.service.impl.OrderTakingServiceImpl;
import com.soss.system.utils.SendSmsUtil;
......@@ -19,25 +25,29 @@ import java.util.Map;
@RequestMapping("/weixin")
@Slf4j
public class WeixinController {
@Autowired
private TokenService tokenService;
@Autowired
WeixinServiceImpl weixinService;
@Autowired
private AppServiceImpl appService;
@Autowired
private OrderTakingServiceImpl orderTakingService;
@Autowired
private ICustomerService customerService;
//这个就是那个使用传code进来的接口
@PostMapping("/login")
public AjaxResult login(@RequestBody String body){
public AjaxResult login(@RequestBody String body) {
JSONObject param = JSONObject.parseObject(body);
String code =param.getString("code");
String code = param.getString("code");
return AjaxResult.success(weixinService.login(code));
return AjaxResult.success(weixinService.login(code));
}
@PostMapping("/decrypt")
public AjaxResult decrypt(@RequestBody String body){
public AjaxResult decrypt(@RequestBody String body) {
JSONObject param = JSONObject.parseObject(body);
String encryptedData = param.getString("encryptedData");
String iv = param.getString("iv");
......@@ -70,20 +80,34 @@ public class WeixinController {
*/
@PostMapping("/native/notify")
public String wxNotify(HttpServletRequest request) throws Exception {
System.out.println("微信发送的回调");
return weixinService.wxNotify(request);
}
@RequestMapping("/getShop")
public AjaxResult getShop(@RequestParam(required = false)String lng,@RequestParam(required = false)String lat){
return AjaxResult.success(appService.getShop(lng,lat));
public AjaxResult getShop(HttpServletRequest request, @RequestParam(required = false) String lng, @RequestParam(required = false) String lat) {
LoginUser loginUser = tokenService.getLoginUser(request);
Shop shop;
if (loginUser == null || StringUtils.isEmpty(loginUser.getOpenId())) {
shop = appService.getShop(lng, lat, false);
} else {
Customer customer = customerService.selectCustById(loginUser.getOpenId());
shop = appService.getShop(lng, lat, customer.getTestFlag());
}
return AjaxResult.success(shop);
}
@RequestMapping("/getArea")
public AjaxResult getArea(@RequestParam(required = false) String lng,@RequestParam(required = false)String lat){
List<JSONObject> area = weixinService.getArea(lng,lat);
public AjaxResult getArea(HttpServletRequest request, @RequestParam(required = false) String lng, @RequestParam(required = false) String lat) {
LoginUser loginUser = tokenService.getLoginUser(request);
List<JSONObject> area;
if (loginUser == null || StringUtils.isEmpty(loginUser.getOpenId())) {
area = weixinService.getArea(lng, lat, false);
} else {
Customer customer = customerService.selectCustById(loginUser.getOpenId());
area = weixinService.getArea(lng, lat, customer.getTestFlag());
}
return AjaxResult.success(area);
}
......
package com.soss.web.controller.coupon;
import com.github.pagehelper.PageInfo;
import com.soss.common.annotation.Log;
import com.soss.common.core.controller.BaseController;
import com.soss.common.core.domain.AjaxResult;
......@@ -80,12 +81,14 @@ public class CouponController extends BaseController {
return couponVo;
}).collect(Collectors.toList());
couponRuleService.translateUseLimit(voList);
return getDataTable(voList);
TableDataInfo dataTable = getDataTable(voList);
dataTable.setTotal(new PageInfo(coupons).getTotal());
return dataTable;
}
private void transLimitToArrStyle(CouponVo couponVo, CouponRule couponRule) {
BeanUtils.copyProperties(couponRule, couponVo, "name", "state", "categoryIds", "goodsIds", "province", "city", "area", "shopIds");
couponVo.setCategoryIds(ArrayUtil.transStrToCodeList(couponRule.getCategoryIds()));
couponVo.setCategoryIds(ArrayUtil.transStrToLongList(couponRule.getCategoryIds()));
couponVo.setGoodsIds(ArrayUtil.transStrToLongList(couponRule.getGoodsIds()));
couponVo.setProvince(ArrayUtil.transStrToCodeList(couponRule.getProvince()));
couponVo.setCity(ArrayUtil.transStrToCodeList(couponRule.getCity()));
......@@ -187,7 +190,7 @@ public class CouponController extends BaseController {
*/
@PreAuthorize("@ss.hasPermi('coupon:list:effective')")
@Log(title = "获取当前有效的规则集合", businessType = BusinessType.INSERT)
@DeleteMapping("/list/effective")
@GetMapping("/list/effective")
@ApiOperation("获取当前有效的规则集合")
public TableDataInfo listEffective() {
startPage();
......
package com.soss.common.enums;
public enum CouponState {
DEFAULT(0, "默认"),
ONLINE(1, "生效中"),
OFFLINE(2, "未生效"),
EXPIRED(3, "已失效"),
......
package com.soss.common.enums;
/**
* sku删除状态枚举类
*/
public enum SkuDeleteState {
NORMAL(0, "未删除"),
DELETE_AUTO(1, "自动删除"),
DELETE_MANUAL(2, "手动删除");
private Integer state;
private String desc;
SkuDeleteState(Integer state, String desc) {
this.state = state;
this.desc = desc;
}
public Integer getState() {
return state;
}
public static String getDesc(Integer state) {
for (SkuDeleteState skuDeleteState : SkuDeleteState.values()) {
if (skuDeleteState.state.equals(state)) {
return skuDeleteState.desc;
}
}
return null;
}
}
......@@ -15,6 +15,7 @@ import com.github.wxpay.sdk.WXPayUtil;
import com.soss.common.core.domain.entity.SysUser;
import com.soss.common.core.domain.model.LoginUser;
import com.soss.common.enums.RefundState;
import com.soss.common.enums.ShopState;
import com.soss.common.exception.ServiceException;
import com.soss.common.utils.StringUtils;
import com.soss.common.utils.ip.IpUtils;
......@@ -37,6 +38,7 @@ import com.soss.system.weixin.util.RandomStringGenerator;
import com.soss.system.weixin.util.SendMessageUtils;
import com.soss.system.weixin.util.Signature;
import com.thoughtworks.xstream.XStream;
import org.apache.commons.lang3.BooleanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -536,25 +538,25 @@ public class WeixinServiceImpl {
return WxPayNotifyResponse.fail("回调有误!");
}
public List<JSONObject> getArea(String lng,String lat) {
public List<JSONObject> getArea(String lng, String lat, Boolean testFlag) {
String provinceString ="[value ='%s'][0].label";
String cityString ="[value='%s'][0].children[value='%s'][0].label";
String zoneString = "[value='%s'][0].children[value='%s'][0].children[value='%s'][0].label";
Shop shop = new Shop();
if (BooleanUtils.isTrue(testFlag)) {
shop.setStates(Arrays.asList(ShopState.TESTING.getState(), ShopState.OPEN.getState()));
} else {
shop.setState(ShopState.OPEN.getState());
}
List<Shop> shops = shopMapper.selectShopList(shop);
List<JSONObject> proviceList = new ArrayList<>();
List<String> proString = new ArrayList<>();
for (Shop shop1 : shops) {
if("3".equals(shop1.getState())){
continue;
}
if(StringUtils.isNotEmpty(lng)&&StringUtils.isNotEmpty(lat)){
String aa = AppServiceImpl.GetDistance(Double.parseDouble(lng), Double.parseDouble(lat), Double.parseDouble(shop1.getLng()), Double.parseDouble(shop1.getLat()));
shop1.setDistance(aa);
double realDistance = AppServiceImpl.GetRealDistance(Double.parseDouble(lng), Double.parseDouble(lat), Double.parseDouble(shop1.getLng()), Double.parseDouble(shop1.getLat()));
if (StringUtils.isNotEmpty(lng) && StringUtils.isNotEmpty(lat)) {
double realDistance = AppServiceImpl.getRealDistance(Double.parseDouble(lng), Double.parseDouble(lat), Double.parseDouble(shop1.getLng()), Double.parseDouble(shop1.getLat()));
shop1.setRealDistance(realDistance);
}else{
shop1.setDistance(AppServiceImpl.getDistance(realDistance));
} else {
shop1.setDistance("-1");
}
String province = shop1.getProvince();
......
......@@ -70,6 +70,9 @@ public class Customer extends BaseEntity
@ApiModelProperty("用户授权有效期,空则永久有效")
private LocalDateTime flagExpireDate;
@ApiModelProperty("测试用户标识:true-测试用户")
private Boolean testFlag;
private List<Order> refundOrder;
private List<Order> normalOrder;
......
package com.soss.system.domain;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.soss.common.annotation.Excel;
import com.soss.common.core.domain.BaseEntity;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* 商品对象 goods
......@@ -16,6 +17,7 @@ import com.soss.common.core.domain.BaseEntity;
* @author zxq
* @date 2022-04-28
*/
@Data
public class Goods extends BaseEntity
{
private static final long serialVersionUID = 1L;
......@@ -27,14 +29,6 @@ public class Goods extends BaseEntity
@Excel(name = "商品名称")
private String name;
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
/** 商品分类 */
@Excel(name = "商品分类")
private String category;
......@@ -92,54 +86,15 @@ public class Goods extends BaseEntity
@Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date updatedAt;
public Date getShelfAt() {
return shelfAt;
}
public void setShelfAt(Date shelfAt) {
this.shelfAt = shelfAt;
}
public Date getRecommendDate() {
return recommendDate;
}
public void setRecommendDate(Date recommendDate) {
this.recommendDate = recommendDate;
}
@JsonFormat(pattern = "yyyy-MM-dd")
private Date shelfAt;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:dd")
private Date recommendDate;
public Integer getSalesVolume() {
return salesVolume;
}
public void setSalesVolume(Integer salesVolume) {
this.salesVolume = salesVolume;
}
public String getRecommend() {
return recommend;
}
public void setRecommend(String recommend) {
this.recommend = recommend;
}
public String getPreferential() {
return preferential;
}
public void setPreferential(String preferential) {
this.preferential = preferential;
}
private String recommend;
private String preferential;
/**
* 总销量
*/
......@@ -151,150 +106,10 @@ public class Goods extends BaseEntity
private List<String> goodsTagList;
public List<String> getGoodsTagList() {
return goodsTagList;
}
public void setGoodsTagList(List<String> goodsTagList) {
this.goodsTagList = goodsTagList;
}
public void setId(long id)
{
this.id = id;
}
public long getId()
{
return id;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setCategory(String category)
{
this.category = category;
}
public String getCategory()
{
return category;
}
public void setPrice(BigDecimal price)
{
this.price = price;
}
public BigDecimal getPrice()
{
return price;
}
public void setDiscount(BigDecimal discount)
{
this.discount = discount;
}
public BigDecimal getDiscount()
{
return discount;
}
public void setTakeTime(Long takeTime)
{
this.takeTime = takeTime;
}
public Long getTakeTime()
{
return takeTime;
}
public void setSpec(String spec)
{
this.spec = spec;
}
public String getSpec()
{
return spec;
}
public void setPics(String pics)
{
this.pics = pics;
}
public String getPics()
{
return pics;
}
public void setDesc(String desc)
{
this.desc = desc;
}
public String getDesc()
{
return desc;
}
public void setRemarks(String remarks)
{
this.remarks = remarks;
}
public String getRemarks()
{
return remarks;
}
public void setState(String state)
{
this.state = state;
}
public String getState()
{
return state;
}
public void setIsDeleted(Long isDeleted)
{
this.isDeleted = isDeleted;
}
public Long getIsDeleted()
{
return isDeleted;
}
public void setCreatedAt(Date createdAt)
{
this.createdAt = createdAt;
}
public Date getCreatedAt()
{
return createdAt;
}
public void setUpdatedAt(Date updatedAt)
{
this.updatedAt = updatedAt;
}
public Date getUpdatedAt()
{
return updatedAt;
}
public void setCode(String code)
{
this.code = code;
}
public String getCode()
{
return code;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
......
......@@ -22,7 +22,7 @@ public class GoodsCategory extends BaseEntity {
/**
* 主键
*/
private String id;
private Long id;
/**
* 分类名称
......
......@@ -33,8 +33,8 @@ public class GoodsSku extends BaseEntity
private String ruleList;
/** 是否删除0否1是 */
@Excel(name = "是否删除0否1是")
private String isDeleted;
@Excel(name = "是否删除0否 1-自动删除 2-手动删除")
private Integer isDeleted;
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
......
package com.soss.system.domain;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.soss.common.annotation.Excel;
......@@ -11,6 +12,7 @@ import com.soss.common.core.domain.BaseEntity;
* @author zxq
* @date 2022-05-22
*/
@Data
public class OrderSnapshot extends BaseEntity
{
private static final long serialVersionUID = 1L;
......@@ -22,25 +24,6 @@ public class OrderSnapshot extends BaseEntity
@Excel(name = "快照数据")
private String snapshot;
public void setOrderId(Long orderId)
{
this.orderId = orderId;
}
public Long getOrderId()
{
return orderId;
}
public void setSnapshot(String snapshot)
{
this.snapshot = snapshot;
}
public String getSnapshot()
{
return snapshot;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
......
......@@ -10,6 +10,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* 店铺对象 shop
......@@ -92,9 +93,14 @@ public class Shop extends BaseEntity
@Excel(name = "店铺状态 1 正常 2 暂停营业 3 关闭")
private Integer state;
/**
* 状态集合,查询时用
*/
private List<Integer> states;
private String distance;
private double realDistance;
private Double realDistance;
private String machieStatus;
......
......@@ -22,7 +22,7 @@ public class CouponPo {
private Integer categoryId;
@ApiModelProperty("可用商品类别列表,全品类传 [0]")
private String[] categoryIds;
private Long[] categoryIds;
@ApiModelProperty("可用商品id列表")
private Long[] goodsIds;
......
......@@ -33,6 +33,9 @@ public class CouponVo extends CouponPo {
@ApiModelProperty("优惠券类型描述")
private String typeDesc;
@ApiModelProperty("优惠券通用描述")
private String categoryDesc;
@ApiModelProperty("优惠券状态")
private Integer state;
......
package com.soss.system.domain.vo.orderTaking;
import com.alibaba.fastjson.JSONArray;
import lombok.Data;
import java.io.Serializable;
@Data
public class SkuVo implements Serializable {
private String skuId;
private String state;
public String getSkuId() {
return skuId;
}
public void setSkuId(String skuId) {
this.skuId = skuId;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getIsDefault() {
return isDefault;
}
public void setIsDefault(String isDefault) {
this.isDefault = isDefault;
}
public JSONArray getRules() {
return rules;
}
public void setRules(JSONArray rules) {
this.rules = rules;
}
private String price;
private JSONArray rules;
public String getRulesString() {
return rulesString;
}
public void setRulesString(String rulesString) {
this.rulesString = rulesString;
}
public String getDiscount() {
return discount;
}
public void setDiscount(String discount) {
this.discount = discount;
}
/**
* 0 默认
*/
......@@ -80,4 +23,6 @@ public class SkuVo implements Serializable {
private String rulesString;
private String discount;
private Integer isDelete;
}
......@@ -55,7 +55,7 @@ public interface CouponUserMapper {
* @param nowTime
* @return
*/
int getCustAvailableCouponCnt(@Param("custId") String custId, @Param("nowTime") LocalDateTime nowTime);
int getCustAvailableCouponCnt(@Param("custId") String custId, @Param("nowTime") LocalDateTime nowTime, @Param("couponUserId") Integer couponUserId);
/**
* 查询用户可用优惠券列表
......
......@@ -26,7 +26,7 @@ public interface GoodsCategoryMapper {
* @param ids 商品分类主键集合
* @return 商品分类
*/
List<GoodsCategory> selectGoodsCategoryByIds(@Param("ids") List<String> ids);
List<GoodsCategory> selectGoodsCategoryByIds(@Param("ids") List<Long> ids);
/**
* 查询商品分类列表
......@@ -68,7 +68,7 @@ public interface GoodsCategoryMapper {
*/
public int deleteGoodsCategoryByIds(String[] ids);
List<GoodsCategory> selectByShopId(long shopId);
List<String> selectCategoryIdByShopId(long shopId);
GoodsCategory selectGoodsCategoryPointer(String id, String pointer);
}
......@@ -69,7 +69,7 @@ public interface GoodsMapper
*/
public int deleteGoodsByIds(String[] ids);
Integer selectCount(String id);
Integer selectCount(Long id);
List<Goods> selectSpec(String query);
......
......@@ -19,7 +19,7 @@ public interface GoodsSkuMapper
* @param id 由规格选项组合生成商品sku主键
* @return 由规格选项组合生成商品sku
*/
public GoodsSku selectGoodsSkuById(String id);
public GoodsSku selectGoodsSkuById(Long id);
/**
* 查询由规格选项组合生成商品sku列表
......
......@@ -21,6 +21,8 @@ public interface OrderDetailMapper {
*/
public OrderDetail selectOrderDetailById(String id);
List<OrderDetail> selectOrderDetailsByIds(@Param("ids") List<Long> ids);
/**
* 根据明细id集合查询明细列表
*
......
package com.soss.system.mapper;
import java.util.List;
import com.soss.system.domain.Goods;
import com.soss.system.domain.ShopGoods;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 店铺和商品关联Mapper接口
*
......@@ -64,7 +64,7 @@ public interface ShopGoodsMapper
List<Goods> selectShopCategoryGoods(long shopId);
List<Goods> selectShopCategoryGoodsByCategoryId(@Param("shopId") long shopId, @Param("categoryId") String categoryId);
List<Goods> selectShopCategoryGoodsByCategoryId(@Param("shopId") long shopId, @Param("categoryId") Long categoryId);
void updateStatus(@Param("shopID")String shopID, @Param("goodsId") Long goodsId,@Param("machineId") String robotID,@Param("status") String s);
......
package com.soss.system.service;
import com.soss.system.domain.CouponUser;
import com.soss.system.domain.GoodsSku;
import com.soss.system.domain.Order;
import com.soss.system.domain.OrderDetail;
import com.soss.system.domain.vo.CouponUserVo;
import com.soss.system.domain.vo.CouponVo;
......@@ -30,4 +32,6 @@ public interface ICouponUserService {
List<CouponUserVo> selectCouponUserList(CouponUser couponUser);
void resovleCouponFitable(List<CouponVo> couponVos, Order order);
List<GoodsSku> orderDetailCheckAndAssign(List<OrderDetail> orderDetails);
}
package com.soss.system.service;
import java.util.List;
import com.soss.system.domain.Goods;
import com.soss.system.domain.GoodsSku;
import java.util.List;
/**
* 商品Service接口
*
......@@ -20,6 +21,8 @@ public interface IGoodsService
*/
public Goods selectGoodsById(Long id);
List<Goods> selectGoodsByIds(List<Long> ids);
/**
* 查询商品列表
*
......@@ -28,6 +31,8 @@ public interface IGoodsService
*/
public List<Goods> selectGoodsList(Goods goods);
void resolverCategoryName(List<Goods> goodsList);
/**
* 新增商品
*
......
package com.soss.system.service;
import java.util.List;
import com.soss.system.domain.GoodsSku;
import java.util.List;
/**
* 由规格选项组合生成商品skuService接口
*
......@@ -17,7 +18,7 @@ public interface IGoodsSkuService
* @param id 由规格选项组合生成商品sku主键
* @return 由规格选项组合生成商品sku
*/
public GoodsSku selectGoodsSkuById(String id);
public GoodsSku selectGoodsSkuById(Long id);
/**
* 查询由规格选项组合生成商品sku列表
......
package com.soss.system.service.impl;
import com.soss.common.enums.ShopState;
import com.soss.common.utils.StringUtils;
import com.soss.system.domain.Shop;
import com.soss.system.mapper.ShopMapper;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
@Service
public class AppServiceImpl {
@Autowired
private ShopMapper shopMapper;
public Shop getShop(String lng, String lat) {
Shop shop = new Shop();
shop.setState(1);
shop.setIsDefault(1L);
List<Shop> shops = shopMapper.selectShopList(shop);
if(shops !=null &&!shops.isEmpty()){
Shop shop1 = shops.get(0);
shop1.setDistance("-1");
if(StringUtils.isNotEmpty(lng)&&StringUtils.isNotEmpty(lat)){
//List<Shop> shopList = shopMapper.selectShopList(new Shop());
private static final double EARTH_RADIUS = 6378137;
shop1.setDistance(AppServiceImpl.GetDistance(Double.parseDouble(lng),Double.parseDouble(lat),Double.parseDouble(shop1.getLng()),Double.parseDouble(shop1.getLat())));
}
return shop1;
}else{
return new Shop();
public Shop getShop(String lng, String lat, Boolean testFlag) {
Shop shop = new Shop();
if (BooleanUtils.isTrue(testFlag)) {
shop.setStates(Arrays.asList(ShopState.TESTING.getState(), ShopState.OPEN.getState()));
} else {
shop.setState(ShopState.OPEN.getState());
}
shop.setIsDefault(1L);
List<Shop> shops = shopMapper.selectShopList(shop);
if (CollectionUtils.isEmpty(shops)) {
return new Shop();
}
shops.forEach(sp -> {
double realDistance;
if (StringUtils.isNotEmpty(lng) && StringUtils.isNotEmpty(lat)) {
realDistance = getRealDistance(Double.parseDouble(lng), Double.parseDouble(lat), Double.parseDouble(sp.getLng()), Double.parseDouble(sp.getLat()));
} else {
realDistance = Double.MAX_VALUE;
}
sp.setRealDistance(realDistance);
sp.setDistance(getDistance(realDistance));
});
shops.sort(Comparator.comparing(Shop::getRealDistance).reversed());
return shops.get(0);
}
public static String getDistance(Double realDistance) {
if (realDistance == null) {
return "-1";
}
if (realDistance.equals(Double.MAX_VALUE)) {
return "-1";
}
if (realDistance > 1000 && realDistance < 10000) {
DecimalFormat df = new DecimalFormat("######0.0");
return df.format(realDistance / 1000) + "km";
} else if (realDistance >= 10000) {
Double aDouble = realDistance / 1000;
return aDouble.intValue() + "km";
}
return realDistance.intValue() + "m";
}
private static final double EARTH_RADIUS = 6378137;
/**
* 根据两点间经纬度坐标(double值),计算两点间距离,单位为米
* @param lng1
* @param lat1
* @param lng2
* @param lat2
* @return
*/
public static String GetDistance(double lng1, double lat1, double lng2, double lat2)
{
double s = GetRealDistance(lng1, lat1, lng2, lat2);
String distance = null;
if(s>1000&&s<10000){
DecimalFormat df = new DecimalFormat("######0.0");
distance = df.format(s/1000);
return distance+"km";
}else if (s>=10000){
Double aDouble = s / 1000;
return aDouble.intValue()+"km";
}else{
Double aDouble =s;
return aDouble.intValue()+"m";
}
public static String getDistance(double lng1, double lat1, double lng2, double lat2) {
double s = getRealDistance(lng1, lat1, lng2, lat2);
return getDistance(s);
}
public static double GetRealDistance(double lng1, double lat1, double lng2, double lat2)
{
double radLat1 = rad(lat1);
double radLat2 = rad(lat2);
public static double getRealDistance(double lng1, double lat1, double lng2, double lat2) {
double radLat1 = Math.toRadians(lat1);
double radLat2 = Math.toRadians(lat2);
double a = radLat1 - radLat2;
double b = rad(lng1) - rad(lng2);
double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2) +
Math.cos(radLat1)*Math.cos(radLat2)*Math.pow(Math.sin(b/2),2)));
s = s * EARTH_RADIUS;
double b = Math.toRadians(lng1) - Math.toRadians(lng2);
double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
s *= EARTH_RADIUS;
s = Math.round(s * 10000) / 10000;
return s;
}
private static double rad(double d)
{
return d * Math.PI / 180.0;
}
}
......@@ -129,8 +129,7 @@ public class CouponCategoryServiceImpl implements ICouponCategoryService {
Coupon coupon = new Coupon();
coupon.setCategoryId(id);
List<Coupon> coupons = couponMapper.listCoupon(coupon);
long unOfflineCnt = coupons.stream().filter(c -> c.getState().equals(CouponState.DEFAULT.getState())
|| c.getState().equals(CouponState.ONLINE.getState())).count();
long unOfflineCnt = coupons.stream().filter(c -> c.getState().equals(CouponState.ONLINE.getState())).count();
if (unOfflineCnt > 0) {
throw new ServiceException("需类下优惠券都处于下线状态才可下线");
}
......
......@@ -83,7 +83,7 @@ public class CouponRuleServiceImpl implements ICouponRuleService {
}
private void transCategoryIds(List<CouponVo> couponVos) {
List<String> categoryIds = new ArrayList<>(16);
List<Long> categoryIds = new ArrayList<>(16);
List<Long> goodsIds = new ArrayList<>(16);
for (CouponVo couponVo : couponVos) {
if (!ArrayUtil.isAllAvailable(couponVo.getCategoryIds())) {
......@@ -92,7 +92,7 @@ public class CouponRuleServiceImpl implements ICouponRuleService {
ArrayUtil.listAddArray(goodsIds, couponVo.getGoodsIds());
}
Map<String, String> categoryMap;
Map<Long, String> categoryMap;
if (!CollectionUtils.isEmpty(categoryIds)) {
List<GoodsCategory> goodsCategories = goodsCategoryMapper.selectGoodsCategoryByIds(categoryIds);
categoryMap = goodsCategories.stream().collect(Collectors.toMap(GoodsCategory::getId, GoodsCategory::getName));
......
......@@ -136,9 +136,14 @@ public class CouponServiceImpl implements ICouponService {
Assert.notNull(couponPo.getUserLimit(), "用户可领取次数限制还未设置");
Assert.notNull(couponPo.getUseStartTime(), "优惠券的绝对有效时间还未设置");
Assert.notNull(couponPo.getUseEndTime(), "优惠券的绝对有效时间还未设置");
if (couponPo.getReceivableTime() != null && couponPo.getReceivableTime().isAfter(couponPo.getUseStartTime())) {
throw new ServiceException("优惠券的可领取时间要早于或等于优惠券的绝对有效时间的起始时间");
}
if (couponPo.getRelativeTime() != null && couponPo.getRelativeTime() > 0) {
Assert.isTrue(couponPo.getUseStartTime().plusDays(couponPo.getRelativeTime()).isBefore(couponPo.getUseEndTime()),
"实际结束时间已超出生命周期,请修改有效时间。");
}
Assert.isTrue((couponPo.getCategoryIds() != null && couponPo.getCategoryIds().length > 0)
|| (couponPo.getGoodsIds() != null && couponPo.getGoodsIds().length > 0), "商品范围还未设置");
if (!ArrayUtil.isEmpty(couponPo.getCategoryIds()) && !ArrayUtil.isEmpty(couponPo.getGoodsIds())) {
......@@ -234,8 +239,8 @@ public class CouponServiceImpl implements ICouponService {
@Transactional
public int deleteCoupon(Integer id) {
Coupon coupon = this.detail(id);
if (!coupon.getState().equals(CouponState.OFFLINE.getState())) {
throw new ServiceException("需下线优惠券才能删除");
if (!coupon.getState().equals(CouponState.OFFLINE.getState()) && !coupon.getState().equals(CouponState.EXPIRED.getState())) {
throw new ServiceException("[已下线]或[已失效]的优惠券才能删除");
}
Coupon delete = new Coupon(id, CouponState.DELETE.getState());
int updateCnt = couponMapper.updateCoupon(delete);
......
......@@ -120,7 +120,7 @@ public class CouponUserServiceImpl implements ICouponUserService {
*/
@Override
public int getCustAvailableCouponCnt(String custId) {
return couponUserMapper.getCustAvailableCouponCnt(custId, LocalDateTime.now());
return couponUserMapper.getCustAvailableCouponCnt(custId, LocalDateTime.now(), null);
}
/**
......@@ -139,7 +139,7 @@ public class CouponUserServiceImpl implements ICouponUserService {
private void transferTabIds(List<CouponVo> couponVos) {
couponVos.forEach(couponVo -> {
couponVo.setCategoryIds(ArrayUtil.transStrToCodeList(couponVo.getCategoryIdStr()));
couponVo.setCategoryIds(ArrayUtil.transStrToLongList(couponVo.getCategoryIdStr()));
couponVo.setGoodsIds(ArrayUtil.transStrToLongList(couponVo.getGoodsIdStr()));
couponVo.setProvince(ArrayUtil.transStrToCodeList(couponVo.getProvinceStr()));
couponVo.setCity(ArrayUtil.transStrToCodeList(couponVo.getCityStr()));
......@@ -176,35 +176,20 @@ public class CouponUserServiceImpl implements ICouponUserService {
}
private void checkGoodsFitable(List<CouponVo> couponVos, List<OrderDetail> orderDetails) {
Assert.notEmpty(orderDetails, "商品明细还未传递");
List<Long> skuIds = orderDetails.stream().map(OrderDetail::getSkuId).collect(Collectors.toList());
Assert.notEmpty(skuIds, "skuId还未传递");
List<GoodsSku> goodsSkus = goodsSkuMapper.selectSkuListForOrder(skuIds);
log.info("sku id size is {} and query size is {}", skuIds.size(), goodsSkus.size());
Assert.isTrue(goodsSkus.size() == skuIds.size(), "未查询到匹配的sku记录");
List<GoodsSku> goodsSkus = this.orderDetailCheckAndAssign(orderDetails);
List<Long> goodsIds = goodsSkus.stream().map(GoodsSku::getGoodsId).collect(Collectors.toList());
List<Goods> goods = goodsMapper.selectGoodsByIds(goodsIds);
Assert.notEmpty(goods, "未查询到匹配的商品信息[id=" + goodsIds + "]");
// sku的ID和价格字典
Map<Long, GoodsSku> skuMap = goodsSkus.stream().collect(Collectors.toMap(GoodsSku::getId, Function.identity()));
// 订单明细设置
orderDetails.forEach(orderDetail -> {
GoodsSku sku = skuMap.get(orderDetail.getSkuId());
BigDecimal skuNum = new BigDecimal(orderDetail.getNum());
orderDetail.setOriAmount(skuNum.multiply(sku.getPrice()));
orderDetail.setUnitPrice(sku.getDiscount());
orderDetail.setAmountShould(skuNum.multiply(sku.getDiscount()));
});
// 订单总额
BigDecimal orderTotalAmount = orderDetails.stream().map(OrderDetail::getAmountShould).reduce(BigDecimal.ZERO, BigDecimal::add);
couponVos.stream().filter(couponVo -> StringUtils.isEmpty(couponVo.getNotFitableDesc())).forEach(couponVo -> {
/** 可用饮品范围的判断 */
List<Long> fitCouponGoodsIdList = goods.stream().filter(good ->
(ArrayUtil.isAllAvailable(couponVo.getCategoryIds()) || ArrayUtil.contains(couponVo.getCategoryIds(), good.getCategory()))
&& (ArrayUtil.isEmpty(couponVo.getGoodsIds()) || ArrayUtil.contains(couponVo.getGoodsIds(), good.getId())))
(ArrayUtil.isAllAvailable(couponVo.getCategoryIds()) || ArrayUtil.containsSplit(couponVo.getCategoryIds(), good.getCategory()))
|| (ArrayUtil.isAllAvailable(couponVo.getGoodsIds()) || ArrayUtil.contains(couponVo.getGoodsIds(), good.getId())))
.map(Goods::getId).collect(Collectors.toList());
if (CollectionUtils.isEmpty(fitCouponGoodsIdList)) {
if (!ArrayUtil.isAllAvailable(couponVo.getCategoryIds())) {
if (couponVo.getCategoryIds() != null && !ArrayUtil.isAllAvailable(couponVo.getCategoryIds())) {
couponVo.setNotFitableDesc("限定品类使用");
} else {
couponVo.setNotFitableDesc("限定商品使用");
......@@ -215,6 +200,7 @@ public class CouponUserServiceImpl implements ICouponUserService {
if (couponVo.getType().equals(CouponCategoryType.DEDUCTION.getType())) { // 抵扣
if (couponVo.getPriceLimit() != null && couponVo.getPriceLimit().compareTo(BigDecimal.ZERO) != 0 && couponVo.getPriceLimit().compareTo(orderTotalAmount) > 0) {
couponVo.setNotFitableDesc("未达到满减要求");
return;
}
couponVo.setCouponAmount(couponVo.getPriceDiscount().min(orderTotalAmount));
} else {
......@@ -226,6 +212,7 @@ public class CouponUserServiceImpl implements ICouponUserService {
} else { // 免单
couponVo.setNotFitableDesc("未达到免单要求");
}
return;
}
this.wrapperCouponAmount(couponVo, fitOrderDetails, fitGoodsAmount);
......@@ -240,6 +227,27 @@ public class CouponUserServiceImpl implements ICouponUserService {
});
}
@Override
public List<GoodsSku> orderDetailCheckAndAssign(List<OrderDetail> orderDetails) {
Assert.notEmpty(orderDetails, "商品明细还未传递");
List<Long> skuIds = orderDetails.stream().map(OrderDetail::getSkuId).collect(Collectors.toList());
Assert.notEmpty(skuIds, "skuId还未传递");
List<GoodsSku> goodsSkus = goodsSkuMapper.selectSkuListForOrder(skuIds);
log.info("sku id size is {} and query size is {}", skuIds.size(), goodsSkus.size());
Assert.isTrue(goodsSkus.size() == skuIds.size(), "未查询到匹配的sku记录");
// sku的ID和价格字典
Map<Long, GoodsSku> skuMap = goodsSkus.stream().collect(Collectors.toMap(GoodsSku::getId, Function.identity()));
// 订单明细设置
orderDetails.forEach(orderDetail -> {
GoodsSku sku = skuMap.get(orderDetail.getSkuId());
BigDecimal skuNum = new BigDecimal(orderDetail.getNum());
orderDetail.setOriAmount(skuNum.multiply(sku.getPrice()));
orderDetail.setUnitPrice(sku.getDiscount());
orderDetail.setAmountShould(skuNum.multiply(sku.getDiscount()));
});
return goodsSkus;
}
private void wrapperCouponAmount(CouponVo couponVo, List<OrderDetail> fitOrderDetails, BigDecimal fitGoodsAmount) {
Map<Long, BigDecimal> couponAmountMap = new HashMap<>();
if (couponVo.getOrderLimit() != null && couponVo.getOrderLimit()) { // 单杯
......@@ -247,13 +255,14 @@ public class CouponUserServiceImpl implements ICouponUserService {
BigDecimal discountAmount = orderDetail.getUnitPrice();
if (couponVo.getType().equals(CouponCategoryType.DISCOUNT.getType())) { // 折扣
discountAmount = this.getDiscountAmount(discountAmount, couponVo.getPriceDiscount());
}/* else { // 免单
}*/
}
couponVo.setCouponAmount(discountAmount);
couponAmountMap.put(orderDetail.getSkuId(), couponVo.getCouponAmount());
} else { // 整单
if (couponVo.getType().equals(CouponCategoryType.DISCOUNT.getType())) { // 折扣
couponVo.setCouponAmount(this.getDiscountAmount(fitGoodsAmount, couponVo.getPriceDiscount()));
BigDecimal couponAmount = this.getDiscountAmount(fitGoodsAmount, couponVo.getPriceDiscount());
couponAmount = couponAmount.min(BigDecimal.valueOf(50)); // 折扣类整单最高抵扣50元
couponVo.setCouponAmount(couponAmount);
fitOrderDetails.forEach(orderDetail -> orderDetail.setCouponAmount(this.getDiscountAmount(orderDetail.getAmountShould(), couponVo.getPriceDiscount())));
// 订单明细优惠总和
BigDecimal detailCouponSum = fitOrderDetails.stream().map(OrderDetail::getCouponAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
......
package com.soss.system.service.impl;
import java.util.Date;
import java.util.List;
import com.soss.common.exception.ServiceException;
import com.soss.common.utils.GenerateCode;
import com.soss.system.domain.Goods;
import com.soss.system.service.IGoodsCategoryService;
import com.soss.system.domain.GoodsCategory;
import com.soss.system.mapper.GoodsCategoryMapper;
import com.soss.system.mapper.GoodsMapper;
import com.soss.system.service.IGoodsCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.soss.system.mapper.GoodsCategoryMapper;
import com.soss.system.domain.GoodsCategory;
import java.util.Date;
import java.util.List;
/**
* 商品分类Service业务层处理
......@@ -69,7 +69,7 @@ public class GoodsCategoryServiceImpl implements IGoodsCategoryService
goodsCategory.setUpdatedAt(new Date());
goodsCategory.setIsDeleted("0");
goodsCategoryMapper.insertGoodsCategory(goodsCategory);
goodsCategory.setTurn(goodsCategory.getId());
goodsCategory.setTurn(goodsCategory.getId().toString());
return goodsCategoryMapper.updateGoodsCategory(goodsCategory);
}
......@@ -84,7 +84,7 @@ public class GoodsCategoryServiceImpl implements IGoodsCategoryService
{
if("2".equals(goodsCategory.getState())){
Goods goods = new Goods();
goods.setCategory(goodsCategory.getId());
goods.setCategory(goodsCategory.getId().toString());
goods.setIsDeleted(0L);
int size = goodsMapper.selectGoodsList(goods).size();
if(size>0){
......@@ -143,14 +143,14 @@ public class GoodsCategoryServiceImpl implements IGoodsCategoryService
if(index<0){
lastId =id;
}else{
lastId = goodsCategories.get(index).getId();
lastId = goodsCategories.get(index).getId().toString();
}
}else if("2".equals(pointer)){
int index=i+1;
if(index>=size){
lastId =id;
}else{
lastId = goodsCategories.get(index).getId();
lastId = goodsCategories.get(index).getId().toString();
}
}
}
......
......@@ -2,6 +2,7 @@ package com.soss.system.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.soss.common.enums.SkuDeleteState;
import com.soss.common.exception.ServiceException;
import com.soss.common.utils.GenerateCode;
import com.soss.common.utils.StringUtils;
......@@ -9,10 +10,14 @@ import com.soss.system.domain.*;
import com.soss.system.jiguang.impl.JiGuangPushServiceImpl;
import com.soss.system.mapper.*;
import com.soss.system.service.IGoodsService;
import jodd.util.StringPool;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.*;
......@@ -54,48 +59,73 @@ public class GoodsServiceImpl implements IGoodsService
/**
* 查询商品
*
*
* @param id 商品主键
* @return 商品
*/
@Override
public Goods selectGoodsById(Long id)
{
Goods goods = goodsMapper.selectGoodsById(id);
public Goods selectGoodsById(Long id) {
Goods goods = goodsMapper.selectGoodsById(id);
Assert.notNull(goods, "未查询到匹配的商品信息");
resolverCategoryName(Collections.singletonList(goods));
GoodsTag goodsTag = new GoodsTag();
goodsTag.setGoodsId(goods.getId());
goods.setGoodsTagList(goodsTagMapper.selectGoodsTagList(goodsTag).stream().map(GoodsTag::getTag).collect(Collectors.toList()));
return goods;
}
@Override
public List<Goods> selectGoodsByIds(List<Long> ids) {
Assert.notEmpty(ids, "goods ids cannot be empty");
List<Goods> goods = goodsMapper.selectGoodsByIds(ids);
this.resolverCategoryName(goods);
return goods;
}
/**
* 查询商品列表
*
*
* @param goods 商品
* @return 商品
*/
@Override
public List<Goods> selectGoodsList(Goods goods)
{
public List<Goods> selectGoodsList(Goods goods) {
List<Goods> goodsList = goodsMapper.selectGoodsList(goods);
for (Goods goods1 : goodsList) {
GoodsCategory goodsCategory = goodsCategoryMapper.selectGoodsCategoryById(goods1.getCategory());
if(goodsCategory !=null){
goods1.setCategoryName(goodsCategory.getName());
}
int count = orderMapper.selectSalesVolume(null,goods1.getId());
goods1.setSalesVolume(count);
this.resolverCategoryName(goodsList);
for (Goods good : goodsList) {
int count = orderMapper.selectSalesVolume(null, good.getId());
good.setSalesVolume(count);
}
return goodsList;
}
@Override
public void resolverCategoryName(List<Goods> goodsList) {
if (CollectionUtils.isEmpty(goodsList)) {
return;
}
List<Long> categoryIds = new ArrayList<>(16);
goodsList.forEach(good -> {
String[] categoryIdArr = good.getCategory().split(StringPool.COMMA);
for (String categoryId : categoryIdArr) {
if (!StringUtils.isEmpty(categoryId)) {
categoryIds.add(Long.parseLong(categoryId));
}
}
});
List<GoodsCategory> categories = goodsCategoryMapper.selectGoodsCategoryByIds(categoryIds);
Map<Long, String> categoryMap = categories.stream().collect(Collectors.toMap(GoodsCategory::getId, GoodsCategory::getName));
goodsList.forEach(good -> {
String categoryName = Arrays.stream(good.getCategory().split(StringPool.COMMA)).filter(StringUtils::isNotEmpty)
.map(Long::parseLong).map(categoryMap::get)
.collect(Collectors.joining(StringPool.COMMA));
good.setCategoryName(categoryName);
});
}
/**
* 新增商品
*
*
* @param goods 商品
* @return 结果
*/
......@@ -171,7 +201,7 @@ public class GoodsServiceImpl implements IGoodsService
GoodsSku goodsSku = new GoodsSku();
goodsSku.setGoodsId(goodsId);
goodsSku.setCreatedAt(new Date());
goodsSku.setIsDeleted("0");
goodsSku.setIsDeleted(SkuDeleteState.NORMAL.getState());
goodsSku.setUpdatedAt(new Date());
BigDecimal price1 = new BigDecimal(price.toPlainString());
BigDecimal discount1 = new BigDecimal(discount.toPlainString());
......@@ -285,13 +315,11 @@ public class GoodsServiceImpl implements IGoodsService
Shop shop = new Shop();
List<Shop> shops = shopService.selectShopList(shop);
for (Shop shop1 : shops) {
if(!"3".equals(shop1.getState())){
try{
shopService.addGoods(shop1.getId(),goodsId);
}catch (ServiceException serviceException){
if (!Objects.equals(3, shop1.getState())) {
try {
shopService.addGoods(shop1.getId(), goodsId);
} catch (ServiceException serviceException) {
}
}
}
}
......@@ -363,42 +391,13 @@ public class GoodsServiceImpl implements IGoodsService
public List<GoodsSku> getGoodsSkus(long goodsId){
GoodsSku goodsSku = new GoodsSku();
goodsSku.setGoodsId(goodsId);
goodsSku.setIsDeleted("0");
return goodsSkuMapper.selectGoodsSkuList(goodsSku);
}
@Data
class RuleNode<T>{
private RuleNode parentRuleNode;
private T ruleNode;
public RuleNode getParentRuleNode() {
return parentRuleNode;
}
public void setParentRuleNode(RuleNode parentRuleNode) {
this.parentRuleNode = parentRuleNode;
}
private List<RuleNode> childNode;
public T getRuleNode() {
return ruleNode;
}
public void setRuleNode(T ruleNode) {
this.ruleNode = ruleNode;
}
public List<RuleNode> getChildNode() {
return childNode;
}
public void setChildNode(List<RuleNode> childNode) {
this.childNode = childNode;
}
}
}
package com.soss.system.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.soss.system.mapper.GoodsSkuMapper;
import com.soss.system.domain.GoodsSku;
import com.soss.system.mapper.GoodsSkuMapper;
import com.soss.system.service.IGoodsSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 由规格选项组合生成商品skuService业务层处理
......@@ -26,7 +27,7 @@ public class GoodsSkuServiceImpl implements IGoodsSkuService
* @return 由规格选项组合生成商品sku
*/
@Override
public GoodsSku selectGoodsSkuById(String id)
public GoodsSku selectGoodsSkuById(Long id)
{
return goodsSkuMapper.selectGoodsSkuById(id);
}
......
......@@ -9,6 +9,7 @@ import com.soss.system.mapper.ShopMapper;
import com.soss.system.service.IMachineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
......@@ -98,27 +99,25 @@ public class MachineServiceImpl implements IMachineService {
}
@Override
@Transactional
public String bindMachine(String code, Long shopId) {
Machine machine = new Machine();
machine.setShopId(shopId);
List<Machine> machines = machineMapper.selectMachineList(machine);
if(!machines.isEmpty()){
if (!machines.isEmpty()) {
throw new ServiceException("目前只允许一个店铺绑定一台机器");
}
Machine machine1 = machineMapper.selectMachineByCode(code);
if (machine1 == null) {
machine.setCode(code);
machine.setBindTime(new Date());
machine.setCreatedAt(new Date());
machine.setUpdatedAt(new Date());
machine.setState(1);
return machineMapper.insertMachine(machine) + "";
throw new ServiceException("未查询到匹配的机器[code=" + code + "]");
}
if (machine1.getShopId() != null) {
if (machine1.getShopId() != null && machine1.getShopId() > 0) {
throw new ServiceException("该机器已经被绑定,请先解绑再绑定");
}
machine1.setCode(code);
machine1.setShopId(shopId);
Date curTime = new Date();
machine1.setBindTime(curTime);
machine1.setUpdatedAt(curTime);
machineMapper.updateMachine(machine1);
// 重新绑定机器后店铺进入测试中状态重新完成运营测试
shopMapper.updateShop(new Shop(shopId, ShopState.TESTING.getState()));
......
......@@ -10,12 +10,15 @@ import com.soss.system.domain.Order;
import com.soss.system.domain.OrderDetail;
import com.soss.system.domain.OrderRefund;
import com.soss.system.domain.vo.OrderQuery;
import com.soss.system.mapper.GoodsMapper;
import com.soss.system.mapper.OrderDetailMapper;
import com.soss.system.mapper.OrderRefundMapper;
import com.soss.system.service.IOrderRefundService;
import io.jsonwebtoken.lang.Assert;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
......@@ -27,20 +30,21 @@ import java.util.stream.Collectors;
/**
* 订单退款Service业务层处理
*
*
* @author zxq
* @date 2022-04-28
*/
@Service
@Slf4j
public class OrderRefundServiceImpl implements IOrderRefundService
{
public class OrderRefundServiceImpl implements IOrderRefundService {
@Autowired
private OrderRefundMapper orderRefundMapper;
@Autowired
private OrderServiceImpl orderService;
@Autowired
private OrderDetailMapper orderDetailMapper;
@Autowired
private GoodsMapper goodsMapper;
/**
* 查询订单退款
......@@ -51,6 +55,7 @@ public class OrderRefundServiceImpl implements IOrderRefundService
@Override
public OrderRefund selectOrderRefundById(String id) {
OrderRefund orderRefund = orderRefundMapper.selectOrderRefundById(id);
Assert.notNull(orderRefund, "未查询到匹配的退款记录");
this.wrapperOrderInfo(orderRefund);
return orderRefund;
}
......@@ -84,21 +89,23 @@ public class OrderRefundServiceImpl implements IOrderRefundService
/**
* 新增订单退款
*
*
* @param orderRefund 订单退款
* @return 结果
*/
@Override
public AjaxResult insertOrderRefund(OrderRefund orderRefund)
{
@Transactional
public AjaxResult insertOrderRefund(OrderRefund orderRefund) {
Order order = orderService.selectById(orderRefund.getOrderId());
if(order ==null ){
return AjaxResult.error("找不到该订单");
if (order == null) {
return AjaxResult.error("找不到该订单");
}
String state = order.getState();
// 制作中、制作完成、取餐中、已完成、待取超时、退款失败
List<String> status = Arrays.asList(OrderStatusConstant.production,OrderStatusConstant.productionCompleted,OrderStatusConstant.Taking,OrderStatusConstant.completed,OrderStatusConstant.timeout,OrderStatusConstant.refundFailed);
// 制作中、制作完成、取餐中、已完成、待取超时、退款失败、部分退款、制作中取消
List<String> status = Arrays.asList(OrderStatusConstant.production, OrderStatusConstant.productionCompleted,
OrderStatusConstant.Taking, OrderStatusConstant.completed, OrderStatusConstant.timeout,
OrderStatusConstant.refundFailed, OrderStatusConstant.PartialRefund, OrderStatusConstant.productionCancel);
if (OrderStatusConstant.Paid.equals(state)) {
//orderRefund.setRefundAmount(order.getAmount());
// 4 支付制作中 5 制作完成未取 6 取餐中 7 取餐完成
......@@ -149,7 +156,11 @@ public class OrderRefundServiceImpl implements IOrderRefundService
orderRefund.setCreateUserName(order.getUserName());
}
orderRefundMapper.insertOrderRefund(orderRefund);
order.setState(OrderStatusConstant.refunding);
if (order.getPaidAmount().compareTo(BigDecimal.ZERO) == 0) {
order.setState(OrderStatusConstant.refund);
} else {
order.setState(OrderStatusConstant.refunding);
}
orderService.updateOrder(order);
orderDetailMapper.bindRefund(orderRefund.getId(), orderRefund.getOrderDetailIds());
orderRefund.setOrder(order);
......
......@@ -29,6 +29,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
......@@ -90,6 +91,10 @@ public class OrderServiceImpl implements IOrderService {
OrderSnapshot orderSnapshot = orderSnapshotService.selectOrderSnapshotByOrderId(order.getId());
String snapshot = orderSnapshot.getSnapshot();
List<OrderDetail> orderDetails1 = JSONObject.parseArray(snapshot, OrderDetail.class);
List<Long> detailIds = orderDetails1.stream().map(OrderDetail::getId).collect(Collectors.toList());
List<OrderDetail> detailsActual = orderDetailMapper.selectOrderDetailsByIds(detailIds);
Map<Long, Long> refundIdMap = detailsActual.stream().filter(da -> da.getRefundId() != null).collect(Collectors.toMap(OrderDetail::getId, OrderDetail::getRefundId));
orderDetails1.forEach(od -> od.setRefundId(refundIdMap.get(od.getId())));
order.setOrderDetails(orderDetails1);
return order;
}
......@@ -135,7 +140,11 @@ public class OrderServiceImpl implements IOrderService {
couponUserMapper.updateCouponUser(couponUser);
}
order.setState(OrderStatusConstant.Unpaid);
if (order.getPaidAmount().compareTo(BigDecimal.ZERO) == 0) {
order.setState(OrderStatusConstant.Paid);
} else {
order.setState(OrderStatusConstant.Unpaid);
}
order.setUserId(loginUser.getOpenId());
order.setUserName(loginUser.getUsername());
order.setUserPhone(loginUser.getUser().getPhonenumber());
......@@ -206,7 +215,7 @@ public class OrderServiceImpl implements IOrderService {
throw new ServiceException("当前时间本店休息中,暂停点单~");
}
if (shop.getDistanceLimit() != null && shop.getDistanceLimit() > 0) {
double distance = AppServiceImpl.GetRealDistance(order.getLng().doubleValue(), order.getLat().doubleValue(), Double.parseDouble(shop.getLng()), Double.parseDouble(shop.getLat()));
double distance = AppServiceImpl.getRealDistance(order.getLng().doubleValue(), order.getLat().doubleValue(), Double.parseDouble(shop.getLng()), Double.parseDouble(shop.getLat()));
if (distance > shop.getDistanceLimit() * 1000) {
throw new ServiceException("超过店铺下单的距离范围");
}
......@@ -414,7 +423,6 @@ public class OrderServiceImpl implements IOrderService {
@Override
public List<Order> getMyOrder(String openId) {
List<Order> orders = orderMapper.selectByUserId(openId);
for (Order order : orders) {
order.setShop(shopMapper.selectShopById(order.getShopId()));
......@@ -472,9 +480,10 @@ public class OrderServiceImpl implements IOrderService {
}
orderNum %= 999;
}
int orderNumTail = (int) (Math.random() * 8);
// redisAtomicInteger.expire(1, TimeUnit.DAYS);
// int andIncrement = redisAtomicInteger.getAndAdd(3);
return key + String.format("%03d", orderNum);
return key + String.format("%03d", orderNum) + (orderNumTail + 1);
}
//获取订单号
......
......@@ -3,14 +3,17 @@ package com.soss.system.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.soss.common.exception.ServiceException;
import com.soss.common.utils.StringUtils;
import com.soss.system.domain.*;
import com.soss.system.domain.vo.orderTaking.*;
import com.soss.system.mapper.*;
import jodd.util.StringPool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
......@@ -129,21 +132,31 @@ public class OrderTakingServiceImpl {
buildSkuRules(skuVos);
goodsVo.setSkus(skuVos);
}
//普通分类的产品
orderTakingVo.setRecommends(recommendVos);
List<GoodsCategory> shopCategories = goodsCategoryMapper.selectByShopId(shopId);
if(!CollectionUtils.isEmpty(shopCategories)){
//普通分类的产品
List<String> categoryIdStrList = goodsCategoryMapper.selectCategoryIdByShopId(shopId);
if (CollectionUtils.isEmpty(categoryIdStrList)) {
return orderTakingVo;
}
List<Long> categoryIds = new ArrayList<>(16);
categoryIdStrList.forEach(categoryIdStr -> {
List<Long> categoryIdsUnit = Arrays.stream(categoryIdStr.split(StringPool.COMMA)).filter(StringUtils::isNotEmpty).map(Long::parseLong).collect(Collectors.toList());
categoryIds.addAll(categoryIdsUnit);
});
List<GoodsCategory> shopCategories = goodsCategoryMapper.selectGoodsCategoryByIds(categoryIds);
if (!CollectionUtils.isEmpty(shopCategories)) {
for (GoodsCategory category : shopCategories) {
CategoryVo categoryVo = new CategoryVo();
categoryVo.setId(Long.parseLong(category.getId()));
categoryVo.setId(category.getId());
categoryVo.setName(category.getName());
categoryVo.setIcon(category.getIcon());
List<Goods> goodsList = shopGoodsMapper.selectShopCategoryGoodsByCategoryId(shopId, category.getId());
List<GoodsVo> goodsVoList = new ArrayList<>();
categoryVo.setGoods(goodsVoList);
if(!CollectionUtils.isEmpty(goodsList)){
if (!CollectionUtils.isEmpty(goodsList)) {
for (Goods good : goodsList) {
GoodsVo goodsVo =new GoodsVo();
GoodsVo goodsVo = new GoodsVo();
goodsVo.setGoodsId(String.valueOf(good.getId()));
goodsVo.setName(good.getName());
goodsVo.setDesc(good.getDesc());
......@@ -176,8 +189,6 @@ public class OrderTakingServiceImpl {
}
}
orderTakingVo.setRecommends(recommendVos);
orderTakingVo.setCategorys(categoryVos);
return orderTakingVo;
......
......@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.soss.common.core.domain.AjaxResult;
import com.soss.common.enums.MachineState;
import com.soss.common.enums.ShopState;
import com.soss.common.enums.SkuDeleteState;
import com.soss.common.exception.ServiceException;
import com.soss.common.utils.StringUtils;
import com.soss.system.domain.*;
......@@ -12,6 +13,7 @@ import com.soss.system.domain.vo.orderTaking.*;
import com.soss.system.jiguang.impl.JiGuangPushServiceImpl;
import com.soss.system.mapper.*;
import com.soss.system.service.IShopService;
import jodd.util.StringPool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -202,7 +204,7 @@ public class ShopServiceImpl implements IShopService
shopGoodsMapper.updateShopGoods(shopGoods);
GoodsSku goodsSku = new GoodsSku();
goodsSku.setGoodsId(goodsId);
goodsSku.setIsDeleted("0");
goodsSku.setIsDeleted(SkuDeleteState.NORMAL.getState());
List<GoodsSku> goodsSkus = goodsSkuMapper.selectGoodsSkuList(goodsSku);
Machine machine = new Machine();
machine.setShopId(shopId);
......@@ -234,24 +236,32 @@ public class ShopServiceImpl implements IShopService
}
@Override
public List<GoodsCategory> getCategoryGoods(long shopId) {
List<GoodsCategory> shopCategories = goodsCategoryMapper.selectByShopId(shopId);
List<String> categoryIdStrList = goodsCategoryMapper.selectCategoryIdByShopId(shopId);
if (CollectionUtils.isEmpty(categoryIdStrList)) {
return new ArrayList<>();
}
List<Long> categoryIds = new ArrayList<>(16);
categoryIdStrList.forEach(categoryIdStr -> {
List<Long> categoryIdsUnit = Arrays.stream(categoryIdStr.split(StringPool.COMMA)).filter(StringUtils::isNotEmpty).map(Long::parseLong).collect(Collectors.toList());
categoryIds.addAll(categoryIdsUnit);
});
List<GoodsCategory> shopCategories = goodsCategoryMapper.selectGoodsCategoryByIds(categoryIds);
for (GoodsCategory category : shopCategories) {
List<Goods> goodsList = shopGoodsMapper.selectShopCategoryGoodsByCategoryId(shopId,category.getId());
List<Goods> goodsList = shopGoodsMapper.selectShopCategoryGoodsByCategoryId(shopId, category.getId());
for (Goods goods : goodsList) {
ShopGoodsSku shopGoodsSku = new ShopGoodsSku();
shopGoodsSku.setShopId(shopId);
shopGoodsSku.setGoodsId(goods.getId());
List<ShopGoodsSku> shopGoodsSkus = shopGoodsSkuMapper.selectShopGoodsSkuList(shopGoodsSku);
if(!shopGoodsSkus.isEmpty()){
boolean boo= true;
if (!shopGoodsSkus.isEmpty()) {
boolean boo = true;
for (ShopGoodsSku goodsSkus : shopGoodsSkus) {
if("2".equals(goodsSkus.getState())){
if ("2".equals(goodsSkus.getState())) {
boo = false;
}
}
if(!boo){
if (!boo) {
goods.setState("2");
}
}
......@@ -450,6 +460,7 @@ public class ShopServiceImpl implements IShopService
goodsVo.setSkus(skuVos);
return goodsVo;
}
private JSONArray buildGoodsSpec(String specs) {
List<Spec> specList = JSONObject.parseArray(specs,Spec.class);
List<SpecVo> specVos = new ArrayList<>();
......
package com.soss.system.utils;
import com.soss.common.utils.StringUtils;
import jodd.util.StringPool;
import java.util.Arrays;
import java.util.List;
......@@ -62,6 +63,19 @@ public class ArrayUtil {
return false;
}
public static boolean containsSplit(Long[] arr, String target) {
if (StringUtils.isEmpty(target)) {
return false;
}
for (String tar : target.split(StringPool.COMMA)) {
if (!StringUtils.isEmpty(tar) && contains(arr, Long.parseLong(tar))) {
return true;
}
}
return false;
}
public static <T> boolean isEmpty(T[] ts) {
return ts == null || ts.length == 0;
}
......
......@@ -84,7 +84,8 @@
select c.id, c.name
from coupon_rule cr
left join coupon c on c.rule_id = cr.id
where cr.use_start_time > now() and cr.use_end_time &lt; now()
where cr.use_start_time &lt; now() and cr.use_end_time > now()
and c.state = ${@com.soss.common.enums.CouponState @ONLINE.getState}
</select>
<update id="expireCoupon">
......
......@@ -17,6 +17,7 @@
<result property="sendMsgFlag2" column="send_msg_flag2"/>
<result property="sendMsgFlag3" column="send_msg_flag3"/>
<result property="flagExpireDate" column="flag_expire_date"/>
<result property="testFlag" column="test_flag"/>
</resultMap>
<sql id="selectCustomerVo">
......@@ -53,6 +54,7 @@
<if test="sendMsgFlag2 != null">send_msg_flag2,</if>
<if test="sendMsgFlag3 != null">send_msg_flag3,</if>
<if test="flagExpireDate != null">flag_expire_date,</if>
<if test="testFlag != null">test_flag,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
......@@ -67,6 +69,7 @@
<if test="sendMsgFlag2 != null">#{sendMsgFlag2},</if>
<if test="sendMsgFlag3 != null">#{sendMsgFlag3},</if>
<if test="flagExpireDate != null">#{flagExpireDate},</if>
<if test="testFlag != null">#{testFlag},</if>
</trim>
</insert>
......@@ -79,11 +82,12 @@
<if test="sex != null">sex = #{sex},</if>
<if test="birthday != null">birthday = #{birthday},</if>
<if test="soucre != null">soucre = #{soucre},</if>
<if test="allow != null">allow = #{soucre},</if>
<!--<if test="allow != null">allow = #{soucre},</if>-->
<if test="sendMsgFlag1 != null">send_msg_flag1 = #{sendMsgFlag1},</if>
<if test="sendMsgFlag2 != null">send_msg_flag2 = #{sendMsgFlag2},</if>
<if test="sendMsgFlag3 != null">send_msg_flag3 = #{sendMsgFlag3},</if>
<if test="flagExpireDate != null">flag_expire_date = #{flagExpireDate},</if>
<if test="testFlag != null">test_flag = #{testFlag},</if>
</trim>
where id = #{id}
</update>
......
......@@ -98,11 +98,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
</foreach>
</delete>
<select id="selectByShopId" resultMap="GoodsCategoryResult">
select DISTINCT gc.* from goods_category gc ,goods g ,
shop_goods sg where g.id =sg.goods_id and g.category =gc.id
and sg.shop_id =#{shopId}
order by gc.turn
<select id="selectCategoryIdByShopId" resultType="java.lang.String">
select g.category
from
goods g ,
shop_goods sg
where
g.id = sg.goods_id
and sg.shop_id = #{shopId}
</select>
</mapper>
\ No newline at end of file
......@@ -25,11 +25,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectGoodsVo">
select id, name, category, price, discount, take_time, spec, pics, `desc`, remarks, state, is_deleted, created_at, updated_at, code,shelf_at from goods
select * from goods
</sql>
<select id="selectGoodsByIds" resultMap="GoodsResult">
select id, name, category from goods where id in
select * from goods where id in
<foreach collection="ids" item="id" separator="," open="(" close=")">#{id}</foreach>
</select>
......@@ -37,7 +37,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectGoodsVo"/>
<where>
<if test="name != null and name != ''">and name like concat('%', #{name}, '%')</if>
<if test="category != null and category != ''">and category = #{category}</if>
<if test="category != null and category != ''">and category like concat('%,', #{category}, ',%')</if>
<if test="price != null ">and price = #{price}</if>
<if test="discount != null ">and discount = #{discount}</if>
<if test="takeTime != null ">and take_time = #{takeTime}</if>
......@@ -56,28 +56,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectGoodsById" parameterType="Long" resultMap="GoodsResult">
select
g.id,
g.name,
g.category,
gc.name as categoryName,
g.price,
g.discount,
g.take_time,
g.spec,
g.pics,
g.`desc`,
g.remarks,
g.state,
g.is_deleted,
g.created_at,
g.updated_at,
g.code,
g.shelf_at
from
goods g,goods_category gc
where g.id = #{id}
and g.category =gc.id
select *
from goods
where id = #{id}
</select>
<insert id="insertGoods" parameterType="Goods" useGeneratedKeys="true" keyProperty="id">
......
......@@ -27,7 +27,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectGoodsSkuList" parameterType="GoodsSku" resultMap="GoodsSkuResult">
<include refid="selectGoodsSkuVo"/>
<where>
and is_deleted =0
and is_deleted in (0, 2)
<if test="goodsId != null and goodsId != ''">and goods_id = #{goodsId}</if>
<if test="ruleList != null and ruleList != ''">and rule_list = #{ruleList}</if>
<if test="isDeleted != null and isDeleted != ''">and is_deleted = #{isDeleted}</if>
......@@ -70,7 +70,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="SET" suffixOverrides=",">
<if test="goodsId != null and goodsId != ''">goods_id = #{goodsId},</if>
<if test="ruleList != null and ruleList != ''">rule_list = #{ruleList},</if>
<if test="isDeleted != null and isDeleted != ''">is_deleted = #{isDeleted},</if>
<if test="isDeleted != null">is_deleted = #{isDeleted},</if>
<if test="updatedAt != null">updated_at = #{updatedAt},</if>
<if test="price != null">price = #{price},</if>
<if test="discount != null">price = #{discount},</if>
......@@ -83,18 +83,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</delete>
<delete id="deleteGoodsSkuByIds" parameterType="String">
delete from goods_sku where id in
delete from goods_sku where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<update id="deleteGoodsSkuByGoodsId">
update goods_sku set is_deleted ='1' where goods_id=#{goodsId}
update goods_sku set is_deleted = 1 where goods_id=#{goodsId}
</update>
<select id="selectSpec" resultMap="GoodsSkuResult">
<include refid="selectGoodsSkuVo"/>
where
is_deleted ='0' and
rule_list like concat('%',#{query},'%')
where is_deleted in (0, 2) and rule_list like concat('%',#{query},'%')
</select>
</mapper>
\ No newline at end of file
......@@ -85,7 +85,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update>
<delete id="deleteMachineById" parameterType="String">
update machine set shop_id = null where id = #{id}
update machine set shop_id = null, bind_time = null, updated_at = now() where id = #{id}
</delete>
<delete id="deleteMachineByIds" parameterType="String">
......@@ -94,9 +94,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
</foreach>
</delete>
<update id="unbound">
update machine set shopId =null where code =#{id}
</update>
<select id="selectRegister" resultType="string">
select register from machine where code =#{id}
</select>
......
......@@ -65,6 +65,12 @@
where id = #{id}
</select>
<select id="selectOrderDetailsByIds" resultMap="OrderDetailResult">
<include refid="selectOrderDetailVo"/>
where id in
<foreach collection="ids" item="id" separator="," open="(" close=")">#{id}</foreach>
</select>
<insert id="insertOrderDetail" parameterType="OrderDetail" useGeneratedKeys="true" keyProperty="id">
insert into order_detail
<trim prefix="(" suffix=")" suffixOverrides=",">
......
......@@ -95,7 +95,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
'1' as state
from shop_goods sg ,goods g where sg.goods_id =g.id and g.state ='3' and g.is_deleted =0
and shop_id =#{shopId} and category =#{categoryId}
and shop_id =#{shopId} and category like concat('%,', #{categoryId}, ',%')
order by sg.turn
</select>
<select id="selectShopNoAddGoods" resultType="com.soss.system.domain.Goods">
......
......@@ -100,13 +100,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
sgs.state as state ,
gs.price as price,
gs.discount as discount,
gs.rule_list as rulesString
gs.rule_list as rulesString,
gs.is_deleted isDelete
from
goods_sku gs ,
shop_goods_sku sgs
where
gs.id = sgs.sku_id
and gs.is_deleted = '0'
<!-- and gs.is_deleted = '0' -->
and gs.is_deleted in (0, 2)
and sgs.goods_id =#{goodsId}
and sgs.shop_id =#{shopId}
......
......@@ -51,6 +51,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updatedAt != null ">and s.updated_at = #{updatedAt}</if>
<if test="isDefault != null ">and s.is_default = #{isDefault}</if>
<if test="machineCode!=null and machineCode != ''">and m.code =#{machineCode}</if>
<if test="states != null and states.size() > 0">
and s.state in
<foreach collection="states" item="state" separator="," open="(" close=")">#{state}</foreach>
</if>
</where>
</select>
......
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