Pārlūkot izejas kodu

服务点充值,扣除

qzy 2 nedēļas atpakaļ
vecāks
revīzija
60fcdff55b
28 mainītis faili ar 958 papildinājumiem un 385 dzēšanām
  1. 2 3
      sp-core/sp-base/src/main/java/com/pj/project4sp/spcfg/SpCfgService.java
  2. 72 72
      sp-core/sp-base/src/main/java/com/pj/utils/cache/RedisUtil.java
  3. 10 4
      sp-service/level-one-server/src/main/java/com/pj/tb_order/TbOrderAppController.java
  4. 19 17
      sp-service/level-one-server/src/main/java/com/pj/tb_order/TbOrderService.java
  5. 1 1
      sp-service/level-one-server/src/main/java/com/pj/tb_people/TbPeople.java
  6. 4 0
      sp-service/level-one-server/src/main/java/com/pj/tb_people/TbPeopleMapper.java
  7. 6 1
      sp-service/level-one-server/src/main/java/com/pj/tb_people/TbPeopleMapper.xml
  8. 4 0
      sp-service/level-one-server/src/main/java/com/pj/tb_people/TbPeopleService.java
  9. 161 79
      sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/TbWalletAppController.java
  10. 9 1
      sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/TbWalletRecord.java
  11. 27 66
      sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/TbWalletRecordController.java
  12. 1 1
      sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/TbWalletRecordMapper.java
  13. 5 2
      sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/TbWalletRecordMapper.xml
  14. 14 15
      sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/TbWalletRecordService.java
  15. 17 0
      sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/WxPayConfiguration.java
  16. 7 1
      sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/WxPayProperties.java
  17. 103 0
      sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/app/AppServiceExample.java
  18. 93 0
      sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/app/AppServiceExtensionExample.java
  19. 47 0
      sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/vo/NotifyBO.java
  20. 3 1
      sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/vo/WalletRecordAppVo.java
  21. 0 6
      sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/vo/WalletRecordVo.java
  22. 25 2
      sp-service/level-one-server/src/main/java/com/pj/tb_wallet_topup/TbWalletTopup.java
  23. 32 65
      sp-service/level-one-server/src/main/java/com/pj/tb_wallet_topup/TbWalletTopupController.java
  24. 27 8
      sp-service/level-one-server/src/main/java/com/pj/tb_wallet_topup/TbWalletTopupMapper.java
  25. 8 3
      sp-service/level-one-server/src/main/java/com/pj/tb_wallet_topup/TbWalletTopupMapper.xml
  26. 177 37
      sp-service/level-one-server/src/main/java/com/pj/tb_wallet_topup/TbWalletTopupService.java
  27. 51 0
      sp-service/level-one-server/src/main/java/com/pj/tb_wallet_topup/WalletTopupAppController.java
  28. 33 0
      sp-service/level-one-server/src/main/java/com/pj/tb_wallet_topup/task/QueryPayTask.java

+ 2 - 3
sp-core/sp-base/src/main/java/com/pj/project4sp/spcfg/SpCfgService.java

@@ -1,6 +1,5 @@
 package com.pj.project4sp.spcfg;
 
-import com.pj.current.config.SystemObject;
 import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
