|
楼主 |
发表于 2016-6-8 23:02:47
|
显示全部楼层
后台代码如下:
- //发布订单(包括检查该用户账户余额是否足够,保存订单,保存相应的交易明细)
- public static JSONObject releaseOrder(JSONObject params, ActionContext context) throws SQLException, NamingException, ParseException {
-
- Connection conn = context.getConnection("WSD");
- JSONObject ret = new JSONObject();
- JSONObject jsonTable = params.getJSONObject("table");
- String userID=null,userName=null,orderID=null;
- BigDecimal money=null;
- Table table=Transform.jsonToTable(jsonTable);
-
- //拿到生成交易记录的必要信息
- for ( Row row :table.getRows(RowState.NEW)){
- userID=row.getString("sendID");
- userName=row.getString("sendNiceName");
- money=row.getDecimal("costSummary");
- orderID=row.getString("fID");
- }
-
- try {
-
- System.out.println(userID);
- //本账户金额=本账户的转入金额-本账户的转出金额
- //本账户转入金额条件:turningInID=本人账户ID并且交易状态等于“已转入”
- //本账户转出金额条件turningInID=本人账户ID并且交易状态不等于“已撤消”
- String sql = "select (select ifnull(sum(amt),0) as moneyIn from fb_accounttransfer where turningInID='"+userID+"' and turningStatus ='已转入'"+
- ") -(select ifnull(sum(amt),0) as moneyOut from fb_accounttransfer where turningOutID='"+userID+"' and turningStatus !='已撤销') as accountMoney ";
- BigDecimal accountMoney = (BigDecimal) DataUtils.getValueBySQL(conn, sql, null);
- if(accountMoney.compareTo(money)<0){ //如果账户余额不足
- ret.put("result", "余额不足");
- }else{
- //保存订单数据
- DataUtils.saveData(conn, table);
-
-
- //生成交易明细
- String transSql="insert into fb_accounttransfer(fID,transferDescriptor,turningOutAccount,turningOutID,truningOutTime,orderID,turningStatus,amt)"+
- "values(uuid(),'发布订单','"+userName+"','"+userID+"',now(),'"+orderID+"','已转出','"+money+"')";
- java.sql.PreparedStatement pstmt = conn.prepareStatement(transSql);
-
- if (pstmt.executeUpdate() == 1)
- ret.put("result", "发布成功"); // 更新成功,返回1
- else
- ret.put("result", "发布失败"); // 更新失败,返回0
- return ret;
- }
-
-
- }catch(Exception e){
- ret.put("result", "保存错误!");
- return ret;
- }
- finally {
- conn.close();
- }
- return ret;
- }
复制代码 |
|