package com.stylefeng.guns.modular.system.service.impl;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
import com.stylefeng.guns.core.util.ToolUtil;
|
import com.stylefeng.guns.modular.account.controller.AppOrderController;
|
import com.stylefeng.guns.modular.system.dao.TaxiCardMapper;
|
import com.stylefeng.guns.modular.system.model.*;
|
import com.stylefeng.guns.modular.system.service.*;
|
import com.stylefeng.guns.modular.system.util.GDMapGeocodingUtil;
|
import com.stylefeng.guns.modular.system.util.PayMoneyUtil;
|
import com.stylefeng.guns.modular.system.util.ResultUtil;
|
import com.stylefeng.guns.modular.system.warpper.CouponWarpper;
|
import com.stylefeng.guns.modular.system.warpper.TaxiCardWapper;
|
import com.stylefeng.guns.modular.taxi.model.PaymentRecord;
|
import com.stylefeng.guns.modular.taxi.service.IPaymentRecordService;
|
import com.stylefeng.guns.modular.taxi.service.ITransactionDetailsService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Service;
|
|
import java.math.BigDecimal;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
@Service
|
public class TaxiCardServiceImpl extends ServiceImpl<TaxiCardMapper, TaxiCard> implements ITaxiCardService {
|
|
@Autowired
|
private ICompanyCityService companyCityService;
|
|
@Autowired
|
private IOpenCityService openCityService;
|
|
@Autowired
|
private GDMapGeocodingUtil gdMapGeocodingUtil;
|
|
@Autowired
|
private ICouponRecordService couponRecordService;
|
|
@Autowired
|
private ICompanyService companyService;
|
|
@Autowired
|
private ITaxiCardPaymentService taxiCardPaymentService;
|
|
@Autowired
|
private IUserUserService userUserService;
|
|
@Autowired
|
private PayMoneyUtil payMoneyUtil;
|
|
@Autowired
|
private IUserInfoService userInfoService;
|
|
@Autowired
|
private IPaymentRecordService paymentRecordService;
|
|
@Autowired
|
private ITransactionDetailsService transactionDetailsService;
|
|
@Autowired
|
private IIncomeService incomeService;
|
|
@Autowired
|
private ISystemNoticeService systemNoticeService;
|
|
@Autowired
|
private IUserTaxiCardService userTaxiCardService;
|
|
@Autowired
|
private IRegionService regionService;
|
|
@Autowired
|
private IUserCouponRecordService userCouponRecordService;
|
|
@Value("${callbackPath}")
|
private String callbackPath;
|
|
|
|
|
@Override
|
public ResultUtil<List<TaxiCardWapper>> getTaxiCardList(Integer uid, Integer type, String lon, String lat) throws Exception {
|
Company company = companyCityService.query(lon, lat);
|
if(null == company ){
|
return ResultUtil.error("当前位置暂无企业服务");
|
}
|
List<Integer> integers1 = companyCityService.query1(lon, lat);
|
System.out.println(integers1);
|
// TODO: 2022/3/19 打车卡可以重复购买,有效期延长 ---> 只能购买使用完和未购买的打车卡
|
List<TaxiCard> taxiCards = this.selectList(new EntityWrapper<TaxiCard>().in("companyCityId", integers1)
|
.eq("state", 1).orderBy("createTime desc"));
|
List<Integer> ids =new ArrayList<>();
|
if(taxiCards.size()==0){
|
ids.add(-1);
|
}
|
ids = taxiCards.stream().map(TaxiCard::getId).collect(Collectors.toList());
|
List<TaxiCard> taxiCards1 = this.selectList(new EntityWrapper<TaxiCard>().notIn("id", ids)
|
.eq("state", 1)
|
.eq("taxiCardType", 2));
|
taxiCards.addAll(taxiCards1);
|
List<TaxiCardWapper> list = new ArrayList<>();
|
taxiCards.forEach(taxiCard -> {
|
List<UserTaxiCard> userTaxiCards = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().eq("userId", uid)
|
.eq("taxiCardId", taxiCard.getId())
|
.where("endTime > now()"));
|
boolean b = false;
|
for (UserTaxiCard userTaxiCard : userTaxiCards) {
|
JSONObject jsonObject = JSON.parseObject(userTaxiCard.getContent());
|
if(userTaxiCard.getType() == 1 || userTaxiCard.getType() == 3){//次数卡
|
Integer time = jsonObject.getInteger("time");
|
if(time > 0){
|
b = true;
|
break;
|
}
|
}
|
if(userTaxiCard.getType() == 2 || userTaxiCard.getType() == 4 || userTaxiCard.getType() == 5){
|
b = true;
|
break;
|
}
|
if(userTaxiCard.getType() == 6){//物流优惠包
|
JSONArray coupons = jsonObject.getJSONArray("coupons");
|
// Integer id = coupons.getInteger(1);
|
for (int i = 0; i < coupons.size(); i++) {
|
JSONArray jsonArray = coupons.getJSONArray(i);
|
int l = userCouponRecordService.selectCount(new EntityWrapper<UserCouponRecord>().eq("userId", uid).eq("couponId", jsonArray.get(1).toString())
|
.eq("activityType", 5).eq("state", 1).eq("couponActivityId", taxiCard.getId()).where("now() <= expirationTime"));
|
if(l > 0){
|
b = true;
|
break;
|
}
|
}
|
|
}
|
|
}
|
if(b){//还未使用完的情况
|
return;
|
}
|
|
|
JSONObject jsonObject = JSON.parseObject(taxiCard.getContent());
|
if(taxiCard.getType() != 6){
|
List<Integer> integers = jsonObject.getJSONArray("businessTypes").toJavaList(Integer.class);
|
if(!integers.contains(0) && !integers.contains(type)){//不包含通用和特定业务类型的数据
|
return;
|
}
|
}
|
if(taxiCard.getType() == 6){
|
JSONArray coupons = jsonObject.getJSONArray("coupons");
|
Integer num = 0;
|
for(int i = 0; i < coupons.size(); i++){
|
CouponRecord couponRecord = couponRecordService.selectById(coupons.getJSONArray(i).getInteger(1));
|
if(null != couponRecord && (couponRecord.getCouponUseType() == 0 || couponRecord.getCouponUseType() == type)){
|
num++;
|
break;
|
}
|
}
|
if(num == 0){
|
return;
|
}
|
}
|
|
TaxiCardWapper taxiCardWapper = new TaxiCardWapper();
|
taxiCardWapper.setId(taxiCard.getId());
|
taxiCardWapper.setName(taxiCard.getName());
|
taxiCardWapper.setState(taxiCard.getState());
|
taxiCardWapper.setValidDate(taxiCard.getValidDate());
|
if(taxiCard.getType() == 1 || taxiCard.getType() == 4 || taxiCard.getType() == 5){
|
taxiCardWapper.setType(taxiCard.getType());
|
taxiCardWapper.setDiscounts(jsonObject.getDouble("discount"));
|
taxiCardWapper.setTime(jsonObject.getInteger("time"));
|
}
|
if(taxiCard.getType() == 2){
|
taxiCardWapper.setType(taxiCard.getType());
|
JSONArray fullReduction = jsonObject.getJSONArray("fullReduction");
|
JSONArray jsonArray = fullReduction.getJSONArray(fullReduction.size() - 1);
|
taxiCardWapper.setDiscounts(jsonArray.getDouble(1));
|
}
|
if(taxiCard.getType() == 3){
|
taxiCardWapper.setType(taxiCard.getType());
|
taxiCardWapper.setDiscounts(jsonObject.getDouble("discountAmount"));
|
taxiCardWapper.setTime(jsonObject.getInteger("time"));
|
}
|
if(taxiCard.getType() == 6){
|
JSONArray coupons = jsonObject.getJSONArray("coupons");
|
Integer num = 0;
|
for(int i = 0; i < coupons.size(); i++){
|
num += coupons.getJSONArray(i).getInteger(0);
|
}
|
taxiCardWapper.setType(taxiCard.getType());
|
taxiCardWapper.setCouponNum(num);
|
}
|
|
|
String str = "";
|
if(taxiCard.getTaxiCardType() == 1){
|
String[] split = taxiCard.getCompanyCityId().split(";");
|
for(String id : split){
|
CompanyCity companyCity = companyCityService.selectById(id);
|
if(ToolUtil.isNotEmpty(companyCity.getAreaCode())){
|
Region region = regionService.selectOne(new EntityWrapper<Region>().eq("code", companyCity.getAreaCode()));
|
str += region.getName() + ";";
|
continue;
|
}
|
if(ToolUtil.isNotEmpty(companyCity.getCityCode())){
|
Region region = regionService.selectOne(new EntityWrapper<Region>().eq("code", companyCity.getCityCode()));
|
str += region.getName() + ";";
|
continue;
|
}
|
if(ToolUtil.isNotEmpty(companyCity.getProvinceCode())){
|
Region region = regionService.selectOne(new EntityWrapper<Region>().eq("code", companyCity.getProvinceCode()));
|
str += region.getName() + ";";
|
continue;
|
}
|
}
|
}else{
|
str = "全国;";
|
}
|
|
taxiCardWapper.setCityName(str.substring(0, str.length() - 1));
|
taxiCardWapper.setOriginalPrice(taxiCard.getOriginalPrice());
|
taxiCardWapper.setSellingPrice(taxiCard.getSellingPrice());
|
list.add(taxiCardWapper);
|
});
|
return ResultUtil.success(list);
|
}
|
|
@Override
|
public TaxiCardWapper getTaxiCardInfo(Integer id) throws Exception {
|
TaxiCard taxiCard = this.selectById(id);
|
JSONObject jsonObject = JSON.parseObject(taxiCard.getContent());
|
TaxiCardWapper taxiCardWapper = new TaxiCardWapper();
|
taxiCardWapper.setId(taxiCard.getId());
|
taxiCardWapper.setName(taxiCard.getName());
|
taxiCardWapper.setType(taxiCard.getType());
|
if(taxiCard.getType() == 1){
|
taxiCardWapper.setDiscounts(jsonObject.getDouble("discount"));
|
taxiCardWapper.setTime(jsonObject.getInteger("time"));
|
}
|
if(taxiCard.getType() == 2){
|
JSONArray fullReduction = jsonObject.getJSONArray("fullReduction");
|
JSONArray jsonArray = fullReduction.getJSONArray(fullReduction.size() - 1);
|
taxiCardWapper.setDiscounts(jsonArray.getDouble(1));
|
}
|
if(taxiCard.getType() == 3){
|
taxiCardWapper.setDiscounts(jsonObject.getDouble("discountAmount"));
|
taxiCardWapper.setTime(jsonObject.getInteger("time"));
|
}
|
if(taxiCard.getType() == 4 || taxiCard.getType() == 5){
|
taxiCardWapper.setDiscounts(jsonObject.getDouble("discount"));
|
}
|
if(taxiCard.getType() == 6){
|
JSONArray coupons = jsonObject.getJSONArray("coupons");
|
Integer num = 0;
|
List<CouponWarpper> couponWarppers = new ArrayList<>();
|
for(int i = 0; i < coupons.size(); i++){
|
JSONArray jsonArray = coupons.getJSONArray(i);
|
num += jsonArray.getInteger(0);
|
CouponRecord couponRecord = couponRecordService.selectById(jsonArray.getInteger(1));
|
CouponWarpper couponWarpper = new CouponWarpper();
|
couponWarpper.setId(couponRecord.getId());
|
couponWarpper.setMoney(couponRecord.getMoney());
|
couponWarpper.setUserType(couponRecord.getCouponUseType());
|
couponWarpper.setType(couponRecord.getCouponType());
|
couponWarpper.setFullMoney(couponRecord.getFullMoney());
|
couponWarpper.setName(companyService.selectById(couponRecord.getCompanyId()).getName());
|
couponWarpper.setCouponName(couponRecord.getName());
|
couponWarppers.add(couponWarpper);
|
}
|
taxiCardWapper.setCouponNum(num);
|
taxiCardWapper.setCouponList(couponWarppers);
|
}
|
String str = "";
|
if(taxiCard.getTaxiCardType() == 1){
|
String[] split = taxiCard.getCompanyCityId().split(";");
|
for(String c : split){
|
CompanyCity companyCity = companyCityService.selectById(c);
|
if(ToolUtil.isNotEmpty(companyCity.getAreaCode())){
|
Region region = regionService.selectOne(new EntityWrapper<Region>().eq("code", companyCity.getAreaCode()));
|
str += region.getName() + ";";
|
continue;
|
}
|
if(ToolUtil.isNotEmpty(companyCity.getCityCode())){
|
Region region = regionService.selectOne(new EntityWrapper<Region>().eq("code", companyCity.getCityCode()));
|
str += region.getName() + ";";
|
continue;
|
}
|
if(ToolUtil.isNotEmpty(companyCity.getProvinceCode())){
|
Region region = regionService.selectOne(new EntityWrapper<Region>().eq("code", companyCity.getProvinceCode()));
|
str += region.getName() + ";";
|
continue;
|
}
|
}
|
}else{
|
str = "全国;";
|
}
|
if(taxiCard.getType() < 5){
|
List<String> list = JSON.parseObject(taxiCard.getContent()).getJSONArray("timeQuantum").toJavaList(String.class);
|
taxiCardWapper.setTimeQuantum(list);
|
}
|
taxiCardWapper.setCityName(str.substring(0, str.length() - 1));
|
taxiCardWapper.setOriginalPrice(taxiCard.getOriginalPrice());
|
taxiCardWapper.setSellingPrice(taxiCard.getSellingPrice());
|
taxiCardWapper.setValidDate(taxiCard.getValidDate());
|
taxiCardWapper.setNote(taxiCard.getNote());
|
return taxiCardWapper;
|
}
|
|
@Override
|
public ResultUtil payTaxiCard(Integer uid, Integer id, Integer payType, Integer type) throws Exception {
|
UserInfo userInfo = userInfoService.selectById(uid);
|
TaxiCard taxiCard = this.selectById(id);
|
UserTaxiCard userTaxiCard1 = userTaxiCardService.selectOne(new EntityWrapper<UserTaxiCard>().eq("userId", uid).eq("taxiCardId", id)
|
.eq("companyId", taxiCard.getCompanyId()).where("now() between startTime and endTime"));
|
if(null != userTaxiCard1){
|
//打车卡类型1=打折次数卡,2=优惠卡,3=次数卡,4=打折天数卡,5=物流打折卡)
|
if(userTaxiCard1.getType() == 1){
|
JSONObject jsonObject = JSON.parseObject(userTaxiCard1.getContent());
|
Integer time = jsonObject.getInteger("time");
|
if(time > 0){
|
return ResultUtil.error("您已经购买了此打车卡,请先去使用吧!");
|
}
|
}
|
if(userTaxiCard1.getType() == 3){
|
JSONObject jsonObject = JSON.parseObject(userTaxiCard1.getContent());
|
Integer time = jsonObject.getInteger("time");
|
if(time > 0){
|
return ResultUtil.error("您已经购买了此打车卡,请先去使用吧!");
|
}
|
}
|
if(userTaxiCard1.getType() == 2 || userTaxiCard1.getType() == 4 || userTaxiCard1.getType() == 5){
|
return ResultUtil.error("您已经购买了此打车卡,请先去使用吧!");
|
}
|
}
|
TaxiCardPayment taxiCardPayment = new TaxiCardPayment();
|
taxiCardPayment.setUserId(uid);
|
taxiCardPayment.setTaxiCardId(id);
|
taxiCardPayment.setPayType(payType);
|
taxiCardPayment.setPayStatus(1);
|
taxiCardPayment.setCreateTime(new Date());
|
taxiCardPayment.setType(taxiCard.getType());
|
taxiCardPayment.setCompanyCityId(taxiCard.getCompanyCityId());
|
taxiCardPayment.setContent(taxiCard.getContent());
|
taxiCardPayment.setCompanyId(taxiCard.getCompanyId());
|
taxiCardPayment.setPayMoney(taxiCard.getSellingPrice());
|
taxiCardPaymentService.insert(taxiCardPayment);
|
|
ResultUtil resultUtil = ResultUtil.success();
|
if(payType == 1){//微信支付
|
String app = type == 1 ? "APP" : "JSAPI";
|
resultUtil = payMoneyUtil.weixinpay("购买出行卡", "", ToolUtil.getRandomString(10), taxiCard.getSellingPrice().toString(), "/base/wxPayTaxiCardPaymentSpread", app, userInfo.getAppletsOpenId());
|
paymentRecordService.saveData(4, taxiCardPayment.getUserId(), 1, taxiCardPayment.getId(), null, 1, taxiCard.getSellingPrice(), "", 1);//添加预支付数据
|
}
|
if(payType == 2){//支付宝支付
|
resultUtil = payMoneyUtil.alipay("购买出行卡", "购买出行卡", "", ToolUtil.getRandomString(10), taxiCard.getSellingPrice().toString(), "/base/aliPayTaxiCardPaymentSpread");
|
paymentRecordService.saveData(4, taxiCardPayment.getUserId(), 1, taxiCardPayment.getId(), null, 2, taxiCard.getSellingPrice(), "", 1);//添加预支付数据
|
}
|
if(payType == 3){//余额支付
|
if(userInfo.getBalance() == null || userInfo.getBalance() < taxiCard.getSellingPrice()){
|
return ResultUtil.error("余额不足,无法完成支付", "");
|
}
|
// resultUtil= appOrderController.moneyPay(taxiCardPayment.getId(),userInfo.getId(),taxiCard.getSellingPrice());
|
// if(resultUtil.getCode()==500){
|
// return ResultUtil.error("电子余额不足,无法完成支付");
|
// }
|
userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(taxiCard.getSellingPrice())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
//添加交易明细
|
transactionDetailsService.saveData(uid, "购买出行卡", taxiCard.getSellingPrice(), 2, 1, 1, 6, taxiCardPayment.getId());
|
userInfoService.updateById(userInfo);
|
|
taxiCardPayment.setPayStatus(2);//已支付
|
taxiCardPayment.setPayTime(new Date());
|
taxiCardPaymentService.updateById(taxiCardPayment);
|
|
|
//已购买没过期的增加有效期
|
UserTaxiCard userTaxiCard = userTaxiCardService.selectOne(new EntityWrapper<UserTaxiCard>().eq("userId", uid).eq("taxiCardId", taxiCardPayment.getTaxiCardId())
|
.eq("companyId", taxiCardPayment.getCompanyId()).where("now() between startTime and endTime"));
|
if(null != userTaxiCard){
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(userTaxiCard.getEndTime());
|
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + taxiCard.getValidDate());
|
userTaxiCard.setEndTime(calendar.getTime());
|
if(taxiCard.getType() == 1 || taxiCard.getType() == 3){//次数卡增加次数
|
JSONObject jsonObject = JSON.parseObject(userTaxiCard.getContent());
|
Integer time = jsonObject.getInteger("time");
|
Integer time1 = JSON.parseObject(taxiCard.getContent()).getInteger("time");
|
jsonObject.put("time", time + time1);
|
userTaxiCard.setContent(jsonObject.toJSONString());
|
}
|
userTaxiCardService.updateById(userTaxiCard);
|
}else{
|
userTaxiCard = new UserTaxiCard();
|
userTaxiCard.setUserId(uid);
|
userTaxiCard.setTaxiCardId(id);
|
userTaxiCard.setStartTime(new Date());
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(new Date());
|
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + taxiCard.getValidDate());
|
userTaxiCard.setEndTime(calendar.getTime());
|
userTaxiCard.setType(taxiCard.getType());
|
userTaxiCard.setCompanyCityId(taxiCard.getCompanyCityId());
|
userTaxiCard.setContent(taxiCard.getContent());
|
userTaxiCard.setCompanyId(taxiCard.getCompanyId());
|
userTaxiCardService.insert(userTaxiCard);
|
}
|
|
//单独处理优惠券数据
|
if(taxiCard.getType() == 6){
|
JSONArray coupons = JSON.parseObject(taxiCard.getContent()).getJSONArray("coupons");
|
for(int i = 0; i < coupons.size(); i++){
|
JSONArray jsonArray = coupons.getJSONArray(i);
|
Integer integer = jsonArray.getInteger(1);
|
Integer time = jsonArray.getInteger(0);
|
List<UserCouponRecord> list = userCouponRecordService.selectList(new EntityWrapper<UserCouponRecord>().eq("userId", uid).eq("couponId", integer)
|
.eq("activityType", 5).eq("state", 1).eq("couponActivityId", taxiCard.getId()).where("now() <= expirationTime"));
|
if(list.size() > 0 && time == list.size()){//历史有购买且都还没使用的情况
|
for (UserCouponRecord userCouponRecord : list) {
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(userCouponRecord.getExpirationTime());
|
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + taxiCard.getValidDate());
|
userCouponRecord.setExpirationTime(calendar.getTime());
|
}
|
userCouponRecordService.updateBatchById(list);
|
}else{//处理历史未购买或购买的使用了部分优惠券的情况
|
for (UserCouponRecord userCouponRecord : list) {
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(userCouponRecord.getExpirationTime());
|
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + taxiCard.getValidDate());
|
userCouponRecord.setExpirationTime(calendar.getTime());
|
userCouponRecordService.updateById(userCouponRecord);
|
}
|
CouponRecord couponRecord = couponRecordService.selectById(integer);
|
if(null != couponRecord){
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(new Date());
|
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + taxiCard.getValidDate());
|
for(int j = list.size(); j < time; j++){
|
UserCouponRecord userCouponRecord = new UserCouponRecord();
|
userCouponRecord.setMoney(couponRecord.getMoney());
|
userCouponRecord.setFullMoney(couponRecord.getFullMoney());
|
userCouponRecord.setExpirationTime(calendar.getTime());
|
userCouponRecord.setInsertTime(new Date());
|
userCouponRecord.setCompanyId(couponRecord.getCompanyId());
|
userCouponRecord.setState(1);
|
userCouponRecord.setCouponUseType(couponRecord.getCouponUseType());
|
userCouponRecord.setCouponType(couponRecord.getCouponType());
|
userCouponRecord.setUserId(uid);
|
userCouponRecord.setCouponId(couponRecord.getId());
|
userCouponRecord.setCouponActivityId(taxiCard.getId());//存储打车id
|
userCouponRecord.setActivityType(5);
|
userCouponRecord.setPaymentRecordId(null);
|
userCouponRecordService.insert(userCouponRecord);
|
}
|
}
|
}
|
}
|
}
|
|
|
//添加已收入明细
|
incomeService.saveData(1, taxiCardPayment.getCompanyId(), 5, taxiCardPayment.getId(), null, taxiCardPayment.getPayMoney());
|
systemNoticeService.addSystemNotice(1, "您已使用余额成功完成出行卡支付,谢谢使用!", uid, 1);
|
}
|
if(payType==4){
|
Integer integer = paymentRecordService.saveData(4, taxiCardPayment.getUserId(), 1, taxiCardPayment.getId(), null, 4, taxiCard.getSellingPrice(), "", 1);
|
resultUtil = appOrderController.placeAnOrder(new BigDecimal(taxiCard.getSellingPrice()), 4,taxiCardPayment.getId(),14,integer);
|
|
}
|
return resultUtil;
|
}
|
@Autowired
|
private AppOrderController appOrderController;
|
|
@Override
|
public void payTaxiCardPaymentSpread(Integer id, String order_id) throws Exception {
|
try {
|
TaxiCardPayment taxiCardPayment = taxiCardPaymentService.selectById(id);
|
//添加交易明细
|
transactionDetailsService.saveData(taxiCardPayment.getUserId(), "购买出行卡", taxiCardPayment.getPayMoney(), 2, 1, 1, 6, taxiCardPayment.getId());
|
taxiCardPayment.setPayStatus(2);//已支付
|
taxiCardPayment.setPayTime(new Date());
|
taxiCardPayment.setOrderNo(order_id);
|
taxiCardPaymentService.updateById(taxiCardPayment);
|
System.out.println("wxdck1");
|
|
PaymentRecord query = paymentRecordService.query(4, taxiCardPayment.getUserId(), 1, id, null, taxiCardPayment.getPayType(), 1);
|
query.setState(2);
|
query.setCode(order_id);
|
paymentRecordService.updateById(query);
|
System.out.println("wxdck2");
|
TaxiCard taxiCard = this.selectById(taxiCardPayment.getTaxiCardId());
|
|
//已购买没过期的增加有效期
|
UserTaxiCard userTaxiCard = userTaxiCardService.selectOne(new EntityWrapper<UserTaxiCard>().eq("userId", taxiCardPayment.getUserId()).eq("taxiCardId", taxiCardPayment.getTaxiCardId())
|
.eq("companyId", taxiCardPayment.getCompanyId()).where("now() between startTime and endTime"));
|
if(null != userTaxiCard){
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(userTaxiCard.getEndTime());
|
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + taxiCard.getValidDate());
|
userTaxiCard.setEndTime(calendar.getTime());
|
if(taxiCard.getType() == 1 || taxiCard.getType() == 3){//次数卡增加次数
|
JSONObject jsonObject = JSON.parseObject(userTaxiCard.getContent());
|
Integer time = jsonObject.getInteger("time");
|
Integer time1 = JSON.parseObject(taxiCard.getContent()).getInteger("time");
|
jsonObject.put("time", time + time1);
|
userTaxiCard.setContent(jsonObject.toJSONString());
|
}
|
userTaxiCardService.updateById(userTaxiCard);
|
}else{
|
userTaxiCard = new UserTaxiCard();
|
userTaxiCard.setUserId(taxiCardPayment.getUserId());
|
userTaxiCard.setTaxiCardId(taxiCardPayment.getTaxiCardId());
|
userTaxiCard.setStartTime(new Date());
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(new Date());
|
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + taxiCard.getValidDate());
|
userTaxiCard.setEndTime(calendar.getTime());
|
userTaxiCard.setType(taxiCard.getType());
|
userTaxiCard.setCompanyCityId(taxiCard.getCompanyCityId());
|
userTaxiCard.setContent(taxiCard.getContent());
|
userTaxiCard.setCompanyId(taxiCard.getCompanyId());
|
userTaxiCardService.insert(userTaxiCard);
|
}
|
|
//单独处理优惠券数据
|
if(taxiCard.getType() == 6){
|
JSONArray coupons = JSON.parseObject(taxiCard.getContent()).getJSONArray("coupons");
|
for(int i = 0; i < coupons.size(); i++){
|
JSONArray jsonArray = coupons.getJSONArray(i);
|
Integer integer = jsonArray.getInteger(1);
|
Integer time = jsonArray.getInteger(0);
|
List<UserCouponRecord> list = userCouponRecordService.selectList(new EntityWrapper<UserCouponRecord>().eq("userId", taxiCardPayment.getUserId()).eq("couponId", integer)
|
.eq("activityType", 5).eq("state", 1).eq("couponActivityId", taxiCard.getId()).where("now() <= expirationTime"));
|
if(list.size() > 0 && time == list.size()){//历史有购买且都还没使用的情况
|
for (UserCouponRecord userCouponRecord : list) {
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(userCouponRecord.getExpirationTime());
|
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + taxiCard.getValidDate());
|
userCouponRecord.setExpirationTime(calendar.getTime());
|
}
|
userCouponRecordService.updateBatchById(list);
|
}else{//处理历史未购买或购买的使用了部分优惠券的情况
|
for (UserCouponRecord userCouponRecord : list) {
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(userCouponRecord.getExpirationTime());
|
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + taxiCard.getValidDate());
|
userCouponRecord.setExpirationTime(calendar.getTime());
|
userCouponRecordService.updateById(userCouponRecord);
|
}
|
CouponRecord couponRecord = couponRecordService.selectById(integer);
|
if(null != couponRecord){
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(new Date());
|
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + taxiCard.getValidDate());
|
for(int j = list.size(); j < time; j++){
|
UserCouponRecord userCouponRecord = new UserCouponRecord();
|
userCouponRecord.setMoney(couponRecord.getMoney());
|
userCouponRecord.setFullMoney(couponRecord.getFullMoney());
|
userCouponRecord.setExpirationTime(calendar.getTime());
|
userCouponRecord.setInsertTime(new Date());
|
userCouponRecord.setCompanyId(couponRecord.getCompanyId());
|
userCouponRecord.setState(1);
|
userCouponRecord.setCouponUseType(couponRecord.getCouponUseType());
|
userCouponRecord.setCouponType(couponRecord.getCouponType());
|
userCouponRecord.setUserId(taxiCardPayment.getUserId());
|
userCouponRecord.setCouponId(couponRecord.getId());
|
userCouponRecord.setCouponActivityId(taxiCard.getId());//存储打车id
|
userCouponRecord.setActivityType(5);
|
userCouponRecord.setPaymentRecordId(null);
|
userCouponRecordService.insert(userCouponRecord);
|
}
|
}
|
}
|
}
|
}
|
|
//添加已收入明细
|
incomeService.saveData(1, taxiCardPayment.getCompanyId(), 5, taxiCardPayment.getId(), null, taxiCardPayment.getPayMoney());
|
systemNoticeService.addSystemNotice(1, "您已使用" + (taxiCardPayment.getPayType() == 1 ? "微信" : (taxiCardPayment.getPayType()==2?"支付宝":"云闪付")) + "成功完成出行卡支付,谢谢使用!", taxiCardPayment.getUserId(), 1);
|
System.out.println("wxdck okok");
|
}catch (Exception e){
|
System.out.println(e);
|
|
}
|
}
|
|
@Override
|
public List<TaxiCardWapper> getMyTaxiCardList(Integer uid, Integer orderType) throws Exception {
|
List<UserTaxiCard> userTaxiCards = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().eq("userId", uid).where("endTime >= now()"));
|
|
//亲密账户
|
List<UserUser> bindUserId = userUserService.selectList(new EntityWrapper<UserUser>().eq("bindUserId", uid));
|
bindUserId.forEach(userUser -> {
|
List<UserTaxiCard> userTaxiCards1 = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().eq("userId", userUser.getUserId()).where("endTime >= now()"));
|
userTaxiCards.addAll(userTaxiCards1);
|
});
|
|
List<TaxiCardWapper> list = new ArrayList<>();
|
userTaxiCards.forEach(userTaxiCard -> {
|
JSONObject jsonObject = JSON.parseObject(userTaxiCard.getContent());
|
TaxiCard taxiCard1 = this.selectById(userTaxiCard.getTaxiCardId());
|
JSONObject jsonObject1 = JSON.parseObject(taxiCard1.getContent());
|
if(userTaxiCard.getType() != 6){
|
List<Integer> integers = jsonObject.getJSONArray("businessTypes").toJavaList(Integer.class);
|
if(!integers.contains(orderType)){
|
return;
|
}
|
}
|
TaxiCard taxiCard = this.selectById(userTaxiCard.getTaxiCardId());
|
TaxiCardWapper taxiCardWapper = new TaxiCardWapper();
|
taxiCardWapper.setId(userTaxiCard.getId());
|
taxiCardWapper.setName(taxiCard.getName());
|
taxiCardWapper.setType(userTaxiCard.getType());
|
if(userTaxiCard.getType() == 1){
|
taxiCardWapper.setDiscounts(jsonObject.getDouble("discount"));
|
Integer time = jsonObject.getInteger("time");
|
if(0 == time){
|
return;
|
}
|
taxiCardWapper.setTime(jsonObject1.getInteger("time"));
|
taxiCardWapper.setLastTime(time);
|
}
|
if(userTaxiCard.getType() == 2){
|
JSONArray fullReduction = jsonObject.getJSONArray("fullReduction");
|
JSONArray jsonArray = fullReduction.getJSONArray(fullReduction.size() - 1);
|
taxiCardWapper.setDiscounts(jsonArray.getDouble(1));
|
}
|
if(userTaxiCard.getType() == 3){
|
taxiCardWapper.setDiscounts(jsonObject.getDouble("discountAmount"));
|
Integer time = jsonObject.getInteger("time");
|
if(0 == time){
|
return;
|
}
|
taxiCardWapper.setTime(jsonObject1.getInteger("time"));
|
taxiCardWapper.setLastTime(time);
|
}
|
if(userTaxiCard.getType() == 4 || userTaxiCard.getType() == 5){
|
taxiCardWapper.setDiscounts(jsonObject.getDouble("discount"));
|
}
|
if(userTaxiCard.getType() == 6){
|
boolean b = true;
|
JSONArray coupons = jsonObject.getJSONArray("coupons");
|
Integer num = 0;
|
for(int i = 0; i < coupons.size(); i++){
|
num += coupons.getJSONArray(i).getInteger(0);
|
Integer couponsId = coupons.getJSONArray(i).getInteger(1);
|
CouponRecord couponRecord = couponRecordService.selectById(couponsId);
|
if(null != couponRecord && (couponRecord.getCouponUseType() == 0 || couponRecord.getCouponUseType().compareTo(orderType) == 0)){
|
b = false;
|
}
|
}
|
if(b){
|
return;
|
}
|
taxiCardWapper.setCouponNum(num);
|
}
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
taxiCardWapper.setEndTime(sdf.format(userTaxiCard.getEndTime()));
|
String str = "";
|
if(taxiCard.getTaxiCardType() == 1){
|
String[] split = taxiCard.getCompanyCityId().split(";");
|
for(String c : split){
|
CompanyCity companyCity = companyCityService.selectById(c);
|
if(ToolUtil.isNotEmpty(companyCity.getAreaCode())){
|
Region region = regionService.selectOne(new EntityWrapper<Region>().eq("code", companyCity.getAreaCode()));
|
str += region.getName() + ";";
|
continue;
|
}
|
if(ToolUtil.isNotEmpty(companyCity.getCityCode())){
|
Region region = regionService.selectOne(new EntityWrapper<Region>().eq("code", companyCity.getCityCode()));
|
str += region.getName() + ";";
|
continue;
|
}
|
if(ToolUtil.isNotEmpty(companyCity.getProvinceCode())){
|
Region region = regionService.selectOne(new EntityWrapper<Region>().eq("code", companyCity.getProvinceCode()));
|
str += region.getName() + ";";
|
continue;
|
}
|
}
|
}else{
|
str = "全国;";
|
}
|
taxiCardWapper.setCityName(str.substring(0, str.length() - 1));
|
if(taxiCard.getType() < 6){
|
List<Integer> integers = JSON.parseObject(taxiCard.getContent()).getJSONArray("businessTypes").toJavaList(Integer.class);
|
taxiCardWapper.setBusinessTypes(integers);
|
}
|
list.add(taxiCardWapper);
|
});
|
|
return list;
|
}
|
|
public static void main(String[] args) {
|
JSONObject jsonObject = JSON.parseObject("{\"businessTypes\":[1,2,3],\"timeQuantum\":[\"00:00:00 - 23:00:00\"],\"fullReduction\":[[2,1]]}");
|
|
System.out.println(jsonObject);
|
}
|
|
@Override
|
public TaxiCardWapper getMyTaxiCardInfo(Integer id) throws Exception {
|
UserTaxiCard userTaxiCard = userTaxiCardService.selectById(id);
|
TaxiCard taxiCard = this.selectById(userTaxiCard.getTaxiCardId());
|
JSONObject jsonObject = JSON.parseObject(userTaxiCard.getContent());
|
TaxiCardWapper taxiCardWapper = new TaxiCardWapper();
|
taxiCardWapper.setId(userTaxiCard.getTaxiCardId());
|
taxiCardWapper.setName(taxiCard.getName());
|
taxiCardWapper.setType(userTaxiCard.getType());
|
if(userTaxiCard.getType() == 1){
|
taxiCardWapper.setDiscounts(jsonObject.getDouble("discount"));
|
Integer time = jsonObject.getInteger("time");
|
taxiCardWapper.setTime(time);
|
taxiCardWapper.setLastTime(time);
|
}
|
if(userTaxiCard.getType() == 2){
|
JSONArray fullReduction = jsonObject.getJSONArray("fullReduction");
|
JSONArray jsonArray = fullReduction.getJSONArray(fullReduction.size() - 1);
|
taxiCardWapper.setDiscounts(jsonArray.getDouble(1));
|
}
|
if(userTaxiCard.getType() == 3){
|
taxiCardWapper.setDiscounts(jsonObject.getDouble("discountAmount"));
|
Integer time = jsonObject.getInteger("time");
|
taxiCardWapper.setTime(time);
|
taxiCardWapper.setLastTime(time);
|
}
|
if(userTaxiCard.getType() == 4 || userTaxiCard.getType() == 5){
|
taxiCardWapper.setDiscounts(jsonObject.getDouble("discount"));
|
}
|
if(userTaxiCard.getType() == 6){
|
JSONArray coupons = jsonObject.getJSONArray("coupons");
|
Integer num = 0;
|
for(int i = 0; i < coupons.size(); i++){
|
num += coupons.getJSONArray(i).getInteger(0);
|
}
|
taxiCardWapper.setCouponNum(num);
|
|
List<CouponWarpper> couponWarppers = new ArrayList<>();
|
for(int i = 0; i < coupons.size(); i++){
|
JSONArray jsonArray = coupons.getJSONArray(i);
|
num += jsonArray.getInteger(0);
|
CouponRecord couponRecord = couponRecordService.selectById(jsonArray.getInteger(1));
|
CouponWarpper couponWarpper = new CouponWarpper();
|
couponWarpper.setId(couponRecord.getId());
|
couponWarpper.setMoney(couponRecord.getMoney());
|
couponWarpper.setUserType(couponRecord.getCouponUseType());
|
couponWarpper.setType(couponRecord.getCouponType());
|
couponWarpper.setFullMoney(couponRecord.getFullMoney());
|
couponWarpper.setName(companyService.selectById(couponRecord.getCompanyId()).getName());
|
couponWarpper.setCouponName(couponRecord.getName());
|
couponWarppers.add(couponWarpper);
|
}
|
taxiCardWapper.setCouponList(couponWarppers);
|
}
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
taxiCardWapper.setEndTime(sdf.format(userTaxiCard.getEndTime()));
|
String str = "";
|
if(taxiCard.getTaxiCardType() == 1){
|
String[] split = taxiCard.getCompanyCityId().split(";");
|
for(String c : split){
|
CompanyCity companyCity = companyCityService.selectById(c);
|
if(ToolUtil.isNotEmpty(companyCity.getAreaCode())){
|
Region region = regionService.selectOne(new EntityWrapper<Region>().eq("code", companyCity.getAreaCode()));
|
str += region.getName() + ";";
|
continue;
|
}
|
if(ToolUtil.isNotEmpty(companyCity.getCityCode())){
|
Region region = regionService.selectOne(new EntityWrapper<Region>().eq("code", companyCity.getCityCode()));
|
str += region.getName() + ";";
|
continue;
|
}
|
if(ToolUtil.isNotEmpty(companyCity.getProvinceCode())){
|
Region region = regionService.selectOne(new EntityWrapper<Region>().eq("code", companyCity.getProvinceCode()));
|
str += region.getName() + ";";
|
continue;
|
}
|
}
|
}else{
|
str = "全国;";
|
}
|
if(taxiCard.getType() < 5){
|
List<String> list = JSON.parseObject(taxiCard.getContent()).getJSONArray("timeQuantum").toJavaList(String.class);
|
taxiCardWapper.setTimeQuantum(list);
|
}
|
taxiCardWapper.setCityName(str.substring(0, str.length() - 1));
|
taxiCardWapper.setNote(taxiCard.getNote());
|
return taxiCardWapper;
|
}
|
}
|