Explorar o código

Merge branch 'master' of http://git.dayaedu.com/yonge/collect_fee

# Conflicts:
#	src/main/java/com/ym/mec/collectfee/controller/YqPayController.java
#	src/main/java/com/ym/mec/collectfee/service/OrderService.java
#	src/main/java/com/ym/mec/collectfee/service/impl/ApplyInfoServiceImpl.java
#	src/main/java/com/ym/mec/collectfee/service/impl/OrderServiceImpl.java
#	src/main/java/com/ym/mec/collectfee/service/impl/SchoolServiceImpl.java
#	src/main/java/com/ym/mec/collectfee/utils/Constants.java
孙镇亮 %!s(int64=5) %!d(string=hai) anos
pai
achega
9390f03380

+ 34 - 3
src/main/java/com/ym/mec/collectfee/controller/UserController.java

@@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.dao.DuplicateKeyException;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpSession;
 import java.util.Date;
 
 @RestController()
@@ -212,11 +213,11 @@ public class UserController extends BaseController {
      */
 //    @ApiOperation(value = "开启乐团缴费功能")
     @PostMapping("/openClassPay")
-    public Object openClassPay(Integer id){
-        if(id == null){
+    public Object openClassPay(Integer id,String smsMsg){
+        if(id == null || StringUtils.isEmpty(smsMsg)){
             return failed(Constants.PARAM_VERIFY_ERROR_MSG);
         }
-        schoolService.openClassPay(id);
+        schoolService.openClassPay(id,smsMsg);
         return succeed();
     }
 
@@ -283,4 +284,34 @@ public class UserController extends BaseController {
     public Object mecUserIsExist(String phone){
         return succeed(applyInfoService.mecUserIsExist(phone));
     }
+
+    /**
+     * 发送短信验证码
+     * @param mobile
+     * @return
+     */
+    @GetMapping("/sendSmsCode")
+    public Object sendLoginVerifyCode(String mobile, HttpSession session) {
+        if(StringUtils.isEmpty(mobile)){
+            return failed(Constants.PARAM_VERIFY_ERROR_MSG);
+        }
+        applyInfoService.sendValidCode(mobile,session);
+        return succeed();
+    }
+
+    /**
+     * 验证短信验证码
+     * @param smsCode
+     * @return
+     */
+    @PostMapping("/verifySmsCode")
+    public Object verifySmsCode(String mobile,String smsCode,HttpSession session) {
+        if(StringUtils.isEmpty(smsCode)){
+            return failed(Constants.PARAM_VERIFY_ERROR_MSG);
+        }
+        if(applyInfoService.verifySmsCode(mobile,smsCode,session)){
+            return succeed();
+        }
+        return failed("验证失败");
+    }
 }

+ 31 - 120
src/main/java/com/ym/mec/collectfee/controller/YqPayController.java

@@ -2,14 +2,14 @@ package com.ym.mec.collectfee.controller;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.ym.mec.collectfee.common.sms.SmsExample;
 import com.ym.mec.collectfee.common.web.BaseController;
 import com.ym.mec.collectfee.entity.*;
 import com.ym.mec.collectfee.service.*;
+import com.ym.mec.collectfee.utils.Constants;
 import com.ym.mec.collectfee.utils.GenerateNum;
-import com.ym.mec.collectfee.utils.yqpay.Intfc;
-import com.ym.mec.collectfee.utils.yqpay.Msg;
-import com.ym.mec.collectfee.utils.yqpay.NotifyMsg;
-import com.ym.mec.collectfee.utils.yqpay.YqPayUtil;
+import com.ym.mec.collectfee.utils.ShortUrlUtil;
+import com.ym.mec.collectfee.utils.yqpay.*;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.IOUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
+import sun.plugin2.util.NativeLibLoader;
 
 import java.io.InputStreamReader;
 import java.math.BigDecimal;
@@ -68,7 +69,7 @@ public class YqPayController extends BaseController {
         BigDecimal amount = new BigDecimal("0");
         School school = schoolService.get(order.getClassId());
         //计划招生人数有更新,更新
-        orderService.getSchoolDetail(school.getSchoolId());
+        orderService.getSchoolDetail(school.getSchoolId(), order.getClassId());
 
         //1、判断已报名人数
         CourseGroupInfo courseGroupInfo = CourseGroupInfoService.get(order.getCourseId());
@@ -127,46 +128,19 @@ public class YqPayController extends BaseController {
         order.setType(1);
         order.setUserName(applyInfo.getName());
 
-        order.setAmount(new BigDecimal("2")); //测试设置金额
-
 
         String orderNo = GenerateNum.getInstance().GenerateOrderNo(); //自己系统订单号
         order.setOrderNo(orderNo);
         order.setCreateTime(new Date()); //订单提交时间
         order.setStatus(1); //订单状态
 
-        String notifyUrl = "http://47.99.212.176:9000/yqpay/notify"; //异步通知地址
-        String returnUrl = "http://pay.dayaedu.com/#/login?schoolId=" + school.getSchoolId() + "&classId=" + order.getClassId() + "&cityId=" + school.getCityId();//支付后返回页面
-        String payUrl = "https://qyfapi.95epay.com/api/api/hPay/toPayHtml";//支付跳转页
-        String payChannels = "{\"weChatPay\":true,\"weChatPayMobile\":false,\"aliPay\":true,\"fastpayXy\":true,\"aliPayMobile\":false,\"balancePay\":false}";//支付方式配置
-
-        //获取支付成功跟支付中的订单数
+        //获取分佣账户
         Integer branchId = 1001;//order.getBranchId();
-        int payOrderNums = orderService.getPayOrderNums();
-        //分佣账户(1、每10笔,前四笔收入私户 2、私户每个商户最多收款400万)
-        if ((payOrderNums + 1) % 10 <= 4) { //私人账户
-            branchId = 0;
-        }
+        Account routingAccount = accountService.getRoutingAccount(branchId);
 
-        //获取分佣账户
-        Account account = accountService.getAccountByBranchId(branchId);
-        if (account == null) {
-            return failed("机构没有设置收款账户");
-        }
-        String routingMerNo = account.getSellerNo();
-        BigDecimal HasRouting = account.getHasRouting().add(order.getAmount());
-        account.setHasRouting(HasRouting);
-
-        List<Map> tempRoutingList = new ArrayList();
-        if (branchId.equals(0)) {
-            Map<String, Object> routingList = new HashMap<>();
-            routingList.put("routingMerNo", routingMerNo);//分佣账户
-            routingList.put("routingFee", order.getAmount()); //分佣金额
-            tempRoutingList.add(routingList);
-        }
+        order.setAccount(routingAccount.getSellerNo());
+        order.setUAccount(routingAccount.getId().toString());
 
-        order.setUAccount(account.getId().toString());
-        order.setAccount(routingMerNo);
 
         //1、插入订单
         orderService.insert(order);
@@ -174,30 +148,13 @@ public class YqPayController extends BaseController {
         courseGroupInfo.setRegNum(courseGroupInfo.getRegNum() + 1);
         CourseGroupInfoService.upByIdAndVersion(courseGroupInfo);
         //3、修改分佣账户已收金额
-        accountService.upByIdAndVersion(account);
-
-
-        /*订单信息*/
-        String orderBody = "大雅乐盟培训课程";
-        /*订单标题*/
-        String orderSubject = "培训订单";
-
-
-        Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
-        resultMap.put("sellerNo", "0021677"); //收款商户号
-        resultMap.put("payChannels", payChannels); //支付方式
-        resultMap.put("orderBody", orderBody); //订单信息
-        resultMap.put("payAmount", order.getAmount()); //支付金额
-        resultMap.put("apiPayType", "1"); //*API支付类型1-即时支付,2-担保支付,3-预授权支付*/
-        resultMap.put("tradeType", "0"); //*交易类型1—充值,0—收款*
-        resultMap.put("merMerOrderNo", orderNo); //商户订单号
-        resultMap.put("orderSubject", orderSubject); //订单标题
-        resultMap.put("returnUrl", returnUrl); //前台页面地址
-        if (branchId.equals(0)) {
-            resultMap.put("tempRoutingList", JSON.toJSONString(tempRoutingList));//分账设置
-        }
-        Map rqMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
-        rqMap.put("host", payUrl);
+        BigDecimal HasRouting = routingAccount.getHasRouting().add(order.getAmount());
+        routingAccount.setHasRouting(HasRouting);
+        accountService.upByIdAndVersion(routingAccount);
+
+        order.setAmount(new BigDecimal("2")); //测试账户设置金额
+
+        Map rqMap = orderService.getPayMap(routingAccount, order, school); //获取支付map
 
         return succeed(rqMap);
     }
@@ -231,8 +188,8 @@ public class YqPayController extends BaseController {
 
         //classType 小课1 大课2
         Integer buyCount = mecCourse4json.getBuyCount();
-        if (buyCount <= 0) {
-            return failed("购买次数不能小于1");
+        if (buyCount <= 0 || buyCount > 20) {
+            return failed("购买课程次数不能小于1,大于20");
         }
         BigDecimal amount = new BigDecimal("0"); //课程总价
         String remark = "";
@@ -251,68 +208,18 @@ public class YqPayController extends BaseController {
         }
         if (pickCourses.size() == 0) {
             return failed("请选择续费课程");
-        }
-
-        School school = schoolService.get(pickCourses.get(0).getClassId());
-        if (school == null) {
-            return failed("报名学校不存在");
-        }
-        String notifyUrl = "http://47.99.212.176:9000/yqpay/notify"; //异步通知地址
-        String returnUrl = "http://pay.dayaedu.com/#/login?schoolId=" + school.getSchoolId() + "&classId=" + pickCourses.get(0).getClassId() + "&cityId=" + school.getCityId();//支付后返回页面
-        String payUrl = "https://qyfapi.95epay.com/api/api/hPay/toPayHtml";//支付跳转页
-        String payChannels = "{\"weChatPay\":true,\"weChatPayMobile\":false,\"aliPay\":true,\"fastpayXy\":true,\"aliPayMobile\":false,\"balancePay\":false}";//支付方式配置
+        };
 
         String orderNo = GenerateNum.getInstance().GenerateOrderNo(); //自己系统订单号
+        //获取分佣账户
+        Integer branchId = 1001;//order.getBranchId();
+        Account routingAccount = accountService.getRoutingAccount(branchId);
 
-        //获取支付成功跟支付中的订单数
-        Integer branchId = 1001;//renewals.getBranchId();
-        int payOrderNums = orderService.getPayOrderNums();
-        //分佣账户(1、每10笔,前四笔收入私户 2、私户每个商户最多收款400万)
-        if ((payOrderNums + 1) % 10 <= 4) { //私人账户
-            branchId = 0;
-        }
+        Order order = renewalsService.addRenewalsOrder(renewals, amount, orderNo, pickCourses, routingAccount, remark);
 
-        //获取分佣账户
-        Account account = accountService.getAccountByBranchId(branchId);
-        if (account == null) {
-            return failed("机构没有设置收款账户");
-        }
-        String routingMerNo = account.getSellerNo();
-        BigDecimal HasRouting = account.getHasRouting().add(amount);
-        account.setHasRouting(HasRouting);
-
-        List<Map> tempRoutingList = new ArrayList();
-        if (branchId.equals(0)) {
-            Map<String, Object> routingList = new HashMap<>();
-            routingList.put("routingMerNo", routingMerNo);//分佣账户
-            routingList.put("routingFee", amount); //分佣金额
-            tempRoutingList.add(routingList);
-        }
+        order.setAmount(new BigDecimal("2")); //测试账户设置金额
 
-        renewalsService.addRenewalsOrder(renewals, amount, orderNo, pickCourses, routingMerNo, account.getId(), remark);
-
-        /*订单信息*/
-        String orderBody = "大雅乐盟培训课程";
-        /*订单标题*/
-        String orderSubject = "培训订单";
-
-        //测试用
-        amount = new BigDecimal("2");
-        Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
-        resultMap.put("sellerNo", "0021677"); //收款商户号
-        resultMap.put("payChannels", payChannels); //支付方式
-        resultMap.put("orderBody", orderBody); //订单信息
-        resultMap.put("payAmount", amount); //支付金额
-        resultMap.put("apiPayType", "1"); //*API支付类型1-即时支付,2-担保支付,3-预授权支付*/
-        resultMap.put("tradeType", "0"); //*交易类型1—充值,0—收款*
-        resultMap.put("merMerOrderNo", orderNo); //商户订单号
-        resultMap.put("orderSubject", orderSubject); //订单标题
-        resultMap.put("returnUrl", returnUrl); //前台页面地址
-        if (branchId.equals(0)) {
-            resultMap.put("tempRoutingList", JSON.toJSONString(tempRoutingList));//分账设置
-        }
-        Map rqMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
-        rqMap.put("host", payUrl);
+        Map rqMap = orderService.getPayMap(routingAccount, order, null); //获取支付map
         return succeed(rqMap);
     }
 
@@ -520,6 +427,9 @@ public class YqPayController extends BaseController {
     public void updateOrder(Map<String, String> rpMap) {
         int status = rpMap.get("tradeState").equals("1") ? 2 : 0;
         Order order = orderService.getOrderByOrderNo(rpMap.get("merOrderNo"));
+        if (order == null) {
+            return;
+        }
         order.setStatus(status);
         order.setBank(rpMap.get("channelType"));
 
@@ -530,11 +440,12 @@ public class YqPayController extends BaseController {
             order.setPay(order.getAmount());
             order.setPayTime(new Date());
             //推送mec
+            ApplyInfo applyInfo = applyInfoService.get(order.getUserId());
             if (order.getTuiFee() != null) { //乐团报名
-                ApplyInfo applyInfo = applyInfoService.get(order.getUserId());
                 applyInfo.setStatus(1);
                 applyInfoService.update(applyInfo);
                 applyInfoService.userRegister(applyInfo.getPatriarchPhone(), order.getId()); //推送mec
+                schoolService.sendPayMsg(applyInfo.getPatriarchPhone(), order.getAmount().toString());
             } else {
                 Renewals renewals = renewalsService.getRenewalsByOrderId(order.getId());
                 RenewBean renewBean = new RenewBean();

+ 11 - 1
src/main/java/com/ym/mec/collectfee/service/AccountService.java

@@ -8,16 +8,26 @@ public interface AccountService extends BaseService<Integer, Account> {
 
     /**
      * 根据分部id获取收款账户信息
+     *
      * @param branchId 分部id
      * @return
      */
     Account getAccountByBranchId(Integer branchId);
 
     /**
-     *  根据id和version更新已收款
+     * 根据id和version更新已收款
+     *
      * @param account
      * @return
      */
     int upByIdAndVersion(Account account);
 
+    /**
+     * 获取分佣账户
+     *
+     * @param accountId 默认收款账户
+     * @return
+     */
+    Account getRoutingAccount(int accountId);
+
 }

+ 15 - 0
src/main/java/com/ym/mec/collectfee/service/ApplyInfoService.java

@@ -4,6 +4,7 @@ import com.ym.mec.collectfee.common.page.PageInfo;
 import com.ym.mec.collectfee.common.service.BaseService;
 import com.ym.mec.collectfee.entity.*;
 
+import javax.servlet.http.HttpSession;
 import java.util.List;
 import java.util.Map;
 
@@ -82,4 +83,18 @@ public interface ApplyInfoService extends BaseService<Integer, ApplyInfo> {
      * @param phone
      */
     boolean mecUserIsExist(String phone);
+
+    /**
+     * 发送短信验证码
+     * @param mobile
+     * @return
+     */
+    boolean sendValidCode(String mobile, HttpSession session);
+
+    /**
+     * 验证短信验证码
+     * @param smsCode
+     * @return
+     */
+    boolean verifySmsCode(String mobile,String smsCode,HttpSession session);
 }

+ 18 - 4
src/main/java/com/ym/mec/collectfee/service/OrderService.java

@@ -1,15 +1,21 @@
 package com.ym.mec.collectfee.service;
 
+import com.alibaba.fastjson.JSON;
 import com.ym.mec.collectfee.common.service.BaseService;
+import com.ym.mec.collectfee.entity.Account;
 import com.ym.mec.collectfee.entity.Order;
+import com.ym.mec.collectfee.entity.School;
+import com.ym.mec.collectfee.utils.yqpay.YqPayUtil;
 
 import javax.xml.bind.JAXBException;
-import java.util.List;
+import java.math.BigDecimal;
+import java.util.*;
 
 public interface OrderService extends BaseService<Integer, Order> {
 
     /**
      * 根据学生编号,获取订单列表
+     *
      * @param userId
      * @return
      */
@@ -25,6 +31,7 @@ public interface OrderService extends BaseService<Integer, Order> {
 
     /**
      * 支付成功后推送订单列表
+     *
      * @param batchNum 批次号
      * @return
      */
@@ -32,14 +39,16 @@ public interface OrderService extends BaseService<Integer, Order> {
 
     /**
      * 查询某声部报名成功人数
-     * @param poName 乐团名称
+     *
+     * @param poName    乐团名称
      * @param voicePort 声部名称
      * @return
      */
-    int countOrder(String poName,String voicePort);
+    int countOrder(String poName, String voicePort);
 
     /**
      * 根据系统订单号获取订单
+     *
      * @param orderNo 系统订单号
      * @return
      */
@@ -48,21 +57,26 @@ public interface OrderService extends BaseService<Integer, Order> {
 
     /**
      * 根据乐团编号获取乐团信息
+     *
      * @param schoolId
      * @return
      */
-    Object getSchoolDetail(Integer schoolId);
+    Object getSchoolDetail(Integer schoolId, Integer clazzId);
 
 
     /**
      * 获取支付中和成功的订单数
+     *
      * @return
      */
     int getPayOrderNums();
 
     /**
      * 获取支付中的订单
+     *
      * @return
      */
     List<Order> findPayingOrders();
+
+    Map getPayMap(Account account, Order order, School school) throws Exception;
 }

+ 4 - 1
src/main/java/com/ym/mec/collectfee/service/RenewalsService.java

@@ -5,6 +5,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import com.ym.mec.collectfee.common.service.BaseService;
+import com.ym.mec.collectfee.entity.Account;
 import com.ym.mec.collectfee.entity.MecCourse;
 import com.ym.mec.collectfee.entity.Order;
 import com.ym.mec.collectfee.entity.Renewals;
@@ -13,16 +14,18 @@ public interface RenewalsService extends BaseService<Integer, Renewals> {
 
     /**
      * 生成续费的订单
+     *
      * @param orderNo
      * @param mecCourses
      * @return
      */
-    Order addRenewalsOrder(Renewals renewals, BigDecimal amount, String orderNo, List<MecCourse> mecCourses, String routingMerNo, int accountId,String remark);
+    Order addRenewalsOrder(Renewals renewals, BigDecimal amount, String orderNo, List<MecCourse> mecCourses, Account routingAccount, String remark);
 
     void renewalsInsert(ArrayList<Renewals> renewalsArrayList);
 
     /**
      * 根据订单号获取小课续费信息
+     *
      * @param orderId
      * @return
      */

+ 7 - 1
src/main/java/com/ym/mec/collectfee/service/SchoolService.java

@@ -12,5 +12,11 @@ public interface SchoolService extends BaseService<Integer, School> {
      * 开启乐团缴费
      * @param classId
      */
-    void openClassPay(Integer classId);
+    void openClassPay(Integer classId,String smsMsg);
+
+    /**
+     * 缴费成功发送短信
+     * @param mobile
+     */
+    void sendPayMsg(String mobile,String amount);
 }

+ 26 - 0
src/main/java/com/ym/mec/collectfee/service/impl/AccountServiceImpl.java

@@ -2,18 +2,28 @@ package com.ym.mec.collectfee.service.impl;
 
 import com.ym.mec.collectfee.common.dao.BaseDAO;
 import com.ym.mec.collectfee.common.service.impl.BaseServiceImpl;
+import com.ym.mec.collectfee.service.OrderService;
 import org.springframework.beans.factory.annotation.Autowired;
 import com.ym.mec.collectfee.entity.Account;
 import com.ym.mec.collectfee.service.AccountService;
 import com.ym.mec.collectfee.dao.AccountDao;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 @Service
 public class AccountServiceImpl extends BaseServiceImpl<Integer, Account> implements AccountService {
 
     @Autowired
     AccountDao accountDao;
 
+    @Autowired
+    OrderService orderService;
+
     @Override
     public BaseDAO<Integer, Account> getDAO() {
         return accountDao;
@@ -29,5 +39,21 @@ public class AccountServiceImpl extends BaseServiceImpl<Integer, Account> implem
         return accountDao.upByIdAndVersion(account);
     }
 
+    /**
+     * 获取分佣账户
+     *
+     * @param branchId 默认收款账户
+     * @return
+     */
+    @Override
+    public Account getRoutingAccount(int branchId) {
+        int payOrderNums = orderService.getPayOrderNums(); //获取支付中和成功的订单数
+        //分佣账户(1、每10笔,前四笔收入私户 2、私户每个商户最多收款400万)
+        if ((payOrderNums + 1) % 10 <= 4) { //私人账户
+            branchId = 0;
+        }
+        return this.getAccountByBranchId(branchId);
+    }
+
 
 }

+ 64 - 66
src/main/java/com/ym/mec/collectfee/service/impl/ApplyInfoServiceImpl.java

@@ -1,57 +1,26 @@
 package com.ym.mec.collectfee.service.impl;
 
-import java.io.StringWriter;
-import java.io.Writer;
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Base64;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
 import com.thoughtworks.xstream.XStream;
 import com.ym.mec.collectfee.common.dao.BaseDAO;
 import com.ym.mec.collectfee.common.page.PageInfo;
 import com.ym.mec.collectfee.common.service.impl.BaseServiceImpl;
-import com.ym.mec.collectfee.dao.ApplyInfoDao;
-import com.ym.mec.collectfee.dao.BranchDao;
-import com.ym.mec.collectfee.dao.CourseGroupInfoDao;
-import com.ym.mec.collectfee.dao.MecUserDao;
-import com.ym.mec.collectfee.dao.OrderDao;
-import com.ym.mec.collectfee.dao.SeminaryDao;
-import com.ym.mec.collectfee.entity.ApplyInfo;
-import com.ym.mec.collectfee.entity.ApplyInfoPage;
-import com.ym.mec.collectfee.entity.Branch;
-import com.ym.mec.collectfee.entity.Course;
-import com.ym.mec.collectfee.entity.CourseGroupInfo;
-import com.ym.mec.collectfee.entity.MecCourse;
-import com.ym.mec.collectfee.entity.MecUser;
-import com.ym.mec.collectfee.entity.MecUserInfo;
-import com.ym.mec.collectfee.entity.Order;
-import com.ym.mec.collectfee.entity.ParseMecCourse;
-import com.ym.mec.collectfee.entity.RenewBean;
-import com.ym.mec.collectfee.entity.RequestMecApplyClass;
-import com.ym.mec.collectfee.entity.RequestParamBean;
-import com.ym.mec.collectfee.entity.ResponseBranchesBean;
-import com.ym.mec.collectfee.entity.ResponseSeminariesBean;
-import com.ym.mec.collectfee.entity.ResponseUserInfo;
-import com.ym.mec.collectfee.entity.Seminary;
-import com.ym.mec.collectfee.entity.StudentsQueryInfo;
-import com.ym.mec.collectfee.entity.Sundry;
+import com.ym.mec.collectfee.common.sms.SmsExample;
+import com.ym.mec.collectfee.dao.*;
+import com.ym.mec.collectfee.entity.*;
 import com.ym.mec.collectfee.service.ApplyInfoService;
-import com.ym.mec.collectfee.utils.CDesECB;
-import com.ym.mec.collectfee.utils.HttpUtil;
-import com.ym.mec.collectfee.utils.MapUtil;
-import com.ym.mec.collectfee.utils.XStreamUtil;
-
+import com.ym.mec.collectfee.utils.*;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.servlet.http.HttpSession;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.*;
 
 @Service
 @Slf4j
@@ -78,9 +47,22 @@ public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> im
 
 	@Value("${common.properties.key}")
 	private String key;
-	
-	@Value("${common.properties.keyId}")
-	private Integer keyId;
+	@Value("${common.properties.sms-appId}")
+	private String appId;
+	@Value("${common.properties.sms-secretKey}")
+	private String secretKey;
+	@Value("${common.properties.sms-host-dev}")
+	private String host;
+	@Value("${common.properties.sms-send-request-url}")
+	private String sendUrl;
+	// 加密算法
+	private String algorithm = "AES/ECB/PKCS5Padding";
+	// 编码
+	private String encode = "UTF-8";
+	// 是否压缩
+	private boolean isGizp = true;
+
+	private final String loginVerifyCodeKey = "loginVerifyCode:";
 
 	@Override
 	public BaseDAO<Integer, ApplyInfo> getDAO() {
@@ -108,7 +90,7 @@ public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> im
 				String body = xs.toXML(applyInfo);
 				body = body.substring(body.indexOf("<user>")+6,body.indexOf("</user>"));
 				//推送mec注册接口
-//				log.info("推送到用户数据到mec注册 body: " + body);
+				log.info("推送到用户数据到mec注册 body: " + body);
 				body = getBody(body,121301);
 				Date date = new Date();
 				try {
@@ -121,7 +103,7 @@ public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> im
 					body = xs.toXML(applyClass);
 					body = body.substring(body.indexOf("<body>")+6,body.indexOf("</body>"));
 					//推送mec用户缴费
-//					log.info("推送到用户数据到mec缴费 body: " + body);
+					log.info("推送到用户数据到mec缴费 body: " + body);
 					getBody(body,125218);
 					applyInfoDao.update(applyInfo);
 					return true;
@@ -161,19 +143,15 @@ public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> im
 			courses.add(course);
 			applyClass.setCourses(courses);
 			//<amount>缴费总金额</amount>
-//			applyClass.setAmount(order.getAmount());
-			applyClass.setAmount(new BigDecimal(0));
+			applyClass.setAmount(order.getAmount());
 			//<tuiFee>学费金额</tuiFee>
-//			applyClass.setTuiFee(order.getTuiFee());
-			applyClass.setTuiFee(new BigDecimal(0));
+			applyClass.setTuiFee(order.getTuiFee());
 			//<goodsFee>乐器费用</goodsFee>
-//			applyClass.setGoodsFee(order.getGoodsFee());
-			applyClass.setGoodsFee(new BigDecimal(0));
+			applyClass.setGoodsFee(order.getGoodsFee());
 			//<sdName>杂费名称</sdName>
 			List<Sundry> sundries = new ArrayList<>();
 			Sundry sundry = new Sundry();
-//			sundry.setSdFee(order.getSdFee());
-			sundry.setSdFee(new BigDecimal(0));
+			sundry.setSdFee(order.getSdFee());
 			String sdName = order.getSdName();
 			if(StringUtils.isEmpty(sdName)){
 				sdName = order.getRemark();
@@ -233,7 +211,7 @@ public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> im
 	public Map<String, Object> getUserRegisterViewDetail(Integer stuId) {
 		Map<String, Object> vIewDetail = applyInfoDao.getUserRegisterVIewDetail(stuId);
 		String subName = vIewDetail.get("sub_name_").toString();
-		if(subName.contains("圆号") || subName.contains("上低音") ||subName.contains("长号") ||subName.contains("大号") || subName.contains("次中音号")){
+		if(subName.contains("圆号") || subName.contains("上低音") ||subName.contains("长号") ||subName.contains("大号")){
 			vIewDetail.put("isCopperPipe",true);
 		}else {
 			vIewDetail.put("isCopperPipe",false);
@@ -301,7 +279,7 @@ public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> im
 			MecUser mecUser = mecUserDao.get(userId);
 			if(mecUser == null){
 				String body = "<body><userId>" + userId + "</userId></body>";
-//				log.info("获取学员信息mec body: " + body);
+				log.info("获取学员信息mec body: " + body);
 				body = getBody(body, 121313);
 				if(!StringUtils.isEmpty(body)){
 					body = new String(Base64.getDecoder().decode(body));
@@ -324,18 +302,18 @@ public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> im
 			xs.autodetectAnnotations(true);
 			String body = xs.toXML(renewBean);
 			body = body.substring(body.indexOf("<body>")+6,body.indexOf("</body>"));
-//			log.info("推送续费数据到mec body: " + body);
+			log.info("推送续费数据到mec body: " + body);
 			body = CDesECB.encode(key,body);
 			RequestParamBean requestParamBean = new RequestParamBean();
 			requestParamBean.setBody(body);
-			requestParamBean.setHead(XStreamUtil.getOrdersHead(body,123255,publicKey,keyId,4));
+			requestParamBean.setHead(XStreamUtil.getOrdersHead(body,123255,publicKey,2,4));
 			Writer writer = new StringWriter();
 			writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
 			xs = new XStream();
 			xs.autodetectAnnotations(true);
 			xs.toXML(requestParamBean,writer);
 			body = HttpUtil.postXmlData(writer.toString(), url);
-//			log.info("mec响应的续费数据 body: " + body);
+			log.info("mec响应的续费数据 body: " + body);
 			body = body.substring(body.indexOf("<errCode>") + 9, body.indexOf("</errCode>"));
 //			body = new String(CDesECB.decode(key,body.getBytes()));
 //			body = CDesECB.decodeValue(key,body);
@@ -362,7 +340,7 @@ public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> im
 	public boolean mecUserIsExist(String phone) {
 		try {
 			String body = "<body><uType>1</uType><uName>" + phone +"</uName></body>";
-//			log.info("用户是否存在mec系统 body: " + body);
+			log.info("用户是否存在mec系统 body: " + body);
 			body = getBody(body, 120431);
 			body = new String(Base64.getDecoder().decode(body));
 			if(StringUtils.isEmpty(body)){
@@ -378,6 +356,26 @@ public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> im
 		return false;
 	}
 
+	@Override
+	public boolean sendValidCode(String mobile, HttpSession session) {
+		String code = RandomStringUtils.randomNumeric(6);
+		session.setMaxInactiveInterval(900);
+		session.setAttribute(loginVerifyCodeKey + mobile,code);
+		SmsExample.setSingleSms(appId,secretKey,host,algorithm,String.format(Constants.SEND_LOGIN_SME_MSG, code),null,null,mobile,isGizp,encode);
+		return true;
+	}
+
+	@Override
+	public boolean verifySmsCode(String mobile,String smsCode,HttpSession session) {
+		Object attribute = session.getAttribute(loginVerifyCodeKey + mobile);
+		if(attribute != null){
+			if(StringUtils.isNotEmpty(attribute.toString()) && attribute.toString().equals(smsCode)){
+				return true;
+			}
+		}
+		return false;
+	}
+
 
 	private List<MecCourse> getCourses(String body) throws Exception{
 		body = getBody(body,123031);
@@ -400,7 +398,7 @@ public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> im
 		xs.autodetectAnnotations(true);
 		xs.toXML(requestParamBean,writer);
 		body = HttpUtil.postXmlData(writer.toString(), url);
-//		log.info("mec响应参数 body: " + body + " ,cmd: " + cmd);
+		log.info("mec响应参数 body: " + body + " ,cmd: " + cmd);
 		return body.substring(body.indexOf("<body>")+6,body.indexOf("</body>"));
 	}
 

+ 134 - 88
src/main/java/com/ym/mec/collectfee/service/impl/OrderServiceImpl.java

@@ -1,5 +1,6 @@
 package com.ym.mec.collectfee.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.thoughtworks.xstream.XStream;
 import com.ym.mec.collectfee.common.dao.BaseDAO;
 import com.ym.mec.collectfee.common.service.impl.BaseServiceImpl;
@@ -8,87 +9,88 @@ import com.ym.mec.collectfee.entity.*;
 import com.ym.mec.collectfee.service.CourseGroupInfoService;
 import com.ym.mec.collectfee.service.OrderService;
 import com.ym.mec.collectfee.service.SchoolService;
+import com.ym.mec.collectfee.service.YqPayService;
 import com.ym.mec.collectfee.utils.HttpUtil;
 import com.ym.mec.collectfee.utils.XStreamUtil;
+import com.ym.mec.collectfee.utils.yqpay.YqPayUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import java.io.StringWriter;
 import java.io.Writer;
-import java.util.Base64;
-import java.util.Date;
-import java.util.List;
+import java.math.BigDecimal;
+import java.util.*;
 
 @Service
 public class OrderServiceImpl extends BaseServiceImpl<Integer, Order> implements OrderService {
 
-	@Autowired
-	private OrderDao orderDao;
-	@Autowired
-	private SchoolService schoolService;
-	@Autowired
-	private CourseGroupInfoService courseGroupInfoService;
-
-	//公共密钥
-	@Value("${common.properties.mec-publicKey}")
-	private String publicKey;
-
-	@Value("${common.properties.mec-url}")
-	private String url;
-
-	@Override
-	public BaseDAO<Integer, Order> getDAO() {
-		return orderDao;
-	}
-
-	@Override
-	public List<Order> getOrderByUserId(Integer userId) {
-		return orderDao.getOrderByUserId(userId);
-	}
-
-	@Override
-	public String pushOrder(String batchNum){
-		try {
-			RequestParamBean requestParamBean = new RequestParamBean();
-			List<Order> orderList = orderDao.getOrderByBatch(batchNum);
-			if(orderList == null || orderList.size() < 1){
-				return null;
-			}
-			XStream xs = new XStream();
-			xs.autodetectAnnotations(true);
-			Writer writer = new StringWriter();
-			Orders orders = new Orders(orderList);
-			xs.toXML(orders,writer);
-			String body = writer.toString();
-			body = body.substring(body.indexOf("<body>")+6,body.indexOf("</body>"));
-
-			body = Base64.getEncoder().encodeToString(body.getBytes());
-			requestParamBean.setBody(body);
-			requestParamBean.setHead(XStreamUtil.getOrdersHead(body,121512,publicKey,null,null));
-
-			xs.autodetectAnnotations(true);
-			writer = new StringWriter();
-			writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
-			xs.toXML(requestParamBean,writer);
-			return writer.toString();
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-		return null;
-	}
-
-
-	@Override
-	public int countOrder(String poName, String voicePort) {
-		return orderDao.countOrder(poName,voicePort);
-	}
-
-
-	@Override
-	public Order getOrderByOrderNo(String orderNo) {
-		return orderDao.getOrderByOrderNo(orderNo);
-	}
+    @Value("${yq-pay.notify-url}")
+    private String notifyUrl;
+
+    @Value("${yq-pay.return-host}")
+    private String returnHost;
+
+    @Autowired
+    private OrderDao orderDao;
+    @Autowired
+    private SchoolService schoolService;
+    @Autowired
+    private CourseGroupInfoService courseGroupInfoService;
+
+    //公共密钥
+    @Value("${common.properties.mec-publicKey}")
+    private String publicKey;
+
+    @Value("${common.properties.mec-url}")
+    private String url;
+
+    @Override
+    public BaseDAO<Integer, Order> getDAO() {
+        return orderDao;
+    }
+
+    @Override
+    public List<Order> getOrderByUserId(Integer userId) {
+        return orderDao.getOrderByUserId(userId);
+    }
+
+    @Override
+    public String pushOrder(String batchNum) {
+        try {
+            RequestParamBean requestParamBean = new RequestParamBean();
+            List<Order> orderList = orderDao.getOrderByBatch(batchNum);
+            if (orderList == null || orderList.size() < 1) {
+                return null;
+            }
+            XStream xs = new XStream();
+            xs.autodetectAnnotations(true);
+            Writer writer = new StringWriter();
+            Orders orders = new Orders(orderList);
+            xs.toXML(orders, writer);
+            String body = writer.toString();
+            body = body.substring(body.indexOf("<body>") + 6, body.indexOf("</body>"));
+
+            body = Base64.getEncoder().encodeToString(body.getBytes());
+            requestParamBean.setBody(body);
+            requestParamBean.setHead(XStreamUtil.getOrdersHead(body, 121512, publicKey, null, null));
+
+            xs.autodetectAnnotations(true);
+            writer = new StringWriter();
+            writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
+            xs.toXML(requestParamBean, writer);
+            return writer.toString();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+
+    @Override
+    public int countOrder(String poName, String voicePort) {
+        return orderDao.countOrder(poName, voicePort);
+    }
 
 	@Override
 	public Object getSchoolDetail(Integer schoolId) {
@@ -113,25 +115,69 @@ public class OrderServiceImpl extends BaseServiceImpl<Integer, Order> implements
 		return null;
 	}
 
-	public String parseBody(String body){
-		body = body.substring(body.indexOf("<body>")+6,body.indexOf("</body>"));
-		return "<body><courses>" + new String(Base64.getDecoder().decode(body)) + "</courses></body>";
-	}
-
-	@Override
-	public int getPayOrderNums() {
-		return orderDao.getPayOrderNums();
-	}
-
-	@Override
-	public List<Order> findPayingOrders(){
-		return orderDao.findPayingOrders();
-	}
-
-	@Override
-	public List<Order> getOrderByClassId(Integer classId,Integer type) {
-		return orderDao.getOrderByClassId(classId,type);
-	}
+    @Override
+    public Order getOrderByOrderNo(String orderNo) {
+        return orderDao.getOrderByOrderNo(orderNo);
+    }
+
+
+    public String parseBody(String body) {
+        body = body.substring(body.indexOf("<body>") + 6, body.indexOf("</body>"));
+        return "<body><courses>" + new String(Base64.getDecoder().decode(body)) + "</courses></body>";
+    }
+
+    @Override
+    public int getPayOrderNums() {
+        return orderDao.getPayOrderNums();
+    }
+
+    @Override
+    public List<Order> findPayingOrders() {
+        return orderDao.findPayingOrders();
+    }
+
+    @Override
+    public Map getPayMap(Account routingAccount, Order order, School school) throws Exception {
+
+        String notifyUrl = this.notifyUrl; //异步通知地址
+        String returnUrl = this.returnHost + "/#/payment?userId="+order.getUserId();//支付后返回页面
+
+        if (school != null) {
+            returnUrl = this.returnHost + "/#/login?schoolId=" + school.getSchoolId() + "&classId=" + order.getClassId() + "&cityId=" + school.getCityId();//支付后返回页面
+        }
+        String payUrl = "https://qyfapi.95epay.com/api/api/hPay/toPayHtml";//支付跳转页
+        String payChannels = "{\"weChatPay\":true,\"weChatPayMobile\":false,\"aliPay\":true,\"fastpayXy\":true,\"aliPayMobile\":false,\"balancePay\":false}";//支付方式配置
+
+        List<Map> tempRoutingList = new ArrayList();
+        if (routingAccount.getBranchId().equals(0)) {
+            Map<String, Object> routingList = new HashMap<>();
+            routingList.put("routingMerNo", routingAccount.getSellerNo());//分佣账户
+            routingList.put("routingFee", order.getAmount()); //分佣金额
+            tempRoutingList.add(routingList);
+        }
+
+        /*订单信息*/
+        String orderBody = "大雅乐盟培训课程";
+        /*订单标题*/
+        String orderSubject = "培训订单";
+
+        Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
+        resultMap.put("sellerNo", "0021677"); //收款商户号
+        resultMap.put("payChannels", payChannels); //支付方式
+        resultMap.put("orderBody", orderBody); //订单信息
+        resultMap.put("payAmount", order.getAmount()); //支付金额
+        resultMap.put("apiPayType", "1"); //*API支付类型1-即时支付,2-担保支付,3-预授权支付*/
+        resultMap.put("tradeType", "0"); //*交易类型1—充值,0—收款*
+        resultMap.put("merMerOrderNo", order.getOrderNo()); //商户订单号
+        resultMap.put("orderSubject", orderSubject); //订单标题
+        resultMap.put("returnUrl", returnUrl); //前台页面地址
+        if (routingAccount.getBranchId().equals(0)) {
+            resultMap.put("tempRoutingList", JSON.toJSONString(tempRoutingList));//分账设置
+        }
+        Map rqMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
+        rqMap.put("host", payUrl);
+        return rqMap;
+    }
 
 
 }

+ 8 - 8
src/main/java/com/ym/mec/collectfee/service/impl/RenewalsServiceImpl.java

@@ -12,6 +12,7 @@ import com.ym.mec.collectfee.service.AccountService;
 import com.ym.mec.collectfee.service.OrderService;
 import com.ym.mec.collectfee.service.RenewalsService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -45,7 +46,7 @@ public class RenewalsServiceImpl extends BaseServiceImpl<Integer, Renewals> impl
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public Order addRenewalsOrder(Renewals renewals, BigDecimal amount, String orderNo, List<MecCourse> mecCourses, String routingMerNo, int accountId, String remark) {
+    public Order addRenewalsOrder(Renewals renewals, BigDecimal amount, String orderNo, List<MecCourse> mecCourses, Account routingAccount, String remark) {
 
         ////classType 小课1 大课2
         Order order = new Order();
@@ -53,11 +54,11 @@ public class RenewalsServiceImpl extends BaseServiceImpl<Integer, Renewals> impl
         order.setUserId(renewals.getUserId());
         order.setOrderNo(orderNo);
         order.setAmount(amount);
-        order.setAccount(routingMerNo);
+        order.setAccount(routingAccount.getSellerNo());
         order.setRemark(remark);
         order.setClassId(renewals.getClassId());
         order.setStatus(1);
-        order.setUAccount(String.valueOf(accountId));
+        order.setUAccount(String.valueOf(routingAccount.getId()));
         order.setCreateTime(new Date());
 
         //1、插入订单
@@ -86,14 +87,13 @@ public class RenewalsServiceImpl extends BaseServiceImpl<Integer, Renewals> impl
 
         }
 
-        //2、添加
+        //2、添加续费记录
         renewalsService.renewalsInsert(renewalsArrayList);
         //3、修改分佣账户已收金额
         //获取分佣账户
-        Account account = accountService.getAccountByBranchId(renewals.getBranchId());
-        BigDecimal HasRouting = account.getHasRouting().add(amount);
-        account.setHasRouting(HasRouting);
-        accountService.upByIdAndVersion(account);
+        BigDecimal HasRouting = routingAccount.getHasRouting().add(amount);
+        routingAccount.setHasRouting(HasRouting);
+        accountService.upByIdAndVersion(routingAccount);
         return order;
     }
 

+ 7 - 1
src/main/java/com/ym/mec/collectfee/service/impl/SchoolServiceImpl.java

@@ -75,7 +75,7 @@ public class SchoolServiceImpl extends BaseServiceImpl<Integer, School> implemen
 	}
 
 	@Override
-	public void openClassPay(Integer classId) {
+	public void openClassPay(Integer classId,String smsMsg) {
 		School school = schoolDao.get(classId);
 		if(school != null && school.getStatus() == 1){
 			school.setUpdateTime(new Date());
@@ -95,6 +95,12 @@ public class SchoolServiceImpl extends BaseServiceImpl<Integer, School> implemen
 			}
 		}
 	}
+
+	@Override
+	public void sendPayMsg(String mobile,String amount){
+		SmsExample.setSingleSms(appId,secretKey,host,algorithm,
+				String.format(Constants.PAY_SMS_TEMPLATE,amount),null,null, mobile,isGizp,encode);
+	}
 	
 //	public static void main(String[] args) {
 //		System.out.println(String.format(Constants.SMS_TEMPLATE, DateUtils.getDayForAfter(new Date(), 2)));

+ 2 - 0
src/main/java/com/ym/mec/collectfee/utils/Constants.java

@@ -5,4 +5,6 @@ public interface Constants {
     String PARAM_EXIST_ERROR_MSG = "该用户已在其他乐团报名";
     
     String SMS_TEMPLATE = "%s家长您好:恭喜您的孩子被管乐团录取!请您收到录取通知书后,于%s晚24:00前点此链接%s 或扫录取通知书上的二维码为学生完成入团注册缴费手续,专业以录取专业为准。完成后请关注深圳大雅乐盟(D-Y-M-E)点击菜单栏乐人进入乐团助手页面,查看课程安排。";
+    String PAY_SMS_TEMPLATE = "家长您好:您已支付乐器及相关费用%s元并完成乐团相关注册手续,欢迎加入管乐团开启您的器乐学习之旅,请等待开课通知!。";
+	String SEND_LOGIN_SME_MSG = "您的验证码是:%s, 在15分钟内有效,请勿向任何人提供您收到的短信验证码。";
 }

+ 2 - 0
src/main/resources/application.yml

@@ -63,6 +63,8 @@ logging:
 yq-pay:
   pay-host: https://qyfapi.95epay.com
   query-host: https://qyfquery.95epay.com
+  notify-url: http://47.99.212.176:9000/yqpay/notify #通知
+  return-host: http://pay.dayaedu.com #支付返回
   merno: 0021677
 
 common: