Prechádzať zdrojové kódy

zyp 收款功能接口

zyp 1 týždeň pred
rodič
commit
507ce5bc5c

+ 6 - 0
fs-service/src/main/java/com/fs/his/service/IFsStorePaymentService.java

@@ -13,6 +13,8 @@ import com.fs.his.param.PayOrderParam;
 import com.fs.his.param.WxSendRedPacketParam;
 import com.fs.his.vo.FsStorePaymentExcelVO;
 import com.fs.his.vo.FsStorePaymentVO;
+import com.fs.hisStore.param.FsStorePaymentGetWxaCodeParam;
+import com.fs.hisStore.param.FsStorePaymentPayParam;
 import me.chanjar.weixin.common.error.WxErrorException;
 
 import javax.servlet.http.HttpServletRequest;
@@ -114,4 +116,8 @@ public interface IFsStorePaymentService
      * @return R
      */
     R processPayment(PayOrderParam payOrderParam);
+
+    R paymentByWxaCode(FsStorePaymentPayParam payment);
+
+    R getWxaCodeByPayment(FsStorePaymentGetWxaCodeParam param);
 }

+ 124 - 1
fs-service/src/main/java/com/fs/his/service/impl/FsStorePaymentServiceImpl.java

@@ -5,9 +5,11 @@ import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
+import cn.binarywang.wx.miniapp.api.WxMaService;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.TypeReference;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.fs.common.annotation.DataScope;
@@ -20,10 +22,15 @@ import com.fs.common.utils.ServletUtils;
 import com.fs.common.utils.StringUtils;
 import com.fs.common.utils.ip.IpUtils;
 import com.fs.common.utils.poi.ExcelUtil;
+import com.fs.company.domain.Company;
+import com.fs.company.domain.CompanyUser;
 import com.fs.company.mapper.CompanyConfigMapper;
 import com.fs.company.param.FsStoreStatisticsParam;
+import com.fs.company.service.ICompanyService;
+import com.fs.company.service.ICompanyUserService;
 import com.fs.company.vo.FsStorePaymentStatisticsVO;
 import com.fs.config.cloud.CloudHostProper;
+import com.fs.core.config.WxMaConfiguration;
 import com.fs.core.config.WxPayProperties;
 import com.fs.core.utils.OrderCodeUtils;
 import com.fs.course.config.CourseConfig;
@@ -48,9 +55,12 @@ import com.fs.his.param.WxSendRedPacketParam;
 import com.fs.his.service.IFsInquiryOrderService;
 import com.fs.his.service.IFsPackageOrderService;
 import com.fs.his.service.IFsStoreOrderService;
+import com.fs.his.service.IFsStorePaymentService;
 import com.fs.his.utils.PhoneUtil;
 import com.fs.his.vo.FsStorePaymentExcelVO;
 import com.fs.his.vo.FsStorePaymentVO;
+import com.fs.hisStore.param.FsStorePaymentGetWxaCodeParam;
+import com.fs.hisStore.param.FsStorePaymentPayParam;
 import com.fs.huifuPay.domain.HuiFuCreateOrder;
 import com.fs.huifuPay.domain.HuiFuQueryOrderResult;
 import com.fs.huifuPay.domain.HuiFuRefundResult;
@@ -60,6 +70,8 @@ import com.fs.huifuPay.sdk.opps.core.request.V2TradePaymentScanpayRefundRequest;
 import com.fs.huifuPay.service.HuiFuService;
 import com.fs.system.domain.SysConfig;
 import com.fs.system.mapper.SysConfigMapper;
+import com.fs.system.oss.CloudStorageService;
+import com.fs.system.oss.OSSFactory;
 import com.fs.system.service.ISysConfigService;
 import com.fs.tzBankPay.TzBankService.TzBankService;
 import com.fs.tzBankPay.TzBankService.TzBankServiceImpl.TzBankServiceImpl;
@@ -103,7 +115,6 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
-import com.fs.his.service.IFsStorePaymentService;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.servlet.http.HttpServletRequest;
@@ -153,6 +164,10 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
     private FsUserMapper userMapper;
     @Autowired
     private FsUserWxMapper userWxMapper;
+    @Autowired
+    private ICompanyUserService companyUserService;
+    @Autowired
+    private ICompanyService companyService;
 
     @Autowired
     private CloudHostProper cloudHostProper;
@@ -1156,4 +1171,112 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
         return storePayment;
     }
 
