master
wangning 7 years ago
parent db26a8bc29
commit d2ed6455d1

@ -301,7 +301,6 @@ public class RetailAppController {
} }
@RequestMapping(value = "/bills",method = RequestMethod.PUT) @RequestMapping(value = "/bills",method = RequestMethod.PUT)
public JSONObject addBill(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device,@RequestBody NewBillBean newBillBean){ public JSONObject addBill(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device,@RequestBody NewBillBean newBillBean){
device.put("client_id",9);
JSONObject result = billService.save(device.getIntValue("client_id"),newBillBean); JSONObject result = billService.save(device.getIntValue("client_id"),newBillBean);
result.remove("bill"); result.remove("bill");
return result; return result;
@ -311,7 +310,9 @@ public class RetailAppController {
billService.updateBillStatus(bill_id,"2",device.getIntValue("client_id")); billService.updateBillStatus(bill_id,"2",device.getIntValue("client_id"));
} }
@RequestMapping(value = "/bills/orders/{bill_id}",method = RequestMethod.GET) @RequestMapping(value = "/bills/orders/{bill_id}",method = RequestMethod.GET)
public List<JSONObject> getBillOrders(@PathVariable("bill_id")String bill_id, QueryBillOrderBean queryBillOrderBean,@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device){ public JSONObject getBillOrders(@PathVariable("bill_id")String bill_id, QueryBillOrderBean queryBillOrderBean,@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device){
return billOrderService.query(bill_id,device.getIntValue("client_id"),queryBillOrderBean); JSONObject result =billOrderService.query(bill_id,device.getIntValue("client_id"),queryBillOrderBean);
result.put("analysis",billOrderService.analysis(bill_id,device.getIntValue("client_id"),queryBillOrderBean));
return result;
} }
} }

@ -13,5 +13,7 @@ public interface BillOrderService {
List<JSONObject> getByBillId(String bill_id, int client_id); List<JSONObject> getByBillId(String bill_id, int client_id);
List<JSONObject> query(String bill_id,int client_id, QueryBillOrderBean queryBillOrderBean); JSONObject query(String bill_id,int client_id, QueryBillOrderBean queryBillOrderBean);
JSONObject analysis(String bill_id,int client_id, QueryBillOrderBean queryBillOrderBean);
} }

