xiongzhu 3 anni fa
parent
commit
07c6727d2a

+ 1 - 0
src/main/java/com/izouma/nineth/domain/SysConfig.java

@@ -24,6 +24,7 @@ public class SysConfig extends AuditedEntity {
     private String desc;
 
     @ApiModelProperty(value = "值", name = "value")
+    @Column(columnDefinition = "TEXT")
     private String value;
 
     @Enumerated(EnumType.STRING)

+ 4 - 0
src/main/java/com/izouma/nineth/repo/BalanceRecordRepo.java

@@ -1,6 +1,8 @@
 package com.izouma.nineth.repo;
 
 import com.izouma.nineth.domain.BalanceRecord;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 
@@ -11,4 +13,6 @@ public interface BalanceRecordRepo extends JpaRepository<BalanceRecord, Long>, J
     List<BalanceRecord> findByUserIdAndCreatedAtBetweenOrderByCreatedAt(Long userId, LocalDateTime start, LocalDateTime end);
 
     List<BalanceRecord> findByUserIdOrderByCreatedAt(Long userId);
+
+    Page<BalanceRecord> findByUserId(Long userId, Pageable pageable);
 }

+ 2 - 0
src/main/java/com/izouma/nineth/repo/UserBalanceRepo.java

@@ -1,6 +1,7 @@
 package com.izouma.nineth.repo;
 
 import com.izouma.nineth.domain.UserBalance;
+import org.springframework.data.domain.Page;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Modifying;
@@ -20,4 +21,5 @@ public interface UserBalanceRepo extends JpaRepository<UserBalance, Long>, JpaSp
     @Modifying
     @Transactional
     int unlock(Long userId);
+
 }

+ 3 - 0
src/main/java/com/izouma/nineth/service/OrderPayService.java

