| | |
| | | import com.dsh.account.mapper.CoachMapper; |
| | | import com.dsh.account.mapper.TAppUserMapper; |
| | | import com.dsh.account.mapper.TStudentMapper; |
| | | import com.dsh.account.model.vo.classDetails.AppointmentRecordVo; |
| | | import com.dsh.account.model.vo.classDetails.ClasspaymentRequest; |
| | | import com.dsh.account.model.vo.classDetails.classInsVo.ClassDetailsInsVo; |
| | | import com.dsh.account.model.vo.classDetails.classInsVo.StuDetailsReq; |
| | |
| | | import com.dsh.account.model.vo.sourceDetail.CourseDetailsOfContinuationResp; |
| | | import com.dsh.account.model.vo.sourceDetail.RecordTimeRequest; |
| | | import com.dsh.account.service.TStudentService; |
| | | import com.dsh.account.util.DateTimeHelper; |
| | | import com.dsh.account.util.DateUtil; |
| | | import com.dsh.account.util.ResultUtil; |
| | | import com.dsh.account.util.ToolUtil; |
| | | import com.dsh.account.util.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | private ParticipantClient participantClient; |
| | | |
| | | |
| | | @Autowired |
| | | private PayMoneyUtil payMoneyUtil; |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public void addStuOfAppUser(StuDetailsReq stu,Integer appUserId) { |
| | | public ResultUtil addStuOfAppUser(StuDetailsReq stu,Integer appUserId) throws Exception { |
| | | TStudent student = new TStudent(); |
| | | if(ToolUtil.isNotEmpty(stu.getName()) && ToolUtil.isNotEmpty(stu.getIdCard())){ |
| | | Boolean aBoolean = JuHeUtil.idcardAuthentication(stu.getIdCard(), stu.getName()); |
| | | if(!aBoolean){ |
| | | return ResultUtil.error("身份证和姓名不匹配"); |
| | | } |
| | | } |
| | | student.setAppUserId(appUserId); |
| | | student.setName(stu.getName()); |
| | | student.setHeadImg(stu.getHeadImg()); |
| | |
| | | saveParticipant.setPhone(student.getPhone()); |
| | | saveParticipant.setIdcard(student.getIdCard()); |
| | | participantClient.saveParticipant(saveParticipant); |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public ResultUtil renewClassPayment(Integer userIdFormRedis, ClasspaymentRequest request) { |
| | | // TODO: 2023/7/5 |
| | | switch (request.getPayType()){ |
| | | case 1: |
| | | WeChatPayment(); |
| | | break; |
| | | case 2: |
| | | AlipayPayment(); |
| | | break; |
| | | case 3: |
| | | PlaypaiGoldPayment(); |
| | | break; |
| | | default: |
| | | break; |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5); |
| | | |
| | | TCoursePackagePayment packagePayment = new TCoursePackagePayment(); |
| | | packagePayment.setCode(code); |
| | | packagePayment.setAppUserId(userIdFormRedis); |
| | | packagePayment.setStudentId(request.getStuId()); |
| | | packagePayment.setCoursePackageId(request.getLessonId()); |
| | | packagePayment.setPayType(request.getPayType()); |
| | | packagePayment.setAbsencesNumber(0); |
| | | packagePayment.setPayUserType(1); |
| | | packagePayment.setPayStatus(1); |
| | | packagePayment.setPayUserId(userIdFormRedis); |
| | | packagePayment.setStatus(1); |
| | | packagePayment.setState(1); |
| | | packagePayment.setInsertTime(new Date()); |
| | | couPayClient.savePaymentCoursePackage(packagePayment); |
| | | |
| | | try { |
| | | switch (request.getPayType()) { |
| | | case 1: |
| | | return WeChatPayment(code,request.getPayAmount()); |
| | | case 2: |
| | | return AlipayPayment(code,request.getPayAmount()); |
| | | case 3: |
| | | int i = PlaypaiGoldPayment(code,request); |
| | | switch (i){ |
| | | case 1: |
| | | return ResultUtil.success(); |
| | | case 2: |
| | | return ResultUtil.error("用户未登录!"); |
| | | case 3: |
| | | return ResultUtil.error("续课失败,玩湃币不足,请充值"); |
| | | case 4: |
| | | return ResultUtil.error("续课失败,请联系管理员"); |
| | | } |
| | | default: |
| | | break; |
| | | } |
| | | }catch (Exception e){ |
| | | ResultUtil.runErr(); |
| | | } |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | |
| | | public void WeChatPayment(){ |
| | | |
| | | public ResultUtil WeChatPayment(String code,BigDecimal amount) throws Exception { |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay("课包续费", "", code, amount.toString(), |
| | | "/base/coursePackage/wechatPaymentCallback", "APP", ""); |
| | | if(weixinpay.getCode() == 200){ |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | int num = 1; |
| | | int wait = 0; |
| | | while (num <= 10){ |
| | | int min = 5000; |
| | | wait += (min * num); |
| | | Thread.sleep(wait); |
| | | TCoursePackagePayment coursePackagePayment = couPayClient.getCoursePackagePaymentByCode(code); |
| | | if(coursePackagePayment.getPayStatus() == 2){ |
| | | break; |
| | | } |
| | | ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(code, ""); |
| | | if(resultUtil.getCode() == 200 && coursePackagePayment.getPayStatus() == 1){ |
| | | /** |
| | | * SUCCESS—支付成功, |
| | | * REFUND—转入退款, |
| | | * NOTPAY—未支付, |
| | | * CLOSED—已关闭, |
| | | * REVOKED—已撤销(刷卡支付), |
| | | * USERPAYING--用户支付中, |
| | | * PAYERROR--支付失败(其他原因,如银行返回失败) |
| | | */ |
| | | Map<String, String> data1 = resultUtil.getData(); |
| | | String s = data1.get("trade_state"); |
| | | String transaction_id = data1.get("transaction_id"); |
| | | if("REFUND".equals(s) || "NOTPAY".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s) || num == 10){ |
| | | coursePackagePayment.setState(3); |
| | | couPayClient.delPaymentCoursePackage(coursePackagePayment.getId()); |
| | | break; |
| | | } |
| | | if("SUCCESS".equals(s)){ |
| | | coursePackagePayment.setPayStatus(2); |
| | | coursePackagePayment.setOrderNumber(transaction_id); |
| | | couPayClient.updatePaymentCoursePackage(coursePackagePayment); |
| | | break; |
| | | } |
| | | if("USERPAYING".equals(s)){ |
| | | num++; |
| | | } |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }).start(); |
| | | } |
| | | return weixinpay; |
| | | } |
| | | |
| | | public void AlipayPayment(){ |
| | | |
| | | public ResultUtil AlipayPayment(String code,BigDecimal amount){ |
| | | ResultUtil alipay = payMoneyUtil.alipay("课包续费", "", "", code, amount.toString(), |
| | | "/base/coursePackage/alipayPaymentCallback"); |
| | | if(alipay.getCode() == 200){ |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | int num = 1; |
| | | int wait = 0; |
| | | while (num <= 10){ |
| | | int min = 5000; |
| | | wait += (min * num); |
| | | Thread.sleep(wait); |
| | | TCoursePackagePayment coursePackagePayment = couPayClient.getCoursePackagePaymentByCode(code); |
| | | if(coursePackagePayment.getPayStatus() == 2){ |
| | | break; |
| | | } |
| | | ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryALIOrder(code); |
| | | if(resultUtil.getCode() == 200 && coursePackagePayment.getPayStatus() == 1){ |
| | | /** |
| | | * WAIT_BUYER_PAY(交易创建,等待买家付款)、 |
| | | * TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)、 |
| | | * TRADE_SUCCESS(交易支付成功)、 |
| | | * TRADE_FINISHED(交易结束,不可退款) |
| | | */ |
| | | Map<String, String> data1 = resultUtil.getData(); |
| | | String s = data1.get("tradeStatus"); |
| | | String tradeNo = data1.get("tradeNo"); |
| | | if("TRADE_CLOSED".equals(s) || "TRADE_FINISHED".equals(s) || num == 10){ |
| | | coursePackagePayment.setState(3); |
| | | couPayClient.delPaymentCoursePackage(coursePackagePayment.getId()); |
| | | break; |
| | | } |
| | | if("TRADE_SUCCESS".equals(s)){ |
| | | coursePackagePayment.setPayStatus(2); |
| | | coursePackagePayment.setOrderNumber(tradeNo); |
| | | couPayClient.updatePaymentCoursePackage(coursePackagePayment); |
| | | break; |
| | | } |
| | | if("WAIT_BUYER_PAY".equals(s)){ |
| | | num++; |
| | | } |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }).start(); |
| | | } |
| | | return alipay; |
| | | } |
| | | |
| | | public void PlaypaiGoldPayment(){ |
| | | public int PlaypaiGoldPayment(String code,ClasspaymentRequest request){ |
| | | PlayPaiGoldCoursePackage paiGoldCoursePackage = new PlayPaiGoldCoursePackage(); |
| | | paiGoldCoursePackage.setCoursePackageId(request.getLessonId()); |
| | | paiGoldCoursePackage.setStuId(request.getStuId()); |
| | | paiGoldCoursePackage.setCoursePayConfigId(request.getCourseConfigId()); |
| | | paiGoldCoursePackage.setCode(code); |
| | | return couPayClient.paymentWanpaiRenewCourse(paiGoldCoursePackage); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public ResultUtil insertVipPaymentCallback(String code, String orderNumber) { |
| | | TCoursePackagePayment coursePackagePayment = couPayClient.getCoursePackagePaymentByCode(code); |
| | | if(coursePackagePayment.getPayStatus() != 1){ |
| | | return ResultUtil.success(); |
| | | } |
| | | coursePackagePayment.setPayStatus(2); |
| | | coursePackagePayment.setOrderNumber(orderNumber); |
| | | couPayClient.updatePaymentCoursePackage(coursePackagePayment); |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | @Override |
| | | public AppointmentRecordVo getAppointmentRecords(Integer stuId, Integer appUserId) { |
| | | AppointmentRecordVo recordVo = new AppointmentRecordVo(); |
| | | TStudent tStudent = this.baseMapper.selectOne(new QueryWrapper<TStudent>() |
| | | .eq("id",stuId ) |
| | | .eq("appUserId",appUserId)); |
| | | if (ToolUtil.isNotEmpty(tStudent)){ |
| | | recordVo.setStuId(tStudent.getId()); |
| | | recordVo.setStuName(tStudent.getName()); |
| | | recordVo.setAppointList(couPayClient.obtainStudentClassDetailsData(stuId)); |
| | | } |
| | | return recordVo; |
| | | } |
| | | |
| | | @Override |
| | | public ResultUtil cancelReservationOfCourse(Integer courseStuRecordId) { |
| | | Integer integer = crClient.cancelCourseRecordClass(courseStuRecordId); |
| | | switch (integer){ |
| | | case 1: |
| | | ResultUtil.success(); |
| | | break; |
| | | case 2: |
| | | ResultUtil.error("开课前三小时不能取消!"); |
| | | break; |
| | | default: |
| | | ResultUtil.runErr(); |
| | | break; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |