张延森 3 vuotta sitten
vanhempi
commit
7dd6642d32

+ 40
- 6
src/main/java/com/yunzhi/shigongli/controller/TaShopAccountController.java Näytä tiedosto

@@ -5,20 +5,18 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
5 5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.yunzhi.shigongli.common.BaseController;
7 7
 import com.yunzhi.shigongli.common.ResponseBean;
8
+import com.yunzhi.shigongli.common.StringUtils;
9
+import com.yunzhi.shigongli.entity.TaHotelAccount;
10
+import com.yunzhi.shigongli.vo.CommissionSettlementVO;
8 11
 import io.swagger.annotations.Api;
9 12
 import io.swagger.annotations.ApiOperation;
10 13
 import io.swagger.annotations.ApiParam;
11 14
 import org.slf4j.Logger;
12 15
 import org.slf4j.LoggerFactory;
13 16
 import org.springframework.beans.factory.annotation.Autowired;
14
-import org.springframework.web.bind.annotation.PathVariable;
15
-import org.springframework.web.bind.annotation.RequestBody;
16
-import org.springframework.web.bind.annotation.RequestMapping;
17
-import org.springframework.web.bind.annotation.RequestMethod;
18
-import org.springframework.web.bind.annotation.RequestParam;
17
+import org.springframework.web.bind.annotation.*;
19 18
 import com.yunzhi.shigongli.service.ITaShopAccountService;
20 19
 import com.yunzhi.shigongli.entity.TaShopAccount;
21
-import org.springframework.web.bind.annotation.RestController;
22 20
 
23 21
 /**
24 22
  * <p>
@@ -38,6 +36,42 @@ public class TaShopAccountController extends BaseController {
38 36
 
39 37
     @Autowired
40 38
     public ITaShopAccountService iTaShopAccountService;
39
+
40
+    /**
41
+     * 佣金结算
42
+     * @param commissionSettlementVO
43
+     * @return
44
+     * @throws Exception
45
+     */
46
+    @PutMapping("/admin/shopAccount/commission/settlement")
47
+    @ApiOperation(value="佣金结算", notes = "佣金结算", httpMethod = "PUT", response = ResponseBean.class)
48
+    public ResponseBean commissionSettlement(@ApiParam("结算佣金") @RequestBody CommissionSettlementVO commissionSettlementVO) throws Exception {
49
+        String shopId = commissionSettlementVO.getTargetId();
50
+        if (StringUtils.isEmpty(shopId)) {
51
+            return ResponseBean.error("未找到结算民宿对象", ResponseBean.ERROR_MISSING_PARAMS);
52
+        }
53
+
54
+        if (null == commissionSettlementVO.getCharges() || commissionSettlementVO.getCharges() < 1) {
55
+            return ResponseBean.error("请设置有效的结算金额", ResponseBean.ERROR_MISSING_PARAMS);
56
+        }
57
+
58
+        TaShopAccount taShopAccount = iTaShopAccountService.getByShop(shopId);
59
+        if (null == taShopAccount) {
60
+            return ResponseBean.error("未找到有效的结算民宿对象", ResponseBean.ERROR_MISSING_PARAMS);
61
+        }
62
+
63
+        if (taShopAccount.getBrokerageCharges() - taShopAccount.getPaidCharges() < commissionSettlementVO.getCharges()) {
64
+            return ResponseBean.error("佣金不足", ResponseBean.ERROR_MISSING_PARAMS);
65
+        }
66
+
67
+        boolean success = iTaShopAccountService.commissionSettlement(taShopAccount, commissionSettlementVO.getCharges());
68
+        if (success) {
69
+            return ResponseBean.success("success");
70
+        } else {
71
+            return ResponseBean.error("结算失败请重试", ResponseBean.ERROR_UNAVAILABLE);
72
+        }
73
+    }
74
+
41 75
 //
42 76
 //
43 77
 //    /**

+ 54
- 55
src/main/java/com/yunzhi/shigongli/controller/WxMaController.java Näytä tiedosto

@@ -11,6 +11,7 @@ import com.yunzhi.shigongli.service.ITaMiniappQrcodeService;
11 11
 import com.yunzhi.shigongli.service.ITaPersonRecommenderService;
12 12
 import com.yunzhi.shigongli.service.ITaPersonRoleService;
13 13
 import com.yunzhi.shigongli.service.ITaPersonService;
14
+import com.yunzhi.shigongli.vo.WxLoginParam;
14 15
 import com.yunzhi.shigongli.vo.WxMaAuthParam;
