admin
2024-07-09 1a43717440c8d112fc72b6344a5f6a26353ab56e
用户设置除非后台设置,否者不自动添加设置
9个文件已修改
1个文件已添加
263 ■■■■ 已修改文件
src/main/java/com/taoke/autopay/controller/admin/AdminWxUserController.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/controller/client/OrderController.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/dao/KeyOrderMapper.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/service/WxUserOrderCountService.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/service/WxUserSettingService.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/service/impl/KeyOrderServiceImpl.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/service/impl/WxUserServiceImpl.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/service/impl/WxUserSettingServiceImpl.java 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/KeyOrderMapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/static/admin/pay_settings.html 170 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/controller/admin/AdminWxUserController.java
@@ -98,7 +98,7 @@
    @ResponseBody
    @RequestMapping("getOrderSettings")
    public String getOrderSettings(Long id) {
        WxUserSettings settings = wxUserSettingService.selectByUid(id);
        WxUserSettings settings = wxUserSettingService.getUserSettings(id);
        return JsonUtil.loadTrueResult(WxUserFactory.createVO(settings));
    }
@@ -110,7 +110,7 @@
        settings.setTotalOrderCountPerDay(vo.getTotalSubmitCount());
        settings.setDyOrderCountPerDay(vo.getDyPayCount());
        settings.setKsOrderCountPerDay(vo.getKsPayCount());
        wxUserSettingService.updateSelective(settings);
        wxUserSettingService.add(settings);
        return JsonUtil.loadTrueResult("");
    }
