|
|
@@ -1,9 +1,12 @@
|
|
|
package restcontroller.webmanage.sale.promotion;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
+import beans.accountbalance.Accountbalance;
|
|
|
+import beans.accountbalance.CashbillEntity;
|
|
|
import common.data.*;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
|
@@ -18,6 +21,7 @@ import common.annotation.API;
|
|
|
import common.annotation.CACHEING;
|
|
|
import common.annotation.CACHEING_CLEAN;
|
|
|
import restcontroller.R;
|
|
|
+import restcontroller.webmanage.sale.rebateaccount.rebateaccounthead;
|
|
|
|
|
|
@API(title = "促销方案")
|
|
|
public class promotion extends Controller {
|
|
|
@@ -49,6 +53,7 @@ public class promotion extends Controller {
|
|
|
Long authmethod = content.getLongValue("authmethod");
|
|
|
BigDecimal associationamount = content.getBigDecimalValue("associationamount");
|
|
|
Long associationaccountclassid = content.getLongValue("associationaccountclassid");
|
|
|
+ BigDecimal rebateratio = content.getBigDecimalValue("rebateratio");
|
|
|
SQLFactory sqlFactory = new SQLFactory(this, "促销方案新增");
|
|
|
|
|
|
if (sa_promotionid <= 0 || dbConnect
|
|
|
@@ -101,6 +106,8 @@ public class promotion extends Controller {
|
|
|
sqlFactory.addParameter("authmethod", authmethod);
|
|
|
sqlFactory.addParameter("associationamount", associationamount);
|
|
|
sqlFactory.addParameter("associationaccountclassid", associationaccountclassid);
|
|
|
+ sqlFactory.addParameter("rebateratio", rebateratio);
|
|
|
+
|
|
|
// 备注说明
|
|
|
sqlFactory.addParameter("remarks", remarks);
|
|
|
sqlList.add(sqlFactory.getSQL());
|
|
|
@@ -484,4 +491,57 @@ public class promotion extends Controller {
|
|
|
dbConnect.runSqlUpdate(sqlList);
|
|
|
return getSucReturnObject().toString();
|
|
|
}
|
|
|
+
|
|
|
+ @API(title = "结算", apiversion = R.ID20230826091303.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiClass = {rebateaccounthead.class})
|
|
|
+ public String settlement() throws YosException {
|
|
|
+ Long sa_promotion_authid = content.getLong("sa_promotion_authid");
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+ Rows promotionauthRows = dbConnect.runSqlQuery(
|
|
|
+ "select t1.*,t2.type,t2.rebateratio,t2.promname from sa_promotion_auth t1 inner join sa_promotion t2 on t1.siteid=t2.siteid and t1.sa_promotionid=t2.sa_promotionid where t1.sa_promotion_authid ='"
|
|
|
+ + sa_promotion_authid + "' and t1.siteid='" + siteid + "'");
|
|
|
+ if(promotionauthRows.isNotEmpty()){
|
|
|
+ if(!promotionauthRows.get(0).getString("type").equals("返利促销")){
|
|
|
+ return getErrReturnObject().setErrMsg("返利促销方案才能返利结算").toString();
|
|
|
+ }
|
|
|
+ if(promotionauthRows.get(0).getBoolean("settlestatus")){
|
|
|
+ return getErrReturnObject().setErrMsg("该经销商结算已经结算成功,无法再次结算").toString();
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ return getErrReturnObject().setErrMsg("该记录不存在").toString();
|
|
|
+ }
|
|
|
+ long sa_promotionid=promotionauthRows.get(0).getLong("sa_promotionid");
|
|
|
+ long sys_enterpriseid=promotionauthRows.get(0).getLong("sys_enterpriseid");
|
|
|
+ BigDecimal saledamount=promotionauthRows.get(0).getBigDecimal("saledamount");
|
|
|
+ BigDecimal rebateratio=promotionauthRows.get(0).getBigDecimal("rebateratio");
|
|
|
+ System.out.println(saledamount);
|
|
|
+ System.out.println(rebateratio);
|
|
|
+ String agentnum="";
|
|
|
+ Rows enterpriserows = dbConnect.runSqlQuery("select * from sa_agents where sys_enterpriseid ='"+sys_enterpriseid+"' and siteid='"+siteid+"'");
|
|
|
+ if(enterpriserows.isNotEmpty()){
|
|
|
+ agentnum=enterpriserows.get(0).getString("agentnum");
|
|
|
+ }
|
|
|
+ //查询经销商未关闭的促销订单
|
|
|
+ Rows rows = dbConnect.runSqlQuery("select * from sa_order where type ='促销订单' and sa_promotionid="+sa_promotionid+" and sys_enterpriseid ='"+sys_enterpriseid+"' and status not in('关闭','手工关闭') and siteid='"+siteid+"'");
|
|
|
+ if (rows.isNotEmpty()) {
|
|
|
+ return getErrReturnObject().setErrMsg("存在未关闭的返利促销订单,无法结算").toString();
|
|
|
+ } else {
|
|
|
+ Rows accountclassrows = dbConnect.runSqlQuery("select sa_accountclassid from sa_accountclass where accountname ='返利金账户' and siteid='"+siteid+"'");
|
|
|
+ if(accountclassrows.isNotEmpty()){
|
|
|
+ long sa_accountclassid=accountclassrows.get(0).getLong("sa_accountclassid");
|
|
|
+ CashbillEntity entity = new CashbillEntity();
|
|
|
+ entity.setAmount(saledamount.multiply(rebateratio));
|
|
|
+ entity.setOwnerid(sa_promotion_authid);
|
|
|
+ entity.setOwnertable("sa_promotion_auth");
|
|
|
+ entity.setSource("返利");
|
|
|
+ entity.setSourcenote("经销商【"+agentnum+"】,【"+promotionauthRows.get(0).getString("promname")+"】方案返利促销");
|
|
|
+ entity.setRemarks("【"+promotionauthRows.get(0).getString("promname")+"】方案返利促销");
|
|
|
+ sqlList.addAll(Accountbalance.createCashbillIncome(this, sys_enterpriseid,sa_accountclassid,entity,true));
|
|
|
+ sqlList.add("update sa_promotion_auth set settlestatus=1 where sa_promotion_authid="+sa_promotion_authid+" and siteid='"+siteid+"'");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+
|
|
|
+ }
|
|
|
}
|