wangxingcheng 3 лет назад
Родитель
Сommit
669fcd5b6c

+ 14 - 1
opms_parent/app/handler/base/district.go

@@ -11,7 +11,7 @@ import (
 
 type DistrictHandler struct{}
 
-//GetList 区域列表
+//GetList 所有区域列表
 func (d *DistrictHandler) GetList(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
 	districtServer, err := server.NewDistrictService(ctx)
 	if err != nil {
@@ -19,6 +19,19 @@ func (d *DistrictHandler) GetList(ctx context.Context, req *comm_def.IdReq, rsp
 		return err
 	}
 	list := districtServer.ListToTree(int(req.Id))
+	g.Log().Info("ID", req.Id)
+	rsp.Data = g.Map{"list": list}
+	return nil
+}
+
+//返回所有省份的
+func (d *DistrictHandler) GetProvinceInfo(ctx context.Context, null, rsp *comm_def.CommonMsg) error {
+	districtServer, err := server.NewDistrictService(ctx)
+	if err != nil {
+		g.Log().Error(err)
+		return err
+	}
+	list := districtServer.GetProvinceInfo()
 	rsp.Data = g.Map{"list": list}
 	return nil
 }

+ 34 - 0
opms_parent/app/handler/cust/contant.go

@@ -0,0 +1,34 @@
+package cust
+
+import (
+	"context"
+
+	"dashoo.cn/common_definition/comm_def"
+	"dashoo.cn/opms_libary/myerrors"
+	"github.com/gogf/gf/frame/g"
+	"github.com/gogf/gf/util/gvalid"
+
+	model "dashoo.cn/micro/app/model/cust"
+	server "dashoo.cn/micro/app/service/cust"
+)
+
+type CustomerContantHeader struct{}
+
+//创建客户联系人
+func (c *CustomerContantHeader) Create(ctx context.Context, req *model.CustCustomerContactSeq, rsp *comm_def.CommonMsg) error {
+	if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
+		return err
+	}
+	contactService, err := server.NewCustomerContactService(ctx)
+	if err != nil {
+		g.Log().Error(err)
+		return err
+	}
+	err = contactService.Create(req)
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+	if err != nil {
+		g.Log().Error(err)
+		return err
+	}
+	return nil
+}

+ 6 - 8
opms_parent/app/handler/cust/customer.go

@@ -33,12 +33,10 @@ func (c *CustomerHeader) GetList(ctx context.Context, req *model.CustCustomerSea
 
 }
 
-//创建客户信息
-func (c *CustomerHeader) Create(ctx context.Context, req *model.AddCustCustomerReq, rsp *comm_def.CommonMsg) error {
-	if err := gvalid.CheckStruct(ctx, req.Cust, nil); err != nil {
-		return err
-	}
-	if err := gvalid.CheckStruct(ctx, req.Info, nil); err != nil {
+//创建客户
+func (c *CustomerHeader) Create(ctx context.Context, req *model.Customer, rsp *comm_def.CommonMsg) error {
+	g.Log().Info("客户名称", req.CustName)
+	if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
 		return err
 	}
 	customerServer, err := server.NewCustomerService(ctx)
@@ -46,13 +44,13 @@ func (c *CustomerHeader) Create(ctx context.Context, req *model.AddCustCustomerR
 		g.Log().Error(err)
 		return err
 	}
-	err = customerServer.Create(req)
-	g.Log().Info("error", err)
+	id, err := customerServer.Create(req)
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
 		g.Log().Error(err)
 		return err
 	}
+	rsp.Data = g.Map{"list": id}
 	return nil
 }
 

+ 5 - 0
opms_parent/app/model/base/base_district.go

@@ -25,3 +25,8 @@ type T struct {
 	DistName string `json:"distName" `
 	Children []*T   `json:"children"`
 }
+type Province struct {
+	Id       int    `json:"id"`
+	ParentId int    `json:"parentId"`
+	DistName string `json:"distName" `
+}

+ 26 - 29
opms_parent/app/model/cust/cust_customer.go

@@ -17,12 +17,10 @@ type CustCustomer internal.CustCustomer
 // Fill with you ideas below.
 //列表搜索参数
 type CustCustomerSearchReq struct {
-	KeyWords   string `json:"custCode"`
-	CustName   string `json:"custName"`
-	CuctName   string `json:"cuctName"`
-	SalesName  string `json:"salesName"`
-	Telephone  string `json:"telePhone"`
-	CustStatus string `json:"custStatus"` //客户状态
+	CustCode string `json:"custCode"`
+	CustName string `json:"custName"`
+	IndusTry string `json:"indusTry"`
+	Level    string `json:"level"`
 	request.PageReq
 }
 
@@ -32,13 +30,19 @@ type AddCustCustomerReq struct {
 	Info *Information
 }
 
+// 单表添加客户信息表
 type Customer struct {
-	CustName     string `p:"custName"        json:"custName"   v:"required#客户名称不能为空"`
-	AbbrName     string `p:"abbrName"        json:"abbrName"   `     // 助计名
-	CustLocation string `p:"custLocation"    json:"custLocation"   ` // 所在地区
-	CustAddress  string `p:"custAddress"     json:"custAddress"   `  // 详细地址
-	SalesName    string `p:"salesName"       json:"salesName"   `    //
-	SalesId      string `p:"salesId"         json:"salesId"   `      //
+	CustName string `p:"custName"        json:"custName"   v:"required#客户名称不能为空"`
+	AbbrName string `p:"abbrName"        json:"abbrName"   ` // 助计名
+	//IndusTry     string      `p:"indusTry"        json:"indusTry"  v:"required#客户行业不能为空" ` //客户行业
+	//Level        string      `p:"level"        json:"level"  v:"required#客户级别不能为空" `
+	CustLocation string      `p:"custLocation"    json:"custLocation"    ` // 所在地区
+	CustAddress  string      `p:"custAddress"     json:"custAddress"   `   // 详细地址
+	FollowUpDate *gtime.Time `p:"followUpDate"     json:"followUpDate"   ` //跟进时间
+	Remark       string
+	//SalesName    string `p:"salesName"       json:"salesName"   `    //
+	//SalesId      string `p:"salesId"         json:"salesId"   `      //
+
 }
 
 //客户联系人信息
@@ -53,23 +57,16 @@ type Information struct {
 
 //返回信息
 type CustList struct {
-	Id           int                  `orm:"id,primary"     json:"id"`           // 主键
-	CustCode     string               `orm:"cust_code"      json:"custCode"`     // 客户编号
-	CustName     string               `orm:"cust_name"      json:"custName"`     // 客户名称
-	AbbrName     string               `orm:"abbr_name"      json:"abbrName"`     // 助记名
-	CustLocation string               `orm:"cust_location"  json:"custLocation"` // 所在地区
-	CustAddress  string               `orm:"cust_address"   json:"custAddress"`  // 详细地址
-	CustStatus   string               `orm:"cust_status"    json:"custStatus"`   // 客户状态(10正常20)
-	DeptId       int                  `orm:"dept_id"        json:"deptId"`       // 所属部门ID
-	DeptName     string               `orm:"dept_name"      json:"deptName"`     // 所属部门
-	SalesId      int                  `orm:"sales_id"       json:"salesId"`      // 所属销售ID
-	FollowUpDate *gtime.Time          `orm:"follow_up_date" json:"followUpDate"` // 最后跟进时间
-	Contact      *CustCustomerContact `orm:"with:cust_id=id"`
-	CuctName     string               `p:"cuctName"      json:"cuctName"`
-	TelePhone    string               `p:"telePhone"      json:"telePhone"`
-	DistName     string               `p:"distName"      json:"distName"`
-	DistLevel    string               `p:"distLevel"      json:"distLevel"` //商机评级
-	Product      string               `p:"product"      json:"product"`     //产品样品
+	Id           int         `orm:"id,primary"     json:"id"`           // 主键
+	CustCode     string      `orm:"cust_code"      json:"custCode"`     // 客户编号
+	CustName     string      `orm:"cust_name"      json:"custName"`     // 客户名称
+	AbbrName     string      `orm:"abbr_name"      json:"abbrName"`     // 助记名
+	CustLocation string      `orm:"cust_location"  json:"custLocation"` // 所在地区
+	CustAddress  string      `orm:"cust_address"   json:"custAddress"`  // 详细地址
+	CustStatus   string      `orm:"cust_status"    json:"custStatus"`   // 客户状态(10正常20)
+	FollowUpDate *gtime.Time `orm:"follow_up_date" json:"followUpDate"` // 最后跟进时间
+	IndusTry     string      `json:"indusTry"`
+	Level        string      `json:"level"`
 }
 
 //转移客户参数

+ 12 - 0
opms_parent/app/model/cust/cust_customer_contact.go

@@ -12,3 +12,15 @@ import (
 type CustCustomerContact internal.CustCustomerContact
 
 // Fill with you ideas below.
+//添加联系人参数
+type CustCustomerContactSeq struct {
+	CustId     int    `  json:"custId"      v:"required#客户ID不能为空" `              // 关联客户
+	CuctName   string `    json:"cuctName"  v:"required#联系人名字不能为空"`              // 姓名
+	CuctGender string `  json:"cuctGender"`                                      // 性别(10男20女)
+	Postion    string `      json:"postion"`                                     // 职位
+	Telephone  string `    json:"telephone"  v:"required|phone#手机号不能为空|手机号格式错误"` // 电话
+	Wechat     string `       json:"wechat"`                                     // 微信
+	Email      string `       json:"email" v:"email#邮箱格式错误"`                     // 邮箱
+	Remark     string `      json:"remark"`                                      // 备注
+	Policy     int    `      json:"policy"`                                      //
+}

+ 17 - 16
opms_parent/app/model/cust/internal/cust_customer_contact.go

@@ -10,20 +10,21 @@ import (
 
 // CustCustomerContact is the golang structure for table cust_customer_contact.
 type CustCustomerContact struct {
-	Id          int         `orm:"id,primary"   json:"id"`                               // 主键
-	CustId      int         `orm:"cust_id"      json:"custId" `                          // 关联客户
-	CuctName    string      `orm:"cuct_name"    json:"cuctName"  v:"required#联系人名字不能为空"` // 姓名
-	CuctGender  string      `orm:"cuct_gender"  json:"cuctGender"`                       // 性别(10男20女)
-	Postion     string      `orm:"postion"      json:"postion"`                          // 职位
-	Telephone   string      `orm:"telephone"    json:"telephone"`                        // 电话
-	Wechat      string      `orm:"wechat"       json:"wechat"`                           // 微信
-	Email       string      `orm:"email"        json:"email"`                            // 邮箱
-	Remark      string      `orm:"remark"       json:"remark"`                           // 备注
-	CreatedBy   int         `orm:"created_by"   json:"createdBy"`                        // 创建者
-	CreatedName string      `orm:"created_name" json:"createdName"`                      // 创建人
-	CreatedTime *gtime.Time `orm:"created_time" json:"createdTime"`                      // 创建时间
-	UpdatedBy   int         `orm:"updated_by"   json:"updatedBy"`                        // 更新者
-	UpdatedName string      `orm:"updated_name" json:"updatedName"`                      // 更新人
-	UpdatedTime *gtime.Time `orm:"updated_time" json:"updatedTime"`                      // 更新时间
-	DeletedTime *gtime.Time `orm:"deleted_time" json:"deletedTime"`                      // 删除时间
+	Id          int         `orm:"id,primary"   json:"id"`          // 主键
+	CustId      int         `orm:"cust_id"      json:"custId" `     // 关联客户
+	CuctName    string      `orm:"cuct_name"    json:"cuctName"  `  // 姓名
+	CuctGender  string      `orm:"cuct_gender"  json:"cuctGender"`  // 性别(10男20女)
+	Postion     string      `orm:"postion"      json:"postion"`     // 职位
+	Telephone   string      `orm:"telephone"    json:"telephone"`   // 电话
+	Wechat      string      `orm:"wechat"       json:"wechat"`      // 微信
+	Email       string      `orm:"email"        json:"email"`       // 邮箱
+	Policy      int         ` orm:"policy"     json:"policy"`       //是否决策
+	Remark      string      `orm:"remark"       json:"remark"`      // 备注
+	CreatedBy   int         `orm:"created_by"   json:"createdBy"`   // 创建者
+	CreatedName string      `orm:"created_name" json:"createdName"` // 创建人
+	CreatedTime *gtime.Time `orm:"created_time" json:"createdTime"` // 创建时间
+	UpdatedBy   int         `orm:"updated_by"   json:"updatedBy"`   // 更新者
+	UpdatedName string      `orm:"updated_name" json:"updatedName"` // 更新人
+	UpdatedTime *gtime.Time `orm:"updated_time" json:"updatedTime"` // 更新时间
+	DeletedTime *gtime.Time `orm:"deleted_time" json:"deletedTime"` // 删除时间
 }

+ 5 - 4
opms_parent/app/service/base/base_distributor.go

@@ -29,8 +29,9 @@ func NewDistributorService(ctx context.Context) (svc *distributorService, err er
 //经销商信息列表 distributorList []*model.BaseDistributorRonp
 func (d *distributorService) GetList(req *model.BaseDistributorSearchReq) (total int, distributorList []*model.DistributorRonp, err error) {
 	distributorModel := d.Dao.M
+
 	if req.DistCode != "" {
-		distributorModel = distributorModel.Where("u.dist_code", req.DistCode)
+		distributorModel = distributorModel.Where("dist_code", req.DistCode)
 	}
 	if req.DistName != "" {
 		distributorModel = distributorModel.Where("dist_name like ?", "%"+req.DistName+"%")
@@ -38,10 +39,10 @@ func (d *distributorService) GetList(req *model.BaseDistributorSearchReq) (total
 	if req.BelongSale != "" {
 		distributorModel = distributorModel.Where("belong_sale like ?", "%"+req.BelongSale+"%")
 	}
-	if req.ProvinceId != 0 {
-		distributorModel = distributorModel.Where("province_id ", req.ProvinceId)
+	if req.ProvinceId > 0 {
+		distributorModel = distributorModel.Where("province_id in (?)", req.ProvinceId)
 	}
-	g.Log().Info("搜索条件", req.BelongSale)
+	g.Log().Info("搜索条件", req.ProvinceId)
 	total, err = distributorModel.Count()
 	if err != nil {
 		g.Log().Error(err)

+ 13 - 0
opms_parent/app/service/base/base_district.go

@@ -3,6 +3,7 @@ package base
 import (
 	"context"
 
+	"github.com/gogf/gf/errors/gerror"
 	"github.com/gogf/gf/frame/g"
 
 	"dashoo.cn/micro/app/dao/base"
@@ -28,6 +29,7 @@ func NewDistrictService(ctx context.Context) (svc *districtService, err error) {
 //区域省市区 树形结构
 func (d *districtService) ListToTree(pid int) []*model.T {
 	var distributorList []model.BaseDistrict
+	g.Log().Info("ID", pid)
 	d.Dao.M.Where(base.BaseDistrict.Columns.ParentId, pid).Scan(&distributorList)
 	treeList := []*model.T{}
 	for _, v := range distributorList {
@@ -45,3 +47,14 @@ func (d *districtService) ListToTree(pid int) []*model.T {
 	g.Log().Info("xc11", treeList)
 	return treeList
 }
+func (d *districtService) GetProvinceInfo() (list []*model.Province) {
+
+	Model := d.Dao.M
+	err := Model.Where(base.BaseDistrict.Columns.ParentId, 0).Scan(&list)
+	if err != nil {
+		g.Log().Error(err)
+		err = gerror.New("获取数据失败")
+		return
+	}
+	return
+}

+ 48 - 72
opms_parent/app/service/cust/cust_customer.go

@@ -4,7 +4,6 @@ import (
 	"context"
 	"strconv"
 
-	"github.com/gogf/gf/database/gdb"
 	"github.com/gogf/gf/errors/gerror"
 	"github.com/gogf/gf/frame/g"
 	"github.com/gogf/gf/os/gtime"
@@ -32,100 +31,76 @@ func NewCustomerService(ctx context.Context) (svc *customerService, err error) {
 }
 
 //创建客户
-func (c *customerService) Create(req *model.AddCustCustomerReq) (err error) {
-
+func (c *customerService) Create(req *model.Customer) (insertId int64, err error) {
 	cusTomer := new(model.CustCustomer)
-	conTact := new(model.CustCustomerContact)
-	if err = gconv.Struct(req.Cust, cusTomer); err != nil {
+	custBelong := new(model.CustCustomerBelong)
+	if err = gconv.Struct(req, cusTomer); err != nil {
 		g.Log().Info("error", err)
 		return
 	}
-	if err = gconv.Struct(req.Info, conTact); err != nil {
-		return
-	}
 	g.Log().Info(err)
 	Model := c.Dao.M
-	record, err := Model.As("c").LeftJoin("cust_customer_contact ct", "c.id=ct.cust_id").Fields("c.*").Where(
+	record, err := Model.Where(
 		g.Map{
-			"ct.telephone": req.Info.TelePhone,
-			"ct.cuct_name": req.Info.CuctName,
-			"c.cust_name":  req.Cust.CustName,
+			"cust_name": req.CustName,
 		},
 	).One()
 	g.Log().Info("recordE", record.IsEmpty())
 	if err != nil || !record.IsEmpty() {
 		err = gerror.New("该客户信息已存在,不可重复添加")
-		return err
-	}
-
-	cusTomer.CustCode = strconv.Itoa(int(gtime.Timestamp()))
-	cusTomer.IsPublic = "10"
-
-	service.SetCreatedInfo(cusTomer, c.GetCxtUserId(), c.GetCxtUserName())
-	var tx *gdb.TX
-	tx, err = g.DB().Begin()
-	if err != nil {
-		err = gerror.New("事务开启失败")
 		return
 	}
-	cus_res, err := Model.Insert(cusTomer)
+	service.SetCreatedInfo(cusTomer, c.GetCxtUserId(), c.GetCxtUserName())
+	cusTomer.CustCode = strconv.Itoa(int(gtime.Timestamp()))
+	cusTomer.IsPublic = "20"
+	cusTomer.DeptId = c.GetCxtUserDeptId()  //部门id
+	cusTomer.DeptId = c.GetCxtUserDeptId()  //部门名称
+	cusTomer.SalesId = c.GetCxtUserId()     //  销售id
+	cusTomer.SalesName = c.GetCxtUserName() //  销售名称
+	res, err := Model.Insert(cusTomer)
 	if err != nil {
 		g.Log().Error(err)
 		err = gerror.New("cusTomer表插入失败")
-		tx.Rollback()
-		return
-	}
-	InsertId, _ := cus_res.LastInsertId()
-	conTact.CustId = int(InsertId)
-	service.SetCreatedInfo(conTact, c.GetCxtUserId(), c.GetCxtUserName())
-	_, err = cust.CustCustomerContact.Insert(conTact)
-	if err != nil {
-		g.Log().Error(err)
-		err = gerror.New("conTact表插入失败")
-		tx.Rollback()
-		return
 	}
-	/**
-		预留逻辑判断当前登录角色是否是销售人员
-	     if 销售人员 {
-		  cusTomer.SalesId  =  当前销售人员id
-		  cusTomer.SalesName = 当前销售人员姓名
-
-	      c.BelongDao.M.Insert()
-
+	insertId, _ = res.LastInsertId()
+	if c.CxtUser.Id == 1 { //
+		service.SetCreatedInfo(custBelong, c.GetCxtUserId(), c.GetCxtUserName())
+		custBelong.CustId = int(insertId)
+		custBelong.OpnType = "10"
+		custBelong.OpnDatetime = gtime.Now()
+		service.SetCreatedInfo(custBelong, c.GetCxtUserId(), c.GetCxtUserName())
+		_, err = c.BelongDao.Insert(custBelong)
+		if err != nil {
+			g.Log().Error(err)
+			err = gerror.New("创建失败")
+			return
 		}
-
-	*/
-
-	tx.Commit()
+	}
 	return
 }
 
 //客户列表列表
 func (c *customerService) GetList(req *model.CustCustomerSearchReq) (total int, customerList []*model.CustList, err error) {
-
-	Model := c.Dao.M.As("c").LeftJoin("cust_customer_contact ct", "c.id=ct.cust_id").Where("c.is_public =?", 20) //非公海客户
+	Model := c.Dao.M //非公海客户
+	Model.Where("is_public", 20)
 	//客户名称
 	if req.CustName != "" {
-		Model = Model.Where("c.cust_name ", req.CustName)
-	}
-	//联系人
-	if req.CuctName != "" {
-		Model = Model.Where("ct.cuct_name", req.CuctName)
-	}
-	// 联系人姓名
-	if req.CustStatus != "" {
-		Model = Model.Where("ct.cuct_name", req.CuctName)
-	}
-	//所属销售
-	if req.SalesName != "" {
-		Model = Model.Where("c.sales_name ?", req.SalesName)
-	}
-	//联系人电话
-	if req.Telephone != "" {
-		Model = Model.Where("ct.telephone ?", req.Telephone)
-	}
-	total, err = Model.Fields("c.id").Count()
+		Model = Model.Where("cust_name ", req.CustName)
+	}
+	//客户编码
+	if req.CustCode != "" {
+		Model = Model.Where("cust_name ", req.CustCode)
+	}
+
+	//客户行业
+	//if req.SalesName != "" {
+	//	Model = Model.Where("c.sales_name ?", req.SalesName)
+	//}
+	//客户级别
+	//if req.Telephone != "" {
+	//	Model = Model.Where("ct.telephone ?", req.Telephone)
+	//}
+	total, err = Model.Fields().Count()
 	if err != nil {
 		g.Log().Error(err)
 		err = gerror.New("获取总行数失败")
@@ -134,12 +109,13 @@ func (c *customerService) GetList(req *model.CustCustomerSearchReq) (total int,
 	if req.PageNum == 0 {
 		req.PageNum = 1
 	}
-	fields := "c.*,ct.cuct_name,ct.telephone"
-	err = Model.Fields(fields).Page(req.PageNum, req.PageSize).Order("c.id asc").Scan(&customerList)
-	
+	fields := "id,cust_code,cust_name,abbr_name,'' as indus_try,'' as level,cust_location,cust_status,follow_up_date,created_name,created_time"
+	err = Model.Fields(fields).Page(req.PageNum, req.PageSize).Order("id desc").Scan(&customerList)
 	return
 }
 
+//
+
 //分配客户
 func (c *customerService) DistriCustomer(req *model.DistriCustomer) error {
 	/**

+ 45 - 0
opms_parent/app/service/cust/cust_customer_contact.go

@@ -1 +1,46 @@
 package cust
+
+import (
+	"context"
+
+	"github.com/gogf/gf/frame/g"
+	"github.com/gogf/gf/util/gconv"
+
+	"fmt"
+
+	"dashoo.cn/micro/app/dao/cust"
+	model "dashoo.cn/micro/app/model/cust"
+	"dashoo.cn/micro/app/service"
+)
+
+type customercontactService struct {
+	*service.ContextService
+	Dao *cust.CustCustomerContactDao
+}
+
+func NewCustomerContactService(ctx context.Context) (svc *customercontactService, err error) {
+	svc = new(customercontactService)
+	if svc.ContextService, err = svc.Init(ctx); err != nil {
+		return nil, err
+	}
+	svc.Dao = cust.NewCustCustomerContactDao(svc.Tenant)
+	return svc, nil
+}
+
+//添加联系人
+func (c *customercontactService) Create(req *model.CustCustomerContactSeq) (err error) {
+	contact := new(model.CustCustomerContact)
+	if err = gconv.Struct(req, contact); err != nil {
+		g.Log().Info("error", err)
+		return
+	}
+	service.SetCreatedInfo(contact, c.GetCxtUserId(), c.GetCxtUserName())
+	Model := c.Dao.M
+	res, err := Model.Insert(contact)
+	if err != nil {
+		return
+	}
+	InsertId, _ := res.LastInsertId()
+	fmt.Println(InsertId)
+	return
+}

+ 1 - 1
opms_parent/main.go

@@ -20,7 +20,7 @@ func main() {
 	s.RegisterName("Distributor", new(base.DistributorHandler), "")
 	s.RegisterName("District", new(base.DistrictHandler), "")
 	s.RegisterName("Customer", new(cust.CustomerHeader), "")
-	s.RegisterName("Customer", new(cust.CustomerHeader), "")
+	s.RegisterName("Contant", new(cust.CustomerContantHeader), "")
 
 	// 注册服务对象
 	//s.RegisterName("Auth", new(handler.Auth), "")