master
wangning 7 years ago
parent bf69dfbfe5
commit db26a8bc29

@ -300,8 +300,11 @@ public class RetailAppController {
return billService.queryBills(device.getIntValue("client_id"),queryBillBean);
}
@RequestMapping(value = "/bills",method = RequestMethod.PUT)
public void addBill(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device,@RequestBody NewBillBean newBillBean){
billService.save(device.getIntValue("client_id"),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);
result.remove("bill");
return result;
}
@RequestMapping(value = "/bills/{bill_id}/close",method = RequestMethod.POST)
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 {
private BigDecimal price;
private BigDecimal amount;
private String currency;
private String remark;
private int ineffective_hour;
private String expire;
public String getRemark() {
return remark;
public BigDecimal getAmount() {
return amount;
}
public void setRemark(String remark) {
this.remark = remark;
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
public String getCurrency() {
@ -32,19 +31,19 @@ public class NewBillBean {
this.currency = currency;
}
public BigDecimal getPrice() {
return price;
public String getRemark() {
return remark;
}
public void setPrice(BigDecimal price) {
this.price = price;
public void setRemark(String remark) {
this.remark = remark;
}
public int getIneffective_hour() {
return ineffective_hour;
public String getExpire() {
return expire;
}
public void setIneffective_hour(int ineffective_hour) {
this.ineffective_hour = ineffective_hour;
public void setExpire(String expire) {
this.expire = expire;
}
}

@ -16,7 +16,7 @@ public interface BillService {
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);

@ -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.core.BillService;
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.NotFoundException;
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
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 {
@Resource
private BillMapper billMapper;
@Resource
private ClientManager clientManager;
@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();
JSONObject record = new JSONObject();
record.put("client_id",client_id);
record.put("price",newBillBean.getPrice());
record.put("currency",newBillBean.getCurrency());
record.put("remark",newBillBean.getRemark());
record.put("client_id", client_id);
record.put("price", newBillBean.getAmount());
record.put("currency", newBillBean.getCurrency());
record.put("remark", newBillBean.getRemark());
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);
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
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);
}
@ -56,7 +75,7 @@ public class BillServiceImpl implements BillService {
}
@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);
if (bill.getIntValue("client_id") != client_id) {
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) {
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">
<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>
b.client_id = #{param.client_id}
<if test="param.status != null">
and o.status = #{param.status}
and o.order_status = #{param.status}
</if>
</where>
group by b.bill_id,create_time,create_date,b.remark,b.price,b.status,b.currency

Loading…
Cancel
Save