master
wangning 7 years ago
parent bf69dfbfe5
commit db26a8bc29

@ -300,8 +300,11 @@ public class RetailAppController {
return billService.queryBills(device.getIntValue("client_id"),queryBillBean); return billService.queryBills(device.getIntValue("client_id"),queryBillBean);
} }
@RequestMapping(value = "/bills",method = RequestMethod.PUT) @RequestMapping(value = "/bills",method = RequestMethod.PUT)
public void addBill(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device,@RequestBody NewBillBean newBillBean){ public JSONObject addBill(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device,@RequestBody NewBillBean newBillBean){
billService.save(device.getIntValue("client_id"),newBillBean); device.put("client_id",9);
JSONObject result = billService.save(device.getIntValue("client_id"),newBillBean);
result.remove("bill");
return result;
} }
@RequestMapping(value = "/bills/{bill_id}/close",method = RequestMethod.POST) @RequestMapping(value = "/bills/{bill_id}/close",method = RequestMethod.POST)
public void closeBill(@PathVariable("bill_id")String bill_id,@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device){ public void closeBill(@PathVariable("bill_id")String bill_id,@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device){

@ -7,21 +7,20 @@ import java.math.BigDecimal;
*/ */
public class NewBillBean { public class NewBillBean {
private BigDecimal price; private BigDecimal amount;
private String currency; private String currency;
private String remark; private String remark;
private int ineffective_hour; private String expire;
public BigDecimal getAmount() {
public String getRemark() { return amount;
return remark;
} }
public void setRemark(String remark) { public void setAmount(BigDecimal amount) {
this.remark = remark; this.amount = amount;
} }
public String getCurrency() { public String getCurrency() {
@ -32,19 +31,19 @@ public class NewBillBean {
this.currency = currency; this.currency = currency;
} }
public BigDecimal getPrice() { public String getRemark() {
return price; return remark;
} }
public void setPrice(BigDecimal price) { public void setRemark(String remark) {
this.price = price; this.remark = remark;
} }
public int getIneffective_hour() { public String getExpire() {
return ineffective_hour; return expire;
} }
public void setIneffective_hour(int ineffective_hour) { public void setExpire(String expire) {
this.ineffective_hour = ineffective_hour; this.expire = expire;
} }
} }

@ -16,7 +16,7 @@ public interface BillService {
void removeBill(String billId); void removeBill(String billId);
void save(int client_id,NewBillBean newBillBean); JSONObject save(int client_id,NewBillBean newBillBean);
JSONObject queryBills(int client_id, QueryBillBean queryBillBean); JSONObject queryBills(int client_id, QueryBillBean queryBillBean);

@ -15,7 +15,11 @@ import au.com.royalpay.payment.manage.bill.bean.NewBillBean;
import au.com.royalpay.payment.manage.bill.bean.QueryBillBean; 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.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.utils.PageListUtils; import au.com.royalpay.payment.tools.utils.PageListUtils;
/** /**
@ -25,24 +29,39 @@ import au.com.royalpay.payment.tools.utils.PageListUtils;
public class BillServiceImpl implements BillService { public class BillServiceImpl implements BillService {
@Resource @Resource
private BillMapper billMapper; private BillMapper billMapper;
@Resource
private ClientManager clientManager;
@Override @Override
public void save(int client_id,NewBillBean newBillBean) { public JSONObject save(int client_id, NewBillBean newBillBean) {
JSONObject client = clientManager.getClientInfo(client_id);
// if(client==null){
// throw new NotFoundException("client info not found");
// }
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.getPrice()); record.put("price", newBillBean.getAmount());
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);
record.put("cancle_time",DateUtils.addHours(now,newBillBean.getIneffective_hour())); record.put("cancle_time", addExpire(now, newBillBean.getExpire()));
record.put("status", 1); record.put("status", 1);
billMapper.save(record); billMapper.save(record);
JSONObject result = new JSONObject();
result.put("partner_name",client.getString("short_name"));
result.put("partner_code",client.getString("client_moniker"));
result.put("full_name",client.getString("company_name"));
result.put("code_url", PlatformEnvironment.getEnv().concatUrl("/bills/payment/orders/"+record.getString("blll_id")));
result.put("bill",record);
return result;
} }
@Override @Override
public JSONObject queryBills(int client_id, QueryBillBean queryBillBean) { public JSONObject queryBills(int client_id, QueryBillBean queryBillBean) {
PageList<JSONObject> list = billMapper.listWithOrderAnalysis(queryBillBean.toParams(), new PageBounds(queryBillBean.getPage(), queryBillBean.getLimit())); JSONObject params = queryBillBean.toParams();
params.put("client_id", client_id);
PageList<JSONObject> list = billMapper.listWithOrderAnalysis(params, new PageBounds(queryBillBean.getPage(), queryBillBean.getLimit()));
return PageListUtils.buildPageListResult(list); return PageListUtils.buildPageListResult(list);
} }
@ -56,7 +75,7 @@ public class BillServiceImpl implements BillService {
} }
@Override @Override
public void updateBillStatus(String billId, String status,int client_id) { public void updateBillStatus(String billId, String status, int client_id) {
JSONObject bill = billMapper.findOne(billId); JSONObject bill = billMapper.findOne(billId);
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");
@ -71,4 +90,20 @@ public class BillServiceImpl implements BillService {
public void removeBill(String billId) { public void removeBill(String billId) {
billMapper.delete(billId); billMapper.delete(billId);
} }
private Date addExpire(Date now, String expire) {
if (Integer.valueOf(expire.substring(0, expire.length() - 1)) == 0) {
return null;
}
String unit = expire.substring(expire.length() - 1, expire.length());
switch (unit) {
case "s":
return DateUtils.addSeconds(now, Integer.valueOf(expire.substring(0, expire.length() - 1)));
case "h":
return DateUtils.addHours(now, Integer.valueOf(expire.substring(0, expire.length() - 1)));
case "d":
return DateUtils.addDays(now, Integer.valueOf(expire.substring(0, expire.length() - 1)));
}
throw new ServerErrorException("日期单位不正确");
}
} }

@ -3,10 +3,12 @@
<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 right join pmt_bill_order o on b.bill_id = o.bill_id and o.order_status = 1 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
<where> <where>
b.client_id = #{param.client_id}
<if test="param.status != null"> <if test="param.status != null">
and o.status = #{param.status} and o.order_status = #{param.status}
</if> </if>
</where> </where>
group by b.bill_id,create_time,create_date,b.remark,b.price,b.status,b.currency group by b.bill_id,create_time,create_date,b.remark,b.price,b.status,b.currency

Loading…
Cancel
Save