Ver código fonte

修复 app 端, 支付完成后 的流水, 缴费人等问题

weiximei 6 anos atrás
pai
commit
5c1ff24604

+ 44
- 3
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/impl/WxPayServiceImpl.java Ver arquivo

@@ -5,8 +5,12 @@ import com.community.huiju.common.wxpay.HfWxConfig;
5 5
 import com.community.huiju.common.wxpay.WXPay;
6 6
 import com.community.huiju.common.wxpay.WXPayConstants;
7 7
 import com.community.huiju.common.wxpay.WXPayUtil;
8
+import com.community.huiju.dao.TaUserMapper;
8 9
 import com.community.huiju.dao.TpBillInvoiceMapper;
10
+import com.community.huiju.dao.TpBillMapper;
9 11
 import com.community.huiju.dao.TpBillStatementMapper;
12
+import com.community.huiju.model.TaUser;
13
+import com.community.huiju.model.TpBill;
10 14
 import com.community.huiju.model.TpBillInvoice;
11 15
 import com.community.huiju.model.TpBillStatement;
12 16
 import com.community.huiju.service.WxPayServiceI;
@@ -35,7 +39,14 @@ public class WxPayServiceImpl implements WxPayServiceI {
35 39
 	
36 40
 	@Autowired
37 41
 	private TpBillStatementMapper tpBillStatementMapper;
38
-	
42
+
43
+	@Autowired
44
+	private TpBillMapper tpBillMapper;
45
+
46
+	@Autowired
47
+	private TaUserMapper taUserMapper;
48
+
49
+
39 50
 	/**
40 51
 	 * 微信支付统一下单
41 52
 	 *
@@ -44,6 +55,7 @@ public class WxPayServiceImpl implements WxPayServiceI {
44 55
 	 * @param userElement
45 56
 	 */
46 57
 	@Override
58
+	@Transactional(rollbackFor = Exception.class)
47 59
 	public Map<String, String> wxUnifiedOrder(Integer billInvoiceId, UserElement userElement) throws Exception {
48 60
 		HfWxConfig config = new HfWxConfig();
49 61
 		WXPay wxpay = new WXPay(config);
@@ -98,6 +110,7 @@ public class WxPayServiceImpl implements WxPayServiceI {
98 110
 	 * @param resultMap
99 111
 	 */
100 112
 	@Override
113
+	@Transactional(rollbackFor = Exception.class)
101 114
 	public String wxNotify(Map<String, String> resultMap) throws Exception {
102 115
 		String outTradeNo = resultMap.get("out_trade_no");
103 116
 		TpBillInvoice tpBillInvoice = tpBillInvoiceMapper.selectByOutTradeNo(outTradeNo);
@@ -106,8 +119,19 @@ public class WxPayServiceImpl implements WxPayServiceI {
106 119
 		}else if (!tpBillInvoice.getBillStatus().equals("3")){
107 120
 			return "订单状态出错";
108 121
 		}
109
-		//更新为正在支付状态
110
-		updateBillInvoiceBillStatus(tpBillInvoice.getId(),"1");
122
+
123
+		// 根据 app 用户id, 查询用户
124
+		TaUser taUser = taUserMapper.selectByPrimaryKey(tpBillInvoice.getTaUserId());
125
+
126
+		// 更新为正在支付状态
127
+		// 更改收费单的缴费人, 缴费时间, 修改人, 修改时间
128
+		tpBillInvoice.setBillStatus("1");
129
+		tpBillInvoice.setPayName(taUser.getUserName());
130
+		tpBillInvoice.setPayDate(new Date());
131
+		tpBillInvoice.setUpdateDate(new Date());
132
+		tpBillInvoice.setUpdateUser(taUser.getId());
133
+		tpBillInvoiceMapper.updateByPrimaryKeySelective(tpBillInvoice);
134
+
111 135
 		//插入流水账单表
112 136
 		TpBillStatement tpBillStatement = new TpBillStatement();
113 137
 		tpBillStatement.setBillInvoiceId(tpBillInvoice.getId());
@@ -119,6 +143,21 @@ public class WxPayServiceImpl implements WxPayServiceI {
119 143
 		tpBillStatement.setPayType("0");
120 144
 		tpBillStatement.setCreateTime(new Date());
121 145
 		tpBillStatementMapper.insert(tpBillStatement);
146
+
147
+		// 更新 收费单流水id
148
+		tpBillInvoice.setBillStatementId(tpBillStatement.getId());
149
+		tpBillInvoiceMapper.updateByPrimaryKeySelective(tpBillInvoice);
150
+
151
+		// 更新收费组的 未交费用户数 和 已缴费用户数
152
+		TpBill tpBill = tpBillMapper.selectById(tpBillInvoice.getBillId());
153
+		tpBill.setPayedNum(tpBill.getPayedNum() + 1);
154
+		tpBill.setUnpayedNum(tpBill.getUnpayedNum() - 1);
155
+		// 如果为零, 表示这个收费组收费完成
156
+		if (tpBill.getUnpayedNum() == 0) {
157
+			tpBill.setBillStatus("1");
158
+		}
159
+		tpBillMapper.updateByPrimaryKeySelective(tpBill);
160
+
122 161
 		return "success";
123 162
 	}
124 163
 	
@@ -138,6 +177,7 @@ public class WxPayServiceImpl implements WxPayServiceI {
138 177
 	}
139 178
 	
140 179
 	@Override
180
+	@Transactional(rollbackFor = Exception.class)
141 181
 	public void wxStartPay(Integer billInvoiceId, UserElement userElement) throws Exception {
142 182
 		//获取支付金额
143 183
 		TpBillInvoice tpBillInvoice = tpBillInvoiceMapper.selectByIdAndUserId(billInvoiceId,userElement.getId(),userElement.getCommunityId());
@@ -157,6 +197,7 @@ public class WxPayServiceImpl implements WxPayServiceI {
157 197
 	 * @param userElement
158 198
 	 */
159 199
 	@Override
200
+	@Transactional(rollbackFor = Exception.class)
160 201
 	public void wxCancelPay(Integer billInvoiceId, UserElement userElement) throws Exception {
161 202
 		//获取支付金额
162 203
 		TpBillInvoice tpBillInvoice = tpBillInvoiceMapper.selectByIdAndUserId(billInvoiceId,userElement.getId(),userElement.getCommunityId());

+ 1
- 1
CODE/smart-community/app-api/src/main/resources/mapper/TpBillStatementMapper.xml Ver arquivo

@@ -26,7 +26,7 @@
26 26
     delete from tp_bill_statement
27 27
     where id = #{id,jdbcType=INTEGER}
28 28
   </delete>
29
-  <insert id="insert" parameterType="com.community.huiju.model.TpBillStatement" >
29
+  <insert id="insert" parameterType="com.community.huiju.model.TpBillStatement" useGeneratedKeys="true" keyColumn="id" keyProperty="id" >
30 30
     insert into tp_bill_statement (id, community_id, bill_invoice_id, 
31 31
       ta_user_id, pay_price, pay_name, 
32 32
       pay_remark, pay_type, create_time