+
+    @Override
+    public R getWxaCodeByPayment(FsStorePaymentGetWxaCodeParam param)  {
+        final WxMaService wxMaService = WxMaConfiguration.getMaService(param.getAppId());
+        String scene;
+        //判断销售id
+        if (param.getCompanyUserId() == null){
+            scene = "companyId="+ param.getCompanyId();
+        }else {
+            scene = "companyId="+ param.getCompanyId()+"&"+"companyUserId="+ param.getCompanyUserId();
+        }
+        byte[] file;
+        try {
+            file = wxMaService.getQrcodeService().createWxaCodeUnlimitBytes(
+                    scene,
+                    "pages_user/user/pay",
+                    true,
+                    "release",
+                    430,
+                    true,
+                    null,
+                    false);
+
+            // 上传图片到存储桶
+            String suffix = ".png";
+            CloudStorageService storage = OSSFactory.build();
+            String url;
+            try {
+                url = storage.uploadSuffix(file, suffix);
+            }  catch (Exception e) {
+                // 记录错误日志
+                logger.error("生成图片失败:{}",e.getMessage(),e);
+                return R.error("生成图片失败");
+            }
+            // 返回成功信息
+            return R.ok().put("url",url);
+
+        } catch (WxErrorException e) {
+            logger.error(e.getMessage(), e);
+            return R.error("微信接口调用失败: " + e.getMessage());
+        }
+    }
+
+
+
+    @Override
+    public R paymentByWxaCode(FsStorePaymentPayParam param) {
+        FsUser user = userMapper.selectFsUserById(param.getUserId());
+        if (user==null){
+            return R.error("用户不存在!");
+        }
+        Company company = companyService.selectCompanyById(param.getCompanyId());
+        if (company==null || company.getStatus()==0){
+            return R.error("服务商不存在,或已被停用!");
+        }
+        if(param.getPayMoney().compareTo(new BigDecimal(0.0))<1){
+            return R.error("支付金额必须大于0");
+        }
+        if (param.getCompanyUserId()!=null){
+            CompanyUser companyUser = companyUserService.selectCompanyUserById(param.getCompanyUserId());
+            if(companyUser == null || companyUser.getStatus().equals("1")){
+                return R.error("注册失败客服已停用,或不存在!");
+            }
+        }
+
+
+        //生成支付流水
+        String orderSn = IdUtil.getSnowflake(0, 0).nextIdStr();
+        FsStorePayment storePayment=new FsStorePayment();
+        storePayment.setCompanyId(param.getCompanyId());
+        //判断销售是否存在
+        if (param.getCompanyUserId()!=null){
+            storePayment.setCompanyUserId(param.getCompanyUserId());
+        }
+        storePayment.setStatus(0);
+        storePayment.setPayCode(orderSn);
+        storePayment.setPayMoney(param.getPayMoney());
+        storePayment.setCreateTime(new Date());
+        storePayment.setPayTypeCode("weixin");
+        storePayment.setBusinessType(1);
+        storePayment.setRemark("商城收款订单支付");
+        storePayment.setOpenId(user.getMaOpenId());
+        storePayment.setUserId(user.getUserId());
+        fsStorePaymentMapper.insertFsStorePayment(storePayment);
+
+        //汇付支付
+        HuiFuCreateOrder o = new HuiFuCreateOrder();
+        o.setTradeType("T_MINIAPP");
+        o.setOpenid(user.getMaOpenId());
+        o.setReqSeqId("payment-"+storePayment.getPayCode());
+        o.setTransAmt(storePayment.getPayMoney().toString());
+        o.setGoodsDesc("商城订单支付");
+        HuifuCreateOrderResult result = huiFuService.createOrder(o);
+        if(result.getResp_code()!=null&&(result.getResp_code().equals("00000000")||result.getResp_code().equals("00000100"))){
+            FsStorePayment mt=new FsStorePayment();
+            mt.setPaymentId(storePayment.getPaymentId());
+            mt.setTradeNo(result.getHf_seq_id());
+            fsStorePaymentMapper.updateFsStorePayment(mt);
+            Map<String, Object> resultMap = com.alibaba.fastjson.JSON.parseObject(result.getPay_info(), new TypeReference<Map<String, Object>>() {});
+            String s = (String) resultMap.get("package");
+            resultMap.put("packageValue",s);
+            return R.ok().put("result",resultMap);
+        }
+        else{
+            return R.error(result.getResp_desc());
+        }
+    }
+
 }