@@ -19,7 +18,7 @@ public class SpCfgService {
 	/** 获得cfg_value 根据cfgName */
 	@Cacheable(value="sp_cfg_", key="#cfgName")	
 	public String getCfgValue(String cfgName){
-		return SP.publicMapper.getColumnByWhere("sp_cfg", "cfg_value", "cfg_name", cfgName);
+		return SP.publicMapper.getColumnByWhere("`sp-admin`.sp_cfg", "cfg_value", "cfg_name", cfgName);
 	}
 	
 	
@@ -27,7 +26,7 @@ public class SpCfgService {
 	@CacheEvict(value="sp_cfg_", key="#cfgName")
 	public int updateCfgValue(String cfgName, String cfgValue){
 		int	num=SpCfgUtil.getTradeNum();
-		return SP.publicMapper.updateColumnBy("sp_cfg", "cfg_value", cfgValue, "cfg_name", cfgName);
+		return SP.publicMapper.updateColumnBy("`sp-admin`.sp_cfg", "cfg_value", cfgValue, "cfg_name", cfgName);
 	}
 	
 	

+ 72 - 72
sp-core/sp-base/src/main/java/com/pj/utils/cache/RedisUtil.java

@@ -10,110 +10,110 @@ import org.springframework.stereotype.Component;
 
 /**
  * Redis工具类
- * @author kongyongshun
  *
+ * @author kongyongshun
  */
 @Component
 public class RedisUtil {
 
 
-	public static long ttl = 24* 7;	//默认超时时间,单位周,此为一周
-
-
-	/**
-	 * 对象专用
-	 */
-	public static RedisTemplate<String, Object> redisTemplate;
-	@Autowired
-	@SuppressWarnings({ "rawtypes", "unchecked" })
-	public void setRedisTemplate(RedisTemplate redisTemplate) {
-		RedisUtil.redisTemplate = redisTemplate;
-	}
+    public static long ttl = 24 * 7;    //默认超时时间,单位周,此为一周
 
-	/**
-	 * string专用
-	 */
-	static StringRedisTemplate stringRedisTemplate;
-	@Autowired
-	public void setStringRedisTemplate(StringRedisTemplate stringRedisTemplates) {
-		RedisUtil.stringRedisTemplate = stringRedisTemplates;
-	}
 
+    /**
+     * 对象专用
+     */
+    public static RedisTemplate<String, Object> redisTemplate;
 
+    @Autowired
+    @SuppressWarnings({"rawtypes", "unchecked"})
+    public void setRedisTemplate(RedisTemplate redisTemplate) {
+        RedisUtil.redisTemplate = redisTemplate;
+    }
 
-	/* * * * * * * * * * * * * * * * String操作 * * * * * * * * * * * * * * * * * * * * * * * * */
+    /**
+     * string专用
+     */
+    static StringRedisTemplate stringRedisTemplate;
 
+    @Autowired
+    public void setStringRedisTemplate(StringRedisTemplate stringRedisTemplates) {
+        RedisUtil.stringRedisTemplate = stringRedisTemplates;
+    }
 
-	// 默认7*24小时
-	public static void set(String key, String value) {
-		stringRedisTemplate.opsForValue().set(key, value, ttl, TimeUnit.HOURS);
-	}
-	public static void setBySECONDS(String key, String value,int time) {
-		stringRedisTemplate.opsForValue().set(key, value, ttl, TimeUnit.MINUTES);
-	}
 
-	// 写入,并设置时长,单位 Hours
-	public static void setByHour(String key, String value, int timeout) {
-		stringRedisTemplate.opsForValue().set(key, value, timeout, TimeUnit.HOURS);
-	}
-	
-	// 写入,并设置时长,单位 分钟 MINUTES
-	public static void setByMINUTES(String key, String value, int timeout) {
-		stringRedisTemplate.opsForValue().set(key, value, timeout, TimeUnit.MINUTES);
-	}
 
-	// 读取
-	public static String get(String key) {
-		return stringRedisTemplate.opsForValue().get(key);
-	}
+    /* * * * * * * * * * * * * * * * String操作 * * * * * * * * * * * * * * * * * * * * * * * * */
 
 
-	// 删除
-	public static void del(String key) {
-		stringRedisTemplate.delete(key);
-	}
+    // 默认7*24小时
+    public static void set(String key, String value) {
+        stringRedisTemplate.opsForValue().set(key, value, ttl, TimeUnit.HOURS);
+    }
 
+    public static void setBySECONDS(String key, String value, int time) {
+        stringRedisTemplate.opsForValue().set(key, value, ttl, TimeUnit.MINUTES);
+    }
 
-	/* * * * * * * * * * * * * * * * List集合操作 * * * * * * * * * * * * * * * * * * * * * * * * */
+    // 写入,并设置时长,单位 Hours
+    public static void setByHour(String key, String value, int timeout) {
+        stringRedisTemplate.opsForValue().set(key, value, timeout, TimeUnit.HOURS);
+    }
 
-	// 查询
-	public static List<Object> forListGet(String key){
-		return redisTemplate.opsForList().range(key, 0, -1);
-	}
+    // 写入,并设置时长,单位 分钟 MINUTES
+    public static void setByMINUTES(String key, String value, int timeout) {
+        stringRedisTemplate.opsForValue().set(key, value, timeout, TimeUnit.MINUTES);
+    }
 
-	// 追加键值
-	public static void forListAdd(String key, Object... args){
-		redisTemplate.opsForList().rightPushAll(key,  args);
-	}
+    // 读取
+    public static String get(String key) {
+        return stringRedisTemplate.opsForValue().get(key);
+    }
 
-	// 移除所有键值
-	public static void forListRemove(String key){
-		List<Object> list = forListGet(key);
-		for (int i = 0; i < list.size(); i++) {
-			redisTemplate.opsForList().remove(key, -1,list.get(i));
-		}
-	}
 
+    // 删除
+    public static void del(String key) {
+        stringRedisTemplate.delete(key);
+    }
 
-	/* * * * * * * * * * * * * * * * Object值操作 * * * * * * * * * * * * * * * * * * * * * * * * */
 
-	// 写入值
-	public static void forValueSet(String key, Object value){
-		redisTemplate.opsForValue().set(key, value, ttl, TimeUnit.HOURS);
-	}
+    /* * * * * * * * * * * * * * * * List集合操作 * * * * * * * * * * * * * * * * * * * * * * * * */
 
-	// 读取值
-	@SuppressWarnings("unchecked")
-	public static <T>T forValueGet(String key, Class<T> cs){
-		return (T) redisTemplate.opsForValue().get(key);
-	}
+    // 查询
+    public static List<Object> forListGet(String key) {
+        return redisTemplate.opsForList().range(key, 0, -1);
+    }
 
+    // 追加键值
+    public static void forListAdd(String key, Object... args) {
+        redisTemplate.opsForList().rightPushAll(key, args);
+    }
 
+    // 移除所有键值
+    public static void forListRemove(String key) {
+        List<Object> list = forListGet(key);
+        for (int i = 0; i < list.size(); i++) {
+            redisTemplate.opsForList().remove(key, -1, list.get(i));
+        }
+    }
 
+    public static void forListRemove(String key, Object value) {
+        redisTemplate.opsForList().remove(key, 1, value);
+    }
 
 
+    /* * * * * * * * * * * * * * * * Object值操作 * * * * * * * * * * * * * * * * * * * * * * * * */
 
+    // 写入值
+    public static void forValueSet(String key, Object value) {
+        redisTemplate.opsForValue().set(key, value, ttl, TimeUnit.HOURS);
+    }
 
+    // 读取值
+    @SuppressWarnings("unchecked")
+    public static <T> T forValueGet(String key, Class<T> cs) {
+        return (T) redisTemplate.opsForValue().get(key);
+    }
 
 
 }

+ 10 - 4
sp-service/level-one-server/src/main/java/com/pj/tb_order/TbOrderAppController.java

@@ -12,6 +12,7 @@ import com.pj.tb_people.TbPeopleService;
 import com.pj.utils.sg.AjaxJson;
 import com.pj.utils.so.SoMap;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.Date;
@@ -81,6 +82,9 @@ public class TbOrderAppController {
 	 */
 	@RequestMapping("cancelOrder")
 	public AjaxJson cancelOrder(Long orderId) {
+		if (!StpAPPUserUtil.isLogin()){
+			return AjaxJson.getError("未登录");
+		}
 		boolean result = tbOrderService.cancelOrder(orderId);
 		if(result) return AjaxJson.getSuccess();
 		return AjaxJson.getError();
@@ -91,7 +95,9 @@ public class TbOrderAppController {
 	 */
 	@PostMapping("updateEnterpriseConfirm")
 	public AjaxJson updateEnterpriseConfirm(TbOrder order) {
-
+		if (!StpAPPUserUtil.isLogin()){
+			return AjaxJson.getError("未登录");
+		}
 		return AjaxJson.toAjax(tbOrderService.updateEnterpriseConfirm(order));
 	}
 
@@ -158,13 +164,13 @@ public class TbOrderAppController {
 		if(tbOrderService.getById(id).getIsCheckoffWallet().equals(0)) {
 			TbPeople tbPeople = tbPeopleService.getById(appLoginInfo.getFk());
 			if (tbPeople.getWallet() < SpCfgUtil.getTradeNum()) {
-				return AjaxJson.getError("余额不足!");
+				return AjaxJson.getError("剩余服务点数不足!");
 			}
 			tbOrderService.up(id,upPrice,tbPeople);
-			return AjaxJson.getSuccess();
+			return AjaxJson.getSuccessData(SpCfgUtil.getTradeNum());
 		}else {
 			tbOrderService.up(id,upPrice,null);
-			return AjaxJson.getSuccess();
+			return AjaxJson.getSuccessData(0);
 		}
 	}
 

+ 19 - 17
sp-service/level-one-server/src/main/java/com/pj/tb_order/TbOrderService.java

@@ -49,6 +49,7 @@ import com.pj.tb_trade_area.TbTradeArea;
 import com.pj.tb_trade_area.TbTradeAreaService;
 import com.pj.tb_wallet_record.TbWalletRecord;
 import com.pj.tb_wallet_record.TbWalletRecordService;
+import com.pj.tb_wallet_topup.TbWalletTopupService;
 import com.pj.utils.sg.AjaxError;
 import com.pj.utils.so.SoMap;
 import io.swagger.models.auth.In;
@@ -109,10 +110,13 @@ public class TbOrderService extends ServiceImpl<TbOrderMapper, TbOrder> implemen
     private HtTradeSettlementService htTradeSettlementService;
     @Autowired
     private PaymentServerInterface paymentServerInterface;
-    @Autowired
-    private TbTradeAreaService tbTradeAreaService;
+    @Resource
+    private TbWalletTopupService tbWalletTopupService;
+
 
-    /** 底层 Service 对象 */
+    /**
+     * 底层 Service 对象
+     */
     @Autowired
     TbWalletRecordService tbWalletRecordService;
 
@@ -122,12 +126,6 @@ public class TbOrderService extends ServiceImpl<TbOrderMapper, TbOrder> implemen
     @Autowired
     private AdminInterface adminInterface;
 
-    /**
-     * 删
-     */
-    void delete(Long id) {
-        removeById(id);
-    }
 
     /**
      * 改
@@ -563,8 +561,8 @@ public class TbOrderService extends ServiceImpl<TbOrderMapper, TbOrder> implemen
             tbOrder.setSxb010Status(1)
                     .setSxb010StatusTime(new Date());
             //如果已经过了卡三,则补发送一次通关报文给银行
-            if(tbOrder.getFinishStatus()==1){
-                HtTradeSettlement htTradeSettlement=htTradeSettlementService.getById(tbOrder.getSaleMainId());
+            if (tbOrder.getFinishStatus() == 1) {
+                HtTradeSettlement htTradeSettlement = htTradeSettlementService.getById(tbOrder.getSaleMainId());
                 //TODO: 2023/8/30 补发通关报文
                 PaymentDto paymentDto2 = new PaymentDto();
                 paymentDto2.setTradeNos(tradeNo);
@@ -1126,21 +1124,23 @@ public class TbOrderService extends ServiceImpl<TbOrderMapper, TbOrder> implemen
     }
 
     public void up(Long id, String upPrice, TbPeople tbPeople) {
-        TbOrder tbOrder =super.getById(id);
+        TbOrder tbOrder = super.getById(id);
         tbOrder.setId(id);
         // -plj 2024-09-5 11:08:00 修改上架扣除服务点处理
-        if (tbPeople!= null) {
+        if (tbPeople != null) {
             tbOrder.setIsCheckoffWallet(1);   //1=已扣除
         }
         tbOrder.setUpPrice(new BigDecimal(upPrice)).setUpTime(new Date()).setUpStatus(2);
         int i = tbOrderMapper.updateById(tbOrder);
-        if (i== 1 && tbPeople != null) {
-            double beforeAmount=tbPeople.getWallet();
-            double afterAmount=tbPeople.getWallet()- SpCfgUtil.getTradeNum();
+        if (i == 1 && tbPeople != null) {
+            double beforeAmount = tbPeople.getWallet();
+            int afterAmount = tbPeople.getWallet() - SpCfgUtil.getTradeNum();
             Date date = new Date();
             tbPeopleService.updateById(tbPeople.setWallet(afterAmount));
             tbWalletRecordService.save(new TbWalletRecord()
                     .setPeopleId(tbPeople.getId().toString())
+                    .setPeopleName(tbPeople.getName())
+                    .setVeNo(tbOrder.getVeNo())
                     .setAmount(SpCfgUtil.getTradeNum().toString())
                     .setBeforeAmount(beforeAmount)
                     .setAfterAmount(afterAmount)
@@ -1152,7 +1152,9 @@ public class TbOrderService extends ServiceImpl<TbOrderMapper, TbOrder> implemen
                     .setCreateBy(StpAPPUserUtil.getAPPLoginInfo().getLoginId().toString())
                     .setCreateName(StpAPPUserUtil.getAPPLoginInfo().getLoginName())
                     .setDeleteStatus(DeleteStatus.DELETE_STATUS_ON.getCode())
-                );
+            );
+            tbWalletTopupService.subAmount(tbOrder.getBuyUserId());
+
         }
         if (i != 1) {
             throw new AjaxError("上架失败");

+ 1 - 1
sp-service/level-one-server/src/main/java/com/pj/tb_people/TbPeople.java

@@ -307,7 +307,7 @@ public class TbPeople extends Model<TbPeople> implements Serializable {
 	/**
 	 *  服务点
 	 */
-	private Double wallet;
+	private Integer wallet;
 
 	/**
 	 *  微信OpenId

+ 4 - 0
sp-service/level-one-server/src/main/java/com/pj/tb_people/TbPeopleMapper.java

@@ -2,6 +2,8 @@ package com.pj.tb_people;
 
 import java.util.List;
 
+import cn.hutool.core.util.NumberUtil;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import org.apache.ibatis.annotations.Mapper;
 
 import com.pj.utils.so.*;
@@ -34,4 +36,6 @@ public interface TbPeopleMapper extends BaseMapper <TbPeople> {
 	int updateApplyStatus(@Param("status") int status,@Param("peopleId") Long peopleId);
 	List<TbPeople> getLeftPeople();
 
+	void updatePeopleWallet(@Param("id") Long id, @Param("amount") Integer amount);
+
 }

+ 6 - 1
sp-service/level-one-server/src/main/java/com/pj/tb_people/TbPeopleMapper.xml

@@ -47,8 +47,13 @@
 		</where>
 
 	</update>
+    <update id="updatePeopleWallet">
+        update tb_people
+        set wallet=wallet + #{amount}
+        where id = #{id}
+    </update>
 
-	<select id="checkApplyExist" resultType="Integer">
+    <select id="checkApplyExist" resultType="Integer">
 		select  count(1) from tb_people_apply where people_id=#{peopleId} and status=0
 	</select>
 

+ 4 - 0
sp-service/level-one-server/src/main/java/com/pj/tb_people/TbPeopleService.java

@@ -45,6 +45,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
+import org.yaml.snakeyaml.events.Event;
 
 import javax.annotation.Resource;
 import javax.swing.filechooser.FileSystemView;
@@ -810,4 +811,7 @@ public class TbPeopleService extends ServiceImpl<TbPeopleMapper, TbPeople> imple
     }
 
 
+    public void updatePeopleWallet(String id, Integer amount) {
+        tbPeopleMapper.updatePeopleWallet(Long.parseLong(id),amount);
+    }
 }

+ 161 - 79
sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/TbWalletAppController.java

@@ -1,13 +1,19 @@
 package com.pj.tb_wallet_record;
 
 import cn.dev33.satoken.spring.SpringMVCUtil;
+import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.XmlUtil;
+import cn.hutool.json.JSONUtil;
+import cn.hutool.log.StaticLog;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.github.binarywang.wxpay.bean.ecommerce.RefundsRequest;
 import com.github.binarywang.wxpay.bean.entpay.EntPayRequest;
 import com.github.binarywang.wxpay.bean.entpay.EntPayResult;
 import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
 import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
 import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest;
 import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
+import com.github.binarywang.wxpay.config.WxPayConfig;
 import com.github.binarywang.wxpay.constant.WxPayConstants;
 import com.github.binarywang.wxpay.exception.WxPayException;
 import com.github.binarywang.wxpay.service.WxPayService;
@@ -18,33 +24,51 @@ import com.pj.enummj.DeleteStatus;
 import com.pj.tb_banner.TbBanner;
 import com.pj.tb_people.TbPeople;
 import com.pj.tb_people.TbPeopleService;
+import com.pj.tb_wallet_record.vo.NotifyBO;
 import com.pj.tb_wallet_record.vo.WalletRecordAppVo;
 import com.pj.tb_wallet_topdown.TbWalletTopdown;
 import com.pj.tb_wallet_topdown.TbWalletTopdownService;
 import com.pj.tb_wallet_topup.TbWalletTopup;
 import com.pj.tb_wallet_topup.TbWalletTopupService;
 import com.pj.utils.LogUtil;
+import com.pj.utils.cache.RedisUtil;
 import com.pj.utils.sg.AjaxJson;
 import com.pj.utils.sg.WebNbUtil;
 import com.pj.utils.so.SoMap;
+import com.wechat.pay.java.core.Config;
+import com.wechat.pay.java.core.RSAAutoCertificateConfig;
+import com.wechat.pay.java.service.payments.app.AppService;
+import com.wechat.pay.java.service.payments.app.AppServiceExtension;
+import com.wechat.pay.java.service.payments.app.model.Amount;
+import com.wechat.pay.java.service.payments.app.model.PrepayRequest;
+import com.wechat.pay.java.service.payments.app.model.PrepayResponse;
+import com.wechat.pay.java.service.payments.app.model.PrepayWithRequestPaymentResponse;
+import io.swagger.models.auth.In;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.Resource;
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
-import java.util.Date;
-import java.util.List;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.util.*;
 
 
 /**
  * Controller: tb_wallet_record -- 服务点交易记录
+ *
  * @author plj
  */
 
 @RestController
 @RequestMapping("/app/WalletManage/")
+@Slf4j
 public class TbWalletAppController {
 
     public static final String CZ_TABLE_NAME = "topup";
@@ -56,11 +80,15 @@ public class TbWalletAppController {
     @Autowired
     TbWalletRecordService tbWalletRecordService;
 
-    /** 底层 Service 对象 */
+    /**
+     * 底层 Service 对象
+     */
     @Autowired
     TbWalletTopupService tbWalletTopupService;
 
-    /** 底层 Service 对象 */
+    /**
+     * 底层 Service 对象
+     */
     @Autowired
     TbWalletTopdownService tbWalletTopdownService;
 
@@ -70,11 +98,11 @@ public class TbWalletAppController {
     @Autowired
     TbPeopleService tbPeopleService;
 
-    /**
-     * 微信支付 Service 对象
-     */
-    @Autowired
-    private WxPayService wxService;
+
+    @Resource
+    private AppServiceExtension appServiceExtension;
+    @Resource
+    private WxPayProperties wxPayProperties;
 
 
     /**
@@ -85,107 +113,129 @@ public class TbWalletAppController {
     @RequestMapping("getList")
     public AjaxJson getList() {
         SoMap so = SoMap.getRequestSoMap();
-        if(StpAPPUserUtil.getAPPLoginInfo().getUserType() == 1){
+        Integer userType = StpAPPUserUtil.getAPPLoginInfo().getUserType();
+        if (userType == 1 || userType == 2) {
             List<WalletRecordAppVo> list = tbWalletRecordService.getAPPList(so.startPage());
             if (list.size() == 0) return AjaxJson.getSuccess("暂无更多的订单消息!");
             return AjaxJson.getPageData(so.getDataCount(), list);
-        }else{
-            return AjaxJson.getError("边民用户才能查看服务点交易记录!");
+        } else {
+            return AjaxJson.getError("暂无更多的订单消息!");
         }
     }
 
 
-    /** 查服务点充值 - 根据id */
+    /**
+     * 查服务点充值 - 根据id
+     */
     @RequestMapping("getTopUpById")
-    public AjaxJson getTopUpById(Long id){
+    public AjaxJson getTopUpById(Long id) {
         TbWalletTopup t = tbWalletTopupService.getById(id);
         return AjaxJson.getSuccessData(t);
     }
 
 
-    /** 查服务点提现- 根据id */
+    /**
+     * 查服务点提现- 根据id
+     */
     @RequestMapping("getTopDownById")
-    public AjaxJson getTopDownById(Long id){
+    public AjaxJson getTopDownById(Long id) {
         TbWalletTopdown t = tbWalletTopdownService.getById(id);
         return AjaxJson.getSuccessData(t);
     }
 
 
-    /** 查服务点扣除 - 根据id */
+    /**
+     * 查服务点扣除 - 根据id
+     */
     @RequestMapping("getWalletRecordById")
-    public AjaxJson getWalletRecordById(Long id){
+    public AjaxJson getWalletRecordById(Long id) {
         TbWalletRecord t = tbWalletRecordService.getById(id);
         return AjaxJson.getSuccessData(t);
     }
+
     /*
-    * 服务点充值
+     * 服务点充值
      */
     @RequestMapping("topupSave")
-    public AjaxJson topupSave(@RequestParam("amount") Integer amount,@RequestParam("goodsName")String goodsName) {
+    public AjaxJson topupSave(@RequestParam("amount") Integer amount, @RequestParam("goodsName") String goodsName) {
         //获取登录人
         APPLoginUserInfo appLoginInfo = StpAPPUserUtil.getAPPLoginInfo();
         TbPeople tbPeople = tbPeopleService.getById(appLoginInfo.getFk());
-        if(StringUtils.isBlank(tbPeople.getWxOpenId())){
-            return AjaxJson.getError("未绑定微信用户!");
-        }
         try {
             TbWalletTopup tbWalletTopup = new TbWalletTopup();
             Date date = new Date();
-            tbWalletTopup.setMchid(this.wxService.getConfig().getMchId());
-            tbWalletTopup.setOutTradeNo(CZ_TABLE_NAME+System.currentTimeMillis());
+            String tradeNo = CZ_TABLE_NAME + System.currentTimeMillis();
+            tbWalletTopup.setMchid(wxPayProperties.getMchId());
+            tbWalletTopup.setOutTradeNo(tradeNo);
             tbWalletTopup.setGoodsName(goodsName);
-            tbWalletTopup.setAmount(amount.toString());
+            tbWalletTopup.setAmount(amount);
+            tbWalletTopup.setBeforeAmount(tbPeople.getWallet());
+            tbWalletTopup.setAfterAmount(tbPeople.getWallet() + amount);
             tbWalletTopup.setPeopleId(tbPeople.getId().toString());
             tbWalletTopup.setTopupTime(date);
             tbWalletTopup.setCreateTime(date);
             tbWalletTopup.setCreateBy(appLoginInfo.getLoginId().toString());
             tbWalletTopup.setCreateName(appLoginInfo.getLoginName());
 
-            //调用统一下单接口,并组装生成支付所需参数对象
-            WxPayUnifiedOrderRequest request = new WxPayUnifiedOrderRequest();
-            // 商品描述
-            request.setBody(tbWalletTopup.getGoodsName());
-            // 商户订单编号
-            request.setOutTradeNo(tbWalletTopup.getOutTradeNo());
-            //支付金额
-            request.setTotalFee(BaseWxPayRequest.yuanToFen(tbWalletTopup.getAmount()));
-            request.setSpbillCreateIp(WebNbUtil.getIP(SpringMVCUtil.getRequest()));
-            // 回调地址
-            request.setNotifyUrl(wxService.getConfig().getNotifyUrl());
-            // 交易类型APP
-            request.setTradeType(wxService.getConfig().getTradeType());
-            request.setOpenid(tbPeople.getWxOpenId());
-            WxPayMpOrderResult data = wxService.createOrder(request);
-            // 业务处理
-            tbWalletTopup.setTransactionId(data.getPackageValue());
+            PrepayWithRequestPaymentResponse response = prepay(tradeNo, BaseWxPayRequest.yuanToFen(tbWalletTopup.getAmount() + ""));
+//            StaticLog.info("response:{}",response);
             // 付款中
-            tbWalletTopup.setPayStatus(1);
+            tbWalletTopup.setPayStatus(1)
+                    .setPrepayid(response.getPrepayId());
             tbWalletTopupService.save(tbWalletTopup);
-            return AjaxJson.getSuccess();
-        } catch (WxPayException e) {
-            e.printStackTrace();
-            return AjaxJson.getError("微信支付失败," + e.getReturnMsg());
-        }catch (Exception e) {
+            Map<String, Object> result = new HashMap<>();
+            result.put("appid", response.getAppid());
+            result.put("noncestr", response.getNonceStr());
+            result.put("package", response.getPackageVal());
+            result.put("partnerid", response.getPartnerId());
+            result.put("prepayid", response.getPrepayId());
+            result.put("timestamp", response.getTimestamp());
+            result.put("sign", response.getSign());
+            RedisUtil.forListAdd(wxPayProperties.getMchId() + "-" + wxPayProperties.getAppId(), tradeNo + "-" + System.currentTimeMillis() / 1000);
+            return AjaxJson.getSuccessData(result);
+        } catch (Exception e) {
             e.printStackTrace();
-            return AjaxJson.getError("下单失败," + e.getMessage());
+            return AjaxJson.getError("微信支付失败," + e.getMessage());
         }
     }
 
+    /**
+     * APP支付下单
+     */
+    public PrepayWithRequestPaymentResponse prepay(String tradeNo, Integer fee) {
+
+        PrepayRequest request = new PrepayRequest();
+        // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
+        request.setAppid(wxPayProperties.getAppId());
+        request.setMchid(wxPayProperties.getMchId());
+        request.setOutTradeNo(tradeNo);
+        request.setDescription(wxPayProperties.getGoodsDescription());
+        request.setNotifyUrl(wxPayProperties.getNotifyUrl());
+        Amount amount = new Amount();
+        amount.setTotal(1);
+        amount.setCurrency("CNY");
+        request.setAmount(amount);
+        // 调用接口
+        return appServiceExtension.prepayWithRequestPayment(request);
+    }
+
+
     /*
-    * 服务点提现
+     * 服务点提现
      */
     @RequestMapping("topdownSave")
-    public AjaxJson topdownSave(@RequestParam("amount") Integer amount,@RequestParam("goodsName")String goodsName) {
+    public AjaxJson topdownSave(@RequestParam("amount") Integer amount, @RequestParam("goodsName") String goodsName) {
         //获取登录人
         APPLoginUserInfo appLoginInfo = StpAPPUserUtil.getAPPLoginInfo();
         TbPeople tbPeople = tbPeopleService.getById(appLoginInfo.getFk());
         if (tbPeople.getWallet() < amount) {
-            return AjaxJson.getError("余额不足!");
+            return AjaxJson.getError("可提现点数不足!");
         }
+        tbPeople.setWallet(tbPeople.getWallet() - amount);
         try {
             TbWalletTopdown tbWalletTopdown = new TbWalletTopdown();
             Date date = new Date();
-            tbWalletTopdown.setMchid(this.wxService.getConfig().getMchId());
+            tbWalletTopdown.setMchid(wxPayProperties.getMchId());
             tbWalletTopdown.setOutTradeNo(TX_TABLE_NAME + System.currentTimeMillis());
             tbWalletTopdown.setGoodsName(goodsName);
             tbWalletTopdown.setAmount(amount.toString());
@@ -195,40 +245,55 @@ public class TbWalletAppController {
             tbWalletTopdown.setCreateBy(appLoginInfo.getLoginId().toString());
             tbWalletTopdown.setCreateName(appLoginInfo.getLoginName());
 
-            //调用企业付款到零钱接口,并组装接口所需参数对象
-            EntPayRequest request = new EntPayRequest();
-            // 商品描述
-            request.setDescription(tbWalletTopdown.getGoodsName());
-            // 商户订单编号
-            request.setPartnerTradeNo(tbWalletTopdown.getOutTradeNo());
-            //支付金额
-            request.setAmount(BaseWxPayRequest.yuanToFen(tbWalletTopdown.getAmount()));
-            request.setSpbillCreateIp(WebNbUtil.getIP(SpringMVCUtil.getRequest()));
-            // 交易类型APP
-            request.setCheckName(WxPayConstants.CheckNameOption.FORCE_CHECK);
-            request.setReUserName(tbPeople.getBankName());
-            request.setOpenid(tbPeople.getWxOpenId());
-            EntPayResult data = this.wxService.getEntPayService().entPay(request);
-            // 业务处理
-            tbWalletTopdown.setTransactionId(data.getPaymentNo());
+            List<TbWalletTopup> list = tbWalletTopupService.findRefundList(tbPeople.getId());
+
+            for (TbWalletTopup tbWalletTopup : list) {
+                //剩余提现点数
+                int refundMoney = tbWalletTopup.getAmount() - tbWalletTopup.getCutCount() - tbWalletTopup.getRefundCount();
+                if (refundMoney > amount) {
+                    //提不完
+                    refundMoney = amount;
+                    tbWalletTopup.setRefundCount(amount);
+                    amount=0;
+                } else {
+                    tbWalletTopup.setRefundCount(refundMoney);
+                    amount = amount - refundMoney;
+                }
+                int total = BaseWxPayRequest.yuanToFen(tbWalletTopup.getAmount() + "");
+                RefundsRequest request = new RefundsRequest();
+                RefundsRequest.Amount refund = RefundsRequest.Amount.builder()
+                        .total(total)
+                        .currency("CNY")
+                        .refund(BaseWxPayRequest.yuanToFen(refundMoney + ""))
+                        .build();
+                request.setAmount(refund);
+                request.setTransactionId(tbWalletTopup.getTransactionId());
+                request.setOutTradeNo(tbWalletTopup.getOutTradeNo());
+                request.setReason("服务点提现");
+                request.setSpAppid(wxPayProperties.getAppId());
+                request.setSubMchid(wxPayProperties.getMchId());
+                request.setNotifyUrl(wxPayProperties.getNotifyUrl());
+                tbWalletTopupService.updateById(tbWalletTopup);
+                if (amount == 0) {
+                    break;
+                }
+            }
             // 成功
             tbWalletTopdown.setPayStatus(2);
             tbWalletTopdownService.updateById(tbWalletTopdown);
-            tbPeople.setWallet(tbPeople.getWallet()-Double.parseDouble(tbWalletTopdown.getAmount()));
+
             tbPeopleService.updateById(tbPeople);
             return AjaxJson.getSuccess();
-        } catch (WxPayException e) {
-            e.printStackTrace();
-            return AjaxJson.getError("微信支付失败," + e.getReturnMsg());
         } catch (Exception e) {
             e.printStackTrace();
-            return AjaxJson.getError("下单失败," + e.getMessage());
+            return AjaxJson.getError("提现失败," + e.getMessage());
         }
 
     }
 
     /**
      * 微信支付回调接口
+     *
      * @return
      */
     @RequestMapping(value = "/wxPay/notify", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")
@@ -249,7 +314,8 @@ public class TbWalletAppController {
             in.close();
             //xml数据
             String reponseXml = new String(out.toByteArray(), "utf-8");
-            WxPayOrderNotifyResult result = wxService.parseOrderNotifyResult(reponseXml);
+//            WxPayOrderNotifyResult result = wxService.parseOrderNotifyResult(reponseXml);
+            WxPayOrderNotifyResult result = null;
             String resultCode = result.getResultCode();
             String outTradeNo = result.getOutTradeNo();
             if ("FAIL".equalsIgnoreCase(resultCode)) {
@@ -258,15 +324,15 @@ public class TbWalletAppController {
             } else if ("SUCCESS".equalsIgnoreCase(resultCode)) {
                 LogUtil.info("订单" + outTradeNo + "支付成功");
                 // 充值数据处理
-                if(outTradeNo.indexOf(CZ_TABLE_NAME)>-1){
+                if (outTradeNo.indexOf(CZ_TABLE_NAME) > -1) {
                     QueryWrapper<TbWalletTopup> queryWrapper = new QueryWrapper<>();
                     queryWrapper.eq("outTradeNo", outTradeNo);
-                    TbWalletTopup tbWalletTopup=tbWalletTopupService.list(queryWrapper).get(0);
+                    TbWalletTopup tbWalletTopup = tbWalletTopupService.list(queryWrapper).get(0);
                     tbWalletTopup.setPayStatus(2);
                     tbWalletTopupService.updateById(tbWalletTopup);
 
                     TbPeople tbPeople = tbPeopleService.getById(tbWalletTopup.getPeopleId());
-                    tbPeople.setWallet(tbPeople.getWallet()+Double.parseDouble(tbWalletTopup.getAmount()));
+                    tbPeople.setWallet(tbPeople.getWallet() + tbWalletTopup.getAmount());
                     tbPeopleService.updateById(tbPeople);
                 }
                 response.getWriter().write(setXml("SUCCESS", "OK"));
@@ -280,6 +346,22 @@ public class TbWalletAppController {
     public static String setXml(String returnCode, String returnMsg) {
         return "<xml><return_code><![CDATA[" + returnCode + "]]></return_code><return_msg><![CDATA[" + returnMsg + "]]></return_msg></xml>";
     }
+
+    @RequestMapping(value = "notify")
+    public void notify(@RequestBody NotifyBO notifyBO, HttpServletResponse response) throws Exception {
+        log.info("wx pay notify;{}", JSONUtil.toJsonStr(notifyBO));
+        response.setContentType("application/json");
+        response.setCharacterEncoding("UTF-8");
+        Writer writer = response.getWriter();
+        Map<String, String> result = new HashMap<>();
+        result.put("return_code", "SUCCESS");
+        result.put("return_msg", "OK");
+        notifyBO.setTradeStatus("SUCCESS");
+        tbWalletTopupService.WxNotify(notifyBO);
+        writer.write(XmlUtil.mapToXmlStr(result));
+        writer.flush();
+        writer.close();
+    }
 }
 
 

+ 9 - 1
sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/TbWalletRecord.java

@@ -50,7 +50,15 @@ public class TbWalletRecord extends Model<TbWalletRecord> implements Serializabl
 	/**
 	 * 边民id 
 	 */
-	private String peopleId;	
+	private String peopleId;
+	/**
+	 * 边民
+	 */
+	private String peopleName;
+	/**
+	 * 车牌
+	 */
+	private String veNo;
 
 	/**
 	 * 交易前点数 

+ 27 - 66
sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/TbWalletRecordController.java

@@ -17,81 +17,42 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
 
 /**
  * Controller: tb_wallet_record -- 服务点交易记录
- * @author plj 
+ *
+ * @author plj
  */
 @RestController
 @RequestMapping("/TbWalletRecord/")
 public class TbWalletRecordController {
 
-	/** 底层 Service 对象 */
-	@Autowired
-	TbWalletRecordService tbWalletRecordService;
+    /**
+     * 底层 Service 对象
+     */
+    @Autowired
+    TbWalletRecordService tbWalletRecordService;
 
-	/** 增 */  
-	@RequestMapping("add")
-	@SaCheckPermission(TbWalletRecord.PERMISSION_CODE_ADD)
-	public AjaxJson add(TbWalletRecord t){
-		tbWalletRecordService.add(t);
-		t = tbWalletRecordService.getById(SP.publicMapper.getPrimarykey());
-		return AjaxJson.getSuccessData(t);
-	}
 
-	/** 删 */  
-	@RequestMapping("delete")
-	@SaCheckPermission(TbWalletRecord.PERMISSION_CODE_DEL)
-	public AjaxJson delete(Long id){
-		 tbWalletRecordService.delete(id);
-		return AjaxJson.getSuccess();
-	}
-	
-	/** 删 - 根据id列表 */  
-	@RequestMapping("deleteByIds")
-	@SaCheckPermission(TbWalletRecord.PERMISSION_CODE_DEL)
-	public AjaxJson deleteByIds(){
-		List<Long> ids = SoMap.getRequestSoMap().getListByComma("ids", long.class); 
-		int line = SP.publicMapper.deleteByIds(TbWalletRecord.TABLE_NAME, ids);
-		return AjaxJson.getByLine(line);
-	}
-	
-	/** 改 */  
-	@RequestMapping("update")
-	@SaCheckPermission(TbWalletRecord.PERMISSION_CODE_EDIT)
-	public AjaxJson update(TbWalletRecord t){
-		tbWalletRecordService.update(t);
-		return AjaxJson.getSuccess();
-	}
+    /**
+     * 查 - 根据id
+     */
+    @RequestMapping("getById")
+    @SaCheckPermission(TbWalletRecord.PERMISSION_CODE)
+    public AjaxJson getById(Long id) {
+        TbWalletRecord t = tbWalletRecordService.getById(id);
+        return AjaxJson.getSuccessData(t);
+    }
+
+    /**
+     * 查集合 - 根据条件(参数为空时代表忽略指定条件)
+     */
+    @RequestMapping("getList")
+    @SaCheckPermission(TbWalletRecord.PERMISSION_CODE)
+    public AjaxJson getList() {
+        SoMap so = SoMap.getRequestSoMap();
+        List<TbWalletRecord> list = tbWalletRecordService.getList(so.startPage());
+        return AjaxJson.getPageData(so.getDataCount(), list);
+    }
 
-	/** 查 - 根据id */  
-	@RequestMapping("getById")
-		@SaCheckPermission(TbWalletRecord.PERMISSION_CODE)
-	public AjaxJson getById(Long id){
-		TbWalletRecord t = tbWalletRecordService.getById(id);
-		return AjaxJson.getSuccessData(t);
-	}
 
-	/** 查集合 - 根据条件(参数为空时代表忽略指定条件) */  
-	@RequestMapping("getList")
-		@SaCheckPermission(TbWalletRecord.PERMISSION_CODE)
-	public AjaxJson getList() { 
-		SoMap so = SoMap.getRequestSoMap();
-		List<WalletRecordVo> list = tbWalletRecordService.getList(so.startPage());
-		return AjaxJson.getPageData(so.getDataCount(), list);
-	}
-	
-	
-	
-	/** 改 - 删除状态(0=禁用,1=启用) */  
-	@RequestMapping("updateDeleteStatus")
-	@SaCheckPermission(TbWalletRecord.PERMISSION_CODE_EDIT)
-	public AjaxJson updateDeleteStatus(Long id, String value){
-		int line = SP.publicMapper.updateColumnById(TbWalletRecord.TABLE_NAME, "delete_status", value, id);
-		return AjaxJson.getByLine(line);
-	}
-	
-	
 
-	
-	
-	
 
 }

+ 1 - 1
sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/TbWalletRecordMapper.java

@@ -27,7 +27,7 @@ public interface TbWalletRecordMapper extends BaseMapper <TbWalletRecord> {
 	 * @param so 参数集合 
 	 * @return 数据列表 
 	 */
-	List<WalletRecordVo> getList(SoMap so);
+	List<TbWalletRecord> getList(SoMap so);
 
 
 	/**

+ 5 - 2
sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/TbWalletRecordMapper.xml

@@ -16,17 +16,19 @@
 	
 	<!-- 查集合 - 根据条件(参数为空时代表忽略指定条件) [G] -->
 	<select id="getList" resultMap="model">
-		<include refid="select_sql"></include>
+		select * from tb_wallet_record as w
 		<where>
 			<if test=' this.has("id") '> and w.id = #{id} </if>
 			<if test=' this.has("peopleId") '> and w.people_id = #{peopleId} </if>
+			<if test=' this.has("peopleName") '> and w.people_name like concat ('%',#{peopleName},'%')  </if>
+			<if test=' this.has("veNo") '> and w.ve_no like concat ('%',#{veNo},'%')  </if>
 			<if test=' this.has("beforeAmount") '> and w.before_amount = #{beforeAmount} </if>
 			<if test=' this.has("afterAmount") '> and w.after_amount = #{afterAmount} </if>
 			<if test=' this.has("amount") '> and w.amount = #{amount} </if>
 			<if test=' this.has("orderId") '> and w.order_id = #{orderId} </if>
 			<if test=' this.has("tradeNo") '> and w.trade_no = #{tradeNo} </if>
 			<if test=' this.has("goodsId") '> and w.goods_id = #{goodsId} </if>
-			<if test=' this.has("goodsNames") '> and w.goods_names = #{goodsNames} </if>
+			<if test=' this.has("goodsNames") '> and w.goods_names like concat ('%',#{goodsNames},'%') </if>
 			<if test=' this.has("recordTime") '> and w.record_time = #{recordTime} </if>
 			<if test=' this.has("createBy") '> and w.create_by = #{createBy} </if>
 			<if test=' this.has("createName") '> and w.create_name = #{createName} </if>
@@ -68,6 +70,7 @@
 			<if test=' this.has("peopleId") '> and w.people_id = #{peopleId} </if>
 			<if test=' this.has("peopleName") '> and p.name = #{peopleName} </if>
 			<if test=' this.has("tagType") '> and w.tag_type = #{tagType} </if>
+			<if test=' this.has("status") '> and w.status = #{status} </if>
 		</where>
 		order by  record_time desc
 	</select>

+ 14 - 15
sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/TbWalletRecordService.java

@@ -8,44 +8,40 @@ import com.pj.tb_order.TbOrder;
 import com.pj.tb_wallet_record.vo.WalletRecordAppVo;
 import com.pj.tb_wallet_record.vo.WalletRecordVo;
 import com.pj.utils.so.SoMap;
+import com.wechat.pay.java.service.payments.app.AppServiceExtension;
+import com.wechat.pay.java.service.payments.app.model.QueryOrderByIdRequest;
+import com.wechat.pay.java.service.payments.model.Transaction;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.annotation.Resource;
+
 /**
  * Service: tb_wallet_record -- 服务点交易记录
  * @author plj 
  */
 @Service
 @Transactional(rollbackFor = Exception.class)
+@Slf4j
 public class TbWalletRecordService extends ServiceImpl<TbWalletRecordMapper, TbWalletRecord> implements IService<TbWalletRecord>{
 
 	/** 底层 Mapper 对象 */
 	@Autowired
 	TbWalletRecordMapper tbWalletRecordMapper;
+	@Autowired
+    WxPayProperties wxPayProperties;
 
-	/** 增 */
-	void add(TbWalletRecord t){
-		save(t);
-	}
 
-	/** 删 */
-	void delete(Long id){
-		removeById(id);
-	}
 
-	/** 改 */
-	void update(TbWalletRecord t){
-		updateById(t);
 
-	}
 
 	/** 查 */
 	TbWalletRecord getById(Long id){
-		//return super.getById(id);
-		List<WalletRecordVo> listObj=tbWalletRecordMapper.getList(new SoMap().set("id",id));
+		List<TbWalletRecord> listObj=tbWalletRecordMapper.getList(new SoMap().set("id",id));
 		if(listObj!=null && listObj.size()>0) {
 			return listObj.get(0);
 		}else {
@@ -54,7 +50,7 @@ public class TbWalletRecordService extends ServiceImpl<TbWalletRecordMapper, TbW
 	}
 
 	/** 查集合 - 根据条件(参数为空时代表忽略指定条件) */  
-	List<WalletRecordVo> getList(SoMap so) {
+	List<TbWalletRecord> getList(SoMap so) {
 		return tbWalletRecordMapper.getList(so);
 	}
 
@@ -68,4 +64,7 @@ public class TbWalletRecordService extends ServiceImpl<TbWalletRecordMapper, TbW
 	List<WalletRecordAppVo> getAPPList(SoMap so) {
 		return tbWalletRecordMapper.getAppList(so);
 	}
+
+
+
 }

+ 17 - 0
sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/WxPayConfiguration.java

@@ -3,6 +3,10 @@ package com.pj.tb_wallet_record;
 import com.github.binarywang.wxpay.config.WxPayConfig;
 import com.github.binarywang.wxpay.service.WxPayService;
 import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
+import com.wechat.pay.java.core.Config;
+import com.wechat.pay.java.core.RSAAutoCertificateConfig;
+import com.wechat.pay.java.service.payments.app.AppService;
+import com.wechat.pay.java.service.payments.app.AppServiceExtension;
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -43,4 +47,17 @@ public class WxPayConfiguration {
     return wxPayService;
   }
 
+  @Bean
+  public AppServiceExtension service(){
+    // 初始化商户配置
+    Config config =
+            new RSAAutoCertificateConfig.Builder()
+                    .merchantId(StringUtils.trimToNull(properties.getMchId()))
+                    // 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
+                    .privateKeyFromPath(properties.getKeyPath())
+                    .merchantSerialNumber(StringUtils.trimToNull(properties.getSerialNumber()))
+                    .apiV3Key(properties.getApiV3Key())
+                    .build();
+   return new AppServiceExtension.Builder().config(config).build();
+  }
 }

+ 7 - 1
sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/WxPayProperties.java

@@ -8,7 +8,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
  * @author plj
  */
 @Data
-@ConfigurationProperties(prefix = "wx.pay")
+@ConfigurationProperties(prefix = "wx")
 public class WxPayProperties {
   /**
    * 设置微信公众号或者小程序等的appid
@@ -19,6 +19,10 @@ public class WxPayProperties {
    * 微信支付商户号
    */
   private String mchId;
+  /**
+   * 证书序列号
+   */
+  private String serialNumber;
 
   /**
    * 微信支付商户密钥
@@ -40,6 +44,8 @@ public class WxPayProperties {
    */
   private String keyPath;
 
+  private String goodsDescription;
+
   /**
    * 支付回调地址
    */

+ 103 - 0
sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/app/AppServiceExample.java

@@ -0,0 +1,103 @@
+package com.pj.tb_wallet_record.app;
+
+import cn.hutool.core.util.RandomUtil;
+import cn.hutool.json.JSONUtil;
+import com.wechat.pay.java.core.Config;
+import com.wechat.pay.java.core.RSAAutoCertificateConfig;
+import com.wechat.pay.java.core.exception.HttpException;
+import com.wechat.pay.java.core.exception.MalformedMessageException;
+import com.wechat.pay.java.core.exception.ServiceException;
+import com.wechat.pay.java.service.payments.app.AppService;
+import com.wechat.pay.java.service.payments.app.model.*;
+import com.wechat.pay.java.service.payments.model.Transaction;
+
+/** AppService使用示例 */
+public class AppServiceExample {
+
+  /** 商户号 */
+  public static String merchantId = "1695540177";
+
+  /** 商户API私钥路径 */
+  public static String privateKeyPath = "E:\\libs\\wx\\apiclient_key.pem";
+
+  /** 商户证书序列号 */
+  public static String merchantSerialNumber = "5469DA5ED227341CF27A93AE1D31811D6965A139";
+
+  /** 商户APIV3密钥 */
+  public static String apiV3Key = "r73q9l7im6qtle33eua3l5ogp6lahss8";
+
+  public static AppService service;
+
+  public static void main(String[] args) {
+    // 初始化商户配置
+    Config config =
+        new RSAAutoCertificateConfig.Builder()
+            .merchantId(merchantId)
+            // 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
+            .privateKeyFromPath(privateKeyPath)
+            .merchantSerialNumber(merchantSerialNumber)
+            .apiV3Key(apiV3Key)
+            .build();
+
+    // 初始化服务
+    service = new AppService.Builder().config(config).build();
+    // ... 调用接口
+    try {
+      PrepayResponse response=prepay();
+      System.out.println("prepay response: " + JSONUtil.toJsonStr(response));
+    } catch (HttpException e) { // 发送HTTP请求失败
+      e.printStackTrace();
+      // 调用e.getHttpRequest()获取请求打印日志或上报监控,更多方法见HttpException定义
+    } catch (ServiceException e) { // 服务返回状态小于200或大于等于300,例如500
+      e.printStackTrace();
+      // 调用e.getResponseBody()获取返回体打印日志或上报监控,更多方法见ServiceException定义
+    } catch (MalformedMessageException e) { // 服务返回成功,返回体类型不合法,或者解析返回体失败
+      e.printStackTrace();
+      // 调用e.getMessage()获取信息打印日志或上报监控,更多方法见MalformedMessageException定义
+    }
+  }
+
+  /** 关闭订单 */
+  public static void closeOrder() {
+
+    CloseOrderRequest request = new CloseOrderRequest();
+    // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
+    // 调用接口
+    service.closeOrder(request);
+  }
+
+  /** APP支付下单 */
+  public static PrepayResponse prepay() {
+    PrepayRequest request = new PrepayRequest();
+    // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
+    request.setAppid("wx0daaef365288a0db");
+    request.setMchid(merchantId);
+    request.setOutTradeNo(RandomUtil.randomString(16));
+    request.setDescription("Image形象店-深圳腾大-QQ公仔");
+    request.setNotifyUrl("http://hs-server.tbgjhc.top:8018/level-one-server/TbPeople/getList");
+    Amount amount=new Amount();
+    amount.setTotal(1);
+    amount.setCurrency("CNY");
+    request.setAmount(amount);
+    // 调用接口
+    return service.prepay(request);
+  }
+
+  /** 微信支付订单号查询订单 */
+  public static Transaction queryOrderById() {
+
+    QueryOrderByIdRequest request = new QueryOrderByIdRequest();
+    // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
+    // 调用接口
+    return service.queryOrderById(request);
+  }
+
+  /** 商户订单号查询订单 */
+  public static Transaction queryOrderByOutTradeNo() {
+
+    QueryOrderByOutTradeNoRequest request = new QueryOrderByOutTradeNoRequest();
+    // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
+    // 调用接口
+    return service.queryOrderByOutTradeNo(request);
+  }
+}

+ 93 - 0
sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/app/AppServiceExtensionExample.java

@@ -0,0 +1,93 @@
+package com.pj.tb_wallet_record.app;
+
+import com.github.binarywang.wxpay.bean.ecommerce.RefundsRequest;
+import com.wechat.pay.java.core.Config;
+import com.wechat.pay.java.core.RSAAutoCertificateConfig;
+import com.wechat.pay.java.core.exception.HttpException;
+import com.wechat.pay.java.core.exception.MalformedMessageException;
+import com.wechat.pay.java.core.exception.ServiceException;
+import com.wechat.pay.java.service.payments.app.AppServiceExtension;
+import com.wechat.pay.java.service.payments.app.model.CloseOrderRequest;
+import com.wechat.pay.java.service.payments.app.model.PrepayRequest;
+import com.wechat.pay.java.service.payments.app.model.PrepayWithRequestPaymentResponse;
+import com.wechat.pay.java.service.payments.app.model.QueryOrderByIdRequest;
+import com.wechat.pay.java.service.payments.app.model.QueryOrderByOutTradeNoRequest;
+import com.wechat.pay.java.service.payments.model.Transaction;
+
+public class AppServiceExtensionExample {
+  /** 商户号 */
+  public static String merchantId = "190000****";
+
+  /** 商户API私钥路径 */
+  public static String privateKeyPath = "/Users/yourname/your/path/apiclient_key.pem";
+
+  /** 商户证书序列号 */
+  public static String merchantSerialNumber = "5157F09EFDC096DE15EBE81A47057A72********";
+
+  /** 商户APIV3密钥 */
+  public static String apiV3Key = "...";
+
+  public static AppServiceExtension service;
+
+  public static void main(String[] args) {
+    // 初始化商户配置
+    Config config =
+        new RSAAutoCertificateConfig.Builder()
+            .merchantId(merchantId)
+            // 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
+            .privateKeyFromPath(privateKeyPath)
+            .merchantSerialNumber(merchantSerialNumber)
+            .apiV3Key(apiV3Key)
+            .build();
+    // 初始化服务
+    service = new AppServiceExtension.Builder().config(config).build();
+    try {
+      // ... 调用接口
+      PrepayWithRequestPaymentResponse response = prepayWithRequestPayment();
+      System.out.println(response);
+    } catch (HttpException e) { // 发送HTTP请求失败
+      // 调用e.getHttpRequest()获取请求打印日志或上报监控,更多方法见HttpException定义
+    } catch (ServiceException e) { // 服务返回状态小于200或大于等于300,例如500
+      // 调用e.getResponseBody()获取返回体打印日志或上报监控,更多方法见ServiceException定义
+    } catch (MalformedMessageException e) { // 服务返回成功,返回体类型不合法,或者解析返回体失败
+      // 调用e.getMessage()获取信息打印日志或上报监控,更多方法见MalformedMessageException定义
+    }
+  }
+
+  /** 关闭订单 */
+  public static void closeOrder() {
+
+
+    CloseOrderRequest request = new CloseOrderRequest();
+    // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
+    // 调用接口
+    service.closeOrder(request);
+  }
+
+  /** APP支付下单,并返回APP调起支付数据 */
+  public static PrepayWithRequestPaymentResponse prepayWithRequestPayment() {
+    PrepayRequest request = new PrepayRequest();
+    // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
+    // 调用接口
+    return service.prepayWithRequestPayment(request);
+  }
+
+  /** 微信支付订单号查询订单 */
+  public static Transaction queryOrderById() {
+
+    QueryOrderByIdRequest request = new QueryOrderByIdRequest();
+    // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
+
+    // 调用接口
+    return service.queryOrderById(request);
+  }
+
+  /** 商户订单号查询订单 */
+  public static Transaction queryOrderByOutTradeNo() {
+
+    QueryOrderByOutTradeNoRequest request = new QueryOrderByOutTradeNoRequest();
+    // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
+    // 调用接口
+    return service.queryOrderByOutTradeNo(request);
+  }
+}

+ 47 - 0
sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/vo/NotifyBO.java

@@ -0,0 +1,47 @@
+package com.pj.tb_wallet_record.vo;
+
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+@JacksonXmlRootElement(localName = "xml")
+@Data
+@Accessors(chain = true)
+public class NotifyBO {
+
+
+    // 返回状态码
+    @JacksonXmlProperty(localName = "return_code")
+    private String returnCode;
+
+    // 返回信息
+    @JacksonXmlProperty(localName = "return_msg")
+    private String returnMsg;
+
+    // 业务结果
+    @JacksonXmlProperty(localName = "result_code")
+    private String resultCode;
+
+    // 商户订单号
+    @JacksonXmlProperty(localName = "out_trade_no")
+    private String outTradeNo;
+
+    // 支付完成时间
+    @JacksonXmlProperty(localName = "time_end")
+    private String timeEnd;
+
+    // 微信支付订单号
+    @JacksonXmlProperty(localName = "transaction_id")
+    private String transactionId;
+
+    // 订单金额
+    @JacksonXmlProperty(localName = "total_fee")
+    private String totalFee;
+    @JacksonXmlProperty(localName = "attach")
+    private String attach;
+
+    @JacksonXmlProperty(localName = "result_code")
+    private String tradeStatus;
+
+}

+ 3 - 1
sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/vo/WalletRecordAppVo.java

@@ -2,6 +2,7 @@ package com.pj.tb_wallet_record.vo;
 
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
+import io.swagger.models.auth.In;
 import lombok.Data;
 
 @Data
@@ -31,7 +32,8 @@ public class WalletRecordAppVo {
     /**
      * 交易扣除点数
      */
-    private String amount;
+    private Integer amount;
+    private Integer status;
 
     /**
      * 扣除时间

+ 0 - 6
sp-service/level-one-server/src/main/java/com/pj/tb_wallet_record/vo/WalletRecordVo.java

@@ -1,18 +1,12 @@
 package com.pj.tb_wallet_record.vo;
 
 import com.pj.tb_wallet_record.TbWalletRecord;
-import lombok.Data;
 
 /**
  * Model: tb_wallet_record -- 服务点交易记录
  * @author plj
  */
-@Data
 public class WalletRecordVo extends TbWalletRecord {
 
 
-    /**
-     * 边民姓名
-     */
-    private String peopleName;
 }

+ 25 - 2
sp-service/level-one-server/src/main/java/com/pj/tb_wallet_topup/TbWalletTopup.java

@@ -74,7 +74,17 @@ public class TbWalletTopup extends Model<TbWalletTopup> implements Serializable
 	/**
 	 * 充值金额 
 	 */
-	private String amount;	
+	private Integer amount;
+
+	private Integer beforeAmount;
+
+	private Integer afterAmount;
+
+
+	/**
+	 * 已扣除数量
+	 */
+	private Integer cutCount;
 
 	/**
 	 * 充值时间 
@@ -111,10 +121,23 @@ public class TbWalletTopup extends Model<TbWalletTopup> implements Serializable
 	 */
 	private String updateName;
 
+	private String prepayid;
 	/**
-	 * 支付状态(0=未支付,1=支付中,2=已支付)
+	 * 支付的用户openid
+	 */
+	private String openid;
+
+	private String successTime;
+
+	/**
+	 * 支付状态(0=未支付,1=支付中,2=已支付,3=取消)
 	 */
 	private Integer payStatus;
 
+	private Integer refundStatus;
+
+	private Integer refundCount;
+
+
 
 }

+ 32 - 65
sp-service/level-one-server/src/main/java/com/pj/tb_wallet_topup/TbWalletTopupController.java

@@ -28,79 +28,46 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
 
 /**
  * Controller: tb_wallet_topup -- 服务点充值记录
- * @author plj 
+ *
+ * @author plj
  */
 @RestController
 @RequestMapping("/TbWalletTopup/")
 public class TbWalletTopupController {
 
-	/** 底层 Service 对象 */
-	@Autowired
-	TbWalletTopupService tbWalletTopupService;
+    /**
+     * 底层 Service 对象
+     */
+    @Autowired
+    TbWalletTopupService tbWalletTopupService;
 
-	@Autowired
-	private WxPayService wxService;
 
-	/** 增 */  
-	@RequestMapping("add")
-	@SaCheckPermission(TbWalletTopup.PERMISSION_CODE_ADD)
-	public AjaxJson add(TbWalletTopup t){
-		tbWalletTopupService.add(t);
-		t = tbWalletTopupService.getById(SP.publicMapper.getPrimarykey());
-		return AjaxJson.getSuccessData(t);
-	}
+    /**
+     * 查 - 根据id
+     */
+    @RequestMapping("getById")
+    @SaCheckPermission(TbWalletTopup.PERMISSION_CODE)
+    public AjaxJson getById(Long id) {
+        ValletTopupVo t = tbWalletTopupService.getById(id);
+        return AjaxJson.getSuccessData(t);
+    }
 
-	/** 删 */  
-	@RequestMapping("delete")
-	@SaCheckPermission(TbWalletTopup.PERMISSION_CODE_DEL)
-	public AjaxJson delete(Long id){
-		 tbWalletTopupService.delete(id);
-		return AjaxJson.getSuccess();
-	}
-	
-	/** 删 - 根据id列表 */  
-	@RequestMapping("deleteByIds")
-	@SaCheckPermission(TbWalletTopup.PERMISSION_CODE_DEL)
-	public AjaxJson deleteByIds(){
-		List<Long> ids = SoMap.getRequestSoMap().getListByComma("ids", long.class); 
-		int line = SP.publicMapper.deleteByIds(TbWalletTopup.TABLE_NAME, ids);
-		return AjaxJson.getByLine(line);
-	}
-	
-	/** 改 */  
-	@RequestMapping("update")
-	@SaCheckPermission(TbWalletTopup.PERMISSION_CODE_EDIT)
-	public AjaxJson update(TbWalletTopup t){
-		tbWalletTopupService.update(t);
-		return AjaxJson.getSuccess();
-	}
+    /**
+     * 查集合 - 根据条件(参数为空时代表忽略指定条件)
+     */
+    @RequestMapping("getList")
+    @SaCheckPermission(TbWalletTopup.PERMISSION_CODE)
+    public AjaxJson getList() {
+        SoMap so = SoMap.getRequestSoMap();
+        List<ValletTopupVo> list = tbWalletTopupService.getList(so.startPage());
+        return AjaxJson.getPageData(so.getDataCount(), list);
+    }
+    @RequestMapping("getSum")
+    @SaCheckPermission(TbWalletTopup.PERMISSION_CODE)
+    public AjaxJson getSum() {
+        Integer sum= tbWalletTopupService.getSum();
+        return AjaxJson.getSuccessData(sum);
+    }
 
-	/** 查 - 根据id */  
-	@RequestMapping("getById")
-		@SaCheckPermission(TbWalletTopup.PERMISSION_CODE)
-	public AjaxJson getById(Long id){
-		ValletTopupVo t = tbWalletTopupService.getById(id);
-		return AjaxJson.getSuccessData(t);
-	}
-
-	/** 查集合 - 根据条件(参数为空时代表忽略指定条件) */  
-	@RequestMapping("getList")
-		@SaCheckPermission(TbWalletTopup.PERMISSION_CODE)
-	public AjaxJson getList() { 
-		SoMap so = SoMap.getRequestSoMap();
-		List<ValletTopupVo> list = tbWalletTopupService.getList(so.startPage());
-		return AjaxJson.getPageData(so.getDataCount(), list);
-	}
-	
-	
-	
-	/** 改 - 删除状态(0=禁用,1=启用) */  
-	@RequestMapping("updateDeleteStatus")
-	@SaCheckPermission(TbWalletTopup.PERMISSION_CODE_EDIT)
-	public AjaxJson updateDeleteStatus(Long id, Integer value){
-		int line = SP.publicMapper.updateColumnById(TbWalletTopup.TABLE_NAME, "delete_status", value, id);
-		return AjaxJson.getByLine(line);
-	}
-	
 
 }

+ 27 - 8
sp-service/level-one-server/src/main/java/com/pj/tb_wallet_topup/TbWalletTopupMapper.java

@@ -1,32 +1,51 @@
 package com.pj.tb_wallet_topup;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.pj.tb_order.TbOrder;
 import com.pj.tb_wallet_topup.vo.ValletTopupVo;
 
 import org.apache.ibatis.annotations.Mapper;
 
 import com.pj.utils.so.*;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
 import java.util.List;
 
 /**
  * Mapper: tb_wallet_topup -- 服务点充值记录
- * @author plj 
+ *
+ * @author plj
  */
 
 @Mapper
 @Repository
-public interface TbWalletTopupMapper extends BaseMapper <TbWalletTopup> {
+public interface TbWalletTopupMapper extends BaseMapper<TbWalletTopup> {
 
 
+    /**
+     * 查集合 - 根据条件(参数为空时代表忽略指定条件)
+     *
+     * @param so 参数集合
+     * @return 数据列表
+     */
+    List<ValletTopupVo> getList(SoMap so);
 
-	/**
-	 * 查集合 - 根据条件(参数为空时代表忽略指定条件)
-	 * @param so 参数集合 
-	 * @return 数据列表 
-	 */
-	List<ValletTopupVo> getList(SoMap so);
 
+    default TbWalletTopup findByOutTradeNo(String outTradeNo) {
+        QueryWrapper<TbWalletTopup> ew = new QueryWrapper<>();
+        ew.lambda().eq(TbWalletTopup::getOutTradeNo, outTradeNo);
+        return selectOne(ew);
+    }
 
+    default TbWalletTopup getByPrePayId(String prePayId) {
+        QueryWrapper<TbWalletTopup> ew = new QueryWrapper<>();
+        ew.lambda().eq(TbWalletTopup::getPrepayid, prePayId);
+        return selectOne(ew);
+    }
+
+    void cancelTopup(@Param("outTradeNo") String outTradeNo);
+
+    Integer getSum();
 }

+ 8 - 3
sp-service/level-one-server/src/main/java/com/pj/tb_wallet_topup/TbWalletTopupMapper.xml

@@ -17,9 +17,12 @@
 		from tb_wallet_topup as w
 		left join tb_people as p on w.people_id = p.id
 	</sql>
+    <delete id="cancelTopup">
+		update tb_wallet_topup set pay_status=3 where out_trade_no=#{outTradeNo}
+	</delete>
 
-	
-	<!-- 查集合 - 根据条件(参数为空时代表忽略指定条件) [G] -->
+
+    <!-- 查集合 - 根据条件(参数为空时代表忽略指定条件) [G] -->
 	<select id="getList" resultMap="model">
 		<include refid="select_sql"></include>
 		<where>
@@ -59,7 +62,9 @@
 			<otherwise> topup_time desc </otherwise>
 		</choose>
 	</select>
+	<select id="getSum" resultType="java.lang.Integer">
+		select sum(amount) from tb_wallet_topup where pay_status =2
+	</select>
 
-	
 
 </mapper>

+ 177 - 37
sp-service/level-one-server/src/main/java/com/pj/tb_wallet_topup/TbWalletTopupService.java

@@ -1,56 +1,196 @@
 package com.pj.tb_wallet_topup;
 
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.pj.project4sp.spcfg.SpCfgUtil;
+import com.pj.tb_order.TbOrder;
+import com.pj.tb_people.TbPeopleService;
+import com.pj.tb_wallet_record.TbWalletRecord;
+import com.pj.tb_wallet_record.WxPayProperties;
+import com.pj.tb_wallet_record.vo.NotifyBO;
 import com.pj.tb_wallet_topup.vo.ValletTopupVo;
+import com.pj.utils.cache.RedisUtil;
 import com.pj.utils.so.SoMap;
+import com.wechat.pay.java.service.payments.app.AppServiceExtension;
+import com.wechat.pay.java.service.payments.app.model.CloseOrderRequest;
+import com.wechat.pay.java.service.payments.app.model.QueryOrderByIdRequest;
+import com.wechat.pay.java.service.payments.app.model.QueryOrderByOutTradeNoRequest;
+import com.wechat.pay.java.service.payments.model.Transaction;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.annotation.Resource;
+import java.util.Date;
 import java.util.List;
 
 /**
  * Service: tb_wallet_topup -- 服务点充值记录
- * @author plj 
+ *
+ * @author plj
  */
 @Service
 @Transactional(rollbackFor = Exception.class)
-public class TbWalletTopupService extends ServiceImpl<TbWalletTopupMapper, TbWalletTopup> implements IService<TbWalletTopup>{
-
-	/** 底层 Mapper 对象 */
-	@Autowired
-	TbWalletTopupMapper tbWalletTopupMapper;
-
-	/** 增 */
-	void add(TbWalletTopup t){
-		save(t);
-	}
-
-	/** 删 */
-	void delete(Long id){
-		removeById(id);
-	}
-
-	/** 改 */
-	void update(TbWalletTopup t){
-		updateById(t);
-	}
-
-	/** 查 */
-	ValletTopupVo getById(Long id){
-		List<ValletTopupVo> listObj=tbWalletTopupMapper.getList(new SoMap().set("id",id));
-		if(listObj!=null && listObj.size()>0) {
-			return listObj.get(0);
-		}else {
-			return  null;
-		}
-	}
-
-	/** 查集合 - 根据条件(参数为空时代表忽略指定条件) */  
-	List<ValletTopupVo> getList(SoMap so) {
-		return tbWalletTopupMapper.getList(so);	
-	}
-	
+@Slf4j
+public class TbWalletTopupService extends ServiceImpl<TbWalletTopupMapper, TbWalletTopup> implements IService<TbWalletTopup> {
 
+    /**
+     * 底层 Mapper 对象
+     */
+    @Autowired
+    TbWalletTopupMapper tbWalletTopupMapper;
+    @Resource
+    private AppServiceExtension appServiceExtension;
+    @Autowired
+    WxPayProperties wxPayProperties;
+    @Resource
+    private TbPeopleService tbPeopleService;
+
+    /**
+     * 增
+     */
+    void add(TbWalletTopup t) {
+        save(t);
+    }
+
+    /**
+     * 删
+     */
+    void delete(Long id) {
+        removeById(id);
+    }
+
+    /**
+     * 改
+     */
+    void update(TbWalletTopup t) {
+        updateById(t);
+    }
+
+    /**
+     * 查
+     */
+    ValletTopupVo getById(Long id) {
+        List<ValletTopupVo> listObj = tbWalletTopupMapper.getList(new SoMap().set("id", id));
+        if (listObj != null && listObj.size() > 0) {
+            return listObj.get(0);
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * 查集合 - 根据条件(参数为空时代表忽略指定条件)
+     */
+    List<ValletTopupVo> getList(SoMap so) {
+        return tbWalletTopupMapper.getList(so);
+    }
+
+
+    public void WxNotify(NotifyBO notifyBO) {
+        String orderStatus = notifyBO.getTradeStatus();
+        if (!"SUCCESS".equals(orderStatus) && !"FINISH".equals(orderStatus)) {
+            log.error("支付订单回调失败:{}", JSONUtil.toJsonStr(notifyBO));
+            return;
+        }
+        String outTradeNo = notifyBO.getOutTradeNo();
+        if (StrUtil.isNotEmpty(RedisUtil.get(outTradeNo))) {
+            log.error("========订单已处理==========:{}", outTradeNo);
+            return;
+        }
+        RedisUtil.setByMINUTES(outTradeNo, DateUtil.now(), 10);
+        TbWalletTopup tbWalletTopup = tbWalletTopupMapper.findByOutTradeNo(outTradeNo);
+        if (tbWalletTopup == null) {
+            log.error("========订单不存在==========:{}", outTradeNo);
+            return;
+        }
+    }
+
+    public void handlerTopup(String outTradeNoStr) {
+        String key = wxPayProperties.getMchId() + "-" + wxPayProperties.getAppId();
+        long now = System.currentTimeMillis() / 1000 - 30 * 60;
+        String outTradeNo = StrUtil.subBefore(outTradeNoStr, "-", true);
+        String timeStr = StrUtil.subAfter(outTradeNoStr, "-", true);
+        if (StrUtil.isEmpty(timeStr) || now > Long.parseLong(timeStr)) {
+            RedisUtil.forListRemove(key, outTradeNoStr);
+            tbWalletTopupMapper.cancelTopup(outTradeNo);
+            return;
+        }
+
+        QueryOrderByOutTradeNoRequest request = new QueryOrderByOutTradeNoRequest();
+        // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
+        request.setMchid(wxPayProperties.getMchId());
+        request.setOutTradeNo(outTradeNo);
+        // 调用接口
+        Transaction transaction = appServiceExtension.queryOrderByOutTradeNo(request);
+        if (transaction.getTradeState().name().equals("SUCCESS")) {
+            RedisUtil.forListRemove(key, outTradeNoStr);
+            TbWalletTopup tbWalletTopup = tbWalletTopupMapper.findByOutTradeNo(outTradeNo);
+            tbWalletTopup.setPayStatus(2).setSuccessTime(transaction.getSuccessTime())
+                    .setTransactionId(transaction.getTransactionId())
+                    .setOpenid(transaction.getPayer().getOpenid())
+                    .setUpdateTime(new Date());
+            this.updateById(tbWalletTopup);
+            tbPeopleService.updatePeopleWallet(tbWalletTopup.getPeopleId(), tbWalletTopup.getAmount());
+        }
+        log.info("Transaction:{}", transaction);
+    }
+
+    /**
+     * 关闭订单
+     */
+    public void closeOrder(String outTradeNo) {
+        CloseOrderRequest request = new CloseOrderRequest();
+        // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
+        request.setMchid(wxPayProperties.getMchId());
+        request.setOutTradeNo(outTradeNo);
+        // 调用接口
+        appServiceExtension.closeOrder(request);
+    }
+
+    public TbWalletTopup getByPrePayId(String prePayId) {
+        return tbWalletTopupMapper.getByPrePayId(prePayId);
+    }
+
+    /**
+     * 减去扣除点数
+     *
+     * @param peopleId
+     */
+    public void subAmount(Long peopleId) {
+        TbWalletTopup tbWalletTopup = getTheFirstRecord(peopleId);
+        if (tbWalletTopup != null) {
+            tbWalletTopup.setCutCount(tbWalletTopup.getCutCount() + SpCfgUtil.getTradeNum());
+            updateById(tbWalletTopup);
+        }
+    }
+
+    private TbWalletTopup getTheFirstRecord(Long peopleId) {
+        LambdaQueryWrapper<TbWalletTopup> ew = new LambdaQueryWrapper<>();
+        ew.eq(TbWalletTopup::getPeopleId, peopleId)
+                .eq(TbWalletTopup::getPayStatus, 2)
+                .apply("amount > cut_count + refund_count")
+                .orderByAsc(TbWalletTopup::getCreateTime);
+        List<TbWalletTopup> list = list(ew);
+        return list.isEmpty() ? null : list.get(0);
+    }
+
+    public Integer getSum() {
+        return tbWalletTopupMapper.getSum();
+    }
+
+    public List<TbWalletTopup> findRefundList(Long peopleId) {
+        LambdaQueryWrapper<TbWalletTopup> ew = new LambdaQueryWrapper<>();
+        ew.eq(TbWalletTopup::getPeopleId, peopleId)
+                .eq(TbWalletTopup::getPayStatus, 2)
+                .apply("amount > cut_count + refund_count")
+                .orderByAsc(TbWalletTopup::getCreateTime);
+        return list(ew);
+    }
 }

+ 51 - 0
sp-service/level-one-server/src/main/java/com/pj/tb_wallet_topup/WalletTopupAppController.java

@@ -0,0 +1,51 @@
+package com.pj.tb_wallet_topup;
+
+import cn.dev33.satoken.annotation.SaCheckPermission;
+import com.pj.current.satoken.StpAPPUserUtil;
+import com.pj.project4sp.SP;
+import com.pj.tb_wallet_record.TbWalletRecord;
+import com.pj.tb_wallet_topup.vo.ValletTopupVo;
+import com.pj.utils.sg.AjaxJson;
+import com.pj.utils.so.SoMap;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+
+/**
+ * Controller: tb_wallet_topup -- 服务点充值记录
+ * @author plj 
+ */
+@RestController
+@RequestMapping("/app/TbWalletTopup/")
+public class WalletTopupAppController {
+
+	/** 底层 Service 对象 */
+	@Autowired
+	TbWalletTopupService tbWalletTopupService;
+
+	/** 查 - 根据id */  
+	@RequestMapping("getByPrePayId")
+	public AjaxJson getByPrePayId(String prePayId){
+		if (!StpAPPUserUtil.isLogin()){
+			return AjaxJson.getError("用户未登录");
+		}
+		TbWalletTopup t = tbWalletTopupService.getByPrePayId(prePayId);
+		return AjaxJson.getSuccessData(t);
+	}
+	/**
+	 * 查 - 根据id
+	 */
+	@RequestMapping("getById")
+	public AjaxJson getById(Long id) {
+		if (!StpAPPUserUtil.isLogin()){
+			return AjaxJson.getError("用户未登录");
+		}
+		TbWalletTopup t = tbWalletTopupService.getById(id);
+		return AjaxJson.getSuccessData(t);
+	}
+
+
+}

+ 33 - 0
sp-service/level-one-server/src/main/java/com/pj/tb_wallet_topup/task/QueryPayTask.java

@@ -0,0 +1,33 @@
+package com.pj.tb_wallet_topup.task;
+
+import cn.hutool.core.util.StrUtil;
+import com.pj.tb_wallet_record.TbWalletRecordService;
+import com.pj.tb_wallet_record.WxPayProperties;
+import com.pj.tb_wallet_topup.TbWalletTopupService;
+import com.pj.utils.cache.RedisUtil;
+import com.wechat.pay.java.service.payments.app.AppServiceExtension;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@Component
+@Slf4j
+public class QueryPayTask {
+    @Resource
+    private WxPayProperties wxPayProperties;
+    @Resource
+    private TbWalletTopupService tbWalletTopupService;
+
+    @Scheduled(cron = "0/5 * * * * ?")  //每3秒执行一次
+    public void query() {
+        String key = wxPayProperties.getMchId() + "-" + wxPayProperties.getAppId();
+        List<Object> list = RedisUtil.forListGet(key);
+        for (Object tradeObj : list) {
+            String tradeNo = tradeObj.toString();
+            tbWalletTopupService.handlerTopup(tradeNo);
+        }
+    }
+}