|
|
@@ -0,0 +1,181 @@
|
|
|
+package restcontroller.crm.agent.customer;
|
|
|
+
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import common.Controller;
|
|
|
+import common.YosException;
|
|
|
+import common.annotation.API;
|
|
|
+import common.data.*;
|
|
|
+import restcontroller.R;
|
|
|
+
|
|
|
+@API(title = "美大CRM_经销商_客户管理")
|
|
|
+public class Customer extends Controller {
|
|
|
+ public Customer(JSONObject content) throws YosException {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "美大CRM_经销商_客户档案列表查询", apiversion = R.ID2026030916100201.v1.class)
|
|
|
+ public String sa_customers_querylist() throws YosException {
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_customers", "*").setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sv_agents", "t2", "t1.sa_agentsid=t2.sa_agentsid", "agentnum", "enterprisename");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sv_agents", "t3", "t1.sa_agentsid_to=t3.sa_agentsid", "agentnum_to", "enterprisename_to");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sa_store", "t4", "t1.sa_storeid=t4.sa_storeid", "storeno", "storename");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sys_datateam", "t5", "t1.sa_customersid=t5.ownerid and t5.ownertable='sa_customers'");
|
|
|
+ querySQL.addQueryFields("saler", "ifnull(t5.name,'')");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setPage(pageSize, pageNumber);
|
|
|
+ querySQL.setWhere("t2.sys_enterpriseid=" + sys_enterpriseid + " or t3.sys_enterpriseid=" + sys_enterpriseid);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "美大CRM_经销商_客户档案详情查询", apiversion = R.ID2026030916272601.v1.class)
|
|
|
+ public String sa_customers_querymain() throws YosException {
|
|
|
+ long sa_customersid = content.getLong("sa_customersid");
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_customers", "*").setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sv_agents", "t2", "t1.sa_agentsid=t2.sa_agentsid", "agentnum", "enterprisename");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sv_agents", "t3", "t1.sa_agentsid_to=t3.sa_agentsid", "agentnum_to", "enterprisename_to");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sa_store", "t4", "t1.sa_storeid=t4.sa_storeid", "storeno", "storename");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sys_datateam", "t5", "t1.sa_customersid=t5.ownerid and t5.ownertable='sa_customers'");
|
|
|
+ querySQL.addQueryFields("saler", "ifnull(t5.name,'')");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setUniqueid(sa_customersid);
|
|
|
+ querySQL.setWhere("t2.sys_enterpriseid=" + sys_enterpriseid + " or t3.sys_enterpriseid=" + sys_enterpriseid);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "美大CRM_经销商_客户档案新增修改", apiversion = R.ID2026030916370001.v1.class)
|
|
|
+ public String sa_customers_save() throws YosException {
|
|
|
+ long sa_customersid = content.getLongValue("sa_customersid");
|
|
|
+ String name = content.getStringValue("name");// 客户名称
|
|
|
+ String phonenumber = content.getStringValue("phonenumber");// 联系电话
|
|
|
+ String sex = content.getStringValue("sex");// 性别
|
|
|
+ String community = content.getStringValue("community");//小区及门牌号
|
|
|
+ String address = content.getStringValue("address");// 详细地址
|
|
|
+ String province = content.getStringValue("province");// 省份
|
|
|
+ String city = content.getStringValue("city");// 城市
|
|
|
+ String county = content.getStringValue("county");// 区县
|
|
|
+ String ext_no = content.getStringValue("ext_no");//外部订单号
|
|
|
+ String birthday = content.getStringValue("birthday");//生日
|
|
|
+ String source = content.getStringValue("source");// 客户来源
|
|
|
+ String remarks = content.getStringValue("remarks");// 备注
|
|
|
+
|
|
|
+ SQLDump sqldump = new SQLDump();
|
|
|
+
|
|
|
+ Rows sa_customersRows = SQLFactory.createQuerySQL(this, "sa_customers", "sa_customersid").setSiteid(siteid).setUniqueid(sa_customersid).query();
|
|
|
+ if (sa_customersid <= 0 || sa_customersRows.isEmpty()) {
|
|
|
+ long sat_orderclueid = content.getLongValue("sat_orderclueid");// 关联数据id
|
|
|
+ long sa_agentsid = userInfo.getAgentID();
|
|
|
+
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "≈");
|
|
|
+ insertSQL.setValue("siteid", siteid);// 站点ID
|
|
|
+ insertSQL.setValue("sa_agentsid_to", sa_agentsid);// 授权经销商
|
|
|
+ insertSQL.setValue("sa_agentsid", sa_agentsid);// 归属经销商表ID
|
|
|
+ insertSQL.setValue("name", name);// 客户名称
|
|
|
+ insertSQL.setValue("phonenumber", phonenumber);// 联系电话
|
|
|
+ insertSQL.setValue("province", province);// 省份
|
|
|
+ insertSQL.setValue("city", city);// 城市
|
|
|
+ insertSQL.setValue("county", county);// 区县
|
|
|
+ insertSQL.setValue("address", address);// 详细地址
|
|
|
+ insertSQL.setValue("custnum", createBillCode("customer"));// 客户编号
|
|
|
+ insertSQL.setValue("sys_enterpriseid", sys_enterpriseid);// 合作企业档案ID
|
|
|
+ insertSQL.setValue("status", "意向");// 客户状态
|
|
|
+ insertSQL.setValue("sex", sex);// 性别
|
|
|
+ insertSQL.setValue("community", community);// 小区及门牌号
|
|
|
+ insertSQL.setValue("ext_no", ext_no);// 外部订单号
|
|
|
+ insertSQL.setValue("birthday", birthday.isBlank() ? null : birthday);// 生日
|
|
|
+ insertSQL.setValue("remarks", remarks);// 备注
|
|
|
+ insertSQL.setValue("source", source);// 客户来源
|
|
|
+ if (sat_orderclueid > 0) {
|
|
|
+ insertSQL.setValue("sourcetable", "sat_orderclue");// 关联数据表
|
|
|
+ insertSQL.setValue("sourceid", sat_orderclueid);// 关联数据id
|
|
|
+ insertSQL.setValue("source", "线索转化");// 客户来源
|
|
|
+ }
|
|
|
+ sqldump.add(insertSQL);
|
|
|
+ } else {
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_customers");
|
|
|
+ updateSQL.setValue("name", name);// 客户名称
|
|
|
+ updateSQL.setValue("phonenumber", phonenumber);// 联系电话
|
|
|
+ updateSQL.setValue("sex", sex);// 性别
|
|
|
+ updateSQL.setValue("province", province);// 省份
|
|
|
+ updateSQL.setValue("city", city);// 城市
|
|
|
+ updateSQL.setValue("county", county);// 区县
|
|
|
+ updateSQL.setValue("address", address);// 详细地址
|
|
|
+ updateSQL.setValue("community", community);// 小区及门牌号
|
|
|
+ updateSQL.setValue("ext_no", ext_no);// 外部订单号
|
|
|
+ updateSQL.setValue("birthday", birthday.isBlank() ? null : birthday);// 生日
|
|
|
+ updateSQL.setValue("remarks", remarks);// 备注
|
|
|
+ if (!"sat_orderclue".equals(sa_customersRows.get(0).getString("sourcetable"))) {
|
|
|
+ updateSQL.setValue("source", source);// 客户来源
|
|
|
+ }
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setUniqueid(sa_customersid);
|
|
|
+ sqldump.add(updateSQL);
|
|
|
+ }
|
|
|
+ sqldump.commit();
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "美大CRM_经销商_客户档案订单列表查询", apiversion = R.ID2026030916334801.v1.class)
|
|
|
+ public String sa_custorder_querylist() throws YosException {
|
|
|
+ long sa_customersid = content.getLong("sa_customersid");
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_custorder");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere("sa_customersid", sa_customersid);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "美大CRM_经销商_客户档案订单列表商品明细查询", apiversion = R.ID2026030916340501.v1.class)
|
|
|
+ public String sa_custorderitems_querylist() throws YosException {
|
|
|
+ long sa_custorderid = content.getLong("sa_custorderid");
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_custorderitems");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere("sa_custorderid", sa_custorderid);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "美大CRM_经销商_客户档案服务申请单查询", apiversion = R.ID2026030916342701.v1.class)
|
|
|
+ public String sa_serviceorder_querylist() throws YosException {
|
|
|
+ long sa_customersid = content.getLong("sa_customersid");
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_serviceorder");
|
|
|
+ querySQL.setWhere("sa_customersid", sa_customersid);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "美大CRM_经销商_客户档案服务工单查询", apiversion = R.ID2026030916343601.v1.class)
|
|
|
+ public String sa_workorder_querylist() throws YosException {
|
|
|
+ long sa_serviceorderid = content.getLong("sa_serviceorderid");
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_workorder");
|
|
|
+ querySQL.setWhere("sa_serviceorderid", sa_serviceorderid);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "美大CRM_经销商_客户档案保修卡列表查询", apiversion = R.ID2026030916344401.v1.class)
|
|
|
+ public String sa_warrantycard_querylist() throws YosException {
|
|
|
+ long sa_customersid = content.getLong("sa_customersid");
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_warrantycard").setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t2", "t1.itemid=t2.itemid", "itemname", "model", "spec");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere("sa_customersid", sa_customersid);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "美大CRM_经销商_客户档案删除", apiversion = R.ID2026031009560201.v1.class)
|
|
|
+ public String sa_customers_delete() throws YosException {
|
|
|
+ long sa_customersid = content.getLong("sa_customersid");
|
|
|
+ Rows sa_customersRows = SQLFactory.createQuerySQL(this, "sa_customers", "status").setSiteid(siteid).setUniqueid(sa_customersid).query();
|
|
|
+ if (sa_customersRows.isNotEmpty()) {
|
|
|
+ if ("意向".equals(sa_customersRows.get(0).getString("status"))) {
|
|
|
+ SQLFactory.createDeleteSQL(this, "sa_customers").setUniqueid(sa_customersid).delete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|