Merge branch 'dev' of http://gitea.dctpay.com/hurui/puhui-go into dev
commit
da5f454c87
@ -0,0 +1,288 @@ |
||||
package com.bweb.controller.discount; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.security.SessionObject; |
||||
import com.hfkj.common.security.UserCenter; |
||||
import com.hfkj.common.utils.OrderUtil; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.*; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.model.SecUserSessionObject; |
||||
import com.hfkj.service.discount.CouponDiscountPackageService; |
||||
import com.hfkj.service.discount.impl.CouponDiscountServiceImpl; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@RequestMapping(value="/discountPackage") |
||||
@Api(value="优惠券包") |
||||
public class DiscountPackageController { |
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(DiscountPackageController.class); |
||||
|
||||
@Resource |
||||
private CouponDiscountPackageService couponDiscountPackageService; |
||||
|
||||
@Resource |
||||
private UserCenter userCenter; |
||||
|
||||
@Resource |
||||
private CouponDiscountServiceImpl couponDiscountService; |
||||
|
||||
@RequestMapping(value = "/getDiscountPackageList", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "获取优惠券包列表") |
||||
public ResponseData getDiscountPackageList( |
||||
@RequestParam(name = "title", required = false) String title, |
||||
@RequestParam(name = "key", required = false) String key, |
||||
@RequestParam(name = "status", required = false) Integer status, |
||||
@RequestParam(value = "pageNum" , required = true) Integer pageNum, |
||||
@RequestParam(value = "pageSize" , required = true) Integer pageSize) { |
||||
try { |
||||
|
||||
Map<String,Object> map = new HashMap<>(); |
||||
|
||||
map.put("title" , title); |
||||
map.put("key" , key); |
||||
map.put("status" , status); |
||||
|
||||
PageHelper.startPage(pageNum, pageSize); |
||||
return ResponseMsgUtil.success(new PageInfo<>(couponDiscountPackageService.getList(map))); |
||||
|
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighOrderController --> getUserOrderList() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
@RequestMapping(value = "/getDiscountPackageRecordList", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "获取优惠券包记录列表") |
||||
public ResponseData getDiscountPackageRecordList(@RequestParam(name = "discountPackageId", required = false) Long discountPackageId) { |
||||
try { |
||||
|
||||
|
||||
Map<String,Object> map = new HashMap<>(); |
||||
|
||||
map.put("discountPackageId" , discountPackageId); |
||||
|
||||
return ResponseMsgUtil.success(couponDiscountPackageService.getListRecordByMap(map)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighOrderController --> getUserOrderList() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/editCouponPackageInfo", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "编辑优惠券包基本信息") |
||||
public ResponseData editCouponPackageInfo(@RequestBody CouponDiscountPackage body, HttpServletRequest request) { |
||||
try { |
||||
|
||||
//发布人员
|
||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||
SecUserSessionObject userModel = (SecUserSessionObject) sessionObject.getObject(); |
||||
|
||||
if (StringUtils.isBlank(body.getTitle()) |
||||
|| body.getEffectiveTime() == null |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
|
||||
CouponDiscountPackage discountPackage; |
||||
|
||||
if (body.getId() != null) { |
||||
// 查询
|
||||
discountPackage = couponDiscountPackageService.queryDetail(body.getId()); |
||||
if (discountPackage == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.CONTENT_NOT_FOUND, ""); |
||||
} |
||||
} else { |
||||
discountPackage = new CouponDiscountPackage(); |
||||
discountPackage.setCreatedUserId(userModel.getAccount().getId().intValue()); |
||||
discountPackage.setKey(OrderUtil.generateOrderNo()); |
||||
discountPackage.setStatus(1); |
||||
discountPackage.setTotalStock(0); |
||||
discountPackage.setCreatedTime(new Date()); |
||||
} |
||||
|
||||
discountPackage.setSurplusStock(body.getSurplusStock()); |
||||
discountPackage.setTitle(body.getTitle()); |
||||
discountPackage.setEffectiveTime(body.getEffectiveTime()); |
||||
discountPackage.setUpdatedTime(new Date()); |
||||
discountPackage.setUpdatedUserId(userModel.getAccount().getId().intValue()); |
||||
|
||||
if (body.getId() != null) { |
||||
couponDiscountPackageService.update(discountPackage); |
||||
} else { |
||||
couponDiscountPackageService.create(discountPackage); |
||||
} |
||||
|
||||
return ResponseMsgUtil.success("成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighAgentController --> insertCouponPackageInfo() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/insertCouponPackageDetail", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "新增优惠券包详情") |
||||
public ResponseData insertCouponPackageDetail(@RequestBody CouponDiscountPackageDetails discountPackageDetails, HttpServletRequest request) { |
||||
try { |
||||
|
||||
|
||||
if ( discountPackageDetails.getDiscountPackageId() == null |
||||
|| discountPackageDetails.getDiscountId() == null |
||||
|| discountPackageDetails.getNum() == null |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
|
||||
CouponDiscount discount = couponDiscountService.queryDetail(discountPackageDetails.getDiscountId().longValue()); |
||||
|
||||
if (discount == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券不存在!"); |
||||
} |
||||
|
||||
CouponDiscountPackageDetails details = couponDiscountPackageService.discountPackageDetail(discountPackageDetails.getDiscountPackageId() , discountPackageDetails.getDiscountId()); |
||||
|
||||
|
||||
if (details == null) { |
||||
discountPackageDetails.setStatus(1); |
||||
discountPackageDetails.setDiscountName(discount.getName()); |
||||
discountPackageDetails.setDiscountImg(discount.getImg()); |
||||
discountPackageDetails.setCreatedTime(new Date()); |
||||
discountPackageDetails.setUpdatedTime(new Date()); |
||||
couponDiscountPackageService.createDetail(discountPackageDetails); |
||||
} else { |
||||
details.setNum(discountPackageDetails.getNum() + details.getNum()); |
||||
details.setUpdatedTime(new Date()); |
||||
couponDiscountPackageService.updateDetail(details); |
||||
} |
||||
|
||||
return ResponseMsgUtil.success("成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighAgentController --> insertAgent() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/deleteDetail", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "删除券包详情") |
||||
public ResponseData deleteDetail(@RequestParam(name = "detailId", required = false) Integer detailId) { |
||||
try { |
||||
|
||||
couponDiscountPackageService.deleteDetail(detailId); |
||||
|
||||
return ResponseMsgUtil.success("删除成功!"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighOrderController --> getUserOrderList() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getDetailList", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "券包详情列表") |
||||
public ResponseData getDetailList(@RequestParam(name = "discountPackageId", required = false) Integer discountPackageId) { |
||||
try { |
||||
|
||||
return ResponseMsgUtil.success( couponDiscountPackageService.getDetailList(discountPackageId)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighOrderController --> getUserOrderList() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/delete", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "删除券包") |
||||
public ResponseData delete(@RequestParam(name = "id", required = false) Long id) { |
||||
try { |
||||
|
||||
couponDiscountPackageService.delete(id , false); |
||||
|
||||
return ResponseMsgUtil.success("删除成功!"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighOrderController --> getUserOrderList() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/discountPackageAudit",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "券包上下架") |
||||
public ResponseData discountPackageAudit(@RequestParam(value = "id" , required = false) Long id) { |
||||
try { |
||||
|
||||
CouponDiscountPackage discountPackage = couponDiscountPackageService.queryDetail(id); |
||||
|
||||
if (discountPackage.getStatus() == 1) { |
||||
discountPackage.setStatus(2); |
||||
discountPackage.setUpdatedTime(new Date()); |
||||
} else if (discountPackage.getStatus() == 2) { |
||||
discountPackage.setStatus(3); |
||||
discountPackage.setUpdatedTime(new Date()); |
||||
} |
||||
|
||||
couponDiscountPackageService.update(discountPackage); |
||||
|
||||
return ResponseMsgUtil.success("成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/giveDiscountPackage", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "赠送券包") |
||||
public ResponseData giveDiscountPackage(@RequestBody JSONObject body) { |
||||
try { |
||||
|
||||
if ( body == null |
||||
|| body.getInteger("discountPackageId") == null |
||||
|| body.getString("phone") == null |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
couponDiscountPackageService.giveDiscountPackage(body.getInteger("discountPackageId") , body.getString("phone")); |
||||
|
||||
return ResponseMsgUtil.success("成功!"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighOrderController --> getUserOrderList() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,75 @@ |
||||
package com.cweb.controller.discount; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.security.SessionObject; |
||||
import com.hfkj.common.security.UserCenter; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.CouponDiscount; |
||||
import com.hfkj.entity.CouponDiscountGoodsRel; |
||||
import com.hfkj.entity.GoodsMsg; |
||||
import com.hfkj.entity.GoodsSpecs; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.model.SecUserSessionObject; |
||||
import com.hfkj.model.UserSessionObject; |
||||
import com.hfkj.model.discount.DiscountGoodsModel; |
||||
import com.hfkj.service.discount.CouponDiscountService; |
||||
import com.hfkj.service.discount.CouponDiscountUserRelService; |
||||
import com.hfkj.service.goods.impl.GoodsMsgServiceImpl; |
||||
import com.hfkj.service.goods.impl.GoodsSpecsServiceImpl; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.beans.BeanUtils; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.*; |
||||
|
||||
@Controller |
||||
@RequestMapping(value="/discount") |
||||
@Api(value="优惠券") |
||||
public class DiscountController { |
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(DiscountController.class); |
||||
|
||||
@Resource |
||||
private UserCenter userCenter; |
||||
|
||||
@Resource |
||||
private CouponDiscountUserRelService discountUserRelService; |
||||
|
||||
@RequestMapping(value = "/getListUserDiscount", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "获取用户优惠券列表") |
||||
public ResponseData getListUserDiscount(@RequestParam(value = "status", required = true) Integer status) { |
||||
try { |
||||
|
||||
// 用户session
|
||||
UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class); |
||||
|
||||
Map<String, Object> map = new HashMap<>(); |
||||
|
||||
map.put("userId", userSession.getUser().getId()); |
||||
map.put("status", status); |
||||
|
||||
return ResponseMsgUtil.success(discountUserRelService.getList(map)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("GoodsDetailController --> getListUser() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
} |
@ -0,0 +1,30 @@ |
||||
package com.hfkj.service.discount; |
||||
|
||||
import com.hfkj.entity.CouponDiscount; |
||||
import com.hfkj.entity.CouponDiscountUserRel; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
public interface CouponDiscountUserRelService { |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @Name create |
||||
* @Description // 创建
|
||||
* @Date 15:11 2024/4/19 |
||||
* @Param CouponDiscount |
||||
* @return void |
||||
*/ |
||||
void create(CouponDiscountUserRel couponDiscountUserRel); |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @Name getList |
||||
* @Description // 根据多条件查询列表
|
||||
* @Date 15:13 2024/4/19 |
||||
* @Param map |
||||
* @return java.util.List<com.hfkj.entity.CouponDiscount> |
||||
*/ |
||||
List<CouponDiscountUserRel> getList(Map<String , Object> map); |
||||
} |
@ -0,0 +1,230 @@ |
||||
package com.hfkj.service.discount.impl; |
||||
|
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.utils.OrderUtil; |
||||
import com.hfkj.dao.CouponDiscountPackageDetailsMapper; |
||||
import com.hfkj.dao.CouponDiscountPackageMapper; |
||||
import com.hfkj.dao.CouponDiscountPackageRecordMapper; |
||||
import com.hfkj.entity.*; |
||||
import com.hfkj.service.discount.CouponDiscountPackageService; |
||||
import com.hfkj.service.discount.CouponDiscountService; |
||||
import com.hfkj.service.discount.CouponDiscountUserRelService; |
||||
import com.hfkj.service.user.BsUserService; |
||||
import com.hfkj.sysenum.UserStatusEnum; |
||||
import io.swagger.models.auth.In; |
||||
import org.apache.commons.collections4.MapUtils; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.*; |
||||
|
||||
@Service("couponDiscountPackageService") |
||||
public class CouponDiscountPackageServiceImpl implements CouponDiscountPackageService { |
||||
|
||||
@Resource |
||||
private CouponDiscountPackageMapper couponDiscountPackageMapper; |
||||
|
||||
@Resource |
||||
private CouponDiscountPackageRecordMapper couponDiscountPackageRecordMapper; |
||||
|
||||
@Resource |
||||
private CouponDiscountPackageDetailsMapper couponDiscountPackageDetailsMapper; |
||||
|
||||
@Resource |
||||
private CouponDiscountUserRelService discountUserRelService; |
||||
|
||||
@Resource |
||||
private BsUserService bsUserService; |
||||
|
||||
@Resource |
||||
private CouponDiscountService discountService; |
||||
|
||||
@Override |
||||
public void create(CouponDiscountPackage discountPackage) { |
||||
couponDiscountPackageMapper.insert(discountPackage); |
||||
} |
||||
|
||||
@Override |
||||
public void update(CouponDiscountPackage discountPackage) { |
||||
couponDiscountPackageMapper.updateByPrimaryKeySelective(discountPackage); |
||||
} |
||||
|
||||
@Override |
||||
public void delete(Long id, Boolean fullDelete) { |
||||
|
||||
if (fullDelete) { |
||||
couponDiscountPackageMapper.deleteByPrimaryKey(id); |
||||
} else { |
||||
CouponDiscountPackage discountPackage = queryDetail(id); |
||||
discountPackage.setStatus(0); |
||||
discountPackage.setUpdatedTime(new Date()); |
||||
update(discountPackage); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public CouponDiscountPackage queryDetail(Long id) { |
||||
return couponDiscountPackageMapper.selectByPrimaryKey(id); |
||||
} |
||||
|
||||
@Override |
||||
public CouponDiscountPackage queryDetailByMap(Map<String, Object> map) { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public List<CouponDiscountPackage> getList(Map<String, Object> map) { |
||||
|
||||
CouponDiscountPackageExample example = new CouponDiscountPackageExample(); |
||||
CouponDiscountPackageExample.Criteria criteria = example.createCriteria(); |
||||
|
||||
if (StringUtils.isNotBlank(MapUtils.getString(map, "title"))) { |
||||
criteria.andTitleLike("%"+MapUtils.getString(map, "title")+"%"); |
||||
} |
||||
if (StringUtils.isNotBlank(MapUtils.getString(map, "key"))) { |
||||
criteria.andKeyEqualTo(MapUtils.getString(map, "key")); |
||||
} |
||||
if (MapUtils.getInteger(map, "status") != null) { |
||||
criteria.andStatusEqualTo(MapUtils.getInteger(map, "status")); |
||||
} else { |
||||
criteria.andStatusNotEqualTo(0); |
||||
} |
||||
|
||||
return couponDiscountPackageMapper.selectByExample(example); |
||||
} |
||||
|
||||
@Override |
||||
public List<CouponDiscountPackageRecord> getListRecordByMap(Map<String, Object> map) { |
||||
|
||||
CouponDiscountPackageRecordExample example = new CouponDiscountPackageRecordExample(); |
||||
CouponDiscountPackageRecordExample.Criteria criteria = example.createCriteria(); |
||||
|
||||
if (MapUtils.getInteger(map, "discountPackageId") != null) { |
||||
criteria.andDiscountPackageIdEqualTo(MapUtils.getInteger(map, "discountPackageId")); |
||||
} |
||||
if (MapUtils.getInteger(map, "status") != null) { |
||||
criteria.andStatusEqualTo(MapUtils.getInteger(map, "status")); |
||||
} else { |
||||
criteria.andStatusNotEqualTo(0); |
||||
} |
||||
|
||||
return couponDiscountPackageRecordMapper.selectByExample(example); |
||||
} |
||||
|
||||
@Override |
||||
public void createRecord(CouponDiscountPackageRecord discountPackageRecord) { |
||||
couponDiscountPackageRecordMapper.insert(discountPackageRecord); |
||||
} |
||||
|
||||
@Override |
||||
public void createDetail(CouponDiscountPackageDetails discountPackageDetails) { |
||||
couponDiscountPackageDetailsMapper.insert(discountPackageDetails); |
||||
} |
||||
|
||||
@Override |
||||
public void updateDetail(CouponDiscountPackageDetails discountPackageDetails) { |
||||
couponDiscountPackageDetailsMapper.updateByPrimaryKeySelective(discountPackageDetails); |
||||
} |
||||
|
||||
@Override |
||||
public List<CouponDiscountPackageDetails> getDetailList(Integer discountPackageId) { |
||||
CouponDiscountPackageDetailsExample example = new CouponDiscountPackageDetailsExample(); |
||||
example.createCriteria().andStatusEqualTo(1).andDiscountPackageIdEqualTo(discountPackageId); |
||||
|
||||
return couponDiscountPackageDetailsMapper.selectByExample(example); |
||||
} |
||||
|
||||
@Override |
||||
public CouponDiscountPackageDetails discountPackageDetail(Integer discountPackageId , Integer discountId) { |
||||
CouponDiscountPackageDetailsExample example = new CouponDiscountPackageDetailsExample(); |
||||
example.createCriteria().andDiscountPackageIdEqualTo(discountPackageId).andDiscountIdEqualTo(discountId).andStatusEqualTo(1); |
||||
|
||||
List<CouponDiscountPackageDetails> list = couponDiscountPackageDetailsMapper.selectByExample(example); |
||||
|
||||
if (!list.isEmpty()) { |
||||
return list.get(0); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void deleteDetail(Integer id) { |
||||
couponDiscountPackageDetailsMapper.deleteByPrimaryKey(id); |
||||
} |
||||
|
||||
@Override |
||||
public void giveDiscountPackage(Integer discountPackageId, String phone) { |
||||
CouponDiscountPackage discountPackage = queryDetail(Long.valueOf(discountPackageId)); |
||||
|
||||
BsUser bsUser = bsUserService.getUser(phone); |
||||
if (bsUser == null) { |
||||
bsUser = new BsUser(); |
||||
bsUser.setPhone(phone); |
||||
bsUser.setStatus(UserStatusEnum.status1.getCode()); |
||||
bsUserService.editData(bsUser); |
||||
} |
||||
|
||||
if (discountPackage == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前券包不存在!"); |
||||
} |
||||
|
||||
CouponDiscountUserRel discountUserRel; |
||||
|
||||
List<CouponDiscountPackageDetails> details = getDetailList(discountPackageId); |
||||
|
||||
for (CouponDiscountPackageDetails detail : details) { |
||||
CouponDiscount discount = discountService.queryDetail(Long.valueOf(detail.getDiscountId())); |
||||
for (int i = 0; i < detail.getNum(); i++) { |
||||
discountUserRel = new CouponDiscountUserRel(); |
||||
discountUserRel.setDiscountId(Long.valueOf(detail.getDiscountId())); |
||||
discountUserRel.setDiscountImg(detail.getDiscountImg()); |
||||
discountUserRel.setDiscountName(detail.getDiscountName()); |
||||
discountUserRel.setDiscountCondition(discount.getCondition()); |
||||
discountUserRel.setDiscountPrice(discount.getPrice()); |
||||
discountUserRel.setDiscountType(discount.getType()); |
||||
discountUserRel.setDiscountPercentage(discount.getPercentage()); |
||||
discountUserRel.setUserId(bsUser.getId()); |
||||
discountUserRel.setStatus(1); |
||||
discountUserRel.setCreateTime(new Date()); |
||||
|
||||
// 计算使用有效期
|
||||
Calendar userEndTime = Calendar.getInstance(); |
||||
userEndTime.setTime(new Date()); |
||||
userEndTime.set(Calendar.HOUR_OF_DAY, 23); |
||||
userEndTime.set(Calendar.MINUTE, 59); |
||||
userEndTime.set(Calendar.SECOND, 59); |
||||
userEndTime.add(Calendar.DATE, discount.getEffectiveDay()); |
||||
|
||||
if (userEndTime.getTime().compareTo(discount.getSalesEndTime()) > 0) { |
||||
discountUserRel.setUseEndTime(discount.getSalesEndTime()); |
||||
} else { |
||||
discountUserRel.setUseEndTime(userEndTime.getTime()); |
||||
} |
||||
|
||||
discountUserRelService.create(discountUserRel); |
||||
} |
||||
} |
||||
|
||||
CouponDiscountPackageRecord discountPackageRecord = new CouponDiscountPackageRecord(); |
||||
discountPackageRecord.setDiscountPackageId(discountPackageId); |
||||
discountPackageRecord.setDiscountPackageTitle(discountPackage.getTitle()); |
||||
discountPackageRecord.setType(2); |
||||
discountPackageRecord.setSerialNo(OrderUtil.generateOrderNo()); |
||||
discountPackageRecord.setUserId(bsUser.getId().intValue()); |
||||
discountPackageRecord.setUserPhone(bsUser.getPhone()); |
||||
discountPackageRecord.setCreatedTime(new Date()); |
||||
discountPackageRecord.setStatus(1); |
||||
|
||||
createRecord(discountPackageRecord); |
||||
|
||||
|
||||
discountPackage.setSurplusStock(discountPackage.getSurplusStock() - 1); |
||||
|
||||
update(discountPackage); |
||||
|
||||
} |
||||
} |
@ -0,0 +1,46 @@ |
||||
package com.hfkj.service.discount.impl; |
||||
|
||||
import com.hfkj.dao.CouponDiscountUserRelMapper; |
||||
import com.hfkj.entity.CouponDiscountExample; |
||||
import com.hfkj.entity.CouponDiscountUserRel; |
||||
import com.hfkj.entity.CouponDiscountUserRelExample; |
||||
import com.hfkj.service.discount.CouponDiscountUserRelService; |
||||
import org.apache.commons.collections4.MapUtils; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
@Service("couponDiscountUserRelService") |
||||
public class CouponDiscountUserRelServiceImpl implements CouponDiscountUserRelService { |
||||
|
||||
@Resource |
||||
private CouponDiscountUserRelMapper couponDiscountUserRelMapper; |
||||
|
||||
@Override |
||||
public void create(CouponDiscountUserRel couponDiscountUserRel) { |
||||
couponDiscountUserRelMapper.insert(couponDiscountUserRel); |
||||
} |
||||
|
||||
@Override |
||||
public List<CouponDiscountUserRel> getList(Map<String, Object> map) { |
||||
CouponDiscountUserRelExample example = new CouponDiscountUserRelExample(); |
||||
CouponDiscountUserRelExample.Criteria criteria = example.createCriteria(); |
||||
|
||||
|
||||
if (MapUtils.getInteger(map, "userId") != null) { |
||||
criteria.andUserIdEqualTo(MapUtils.getLong(map, "userId")); |
||||
} |
||||
|
||||
if (MapUtils.getInteger(map, "status") != null) { |
||||
criteria.andStatusEqualTo(MapUtils.getInteger(map, "status")); |
||||
} |
||||
|
||||
return couponDiscountUserRelMapper.selectByExample(example); |
||||
} |
||||
|
||||
|
||||
} |
Loading…
Reference in new issue