123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628 |
- 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;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import beans.data.BatchDeleteErr;
- import beans.datacontrllog.DataContrlLog;
- import common.Controller;
- import common.YosException;
- 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 {
- public promotion(JSONObject arg0) throws YosException {
- super(arg0);
- // TODO Auto-generated constructor stub
- }
- @API(title = "促销方案新增更新", apiversion = R.ID20221230144503.v1.class, intervaltime = 200)
- @CACHEING_CLEAN(apiversions = {R.ID20221230144703.v1.class, R.ID20221230144803.v1.class, R.ID20220103140003.v1.class})
- public String insertormodify_promotion() throws YosException {
- ArrayList<String> sqlList = new ArrayList<>();
- // 表名
- String tableName = "sa_promotion";
- Long sa_promotionid = content.getLong("sa_promotionid");
- Long sa_accountclassid = content.getLong("sa_accountclassid");
- Long sa_brandid = content.getLong("sa_brandid");
- String promname = content.getStringValue("promname");
- String remarks = content.getStringValue("remarks");
- String type = content.getStringValue("type");
- //String tradefield = content.getStringValue("tradefield");
- JSONArray tradefield = content.getJSONArray("tradefield");
- BigDecimal orderminqty = content.getBigDecimal("orderminqty");
- BigDecimal orderaddqty = content.getBigDecimal("orderaddqty");
- BigDecimal orderminamount = content.getBigDecimal("orderminamount");
- String begdate = content.getStringValue("begdate");
- String enddate = content.getStringValue("enddate");
- Long authmethod = content.getLongValue("authmethod");
- boolean isauth = content.getBooleanValue("isauth");
- 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
- .runSqlQuery("select sa_promotionid from sa_promotion where sa_promotionid=" + sa_promotionid)
- .isEmpty()) {
- sa_promotionid = createTableID(tableName);
- sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "新增", "促销方案新增成功").getSQL());
- } else {
- Rows rows = dbConnect
- .runSqlQuery("SELECT status,authmethod from sa_promotion WHERE sa_promotionid = " + sa_promotionid);
- if (rows.isNotEmpty()) {
- if (rows.get(0).getString("status").equals("新建")) {
- sqlFactory = new SQLFactory(this, "促销方案更新");
- sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "更新", "促销方案更新成功").getSQL());
- if (rows.get(0).getLong("authmethod") != authmethod) {
- if (dbConnect.runSqlQuery("select * from sa_promotion_auth where siteid='" + siteid + "' and sa_promotionid=" + sa_promotionid).isNotEmpty()) {
- return getErrReturnObject().setErrMsg("已有授权经销商,无法更改授权方式").toString();
- }
- sqlList.add("delete from sa_promotion_auth where siteid='" + siteid + "' and sa_promotionid=" + sa_promotionid);
- }
- } else {
- return getErrReturnObject().setErrMsg("非新建状态下无法编辑").toString();
- }
- } else {
- return getErrReturnObject().setErrMsg("该促销方案不存在").toString();
- }
- }
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("userid", userid);
- sqlFactory.addParameter("username", username);
- sqlFactory.addParameter("sa_promotionid", sa_promotionid);
- // 促销方案号createBillCode("promotionbillno")
- sqlFactory.addParameter("promnum", createBillCode("promotionbill"));
- sqlFactory.addParameter("promname", promname);
- sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
- sqlFactory.addParameter("sa_brandid", sa_brandid);
- sqlFactory.addParameter("type", type);
- sqlFactory.addParameter("tradefield", tradefield.toJSONString());
- sqlFactory.addParameter("orderminqty", orderminqty);
- sqlFactory.addParameter("orderaddqty", orderaddqty);
- sqlFactory.addParameter("orderminamount", orderminamount);
- sqlFactory.addParameter("sa_openpromotionid", content.getIntValue("sa_openpromotionid"));
- sqlFactory.addParameter("openamount", content.getBigDecimalValue("openamount"));
- sqlFactory.addParameter("isrelevancepromotion", content.getLongValue("isrelevancepromotion"));
- sqlFactory.addParameter("begdate", begdate);
- sqlFactory.addParameter("enddate", enddate);
- sqlFactory.addParameter("authmethod", authmethod);
- sqlFactory.addParameter("isauth", isauth);
- sqlFactory.addParameter("associationamount", associationamount);
- sqlFactory.addParameter("associationaccountclassid", associationaccountclassid);
- sqlFactory.addParameter("rebateratio", rebateratio);
- // 备注说明
- sqlFactory.addParameter("remarks", remarks);
- sqlList.add(sqlFactory.getSQL());
- dbConnect.runSqlUpdate(sqlList);
- content.put("sa_promotionid", sa_promotionid);
- return querypromotionMain();
- }
- @API(title = "促销方案详情", apiversion = R.ID20221230144703.v1.class)
- @CACHEING
- public String querypromotionMain() throws YosException {
- Long sa_promotionid = content.getLong("sa_promotionid");
- SQLFactory sqlFactory = new SQLFactory(this, "促销方案详情查询");
- sqlFactory.addParameter("sa_promotionid", sa_promotionid);
- sqlFactory.addParameter("siteid", siteid);
- Rows rows = dbConnect.runSqlQuery(sqlFactory);
- Row row = rows.isNotEmpty() ? rows.get(0) : new Row();
- //附件
- ArrayList<Long> ids = rows.toArrayList("sa_promotionid", new ArrayList<>());
- RowsMap attRowsMap = getAttachmentUrl("sa_promotion", ids);
- row.put("attinfos", attRowsMap.getOrDefault(row.getString("sa_promotionid"), new Rows()));
- if (!StringUtils.isBlank(row.getString("tradefield"))) {
- row.put("tradefield", JSONArray.parseArray(row.getString("tradefield")));
- } else {
- row.put("tradefield", new JSONArray());
- }
- return getSucReturnObject().setData(row).toString();
- }
- @API(title = "一键复制促销方案", apiversion = R.ID20230713101303.v1.class)
- @CACHEING_CLEAN(apiClass = {promotion.class, promotionSalearea.class, promotionAuth.class, promotionItems.class, promotionItemPrice.class})
- public String copyPromotion() throws YosException {
- Long sa_promotionid = content.getLong("sa_promotionid");
- ArrayList<String> sqlList = new ArrayList<>();
- Rows rows = dbConnect.runSqlQuery("SELECT * from sa_promotion WHERE sa_promotionid = " + sa_promotionid + " and siteid = '" + siteid + "'");
- if (rows.isEmpty()) {
- return getErrReturnObject().setErrMsg("促销方案不存在").toString();
- }
- Row row = rows.get(0);
- Long sa_promotion_copy = createTableID("sa_promotion");
- SQLFactory sqlFactory = new SQLFactory(this, "促销方案新增");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("sa_promotionid", sa_promotion_copy);
- sqlFactory.addParameter("userid", userid);
- sqlFactory.addParameter("username", username);
- //促销方案名称
- sqlFactory.addParameter("promname", row.getString("promname") + "复制");
- sqlFactory.addParameter("promnum", createBillCode("promotionbill"));
- sqlFactory.addParameter("sa_accountclassid", row.getLong("sa_accountclassid"));
- sqlFactory.addParameter("sa_brandid", row.getLong("sa_brandid"));
- sqlFactory.addParameter("type", row.getString("type"));
- sqlFactory.addParameter("tradefield", row.getString("tradefield"));
- sqlFactory.addParameter("orderminqty", row.getBigDecimal("orderminqty"));
- sqlFactory.addParameter("orderaddqty", row.getBigDecimal("orderaddqty"));
- sqlFactory.addParameter("orderminamount", row.getBigDecimal("orderminamount"));
- sqlFactory.addParameter("sa_openpromotionid", row.getLong("sa_openpromotionid"));
- sqlFactory.addParameter("openamount", row.getBigDecimal("openamount"));
- sqlFactory.addParameter("isrelevancepromotion", row.getString("isrelevancepromotion"));
- sqlFactory.addParameter("associationamount", row.getString("associationamount"));
- sqlFactory.addParameter("associationaccountclassid", row.getString("associationaccountclassid"));
- sqlFactory.addParameter("begdate", row.getString("begdate"));
- sqlFactory.addParameter("enddate", row.getString("enddate"));
- sqlFactory.addParameter("authmethod", row.getString("authmethod"));
- sqlFactory.addParameter("associationamount", 0);
- sqlFactory.addParameter("associationaccountclassid", 0);
- sqlFactory.addParameter("rebateratio", 0);
- // 备注说明
- sqlFactory.addParameter("remarks", row.getString("remarks"));
- sqlList.add(sqlFactory.getSQL());
- //复制商品
- Rows promotionitemsRows = dbConnect.runSqlQuery("SELECT * from sa_promotion_items WHERE sa_promotionid = " + sa_promotionid + " and siteid = '" + siteid + "'");
- //复制商品
- Rows promotionitemspriceRows = dbConnect.runSqlQuery("SELECT * from sa_promotion_itemprice WHERE sa_promotionid = " + sa_promotionid + " and siteid = '" + siteid + "'");
- RowsMap promotionitemspriceRowsMap = promotionitemspriceRows.toRowsMap("sa_promotion_itemsid");
- for (Row promotionitemsRow : promotionitemsRows) {
- sqlFactory = new SQLFactory(this, "促销方案商品新增");
- sqlFactory.addParameter("siteid", siteid);
- long sa_promotion_itemsidcopy = createTableID("sa_promotion_items");
- sqlFactory.addParameter("sa_promotion_itemsid", sa_promotion_itemsidcopy);
- sqlFactory.addParameter("sa_promotionid", sa_promotion_copy);
- sqlFactory.addParameter("sa_promotion_itemgroupid", promotionitemsRow.getLong("sa_promotion_itemgroupid"));
- sqlFactory.addParameter("groupqty", promotionitemsRow.getBigDecimal("groupqty"));
- sqlFactory.addParameter("itemid", promotionitemsRow.getLong("itemid"));
- sqlFactory.addParameter("orderaddqty", promotionitemsRow.getBigDecimal("orderaddqty"));
- sqlFactory.addParameter("orderminqty", promotionitemsRow.getBigDecimal("orderminqty"));
- sqlFactory.addParameter("islimit", promotionitemsRow.getLong("islimit"));
- sqlFactory.addParameter("signaturecode", promotionitemsRow.getString("signaturecode"));
- sqlList.add(sqlFactory.getSQL());
- if (promotionitemspriceRowsMap.containsKey(promotionitemsRow.getString("sa_promotion_itemsid")) && promotionitemspriceRowsMap.get(promotionitemsRow.getString("sa_promotion_itemsid")).isNotEmpty()) {
- for (Row rowdetail : promotionitemspriceRowsMap.get(promotionitemsRow.getString("sa_promotion_itemsid"))) {
- SQLFactory itempriceFactory = new SQLFactory(this, "促销方案商品价格新增");
- itempriceFactory.addParameter("siteid", siteid);
- itempriceFactory.addParameter("sa_promotion_itempriceid",
- createTableID("sa_promotion_itemprice"));
- itempriceFactory.addParameter("sa_promotionid", sa_promotion_copy);
- itempriceFactory.addParameter("sa_promotion_itemsid", sa_promotion_itemsidcopy);
- itempriceFactory.addParameter("itemid", rowdetail.getLong("itemid"));
- itempriceFactory.addParameter("pricegrade", rowdetail.getBigDecimal("pricegrade"));
- itempriceFactory.addParameter("oldprice", rowdetail.getBigDecimal("oldprice"));
- itempriceFactory.addParameter("price", rowdetail.getBigDecimal("price"));
- sqlList.add(itempriceFactory.getSQL());
- }
- }
- }
- dbConnect.runSqlUpdate(sqlList);
- content.put("sa_promotionid", sa_promotion_copy);
- return querypromotionMain();
- }
- @API(title = "查询促销方案列表", apiversion = R.ID20221230144803.v1.class)
- @CACHEING
- public String querypromotionList() throws YosException {
- StringBuffer where = new StringBuffer(" 1=1 ");
- if (content.containsKey("where")) {
- JSONObject whereObject = content.getJSONObject("where");
- if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
- where.append(" and(");
- where.append("t1.promnum like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.promname like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.remarks like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
- where.append(" and t1.status ='").append(whereObject.getString("status")).append("' ");
- }
- if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
- where.append(" and DATE_FORMAT(t1.begdate, '%Y-%m-%d') >='").append(whereObject.getString("begindate")).append("' ");
- }
- if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
- where.append(" and DATE_FORMAT(t1.enddate, '%Y-%m-%d') <='").append(whereObject.getString("enddate")).append("' ");
- }
- }
- // SQLFactory sqlFactory = new SQLFactory(this, "促销方案列表查询", pageSize, pageNumber, pageSorting);
- // sqlFactory.addParameter("siteid", siteid);
- // sqlFactory.addParameter_SQL("where", where);
- // Rows rows = dbConnect.runSqlQuery(sqlFactory);
- QuerySQL querySQL = queryPomotionList(where.toString());
- querySQL.setOrderBy(pageSorting);
- querySQL.setPage(pageSize, pageNumber);
- Rows rows = querySQL.query();
- //附件
- ArrayList<Long> ids = rows.toArrayList("sa_promotionid", new ArrayList<>());
- RowsMap attRowsMap = getAttachmentUrl("sa_promotion", ids);
- for (Row row : rows) {
- if (!StringUtils.isBlank(row.getString("tradefield"))) {
- row.put("tradefield", JSONArray.parseArray(row.getString("tradefield")));
- } else {
- row.put("tradefield", new JSONArray());
- }
- row.put("attinfos", attRowsMap.getOrDefault(row.getString("sa_promotionid"), new Rows()));
- }
- return getSucReturnObject().setData(rows).toString();
- }
- public QuerySQL queryPomotionList(String where) throws YosException {
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_promotion");
- querySQL.setTableAlias("t1");
- querySQL.addJoinTable(JOINTYPE.left, "sa_brand", "t2", "t1.sa_brandid = t2.sa_brandid AND t1.siteid = t2.siteid",
- "brandname");
- querySQL.addJoinTable(JOINTYPE.left, "sa_accountclass", "t3", "t1.sa_accountclassid = t3.sa_accountclassid AND t1.siteid = t3.siteid",
- "accountno", "accountname");
- querySQL.setWhere("t1.siteid", siteid);
- querySQL.setWhere(where);
- return querySQL;
- }
- @API(title = "查询促销方案销售排行(经销商)", apiversion = R.ID20231007101703.v1.class)
- @CACHEING
- public String queryAgentSalesRanking() throws YosException {
- long sa_promotionid =content.getLongValue("sa_promotionid");
- StringBuffer where = new StringBuffer(" 1=1 ");
- if (content.containsKey("where")) {
- JSONObject whereObject = content.getJSONObject("where");
- if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
- where.append(" and(");
- where.append("t2.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t3.abbreviation like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- }
- SQLFactory sqlFactory = new SQLFactory(this, "促销方案销售排行查询(经销商)", pageSize, pageNumber, pageSorting);
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("sa_promotionid", sa_promotionid);
- sqlFactory.addParameter_SQL("where", where);
- Rows rows = dbConnect.runSqlQuery(sqlFactory);
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "查询促销方案销售排行(商品)", apiversion = R.ID20231007101803.v1.class)
- @CACHEING
- public String queryItemSalesRanking() throws YosException {
- long sa_promotionid =content.getLongValue("sa_promotionid");
- StringBuffer where = new StringBuffer(" 1=1 ");
- if (content.containsKey("where")) {
- JSONObject whereObject = content.getJSONObject("where");
- if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
- where.append(" and(");
- where.append("t2.itemno like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.itemname like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- }
- SQLFactory sqlFactory = new SQLFactory(this, "促销方案销售排行查询(商品)", pageSize, pageNumber, pageSorting);
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("sa_promotionid", sa_promotionid);
- sqlFactory.addParameter_SQL("where", where);
- Rows rows = dbConnect.runSqlQuery(sqlFactory);
- // //附件
- // ArrayList<Long> ids = rows.toArrayList("sa_promotionid", new ArrayList<>());
- // RowsMap attRowsMap = getAttachmentUrl("sa_promotion", ids);
- // for (Row row : rows) {
- // if (!StringUtils.isBlank(row.getString("tradefield"))) {
- // row.put("tradefield", JSONArray.parseArray(row.getString("tradefield")));
- // } else {
- // row.put("tradefield", new JSONArray());
- // }
- // row.put("attinfos", attRowsMap.getOrDefault(row.getString("sa_promotionid"), new Rows()));
- // }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "删除", apiversion = R.ID20221230144903.v1.class)
- @CACHEING_CLEAN(apiversions = {R.ID20221230144703.v1.class, R.ID20221230144803.v1.class, R.ID20220103140003.v1.class})
- public String delete() throws YosException {
- ArrayList<String> sqlList = new ArrayList<>();
- JSONArray sa_promotionids = content.getJSONArray("sa_promotionids");
- BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_promotionids.size());
- for (Object o : sa_promotionids) {
- long sa_promotionid = Long.parseLong(o.toString());
- Rows RowsStatus = dbConnect.runSqlQuery("select sa_promotionid,status from sa_promotion where siteid='"
- + siteid + "' and sa_promotionid='" + sa_promotionid + "'");
- Rows Rowsdetail = dbConnect.runSqlQuery("select sa_promotion_authid from sa_promotion_auth where siteid='"
- + siteid + "' and sa_promotionid='" + sa_promotionid + "' and saledamount>0");
- if (RowsStatus.isNotEmpty()) {
- if (!RowsStatus.get(0).getString("status").equals("新建")) {
- batchDeleteErr.addErr(sa_promotionid, "非新建状态的促销方案无法删除");
- continue;
- }
- }
- if (Rowsdetail.isNotEmpty()) {
- batchDeleteErr.addErr(sa_promotionid, "存在已购金额的授权经销商禁止删除促销活动");
- continue;
- }
- sqlList.add("delete from sa_promotion where siteid='" + siteid + "' and sa_promotionid=" + sa_promotionid);
- sqlList.add(
- "delete from sa_promotion_auth where siteid='" + siteid + "' and sa_promotionid=" + sa_promotionid);
- sqlList.add("delete from sa_promotion_itemgroup where siteid='" + siteid + "' and sa_promotionid="
- + sa_promotionid);
- sqlList.add("delete from sa_promotion_itemprice where siteid='" + siteid + "' and sa_promotionid="
- + sa_promotionid);
- sqlList.add("delete from sa_promotion_items where siteid='" + siteid + "' and sa_promotionid="
- + sa_promotionid);
- dbConnect.runSqlUpdate(sqlList);
- }
- return batchDeleteErr.getReturnObject().toString();
- }
- @API(title = "审核", apiversion = R.ID20221230145003.v1.class)
- @CACHEING_CLEAN(apiversions = {R.ID20221230144703.v1.class, R.ID20221230144803.v1.class, R.ID20220103140003.v1.class})
- public String check() throws YosException {
- Long sa_promotionid = content.getLong("sa_promotionid");
- Rows rows = dbConnect
- .runSqlQuery("select sa_promotionid,status,promnum,promname,type,associationaccountclassid,associationamount from sa_promotion where sa_promotionid ='"
- + sa_promotionid + "' and siteid='" + siteid + "'");
- if (rows.isEmpty()) {
- return getErrReturnObject().setErrMsg("该促销方案不存在").toString();
- } else {
- if (!rows.get(0).getString("status").equals("新建")) {
- return getErrReturnObject().setErrMsg("单号为:【" + rows.get(0).getString("promnum") + "】的促销方案为非新建状态,无法审核")
- .toString();
- }
- if(rows.get(0).getString("type").equals("返利促销")){
- if(rows.get(0).getLong("associationaccountclassid")==0 || rows.get(0).getBigDecimal("associationamount").compareTo(BigDecimal.ZERO)==0){
- return getErrReturnObject().setErrMsg("返利促销必须选择关联支付账户和关联支付金额").toString();
- }
- Rows islimitRows = dbConnect.runSqlQuery("select ifnull(islimit,0) islimit,count(1) from sa_promotion_auth where siteid='"+siteid+"' and sa_promotionid="+sa_promotionid+" group by ifnull(islimit,0)");
- if(islimitRows.isEmpty()){
- return getErrReturnObject().setErrMsg("返利促销必须授权经销商").toString();
- } else if(islimitRows.size()>1 || (islimitRows.size()==1 && !islimitRows.get(0).getBoolean("islimit"))){
- return getErrReturnObject().setErrMsg("返利促销授权的经销商必须都为限购").toString();
- }
- }
- }
- ArrayList<String> sqlList = new ArrayList<>();
- SQLFactory sqlFactoryupdate = new SQLFactory(this, "促销方案审核");
- sqlFactoryupdate.addParameter("siteid", siteid);
- sqlFactoryupdate.addParameter("sa_promotionid", sa_promotionid);
- sqlFactoryupdate.addParameter("checkby", username);
- sqlList.add(sqlFactoryupdate.getSQL());
- sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "审核", "促销方案审核成功").getSQL());
- dbConnect.runSqlUpdate(sqlList);
- return getSucReturnObject().toString();
- }
- @API(title = "反审核", apiversion = R.ID20221230145103.v1.class)
- @CACHEING_CLEAN(apiversions = {R.ID20221230144703.v1.class, R.ID20221230144803.v1.class, R.ID20220103140003.v1.class})
- public String uncheck() throws YosException {
- Long sa_promotionid = content.getLong("sa_promotionid");
- Rows rows = dbConnect
- .runSqlQuery("select sa_promotionid,status,promnum,promname from sa_promotion where sa_promotionid ='"
- + sa_promotionid + "' and siteid='" + siteid + "'");
- if (rows.isEmpty()) {
- return getErrReturnObject().setErrMsg("该促销方案不存在").toString();
- } else {
- if (!rows.get(0).getString("status").equals("审核")) {
- return getErrReturnObject().setErrMsg("单号为:【" + rows.get(0).getString("promnum") + "】的促销方案为非审核状态,无法反审核")
- .toString();
- }
- // if(!dbConnect.runSqlQuery("select * from sa_order where sa_promotionid="+sa_promotionid+" and siteid='"+siteid+"'").isEmpty()){
- // return getErrReturnObject().setErrMsg("存在已使用方案的订单,无法反审核")
- // .toString();
- // }
- }
- ArrayList<String> sqlList = new ArrayList<>();
- SQLFactory sqlFactoryupdate = new SQLFactory(this, "促销方案反审核");
- sqlFactoryupdate.addParameter("siteid", siteid);
- sqlFactoryupdate.addParameter("sa_promotionid", sa_promotionid);
- sqlFactoryupdate.addParameter("checkby", username);
- sqlList.add(sqlFactoryupdate.getSQL());
- sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "反审核", "促销方案反审核成功").getSQL());
- dbConnect.runSqlUpdate(sqlList);
- return getSucReturnObject().toString();
- }
- @API(title = "发布反发布", apiversion = R.ID20221230145203.v1.class)
- @CACHEING_CLEAN(apiversions = {R.ID20221230144703.v1.class, R.ID20221230144803.v1.class, R.ID20220103140003.v1.class})
- public String recheck() throws YosException {
- Long sa_promotionid = content.getLong("sa_promotionid");
- boolean isrecheck = content.getBooleanValue("isrecheck");
- Rows rows = dbConnect
- .runSqlQuery("select sa_promotionid,status,promnum from sa_promotion where sa_promotionid ='"
- + sa_promotionid + "' and siteid='" + siteid + "'");
- for (Row row : rows) {
- if (isrecheck) {
- if (!row.getString("status").equals("审核")) {
- return getErrReturnObject().setErrMsg("单号为:【" + row.getString("promnum") + "】的促销方案为非审核状态,无法发布")
- .toString();
- }
- } else {
- if (!row.getString("status").equals("发布")) {
- return getErrReturnObject().setErrMsg("单号为:【" + row.getString("promnum") + "】的促销方案为非发布状态,无法反发布")
- .toString();
- }
- }
- }
- ArrayList<String> sqlList = new ArrayList<>();
- SQLFactory sqlFactoryupdate;
- if (isrecheck) {
- sqlFactoryupdate = new SQLFactory(this, "促销方案发布");
- sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "发布", "促销方案发布成功").getSQL());
- } else {
- sqlFactoryupdate = new SQLFactory(this, "促销方案反发布");
- sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "反发布", "促销方案反发布成功").getSQL());
- }
- sqlFactoryupdate.addParameter("siteid", siteid);
- sqlFactoryupdate.addParameter("sa_promotionid", sa_promotionid);
- sqlFactoryupdate.addParameter("sendby", username);
- sqlList.add(sqlFactoryupdate.getSQL());
- dbConnect.runSqlUpdate(sqlList);
- return getSucReturnObject().toString();
- }
- @API(title = "关闭反关闭", apiversion = R.ID20230102095403.v1.class)
- @CACHEING_CLEAN(apiversions = {R.ID20221230144703.v1.class, R.ID20221230144803.v1.class, R.ID20220103140003.v1.class})
- public String close() throws YosException {
- Long sa_promotionid = content.getLong("sa_promotionid");
- boolean isclose = content.getBooleanValue("isclose");
- Rows rows = dbConnect
- .runSqlQuery("select sa_promotionid,status,promnum from sa_promotion where sa_promotionid ='"
- + sa_promotionid + "' and siteid='" + siteid + "'");
- for (Row row : rows) {
- if (isclose) {
- if (!row.getString("status").equals("发布")) {
- return getErrReturnObject().setErrMsg("单号为:【" + row.getString("promnum") + "】的促销方案为非发布状态,无法关闭")
- .toString();
- }
- } else {
- if (!row.getString("status").equals("关闭")) {
- return getErrReturnObject().setErrMsg("单号为:【" + row.getString("promnum") + "】的促销方案为非关闭状态,无法反关闭")
- .toString();
- }
- }
- }
- ArrayList<String> sqlList = new ArrayList<>();
- SQLFactory sqlFactoryupdate;
- if (isclose) {
- sqlFactoryupdate = new SQLFactory(this, "促销方案关闭");
- sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "关闭", "促销方案关闭成功").getSQL());
- } else {
- sqlFactoryupdate = new SQLFactory(this, "促销方案反关闭");
- sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "反关闭", "促销方案反关闭成功").getSQL());
- }
- sqlFactoryupdate.addParameter("siteid", siteid);
- sqlFactoryupdate.addParameter("sa_promotionid", sa_promotionid);
- sqlFactoryupdate.addParameter("closeby", username);
- sqlList.add(sqlFactoryupdate.getSQL());
- dbConnect.runSqlUpdate(sqlList);
- return getSucReturnObject().toString();
- }
- @API(title = "切换授权方式", apiversion = R.ID20230509100504.v1.class)
- @CACHEING_CLEAN(apiversions = {R.ID20221230144703.v1.class, R.ID20220103140003.v1.class})
- public String updateAuthMethod() throws YosException {
- Long sa_promotionid = content.getLong("sa_promotionid");
- Rows rows = dbConnect.runSqlQuery("select sa_promotionid,status,authmethod from sa_promotion where sa_promotionid ='" + sa_promotionid + "' and siteid='" + siteid + "'");
- if (rows.isEmpty()) {
- return getErrReturnObject().setErrMsg("无效促销方案").toString();
- }
- if (!rows.get(0).getString("status").equals("新建")) {
- return getErrReturnObject().setErrMsg("非新建状态不能修改授权方式").toString();
- }
- if (dbConnect.runSqlQuery("select * from sa_promotion_auth where siteid='" + siteid + "' and sa_promotionid=" + sa_promotionid).isNotEmpty()) {
- return getErrReturnObject().setErrMsg("已有授权经销商,无法更改授权方式").toString();
- }
- ArrayList<String> sqlList = new ArrayList<>();
- sqlList.add("delete from sa_promotion_auth where siteid='" + siteid + "' and sa_promotionid=" + sa_promotionid);
- if (rows.get(0).getLong("authmethod") == 0) {
- sqlList.add("update sa_promotion set authmethod=1 where siteid='" + siteid + "' and sa_promotionid=" + sa_promotionid);
- } else {
- sqlList.add("update sa_promotion set authmethod=0 where siteid='" + siteid + "' and sa_promotionid=" + sa_promotionid);
- }
- dbConnect.runSqlUpdate(sqlList);
- return getSucReturnObject().toString();
- }
- @API(title = "结算", apiversion = R.ID20230826091303.v1.class)
- @CACHEING_CLEAN(apiClass = {promotionAuth.class,promotion.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 deleted!=1 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,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();
- }
- }
|