@@ -172,6 +172,9 @@ public class OrderPayService {
         if (amount.compareTo(minAmount) < 0) {
             throw new BusinessException("充值金额不能小于" + minAmount);
         }
+        if (amount.compareTo(new BigDecimal("50000")) > 0) {
+            throw new BusinessException("充值金额不能大于50000");
+        }
         RechargeOrder order = RechargeOrder.builder()
                 .id(snowflakeIdWorker.nextId())
                 .userId(userId)

+ 21 - 10
src/main/java/com/izouma/nineth/service/SysConfigService.java

@@ -7,6 +7,7 @@ import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.repo.SysConfigRepo;
 import com.izouma.nineth.utils.JpaUtils;
 import lombok.AllArgsConstructor;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Service;
 
@@ -14,6 +15,7 @@ import javax.annotation.PostConstruct;
 import java.math.BigDecimal;
 import java.time.LocalTime;
 import java.time.format.DateTimeFormatter;
+import java.util.List;
 
 @Service
 @AllArgsConstructor
@@ -50,7 +52,8 @@ public class SysConfigService {
 
     @PostConstruct
     public void init() {
-        if (sysConfigRepo.findByName("gift_gas_fee").isEmpty()) {
+        List<SysConfig> list = sysConfigRepo.findAll();
+        if (list.stream().anyMatch(i -> i.getName().equals("search_mode"))) {
             sysConfigRepo.save(SysConfig.builder()
                     .name("gift_gas_fee")
                     .desc("转赠gas费")
@@ -58,7 +61,7 @@ public class SysConfigService {
                     .value("1")
                     .build());
         }
-        if (sysConfigRepo.findByName("enable_wx_pub").isEmpty()) {
+        if (list.stream().anyMatch(i -> i.getName().equals("enable_wx_pub"))) {
             sysConfigRepo.save(SysConfig.builder()
                     .name("enable_wx_pub")
                     .desc("使用公众号支付")
@@ -66,7 +69,7 @@ public class SysConfigService {
                     .value("FALSE")
                     .build());
         }
-        if (sysConfigRepo.findByName("enable_wx_lite").isEmpty()) {
+        if (list.stream().anyMatch(i -> i.getName().equals("enable_wx_lite"))) {
             sysConfigRepo.save(SysConfig.builder()
                     .name("enable_wx_lite")
                     .desc("使用小程序支付")
@@ -74,7 +77,7 @@ public class SysConfigService {
                     .value("FALSE")
                     .build());
         }
-        if (sysConfigRepo.findByName("hold_days").isEmpty()) {
+        if (list.stream().anyMatch(i -> i.getName().equals("hold_days"))) {
             sysConfigRepo.save(SysConfig.builder()
                     .name("hold_days")
                     .desc("持有满几天可销售")
@@ -82,7 +85,7 @@ public class SysConfigService {
                     .value("5")
                     .build());
         }
-        if (sysConfigRepo.findByName("default_search_mode").isEmpty()) {
+        if (list.stream().anyMatch(i -> i.getName().equals("default_search_mode"))) {
             sysConfigRepo.save(SysConfig.builder()
                     .name("default_search_mode")
                     .desc("默认搜索方式")
@@ -90,7 +93,7 @@ public class SysConfigService {
                     .value("FULL")
                     .build());
         }
-        if (sysConfigRepo.findByName("enable_sand_quick").isEmpty()) {
+        if (list.stream().anyMatch(i -> i.getName().equals("enable_sand_quick"))) {
             sysConfigRepo.save(SysConfig.builder()
                     .name("enable_sand_quick")
                     .desc("使用衫德h5快捷支付")
@@ -98,7 +101,7 @@ public class SysConfigService {
                     .value("FALSE")
                     .build());
         }
-        if (sysConfigRepo.findByName("order_cancel_interval").isEmpty()) {
+        if (list.stream().anyMatch(i -> i.getName().equals("order_cancel_interval"))) {
             sysConfigRepo.save(SysConfig.builder()
                     .name("order_cancel_time")
                     .desc("订单自动取消间隔(S)")
@@ -106,7 +109,7 @@ public class SysConfigService {
                     .value("210")
                     .build());
         }
-        if (sysConfigRepo.findByName("pay_channel").isEmpty()) {
+        if (list.stream().anyMatch(i -> i.getName().equals("pay_channel"))) {
             sysConfigRepo.save(SysConfig.builder()
                     .name("pay_channel")
                     .desc("支付通道")
@@ -115,7 +118,7 @@ public class SysConfigService {
                     .options("hmPay,sandPay")
                     .build());
         }
-        if (sysConfigRepo.findByName("gift_days").isEmpty()) {
+        if (list.stream().anyMatch(i -> i.getName().equals("gift_days"))) {
             sysConfigRepo.save(SysConfig.builder()
                     .name("gift_days")
                     .desc("转赠满多少天可销售")
@@ -123,7 +126,7 @@ public class SysConfigService {
                     .value("20")
                     .build());
         }
-        if (sysConfigRepo.findByName("min_recharge_amount").isEmpty()) {
+        if (list.stream().anyMatch(i -> i.getName().equals("min_recharge_amount"))) {
             sysConfigRepo.save(SysConfig.builder()
                     .name("min_recharge_amount")
                     .desc("最小充值金额")
@@ -131,6 +134,14 @@ public class SysConfigService {
                     .value("100")
                     .build());
         }
+        if (list.stream().anyMatch(i -> i.getName().equals("enable_balance_pay"))) {
+            sysConfigRepo.save(SysConfig.builder()
+                    .name("enable_balance_pay")
+                    .desc("使用余额支付")
+                    .type(SysConfig.ValueType.BOOLEAN)
+                    .value("0")
+                    .build());
+        }
         SearchMode searchMode = SearchMode.valueOf(sysConfigRepo.findByName("default_search_mode").get().getValue());
         JpaUtils.setDefaultSearchMode(searchMode);
 

+ 2 - 1
src/main/java/com/izouma/nineth/web/OrderPayControllerV2.java

@@ -27,7 +27,7 @@ import java.math.BigDecimal;
 import java.util.regex.Pattern;
 
 @Controller
-@RequestMapping("/payOrder/v2")
+@RequestMapping({"/payOrder/v2", "/pay/v2"})
 @Slf4j
 @AllArgsConstructor
 public class OrderPayControllerV2 {
@@ -117,6 +117,7 @@ public class OrderPayControllerV2 {
     }
 
     @RequestMapping("/recharge")
+    @ResponseBody
     public String recharge(@RequestParam BigDecimal amount) {
         return orderPayService.recharge(SecurityUtils.getAuthenticatedUser().getId(), amount);
     }

+ 18 - 1
src/main/java/com/izouma/nineth/web/UserBalanceController.java

@@ -12,6 +12,7 @@ import com.izouma.nineth.repo.UserBalanceRepo;
 import com.izouma.nineth.service.UserBalanceService;
 import com.izouma.nineth.utils.DateTimeUtils;
 import com.izouma.nineth.utils.JpaUtils;
+import com.izouma.nineth.utils.SecurityUtils;
 import lombok.AllArgsConstructor;
 import org.apache.commons.io.IOUtils;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
@@ -35,7 +36,6 @@ import java.util.concurrent.ExecutionException;
 @RestController
 @RequestMapping("/userBalance")
 @AllArgsConstructor
-@PreAuthorize("hasRole('ADMIN')")
 public class UserBalanceController extends BaseController {
 
     private final UserBalanceRepo               userBalanceRepo;
@@ -46,37 +46,44 @@ public class UserBalanceController extends BaseController {
     private final AutoWithdrawRecordRepo        autoWithdrawRecordRepo;
 
     @PostMapping("/all")
+    @PreAuthorize("hasRole('ADMIN')")
     public Page<UserBalance> all(@RequestBody PageQuery pageQuery) {
         return userBalanceRepo.findAll(JpaUtils.toSpecification(pageQuery, UserBalance.class), JpaUtils.toPageRequest(pageQuery));
     }
 
     @PostMapping("/records")
+    @PreAuthorize("hasRole('ADMIN')")
     public Page<BalanceRecord> records(@RequestBody PageQuery pageQuery) {
         return balanceRecordRepo.findAll(JpaUtils.toSpecification(pageQuery, BalanceRecord.class), JpaUtils.toPageRequest(pageQuery));
     }
 
     @PostMapping("/settle")
+    @PreAuthorize("hasRole('ADMIN')")
     public void settle(@RequestParam LocalDate start, @RequestParam LocalDate end) {
         userBalanceService.settle(start, end);
     }
 
     @PostMapping(value = "/exportWithdraw")
+    @PreAuthorize("hasRole('ADMIN')")
     public void exportWithdraw(String remark) throws IOException, InvalidFormatException {
         userBalanceService.exportWithdrawAsync(remark);
     }
 
     @PostMapping(value = "/exportHistory")
+    @PreAuthorize("hasRole('ADMIN')")
     public Page<ExportWithdraw> exportHistory(Pageable pageable) {
         return exportWithdrawRepo.findAll(pageable);
     }
 
     @PostMapping("/importFail")
+    @PreAuthorize("hasRole('ADMIN')")
     public void importFail(@RequestPart("withdrawList") MultipartFile withdrawFile,
                            @RequestPart("failList") MultipartFile failFile) throws IOException {
         userBalanceService.importFail(withdrawFile, failFile);
     }
 
     @PostMapping("/autoWithdraw")
+    @PreAuthorize("hasRole('ADMIN')")
     public void autoWithdraw() throws ExecutionException, InterruptedException {
 
         LocalDate date = LocalDate.now();
@@ -86,4 +93,14 @@ public class UserBalanceController extends BaseController {
 
         userBalanceService.autoWithdraw(date);
     }
+
+    @GetMapping("/my")
+    public UserBalance my() {
+        return userBalanceRepo.findById(SecurityUtils.getAuthenticatedUser().getId()).orElse(new UserBalance());
+    }
+
+    @GetMapping("/my/record")
+    public Page<BalanceRecord> myRecord(Pageable pageable) {
+        return balanceRecordRepo.findByUserId(SecurityUtils.getAuthenticatedUser().getId(), pageable);
+    }
 }

+ 145 - 2
src/main/vue/src/views/SysConfigList.vue

@@ -112,6 +112,51 @@
                 <el-button type="primary" size="mini" @click="save" :loading="saving">保存</el-button>
             </span>
         </el-dialog>
+
+        <el-dialog title="支付选项" :visible.sync="showPayConfigDialog" width="800px">
+            <div class="pay-config-item-list">
+                <div class="pay-config-item head">
+                    <div class="key">KEY</div>
+                    <div class="name">名称</div>
+                    <div class="icon">图标</div>
+                    <div class="show">显示</div>
+                    <div class="enabled">可用</div>
+                    <div class="sort">排序</div>
+                </div>
+                <div class="pay-config-item" v-for="item in payConfig">
+                    <div class="key">
+                        <el-input v-model="item.key" size="mini"></el-input>
+                    </div>
+                    <div class="name">
+                        <el-input v-model="item.name" size="mini"></el-input>
+                    </div>
+                    <div class="icon">
+                        <el-image
+                            @click="addIcon(item)"
+                            :src="item.icon"
+                            v-if="item.icon"
+                            fit="contain"
+                            style="width: 26px; height: 26px"
+                        ></el-image>
+                        <el-button v-else type="text" @click="addIcon(item)">上传</el-button>
+                    </div>
+                    <div class="show">
+                        <el-checkbox v-model="item.show"></el-checkbox>
+                    </div>
+                    <div class="enabled">
+                        <el-checkbox v-model="item.enabled"></el-checkbox>
+                    </div>
+                    <div class="sort">
+                        <el-input-number v-model="item.sort" :controls="false"></el-input-number>
+                    </div>
+                </div>
+            </div>
+            <el-button @click="addPayConfig" size="mini">添加 </el-button>
+            <div slot="footer">
+                <el-button @click="showPayConfigDialog = false" size="mini">取消</el-button>
+                <el-button @click="savePayConfig" size="mini" type="primary" :loading="saving">保存</el-button>
+            </div>
+        </el-dialog>
     </div>
 </template>
 <script>
@@ -177,7 +222,9 @@ export default {
                     value: 'SELECT'
                 }
             ],
-            htmlContents: ['']
+            htmlContents: [''],
+            showPayConfigDialog: false,
+            payConfig: []
         };
     },
     computed: {
@@ -204,6 +251,16 @@ export default {
             });
         },
         editRow(row, edit) {
+            if (row && row.name === 'pay_config') {
+                if (row.value) {
+                    this.payConfig = JSON.parse(row.value).sort((a, b) => {
+                        return a.sort - b.sort;
+                    });
+                }
+                this.formData = { ...row };
+                this.showPayConfigDialog = true;
+                return;
+            }
             this.edit = edit;
             if (!row) {
                 row = {
@@ -267,8 +324,94 @@ export default {
         typeFormatter(row, cell, cellValue) {
             let item = this.valueTypes.find(i => i.value === cellValue);
             return item ? item.label : '';
+        },
+        addPayConfig() {
+            this.payConfig.push({
+                name: '',
+                icon: '',
+                show: false,
+                enabled: false,
+                description: '',
+                sort: 0
+            });
+        },
+        savePayConfig() {
+            let data = { ...this.formData, value: JSON.stringify(this.payConfig) };
+            this.saving = true;
+            this.$http
+                .post('/sysConfig/save', data, { body: 'json' })
+                .then(res => {
+                    this.saving = false;
+                    this.$message.success('成功');
+                    this.showPayConfigDialog = false;
+                    this.getData();
+                })
+                .catch(e => {
+                    console.log(e);
+                    this.saving = false;
+                    this.showPayConfigDialog = false;
+                    this.$message.error(e.error);
+                });
+        },
+        addIcon(item) {
+            const input = document.createElement('input');
+            input.type = 'file';
+            input.accept = 'image/*';
+            input.onchange = e => {
+                console.log(input.files[0]);
+                let form = new FormData();
+                form.append('file', input.files[0]);
+                this.$axios.post('/upload/file', form).then(res => {
+                    this.$set(item, 'icon', res.data);
+                });
+            };
+            input.click();
         }
     }
 };
 </script>
-<style lang="less" scoped></style>
+<style lang="less" scoped>
+.pay-config-item-list {
+    .pay-config-item {
+        margin-bottom: 6px;
+        .flex();
+        font-size: 14px;
+        .key {
+            width: 150px;
+        }
+        .name {
+            margin-left: 20px;
+            width: 150px;
+        }
+        .icon {
+            width: 50px;
+            margin-left: 10px;
+            font-size: 0;
+            text-align: center;
+        }
+        .show {
+            width: 50px;
+            margin-left: 10px;
+            text-align: center;
+        }
+        .enabled {
+            width: 50px;
+            margin-left: 10px;
+            text-align: center;
+        }
+        .sort {
+            width: 80px;
+            margin-left: 10px;
+            text-align: center;
+            .el-input-number {
+                width: 60px;
+            }
+        }
+        &.head {
+            .icon {
+                font-size: 14px;
+            }
+        }
+    }
+}
+</style>