@ -4,10 +4,11 @@ import java.util.List;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import au.com.royalpay.payment.manage.bill.bean.QueryBillOrderBean; import au.com.royalpay.payment.manage.bill.bean.QueryBillOrderBean;
import au.com.royalpay.payment.manage.bill.core.BillOrderService; import au.com.royalpay.payment.manage.bill.core.BillOrderService;
@ -15,6 +16,7 @@ import au.com.royalpay.payment.manage.mappers.bill.BillMapper;
import au.com.royalpay.payment.manage.mappers.bill.BillOrderMapper; import au.com.royalpay.payment.manage.mappers.bill.BillOrderMapper;
import au.com.royalpay.payment.manage.mappers.system.CustomerRelationAlipayMapper; import au.com.royalpay.payment.manage.mappers.system.CustomerRelationAlipayMapper;
import au.com.royalpay.payment.tools.exceptions.BadRequestException; import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.utils.PageListUtils;
/** /**
* Created by wangning on 11/02/2018. * Created by wangning on 11/02/2018.
@ -27,30 +29,53 @@ public class BillOrderServiceImpl implements BillOrderService {
private BillMapper billMapper; private BillMapper billMapper;
@Resource @Resource
private CustomerRelationAlipayMapper customerRelationAlipayMapper; private CustomerRelationAlipayMapper customerRelationAlipayMapper;
@Override @Override
public List<JSONObject> getByBillId(String bill_id, int client_id) { public List<JSONObject> getByBillId(String bill_id, int client_id) {
JSONObject bill = billMapper.findOne(bill_id); JSONObject bill = billMapper.findOne(bill_id);
if(bill.getIntValue("client_id")!= client_id){ if (bill.getIntValue("client_id") != client_id) {
throw new BadRequestException("You have no right to check this bill"); throw new BadRequestException("You have no right to check this bill");
} }
List<JSONObject> wechatBillOrders = billOrderMapper.findByBillIdWithWechatInfo(bill_id); List<JSONObject> wechatBillOrders = billOrderMapper.findByBillIdWithWechatInfo(bill_id);
for (JSONObject order : wechatBillOrders) { for (JSONObject order : wechatBillOrders) {
if("Alipay".equals(order.getString("channel"))){ if ("Alipay".equals(order.getString("channel"))) {
JSONObject alipayInfo = customerRelationAlipayMapper.findCustomerByUserId(order.getString("customer_id")); JSONObject alipayInfo = customerRelationAlipayMapper.findCustomerByUserId(order.getString("customer_id"));
order.put("nickname",alipayInfo.getString("nickname")); if (alipayInfo != null) {
order.put("headimg",alipayInfo.getString("headimg")); order.put("nickname", alipayInfo.getString("nickname"));
order.put("headimg", alipayInfo.getString("headimg"));
}
} }
} }
return wechatBillOrders; return wechatBillOrders;
} }
@Override @Override
public List<JSONObject> query(String bill_id,int client_id, QueryBillOrderBean queryBillOrderBean) { public JSONObject query(String bill_id, int client_id, QueryBillOrderBean queryBillOrderBean) {
JSONObject bill = billMapper.findOne(bill_id);
if (bill.getIntValue("client_id") != client_id) {
throw new BadRequestException("You have no right to check this bill");
}
PageList<JSONObject> list = billOrderMapper.queryWithWechatInfo(bill_id, queryBillOrderBean.toParams(),
new PageBounds(queryBillOrderBean.getPage(), queryBillOrderBean.getLimit()));
for (JSONObject jsonObject : list) {
if ("Alipay".equals(jsonObject.getString("channel"))) {
JSONObject alipayInfo = customerRelationAlipayMapper.findCustomerByUserId(jsonObject.getString("customer_id"));
if (alipayInfo != null) {
jsonObject.put("nickname", alipayInfo.getString("nickname"));
jsonObject.put("headimg", alipayInfo.getString("headimg"));
}
}
}
return PageListUtils.buildPageListResult(list);
}
@Override
public JSONObject analysis(String bill_id, int client_id, QueryBillOrderBean queryBillOrderBean) {
JSONObject bill = billMapper.findOne(bill_id); JSONObject bill = billMapper.findOne(bill_id);
if(bill.getIntValue("client_id")!= client_id){ if (bill.getIntValue("client_id") != client_id) {
throw new BadRequestException("You have no right to check this bill"); throw new BadRequestException("You have no right to check this bill");
} }
return billOrderMapper.query(bill_id,queryBillOrderBean.toParams()); return billOrderMapper.analysis(bill_id, queryBillOrderBean.toParams());
} }
} }

@ -1,5 +1,6 @@
package au.com.royalpay.payment.manage.bill.core.impl; package au.com.royalpay.payment.manage.bill.core.impl;
import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -16,9 +17,9 @@ import au.com.royalpay.payment.manage.bill.bean.QueryBillBean;
import au.com.royalpay.payment.manage.bill.core.BillService; import au.com.royalpay.payment.manage.bill.core.BillService;
import au.com.royalpay.payment.manage.mappers.bill.BillMapper; import au.com.royalpay.payment.manage.mappers.bill.BillMapper;
import au.com.royalpay.payment.manage.merchants.core.ClientManager; import au.com.royalpay.payment.manage.merchants.core.ClientManager;
import au.com.royalpay.payment.tools.CommonConsts;
import au.com.royalpay.payment.tools.env.PlatformEnvironment; import au.com.royalpay.payment.tools.env.PlatformEnvironment;
import au.com.royalpay.payment.tools.exceptions.BadRequestException; import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.exceptions.NotFoundException;
import au.com.royalpay.payment.tools.exceptions.ServerErrorException; import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
import au.com.royalpay.payment.tools.utils.PageListUtils; import au.com.royalpay.payment.tools.utils.PageListUtils;
@ -41,7 +42,7 @@ public class BillServiceImpl implements BillService {
Date now = new Date(); Date now = new Date();
JSONObject record = new JSONObject(); JSONObject record = new JSONObject();
record.put("client_id", client_id); record.put("client_id", client_id);
record.put("price", newBillBean.getAmount()); record.put("price", newBillBean.getAmount().divide(CommonConsts.HUNDRED,2, BigDecimal.ROUND_DOWN));
record.put("currency", newBillBean.getCurrency()); record.put("currency", newBillBean.getCurrency());
record.put("remark", newBillBean.getRemark()); record.put("remark", newBillBean.getRemark());
record.put("create_time", now); record.put("create_time", now);

@ -5,6 +5,8 @@ import java.util.List;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import com.alibaba.fastjson.JSONObject; 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.AutoMapper;
import cn.yixblog.support.mybatis.autosql.annotations.AutoSql; import cn.yixblog.support.mybatis.autosql.annotations.AutoSql;
@ -31,5 +33,9 @@ public interface BillOrderMapper {
@AutoSql(type = SqlType.SELECT) @AutoSql(type = SqlType.SELECT)
List<JSONObject> findByBillId(@Param("bill_id") String bill_id); List<JSONObject> findByBillId(@Param("bill_id") String bill_id);
List<JSONObject> query(@Param("bill_id") String bill_id, @Param("param") JSONObject jsonObject); PageList<JSONObject> query(@Param("bill_id") String bill_id, @Param("param") JSONObject jsonObject, PageBounds pageBounds);
PageList<JSONObject> queryWithWechatInfo(@Param("bill_id") String bill_id, @Param("param") JSONObject jsonObject, PageBounds pageBounds);
JSONObject analysis(@Param("bill_id")String bill_id,@Param("param")JSONObject jsonObject);
} }

@ -3,9 +3,10 @@
<mapper namespace="au.com.royalpay.payment.manage.mappers.bill.BillMapper"> <mapper namespace="au.com.royalpay.payment.manage.mappers.bill.BillMapper">
<select id="listWithOrderAnalysis" resultType="com.alibaba.fastjson.JSONObject" > <select id="listWithOrderAnalysis" resultType="com.alibaba.fastjson.JSONObject" >
select b.bill_id,b.status,b.currency,DATE_FORMAT(b.create_time,'%Y-%c-%e') create_date, DATE_FORMAT(b.create_time,'%H:%m:%s') create_time,b.remark,b.price,count(o.bill_order_id) order_counts,sum(o.order_total_amount) order_total_amount from pmt_bill b left join pmt_bill_order o on b.bill_id = o.bill_id select b.bill_id,b.status,b.currency,DATE_FORMAT(b.create_time,'%Y-%c-%e') create_date, DATE_FORMAT(b.create_time,'%H:%m:%s') create_time,b.remark,b.price,count(o.bill_order_id) order_counts,sum(o.order_total_amount) order_total_amount
from pmt_bill b left join pmt_bill_order o
on b.bill_id = o.bill_id and o.order_status &lt; 2
<where> <where>
b.client_id = #{param.client_id} b.client_id = #{param.client_id}
<if test="param.status != null"> <if test="param.status != null">
and o.order_status = #{param.status} and o.order_status = #{param.status}

@ -19,5 +19,24 @@
<if test="param.status != null"> <if test="param.status != null">
and order_status = #{param.status} and order_status = #{param.status}
</if> </if>
order by create_time
</select>
<select id="queryWithWechatInfo" resultType="com.alibaba.fastjson.JSONObject">
select o.*,r.nickname,r.headimg from pmt_bill_order o left join sys_customer_relation r on r.wechat_openid = o.customer_id
where
bill_id = #{bill_id}
<if test="param.status != null">
and order_status = #{param.status}
</if>
order by create_time
</select>
<select id="analysis" resultType="com.alibaba.fastjson.JSONObject">
select count(1) counts from pmt_bill_order
where
bill_id = #{bill_id}
<if test="param.status != null">
and order_status = #{param.status}
</if>
</select> </select>
</mapper> </mapper>
Loading…
Cancel
Save