15 16
 import io.swagger.annotations.Api;
16 17
 import io.swagger.annotations.ApiOperation;
@@ -18,6 +19,7 @@ import io.swagger.annotations.ApiParam;
18 19
 import org.springframework.beans.factory.annotation.Autowired;
19 20
 import org.springframework.web.bind.annotation.*;
20 21
 
22
+import java.time.LocalDateTime;
21 23
 import java.util.*;
22 24
 
23 25
 
@@ -60,45 +62,62 @@ public class WxMaController extends BaseController {
60 62
         result.put("openid", taPerson.getOpenid());
61 63
         result.put("sessionKey", info.getSessionKey());
62 64
 
63
-        if (!StringUtils.isEmpty(query)) {
64
-            Map<String, String> params = StringUtils.parseQueryString(query);
65
-
66
-            String fromType = params.get("fromType");
67
-            String recommender = params.get("recommender");
68
-            String qrCodeId = params.get("scene");
69
-
70
-            // 如果是扫码进入
71
-            if (!StringUtils.isEmpty(qrCodeId)) {
72
-                TaMiniappQrcode miniappQrcode = miniappQrcodeService.getById(Integer.valueOf(qrCodeId));
73
-                if (null != miniappQrcode) {
74
-                    String qrcodeParamStr = miniappQrcode.getScene();
75
-                    if (!StringUtils.isEmpty(qrcodeParamStr)) {
76
-                        // 把真正的参数返回
77
-                        result.put("qrcode", qrcodeParamStr);
78
-                        // 如果小程序码中有
79
-                        Map<String, String> qrcodeParams = StringUtils.parseQueryString(qrcodeParamStr);
80
-                        if (!StringUtils.isEmpty(qrcodeParams.get("id"))) {
81
-                            fromType = qrcodeParams.get("type");
82
-                            recommender = qrcodeParams.get("id");
83
-                        }
65
+        return ResponseBean.success(result);
66
+    }
67
+
68
+    @PostMapping("/login")
69
+    @ApiOperation(value="登录", notes = "登录", httpMethod = "POST", response = ResponseBean.class)
70
+    public ResponseBean login(@ApiParam("登录参数") @RequestBody WxLoginParam params) throws Exception {
71
+        if (StringUtils.isEmpty(params.getCode()) || StringUtils.isEmpty(params.getPersonId())) {
72
+            return ResponseBean.error("登录参数不能为空", ResponseBean.ERROR_MISSING_PARAMS);
73
+        }
74
+
75
+        // 返回值
76
+        Map<String, Object> rtn = new HashMap<>();
77
+
78
+        WxMaJscode2SessionResult info = wxUtils.getService().getUserService().getSessionInfo(params.getCode());
79
+        rtn.put("sessionKey", info.getSessionKey());
80
+
81
+        TaPerson taPerson = iTaPersonService.getById(params.getPersonId());
82
+        rtn.put("person", taPerson);
83
+
84
+        // 查询人员角色
85
+        List<TaPersonRole> roleList = personRoleService.getListByPerson(taPerson.getPersonId());
86
+        rtn.put("personRoleList", roleList);
87
+
88
+        String fromType = params.getFromType();
89
+        String recommender = params.getRecommender();
90
+        Integer qrCodeId = params.getQrCodeId();
91
+        if (null != qrCodeId && qrCodeId > 0) {
92
+            TaMiniappQrcode miniappQrcode = miniappQrcodeService.getById(qrCodeId);
93
+            if (null != miniappQrcode) {
94
+                String qrcodeParamStr = miniappQrcode.getScene();
95
+                if (!StringUtils.isEmpty(qrcodeParamStr)) {
96
+                    // 把真正的参数返回
97
+                    rtn.put("qrcode", qrcodeParamStr);
98
+                    // 如果小程序码中有
99
+                    Map<String, String> qrcodeParams = StringUtils.parseQueryString(qrcodeParamStr);
100
+                    if (!StringUtils.isEmpty(qrcodeParams.get("id"))) {
101
+                        fromType = qrcodeParams.get("type");
102
+                        recommender = qrcodeParams.get("id");
84 103
                     }
85 104
                 }
86 105
             }
106
+        }
87 107
 
88
-            // 如果有推广ID, 比如民宿或者商铺
89
-            if (!StringUtils.isEmpty(recommender)) {
90
-                if (StringUtils.isEmpty(taPerson.getRecommender())) {
91
-                    taPerson.setFromType(fromType);
92
-                    taPerson.setRecommender(recommender);
93
-                    iTaPersonService.updateById(taPerson);
94
-                }
108
+        // 如果有推广ID, 比如民宿或者商铺
109
+        if (!StringUtils.isEmpty(recommender)) {
110
+            if (StringUtils.isEmpty(taPerson.getRecommender())) {
111
+                taPerson.setFromType(fromType);
112
+                taPerson.setRecommender(recommender);
113
+                iTaPersonService.updateById(taPerson);
114
+            }
95 115
 
96
-                // 写入推荐表
97
-                try {
98
-                    recommenderService.addNewRecommender(taPerson.getPersonId(), fromType, recommender);
99
-                } catch (Exception e) {
100
-                    e.printStackTrace();;
101
-                }
116
+            // 写入推荐表
117
+            try {
118
+                recommenderService.addNewRecommender(taPerson.getPersonId(), fromType, recommender);
119
+            } catch (Exception e) {
120
+                e.printStackTrace();;
102 121
             }
103 122
         }
104 123
 
@@ -107,27 +126,7 @@ public class WxMaController extends BaseController {
107 126
         tokenClaims.put("userId", taPerson.getPersonId());
108 127
         tokenClaims.put("miniApp", true);
109 128
         String authToken = JWTUtils.encode(tokenClaims);
110
-        result.put("token", authToken);
111
-
112
-        return ResponseBean.success(result);
113
-    }
114
-
115
-    @PostMapping("/login")
116
-    @ApiOperation(value="登录", notes = "登录", httpMethod = "POST", response = ResponseBean.class)
117
-    public ResponseBean login(@ApiParam("登录参数") @RequestParam String personId) throws Exception {
118
-//        WxMaJscode2SessionResult info = wxUtils.getService().getUserService().getSessionInfo(code);
119
-//
120
-//        String openid = info.getOpenid();
121
-//        TaPerson taPerson = iTaPersonService.getByOpenid(openid);
122
-        TaPerson taPerson = iTaPersonService.getById(personId);
123
-
124
-        // 查询人员角色
125
-        List<TaPersonRole> roleList = personRoleService.getListByPerson(taPerson.getPersonId());
126
-
127
-        Map<String, Object> rtn = new HashMap<>();
128
-        rtn.put("person", taPerson);
129
-        rtn.put("personRoleList", roleList);
130
-//        rtn.put("sessionKey", info.getSessionKey());
129
+        rtn.put("token", authToken);
131 130
 
132 131
         return ResponseBean.success(rtn);
133 132
     }

+ 2
- 0
src/main/java/com/yunzhi/shigongli/mapper/TaShopAccountMapper.java Näytä tiedosto

@@ -19,4 +19,6 @@ public interface TaShopAccountMapper extends BaseMapper<TaShopAccount> {
19 19
     TaShopAccount selectByShop(@Param("shopId") String shopId);
20 20
 
21 21
     int updateCommission(@Param("accountId") String accountId, @Param("amount") Integer amount);
22
+
23
+    int commissionSettlement(@Param("accountId") String accountId, @Param("charges") Integer charges);
22 24
 }

+ 3
- 0
src/main/java/com/yunzhi/shigongli/service/ITaShopAccountService.java Näytä tiedosto

@@ -13,4 +13,7 @@ import com.yunzhi.shigongli.entity.TaShopAccount;
13 13
  */
14 14
 public interface ITaShopAccountService extends IBaseService<TaShopAccount> {
15 15
 
16
+    TaShopAccount getByShop(String shopId);
17
+
18
+    boolean commissionSettlement(TaShopAccount taShopAccount, Integer charges) throws Exception;
16 19
 }

+ 0
- 2
src/main/java/com/yunzhi/shigongli/service/impl/TaPersonServiceImpl.java Näytä tiedosto

@@ -8,7 +8,6 @@ import com.yunzhi.shigongli.mapper.TaPersonMapper;
8 8
 import com.yunzhi.shigongli.service.ITaPersonService;
9 9
 
10 10
 import org.springframework.stereotype.Service;
11
-import org.springframework.transaction.annotation.Transactional;
12 11
 
13 12
 /**
14 13
  * <p>
@@ -35,7 +34,6 @@ public class TaPersonServiceImpl extends BaseServiceImpl<TaPersonMapper, TaPerso
35 34
         return getOne(queryWrapper);
36 35
     }
37 36
 
38
-    @Transactional
39 37
     @Override
40 38
     public TaPerson getByOpenidOrNot(String openid) {
41 39
         TaPerson taPerson = getByOpenid(openid);

+ 42
- 0
src/main/java/com/yunzhi/shigongli/service/impl/TaShopAccountServiceImpl.java Näytä tiedosto

@@ -1,10 +1,18 @@
1 1
 package com.yunzhi.shigongli.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4
+import com.yunzhi.shigongli.common.Constants;
3 5
 import com.yunzhi.shigongli.entity.TaShopAccount;
6
+import com.yunzhi.shigongli.entity.TaShopAccountLog;
7
+import com.yunzhi.shigongli.mapper.TaShopAccountLogMapper;
4 8
 import com.yunzhi.shigongli.mapper.TaShopAccountMapper;
5 9
 import com.yunzhi.shigongli.service.ITaShopAccountService;
6 10
 
11
+import org.springframework.beans.factory.annotation.Autowired;
7 12
 import org.springframework.stereotype.Service;
13
+import org.springframework.transaction.annotation.Transactional;
14
+
15
+import java.time.LocalDateTime;
8 16
 
9 17
 /**
10 18
  * <p>
@@ -17,4 +25,38 @@ import org.springframework.stereotype.Service;
17 25
 @Service
18 26
 public class TaShopAccountServiceImpl extends BaseServiceImpl<TaShopAccountMapper, TaShopAccount> implements ITaShopAccountService {
19 27
 
28
+    @Autowired
29
+    TaShopAccountMapper shopAccountMapper;
30
+
31
+    @Autowired
32
+    TaShopAccountLogMapper shopAccountLogMapper;
33
+
34
+    @Override
35
+    public TaShopAccount getByShop(String shopId) {
36
+        LambdaQueryWrapper<TaShopAccount> queryWrapper = new LambdaQueryWrapper<>();
37
+        queryWrapper.eq(TaShopAccount::getShopId, shopId);
38
+
39
+        return getOne(queryWrapper);
40
+    }
41
+
42
+    @Transactional(rollbackFor = Exception.class)
43
+    @Override
44
+    public boolean commissionSettlement(TaShopAccount taShopAccount, Integer charges) throws Exception {
45
+        int cnt = shopAccountMapper.commissionSettlement(taShopAccount.getAccountId(), charges);
46
+        if (cnt < 1) {
47
+            throw new Exception("待结算佣金不足");
48
+        }
49
+
50
+        TaShopAccountLog accountLog = new TaShopAccountLog();
51
+        accountLog.setAccountId(taShopAccount.getAccountId());
52
+        accountLog.setShopId(taShopAccount.getShopId());
53
+        accountLog.setSignType(Constants.ACCOUNT_EXPENSE);
54
+        accountLog.setAmountType(Constants.ACCOUNT_SETTLEMENT);
55
+        accountLog.setAmount(-charges);
56
+        accountLog.setCreateDate(LocalDateTime.now());
57
+
58
+        shopAccountLogMapper.insert(accountLog);
59
+
60
+        return true;
61
+    }
20 62
 }

+ 26
- 0
src/main/java/com/yunzhi/shigongli/vo/WxLoginParam.java Näytä tiedosto

@@ -0,0 +1,26 @@
1
+package com.yunzhi.shigongli.vo;
2
+
3
+
4
+import io.swagger.annotations.ApiModel;
5
+import io.swagger.annotations.ApiModelProperty;
6
+import lombok.Data;
7
+
8
+@ApiModel(description = "登录参数")
9
+@Data
10
+public class WxLoginParam {
11
+
12
+    @ApiModelProperty("personId")
13
+    String personId;
14
+
15
+    @ApiModelProperty("code")
16
+    String code;
17
+
18
+    @ApiModelProperty("来源类型")
19
+    String fromType;
20
+
21
+    @ApiModelProperty("推荐人")
22
+    String recommender;
23
+
24
+    @ApiModelProperty("二维码")
25
+    Integer qrCodeId;
26
+}

+ 7
- 0
src/main/resources/mapper/TaShopAccountMapper.xml Näytä tiedosto

@@ -8,6 +8,13 @@
8 8
         WHERE
9 9
             account_id = #{accountId}
10 10
     </update>
11
+    <update id="commissionSettlement">
12
+        UPDATE ta_shop_account t
13
+        SET t.paid_charges = t.paid_charges + #{charges}
14
+        WHERE
15
+            t.account_id = #{accountId}
16
+          AND t.brokerage_charges - t.paid_charges > #{charges}
17
+    </update>
11 18
 
12 19
     <select id="selectByShop" resultType="com.yunzhi.shigongli.entity.TaShopAccount">
13 20
         SELECT