|
|
@@ -1,13 +1,12 @@
|
|
|
package restcontroller.crm.agent.custorder;
|
|
|
|
|
|
+import beans.datateam.DataTeam;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import common.Controller;
|
|
|
import common.YosException;
|
|
|
import common.annotation.API;
|
|
|
-import common.data.InsertSQL;
|
|
|
-import common.data.SQLDump;
|
|
|
-import common.data.SQLFactory;
|
|
|
-import common.data.UpdateSQL;
|
|
|
+import common.annotation.Param;
|
|
|
+import common.data.*;
|
|
|
import restcontroller.R;
|
|
|
|
|
|
@API(title = "美大CRM_经销商_客户订单管理")
|
|
|
@@ -16,61 +15,113 @@ public class Custorder extends Controller {
|
|
|
super(content);
|
|
|
}
|
|
|
|
|
|
- @API(title = "美大CRM_经销商_客户订单新增修改", apiversion = R.ID2026031309441701.v1.class)
|
|
|
+ @API(title = "美大CRM_经销商_客户订单列表查询", apiversion = R.ID2026031410293201.v1.class)
|
|
|
+ public String sa_custorder_querylist() throws YosException {
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_custorder", "sa_custorderid", // C端订单ID
|
|
|
+ "siteid", // 站点
|
|
|
+ "billdate", // 开单日期
|
|
|
+ "sa_customersid", // 客户档案ID
|
|
|
+ "sa_storeid", // 门店表ID
|
|
|
+ "ispaid", // 付款状态
|
|
|
+ "amount", // 金额(元)
|
|
|
+ "payamount",//已收款金额
|
|
|
+ "qty", // 数量
|
|
|
+ "remarks", // 备注说明
|
|
|
+ "status", // 状态
|
|
|
+ "sys_enterpriseid", // 合作企业档案ID
|
|
|
+ "sonum", // 订单编号
|
|
|
+ "createby", // 创建人
|
|
|
+ "createdate", // 创建时间
|
|
|
+ "changeby", // 修改人
|
|
|
+ "changedate" // 修改时间
|
|
|
+ ).setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sa_customers", "t2", "t1.sa_customersid=t2.sa_customersid", "name", "phonenumber", "address");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sa_store", "t3", "t1.sa_storeid=t3.sa_storeid", "storeno", "storename");
|
|
|
+
|
|
|
+ querySQL.setWhere("sys_enterpriseid", sys_enterpriseid);
|
|
|
+ if (userInfo.getEnterprise_HrRow().getBoolean("storedatalimit")) {
|
|
|
+ querySQL.setWhere("sa_storeid", userInfo.getStoreID());
|
|
|
+ }
|
|
|
+ if (userInfo.getEnterprise_HrRow().getBoolean("userdatalimit")) {
|
|
|
+ querySQL.setDataTeamLimit(DataTeam.FilterType.MyLeader);
|
|
|
+ }
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setPage(pageSize, pageNumber);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+
|
|
|
+ RowsMap leaderRowsMap = DataTeam.getLeader(this, "sa_customers", rows.toArrayList("sa_customersid")).toRowsMap("ownerid");
|
|
|
+ for (Row row : rows) {
|
|
|
+ if (leaderRowsMap.containsKey(row.getString("sa_customersid"))) {
|
|
|
+ row.put("leader", leaderRowsMap.get(row.getString("sa_customersid")).get(0).getString("name"));
|
|
|
+ } else {
|
|
|
+ row.put("leader", "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "美大CRM_经销商_客户订单详情查询", apiversion = R.ID2026031414384501.v1.class, params = {@Param(paramname = "sa_custorderid", fieldtype = FieldType.BigInt)})
|
|
|
+ public String sa_custorder_querymain() throws YosException {
|
|
|
+ long sa_custorderid = content.getLongValue("sa_custorderid");
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_custorder", "sa_custorderid", // C端订单ID
|
|
|
+ "siteid", // 站点
|
|
|
+ "billdate", // 开单日期
|
|
|
+ "sa_customersid", // 客户档案ID
|
|
|
+ "sa_storeid", // 门店表ID
|
|
|
+ "ispaid", // 付款状态
|
|
|
+ "amount", // 金额(元)
|
|
|
+ "payamount",//已收款金额
|
|
|
+ "qty", // 数量
|
|
|
+ "remarks", // 备注说明
|
|
|
+ "status", // 状态
|
|
|
+ "sys_enterpriseid", // 合作企业档案ID
|
|
|
+ "sonum", // 订单编号
|
|
|
+ "createby", // 创建人
|
|
|
+ "createdate", // 创建时间
|
|
|
+ "changeby", // 修改人
|
|
|
+ "changedate" // 修改时间
|
|
|
+ ).setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sa_customers", "t2", "t1.sa_customersid=t2.sa_customersid", "name", "phonenumber", "address", "community");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sa_store", "t3", "t1.sa_storeid=t3.sa_storeid", "storeno", "storename");
|
|
|
+ querySQL.setWhere("sys_enterpriseid", sys_enterpriseid);
|
|
|
+ querySQL.setUniqueid(sa_custorderid);
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ RowsMap leaderRowsMap = DataTeam.getLeader(this, "sa_customers", rows.toArrayList("sa_customersid")).toRowsMap("ownerid");
|
|
|
+ for (Row row : rows) {
|
|
|
+ if (leaderRowsMap.containsKey(row.getString("sa_customersid"))) {
|
|
|
+ row.put("leader", leaderRowsMap.get(row.getString("sa_customersid")).get(0).getString("name"));
|
|
|
+ } else {
|
|
|
+ row.put("leader", "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "美大CRM_经销商_客户订单新增修改", apiversion = R.ID2026031309441701.v1.class, params = {@Param(paramname = "sa_custorderid", remarks = "订单ID,修改时必填", fieldtype = FieldType.BigInt, isrequired = false), @Param(paramname = "sa_customersid", remarks = "客户ID,新增时必填", fieldtype = FieldType.BigInt), @Param(paramname = "remarks", remarks = "备注说明", fieldtype = FieldType.Varchar, isrequired = false), @Param(paramname = "billdate", remarks = "开单日期", fieldtype = FieldType.Date, isrequired = false)})
|
|
|
public String sa_custorder_save() throws YosException {
|
|
|
long sa_custorderid = content.getLongValue("sa_custorderid");
|
|
|
- long sa_storeid = content.getLongValue("sa_storeid");// 门店表ID
|
|
|
- long rec_contactsid = content.getLongValue("rec_contactsid");// 合作企业联系人表ID
|
|
|
- boolean ispaid = content.getBooleanValue("ispaid");// 付款状态
|
|
|
- String out_refund_no = content.getStringValue("out_refund_no");// 商户退款单号
|
|
|
- String wechatpayorder = content.getStringValue("wechatpayorder");// 微信支付订单查询结果
|
|
|
- boolean deleted = content.getBooleanValue("deleted");// 删除状态
|
|
|
- String phonenumber = content.getStringValue("phonenumber");// 联系电话
|
|
|
- String name = content.getStringValue("name");// 客户名称
|
|
|
- double amount = content.getDoubleValue("amount");// 金额(元)
|
|
|
- String paytime = content.getStringValue("paytime");// 付费时间
|
|
|
- String remarks = content.getStringValue("remarks");// 订单日志
|
|
|
- String paymode = content.getStringValue("paymode");// 付款方式
|
|
|
- String status = content.getStringValue("status");// 状态
|
|
|
- long sys_enterpriseid = content.getLongValue("sys_enterpriseid");// 合作企业档案ID
|
|
|
- String sonum = content.getStringValue("sonum");// 订单编号
|
|
|
+ String remarks = content.getStringValue("remarks");// 备注说明
|
|
|
+ String billdate = content.getStringValue("billdate");// 开单日期
|
|
|
+ Rows sa_custorderRow = SQLFactory.createQuerySQL(this, "sa_custorder", "sa_custorderid").setSiteid(siteid).setUniqueid(sa_custorderid).query();
|
|
|
SQLDump sqldump = new SQLDump();
|
|
|
- if (sa_custorderid <= 0 || SQLFactory.createQuerySQL(this, "sa_custorder", "sa_custorderid").setSiteid(siteid).setUniqueid(sa_custorderid).query().isEmpty()) {
|
|
|
+ if (sa_custorderid == 0 || sa_custorderRow.isEmpty()) {
|
|
|
+ long sa_customersid = content.getLong("sa_customersid");//客户ID
|
|
|
InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_custorder");
|
|
|
+ insertSQL.setValue("sonum", createBillCode("custorder"));// 订单编号
|
|
|
insertSQL.setValue("siteid", siteid);// 站点
|
|
|
- insertSQL.setValue("sa_storeid", sa_storeid);// 门店表ID
|
|
|
- insertSQL.setValue("rec_contactsid", rec_contactsid);// 合作企业联系人表ID
|
|
|
- insertSQL.setValue("ispaid", ispaid);// 付款状态
|
|
|
- insertSQL.setValue("out_refund_no", out_refund_no);// 商户退款单号
|
|
|
- insertSQL.setValue("wechatpayorder", wechatpayorder);// 微信支付订单查询结果
|
|
|
- insertSQL.setValue("deleted", deleted);// 删除状态
|
|
|
- insertSQL.setValue("phonenumber", phonenumber);// 联系电话
|
|
|
- insertSQL.setValue("name", name);// 客户名称
|
|
|
- insertSQL.setValue("amount", amount);// 金额(元)
|
|
|
- insertSQL.setValue("paytime", paytime);// 付费时间
|
|
|
- insertSQL.setValue("remarks", remarks);// 订单日志
|
|
|
- insertSQL.setValue("paymode", paymode);// 付款方式
|
|
|
- insertSQL.setValue("status", status);// 状态
|
|
|
+ insertSQL.setValue("sa_storeid", userInfo.getStoreID());// 门店表ID
|
|
|
+ insertSQL.setValue("remarks", remarks);// 备注说明
|
|
|
+ insertSQL.setValue("billdate", billdate);// 开单日期
|
|
|
+ insertSQL.setValue("status", "待出库");// 状态
|
|
|
+ insertSQL.setValue("ispaid", 0);// 付款状态,待付款
|
|
|
insertSQL.setValue("sys_enterpriseid", sys_enterpriseid);// 合作企业档案ID
|
|
|
- insertSQL.setValue("sonum", sonum);// 订单编号
|
|
|
+ insertSQL.setValue("sa_customersid", sa_customersid);// 合作企业档案ID
|
|
|
sqldump.add(insertSQL);
|
|
|
} else {
|
|
|
UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_custorder");
|
|
|
- updateSQL.setValue("sa_storeid", sa_storeid);// 门店表ID
|
|
|
- updateSQL.setValue("rec_contactsid", rec_contactsid);// 合作企业联系人表ID
|
|
|
- updateSQL.setValue("ispaid", ispaid);// 付款状态
|
|
|
- updateSQL.setValue("out_refund_no", out_refund_no);// 商户退款单号
|
|
|
- updateSQL.setValue("wechatpayorder", wechatpayorder);// 微信支付订单查询结果
|
|
|
- updateSQL.setValue("deleted", deleted);// 删除状态
|
|
|
- updateSQL.setValue("phonenumber", phonenumber);// 联系电话
|
|
|
- updateSQL.setValue("name", name);// 客户名称
|
|
|
- updateSQL.setValue("amount", amount);// 金额(元)
|
|
|
- updateSQL.setValue("paytime", paytime);// 付费时间
|
|
|
- updateSQL.setValue("remarks", remarks);// 订单日志
|
|
|
- updateSQL.setValue("paymode", paymode);// 付款方式
|
|
|
- updateSQL.setValue("status", status);// 状态
|
|
|
- updateSQL.setValue("sys_enterpriseid", sys_enterpriseid);// 合作企业档案ID
|
|
|
- updateSQL.setValue("sonum", sonum);// 订单编号
|
|
|
+ updateSQL.setValue("remarks", remarks);// 备注说明
|
|
|
+ updateSQL.setValue("billdate", billdate);// 开单日期
|
|
|
updateSQL.setSiteid(siteid);
|
|
|
updateSQL.setUniqueid(sa_custorderid);
|
|
|
sqldump.add(updateSQL);
|
|
|
@@ -79,5 +130,120 @@ public class Custorder extends Controller {
|
|
|
return getSucReturnObject().toString();
|
|
|
}
|
|
|
|
|
|
+ @API(title = "美大CRM_经销商_客户订单删除", apiversion = R.ID2026031414454901.v1.class, params = {@Param(paramname = "sa_custorderid", fieldtype = FieldType.BigInt)})
|
|
|
+ public String sa_custorder_delete() throws YosException {
|
|
|
+ long sa_custorderid = content.getLongValue("sa_custorderid");
|
|
|
+ SQLDump sqldump = new SQLDump();
|
|
|
+ sqldump.add(SQLFactory.createDeleteSQL(this, "sa_custorder").setUniqueid(sa_custorderid));
|
|
|
+ sqldump.add(SQLFactory.createDeleteSQL(this, "sa_custorderitems").setWhere("sa_custorderid", sa_custorderid));
|
|
|
+ sqldump.commit();
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "美大CRM_经销商_客户订单退单", apiversion = R.ID2026031416194201.v1.class)
|
|
|
+ public String sa_custorder_void() throws YosException {
|
|
|
+ long sa_custorderid = content.getLongValue("sa_custorderid");
|
|
|
+ String voidreason = content.getString("voidreason");
|
|
|
+ SQLFactory.createUpdateSQL(this, "sa_custorder").setValue("status", "已退单").setValue("voidreason", voidreason).setUniqueid(sa_custorderid).update();
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "美大CRM_经销商_客户订单商品明细查询", apiversion = R.ID2026031414243401.v1.class, params = {@Param(paramname = "sa_custorderid", fieldtype = FieldType.BigInt)})
|
|
|
+ public String sa_custorderitems_querylist() throws YosException {
|
|
|
+ long sa_custorderid = content.getLong("sa_custorderid");
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_custorderitems", "*").setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t2", "t1.unitid=t2.unitid", "unitname");
|
|
|
+ querySQL.setWhere("sa_custorderid", sa_custorderid);
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setPage(pageSize, pageNumber);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
|
|
|
+ @API(title = "美大CRM_经销商_客户订单商品明细新增修改", apiversion = R.ID2026031415462301.v1.class, params = {@Param(paramname = "sa_custorderid", fieldtype = FieldType.BigInt), @Param(paramname = "sa_custorderitemsid", fieldtype = FieldType.BigInt), @Param(paramname = "sys_enterprise_itemid", remarks = "企业商品ID", fieldtype = FieldType.BigInt), @Param(paramname = "qty", remarks = "数量", fieldtype = FieldType.Decimal), @Param(paramname = "oldprice", remarks = "原价(元)", fieldtype = FieldType.Decimal), @Param(paramname = "discountrate", remarks = "折扣%", fieldtype = FieldType.Decimal), @Param(paramname = "price", remarks = "单价(元)", fieldtype = FieldType.Decimal), @Param(paramname = "amount", remarks = "金额(元)", fieldtype = FieldType.Decimal)})
|
|
|
+ public String sa_custorderitems_save() throws YosException {
|
|
|
+ long sa_custorderid = content.getLong("sa_custorderid");// 订单ID
|
|
|
+ long sa_custorderitemsid = content.getLongValue("sa_custorderitemsid");
|
|
|
+ double qty = content.getDoubleValue("qty");// 数量
|
|
|
+ double price = content.getDoubleValue("price");// 单价(元)
|
|
|
+ double amount = content.getDoubleValue("amount");// 金额(元)
|
|
|
+ double discountrate = content.getDoubleValue("discountrate");// 折扣%
|
|
|
+
|
|
|
+ SQLDump sqldump = new SQLDump();
|
|
|
+ if (sa_custorderitemsid <= 0 || SQLFactory.createQuerySQL(this, "sa_custorderitems", "sa_custorderitemsid").setSiteid(siteid).setUniqueid(sa_custorderitemsid).query().isEmpty()) {
|
|
|
+ long sys_enterprise_itemid = content.getLongValue("sys_enterprise_itemid");// 企业商品档案表ID
|
|
|
+ double oldprice = content.getDoubleValue("oldprice");// 原单价(元)
|
|
|
+
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_custorderitems");
|
|
|
+ insertSQL.setValue("siteid", siteid);// 站点
|
|
|
+ insertSQL.setValue("sa_custorderid", sa_custorderid);// C端订单ID
|
|
|
+ insertSQL.setValue("sys_enterprise_itemid", sys_enterprise_itemid);// 企业商品档案表ID
|
|
|
+ insertSQL.setValue("qty", qty);// 数量
|
|
|
+ insertSQL.setValue("oldprice", oldprice);// 原单价(元)
|
|
|
+ insertSQL.setValue("discountrate", discountrate);// 折扣%
|
|
|
+ insertSQL.setValue("price", price);// 单价(元)
|
|
|
+ insertSQL.setValue("amount", amount);// 金额(元)
|
|
|
+
|
|
|
+ Rows sys_enterprise_itemRows = SQLFactory.createQuerySQL(this, "sys_enterprise_item", "unitid").setWhere("sys_enterprise_itemid", sys_enterprise_itemid).query();
|
|
|
+ if (sys_enterprise_itemRows.isEmpty()) {
|
|
|
+ return getErrReturnObject().setErrMsg("未找到商品档案信息").toString();
|
|
|
+ }
|
|
|
+ long unitid = sys_enterprise_itemRows.get(0).getLong("unitid");
|
|
|
+ String spec = sys_enterprise_itemRows.get(0).getString("spec");
|
|
|
+ String itemno = sys_enterprise_itemRows.get(0).getString("itemno");
|
|
|
+ String model = sys_enterprise_itemRows.get(0).getString("model");
|
|
|
+ String itemname = sys_enterprise_itemRows.get(0).getString("itemname");
|
|
|
+
|
|
|
+ insertSQL.setValue("itemno", itemno);// 商品编号
|
|
|
+ insertSQL.setValue("itemname", itemname);// 产品名称
|
|
|
+ insertSQL.setValue("model", model);// 型号
|
|
|
+ insertSQL.setValue("spec", spec);// 尺寸
|
|
|
+ insertSQL.setValue("unitid", unitid);// 单位
|
|
|
+ sqldump.add(insertSQL);
|
|
|
+ } else {
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_custorderitems");
|
|
|
+ updateSQL.setValue("qty", qty);// 数量
|
|
|
+ updateSQL.setValue("discountrate", discountrate);// 折扣%
|
|
|
+ updateSQL.setValue("price", price);// 单价(元)
|
|
|
+ updateSQL.setValue("amount", amount);// 金额(元)
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setWhere("sa_custorderid", sa_custorderid);
|
|
|
+ updateSQL.setUniqueid(sa_custorderitemsid);
|
|
|
+ sqldump.add(updateSQL);
|
|
|
+ }
|
|
|
+ sqldump.commit();
|
|
|
+ updateOrderHeadData(sa_custorderid);
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "美大CRM_经销商_客户订单商品明细删除", apiversion = R.ID2026031416083401.v1.class,
|
|
|
+ params = {
|
|
|
+ @Param(paramname = "sa_custorderid", fieldtype = FieldType.BigInt),
|
|
|
+ @Param(paramname = "sa_custorderitemsid", fieldtype = FieldType.BigInt)
|
|
|
+ })
|
|
|
+ public String sa_custorderitems_delete() throws YosException {
|
|
|
+ long sa_custorderid = content.getLongValue("sa_custorderid");
|
|
|
+ long sa_custorderitemsid = content.getLongValue("sa_custorderitemsid");
|
|
|
+ SQLFactory.createDeleteSQL(this, "sa_custorderitems").setWhere("sa_custorderid", sa_custorderid).setUniqueid(sa_custorderitemsid).delete();
|
|
|
+ updateOrderHeadData(sa_custorderid);
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新订单表头金额数量
|
|
|
+ *
|
|
|
+ * @param sa_custorderid
|
|
|
+ * @throws YosException
|
|
|
+ */
|
|
|
+ public void updateOrderHeadData(long sa_custorderid) throws YosException {
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_custorderitems");
|
|
|
+ querySQL.addQueryFields("qty", "ifnull(sum(qty),0)");
|
|
|
+ querySQL.addQueryFields("amount", "ifnull(sum(amount),0)");
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ if (rows.isNotEmpty()) {
|
|
|
+ double qty = rows.get(0).getDouble("qty");
|
|
|
+ double amount = rows.get(0).getDouble("amount");
|
|
|
+ SQLFactory.createUpdateSQL(this, "sa_custorder").setValue("qty", qty).setValue("amount", amount).setUniqueid(sa_custorderid).update();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|