|
|
@@ -1002,6 +1002,9 @@ public class Order extends Controller {
|
|
|
return getErrReturnObject().setErrMsg("订单不存在").toString();
|
|
|
}
|
|
|
Row row = rows.get(0);
|
|
|
+ //付款账户信息
|
|
|
+ JSONArray accountclassinfos = row.getJSONArray("sa_accountclassinfos");
|
|
|
+
|
|
|
Long sa_accountclassid = row.getLong("sa_accountclassid");
|
|
|
if (sa_accountclassid <= 0) {
|
|
|
return getErrReturnObject().setErrMsg("请选择支付账号").toString();
|
|
|
@@ -1123,17 +1126,42 @@ public class Order extends Controller {
|
|
|
sqlList.addAll(useRateBill(row, "订单提交"));
|
|
|
|
|
|
} else {
|
|
|
- if (Accountbalance.judgeBalance(this, pay_enterpriseid, sa_accountclassid, amount)) {
|
|
|
- CashbillEntity entity = getCashbillEntity(amount, sa_orderid, "订单提交", "由" + sonum + "订单提交时自动产生");
|
|
|
- sqlList.addAll(Accountbalance.createCashbillPay(this, pay_enterpriseid, sa_accountclassid, entity, true));
|
|
|
- } else {
|
|
|
- return getErrReturnObject().setErrMsg("账户余额不足,还差"+Accountbalance.InsufficientBalance(this, pay_enterpriseid, sa_accountclassid, amount)+"元!").toString();
|
|
|
+
|
|
|
+ Rows accountclassrows =dbConnect.runSqlQuery("select t1.*,ifnull(t2.balance,0) balance,ifnull(t2.creditquota,0) creditquota from sa_accountclass t1 left join sa_accountbalance t2 on t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid and t2.sys_enterpriseid="+pay_enterpriseid+" where isused=1 and t1.siteid='"+siteid+"'");
|
|
|
+ RowsMap accountclassrowsMap = accountclassrows.toRowsMap("sa_accountclassid");
|
|
|
+ if(!accountclassinfos.isEmpty()){
|
|
|
+ for (Object object:accountclassinfos) {
|
|
|
+ JSONObject jsonObject = (JSONObject) object;
|
|
|
+ if (Accountbalance.judgeBalance(this, pay_enterpriseid, jsonObject.getLong("sa_accountclassid"), jsonObject.getBigDecimal("amount"))) {
|
|
|
+ CashbillEntity entity = getCashbillEntity(jsonObject.getBigDecimal("amount"), sa_orderid, "订单提交", "由" + sonum + "订单提交时,"+jsonObject.getString("accountname")+"账户自动支出产生");
|
|
|
+ //
|
|
|
+ if(accountclassrowsMap.containsKey(jsonObject.getString("sa_accountclassid")) && accountclassrowsMap.get(jsonObject.getString("sa_accountclassid")).isNotEmpty()){
|
|
|
+ jsonObject.put("balance",accountclassrowsMap.get(jsonObject.getString("sa_accountclassid")).get(0).getBigDecimal("balance").subtract(jsonObject.getBigDecimal("amount")));
|
|
|
+ }else {
|
|
|
+ jsonObject.put("balance",jsonObject.getBigDecimalValue("balance").subtract(jsonObject.getBigDecimal("amount")));
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlList.addAll(Accountbalance.createCashbillPay(this, pay_enterpriseid, jsonObject.getLong("sa_accountclassid"), entity, true));
|
|
|
+ } else {
|
|
|
+ return getErrReturnObject().setErrMsg("账户余额不足,还差"+Accountbalance.InsufficientBalance(this, pay_enterpriseid, jsonObject.getLong("sa_accountclassid"), jsonObject.getBigDecimal("amount"))+"元!").toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if (Accountbalance.judgeBalance(this, pay_enterpriseid, sa_accountclassid, amount)) {
|
|
|
+ CashbillEntity entity = getCashbillEntity(amount, sa_orderid, "订单提交", "由" + sonum + "订单提交时自动产生");
|
|
|
+ sqlList.addAll(Accountbalance.createCashbillPay(this, pay_enterpriseid, sa_accountclassid, entity, true));
|
|
|
+ } else {
|
|
|
+ return getErrReturnObject().setErrMsg("账户余额不足,还差"+Accountbalance.InsufficientBalance(this, pay_enterpriseid, sa_accountclassid, amount)+"元!").toString();
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
|
String message = "您的订单【" + sonum + "】 金额为【" + amount + "】 已提交!";
|
|
|
|
|
|
+ sqlList.add("update sa_order set sa_accountclassinfos='"+accountclassinfos+"' where sa_orderid="+sa_orderid+" and siteid='"+siteid+"'");
|
|
|
sqlList.add(getOrderSubmitSql(sa_orderid, status, freightstatus));
|
|
|
sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "订单提交", "订单提交成功,金额:" + amount).getSQL());
|
|
|
dbConnect.runSqlUpdate(sqlList);
|
|
|
@@ -1233,6 +1261,7 @@ public class Order extends Controller {
|
|
|
return getErrReturnObject().setErrMsg("订单不存在").toString();
|
|
|
}
|
|
|
Row row = rows.get(0);
|
|
|
+ JSONArray accountclassinfos = row.getJSONArray("accountclassinfos");
|
|
|
Long sys_enterpriseid = row.getLong("sys_enterpriseid");
|
|
|
Long sa_accountclassid = row.getLong("sa_accountclassid");
|
|
|
if (sa_accountclassid <= 0) {
|
|
|
@@ -1285,11 +1314,24 @@ public class Order extends Controller {
|
|
|
sqlList.addAll(useRateBill(row, "订单审核"));
|
|
|
|
|
|
} else {
|
|
|
- if (Accountbalance.judgeBalance(this, pay_enterpriseid, sa_accountclassid, amount)) {
|
|
|
- CashbillEntity entity = getCashbillEntity(amount, sa_orderid, "订单审核", "由" + sonum + "订单审核时自动产生");
|
|
|
- sqlList.addAll(Accountbalance.createCashbillPay(this, pay_enterpriseid, sa_accountclassid, entity, true));
|
|
|
- } else {
|
|
|
- return getErrReturnObject().setErrMsg("账户余额不足").toString();
|
|
|
+ if(!accountclassinfos.isEmpty()){
|
|
|
+ for (Object object:accountclassinfos) {
|
|
|
+ JSONObject jsonObject = (JSONObject) object;
|
|
|
+ if (Accountbalance.judgeBalance(this, pay_enterpriseid, jsonObject.getLong("sa_accountclassid"), jsonObject.getBigDecimal("amount"))) {
|
|
|
+ CashbillEntity entity = getCashbillEntity(jsonObject.getBigDecimal("amount"), sa_orderid, "订单审核", "由" + sonum + "订单审核时,"+jsonObject.getString("accountname")+"账户自动支出产生");
|
|
|
+ jsonObject.put("balance",jsonObject.getBigDecimalValue("balance").subtract(jsonObject.getBigDecimal("amount")));
|
|
|
+ sqlList.addAll(Accountbalance.createCashbillPay(this, pay_enterpriseid, jsonObject.getLong("sa_accountclassid"), entity, true));
|
|
|
+ } else {
|
|
|
+ return getErrReturnObject().setErrMsg("账户余额不足,还差"+Accountbalance.InsufficientBalance(this, pay_enterpriseid, jsonObject.getLong("sa_accountclassid"), jsonObject.getBigDecimal("amount"))+"元!").toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if (Accountbalance.judgeBalance(this, pay_enterpriseid, sa_accountclassid, amount)) {
|
|
|
+ CashbillEntity entity = getCashbillEntity(amount, sa_orderid, "订单审核", "由" + sonum + "订单审核时自动产生");
|
|
|
+ sqlList.addAll(Accountbalance.createCashbillPay(this, pay_enterpriseid, sa_accountclassid, entity, true));
|
|
|
+ } else {
|
|
|
+ return getErrReturnObject().setErrMsg("账户余额不足,还差"+Accountbalance.InsufficientBalance(this, pay_enterpriseid, sa_accountclassid, amount)+"元!").toString();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1739,7 +1781,8 @@ public class Order extends Controller {
|
|
|
|
|
|
public ArrayList<String> returnPayBill(Row orderrow, String source, String remarks) throws YosException {
|
|
|
Long sa_orderid = orderrow.getLong("sa_orderid");
|
|
|
- Long sa_accountclassid = orderrow.getLong("sa_accountclassid");
|
|
|
+ JSONArray sa_accountclassinfos =orderrow.getJSONArray("sa_accountclassinfos");
|
|
|
+ //Long sa_accountclassid = orderrow.getLong("sa_accountclassid");
|
|
|
//验证结算企业
|
|
|
Long pay_enterpriseid = orderrow.getLong("pay_enterpriseid");
|
|
|
ArrayList<String> sqlList = new ArrayList<>();
|
|
|
@@ -1759,15 +1802,31 @@ public class Order extends Controller {
|
|
|
|
|
|
}
|
|
|
//金额
|
|
|
- Rows amountRows = getCashbillRows(sa_orderid);
|
|
|
+ Rows amountRows = getMultipleAccountsCashbillRows(sa_orderid);
|
|
|
if (amountRows.isNotEmpty()) {
|
|
|
- amount = amountRows.get(0).getBigDecimal("amount");
|
|
|
- if (amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- CashbillEntity entity = getCashbillEntity(amount.negate(), sa_orderid, source, remarks);
|
|
|
- sqlList.addAll(Accountbalance.createCashbillPay(this, pay_enterpriseid, sa_accountclassid, entity, true));
|
|
|
+ for (Row row:amountRows) {
|
|
|
+ amount=row.getBigDecimal("amount");
|
|
|
+ if(!sa_accountclassinfos.isEmpty()){
|
|
|
+ for (Object object:sa_accountclassinfos) {
|
|
|
+ JSONObject jsonObject = (JSONObject)object;
|
|
|
+ if(jsonObject.getLong("sa_accountclassid")==row.getLong("sa_accountclassid")){
|
|
|
+ System.out.println(jsonObject.getBigDecimal("balance"));
|
|
|
+ System.out.println(amount);
|
|
|
+ System.out.println(jsonObject.getBigDecimal("balance").add(amount));
|
|
|
+ jsonObject.put("balance",jsonObject.getBigDecimal("balance").add(amount));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ CashbillEntity entity = getCashbillEntity(amount.negate(), sa_orderid, source, remarks);
|
|
|
+ sqlList.addAll(Accountbalance.createCashbillPay(this, pay_enterpriseid, row.getLong("sa_accountclassid"), entity, true));
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
+ }
|
|
|
+ sqlList.add("update sa_order set sa_accountclassinfos='"+sa_accountclassinfos+"' where sa_orderid="+sa_orderid+" and siteid='"+siteid+"'");
|
|
|
return sqlList;
|
|
|
}
|
|
|
|
|
|
@@ -2472,7 +2531,13 @@ public class Order extends Controller {
|
|
|
|
|
|
public Rows getCashbillRows(Long sa_orderid) throws YosException {
|
|
|
|
|
|
- return dbConnect.runSqlQuery("SELECT sum(amount) amount from sa_cashbill WHERE ownerid ='" + sa_orderid + "' and ownertable='sa_order' and type = 0 and sa_cashbillid_rebate is null and siteid = '" + siteid + "'");
|
|
|
+ return dbConnect.runSqlQuery("SELECT sum(amount) amount from sa_cashbill WHERE ownerid ='" + sa_orderid + "' and ownertable='sa_order' and type = 0 and sa_cashbillid_rebate is null and siteid = '" + siteid + "' ");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public Rows getMultipleAccountsCashbillRows(Long sa_orderid) throws YosException {
|
|
|
+
|
|
|
+ return dbConnect.runSqlQuery("SELECT sa_accountclassid,sum(amount) amount from sa_cashbill WHERE ownerid ='" + sa_orderid + "' and ownertable='sa_order' and type = 0 and sa_cashbillid_rebate is null and siteid = '" + siteid + "' group by sa_accountclassid");
|
|
|
|
|
|
}
|
|
|
|