|
@@ -16,6 +16,7 @@ import com.szwl.model.bo.R;
|
|
|
import com.szwl.model.bo.ResponseModel;
|
|
|
import com.szwl.model.dto.PromoCodeTarget;
|
|
|
import com.szwl.model.entity.*;
|
|
|
+import com.szwl.model.utils.DateUtils;
|
|
|
import com.szwl.service.*;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -39,6 +40,7 @@ import java.util.*;
|
|
|
|
|
|
import static com.szwl.constant.ResponseCodesEnum.A0001;
|
|
|
import static com.szwl.constant.ResponseCodesEnum.A0002;
|
|
|
+import static com.szwl.model.utils.DateUtils.PATTERN_yyyy_MM_dd_HH_mm_ss;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -86,12 +88,29 @@ public class TPromoCodeController {
|
|
|
}
|
|
|
@ApiOperation(value = "小程序获取优惠码")
|
|
|
@GetMapping("/getCode")
|
|
|
- public ResponseModel<TPromoCode> getCode( String code) {
|
|
|
- LambdaQueryWrapper<TPromoCode> query = Wrappers.lambdaQuery();
|
|
|
- query.eq(TPromoCode::getCode,code);
|
|
|
- List<TPromoCode> list = promoCodeService.list(query);
|
|
|
- if(list.size()>0){
|
|
|
- TPromoCode tPromoCode = list.get(0);
|
|
|
+ public ResponseModel<TPromoCode> getCode(String clientId, String code) {
|
|
|
+ if(StringUtils.isEmpty(clientId)){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
|
|
|
+ query.eq(TEquipment::getClientId,clientId);
|
|
|
+ List<TEquipment> list = tEquipmentService.list(query);
|
|
|
+ TEquipment equipment = list.get(0);
|
|
|
+ LambdaQueryWrapper<TPromoCode> query1 = Wrappers.lambdaQuery();
|
|
|
+ query1.eq(TPromoCode::getCode,code);
|
|
|
+ query1.eq(TPromoCode::getAdminId,equipment.getAdminId());
|
|
|
+ List<TPromoCode> list1 = promoCodeService.list(query1);
|
|
|
+ if(list1.size()>0){
|
|
|
+ TPromoCode tPromoCode = list1.get(0);
|
|
|
+ String isUse = tPromoCode.getIsUse();
|
|
|
+ if(isUse.equals("1")){
|
|
|
+ return R.fail(A0002,"已使用");
|
|
|
+ }
|
|
|
+ Date lastUseDate = tPromoCode.getLastUseDate();
|
|
|
+ Date date = new Date();
|
|
|
+ if(date.getTime()>lastUseDate.getTime()){
|
|
|
+ return R.fail(A0002,"已过期");
|
|
|
+ }
|
|
|
return R.ok(tPromoCode);
|
|
|
}else {
|
|
|
return R.fail(A0002,"没有找到优惠码");
|
|
@@ -102,6 +121,9 @@ public class TPromoCodeController {
|
|
|
public void updatePromoCode(@RequestParam(value = "id")String id, @RequestParam(value = "type")String type) {
|
|
|
TPromoCode promoCode = promoCodeService.getById(id);
|
|
|
promoCode.setIsUse(type);
|
|
|
+ if(type.equals("1")){
|
|
|
+ promoCode.setUseDate(DateUtils.formatDate(new Date(),PATTERN_yyyy_MM_dd_HH_mm_ss));
|
|
|
+ }
|
|
|
promoCodeService.updateById(promoCode);
|
|
|
}
|
|
|
@ApiOperation(value = "生成0折优惠码")
|