Bladeren bron

返利促销(全部功能更新)

hu 2 jaren geleden
bovenliggende
commit
277683c95f

+ 4 - 0
src/custom/restcontroller/R.java

@@ -5233,6 +5233,10 @@ public class R {
         public static class v1 {
         }
     }
+    public static class ID20230826091303 {
+        public static class v1 {
+        }
+    }
 
 
 }

+ 1 - 0
src/custom/restcontroller/webmanage/sale/promotion/SQL/促销方案列表查询.sql

@@ -29,6 +29,7 @@ SELECT
 	t1.sa_openpromotionid,
 	t1.openamount,
 	t1.associationaccountclassid,
+	t1.rebateratio,
 	t4.accountname associationaccountname,
 	t4.accountno associationaccountno,
 	t1.associationamount,

+ 1 - 0
src/custom/restcontroller/webmanage/sale/promotion/SQL/促销方案参与授权范围查询.sql

@@ -8,6 +8,7 @@ SELECT t1.sa_promotion_authid,
        t1.saledamount,
        t1.saledordercount,
        t1.saledgroupqty,
+       t1.settlestatus,
        t1.createby,
        t1.createdate,
        t2.enterprisename,

+ 2 - 2
src/custom/restcontroller/webmanage/sale/promotion/SQL/促销方案新增.sql

@@ -1,8 +1,8 @@
 insert into sa_promotion (siteid, sa_promotionid, createuserid, createby, createdate, promnum, changeuserid, changeby,
                           changedate, promname, remarks, type, sa_accountclassid,
                           sa_brandid, tradefield, status, orderminqty, orderaddqty, orderminamount, begdate, enddate,
-                          sa_openpromotionid, openamount, isrelevancepromotion, authmethod,associationaccountclassid,associationamount)
+                          sa_openpromotionid, openamount, isrelevancepromotion, authmethod,associationaccountclassid,associationamount,rebateratio)
 values ($siteid$, $sa_promotionid$, $userid$, $username$, CURRENT_TIME, $promnum$, $userid$, $username$, CURRENT_TIME,
         $promname$, $remarks$, $type$, $sa_accountclassid$,
         $sa_brandid$, $tradefield$, '新建', $orderminqty$, $orderaddqty$, $orderminamount$, $begdate$, $enddate$,
-        $sa_openpromotionid$, $openamount$, $isrelevancepromotion$, $authmethod$,$associationaccountclassid$,$associationamount$);
+        $sa_openpromotionid$, $openamount$, $isrelevancepromotion$, $authmethod$,$associationaccountclassid$,$associationamount$,$rebateratio$);

+ 2 - 1
src/custom/restcontroller/webmanage/sale/promotion/SQL/促销方案更新.sql

@@ -18,6 +18,7 @@ SET changeuserid=$userid$,
     isrelevancepromotion=$isrelevancepromotion$,
     authmethod=$authmethod$,
     associationaccountclassid=$associationaccountclassid$,
-    associationamount=$associationamount$
+    associationamount=$associationamount$,
+    rebateratio=$rebateratio$
 WHERE sa_promotionid = $sa_promotionid$
   and siteid = $siteid$

+ 1 - 0
src/custom/restcontroller/webmanage/sale/promotion/SQL/促销方案详情查询.sql

@@ -30,6 +30,7 @@ SELECT t1.promnum,
 	     t5.accountname associationaccountname,
 	     t5.accountno associationaccountno,
 	     t1.associationamount,
+	     t1.rebateratio,
        t4.promname              openpromname,
        t1.openamount,
        t2.brandname,

+ 60 - 0
src/custom/restcontroller/webmanage/sale/promotion/promotion.java

@@ -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();
+
+    }
 }