diff --git a/src/main/java/au/com/royalpay/payment/manage/actchairty/beans/ActChairtyBean.java b/src/main/java/au/com/royalpay/payment/manage/actchairty/beans/ActChairtyBean.java new file mode 100644 index 000000000..aac44aefa --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/actchairty/beans/ActChairtyBean.java @@ -0,0 +1,33 @@ +package au.com.royalpay.payment.manage.actchairty.beans; + +import au.com.royalpay.payment.tools.exceptions.BadRequestException; +import com.alibaba.fastjson.annotation.JSONField; +import org.apache.commons.lang3.time.DateUtils; + +import java.math.BigDecimal; +import java.text.ParseException; +import java.util.Date; + +/** + * Created by yangluo on 2018/7/9. + */ +public class ActChairtyBean { + @JSONField(name = "date") + private String date; + + public String getDate() { + return date; + } + + public void setDate(String date) { + this.date = date; + } + + public java.util.Date toDate() { + try { + return DateUtils.parseDate(date, new String[]{"yyyy-MM-dd"}); + } catch (ParseException e) { + throw new BadRequestException("Invalid To Date"); + } + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/actchairty/beans/ActChairtyQuery.java b/src/main/java/au/com/royalpay/payment/manage/actchairty/beans/ActChairtyQuery.java new file mode 100644 index 000000000..ee3f9340b --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/actchairty/beans/ActChairtyQuery.java @@ -0,0 +1,75 @@ +package au.com.royalpay.payment.manage.actchairty.beans; + +import au.com.royalpay.payment.core.exceptions.ParamInvalidException; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.time.DateUtils; + +import java.text.ParseException; +import java.util.Date; + +/** + * redpack query + * Created by davep on 2016-08-03. + */ +public class ActChairtyQuery { + private static final String[] DATE_PATTERNS = {"yyyyMMdd", "yyyy-MM-dd"}; + private String begin; + private String end; + private int page = 1; + private int limit = 20; + + public JSONObject params() { + JSONObject param = new JSONObject(); + if (begin != null) { + try { + Date fromDate = DateUtils.parseDate(begin, DATE_PATTERNS); + param.put("begin", fromDate); + } catch (ParseException e) { + throw new ParamInvalidException("begin", "error.payment.valid.invalid_date_format"); + } + } + if (end != null) { + try { + Date fromDate = DateUtils.addDays(DateUtils.parseDate(end, DATE_PATTERNS), 1); + param.put("end", fromDate); + } catch (ParseException e) { + throw new ParamInvalidException("end", "error.payment.valid.invalid_date_format"); + } + } + param.put("page",page); + param.put("limit",limit); + return param; + } + + public String getBegin() { + return begin; + } + + public void setBegin(String begin) { + this.begin = begin; + } + + public String getEnd() { + return end; + } + + public void setEnd(String end) { + this.end = end; + } + + public int getPage() { + return page; + } + + public void setPage(int page) { + this.page = page; + } + + public int getLimit() { + return limit; + } + + public void setLimit(int limit) { + this.limit = limit; + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/actchairty/core/ActChairtyService.java b/src/main/java/au/com/royalpay/payment/manage/actchairty/core/ActChairtyService.java new file mode 100644 index 000000000..0a868a187 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/actchairty/core/ActChairtyService.java @@ -0,0 +1,29 @@ +package au.com.royalpay.payment.manage.actchairty.core; + + +import au.com.royalpay.payment.manage.actchairty.beans.ActChairtyBean; +import com.alibaba.fastjson.JSONObject; +import com.github.miemiedev.mybatis.paginator.domain.PageList; + +import java.util.List; + +/** + * Created by yangluo on 2018/7/9. + */ + +public interface ActChairtyService { + + void configClient(String clientMoniker, ActChairtyBean config, JSONObject manager); + + JSONObject listChairClients(int page, int limit); + + void disableClient(String clientMoniker); + + List getWeekendAnalysis(JSONObject params); + + PageList getClientRank(JSONObject params); + + + + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/actchairty/core/impls/ActChairtyServiceImp.java b/src/main/java/au/com/royalpay/payment/manage/actchairty/core/impls/ActChairtyServiceImp.java new file mode 100644 index 000000000..ade6ede8b --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/actchairty/core/impls/ActChairtyServiceImp.java @@ -0,0 +1,97 @@ +package au.com.royalpay.payment.manage.actchairty.core.impls; + +import au.com.royalpay.payment.core.exceptions.InvalidShortIdException; +import au.com.royalpay.payment.manage.actchairty.beans.ActChairtyBean; +import au.com.royalpay.payment.manage.actchairty.core.ActChairtyService; +import au.com.royalpay.payment.manage.mappers.act.ActChairtyMapper; +import au.com.royalpay.payment.manage.merchants.core.ClientManager; +import au.com.royalpay.payment.tools.utils.PageListUtils; +import com.alibaba.fastjson.JSONObject; +import com.github.miemiedev.mybatis.paginator.domain.PageBounds; +import com.github.miemiedev.mybatis.paginator.domain.PageList; +import org.apache.commons.lang3.time.DateFormatUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +/** + * Created by yangluo on 2018/7/9. + */ +@Service +public class ActChairtyServiceImp implements ActChairtyService { + + @Resource + private ClientManager clientManager; + @Resource + private ActChairtyMapper actChairtyMapper; + @Override + public void configClient(String clientMoniker, ActChairtyBean config, JSONObject manager) { + JSONObject client = clientManager.getClientInfoByMoniker(clientMoniker); + if (client == null) { + throw new InvalidShortIdException(); + } + JSONObject findChairty = actChairtyMapper.findChairtyClient(clientMoniker); + if (findChairty == null) { + JSONObject chairtyClient = new JSONObject(); + chairtyClient.put("client_id", client.get("client_id")); + chairtyClient.put("client_moniker", clientMoniker); + chairtyClient.put("active_time", config.toDate()); + actChairtyMapper.save(chairtyClient); + } + } + + @Override + public JSONObject listChairClients(int page, int limit) { + PageList clients = actChairtyMapper.chairtyClientNum(new PageBounds(page, limit)); + for (JSONObject client : clients){ + client.put("client_moniker", client.getString("client_moniker")); + client.put("active_time", DateFormatUtils.format(client.getDate("active_time"), "yyyy/MM/dd")); + BigDecimal bg = new BigDecimal(client.getIntValue("count_ordernum") * 0.01); + double f1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + client.put("chairty_num", f1); + } + return PageListUtils.buildPageListResult(clients); + } + + @Override + public void disableClient(String clientMoniker) { + actChairtyMapper.disableClient(clientMoniker); + } + + + @Override + public List getWeekendAnalysis(JSONObject params) { + List result = new ArrayList<>(); + List getWeekstartanalysis = actChairtyMapper.getChairtyWeekstartAnalysis(params.getDate("begin"), params.getDate("end")); + for (JSONObject getWeekendAnalysis : getWeekstartanalysis) { + Calendar rightNow = Calendar.getInstance(); + rightNow.setTime(getWeekendAnalysis.getDate("weekstart")); + rightNow.add(Calendar.DAY_OF_YEAR,7); + Date dt1=rightNow.getTime(); + JSONObject getAnalysis = actChairtyMapper.getChairtyWeekAnalysis(getWeekendAnalysis.getDate("weekstart"), dt1); + getWeekendAnalysis.put("count_ordernum", getAnalysis.getIntValue("count_ordernum")); + getWeekendAnalysis.put("sum_ordernum", getAnalysis.getBigDecimal("sum_ordernum")); + BigDecimal bg = new BigDecimal(getAnalysis.getIntValue("count_ordernum") * 0.01); + double f1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + getWeekendAnalysis.put("chairty_amount", f1); + result.add(getWeekendAnalysis); + } + return result; + } + + @Override + public PageList getClientRank(JSONObject params) { + PageList getChairtyWeekRaking = actChairtyMapper.getChairtyWeekRaking(params.getDate("begin"), params.getDate("end"),new PageBounds(params.getIntValue("page"), params.getIntValue("limit"))); + return getChairtyWeekRaking; + } + + + +} + + diff --git a/src/main/java/au/com/royalpay/payment/manage/actchairty/web/ActChairtyController.java b/src/main/java/au/com/royalpay/payment/manage/actchairty/web/ActChairtyController.java new file mode 100644 index 000000000..d041c5e81 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/actchairty/web/ActChairtyController.java @@ -0,0 +1,62 @@ +package au.com.royalpay.payment.manage.actchairty.web; + +import au.com.royalpay.payment.manage.actchairty.beans.ActChairtyBean; +import au.com.royalpay.payment.manage.actchairty.beans.ActChairtyQuery; +import au.com.royalpay.payment.manage.actchairty.core.ActChairtyService; +import au.com.royalpay.payment.manage.cashback.core.CashbackService; +import au.com.royalpay.payment.manage.management.clearing.core.SettleDelayConfigurer; +import au.com.royalpay.payment.manage.permission.manager.ManagerMapping; +import au.com.royalpay.payment.tools.CommonConsts; +import au.com.royalpay.payment.tools.http.HttpUtils; +import au.com.royalpay.payment.tools.permission.enums.ManagerRole; +import au.com.royalpay.payment.tools.utils.PageListUtils; +import com.alibaba.fastjson.JSONObject; +import com.github.miemiedev.mybatis.paginator.domain.PageList; +import org.springframework.validation.Errors; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.validation.Valid; +import java.util.List; + +/** + * Created by yangluo on 2018/7/9. + */ + +@RequestMapping(value = "/actchairty") +@RestController +public class ActChairtyController { + @Resource + private ActChairtyService actChairtyService; + + @ManagerMapping(value = "/clients", method = RequestMethod.GET, role = { ManagerRole.ADMIN }) + public JSONObject listAttendingClients(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int limit) { + // todo params + return actChairtyService.listChairClients(page, limit); + } + + @ManagerMapping(value = "/clients/{clientMoniker}", method = RequestMethod.PUT, role = { ManagerRole.ADMIN }) + public void configClient(@PathVariable String clientMoniker, @RequestBody @Valid ActChairtyBean config, Errors errors, + @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { + HttpUtils.handleValidErrors(errors); + actChairtyService.configClient(clientMoniker, config, manager); + } + + @ManagerMapping(value = "/clients/{clientMoniker}", method = RequestMethod.DELETE, role = { ManagerRole.ADMIN }) + public void disableClient(@PathVariable String clientMoniker) { + actChairtyService.disableClient(clientMoniker); + } + + @ManagerMapping(value = "/traAnalysis", method = RequestMethod.GET, role = { ManagerRole.ADMIN }) + public List traAnalysis(ActChairtyQuery params) { + return actChairtyService.getWeekendAnalysis(params.params()); + } + @ManagerMapping(value = "/ranking", method = RequestMethod.GET, role = { ManagerRole.ADMIN }) + public JSONObject getRanking(ActChairtyQuery params) { + PageList clientRank = actChairtyService.getClientRank(params.params()); + if(clientRank==null){ + return null; + } + return PageListUtils.buildPageListResult(clientRank); + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/act/ActChairtyMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/act/ActChairtyMapper.java new file mode 100644 index 000000000..1515f7fde --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/act/ActChairtyMapper.java @@ -0,0 +1,38 @@ +package au.com.royalpay.payment.manage.mappers.act; + +import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper; +import cn.yixblog.support.mybatis.autosql.annotations.AutoSql; +import cn.yixblog.support.mybatis.autosql.annotations.SqlType; +import com.alibaba.fastjson.JSONObject; +import com.github.miemiedev.mybatis.paginator.domain.PageBounds; +import com.github.miemiedev.mybatis.paginator.domain.PageList; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; +import java.util.List; + +/** + * Created by yangluo on 2018/7/9. + */ +@AutoMapper(tablename = "act_charity", pkName = "client_moniker") +public interface ActChairtyMapper { + + @AutoSql(type = SqlType.SELECT) + JSONObject findChairtyClient(@Param("client_moniker") String clientMoniker); + + @AutoSql(type = SqlType.INSERT) + void save(JSONObject chairtyClient); + + @AutoSql(type = SqlType.DELETE) + void disableClient(@Param("client_moniker") String clientMoniker); + + PageList chairtyClientNum(PageBounds pageBounds); + + List getChairtyWeekstartAnalysis(@Param("begin") Date begin, @Param("end") Date end); + + JSONObject getChairtyWeekAnalysis(@Param("begin") Date begin, @Param("end") Date end); + + PageList getChairtyWeekRaking(@Param("begin") Date begin, @Param("end") Date end,PageBounds pageBounds); + + +} diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/act/ActChairtyMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/act/ActChairtyMapper.xml new file mode 100644 index 000000000..63a760c86 --- /dev/null +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/act/ActChairtyMapper.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/ui/manage.html b/src/main/ui/manage.html index 5c2f09795..a5e3f5bdb 100644 --- a/src/main/ui/manage.html +++ b/src/main/ui/manage.html @@ -347,6 +347,14 @@ margin-bottom: 10%;"/> 合同签约情况 + +
  • + + 半边天公益活动 + +
  • diff --git a/src/main/ui/static/actchairty/act_chairty.js b/src/main/ui/static/actchairty/act_chairty.js new file mode 100644 index 000000000..19c011b62 --- /dev/null +++ b/src/main/ui/static/actchairty/act_chairty.js @@ -0,0 +1,216 @@ +define(['angular', 'uiBootstrap', 'uiRouter', 'angularEcharts'], function (angular) { + 'use strict'; + var colors = ['#00c0ef', '#00a65a', '#ff851b']; + var app = angular.module('actChairty', ['ui.bootstrap', 'ui.router', 'ngEcharts']); + var total; + + app.config(['$stateProvider', function ($stateProvider) { + $stateProvider.state('act_chairty', { + url: '/act_chairty', + templateUrl: '/static/actchairty/templates/act_chairty_merchants.html', + controller: 'actChairtyConfDialogCtrl' + }).state('act_chairty.analysis',{ + url:'/act_chairty/analysis', + templateUrl: '/static/actchairty/templates/act_chairty_analysis.html', + controller: 'actChairtyAnalysisConfDialogCtrl' + }) + }]); + app.controller('actChairtyConfDialogCtrl', ['$scope', '$http', '$filter', function ($scope, $http, $filter) { + $scope.pagination = {}; + $scope.today = new Date(); + $scope.loadClients = function (page) { + var params = {page: page || $scope.pagination.page || 1}; + $http.get('/actchairty/clients', {params: params}).then(function (resp) { + $scope.clients = resp.data.data; + $scope.pagination = resp.data.pagination; + }) + }; + $scope.loadClients(); + $scope.new_conf = {}; + $scope.ctrl = {dateInput: false}; + $scope.disableClient = function (client) { + $http.delete('/actchairty/clients/' + client.client_moniker).then(function () { + $scope.loadClients(); + }); + }; + $scope.submitClient = function () { + $scope.errmsg = null; + var conf = { + date: $filter('date')($scope.new_conf.date, 'yyyy-MM-dd'), + }; + $http.put('/actchairty/clients/' + $scope.new_conf.client_moniker, conf).then(function () { + $scope.new_conf = {}; + $scope.loadClients(); + }, function (resp) { + $scope.errmsg = resp.data.message; + }); + }; + }]); + + app.controller('actChairtyAnalysisConfDialogCtrl', ['$scope', '$http', '$filter', function ($scope, $http, $filter) { + $scope.params = {}; + $scope.today = new Date(); + $scope.params.end = new Date(); + var date = new Date(); + date.setDate(date.getDate()-30); + $scope.params.begin = date; + $scope.thisMonth = function () { + $scope.params.end = new Date(); + var monthBegin = new Date(); + monthBegin.setDate(1); + $scope.params.begin = monthBegin; + $scope.doAnalysis(1); + }; + $scope.lastMonth = function () { + var monthFinish = new Date(); + monthFinish.setDate(0); + $scope.params.end = monthFinish; + var monthBegin = new Date(); + monthBegin.setDate(0); + monthBegin.setDate(1); + $scope.params.begin = monthBegin; + $scope.doAnalysis(1); + }; + + $scope.doPartnerTotalRanking = function (page) { + var params = {}; + params.page = page||$scope.total_ranking_pagination.page || 1; + params.limit = 10; + + $http.get('/actchairty/clients', {params: params}).then(function (resp) { + $scope.chairtyPartnersRanking = resp.data.data; + $scope.total_ranking_pagination = resp.data.pagination; + var amount = 0; + var chairty = 0; + angular.forEach(resp.data.data, function (data) { + amount += parseFloat(data.sum_ordernum); + chairty += parseFloat(data.chairty_num) + return amount,chairty; + }); + $scope.totalAmount = amount; + $scope.totalChairty = Math.round(chairty*100)/100; ; + }) + }; + + + + $scope.getTotalCashBack = function () { + + + + }; + + + $scope.getClientsCashbackRankingByDate = function (date,page) { + $scope.event_date = date; + var params = {}; + params.begin = date; + var event_date_format=date.replace(/^(\d{4})(\d{2})(\d{2})$/, "$1-$2-$3") + var endDate = new Date(event_date_format); + endDate.setDate(endDate.getDate()+6); + params.end =$filter('date')(endDate,'yyyyMMdd'); + params.page = page||$scope.day_ranking_pagination.page || 1; + params.limit = 10; + if ($scope.params.cashback_type){ + params.cashback_type = angular.copy($scope.params.cashback_type); + } + $http.get('/actchairty/ranking', {params: params}).then(function (resp) { + $scope.cashbackPartnersRankingByDate = resp.data.data; + if(resp.data.data != null){ + + } + $scope.day_ranking_pagination = resp.data.pagination; + }); + }; + $scope.doAnalysis = function () { + var params = angular.copy($scope.params); + if (params.begin) { + params.begin = $filter('date')(params.begin, 'yyyyMMdd'); + } else { + params.begin = $filter('date')(new Date(), 'yyyyMMdd'); + } + if (params.end) { + params.end = $filter('date')(params.end, 'yyyyMMdd'); + } else { + params.end = $filter('date')(new Date(), 'yyyyMMdd'); + } + $http.get('/actchairty/traAnalysis', {params: params}).then(function (resp) { + $scope.cashbackDaily = angular.copy(resp.data); + var dates = []; + var count_ordernum = []; + var sum_ordernum = []; + var chairty_amount = []; + resp.data.forEach(function (e) { + dates.push(e.weekstart); + chairty_amount.push(e.chairty_amount); + count_ordernum.push(e.count_ordernum); + sum_ordernum.push(e.sum_ordernum); + }); + var cashbackHistoryConfig = function (dates,sum_ordernum, count_ordernum, chairty_amount) { + return { + color: colors, + tooltip: { + trigger: 'axis', + axisPointer: { // 坐标轴指示器,坐标轴触发有效 + type: 'shadow' // 默认为直线,可选为:'line' | 'shadow' + } + }, + legend: { + data: ['周一交易额', '交易量','公益额'] + }, + grid: { + left: '3%', + right: '4%', + bottom: '3%', + containLabel: true + }, + xAxis: [ + { + type: 'category', + data: dates + } + ], + yAxis: [ + { + type: 'value', + name: 'Amount(AUD)' + } + ], + series: [{ + name: '周一交易额', + type: 'bar', + data: sum_ordernum + }, { + name: '交易量', + type: 'bar', + data: count_ordernum + }, { + name: '公益额', + type: 'bar', + data: chairty_amount + } + ] + }; + }; + $scope.settleDelayHistory = cashbackHistoryConfig(dates,sum_ordernum, count_ordernum, chairty_amount); + }); + $scope.doPartnerTotalRanking(1); + }; + $scope.doAnalysis(1); + $scope.getTotalCashBack(1); + $scope.settleDelayEchart = function (chart) { + chart.on('click', function (params) { + $scope.cashBack_total_daily = $scope.cashbackDaily[params.dataIndex].chairty_amount; + var event_date = $scope.cashbackDaily[params.dataIndex].weekstart; + + if (event_date) { + event_date+=""; + var event_date_format=event_date.replace(/^(\d{4})(\d{2})(\d{2})$/, "$1-$2-$3") + var date = new Date(event_date_format); + $scope.getClientsCashbackRankingByDate($filter('date')(date,'yyyyMMdd'),1); + } + }) + }; + }]); + return app; +}); \ No newline at end of file diff --git a/src/main/ui/static/actchairty/templates/act_chairty_analysis.html b/src/main/ui/static/actchairty/templates/act_chairty_analysis.html new file mode 100644 index 000000000..710d34f72 --- /dev/null +++ b/src/main/ui/static/actchairty/templates/act_chairty_analysis.html @@ -0,0 +1,138 @@ +
    +
    +
    +
    +
    +
    + +
    +
    +
    + +
    + ~ +
    + +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    +

    Settle Delay Ranking

    +
    +
    +
    +
    +

    到目前为止交易总金额排名(总额:{{totalAmount}}) + (总公益额:{{totalChairty}}) +

    +
    + + + + + + + + + + + + + + + + + + + +
    Partner NameAmount订单量捐款额
    +
    + +
    +
    Total Records:{{total_ranking_pagination.totalCount}};Total Pages:{{total_ranking_pagination.totalPages}}
    +
    +
    +
    +

    {{event_date}} 商户半边天公益活动总排名 (选择上图相应的日期获取当日排名)当日总额:{{cashBack_total_daily}}

    +
    + + + + + + + + + + + + + + + +
    Partner NameAmount捐款额
    +
    + +
    +
    Total Records:{{day_ranking_pagination.totalCount}};Total Pages:{{day_ranking_pagination.totalPages}}
    +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/src/main/ui/static/actchairty/templates/act_chairty_merchants.html b/src/main/ui/static/actchairty/templates/act_chairty_merchants.html new file mode 100644 index 000000000..b66d46696 --- /dev/null +++ b/src/main/ui/static/actchairty/templates/act_chairty_merchants.html @@ -0,0 +1,93 @@ +
    +

    半边天公益活动

    + +
    +
    +
    +
    + +
    +
    +
    + + + + + +