From 1b48cd65f365671a2947df8596fb93d1bd242b99 Mon Sep 17 00:00:00 2001 From: wangning <164851225@qq.com> Date: Thu, 28 Dec 2017 18:39:17 +0800 Subject: [PATCH] Customer impression --- src/db/modify.sql | 2 + .../apps/bean/CustomerImpressionQuery.java | 100 +++++++++++++++ .../manage/apps/core/CustomerImpression.java | 17 +++ .../core/impls/CustomerImpressionImpl.java | 118 ++++++++++++++++++ .../web/CustomerImpressionController.java | 36 ++++++ .../mappers/client/ClientCustomersMapper.java | 13 +- .../manage/mappers/payment/OrderMapper.java | 2 + .../core/impls/TradeLogServiceImpl.java | 2 + .../mappers/client/ClientCustomersMapper.xml | 28 +++++ .../manage/mappers/payment/OrderMapper.xml | 22 ++++ 10 files changed, 338 insertions(+), 2 deletions(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/apps/bean/CustomerImpressionQuery.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/apps/core/CustomerImpression.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImpl.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/apps/web/CustomerImpressionController.java create mode 100644 src/main/resources/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.xml diff --git a/src/db/modify.sql b/src/db/modify.sql index 7328ed984..b5755e9b4 100644 --- a/src/db/modify.sql +++ b/src/db/modify.sql @@ -108,6 +108,8 @@ ALTER TABLE `sys_accounts` ALTER TABLE `sys_clients_audit_process` MODIFY COLUMN `operator_id` varchar(50) NOT NULL ; +ALTER TABLE `pmt_refunds` + MODIFY COLUMN `operator_id` varchar(50) DEFAULT NULL COMMENT '退款操作者账号'; diff --git a/src/main/java/au/com/royalpay/payment/manage/apps/bean/CustomerImpressionQuery.java b/src/main/java/au/com/royalpay/payment/manage/apps/bean/CustomerImpressionQuery.java new file mode 100644 index 000000000..a177232b0 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/apps/bean/CustomerImpressionQuery.java @@ -0,0 +1,100 @@ +package au.com.royalpay.payment.manage.apps.bean; + +import com.alibaba.fastjson.JSONObject; + +import java.math.BigDecimal; + +/** + * Created by wangning on 2017/12/28. + */ +public class CustomerImpressionQuery { + private int payment_times; + private BigDecimal amount_begin; + private BigDecimal amount_end; + private String order; + private int client_id; + private int page = 1; + private int limit = 10; + + public JSONObject toParam(){ + JSONObject param = new JSONObject(); + param.put("payment_times",this.payment_times); + param.put("amount_begin",this.amount_begin); + param.put("amount_end",this.amount_end); + param.put("order",this.order); + param.put("client_id",this.client_id); + return param; + } + public int getPayment_times() { + return payment_times; + } + + public void setPayment_times(int payment_times) { + this.payment_times = payment_times; + } + + public BigDecimal getamount_begin() { + return amount_begin; + } + + public void setamount_begin(BigDecimal amount_begin) { + this.amount_begin = amount_begin; + } + + public BigDecimal getamount_end() { + return amount_end; + } + + public void setamount_end(BigDecimal amount_end) { + this.amount_end = amount_end; + } + + public String getOrder() { + return order; + } + + public void setOrder(String order) { + this.order = order; + } + + public BigDecimal getAmount_begin() { + return amount_begin; + } + + public void setAmount_begin(BigDecimal amount_begin) { + this.amount_begin = amount_begin; + } + + public BigDecimal getAmount_end() { + return amount_end; + } + + public void setAmount_end(BigDecimal amount_end) { + this.amount_end = amount_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; + } + + public int getClient_id() { + return client_id; + } + + public void setClient_id(int client_id) { + this.client_id = client_id; + } +} + diff --git a/src/main/java/au/com/royalpay/payment/manage/apps/core/CustomerImpression.java b/src/main/java/au/com/royalpay/payment/manage/apps/core/CustomerImpression.java new file mode 100644 index 000000000..5ec9f7006 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/apps/core/CustomerImpression.java @@ -0,0 +1,17 @@ +package au.com.royalpay.payment.manage.apps.core; + +import au.com.royalpay.payment.manage.apps.bean.CustomerImpressionQuery; + +import com.alibaba.fastjson.JSONObject; + +/** + * Created by wangning on 2017/12/28. + */ +public interface CustomerImpression { + + JSONObject listPageble(CustomerImpressionQuery customerImpressionQuery); + + JSONObject findOne(int client_id,String customer_id); + + void generate(int client_id); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImpl.java b/src/main/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImpl.java new file mode 100644 index 000000000..7067edb79 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImpl.java @@ -0,0 +1,118 @@ +package au.com.royalpay.payment.manage.apps.core.impls; + +import java.util.Date; +import java.util.List; + +import javax.annotation.Resource; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.time.DateFormatUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; + +import com.alibaba.fastjson.JSONObject; +import com.github.miemiedev.mybatis.paginator.domain.Order; +import com.github.miemiedev.mybatis.paginator.domain.PageBounds; +import com.github.miemiedev.mybatis.paginator.domain.PageList; +import com.maxmind.geoip.LookupService; + +import au.com.royalpay.payment.manage.apps.bean.CustomerImpressionQuery; +import au.com.royalpay.payment.manage.apps.core.CustomerImpression; +import au.com.royalpay.payment.manage.mappers.client.ClientCustomersMapper; +import au.com.royalpay.payment.manage.mappers.payment.OrderMapper; +import au.com.royalpay.payment.tools.exceptions.BadRequestException; +import au.com.royalpay.payment.tools.utils.PageListUtils; + +/** + * Created by wangning on 2017/12/28. + */ +@Service +public class CustomerImpressionImpl implements CustomerImpression { + @Resource + private ClientCustomersMapper clientCustomersMapper; + @Resource + private OrderMapper orderMapper; + @Resource + private LookupService lookupService; + + @Override + public JSONObject listPageble(CustomerImpressionQuery customerImpressionQuery) { + PageList logs = clientCustomersMapper.listCustomerInfo(customerImpressionQuery.toParam(), + new PageBounds(customerImpressionQuery.getPage(), customerImpressionQuery.getLimit(), Order.formString(customerImpressionQuery.getOrder()))); + return PageListUtils.buildPageListResult(logs); + } + + @Override + public JSONObject findOne(int client_id, String customer_id) { + JSONObject customer = clientCustomersMapper.getClientCustomerWithNull(client_id, customer_id); + if(customer==null){ + throw new BadRequestException("customer info not exist"); + } + JSONObject params = new JSONObject(); + params.put("customer_id", customer_id); + PageList ordersLast = orderMapper.listOrderByCustomer(params, new PageBounds(1, 1, Order.formString("create_time.desc"))); + if (!CollectionUtils.isEmpty(ordersLast)) { + JSONObject order = ordersLast.get(0); + customer.put("last_pay_time", DateFormatUtils.format(order.getDate("create_time"), "yyyy-MM-dd HH:mm:ss")); + customer.put("last_pay_location", lookupService.getLocation(order.getString("customer_ip")).city); + } + PageList ordersFirst = orderMapper.listOrderByCustomer(params, new PageBounds(1, 1, Order.formString("create_time.asc"))); + if (!CollectionUtils.isEmpty(ordersFirst)) { + JSONObject order = ordersFirst.get(0); + customer.put("first_pay_time", DateFormatUtils.format(order.getDate("create_time"), "yyyy-MM-dd HH:mm:ss")); + customer.put("first_pay_location", lookupService.getLocation(order.getString("customer_ip")).city); + + } + return customer; + } + + @Override + @Transactional + public void generate(int client_id) { + JSONObject params = new JSONObject(); + params.put("client_id", client_id); + PageList lastRecord = clientCustomersMapper.listCustomerInfo(params, new PageBounds(1, 1, Order.formString("create_time.desc"))); + if (!CollectionUtils.isEmpty(lastRecord)) { + params.put("confirm_time", lastRecord.get(0).getDate("creata_time")); + } + List orders = orderMapper.listAnalysisClientCustomer(params); + Date now = new Date(); + for (JSONObject order : orders) { + if(StringUtils.isEmpty(order.getString("channel"))){ + continue; + } + JSONObject clientCustomerInfo = clientCustomersMapper.getClientCustomerWithNull(client_id, order.getString("customer_id")); + if (clientCustomerInfo == null) { + JSONObject client_customer = new JSONObject(); + client_customer.put("client_id", order.getIntValue("client_id")); + client_customer.put("customer_id", order.getString("customer_id")); + client_customer.put("channel", order.getString("channel")); + if (order.getString("alipay_headimg") == null) { + client_customer.put("headimg", order.getString("wechat_headimg")); + client_customer.put("nick_name", order.getString("wechat_nickname")); + } else { + client_customer.put("headimg", order.getString("alipay_headimg")); + client_customer.put("nick_name", order.getString("alipay_nickname")); + } + client_customer.put("payment_times", order.getIntValue("payment_times")); + client_customer.put("total_amount", order.getBigDecimal("total_amount")); + client_customer.put("create_time", now); + clientCustomersMapper.insert(client_customer); + } else { + clientCustomerInfo.put("payment_times", clientCustomerInfo.getIntValue("payment_times") + order.getIntValue("payment_times")); + clientCustomerInfo.put("total_amount", clientCustomerInfo.getBigDecimal("total_amount").add(order.getBigDecimal("total_amount"))); + if (order.getString("alipay_headimg") == null) { + clientCustomerInfo.put("headimg", order.getString("wechat_headimg")); + clientCustomerInfo.put("nick_name", order.getString("wechat_nickname")); + } else { + clientCustomerInfo.put("headimg", order.getString("alipay_headimg")); + clientCustomerInfo.put("nick_name", order.getString("alipay_nickname")); + } + clientCustomerInfo.put("channel", order.getString("channel")); + clientCustomersMapper.update(clientCustomerInfo); + } + } + } + +} \ No newline at end of file diff --git a/src/main/java/au/com/royalpay/payment/manage/apps/web/CustomerImpressionController.java b/src/main/java/au/com/royalpay/payment/manage/apps/web/CustomerImpressionController.java new file mode 100644 index 000000000..1d26c1281 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/apps/web/CustomerImpressionController.java @@ -0,0 +1,36 @@ +package au.com.royalpay.payment.manage.apps.web; + +import au.com.royalpay.payment.manage.apps.bean.CustomerImpressionQuery; +import au.com.royalpay.payment.manage.apps.core.CustomerImpression; + +import com.alibaba.fastjson.JSONObject; + +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +@RestController +@RequestMapping(value = "/customers/impression") +public class CustomerImpressionController { + @Resource + private CustomerImpression customerImpression; + + @RequestMapping(value = "/list", method = RequestMethod.GET) + @ResponseBody + public JSONObject checkPointsAfterPay(CustomerImpressionQuery customerImpressionQuery) { + return customerImpression.listPageble(customerImpressionQuery); + } + + + @RequestMapping(value = "/{client_id}/{customer_id}", method = RequestMethod.GET) + @ResponseBody + public JSONObject checkPointsAfterPay(@PathVariable int client_id,@PathVariable String customer_id) { + customerImpression.generate(9); +// return customerImpression.findOne(client_id,customer_id); + return null; + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.java index 6b3b95ba5..52257fdfe 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.java @@ -1,10 +1,14 @@ package au.com.royalpay.payment.manage.mappers.client; +import org.apache.ibatis.annotations.Param; + +import com.alibaba.fastjson.JSONObject; +import com.github.miemiedev.mybatis.paginator.domain.PageBounds; +import com.github.miemiedev.mybatis.paginator.domain.PageList; + 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 org.apache.ibatis.annotations.Param; /** * Created by yuan on 2017/9/12. @@ -14,9 +18,14 @@ public interface ClientCustomersMapper { @AutoSql(type = SqlType.SELECT) public JSONObject getClientCustomer(@Param("client_id") int client_id, @Param("customer_id") String customer_id); + public JSONObject getClientCustomerWithNull(@Param("client_id") int client_id, @Param("customer_id") String customer_id); + @AutoSql(type = SqlType.INSERT) public void insert(JSONObject obj); @AutoSql(type = SqlType.UPDATE) public void update(JSONObject obj); + + PageList listCustomerInfo(JSONObject params, PageBounds pageBounds); + } diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.java index 5300d7f1f..3c7f8f001 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.java @@ -75,4 +75,6 @@ public interface OrderMapper { List listPaid(JSONObject params, PageBounds pageBounds); List listOrdersByClientsNoPages(JSONObject params); + + List listAnalysisClientCustomer(JSONObject params); } diff --git a/src/main/java/au/com/royalpay/payment/manage/tradelog/core/impls/TradeLogServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/tradelog/core/impls/TradeLogServiceImpl.java index 7de883812..960b56de9 100644 --- a/src/main/java/au/com/royalpay/payment/manage/tradelog/core/impls/TradeLogServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/tradelog/core/impls/TradeLogServiceImpl.java @@ -379,6 +379,8 @@ public class TradeLogServiceImpl implements TradeLogService { obj.put("client_id", orderLog.getInteger("client_id")); obj.put("customer_id", orderLog.getString("customer_id")); obj.put("name_remak", name_remark); + obj.put("channel",order.getString("channel")); + obj.put("create_time",new Date()); JSONObject client_coustom = clientCustomersMapper.getClientCustomer(orderLog.getInteger("client_id"), orderLog.getString("customer_id")); if (null == client_coustom) { clientCustomersMapper.insert(obj); diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.xml new file mode 100644 index 000000000..1de5ec0bb --- /dev/null +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.xml @@ -0,0 +1,28 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.xml index 2bc38a6c6..c6308a28f 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.xml @@ -529,6 +529,28 @@ +