|
@@ -3,9 +3,15 @@ package com.ygj.yuemum.service.coupon;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.ygj.yuemum.dao.coupon.CouponDao;
|
|
|
import com.ygj.yuemum.domain.coupon.Coupon;
|
|
|
+import com.ygj.yuemum.domain.coupon.CouponLog;
|
|
|
+import com.ygj.yuemum.domain.customer.CustomerCoupon;
|
|
|
+import com.ygj.yuemum.service.customer.CustomerCouponService;
|
|
|
+import com.ygj.yuemum.service.order.OrderTempService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -15,20 +21,29 @@ public class CouponService {
|
|
|
|
|
|
@Autowired
|
|
|
private CouponDao couponDao;
|
|
|
+ @Autowired
|
|
|
+ private OrderTempService orderTempService;
|
|
|
+ @Autowired
|
|
|
+ private CustomerCouponService customerCouponService;
|
|
|
+ @Autowired
|
|
|
+ private CouponLogService couponLogService;
|
|
|
+
|
|
|
//分页
|
|
|
public Map<String, Object> getCoupons(int page, int limit) {
|
|
|
PageHelper.startPage(page, limit);
|
|
|
List<Coupon> coupons = couponDao.getAll();
|
|
|
Map<String, Object> tableData = new HashMap<>();
|
|
|
- Integer count = couponDao.getCount();
|
|
|
+ Integer count = couponDao.getCount();
|
|
|
tableData.put("items", coupons);
|
|
|
tableData.put("total", count);
|
|
|
return tableData;
|
|
|
}
|
|
|
+
|
|
|
public List<Coupon> getAll() {
|
|
|
List<Coupon> coupons = couponDao.getAll();
|
|
|
return coupons;
|
|
|
}
|
|
|
+
|
|
|
public int addCoupon(Coupon coupon) {
|
|
|
return couponDao.insertSelective(coupon);
|
|
|
}
|
|
@@ -53,5 +68,208 @@ public class CouponService {
|
|
|
return couponDao.selectByPrimaryKey(id);
|
|
|
}
|
|
|
|
|
|
+ //Modoo API 1.成功领取 | 61.已有订单 | 62.重复领取 | 63.超出金额 | 98.优惠券不足 | 99.系统异常
|
|
|
+ public int getNewUserCoupon(String phone, int channel) {//新用户礼包
|
|
|
+ /*
|
|
|
+ 券总金额大于500 不能再领
|
|
|
+ 检查用户是否符合领取条件 customer_coupon order_temp --
|
|
|
+ 获取优惠券信息 --
|
|
|
+ 保存都customer_coupon表 --
|
|
|
+ 更新优惠券状态--
|
|
|
+ 日志里面插入一条信息--
|
|
|
+ 返回
|
|
|
+ */
|
|
|
+ try {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ if (customerCouponService.checkSumCustomerCoupon(phone) > 500) {
|
|
|
+ return 63;
|
|
|
+ }
|
|
|
+ if (orderTempService.checkOrder(phone) > 0) {
|
|
|
+ return 61;
|
|
|
+ }
|
|
|
+ CustomerCoupon checkCustomer = new CustomerCoupon();
|
|
|
+ checkCustomer.setCm_phone(phone);
|
|
|
+ checkCustomer.setCb_code("PVP2018051297451");
|
|
|
+ if (customerCouponService.checkCustomerCoupon(checkCustomer) > 0) {
|
|
|
+ return 62;
|
|
|
+ }
|
|
|
+ String cp_code = couponDao.getCoupon("PVP2018051297451");
|
|
|
+ if (cp_code.equals(null)) {
|
|
|
+ return 98;
|
|
|
+ }
|
|
|
+ CustomerCoupon customerCoupon = new CustomerCoupon();
|
|
|
+ customerCoupon.setCm_phone(phone);
|
|
|
+ customerCoupon.setCb_code("PVP2018051297451");
|
|
|
+ customerCoupon.setCc_code(cp_code);
|
|
|
+ customerCoupon.setCp_status(1);
|
|
|
+ customerCoupon.setCc_getdate(sdf.format(new Date()));
|
|
|
+ customerCoupon.setCc_getchannel(channel);
|
|
|
+ customerCouponService.addCustomerCoupon(customerCoupon);
|
|
|
+ couponDao.updateGetCoupon(cp_code);
|
|
|
+ CouponLog couponLog = new CouponLog();
|
|
|
+ couponLog.setCp_code(cp_code);
|
|
|
+ couponLog.setCl_type(1);
|
|
|
+ couponLog.setCl_mp(phone);
|
|
|
+ couponLog.setCl_user(9527);
|
|
|
+ couponLog.setCl_date(sdf.format(new Date()));
|
|
|
+ couponLog.setCb_code("PVP2018051297451");
|
|
|
+ couponLogService.addCouponLog(couponLog);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ return 99;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getConsultTaskCoupon(String phone, int channel) {//咨询任务
|
|
|
+ try {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ if (customerCouponService.checkSumCustomerCoupon(phone) > 500) {
|
|
|
+ return 63;
|
|
|
+ }
|
|
|
+ if (orderTempService.checkOrder(phone) > 0) {
|
|
|
+ return 61;
|
|
|
+ }
|
|
|
+ CustomerCoupon checkCustomer = new CustomerCoupon();
|
|
|
+ checkCustomer.setCm_phone(phone);
|
|
|
+ checkCustomer.setCb_code("PVP2018051273883");
|
|
|
+ int coupons = customerCouponService.checkCustomerCoupon(checkCustomer);
|
|
|
+ Coupon getCouponAmount = new Coupon();
|
|
|
+ if ( coupons >= 3) {
|
|
|
+ return 62;
|
|
|
+ } else if (coupons == 2){
|
|
|
+ getCouponAmount.setCp_amount(50);
|
|
|
+ } else if (coupons == 1){
|
|
|
+ getCouponAmount.setCp_amount(30);
|
|
|
+ } else if (coupons == 0){
|
|
|
+ getCouponAmount.setCp_amount(20);
|
|
|
+ }
|
|
|
+ getCouponAmount.setCb_code("PVP2018051273883");
|
|
|
+ String cp_code = couponDao.getCouponAmount(getCouponAmount);
|
|
|
+ if (cp_code.equals(null)) {
|
|
|
+ return 98;
|
|
|
+ }
|
|
|
+ CustomerCoupon customerCoupon = new CustomerCoupon();
|
|
|
+ customerCoupon.setCm_phone(phone);
|
|
|
+ customerCoupon.setCb_code("PVP2018051273883");
|
|
|
+ customerCoupon.setCc_code(cp_code);
|
|
|
+ customerCoupon.setCp_status(1);
|
|
|
+ customerCoupon.setCc_getdate(sdf.format(new Date()));
|
|
|
+ customerCoupon.setCc_getchannel(channel);
|
|
|
+ customerCouponService.addCustomerCoupon(customerCoupon);
|
|
|
+ couponDao.updateGetCoupon(cp_code);
|
|
|
+ CouponLog couponLog = new CouponLog();
|
|
|
+ couponLog.setCp_code(cp_code);
|
|
|
+ couponLog.setCl_type(1);
|
|
|
+ couponLog.setCl_mp(phone);
|
|
|
+ couponLog.setCl_user(9527);
|
|
|
+ couponLog.setCl_date(sdf.format(new Date()));
|
|
|
+ couponLog.setCb_code("PVP2018051273883");
|
|
|
+ couponLogService.addCouponLog(couponLog);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ return 99;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getDetectionTaskCoupon(String phone, int channel) {//测胎心任务
|
|
|
+ try {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ if (customerCouponService.checkSumCustomerCoupon(phone) > 500) {
|
|
|
+ return 63;
|
|
|
+ }
|
|
|
+ if (orderTempService.checkOrder(phone) > 0) {
|
|
|
+ return 61;
|
|
|
+ }
|
|
|
+ CustomerCoupon checkCustomer = new CustomerCoupon();
|
|
|
+ checkCustomer.setCm_phone(phone);
|
|
|
+ checkCustomer.setCb_code("PVP2018051211608");
|
|
|
+ int coupons = customerCouponService.checkCustomerCoupon(checkCustomer);
|
|
|
+ Coupon getCouponAmount = new Coupon();
|
|
|
+ if ( coupons >= 3) {
|
|
|
+ return 62;
|
|
|
+ } else if (coupons == 2) getCouponAmount.setCp_amount(50);
|
|
|
+ else if (coupons == 1){
|
|
|
+ getCouponAmount.setCp_amount(30);
|
|
|
+ } else if (coupons == 0){
|
|
|
+ getCouponAmount.setCp_amount(20);
|
|
|
+ }
|
|
|
+ getCouponAmount.setCb_code("PVP2018051211608");
|
|
|
+ String cp_code = couponDao.getCouponAmount(getCouponAmount);
|
|
|
+ if (cp_code.equals(null)) {
|
|
|
+ return 98;
|
|
|
+ }
|
|
|
+ CustomerCoupon customerCoupon = new CustomerCoupon();
|
|
|
+ customerCoupon.setCm_phone(phone);
|
|
|
+ customerCoupon.setCb_code("PVP2018051211608");
|
|
|
+ customerCoupon.setCc_code(cp_code);
|
|
|
+ customerCoupon.setCp_status(1);
|
|
|
+ customerCoupon.setCc_getdate(sdf.format(new Date()));
|
|
|
+ customerCoupon.setCc_getchannel(channel);
|
|
|
+ customerCouponService.addCustomerCoupon(customerCoupon);
|
|
|
+ couponDao.updateGetCoupon(cp_code);
|
|
|
+ CouponLog couponLog = new CouponLog();
|
|
|
+ couponLog.setCp_code(cp_code);
|
|
|
+ couponLog.setCl_type(1);
|
|
|
+ couponLog.setCl_mp(phone);
|
|
|
+ couponLog.setCl_user(9527);
|
|
|
+ couponLog.setCl_date(sdf.format(new Date()));
|
|
|
+ couponLog.setCb_code("PVP2018051211608");
|
|
|
+ couponLogService.addCouponLog(couponLog);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ return 99;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getRechargeTaskCoupon(String phone, int channel) {//充值任务
|
|
|
+ try {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ if (customerCouponService.checkSumCustomerCoupon(phone) > 500) {
|
|
|
+ return 63;
|
|
|
+ }
|
|
|
+ if (orderTempService.checkOrder(phone) > 0) {
|
|
|
+ return 61;
|
|
|
+ }
|
|
|
+ CustomerCoupon checkCustomer = new CustomerCoupon();
|
|
|
+ checkCustomer.setCm_phone(phone);
|
|
|
+ checkCustomer.setCb_code("PVP2018051263016");
|
|
|
+ if (customerCouponService.checkCustomerCoupon(checkCustomer) > 0) {
|
|
|
+ return 62;
|
|
|
+ }
|
|
|
+ String cp_code = couponDao.getCoupon("PVP2018051263016");
|
|
|
+ if (cp_code.equals(null)) {
|
|
|
+ return 98;
|
|
|
+ }
|
|
|
+ CustomerCoupon customerCoupon = new CustomerCoupon();
|
|
|
+ customerCoupon.setCm_phone(phone);
|
|
|
+ customerCoupon.setCb_code("PVP2018051263016");
|
|
|
+ customerCoupon.setCc_code(cp_code);
|
|
|
+ customerCoupon.setCp_status(1);
|
|
|
+ customerCoupon.setCc_getdate(sdf.format(new Date()));
|
|
|
+ customerCoupon.setCc_getchannel(channel);
|
|
|
+ customerCouponService.addCustomerCoupon(customerCoupon);
|
|
|
+ couponDao.updateGetCoupon(cp_code);
|
|
|
+ CouponLog couponLog = new CouponLog();
|
|
|
+ couponLog.setCp_code(cp_code);
|
|
|
+ couponLog.setCl_type(1);
|
|
|
+ couponLog.setCl_mp(phone);
|
|
|
+ couponLog.setCl_user(9527);
|
|
|
+ couponLog.setCl_date(sdf.format(new Date()));
|
|
|
+ couponLog.setCb_code("PVP2018051263016");
|
|
|
+ couponLogService.addCouponLog(couponLog);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ return 99;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|