| | |
| | | import com.taoke.autopay.entity.AdminUser; |
| | | import com.taoke.autopay.entity.WxUserInfo; |
| | | import com.taoke.autopay.entity.WxUserSettings; |
| | | import com.taoke.autopay.entity.credit.UserCreditBalance; |
| | | import com.taoke.autopay.factory.WxUserFactory; |
| | | import com.taoke.autopay.service.AdminUserService; |
| | | import com.taoke.autopay.service.WxUserService; |
| | | import com.taoke.autopay.service.WxUserSettingService; |
| | | import com.taoke.autopay.service.credit.UserCreditBalanceService; |
| | | import com.taoke.autopay.utils.TimeUtil; |
| | | import com.taoke.autopay.vo.WxUserOrderSettingVO; |
| | | import com.taoke.autopay.vo.WxUserVO; |
| | |
| | | @Resource |
| | | private WxUserSettingService wxUserSettingService; |
| | | |
| | | @Resource |
| | | private UserCreditBalanceService userCreditBalanceService; |
| | | |
| | | |
| | | /** |
| | | * @param key |
| | |
| | | List<WxUserInfo> userList = wxUserService.list(query, page, limit); |
| | | long count = wxUserService.count(query); |
| | | Map<Long, WxUserSettings> settingsMap = new HashMap<>(); |
| | | Map<Long, UserCreditBalance> creditBalanceMap = new HashMap<>(); |
| | | if (userList.size() > 0) { |
| | | List<Long> uids = new ArrayList<>(); |
| | | for (WxUserInfo u : userList) { |
| | |
| | | for (WxUserSettings setting : settings) { |
| | | settingsMap.put(setting.getId(), setting); |
| | | } |
| | | // 获取用户积分余额 |
| | | creditBalanceMap = userCreditBalanceService.getCreditBalancesByUserIds(uids); |
| | | |
| | | } |
| | | |
| | | |
| | | // 转vo |
| | | List<WxUserVO> voList = new ArrayList<>(); |
| | | for (WxUserInfo user : userList) { |
| | | voList.add(WxUserFactory.createVO(user, settingsMap.get(user.getId()))); |
| | | voList.add(WxUserFactory.createVO(user, settingsMap.get(user.getId()), creditBalanceMap.get(user.getId()))); |
| | | } |
| | | JSONObject data = new JSONObject(); |
| | | data.put("count", count); |
| | |
| | | import com.taoke.autopay.utils.StringUtil; |
| | | import com.taoke.autopay.utils.TimeUtil; |
| | | import com.taoke.autopay.vo.admin.UserCreditExchangeRecordSearchVO; |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | |
| | | |
| | | private Gson gson = new GsonBuilder() |
| | | .registerTypeAdapter(Date.class, new TypeAdapter<Date>() { |
| | | @Override |
| | | public void write(JsonWriter out, Date value) throws IOException { |
| | | String desc = ""; |
| | | if (value != null) { |
| | | desc = TimeUtil.getGernalTime(value.getTime(), "yyyy-MM-dd HH:mm:ss"); |
| | | out.value(desc); |
| | | } else { |
| | | out.value(""); |
| | | } |
| | | } |
| | | @Override |
| | | public void write(JsonWriter out, Date value) throws IOException { |
| | | String desc = ""; |
| | | if (value != null) { |
| | | desc = TimeUtil.getGernalTime(value.getTime(), "yyyy-MM-dd HH:mm:ss"); |
| | | out.value(desc); |
| | | } else { |
| | | out.value(""); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Date read(JsonReader in) throws IOException { |
| | | return new Date(); |
| | | } |
| | | }) .registerTypeAdapter(CreditExchangeRecord.ExchangeType.class, new TypeAdapter<CreditExchangeRecord.ExchangeType>() { |
| | | @Override |
| | | public Date read(JsonReader in) throws IOException { |
| | | return new Date(); |
| | | } |
| | | }).registerTypeAdapter(CreditExchangeRecord.ExchangeType.class, new TypeAdapter<CreditExchangeRecord.ExchangeType>() { |
| | | @Override |
| | | public void write(JsonWriter out, CreditExchangeRecord.ExchangeType value) throws IOException { |
| | | String desc = ""; |
| | |
| | | @ResponseBody |
| | | @RequestMapping("list") |
| | | public String listRecords(UserCreditExchangeRecordSearchVO search, int page, int limit) { |
| | | CreditExchangeRecordMapper.DaoQuery query = CreditExchangeRecordMapper.DaoQuery.builder().build(); |
| | | CreditExchangeRecordMapper.DaoQuery query = CreditExchangeRecordMapper.DaoQuery.builder().build(); |
| | | if (!StringUtil.isNullOrEmpty(search.getUid())) { |
| | | query.uid = Long.parseLong(search.getUid()); |
| | | } |
| | | if (!StringUtil.isNullOrEmpty(search.getStatus())) { |
| | | query.exchangeStatus =Integer.parseInt(search.getStatus()); |
| | | query.exchangeStatus = Integer.parseInt(search.getStatus()); |
| | | } |
| | | |
| | | if (!StringUtil.isNullOrEmpty(search.getStart_date())) { |
| | |
| | | } |
| | | |
| | | if (!StringUtil.isNullOrEmpty(search.getEnd_date())) { |
| | | query.maxCreateTime = new Date(TimeUtil.convertToTimeTemp(search.getEnd_date(), "yyyy-MM-dd")+1000*60*60*24L); |
| | | query.maxCreateTime = new Date(TimeUtil.convertToTimeTemp(search.getEnd_date(), "yyyy-MM-dd") + 1000 * 60 * 60 * 24L); |
| | | } |
| | | query.sortList = Arrays.asList(new String[]{"_create_time desc"}); |
| | | query.start = (long) (page - 1) * limit; |
| | |
| | | */ |
| | | @ResponseBody |
| | | @RequestMapping("approve") |
| | | public String approveRecords(Long[] ids) { |
| | | public String approveRecords(String ids) { |
| | | int successCount = 0; |
| | | int failCount = 0; |
| | | for(Long id :ids) { |
| | | JSONArray idsArray = JSONArray.fromObject(ids); |
| | | for (int i = 0; i < idsArray.size(); i++) { |
| | | long id = idsArray.optLong(i); |
| | | try { |
| | | userCreditExchangeManager.approveExchange(id); |
| | | successCount+=1; |
| | | successCount += 1; |
| | | } catch (UserCreditExchangeException e) { |
| | | failCount+=1; |
| | | failCount += 1; |
| | | } |
| | | } |
| | | return JsonUtil.loadTrueResult(String.format("成功通过 %d 条记录 通过异常 %d 条记录", successCount, failCount)); |
| | | return JsonUtil.loadFalseResult(String.format("成功通过 %d 条记录 通过异常 %d 条记录", successCount, failCount)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @ResponseBody |
| | | @RequestMapping("reject") |
| | | public String rejectRecords(Long[] ids) { |
| | | public String rejectRecords(String ids) { |
| | | int successCount = 0; |
| | | int failCount = 0; |
| | | for(Long id :ids) { |
| | | JSONArray idsArray = JSONArray.fromObject(ids); |
| | | for (int i = 0; i < idsArray.size(); i++) { |
| | | long id = idsArray.optLong(i); |
| | | try { |
| | | userCreditExchangeManager.rejectExchange(id); |
| | | successCount+=1; |
| | | successCount += 1; |
| | | } catch (UserCreditExchangeException e) { |
| | | failCount+=1; |
| | | failCount += 1; |
| | | } |
| | | } |
| | | return JsonUtil.loadTrueResult(String.format("成功驳回 %d 条记录 驳回异常 %d 条记录", successCount, failCount)); |
| | | return JsonUtil.loadFalseResult(String.format("成功驳回 %d 条记录 驳回异常 %d 条记录", successCount, failCount)); |
| | | } |
| | | } |
| | |
| | | import com.google.gson.Gson; |
| | | import com.taoke.autopay.entity.WxUserInfo; |
| | | import com.taoke.autopay.entity.WxUserSettings; |
| | | import com.taoke.autopay.entity.credit.UserCreditBalance; |
| | | import com.taoke.autopay.utils.IPUtil; |
| | | import com.taoke.autopay.utils.StringUtil; |
| | | import com.taoke.autopay.vo.WxUserOrderSettingVO; |
| | |
| | | */ |
| | | public class WxUserFactory { |
| | | |
| | | public static WxUserVO createVO(WxUserInfo user, WxUserSettings settings) { |
| | | public static WxUserVO createVO(WxUserInfo user, WxUserSettings settings, UserCreditBalance balance) { |
| | | WxUserVO vo = new WxUserVO(); |
| | | vo.setId(user.getId()); |
| | | vo.setCreateTime(user.getCreateTime()); |
| | |
| | | vo.setIpInfo(new Gson().fromJson(user.getLatestIPInfo(), IPUtil.IPInfo.class)); |
| | | } |
| | | vo.setStatus(user.getStatus()); |
| | | vo.setCredit(balance==null?0:balance.getCreditBalance()); |
| | | if(settings!=null) { |
| | | WxUserOrderSettingVO settingVO = new WxUserOrderSettingVO(settings.getDyOrderCountPerDay(), settings.getKsOrderCountPerDay(), settings.getTotalOrderCountPerDay()); |
| | | vo.setOrderSetting(settingVO); |
| | |
| | | throw new UserCreditExchangeException(UserCreditExchangeException.CODE_NOT_BIND_ALIPAY_ACCOUNT, "兑换记录不存在"); |
| | | } |
| | | |
| | | if(exchangeRecord.getExchangeStatus() != CreditExchangeRecord.STATUS_NOT_VERIFY){ |
| | | throw new UserCreditExchangeException(UserCreditExchangeException.CODE_COMMON, "兑换已处理"); |
| | | } |
| | | |
| | | // 如果是红包兑换,调用通过兑换逻辑(TODO) |
| | | if (exchangeRecord.getExchangeType() == CreditExchangeRecord.ExchangeType.FUND_EXCHANGE) { |
| | | // TODO: 调用通过兑换逻辑 |
| | |
| | | throw new UserCreditExchangeException(UserCreditExchangeException.CODE_NOT_BIND_ALIPAY_ACCOUNT, "兑换记录不存在"); |
| | | } |
| | | |
| | | if(exchangeRecord.getExchangeStatus() != CreditExchangeRecord.STATUS_NOT_VERIFY){ |
| | | throw new UserCreditExchangeException(UserCreditExchangeException.CODE_COMMON, "兑换已处理"); |
| | | } |
| | | |
| | | |
| | | // 退回用户积分余额 |
| | | userCreditBalanceService.increaseCreditBalance(exchangeRecord.getUid(), exchangeRecord.getConsumedCredits()); |
| | | // 添加积分记录 |
| | |
| | | private String ip; |
| | | private IPUtil.IPInfo ipInfo; |
| | | private Integer status; |
| | | private int credit; |
| | | } |
| | |
| | | templet: function (d) { |
| | | return d.status == 0 ? '正常' : '封禁' |
| | | } |
| | | }, { |
| | | },{ |
| | | field: '', |
| | | title: '积分是否开启', |
| | | width: 100, |
| | | sort: false, |
| | | templet: function (d) { |
| | | return d.creditEnable == 0 ? '关闭' : '<span style="color: green">开启</span>' |
| | | } |
| | | }, |
| | | |
| | | |
| | | { |
| | | field: 'createTime', |
| | | title: '创建时间', |
| | | width: 180, |
| | |
| | | <div class="layui-form-item"> |
| | | <label class="layui-form-label">是否开启积分:</label> |
| | | <div class="layui-input-inline"> |
| | | <input type="checkbox" name="creditEnable" required lay-verify="" autocomplete="off" class="layui-input"> |
| | | <div class="layui-form-mid layui-word-aux">队员是否可得积分</div> |
| | | <input type="checkbox" checked name="creditEnable" lay-skin="switch" value="1" lay-filter="switchTest" title=""> |
| | | |
| | | </div> |
| | | </div> |
| | | |
| | |
| | | <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="toolbarDemo"> |
| | | <div class="layui-btn-container"> |
| | | <!-- <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>--> |
| | | <!-- <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>--> |
| | | <!-- <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>--> |
| | | </div> |
| | | </script> |
| | | <script> |
| | | layui.use(['form', 'jquery', 'layer', 'table', 'laydate'], function () { |
| | | var table = layui.table; |
| | |
| | | "data": res.data.list // 解析数据列表 |
| | | }; |
| | | }, |
| | | toolbar: '#toolbarDemo', |
| | | defaultToolbar: ['filter', 'exports', { //自定义头部工具栏右侧图标。如无需自定义,去除该参数即可 |
| | | title: '提示' |
| | | ,layEvent: 'LAYTABLE_TIPS' |
| | | ,icon: 'layui-icon-tips' |
| | | }], |
| | | page: true, // 开启分页 |
| | | cols: [ |
| | | [ |
| | | {field: 'id', title: 'ID', width: 100, fixed: 'left'}, |
| | | {type:'checkbox',fixed: 'left'}, |
| | | {field: 'id', title: 'ID', width: 100}, |
| | | {field: 'uid', title: '用户ID', width: 150}, |
| | | {field: 'exchangeType', title: '兑换类型', width: 150}, |
| | | {field: 'exchangeValue', title: '兑换数值', width: 150}, |
| | | {field: 'exchangeValue', title: '兑换金额(元)', width: 150}, |
| | | {field: 'consumedCredits', title: '消耗积分', width: 150}, |
| | | {field: 'creditBalance', title: '积分余额', width: 150}, |
| | | {field: 'status', title: '状态', width: 150, templet: function (d) { |
| | |
| | | } |
| | | return "未知"; |
| | | }}, |
| | | {field: 'createTime', title: '创建时间', width: 180} |
| | | {field: 'createTime', title: '创建时间', width: 180}, |
| | | {field: 'updateTime', title: '更新时间', width: 180} |
| | | ] |
| | | ] |
| | | }; |
| | |
| | | let ids = checkStatus.data.map(item => item.id); |
| | | if (ids.length === 0) { |
| | | layer.msg("请至少选择一条记录"); |
| | | return; |
| | | return true; |
| | | } |
| | | $.post('/admin/api/credit/exchange-record/approve', {ids: ids}, function (response) { |
| | | $.post('/admin/api/credit/exchange-record/approve', {ids: JSON.stringify(ids)}, function (response) { |
| | | if (response.code === 0) { |
| | | layer.msg(response.msg); |
| | | tableIns.reload(); |
| | |
| | | layer.msg("请至少选择一条记录"); |
| | | return; |
| | | } |
| | | $.post('/admin/api/credit/exchange-record/reject', {ids: ids}, function (response) { |
| | | $.post('/admin/api/credit/exchange-record/reject', {ids: JSON.stringify(ids)}, function (response) { |
| | | if (response.code === 0) { |
| | | layer.msg(response.msg); |
| | | tableIns.reload(); |
| | |
| | | |
| | | }, |
| | | { |
| | | field: 'credit', |
| | | title: '积分余额', |
| | | sort: false |
| | | |
| | | }, |
| | | { |
| | | field: '', |
| | | title: '头像', |
| | | sort: false, |