+ 14 - 0
fs-service/src/main/java/com/fs/hisStore/param/FsStorePaymentGetWxaCodeParam.java

@@ -0,0 +1,14 @@
+package com.fs.hisStore.param;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class FsStorePaymentGetWxaCodeParam {
+    private Long companyId;
+
+    private Long companyUserId;
+
+    private String appId;
+}

+ 5 - 4
fs-service/src/main/java/com/fs/hisStore/service/IFsStorePaymentScrmService.java

@@ -6,10 +6,7 @@ import java.util.Map;
 import com.alibaba.fastjson.JSONObject;
 import com.fs.common.core.domain.R;
 import com.fs.hisStore.domain.FsStorePaymentScrm;
-import com.fs.hisStore.param.FsStorePaymentPayParam;
-import com.fs.hisStore.param.FsStorePaymentParam;
-import com.fs.hisStore.param.FsStoreStatisticsParam;
-import com.fs.hisStore.param.WxSendRedPacketParam;
+import com.fs.hisStore.param.*;
 import com.fs.hisStore.vo.FsStorePaymentStatisticsVO;
 import com.fs.hisStore.vo.FsStorePaymentVO;
 
@@ -115,4 +112,8 @@ public interface IFsStorePaymentScrmService
     void bufaRedPacket();
 
     R sendRewardByTest(Long userId);
+
+    R getWxaCodeByPayment(FsStorePaymentGetWxaCodeParam param);
+
+    R paymentByWxaCode(FsStorePaymentPayParam param);
 }

+ 141 - 11
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStorePaymentScrmServiceImpl.java

@@ -1,21 +1,25 @@
 package com.fs.hisStore.service.impl;
 
+
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+
+import java.util.*;
+
 
 import cn.binarywang.wx.miniapp.api.WxMaService;
 import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.TypeReference;
 import com.fs.common.annotation.DataScope;
 import com.fs.common.config.FSSysConfig;
 import com.fs.common.core.domain.R;
+import com.fs.common.core.redis.RedisCache;
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.StringUtils;
+import com.fs.company.domain.Company;
 import com.fs.company.domain.CompanyUser;
 import com.fs.company.mapper.CompanyConfigMapper;
 import com.fs.company.service.ICompanyService;
@@ -26,20 +30,26 @@ import com.fs.course.config.RedPacketConfig;
 import com.fs.course.domain.FsCourseRedPacketLog;
 import com.fs.course.mapper.FsCourseRedPacketLogMapper;
 import com.fs.course.service.IFsCourseRedPacketLogService;
+import com.fs.his.config.FsSysConfig;
+import com.fs.his.domain.FsUser;
 import com.fs.his.domain.FsUserWx;
+import com.fs.his.service.IFsUserService;
 import com.fs.his.service.IFsUserWxService;
 import com.fs.his.utils.ConfigUtil;
+import com.fs.his.utils.HttpUtil;
 import com.fs.hisStore.enums.SysConfigEnum;
+import com.fs.hisStore.param.*;
+import com.fs.huifuPay.domain.HuiFuCreateOrder;
+import com.fs.huifuPay.domain.HuifuCreateOrderResult;
+import com.fs.huifuPay.service.HuiFuService;
 import com.fs.pay.pay.config.PayConfig;
 import com.fs.pay.pay.dto.WxJspayDTO;
-import com.fs.hisStore.param.FsStoreStatisticsParam;
-import com.fs.hisStore.param.WxSendRedPacketParam;
 import com.fs.hisStore.vo.FsStorePaymentStatisticsVO;
+import com.fs.system.oss.CloudStorageService;
+import com.fs.system.oss.OSSFactory;
 import com.fs.system.service.ISysConfigService;
 import com.fs.wx.miniapp.config.WxMaProperties;
 import com.fs.hisStore.domain.FsUserScrm;
-import com.fs.hisStore.param.FsStorePaymentPayParam;
-import com.fs.hisStore.param.FsStorePaymentParam;
 import com.fs.hisStore.service.IFsUserScrmService;
 import com.fs.hisStore.vo.FsStorePaymentVO;
 import com.fs.pay.service.IPayService;
@@ -54,6 +64,8 @@ import com.github.binarywang.wxpay.exception.WxPayException;
 import com.github.binarywang.wxpay.service.TransferService;
 import com.github.binarywang.wxpay.service.WxPayService;
 import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
