修复退款失败的问题

修复商品选择优惠券可能出错的问题
This commit is contained in:
stivepeim
2021-01-11 16:22:39 +08:00
parent 590fec398e
commit 89fbecbcee
4 changed files with 202 additions and 215 deletions

View File

@@ -91,178 +91,178 @@
</template> </template>
<script> <script>
import { marketingListApi, couponUserApi } from '@/api/marketing' import { marketingListApi, couponUserApi } from '@/api/marketing'
export default { export default {
name: 'CouponList', name: 'CouponList',
props: { props: {
handle: { handle: {
type: String, type: String,
default: '' default: ''
},
couponData: {
type: Array,
default: () => []
},
keyNum: {
type: Number,
default: 0
},
userIds: {
type: String,
default: ''
}
},
data() {
return {
listLoading: true,
tableData: {
data: [],
total: 0
}, },
tableFrom: { couponData: {
page: 1, type: Array,
limit: 10, default: () => []
name: '',
// type: 0,
isDel: 0,
status: 1
}, },
multipleSelection: [], keyNum: {
multipleSelectionAll: [], type: Number,
idKey: 'id', default: 0
nextPageFlag: false, },
attr: [] userIds: {
} type: String,
}, default: ''
watch: {
keyNum: {
deep: true,
handler(val) {
this.getList()
} }
}
},
mounted() {
this.tableFrom.page = 1
this.getList()
this.multipleSelectionAll = this.couponData
},
methods: {
close() {
this.multipleSelection = []
}, },
handleSelectionChange(val) { data() {
this.multipleSelection = val return {
setTimeout(() => { listLoading: true,
this.changePageCoreRecordData() tableData: {
}, 50) data: [],
}, total: 0
// 设置选中的方法 },
setSelectRow() { tableFrom: {
if (!this.multipleSelectionAll || this.multipleSelectionAll.length <= 0) { page: 1,
return limit: 10,
name: '',
// type: 0,
isDel: 0,
status: 1
},
multipleSelection: [],
multipleSelectionAll: [],
idKey: 'id',
nextPageFlag: false,
attr: []
} }
// 标识当前行的唯一键的名称 },
const idKey = this.idKey watch: {
const selectAllIds = [] keyNum: {
this.multipleSelectionAll.forEach(row => { deep: true,
selectAllIds.push(row[idKey]) handler(val) {
}) this.getList()
this.$refs.table.clearSelection()
for (var i = 0; i < this.tableData.data.length; i++) {
if (selectAllIds.indexOf(this.tableData.data[i][idKey]) >= 0) {
// 设置选中记住table组件需要使用ref="table"
this.$refs.table.toggleRowSelection(this.tableData.data[i], true)
} }
} }
}, },
// 记忆选择核心方法 mounted() {
changePageCoreRecordData() { this.tableFrom.page = 1
// 标识当前行的唯一键的名称 this.getList()
const idKey = this.idKey this.multipleSelectionAll = this.couponData || []
const that = this },
// 如果总记忆中还没有选择的数据,那么就直接取当前页选中的数据,不需要后面一系列计算 methods: {
if (this.multipleSelectionAll.length <= 0) { close() {
this.multipleSelectionAll = this.multipleSelection this.multipleSelection = []
return },
} handleSelectionChange(val) {
// 总选择里面的key集合 this.multipleSelection = val
const selectAllIds = [] setTimeout(() => {
this.multipleSelectionAll.forEach(row => { this.changePageCoreRecordData()
selectAllIds.push(row[idKey]) }, 50)
}) },
const selectIds = [] // 设置选中的方法
// 获取当前页选中的id setSelectRow() {
this.multipleSelection.forEach(row => { if (!this.multipleSelectionAll || this.multipleSelectionAll.length <= 0) {
selectIds.push(row[idKey]) return
// 如果总选择里面不包含当前页选中的数据,那么就加入到总选择集合里
if (selectAllIds.indexOf(row[idKey]) < 0) {
that.multipleSelectionAll.push(row)
} }
}) // 标识当前行的唯一键的名称
const noSelectIds = [] const idKey = this.idKey
// 得到当前页没有选中的id const selectAllIds = []
this.tableData.data.forEach(row => { this.multipleSelectionAll.forEach(row => {
if (selectIds.indexOf(row[idKey]) < 0) { selectAllIds.push(row[idKey])
noSelectIds.push(row[idKey]) })
} this.$refs.table.clearSelection()
}) for (var i = 0; i < this.tableData.data.length; i++) {
noSelectIds.forEach(id => { if (selectAllIds.indexOf(this.tableData.data[i][idKey]) >= 0) {
if (selectAllIds.indexOf(id) >= 0) { // 设置选中记住table组件需要使用ref="table"
for (let i = 0; i < that.multipleSelectionAll.length; i++) { this.$refs.table.toggleRowSelection(this.tableData.data[i], true)
if (that.multipleSelectionAll[i][idKey] == id) {
// 如果总选择中有未被选中的,那么就删除这条
that.multipleSelectionAll.splice(i, 1)
break
}
} }
} }
}) },
}, // 记忆选择核心方法
ok() { changePageCoreRecordData() {
if (this.multipleSelection.length > 0) { // 标识当前行的唯一键的名称
this.$emit('getCouponId', this.multipleSelectionAll) const idKey = this.idKey
// this.close() const that = this
} else { // 如果总记忆中还没有选择的数据,那么就直接取当前页选中的数据,不需要后面一系列计算
this.$message.warning('请先选择优惠劵') if (this.multipleSelectionAll.length <= 0) {
this.multipleSelectionAll = this.multipleSelection
return
}
// 总选择里面的key集合
const selectAllIds = []
this.multipleSelectionAll.forEach(row => {
selectAllIds.push(row[idKey])
})
const selectIds = []
// 获取当前页选中的id
this.multipleSelection.forEach(row => {
selectIds.push(row[idKey])
// 如果总选择里面不包含当前页选中的数据,那么就加入到总选择集合里
if (selectAllIds.indexOf(row[idKey]) < 0) {
that.multipleSelectionAll.push(row)
}
})
const noSelectIds = []
// 得到当前页没有选中的id
this.tableData.data.forEach(row => {
if (selectIds.indexOf(row[idKey]) < 0) {
noSelectIds.push(row[idKey])
}
})
noSelectIds.forEach(id => {
if (selectAllIds.indexOf(id) >= 0) {
for (let i = 0; i < that.multipleSelectionAll.length; i++) {
if (that.multipleSelectionAll[i][idKey] == id) {
// 如果总选择中有未被选中的,那么就删除这条
that.multipleSelectionAll.splice(i, 1)
break
}
}
}
})
},
ok() {
if (this.multipleSelection.length > 0) {
this.$emit('getCouponId', this.multipleSelectionAll)
// this.close()
} else {
this.$message.warning('请先选择优惠劵')
}
},
// 列表
getList(num) {
this.listLoading = true
this.tableFrom.page = num ? num : this.tableFrom.page
marketingListApi(this.tableFrom).then(res => {
this.tableData.data = res.list
this.tableData.total = res.total
this.listLoading = false
this.$nextTick(function() {
this.setSelectRow()// 调用跨页选中方法
})
}).catch(res => {
this.listLoading = false
})
},
pageChange(page) {
this.changePageCoreRecordData()
this.tableFrom.page = page
this.getList()
},
handleSizeChange(val) {
this.changePageCoreRecordData()
this.tableFrom.limit = val
this.getList()
},
// 发送
sendGrant(id){
this.$modalSure('发送优惠劵吗').then(() => {
couponUserApi({ couponId:id, uid:this.userIds }).then(() => {
this.$message.success('发送成功')
this.getList()
})
})
} }
},
// 列表
getList(num) {
this.listLoading = true
this.tableFrom.page = num ? num : this.tableFrom.page
marketingListApi(this.tableFrom).then(res => {
this.tableData.data = res.list
this.tableData.total = res.total
this.listLoading = false
this.$nextTick(function() {
this.setSelectRow()// 调用跨页选中方法
})
}).catch(res => {
this.listLoading = false
})
},
pageChange(page) {
this.changePageCoreRecordData()
this.tableFrom.page = page
this.getList()
},
handleSizeChange(val) {
this.changePageCoreRecordData()
this.tableFrom.limit = val
this.getList()
},
// 发送
sendGrant(id){
this.$modalSure('发送优惠劵吗').then(() => {
couponUserApi({ couponId:id, uid:this.userIds }).then(() => {
this.$message.success('发送成功')
this.getList()
})
})
} }
} }
}
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">

View File

@@ -573,6 +573,7 @@
handleCloseCoupon(tag) { handleCloseCoupon(tag) {
this.isAttr = true this.isAttr = true
this.formValidate.coupons.splice(this.formValidate.coupons.indexOf(tag), 1) this.formValidate.coupons.splice(this.formValidate.coupons.indexOf(tag), 1)
this.formValidate.couponIds.splice(this.formValidate.couponIds.indexOf(tag.id), 1)
}, },
addCoupon() { addCoupon() {
const _this = this const _this = this
@@ -894,6 +895,7 @@
giveIntegral: info.giveIntegral, giveIntegral: info.giveIntegral,
ficti: info.ficti, ficti: info.ficti,
coupons: info.coupons, coupons: info.coupons,
couponIds: info.couponIds,
activity: info.activityStr ? info.activityStr.split(',') : ['默认','秒杀','砍价','拼团'] activity: info.activityStr ? info.activityStr.split(',') : ['默认','秒杀','砍价','拼团']
} }
if(info.isHot) this.checkboxGroup.push('isHot') if(info.isHot) this.checkboxGroup.push('isHot')

View File

@@ -38,8 +38,8 @@ public class StoreOrderRefundRequest {
@DecimalMin(value = "0.00", message = "退款金额不能少于0.00") @DecimalMin(value = "0.00", message = "退款金额不能少于0.00")
private BigDecimal amount; private BigDecimal amount;
@ApiModelProperty(value = "status 1 = 直接退款, 2 = 退款后,返回原状态", allowableValues = "range[1,2]") // @ApiModelProperty(value = "status 1 = 直接退款, 2 = 退款后,返回原状态", allowableValues = "range[1,2]")
@Range(min = 1, max = 2, message = "请选择退款状态 1 = 直接退款, 2 = 退款后,返回原状态") // @Range(min = 1, max = 2, message = "请选择退款状态 1 = 直接退款, 2 = 退款后,返回原状态")
private int type; // private int type;
} }

View File

@@ -760,18 +760,19 @@ public class StoreOrderServiceImpl extends ServiceImpl<StoreOrderDao, StoreOrder
/** 退款 /** 退款
* @param request StoreOrderRefundRequest 退款参数 * @param request StoreOrderRefundRequest 退款参数
* @author Mr.Zhang
* @since 2020-06-10
* @return boolean * @return boolean
* 这里只处理订单状态
* 余额支付需要把余额给用户加回去
* 其余处理放入redis中处理
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class)
public boolean refund(StoreOrderRefundRequest request) { public boolean refund(StoreOrderRefundRequest request) {
StoreOrder storeOrder = getById(request.getOrderId()); StoreOrder storeOrder = getById(request.getOrderId());
if(null == storeOrder){throw new CrmebException("未查到订单");} if(ObjectUtil.isNull(storeOrder)){throw new CrmebException("未查到订单");}
if(!storeOrder.getPaid()){throw new CrmebException("未支付无法退款");} if(!storeOrder.getPaid()){throw new CrmebException("未支付无法退款");}
if(storeOrder.getRefundPrice().add(request.getAmount()).compareTo(storeOrder.getPayPrice()) > 0){throw new CrmebException("退款金额大于支付金额,请修改退款金额");} if(storeOrder.getRefundPrice().add(request.getAmount()).compareTo(storeOrder.getPayPrice()) > 0) {
throw new CrmebException("退款金额大于支付金额,请修改退款金额");
}
//用户 //用户
User user = userService.getById(storeOrder.getUid()); User user = userService.getById(storeOrder.getUid());
@@ -785,61 +786,45 @@ public class StoreOrderServiceImpl extends ServiceImpl<StoreOrderDao, StoreOrder
throw new CrmebException("微信申请退款失败!"); throw new CrmebException("微信申请退款失败!");
} }
} }
if (storeOrder.getPayType().equals(Constants.PAY_TYPE_YUE)) {
UserOperateFundsRequest userOperateFundsRequest = new UserOperateFundsRequest();
userOperateFundsRequest.setUid(storeOrder.getUid());
userOperateFundsRequest.setValue(request.getAmount());
userOperateFundsRequest.setFoundsCategory(Constants.USER_BILL_CATEGORY_MONEY);
userOperateFundsRequest.setFoundsType(Constants.ORDER_STATUS_REFUNDED);
userOperateFundsRequest.setType(1);
userOperateFundsRequest.setTitle(Constants.ORDER_STATUS_STR_REFUNDED);
boolean addMoney = userService.updateFounds(userOperateFundsRequest, false); //更新余额
if(!addMoney){throw new CrmebException("余额退款失败");}
//新增日志
boolean addBill = userBillService.saveRefundBill(request, user);
if(!addBill){throw new CrmebException("余额退款失败");}
}
//修改订单退款状态 //修改订单退款状态
if(request.getType() == 1){ storeOrder.setRefundStatus(3);
storeOrder.setRefundStatus(2);
}else if(request.getType() == 2){
storeOrder.setRefundStatus(0);
}else{
throw new CrmebException("选择退款状态错误");
}
storeOrder.setRefundPrice(request.getAmount()); storeOrder.setRefundPrice(request.getAmount());
boolean updateOrder = updateById(storeOrder);
if(!updateOrder){ Boolean execute = transactionTemplate.execute(e -> {
updateById(storeOrder);
if (storeOrder.getPayType().equals(Constants.PAY_TYPE_YUE)) {
// 更新用户金额 TODO 后期要调整
UserOperateFundsRequest userOperateFundsRequest = new UserOperateFundsRequest();
userOperateFundsRequest.setUid(storeOrder.getUid());
userOperateFundsRequest.setValue(request.getAmount());
userOperateFundsRequest.setFoundsCategory(Constants.USER_BILL_CATEGORY_MONEY);
userOperateFundsRequest.setFoundsType(Constants.ORDER_STATUS_REFUNDED);
userOperateFundsRequest.setType(1);
userOperateFundsRequest.setTitle(Constants.ORDER_STATUS_STR_REFUNDED);
userService.updateFounds(userOperateFundsRequest, false); //更新余额
//新增日志
userBillService.saveRefundBill(request, user);
// 退款task
redisUtil.lPush(Constants.ORDER_TASK_REDIS_KEY_AFTER_REFUND_BY_USER, storeOrder.getId());
}
return Boolean.TRUE;
});
if(!execute){
storeOrderStatusService.saveRefund(request.getOrderId(), request.getAmount(), "失败"); storeOrderStatusService.saveRefund(request.getOrderId(), request.getAmount(), "失败");
throw new CrmebException("订单更新失败"); throw new CrmebException("订单更新失败");
} }
//退款成功 // // 小程序订阅消息 退款成功
storeOrderStatusService.saveRefund(request.getOrderId(), request.getAmount(), null); // String storeNameAndCarNumString = orderUtils.getStoreNameAndCarNumString(storeOrder.getId());
// WechatSendMessageForReFundEd forReFundEd = new WechatSendMessageForReFundEd(
// "退款成功",storeNameAndCarNumString,request.getAmount()+"",DateUtil.nowDateTimeStr(),"退款金额已到余额中",
// storeOrder.getOrderId(),storeOrder.getId()+"",storeOrder.getCreateTime()+"",storeOrder.getRefundPrice()+"",
// storeNameAndCarNumString,storeOrder.getRefundReason(),"CRMEB",storeOrder.getRefundReasonWapExplain(),
// "暂无"
// );
// wechatSendMessageForMinService.sendReFundEdMessage(forReFundEd, userService.getUserIdException());
//佣金 return execute;
subtractBill(request, Constants.USER_BILL_CATEGORY_MONEY,
Constants.USER_BILL_TYPE_BROKERAGE, Constants.USER_BILL_CATEGORY_BROKERAGE_PRICE);
//积分
subtractBill(request, Constants.USER_BILL_CATEGORY_INTEGRAL,
Constants.USER_BILL_TYPE_GAIN, Constants.USER_BILL_CATEGORY_INTEGRAL);
// 回滚库存 后续操作放入redis
redisUtil.lPush(Constants.ORDER_TASK_REDIS_KEY_AFTER_REFUND_BY_USER, storeOrder.getId());
// 小程序订阅消息 退款成功
String storeNameAndCarNumString = orderUtils.getStoreNameAndCarNumString(storeOrder.getId());
WechatSendMessageForReFundEd forReFundEd = new WechatSendMessageForReFundEd(
"退款成功",storeNameAndCarNumString,request.getAmount()+"",DateUtil.nowDateTimeStr(),"退款金额已到余额中",
storeOrder.getOrderId(),storeOrder.getId()+"",storeOrder.getCreateTime()+"",storeOrder.getRefundPrice()+"",
storeNameAndCarNumString,storeOrder.getRefundReason(),"CRMEB",storeOrder.getRefundReasonWapExplain(),
"暂无"
);
wechatSendMessageForMinService.sendReFundEdMessage(forReFundEd, userService.getUserIdException());
return true;
} }
/** 订单详情 /** 订单详情