src/main/java/com/taoke/autopay/controller/client/OrderController.java
@@ -224,7 +224,7 @@
            if (order.getUid() != null) {
                WxUserOrderCount countInfo = wxUserOrderCountService.get(order.getUid(), OrderCountTypeEnum.DY_ORDER_PAY, TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd"));
                if (countInfo != null) {
                    WxUserSettings settings = wxUserSettingService.selectByUid(order.getUid());
                    WxUserSettings settings = wxUserSettingService.getUserSettings(order.getUid());
                    if (settings.getDyOrderCountPerDay() <= countInfo.getOrderCount()) {
                        throw new Exception("今日已达支付次数上限:" + settings.getDyOrderCountPerDay());
                    }
@@ -288,7 +288,7 @@
            if (order.getUid() != null) {
                WxUserOrderCount countInfo = wxUserOrderCountService.get(order.getUid(), OrderCountTypeEnum.DY_ORDER_PAY, TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd"));
                if (countInfo != null) {
                    WxUserSettings settings = wxUserSettingService.selectByUid(order.getUid());
                    WxUserSettings settings = wxUserSettingService.getUserSettings(order.getUid());
                    if (settings.getDyOrderCountPerDay() <= countInfo.getOrderCount()) {
                        throw new Exception("今日已达支付次数上限:" + settings.getDyOrderCountPerDay());
                    }
src/main/java/com/taoke/autopay/dao/KeyOrderMapper.java
@@ -21,7 +21,7 @@
    long count(@Param("query") DaoQuery query);
    List<OrderDistributeCountInfo> listDistributeUids(@Param("minActiveTime") Date minActiveTime);
    List<OrderDistributeCountInfo> listDistributeUids(@Param("minActiveTime") Date minActiveTime, @Param("minKeyOrderCreateTime") Date minKeyOrderCreateTime);
    List<KeyOrder>  listNotDistributed(@Param("start") int start,@Param("count") int count);
src/main/java/com/taoke/autopay/service/WxUserOrderCountService.java
@@ -14,4 +14,6 @@
    public void addOrderCount(Long uid, OrderCountTypeEnum orderType, String day, int count, Integer maxCount) throws WxOrderCountException;
    public WxUserOrderCount get(Long uid, OrderCountTypeEnum orderType, String day);
}
src/main/java/com/taoke/autopay/service/WxUserSettingService.java
@@ -14,6 +14,8 @@
    public void add(WxUserSettings settings);
    public WxUserSettings getUserSettings(Long uid);
    public WxUserSettings selectByUid(Long uid);
    public void updateSelective(WxUserSettings settings);
src/main/java/com/taoke/autopay/service/impl/KeyOrderServiceImpl.java
@@ -51,7 +51,7 @@
    public KeyOrder addKeyOrder(SubmitKeyInfo keyInfo, Long uid, String day) throws KeyOrderException, WxOrderCountException {
        // 判断提交次数是否过量
        if (uid != null) {
            WxUserSettings settings = wxUserSettingService.selectByUid(uid);
            WxUserSettings settings = wxUserSettingService.getUserSettings(uid);
            wxUserOrderCountService.addOrderCount(uid, OrderCountTypeEnum.SUBMIT_TOKEN_COUNT, day, 1, settings.getTotalOrderCountPerDay());
        }
        String id = OrderFactory.createId(keyInfo.getKey());
@@ -145,8 +145,8 @@
    @Override
    public Long getCanDistributeUid() {
        // 最近1小时有活跃
        List<OrderDistributeCountInfo> list = keyOrderMapper.listDistributeUids(new Date(System.currentTimeMillis() - 1000 * 60 * 60L));
        // 最近1小时有活跃,且不算12以上未执行的数据
        List<OrderDistributeCountInfo> list = keyOrderMapper.listDistributeUids(new Date(System.currentTimeMillis() - 1000 * 60 * 60L),new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 12L));
        if (list == null || list.size() == 0) {
            return null;
        }
src/main/java/com/taoke/autopay/service/impl/WxUserServiceImpl.java
@@ -50,22 +50,6 @@
            user.setLoginTime(new Date());
            user.setCreateTime(new Date());
            wxUserInfoMapper.insertSelective(user);
            WxUserSettings settings = new WxUserSettings();
            settings.setId(user.getId());
            String value = systemConfigService.getValueCache(SystemConfigKeyEnum.DY_ORDER_MAX_PAY_COUNT_DEFAULT);
            if (!StringUtil.isNullOrEmpty(value)) {
                settings.setDyOrderCountPerDay(Integer.parseInt(value));
            }
            value = systemConfigService.getValueCache(SystemConfigKeyEnum.KS_ORDER_MAX_PAY_COUNT_DEFAULT);
            if (!StringUtil.isNullOrEmpty(value)) {
                settings.setKsOrderCountPerDay(Integer.parseInt(value));
            }
            value = systemConfigService.getValueCache(SystemConfigKeyEnum.ORDER_MAX_SUBMIT_COUNT_DEFAULT);
            if (!StringUtil.isNullOrEmpty(value)) {
                settings.setTotalOrderCountPerDay(Integer.parseInt(value));
            }
            wxUserSettingService.add(settings);
            return user;
        } else {
            WxUserInfo update = new WxUserInfo();
src/main/java/com/taoke/autopay/service/impl/WxUserSettingServiceImpl.java
@@ -7,6 +7,7 @@
import com.taoke.autopay.service.WxUserSettingService;
import com.taoke.autopay.utils.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
@@ -25,13 +26,53 @@
    @Resource
    private WxUserSettingsMapper wxUserSettingsMapper;
    @Resource
    private SystemConfigService systemConfigService;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void add(WxUserSettings settings) {
        if (settings.getCreateTime() == null) {
            settings.setCreateTime(new Date());
        WxUserSettings old =   wxUserSettingsMapper.selectByPrimaryKeyForUpdate(settings.getId());
        if(old==null) {
            if (settings.getCreateTime() == null) {
                settings.setCreateTime(new Date());
            }
            wxUserSettingsMapper.insertSelective(settings);
        }else{
            settings.setUpdateTime(new Date());
            wxUserSettingsMapper.updateByPrimaryKeySelective(settings);
        }
        wxUserSettingsMapper.insertSelective(settings);
    }
    /**
     * @author hxh
     * @description 获取用户设置,如果没有设置就采用默认设置
     * @date 18:32 2024/7/9
     * @param: uid
     * @return com.taoke.autopay.entity.WxUserSettings
     **/
    @Override
    public WxUserSettings getUserSettings(Long uid) {
        WxUserSettings settings = selectByUid(uid);
        if(settings!=null){
            return settings;
        }
        settings = new WxUserSettings();
        settings.setId(uid);
        String value = systemConfigService.getValueCache(SystemConfigKeyEnum.DY_ORDER_MAX_PAY_COUNT_DEFAULT);
        if (!StringUtil.isNullOrEmpty(value)) {
            settings.setDyOrderCountPerDay(Integer.parseInt(value));
        }
        value = systemConfigService.getValueCache(SystemConfigKeyEnum.KS_ORDER_MAX_PAY_COUNT_DEFAULT);
        if (!StringUtil.isNullOrEmpty(value)) {
            settings.setKsOrderCountPerDay(Integer.parseInt(value));
        }
        value = systemConfigService.getValueCache(SystemConfigKeyEnum.ORDER_MAX_SUBMIT_COUNT_DEFAULT);
        if (!StringUtil.isNullOrEmpty(value)) {
            settings.setTotalOrderCountPerDay(Integer.parseInt(value));
        }
       return settings;
    }
    @Override
@@ -55,6 +96,10 @@
        if (uidList == null || uidList.size() == 0) {
            return new ArrayList<>();
        }
        return wxUserSettingsMapper.listByUids(uidList);
        List<WxUserSettings> list=new ArrayList<>();
        for(Long uid:uidList){
            list.add(getUserSettings(uid));
        }
        return list;
    }
}
src/main/resources/mapper/KeyOrderMapper.xml
@@ -101,7 +101,7 @@
      <if test="orderMoney != null">#{orderMoney,jdbcType=DECIMAL}</if>
    </trim> 
  </insert>  
  <update id="updateByPrimaryKey" parameterType="com.taoke.autopay.entity.KeyOrder">update table_order set uid = #{uid,jdbcType=BIGINT},`key` = #{key,jdbcType=VARCHAR},order_type = #{orderType,jdbcType=INTEGER},order_no = #{orderNo,jdbcType=VARCHAR},order_state = #{orderState,jdbcType=INTEGER},state = #{state,jdbcType=INTEGER},state_desc = #{stateDesc,jdbcType=VARCHAR},distribute_client_uid = #{distributeClientUid,jdbcType=BIGINT},distribute_time = #{distributeTime,jdbcType=TIMESTAMP},create_time = #{createTime,jdbcType=TIMESTAMP},update_time = #{updateTime,jdbcType=TIMESTAMP} ,excute_pay_time =#{excutePayTime,jdbcType=TIMESTAMP} ,order_money =#{orderMoney,jdbcType=DECIMAL}, where id = #{id,jdbcType=VARCHAR}</update>
  <update id="updateByPrimaryKey" parameterType="com.taoke.autopay.entity.KeyOrder">update table_order set uid = #{uid,jdbcType=BIGINT},`key` = #{key,jdbcType=VARCHAR},order_type = #{orderType,jdbcType=INTEGER},order_no = #{orderNo,jdbcType=VARCHAR},order_state = #{orderState,jdbcType=INTEGER},state = #{state,jdbcType=INTEGER},state_desc = #{stateDesc,jdbcType=VARCHAR},distribute_client_uid = #{distributeClientUid,jdbcType=BIGINT},distribute_time = #{distributeTime,jdbcType=TIMESTAMP},create_time = #{createTime,jdbcType=TIMESTAMP},update_time = #{updateTime,jdbcType=TIMESTAMP} ,excute_pay_time =#{excutePayTime,jdbcType=TIMESTAMP}, pay_time =#{payTime,jdbcType=TIMESTAMP} ,order_money =#{orderMoney,jdbcType=DECIMAL}, where id = #{id,jdbcType=VARCHAR}</update>
  <update id="updateByPrimaryKeySelective" parameterType="com.taoke.autopay.entity.KeyOrder">update table_order 
    <set> 
      <if test="uid != null">uid=#{uid,jdbcType=BIGINT},</if>  
@@ -120,7 +120,7 @@
      <if test="orderMoney !=null">order_money =#{orderMoney,jdbcType=DECIMAL},</if>
    </set> where id = #{id,jdbcType=VARCHAR}
  </update>  
  <select id="listDistributeUids" resultMap="DistributeResultMap" parameterType="java.util.Date">SELECT u.`id` as uid, IF( a.count IS NULL,0,a.count) AS `count` FROM `table_user` u LEFT JOIN (SELECT o.`distribute_client_uid` AS uid,COUNT(*) AS `count` FROM `table_order` o WHERE o.`state` = 0 GROUP BY o.`distribute_client_uid`) a ON a.uid = u.`id` WHERE rule=0
  <select id="listDistributeUids" resultMap="DistributeResultMap" >SELECT u.`id` as uid, IF( a.count IS NULL,0,a.count) AS `count` FROM `table_user` u LEFT JOIN (SELECT o.`distribute_client_uid` AS uid,COUNT(*) AS `count` FROM `table_order` o WHERE o.`state` = 0 and  create_time > #{minKeyOrderCreateTime} GROUP BY o.`distribute_client_uid`) a ON a.uid = u.`id` WHERE rule=0
    <if test="minActiveTime!=null">and active_time &gt;=#{minActiveTime}</if> 
  </select>  
  <select id="listNotDistributed" resultMap="BaseResultMap">select 
src/main/resources/static/admin/pay_settings.html
New file
@@ -0,0 +1,170 @@
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport"
            content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <title>支付设置</title>
        <link rel="stylesheet" type="text/css" href="layui/css/layui.css" />
        <style>
            body {
                padding: 10px;
            }
            input {
                width: 100px !important;
                display: inline;
            }
            .layui-input-inline{
                width: 400px;
                display:flex;
                align-items:center;
            }
            .layui-form-item{
                display:flex;
                    align-items:center;
            }
            .layui-icon{
                margin-left: 10px;
            }
        </style>
    </head>
    <body>
        <form class="layui-form" lay-filter="edit">
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-inline">
                   <input class="layui-btn layui-btn-danger" id="add" type="button" value="新增金额"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">口令可提交时间</label>
                <div class="layui-input-inline">
                    <input type="text" id = "start_submit_time" name="startSubmitTime" required lay-verify="required|time"
                        placeholder="起始时间" autocomplete="off" class="layui-input layui-input-inline">
                    <input type="text" id = "end_submit_time" name="endSubmitTime" required lay-verify="required|time"
                            placeholder="结束时间" autocomplete="off" class="layui-input layui-input-inline">
                </div>
            </div>
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="sure" id="sure">确定</button>
            </div>
        </form>
        <script src="layui/layui.js" type="text/javascript" charset="utf-8"></script>
        <script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="js/http_api.js"></script>
        <script type="text/html" id="payMoneyTemplate">
               <div class="layui-form-item">
                    <label class="layui-form-label">{{ d.label }}</label>
                    <div class="layui-input-inline">
                        <input type="text" name="money_{{d.index}}" required lay-verify="required|money"
                            placeholder="保留2位小数" autocomplete="off" value="{{ d.money }}" class="layui-input money">
                        <span class="layui-icon layui-icon-close delete"></span>
                    </div>
               </div>
        </script>
        <script>
            layui.use(['form', 'layedit', 'laydate', 'laytpl'], function() {
                var form = layui.form,
                    layer = layui.layer,
                    laydate = layui.laydate,
                    laytpl = layui.laytpl
                    ;
                    laydate.render({
                      elem: "#start_submit_time",
                      type: "time",
                      value: new Date(),
                      isInitValue:false
                    });
                    laydate.render({
                      elem: "#end_submit_time",
                      type: "time",
                      value: new Date(),
                      isInitValue:false
                    });
                 $("#add").click(function(){
                     const index = $(".money").length + 1;
                     laytpl($('#payMoneyTemplate').html()).render({"index": index, "label":"金额"+ index,"money":""}, function(html){
                                             $("#add").parent().parent().before(html);
                     });
                     $(".delete").bind("click",function(e){
                                          $(e.target).parent().parent().remove();
                     });
                 });
                 // 在 iframe 内部的子页面中
                 // 示例:向父页面发送消息
                 window.parent.postMessage('Hello from iframe child!', window.location.href);
                //自定义验证规则
                form.verify({
                    money: [/^\d+(\.\d{1,2})?$/, "金额最多保留2位小数"]
                });
                let index = layer.load(1);
                $.post("/admin/api/settings/getPayMoneyAndTime", {},
                    function(response) {
                        layer.close(index);
                        if (response.code == 0) {
                            form.val("edit", response.data);
                            // 设置资金
                            for(var i=0;i<response.data.moneys.length;i++){
                                laytpl($('#payMoneyTemplate').html()).render({"index": i+1, "label":"金额"+ (i+1),"money":response.data.moneys[i]}, function(html){
                                                        $("#add").parent().parent().before(html);
                                });
                            }
                        } else {
                            layer.msg(response.msg);
                        }
                    }, 'json').fail(function(jqXHR, textStatus, errorThrown) {
                    layer.msg("网络请求失败");
                    layer.close(index);
                });
                //监听提交
                form.on('submit(sure)', function(data) {
                    var params = {"moneys":[]};
                    for(var key in data.field){
                        if(key.indexOf("money_")==0){
                                params["moneys"].push(data.field[key]);
                        }else{
                            params[key] = data.field[key];
                        }
                    }
                    params["moneys"] = JSON.stringify(params["moneys"]);
                    $.post("/admin/api/settings/setPayMoneyAndTime", params,
                        function(response) {
                            if (response.code == 0) {
                                layer.msg("修改成功");
                            } else {
                                layer.msg(response.msg);
                            }
                        }, 'json').fail(function(jqXHR, textStatus, errorThrown) {
                        layer.msg("网络请求失败");
                    });
                    return false;
                });
            });
        </script>
    </body>
</html>