+import com.google.common.reflect.TypeToken;
+import com.google.gson.Gson;
 import me.chanjar.weixin.common.error.WxErrorException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -104,6 +116,13 @@ public class FsStorePaymentScrmServiceImpl implements IFsStorePaymentScrmService
 
     @Autowired
     private CompanyConfigMapper companyConfigMapper;
+
+    @Autowired
+    private HuiFuService huiFuService;
+
+    @Autowired
+    private RedisCache redisCache;
+
     /**
      * 查询支付明细
      *
@@ -322,9 +341,9 @@ public class FsStorePaymentScrmServiceImpl implements IFsStorePaymentScrmService
         storePayment.setBankTransactionId(bankTransactionId);
         fsStorePaymentMapper.updateFsStorePayment(storePayment);
         //增加佣金
-        if(storePayment.getCompanyId()!=null&&storePayment.getCompanyId()>0){
-            companyService.addCompanyPaymentMoney(storePayment);
-        }
+//        if(storePayment.getCompanyId()!=null&&storePayment.getCompanyId()>0){
+//            companyService.addCompanyPaymentMoney(storePayment);
+//        }
         return "SUCCESS";
     }
 
@@ -768,4 +787,115 @@ public class FsStorePaymentScrmServiceImpl implements IFsStorePaymentScrmService
         }
         return R.ok();
         }
+
+
+    @Override
+    public R getWxaCodeByPayment(FsStorePaymentGetWxaCodeParam param)  {
+        final WxMaService wxMaService = WxMaConfiguration.getMaService(param.getAppId());
+        String scene;
+        //判断销售id
+        if (param.getCompanyUserId() == null){
+            scene = "companyId="+ param.getCompanyId();
+        }else {
+            scene = "companyId="+ param.getCompanyId()+"&"+"companyUserId="+ param.getCompanyUserId();
+        }
+        byte[] file;
+        try {
+            file = wxMaService.getQrcodeService().createWxaCodeUnlimitBytes(
+                    scene,
+                    "pages_user/user/pay",
+                    true,
+                    "release",
+                    430,
+                    true,
+                    null,
+                    false);
+
+            // 上传图片到存储桶
+            String suffix = ".png";
+            CloudStorageService storage = OSSFactory.build();
+            String url;
+            try {
+                url = storage.uploadSuffix(file, suffix);
+            }  catch (Exception e) {
+                // 记录错误日志
+                logger.error("生成图片失败:{}",e.getMessage(),e);
+                return R.error("生成图片失败");
+            }
+            redisCache.setCacheObject("company-wxa-code:"+param.getCompanyId(),url);
+            // 返回成功信息
+            return R.ok().put("url",url);
+
+        } catch (WxErrorException e) {
+            logger.error(e.getMessage(), e);
+            return R.error("微信接口调用失败: " + e.getMessage());
+        }
+    }
+
+
+    @Autowired
+    private IFsUserService fsUserService;
+
+    @Override
+    public R paymentByWxaCode(FsStorePaymentPayParam param) {
+        FsUser user = fsUserService.selectFsUserById(param.getUserId());
+        if (user==null){
+            return R.error("用户不存在!");
+        }
+        Company company = companyService.selectCompanyById(param.getCompanyId());
+        if (company==null || company.getStatus()==0){
+            return R.error("服务商不存在,或已被停用!");
+        }
+        if(param.getPayMoney().compareTo(new BigDecimal(0.0))<1){
+            return R.error("支付金额必须大于0");
+        }
+        if (param.getCompanyUserId()!=null){
+            CompanyUser companyUser = companyUserService.selectCompanyUserById(param.getCompanyUserId());
+            if(companyUser == null || companyUser.getStatus().equals("1")){
+                return R.error("注册失败客服已停用,或不存在!");
+            }
+        }
+
+
+        //生成支付流水
+        String orderSn = IdUtil.getSnowflake(0, 0).nextIdStr();
+        FsStorePaymentScrm storePayment=new FsStorePaymentScrm();
+        storePayment.setCompanyId(param.getCompanyId());
+        //判断销售是否存在
+        if (param.getCompanyUserId()!=null){
+            storePayment.setCompanyUserId(param.getCompanyUserId());
+        }
+        storePayment.setStatus(0);
+        storePayment.setPayCode(orderSn);
+        storePayment.setPayMoney(param.getPayMoney());
+        storePayment.setCreateTime(new Date());
+        storePayment.setPayTypeCode("weixin");
+        storePayment.setBusinessType(1);
+        storePayment.setRemark("商城收款订单支付");
+        storePayment.setOpenId(user.getMaOpenId());
+        storePayment.setUserId(user.getUserId());
+        fsStorePaymentMapper.insertFsStorePayment(storePayment);
+
+        //汇付支付
+        HuiFuCreateOrder o = new HuiFuCreateOrder();
+        o.setTradeType("T_MINIAPP");
+        o.setOpenid(user.getMaOpenId());
+        o.setReqSeqId("payment-"+storePayment.getPayCode());
+        o.setTransAmt(storePayment.getPayMoney().toString());
+        o.setGoodsDesc("商城订单支付");
+        HuifuCreateOrderResult result = huiFuService.createOrder(o);
+        if(result.getResp_code()!=null&&(result.getResp_code().equals("00000000")||result.getResp_code().equals("00000100"))){
+            FsStorePaymentScrm mt=new FsStorePaymentScrm();
+            mt.setPaymentId(storePayment.getPaymentId());
+            mt.setTradeNo(result.getHf_seq_id());
+            fsStorePaymentMapper.updateFsStorePayment(mt);
+            Map<String, Object> resultMap = JSON.parseObject(result.getPay_info(), new TypeReference<Map<String, Object>>() {});
+            String s = (String) resultMap.get("package");
+            resultMap.put("packageValue",s);
+            return R.ok().put("result",resultMap);
+        }
+        else{
+            return R.error(result.getResp_desc());
+        }
+    }
 }

+ 8 - 0
fs-user-app/src/main/java/com/fs/app/controller/CompanyUserController.java

@@ -173,4 +173,12 @@ public class CompanyUserController extends  AppBaseController {
 
     }
 
+    @ApiOperation("获取公司收款码")
+    @GetMapping("/getCompanyWxaCodeByPayment")
+    public R getCompanyWxaCodeByPayment(@RequestParam("companyId")Long companyId,HttpServletRequest request){
+        //获取用户码
+        String WxaCode = redisCache.getCacheObject("company-wxa-code:"+companyId);
+        return R.ok().put("data",WxaCode);
+    }
+
 }

+ 62 - 0
fs-user-app/src/main/java/com/fs/app/controller/PaymentController.java

@@ -0,0 +1,62 @@
+package com.fs.app.controller;
+
+
+import cn.binarywang.wx.miniapp.api.WxMaService;
+import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
+import com.fs.app.annotation.Login;
+import com.fs.common.annotation.RepeatSubmit;
+import com.fs.common.core.controller.BaseController;
+import com.fs.common.core.domain.R;
+import com.fs.common.utils.IpUtil;
+import com.fs.core.config.WxMaConfiguration;
+import com.fs.his.service.IFsStorePaymentService;
+import com.fs.hisStore.domain.FsUserScrm;
+import com.fs.hisStore.param.FsStorePaymentGetWxaCodeParam;
+import com.fs.hisStore.param.FsStorePaymentPayParam;
+import com.fs.hisStore.service.IFsStorePaymentScrmService;
+import com.fs.hisStore.service.IFsUserScrmService;
+import com.fs.wx.miniapp.config.WxMaProperties;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import me.chanjar.weixin.common.error.WxErrorException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+
+@Api("支付接口")
+@RestController
+@RequestMapping("/app/payment")
+public class PaymentController extends AppBaseController {
+    @Autowired
+    private WxMaProperties properties;
+    protected final Logger logger = LoggerFactory.getLogger(BaseController.class);
+
+    @Autowired
+    private IFsStorePaymentService paymentService;
+
+
+    @Login
+    @ApiOperation("收款订单支付")
+    @PostMapping("/paymentByWxaCode")
+    @RepeatSubmit
+    public R paymentByWxaCode(@Validated @RequestBody FsStorePaymentPayParam payment)
+    {
+        payment.setUserId(Long.parseLong(getUserId()));
+        return paymentService.paymentByWxaCode(payment);
+    }
+
+    @ApiOperation("生成收款页面小程序码")
+    @GetMapping("/getWxaCodeByPayment")
+    public R getWxaCodeByPayment(FsStorePaymentGetWxaCodeParam param)
+    {
+        return paymentService.getWxaCodeByPayment(param);
+    }
+
+
+
+
+}

+ 9 - 0
fs-user-app/src/main/java/com/fs/app/controller/store/CompanyUserScrmController.java

@@ -11,6 +11,7 @@ import com.fs.common.core.domain.R;
 import com.fs.common.core.redis.RedisCache;
 import com.fs.common.exception.CustomException;
 import com.fs.common.utils.sign.Md5Utils;
+import com.fs.company.domain.Company;
 import com.fs.company.domain.CompanyUser;
 import com.fs.company.domain.CompanyUserCard;
 import com.fs.company.param.CompanyUserLoginParam;
@@ -173,6 +174,14 @@ public class CompanyUserScrmController extends AppBaseController {
         }
     }
 
+    @ApiOperation("获取公司收款码")
+    @GetMapping("/getCompanyWxaCodeByPayment")
+    public R getCompanyWxaCodeByPayment(@RequestParam("companyId")Long companyId,HttpServletRequest request){
+        //获取用户码
+        String WxaCode = redisCache.getCacheObject("company-wxa-code:"+companyId);
+        return R.ok().put("data",WxaCode);
+    }
+
 
 
 }

+ 23 - 17
fs-user-app/src/main/java/com/fs/app/controller/store/PaymentController.java → fs-user-app/src/main/java/com/fs/app/controller/store/PaymentScrmController.java

@@ -3,6 +3,7 @@ package com.fs.app.controller.store;
 
 import cn.binarywang.wx.miniapp.api.WxMaService;
 import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
+import com.fs.app.annotation.Login;
 import com.fs.app.controller.AppBaseController;
 import com.fs.common.annotation.RepeatSubmit;
 import com.fs.common.core.controller.BaseController;
@@ -10,6 +11,7 @@ import com.fs.common.core.domain.R;
 import com.fs.common.utils.IpUtil;
 import com.fs.core.config.WxMaConfiguration;
 import com.fs.hisStore.domain.FsUserScrm;
+import com.fs.hisStore.param.FsStorePaymentGetWxaCodeParam;
 import com.fs.hisStore.param.FsStorePaymentPayParam;
 import com.fs.hisStore.service.IFsStorePaymentScrmService;
 import com.fs.hisStore.service.IFsUserScrmService;
@@ -21,18 +23,14 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
-import java.util.Date;
 
 @Api("支付接口")
 @RestController
 @RequestMapping("/store/app/payment")
-public class PaymentController extends AppBaseController {
+public class PaymentScrmController extends AppBaseController {
     @Autowired
     private WxMaProperties properties;
     protected final Logger logger = LoggerFactory.getLogger(BaseController.class);
@@ -41,6 +39,7 @@ public class PaymentController extends AppBaseController {
     private IFsStorePaymentScrmService paymentService;
     @Autowired
     private IFsUserScrmService userService;
+
     @ApiOperation("支付")
     @PostMapping("/payment")
     @RepeatSubmit
@@ -51,17 +50,7 @@ public class PaymentController extends AppBaseController {
             WxMaJscode2SessionResult session = wxService.getUserService().getSessionInfo(payment.getCode());
             FsUserScrm user=userService.selectFsUserByMaOpenId(session.getOpenid());
             if(user==null){
-                //创建
-                user=new FsUserScrm();
-                user.setUsername("");
-                user.setNickname("微信用户");
-                user.setStatus(1);
-                user.setMaOpenId(session.getOpenid());
-                user.setUnionId(session.getUnionid());
-                user.setIsWeixinAuth(0);
-                user.setLastIp(ip);
-                user.setCreateTime(new Date());
-                userService.insertFsUser(user);
+                return R.error("用户不存在,返回主页授权登录!");
             }
             payment.setUserId(user.getUserId());
             return paymentService.payment(payment);
@@ -74,6 +63,23 @@ public class PaymentController extends AppBaseController {
 
     }
 
+    @Login
+    @ApiOperation("收款订单支付")
+    @PostMapping("/paymentByWxaCode")
+    @RepeatSubmit
+    public R paymentByWxaCode(@Validated @RequestBody FsStorePaymentPayParam payment)
+    {
+        payment.setUserId(Long.parseLong(getUserId()));
+        return paymentService.paymentByWxaCode(payment);
+    }
+
+    @ApiOperation("生成收款页面小程序码")
+    @GetMapping("/getWxaCodeByPayment")
+    public R getWxaCodeByPayment(FsStorePaymentGetWxaCodeParam param)
+    {
+        return paymentService.getWxaCodeByPayment(param);
+    }
+