소스 검색

Merge branch 'feature/customer_1.0' into develop

wangxingcheng 3 년 전
부모
커밋
476d2aab34

+ 468 - 0
opms_parent/app/dao/internal/cust_customer.go

@@ -0,0 +1,468 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
+// ==========================================================================
+
+package internal
+
+import (
+	"context"
+	"database/sql"
+	"github.com/gogf/gf/database/gdb"
+	"github.com/gogf/gf/frame/g"
+	"github.com/gogf/gf/frame/gmvc"
+	"time"
+
+	"dashoo.cn/micro/app/model"
+)
+
+// CustCustomerDao is the manager for logic model data accessing
+// and custom defined data operations functions management.
+type CustCustomerDao struct {
+	gmvc.M
+	DB      gdb.DB
+	Table   string
+	Columns custCustomerColumns
+}
+
+// CustCustomerColumns defines and stores column names for table cust_customer.
+type custCustomerColumns struct {
+	Id           string // 主键
+	CustCode     string // 客户编号
+	CustName     string // 客户名称
+	AbbrName     string // 助记名
+	CustDistCode string // 客户所在省级ID
+	CustLocation string // 所在地区
+	CustAddress  string // 详细地址
+	CustIndustry string // 客户行业
+	CustLevel    string // 客户级别(10 重点客户 20 普通客户 30非优客户)
+	CustStatus   string // 客户状态(10正常20)
+	CustSource   string // 客户来源
+	IsPublic     string // 公海客户(10是20否)
+	DeptId       string // 所属部门ID
+	DeptName     string // 所属部门
+	SalesId      string // 所属销售ID
+	SalesName    string // 所属销售
+	FollowUpDate string // 最后跟进时间
+	Remark       string // 备注
+	CreatedBy    string // 创建者
+	CreatedName  string // 创建人
+	CreatedTime  string // 创建时间
+	UpdatedBy    string // 更新者
+	UpdatedName  string // 更新人
+	UpdatedTime  string // 更新时间
+	DeletedTime  string // 删除时间
+}
+
+var (
+	// CustCustomer is globally public accessible object for table cust_customer operations.
+	CustCustomer = CustCustomerDao{
+		M:     g.DB("default").Model("cust_customer").Safe(),
+		DB:    g.DB("default"),
+		Table: "cust_customer",
+		Columns: custCustomerColumns{
+			Id:           "id",
+			CustCode:     "cust_code",
+			CustName:     "cust_name",
+			AbbrName:     "abbr_name",
+			CustDistCode: "cust_dist_code",
+			CustLocation: "cust_location",
+			CustAddress:  "cust_address",
+			CustIndustry: "cust_industry",
+			CustLevel:    "cust_level",
+			CustStatus:   "cust_status",
+			CustSource:   "cust_source",
+			IsPublic:     "is_public",
+			DeptId:       "dept_id",
+			DeptName:     "dept_name",
+			SalesId:      "sales_id",
+			SalesName:    "sales_name",
+			FollowUpDate: "follow_up_date",
+			Remark:       "remark",
+			CreatedBy:    "created_by",
+			CreatedName:  "created_name",
+			CreatedTime:  "created_time",
+			UpdatedBy:    "updated_by",
+			UpdatedName:  "updated_name",
+			UpdatedTime:  "updated_time",
+			DeletedTime:  "deleted_time",
+		},
+	}
+)
+
+func NewCustCustomerDao(tenant string) CustCustomerDao {
+	var dao CustCustomerDao
+	dao = CustCustomerDao{
+		M:     g.DB(tenant).Model("cust_customer").Safe(),
+		DB:    g.DB(tenant),
+		Table: "cust_customer",
+		Columns: custCustomerColumns{
+			Id:           "id",
+			CustCode:     "cust_code",
+			CustName:     "cust_name",
+			AbbrName:     "abbr_name",
+			CustDistCode: "cust_dist_code",
+			CustLocation: "cust_location",
+			CustAddress:  "cust_address",
+			CustIndustry: "cust_industry",
+			CustLevel:    "cust_level",
+			CustStatus:   "cust_status",
+			CustSource:   "cust_source",
+			IsPublic:     "is_public",
+			DeptId:       "dept_id",
+			DeptName:     "dept_name",
+			SalesId:      "sales_id",
+			SalesName:    "sales_name",
+			FollowUpDate: "follow_up_date",
+			Remark:       "remark",
+			CreatedBy:    "created_by",
+			CreatedName:  "created_name",
+			CreatedTime:  "created_time",
+			UpdatedBy:    "updated_by",
+			UpdatedName:  "updated_name",
+			UpdatedTime:  "updated_time",
+			DeletedTime:  "deleted_time",
+		},
+	}
+	return dao
+}
+
+// Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
+// of current DB object and with given context in it.
+// Note that this returned DB object can be used only once, so do not assign it to
+// a global or package variable for long using.
+func (d *CustCustomerDao) Ctx(ctx context.Context) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.Ctx(ctx)}
+}
+
+// As sets an alias name for current table.
+func (d *CustCustomerDao) As(as string) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.As(as)}
+}
+
+// TX sets the transaction for current operation.
+func (d *CustCustomerDao) TX(tx *gdb.TX) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.TX(tx)}
+}
+
+// Master marks the following operation on master node.
+func (d *CustCustomerDao) Master() *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.Master()}
+}
+
+// Slave marks the following operation on slave node.
+// Note that it makes sense only if there's any slave node configured.
+func (d *CustCustomerDao) Slave() *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.Slave()}
+}
+
+// Args sets custom arguments for model operation.
+func (d *CustCustomerDao) Args(args ...interface{}) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.Args(args...)}
+}
+
+// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
+func (d *CustCustomerDao) LeftJoin(table ...string) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.LeftJoin(table...)}
+}
+
+// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
+func (d *CustCustomerDao) RightJoin(table ...string) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.RightJoin(table...)}
+}
+
+// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
+func (d *CustCustomerDao) InnerJoin(table ...string) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.InnerJoin(table...)}
+}
+
+// Fields sets the operation fields of the model, multiple fields joined using char ','.
+// The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
+func (d *CustCustomerDao) Fields(fieldNamesOrMapStruct ...interface{}) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.Fields(fieldNamesOrMapStruct...)}
+}
+
+// FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
+// The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
+func (d *CustCustomerDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...)}
+}
+
+// Option sets the extra operation option for the model.
+func (d *CustCustomerDao) Option(option int) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.Option(option)}
+}
+
+// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
+// the data and where attributes for empty values.
+func (d *CustCustomerDao) OmitEmpty() *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.OmitEmpty()}
+}
+
+// Filter marks filtering the fields which does not exist in the fields of the operated table.
+func (d *CustCustomerDao) Filter() *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.Filter()}
+}
+
+// Where sets the condition statement for the model. The parameter <where> can be type of
+// string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
+// multiple conditions will be joined into where statement using "AND".
+// Eg:
+// Where("uid=10000")
+// Where("uid", 10000)
+// Where("money>? AND name like ?", 99999, "vip_%")
+// Where("uid", 1).Where("name", "john")
+// Where("status IN (?)", g.Slice{1,2,3})
+// Where("age IN(?,?)", 18, 50)
+// Where(User{ Id : 1, UserName : "john"})
+func (d *CustCustomerDao) Where(where interface{}, args ...interface{}) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.Where(where, args...)}
+}
+
+// WherePri does the same logic as M.Where except that if the parameter <where>
+// is a single condition like int/string/float/slice, it treats the condition as the primary
+// key value. That is, if primary key is "id" and given <where> parameter as "123", the
+// WherePri function treats the condition as "id=123", but M.Where treats the condition
+// as string "123".
+func (d *CustCustomerDao) WherePri(where interface{}, args ...interface{}) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.WherePri(where, args...)}
+}
+
+// And adds "AND" condition to the where statement.
+func (d *CustCustomerDao) And(where interface{}, args ...interface{}) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.And(where, args...)}
+}
+
+// Or adds "OR" condition to the where statement.
+func (d *CustCustomerDao) Or(where interface{}, args ...interface{}) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.Or(where, args...)}
+}
+
+// Group sets the "GROUP BY" statement for the model.
+func (d *CustCustomerDao) Group(groupBy string) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.Group(groupBy)}
+}
+
+// Order sets the "ORDER BY" statement for the model.
+func (d *CustCustomerDao) Order(orderBy ...string) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.Order(orderBy...)}
+}
+
+// Limit sets the "LIMIT" statement for the model.
+// The parameter <limit> can be either one or two number, if passed two number is passed,
+// it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
+// statement.
+func (d *CustCustomerDao) Limit(limit ...int) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.Limit(limit...)}
+}
+
+// Offset sets the "OFFSET" statement for the model.
+// It only makes sense for some databases like SQLServer, PostgreSQL, etc.
+func (d *CustCustomerDao) Offset(offset int) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.Offset(offset)}
+}
+
+// Page sets the paging number for the model.
+// The parameter <page> is started from 1 for paging.
+// Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
+func (d *CustCustomerDao) Page(page, limit int) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.Page(page, limit)}
+}
+
+// Batch sets the batch operation number for the model.
+func (d *CustCustomerDao) Batch(batch int) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.Batch(batch)}
+}
+
+// Cache sets the cache feature for the model. It caches the result of the sql, which means
+// if there's another same sql request, it just reads and returns the result from cache, it
+// but not committed and executed into the database.
+//
+// If the parameter <duration> < 0, which means it clear the cache with given <name>.
+// If the parameter <duration> = 0, which means it never expires.
+// If the parameter <duration> > 0, which means it expires after <duration>.
+//
+// The optional parameter <name> is used to bind a name to the cache, which means you can later
+// control the cache like changing the <duration> or clearing the cache with specified <name>.
+//
+// Note that, the cache feature is disabled if the model is operating on a transaction.
+func (d *CustCustomerDao) Cache(duration time.Duration, name ...string) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.Cache(duration, name...)}
+}
+
+// Data sets the operation data for the model.
+// The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
+// Eg:
+// Data("uid=10000")
+// Data("uid", 10000)
+// Data(g.Map{"uid": 10000, "name":"john"})
+// Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
+func (d *CustCustomerDao) Data(data ...interface{}) *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.Data(data...)}
+}
+
+// All does "SELECT FROM ..." statement for the model.
+// It retrieves the records from table and returns the result as []*model.CustCustomer.
+// It returns nil if there's no record retrieved with the given conditions from table.
+//
+// The optional parameter <where> is the same as the parameter of M.Where function,
+// see M.Where.
+func (d *CustCustomerDao) All(where ...interface{}) ([]*model.CustCustomer, error) {
+	all, err := d.M.All(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*model.CustCustomer
+	if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entities, nil
+}
+
+// One retrieves one record from table and returns the result as *model.CustCustomer.
+// It returns nil if there's no record retrieved with the given conditions from table.
+//
+// The optional parameter <where> is the same as the parameter of M.Where function,
+// see M.Where.
+func (d *CustCustomerDao) One(where ...interface{}) (*model.CustCustomer, error) {
+	one, err := d.M.One(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *model.CustCustomer
+	if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entity, nil
+}
+
+// FindOne retrieves and returns a single Record by M.WherePri and M.One.
+// Also see M.WherePri and M.One.
+func (d *CustCustomerDao) FindOne(where ...interface{}) (*model.CustCustomer, error) {
+	one, err := d.M.FindOne(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *model.CustCustomer
+	if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entity, nil
+}
+
+// FindAll retrieves and returns Result by by M.WherePri and M.All.
+// Also see M.WherePri and M.All.
+func (d *CustCustomerDao) FindAll(where ...interface{}) ([]*model.CustCustomer, error) {
+	all, err := d.M.FindAll(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*model.CustCustomer
+	if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entities, nil
+}
+
+// Struct retrieves one record from table and converts it into given struct.
+// The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
+// it can create the struct internally during converting.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+//
+// Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
+// from table and <pointer> is not nil.
+//
+// Eg:
+// user := new(User)
+// err  := dao.User.Where("id", 1).Struct(user)
+//
+// user := (*User)(nil)
+// err  := dao.User.Where("id", 1).Struct(&user)
+func (d *CustCustomerDao) Struct(pointer interface{}, where ...interface{}) error {
+	return d.M.Struct(pointer, where...)
+}
+
+// Structs retrieves records from table and converts them into given struct slice.
+// The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
+// slice internally during converting.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+//
+// Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
+// from table and <pointer> is not empty.
+//
+// Eg:
+// users := ([]User)(nil)
+// err   := dao.User.Structs(&users)
+//
+// users := ([]*User)(nil)
+// err   := dao.User.Structs(&users)
+func (d *CustCustomerDao) Structs(pointer interface{}, where ...interface{}) error {
+	return d.M.Structs(pointer, where...)
+}
+
+// Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
+// It calls function Struct if <pointer> is type of *struct/**struct.
+// It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+//
+// Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
+//
+// Eg:
+// user  := new(User)
+// err   := dao.User.Where("id", 1).Scan(user)
+//
+// user  := (*User)(nil)
+// err   := dao.User.Where("id", 1).Scan(&user)
+//
+// users := ([]User)(nil)
+// err   := dao.User.Scan(&users)
+//
+// users := ([]*User)(nil)
+// err   := dao.User.Scan(&users)
+func (d *CustCustomerDao) Scan(pointer interface{}, where ...interface{}) error {
+	return d.M.Scan(pointer, where...)
+}
+
+// Chunk iterates the table with given size and callback function.
+func (d *CustCustomerDao) Chunk(limit int, callback func(entities []*model.CustCustomer, err error) bool) {
+	d.M.Chunk(limit, func(result gdb.Result, err error) bool {
+		var entities []*model.CustCustomer
+		err = result.Structs(&entities)
+		if err == sql.ErrNoRows {
+			return false
+		}
+		return callback(entities, err)
+	})
+}
+
+// LockUpdate sets the lock for update for current operation.
+func (d *CustCustomerDao) LockUpdate() *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.LockUpdate()}
+}
+
+// LockShared sets the lock in share mode for current operation.
+func (d *CustCustomerDao) LockShared() *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.LockShared()}
+}
+
+// Unscoped enables/disables the soft deleting feature.
+func (d *CustCustomerDao) Unscoped() *CustCustomerDao {
+	return &CustCustomerDao{M: d.M.Unscoped()}
+}

+ 13 - 16
opms_parent/app/handler/cust/contant.go

@@ -30,18 +30,19 @@ func (c *CustomerContantHeader) Create(ctx context.Context, req *model.CustCusto
 	}
 	contactService, err := server.NewCustomerContactService(ctx)
 	if err != nil {
-		g.Log().Error(err)
-		return err
+		return myerrors.New("系统异常,请重新尝试", err)
+
 	}
 	err = contactService.Create(req)
-	var Ids []int64
-	Ids = append(Ids, gconv.Int64(req.CustId))
-	c.WriteCustLog(ctx, ContantCreate, Ids, req)
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
 		g.Log().Error(err)
 		return err
 	}
+	var Ids []int64
+	Ids = append(Ids, gconv.Int64(req.CustId))
+	c.WriteCustLog(ctx, ContantCreate, Ids, req)
+
 	return nil
 }
 
@@ -52,8 +53,7 @@ func (c *CustomerContantHeader) UpdateById(ctx context.Context, req *model.Updat
 	}
 	customerServer, err := server.NewCustomerContactService(ctx)
 	if err != nil {
-		g.Log().Error(err)
-		return gerror.New("系统异常,请重新尝试")
+		return myerrors.New("系统异常,请重新尝试", err)
 	}
 
 	err = customerServer.UpdateById(req)
@@ -75,13 +75,12 @@ func (c *CustomerContantHeader) GetList(ctx context.Context, req *model.ContactS
 	}
 	customerServer, err := server.NewCustomerContactService(ctx)
 	if err != nil {
-		g.Log().Error(err)
-		return gerror.New("系统异常,请重新尝试")
+		return myerrors.New("系统异常,请重新尝试", err)
 	}
 	list, err := customerServer.GetList(req.CustId)
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
-		g.Log().Error(err)
+
 		return err
 	}
 	rsp.Data = g.Map{"list": list}
@@ -95,18 +94,16 @@ func (c *CustomerContantHeader) DeleteById(ctx context.Context, req *model.DelCu
 	}
 	customerServer, err := server.NewCustomerContactService(ctx)
 	if err != nil {
-		g.Log().Error(err)
-		return gerror.New("系统异常,请重新尝试")
+		return myerrors.New("系统异常,请重新尝试", err)
 	}
 	err = customerServer.DeleteById(req.Id)
-	var Ids []int64
-	Ids = append(Ids, gconv.Int64(req.CustId))
-	c.WriteCustLog(ctx, ContantDeleteById, Ids, req)
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
-		g.Log().Error(err)
 		return err
 	}
+	var Ids []int64
+	Ids = append(Ids, gconv.Int64(req.CustId))
+	c.WriteCustLog(ctx, ContantDeleteById, Ids, req)
 	return nil
 }
 

+ 63 - 59
opms_parent/app/handler/cust/customer.go

@@ -38,39 +38,54 @@ func (c *CustomerHeader) Create(ctx context.Context, req *model.CustomerAddSeq,
 	}
 	customerServer, err := server.NewCustomerService(ctx)
 	if err != nil {
-		g.Log().Error(err)
-		return err
+		return myerrors.New("系统异常,请重新尝试", err)
+
 	}
 	id, err := customerServer.Create(req)
-
-	var Ids []int64
-	Ids = append(Ids, gconv.Int64(id))
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
-		g.Log().Error(err)
 		return err
 	}
+
+	var Ids []int64
+	Ids = append(Ids, gconv.Int64(id))
+
 	//创建客户
 	c.WriteCustLog(ctx, Creates, Ids, req)
 	rsp.Data = g.Map{"lastId": id}
 	return nil
 }
 
+//修改客户
+func (c *CustomerHeader) UpdateById(ctx context.Context, req *model.UpdateCustomer, rsp *comm_def.CommonMsg) error {
+	customerServer, err := server.NewCustomerService(ctx)
+	if err != nil {
+
+		return myerrors.New("系统异常,请重新尝试", err)
+	}
+	err = customerServer.UpdateById(req)
+	var Ids []int64
+	Ids = append(Ids, gconv.Int64(req.Id))
+	c.WriteCustLog(ctx, UpdateById, Ids, req)
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
 //客户详情
 func (c *CustomerHeader) GetEntityById(ctx context.Context, req *comm_def.IdsReq, rsp *comm_def.CommonMsg) error {
 	if len(req.Ids) == 0 {
-
-		return gerror.New("参数有误!")
+		return myerrors.NewMsgError(nil, "参数有误")
 	}
 	customerServer, err := server.NewCustomerService(ctx)
 	if err != nil {
-
 		return myerrors.New("系统异常,请重新尝试", err)
 	}
 	list, err := customerServer.GetEntityById(req.Ids)
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
-		g.Log().Error(err)
 		return err
 	}
 	rsp.Data = g.Map{"list": list}
@@ -80,24 +95,39 @@ func (c *CustomerHeader) GetEntityById(ctx context.Context, req *comm_def.IdsReq
 //删除客户
 func (c *CustomerHeader) DeleteById(ctx context.Context, req *model.DelCustomer, rsp *comm_def.CommonMsg) error {
 	if req.Id == 0 {
-		return gerror.New("参数有误!")
+		return myerrors.NewMsgError(nil, "参数有误")
 	}
 	customerServer, err := server.NewCustomerService(ctx)
 	if err != nil {
-		g.Log().Error(err)
 		return myerrors.New("系统异常,请重新尝试", err)
 	}
 	err = customerServer.DeleteById(req.Id)
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
 	var Ids []int64
 	Ids = append(Ids, gconv.Int64(req.Id))
 	//删除客户
 	c.WriteCustLog(ctx, DeleteById, Ids, req)
+	return nil
+}
 
+//判断客户名称是否存在  bool
+func (c *CustomerHeader) GetCustNameIsExist(ctx context.Context, req *model.CustName, rsp *comm_def.CommonMsg) error {
+	if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
+		return err
+	}
+	customerServer, err := server.NewCustomerService(ctx)
+	if err != nil {
+		return myerrors.New("系统异常,请重新尝试", err)
+	}
+	exist, err := customerServer.GetCustNameIsExist(req.CustName)
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
-		g.Log().Error(err)
 		return err
 	}
+	rsp.Data = g.Map{"list": exist}
 	return nil
 }
 
@@ -105,17 +135,16 @@ func (c *CustomerHeader) DeleteById(ctx context.Context, req *model.DelCustomer,
 func (c *CustomerHeader) PublicGetList(ctx context.Context, req *model.CustCustomerSearchReq, rsp *comm_def.CommonMsg) error {
 	customerServer, err := server.NewCustomerService(ctx)
 	if err != nil {
-		g.Log().Error(err)
-		return err
+
+		return myerrors.New("系统异常,请重新尝试", err)
 	}
 
 	req.IsPublic = noCustomer
-	g.Log().Info("publicGetlist", req)
 
 	total, list, err := customerServer.GetList(req)
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
-		g.Log().Error(err)
+
 		return err
 	}
 	rsp.Data = g.Map{"list": list, "total": total}
@@ -127,13 +156,11 @@ func (c *CustomerHeader) PublicGetList(ctx context.Context, req *model.CustCusto
 func (c *CustomerHeader) GetList(ctx context.Context, req *model.CustCustomerSearchReq, rsp *comm_def.CommonMsg) error {
 	customerServer, err := server.NewCustomerService(ctx)
 	if err != nil {
-		g.Log().Error(err)
-		return err
+		return myerrors.New("系统异常,请重新尝试", err)
 	}
 	total, list, err := customerServer.GetList(req)
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
-		g.Log().Error(err)
 		return err
 	}
 	rsp.Data = g.Map{"list": list, "total": total}
@@ -151,26 +178,21 @@ func (c *CustomerHeader) UpdateBytransfer(ctx context.Context, req *model.Distri
 		return myerrors.New("系统异常,请重新尝试", err)
 	}
 	err = customerServer.UpdateBytransfer(req)
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
-		return gerror.New("转移失败")
-
+		return err
 	}
 	var Ids []int64
 	Ids = append(Ids, gconv.Int64(req.Ids))
 	//转移客户
 	c.WriteCustLog(ctx, UpdateBytransfer, Ids, req)
-	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
-	if err != nil {
-		g.Log().Error(err)
-		return err
-	}
 	return nil
 }
 
 //分配客户
 func (c *CustomerHeader) DistriCustomer(ctx context.Context, req *model.DistriCustomer, rsp *comm_def.CommonMsg) error {
 	if len(req.Ids) == 0 || req.SalesId == 0 {
-		return gerror.New("参数有误!")
+		return myerrors.NewMsgError(nil, "参数有误")
 	}
 	customerServer, err := server.NewCustomerService(ctx)
 	if err != nil {
@@ -178,6 +200,7 @@ func (c *CustomerHeader) DistriCustomer(ctx context.Context, req *model.DistriCu
 		return myerrors.New("系统异常,请重新尝试", err)
 	}
 	err = customerServer.DistriCustomer(req)
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
 		return err
 	}
@@ -188,12 +211,6 @@ func (c *CustomerHeader) DistriCustomer(ctx context.Context, req *model.DistriCu
 		behavior = Receive
 	}
 	c.WriteCustLog(ctx, behavior, req.Ids, req)
-	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
-	if err != nil {
-		g.Log().Error(err)
-		return err
-	}
-
 	return nil
 
 }
@@ -259,24 +276,6 @@ func (c *CustomerHeader) Mergecustomer(ctx context.Context, req *model.Mergecust
 	return nil
 }
 
-//修改客户
-func (c *CustomerHeader) UpdateById(ctx context.Context, req *model.UpdateCustomer, rsp *comm_def.CommonMsg) error {
-	customerServer, err := server.NewCustomerService(ctx)
-	if err != nil {
-
-		return myerrors.New("系统异常,请重新尝试", err)
-	}
-	err = customerServer.UpdateById(req)
-	var Ids []int64
-	Ids = append(Ids, gconv.Int64(req.Id))
-	c.WriteCustLog(ctx, UpdateById, Ids, req)
-	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
-	if err != nil {
-		return err
-	}
-	return nil
-}
-
 //客户摘要
 func (c *CustomerHeader) CustAbstract(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
 	if req.Id == 0 {
@@ -284,11 +283,14 @@ func (c *CustomerHeader) CustAbstract(ctx context.Context, req *comm_def.IdReq,
 	}
 	customerServer, err := server.NewCustomerService(ctx)
 	if err != nil {
-		g.Log().Error(err)
-		return gerror.New("系统异常,请重新尝试")
+
+		return myerrors.New("系统异常,请重新尝试", err)
 	}
 	list, err := customerServer.CustAbstract(req.Id)
-	g.Log().Info("CustAbstract", list)
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
 	rsp.Data = g.Map{"list": list}
 	return nil
 }
@@ -305,13 +307,15 @@ func (c *CustomerHeader) WriteCustLog(ctx context.Context, custType string, cust
 
 //导出
 func (c *CustomerHeader) DeriveList(ctx context.Context, req *model.CustCustomerExport, rsp *comm_def.CommonMsg) error {
-
 	customerServer, err := server.NewCustomerService(ctx)
 	if err != nil {
-		g.Log().Error(err)
-		return gerror.New("系统异常,请重新尝试")
+		return myerrors.New("系统异常,请重新尝试", err)
 	} //Export
-	buffer, _ := customerServer.Export(req)
+	buffer, err := customerServer.Export(req)
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
 	rsp.Data = g.Map{"list": buffer}
 	return nil
 }

+ 5 - 0
opms_parent/app/model/cust/cust_customer.go

@@ -156,3 +156,8 @@ type MoveToPubicRep struct {
 	Ids    []int64 `json:"ids,omitempty"`
 	Remark string  `json:"remark,omitempty"`
 }
+
+//客户名称
+type CustName struct {
+	CustName string `json:"custName"` // 客户名称
+}

+ 38 - 0
opms_parent/app/model/internal/cust_customer.go

@@ -0,0 +1,38 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
+// ==========================================================================
+
+package internal
+
+import (
+	"github.com/gogf/gf/os/gtime"
+)
+
+// CustCustomer is the golang structure for table cust_customer.
+type CustCustomer 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"`     // 助记名
+	CustDistCode int         `orm:"cust_dist_code" json:"custDistCode"` // 客户所在省级ID
+	CustLocation string      `orm:"cust_location"  json:"custLocation"` // 所在地区
+	CustAddress  string      `orm:"cust_address"   json:"custAddress"`  // 详细地址
+	CustIndustry string      `orm:"cust_industry"  json:"custIndustry"` // 客户行业
+	CustLevel    string      `orm:"cust_level"     json:"custLevel"`    // 客户级别(10 重点客户 20 普通客户 30非优客户)
+	CustStatus   string      `orm:"cust_status"    json:"custStatus"`   // 客户状态(10正常20)
+	CustSource   string      `orm:"cust_source"    json:"custSource"`   // 客户来源
+	IsPublic     string      `orm:"is_public"      json:"isPublic"`     // 公海客户(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
+	SalesName    string      `orm:"sales_name"     json:"salesName"`    // 所属销售
+	FollowUpDate *gtime.Time `orm:"follow_up_date" json:"followUpDate"` // 最后跟进时间
+	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"`  // 删除时间
+}

+ 110 - 108
opms_parent/app/service/cust/cust_customer.go

@@ -77,15 +77,15 @@ func (c *CustomerService) Create(req *model.CustomerAddSeq) (insertId int64, err
 	cusTomer.CustCode = "CT" + strconv.Itoa(int(gtime.Timestamp()))
 	cusTomer.CustStatus = "10"
 
-	Roles := c.GetCxtUserRoles()
-	roles := false
-	for _, v := range Roles {
+	roles := c.GetCxtUserRoles()
+	isSales := false
+	for _, v := range roles {
 		if v == "Sales" { // 销售角色
-			roles = true
+			isSales = true
 		}
 	}
 	// 销售角色
-	if roles {
+	if isSales {
 		cusTomer.IsPublic = noPublic
 		cusTomer.SalesId = c.GetCxtUserId()
 		cusTomer.SalesName = c.GetCxtUserName()
@@ -127,11 +127,13 @@ func (c *CustomerService) DeleteById(id int) error {
 	Model := c.Dao
 	ContactModel := c.ContactDao //联系人
 	BelongModel := c.BelongDao
-	regionDetail := new(model.CustCustomer)
-	err := Model.Where(c.Dao.Columns.Id, id).Scan(&regionDetail)
+	//regionDetail := new(model.CustCustomer)
+	customerCount, err := Model.Where(c.Dao.Columns.Id, id).Count()
 	if err != nil {
-		g.Log().Error(err)
-		err = gerror.New("没有要删除的数据")
+		return myerrors.New(" 删除客户 DeleteById Sql执行异常", err)
+	}
+	if customerCount == 0 {
+		err = myerrors.NewMsgError(nil, "客户信息不存在")
 		return err
 	}
 
@@ -142,17 +144,16 @@ func (c *CustomerService) DeleteById(id int) error {
 		if err == nil {
 			_, err = BelongModel.Where(c.BelongDao.Columns.CustId, id).Delete()
 			if err != nil {
-				err = gerror.New("删除数据失败")
-				return err
+				return myerrors.New(" 删除客户 BelongModel Sql执行异常", err)
+
 			}
 		} else {
-			err = gerror.New("删除数据失败")
-			return err
+			return myerrors.New(" 删除客户 ContactModel Sql执行异常", err)
+
 		}
 	} else {
-		g.Log().Error(err)
-		err = gerror.New("删除数据失败")
-		return err
+
+		return myerrors.New(" 删除客户 ColumnsModel Sql执行异常", err)
 	}
 	return nil
 }
@@ -166,17 +167,16 @@ func (c *CustomerService) UpdateById(req *model.UpdateCustomer) (err error) {
 		return
 	}
 	if count == 0 {
-		err = myerrors.New("用户信息不存在", err)
+		err = myerrors.NewMsgError(nil, "用户信息不存在")
 		return
 	}
 	countNums, err := db.Where(c.Dao.Columns.CustName+" = ", req.CustName).Where(c.Dao.Columns.Id+" not in (?)", req.Id).Count()
 	if err != nil {
 		err = myerrors.New("  Sql执行异常", err)
-
 		return
 	}
 	if countNums > 0 {
-		err = myerrors.New("客户名称已存在", err)
+		err = myerrors.NewMsgError(nil, "客户名称已存在")
 		return
 	}
 
@@ -220,7 +220,7 @@ func (c *CustomerService) GetList(req *model.CustCustomerSearchReq) (total int,
 	}
 	//客户级别
 	if req.CustLevel != "" {
-		g.Log().Info("level", req.CustLevel)
+
 		Model = Model.Where(c.Dao.Columns.CustLevel, req.CustLevel)
 	}
 	//
@@ -229,15 +229,16 @@ func (c *CustomerService) GetList(req *model.CustCustomerSearchReq) (total int,
 	}
 	total, err = Model.Count()
 	if err != nil {
-		g.Log().Error(err)
-		err = gerror.New("获取总行数失败")
+		err = myerrors.New("获取总行数失败", err)
+
 		return
 	}
-	if req.PageNum == 0 {
-		req.PageNum = 1
-	}
 
 	err = Model.Page(req.GetPage()).Order("id desc").Scan(&customerList)
+	if err != nil {
+		err = myerrors.New("获取列表失败", err)
+		return
+	}
 	for _, v := range customerList {
 		times := gconv.String(v.CreatedTime)
 		v.FollowUpDate = gstr.SubStr(v.FollowUpDate, 0, 16)
@@ -247,14 +248,19 @@ func (c *CustomerService) GetList(req *model.CustCustomerSearchReq) (total int,
 }
 
 //移入公海
-func (c *CustomerService) MoveToPubic(ids []int64) error {
-	Model := c.Dao.M
-	list, err := Model.Fields(c.Dao.Columns.CreatedTime).Where(c.Dao.Columns.Id+" in (?) ", ids).All()
-	if err != nil || list.Len() <= 0 {
-		g.Log().Error(err)
-		err = gerror.New("没有要移除的数据")
-		return err
+func (c *CustomerService) MoveToPubic(ids []int64) (err error) {
+	Model := c.Dao
+	columnsCount, err := Model.Fields(c.Dao.Columns.CreatedTime).Where(c.Dao.Columns.Id+" in (?) ", ids).Count()
+	if err != nil {
+
+		err = myerrors.New("MoveToPubic Sql 执行异常", err)
+		return
 	}
+	if columnsCount == 0 {
+		err = myerrors.NewMsgError(nil, "没有要移除的数据")
+		return
+	}
+
 	_, err = Model.Data(g.Map{
 		"is_public":    isPublic,
 		"sales_id":     0,
@@ -268,52 +274,49 @@ func (c *CustomerService) MoveToPubic(ids []int64) error {
 	}).Where(c.ContactDao.Columns.Id+" in (?)", ids).Update()
 
 	if err != nil {
-		g.Log().Error(err)
-		err = gerror.New("移入公海失败")
-		return err
+		err = myerrors.New("MoveToPubic updateSql 执行异常", err)
+		return
 	}
 	return nil
 }
 
 //分配客户
-func (c *CustomerService) DistriCustomer(req *model.DistriCustomer) error {
+func (c *CustomerService) DistriCustomer(req *model.DistriCustomer) (err error) {
 	custModel := c.Dao
-	rep, err := custModel.Where(cust.CustCustomer.Columns.Id+" in (?)  ", req.Ids).All()
+	customerData, err := custModel.Where(cust.CustCustomer.Columns.Id+" in (?)  ", req.Ids).All()
 	if err != nil {
 		err = myerrors.New("DistriCustomer Sql执行异常", err)
-		return err
+		return
+	}
+	if len(customerData) == 0 {
+		err = myerrors.NewMsgError(nil, "无可分配客户")
+		return
 	}
 	var custMap = make(map[int]string)
-	for _, v := range rep {
+	for _, v := range customerData {
 		custMap[v.Id] = v.SalesName
 	}
 	for _, v := range req.Ids {
 		g.Log().Info("req.Ids", v)
 		if custMap[gconv.Int(v)] != "" {
-			err = gerror.New("ID" + gconv.String(v) + "已被认领")
-			return err
+			err = myerrors.NewMsgError(nil, "ID"+gconv.String(v)+"已被认领")
+			return
 		}
 	}
-	err = c.updateCustomer(req.Ids, req.SalesId, req.SalesName)
-	if err != nil {
-		err = gerror.New("可配客户失败")
-		return err
-
-	}
+	c.updateCustomer(req.Ids, req.SalesId, req.SalesName)
+	//if err != nil {
+	//	err = myerrors.New("DistriCustomer update Sql执行异常", err)
+	//	return
+	//
+	//}
 	if req.Receive != "" {
 		req.Receive = Receive
 	} else {
 		req.Receive = AllocaTion
 	}
 
-	err = c.Createbelong(rep, req)
-	g.Log().Info("errr", req)
-
-	if err != nil {
-		err = gerror.New("分配客户失败")
-		return err
-	}
-	return nil
+	c.Createbelong(customerData, req)
+	return
 }
 
 //客户详情
@@ -332,46 +335,46 @@ func (c *CustomerService) GetEntityById(ids []int64) (entityInfo []*model.CustLi
 	return
 }
 
+//获取客户名称
+func (c *CustomerService) GetCustNameIsExist(name string) (exist bool, err error) {
+	Model := c.Dao //
+	count, err := Model.Where(cust.CustCustomer.Columns.CustName, name).Count()
+	if err != nil {
+		err = myerrors.New("获取用户名称是否存在 GetCustName Sql执行异常", err)
+		return
+	}
+	exist = false
+	if count > 0 {
+		exist = true
+	}
+
+	return
+}
+
 //客户摘要
 func (c *CustomerService) CustAbstract(id int64) (followInfo *model.Follow, err error) {
 	custModel := c.Dao //
 	Model := c.FollowDao
 	count, err := Model.Where(c.FollowDao.Columns.CustId, id).Count()
 	if err != nil {
-
-		err = myerrors.New("获取用户数据失败", err)
-		return
+		return nil, myerrors.New(" CustAbstract Sql执行异常", err)
 	}
 	followInfo = new(model.Follow)
 	followInfo.FollowCount = count
-	//
-
-	followUpdate, err := custModel.Fields(c.Dao.Columns.FollowUpDate).FindOne(id)
+	followTime, err := custModel.Fields(c.Dao.Columns.FollowUpDate, c.Dao.Columns.CreatedTime).FindOne(id)
 	if err != nil {
 		err = myerrors.New("CustAbstract Sql执行错误", err)
 		return
 	}
-	if followUpdate.FollowUpDate == nil {
-		followInfo.NotFollowDay = 0
-		return
-	}
-
-	g.Log().Info("fasa1211", followUpdate)
-	//g.Log().Info("find", followUpdate)
-	//if err != nil {
-	//	g.Log().Error(err)
-	//	myerrors.New("获取用户数据失败", err)
-	//	return
-	//}
-	//if followUpdate.FollowUpDate != nil {
-	//	followInfo.NotFollowDay = 0
-	//	return
-	//}
-	upDate := gtime.New(followUpdate.FollowUpDate)
 	now := gtime.Now()
-	//
-	poor := now.Sub(upDate)
-	hours := float64(poor.Hours() / 24)
+	var hours float64
+	if followTime.FollowUpDate == nil {
+		poor := now.Sub(gtime.New(followTime.CreatedTime))
+		hours = float64(poor.Hours() / 24)
+	} else {
+		poor := now.Sub(gtime.New(followTime.FollowUpDate))
+		hours = float64(poor.Hours() / 24)
+	}
 	if hours < 0 {
 		followInfo.NotFollowDay = 0
 	} else {
@@ -397,9 +400,7 @@ func (c *CustomerService) UpdateBytransfer(req *model.DistriCustomer) (err error
 	if err != nil {
 		return
 	}
-
 	err = c.Createbelong(data, req)
-	g.Log().Info("err", err)
 	if err != nil {
 		return
 	}
@@ -420,7 +421,7 @@ func (c *CustomerService) updateCustomer(ids []int64, salesId int64, salesName s
 	}).Where(cust.CustCustomer.Columns.Id+" in (?)", ids).Update()
 
 	if err != nil {
-		err = myerrors.New("updateCustomer 变更执行失败", err)
+		err = myerrors.New("updateCustomer 变更Sql执行失败", err)
 		return err
 	}
 	return nil
@@ -428,10 +429,9 @@ func (c *CustomerService) updateCustomer(ids []int64, salesId int64, salesName s
 
 //客户操作日志
 func (c *CustomerService) OperationLog(ctx context.Context, ids []int64, req *model.AddCustomerDynameicsReq) (err error) {
-	g.Log("fdasfsa", gconv.String(ctx))
 	cusDynameics := new(model.CustCustomerDynamics)
 	if err = gconv.Struct(req, cusDynameics); err != nil {
-		g.Log().Info("error", err)
+		err = myerrors.NewMsgError(nil, "操作日志验证结构体失败")
 		return
 	}
 	Model := c.DynamicsDao.M
@@ -467,11 +467,10 @@ func (c *CustomerService) OperationLog(ctx context.Context, ids []int64, req *mo
 
 //客户动态
 func (c *CustomerService) DynamicsList(req *model.CustomerDynameicsReq) (total int, result []interface{}, err error) {
-	Model := c.DynamicsDao.M
-	total, err = Model.Fields().Count()
+	Model := c.DynamicsDao
+	total, err = Model.Where("cust_id = ", req.CustId).Count()
 	if err != nil {
-		g.Log().Error(err)
-		err = gerror.New("获取总行数失败")
+		err = myerrors.New("DynamicsList Sql执行异常", err)
 		return
 	}
 	//if req.PageNum == 0 {
@@ -492,9 +491,7 @@ func (c *CustomerService) DynamicsList(req *model.CustomerDynameicsReq) (total i
 		})
 
 	}
-	//g.Log().Info("DynamicsList----", dynamicsList)
-	//result = append(result, dynamicsList)
-	//g.Log().Info("Dy---", result)
+	result = append(result, dynamicsList)
 	return
 }
 
@@ -504,16 +501,21 @@ func (c *CustomerService) Mergecustomer(req *model.MergecustomerRep) (err error)
 	//ContactModel := c.ContactDao.M
 	BelongDao := c.BelongDao
 	//当前目标客户是否存在
-	FindOne, err := Model.Where(c.Dao.Columns.DeletedTime+" is  null").Where(c.Dao.Columns.Id, req.Id).FindOne()
-	if err != nil || FindOne.IsEmpty() {
-		err = gerror.New("该数据不存在")
+	customerCount, err := Model.Where(c.Dao.Columns.Id, req.Id).Count()
+	if err != nil {
+		err = myerrors.New("Mergecustomer 合并客户 Sql执行异常", err)
+		return
+	}
+	if customerCount == 0 {
+		err = myerrors.NewMsgError(nil, "该客户不存在")
 		return
 	}
 	ContactModel := c.ContactDao
 	_, err = ContactModel.Where(c.ContactDao.Columns.CustId+" in (?)", req.ChooseId).WhereOr(c.ContactDao.Columns.CustId, req.Id).Delete()
 	if err != nil {
-		err = gerror.New("合并联系人失败")
+		err = myerrors.New("Mergecustomer 合并联系人 Sql执行异常", err)
 		return
+
 	}
 	CustomertData := new(model.CustomerAddSeq)
 	if err = gconv.Struct(req, CustomertData); err != nil {
@@ -524,15 +526,19 @@ func (c *CustomerService) Mergecustomer(req *model.MergecustomerRep) (err error)
 		c.Dao.Columns.CreatedName, c.Dao.Columns.Id,
 		c.Dao.Columns.CustCode).WherePri(c.Dao.Columns.Id, req.Id).Update(CustomertData)
 	if err != nil {
-		err = gerror.New("合并失败")
+		err = myerrors.New("Mergecustomer 合并客户 update Sql执行异常", err)
 		return
 	}
 	//删除被合并的客户信息
-	Model.Where(c.Dao.Columns.Id+" in (?)", req.ChooseId).Delete()
+	_, err = Model.Where(c.Dao.Columns.Id+" in (?)", req.ChooseId).Delete()
+	if err != nil {
+		err = myerrors.New("Mergecustomer 删除被合并的客户信息 Sql执行异常", err)
+		return
+	}
 	//删除 所选客户销售联系人
 	_, err = BelongDao.Where(c.BelongDao.Columns.CustId+" in (?)", req.ChooseId).WhereOr(c.BelongDao.Columns.CustId, req.Id).Delete()
 	if err != nil {
-		err = gerror.New("合并失败")
+		err = myerrors.New("Mergecustomer 删除所选客户销售联系人 Sql执行异常", err)
 		return
 	}
 
@@ -543,26 +549,22 @@ func (c *CustomerService) Mergecustomer(req *model.MergecustomerRep) (err error)
 	req.AddCustomerBelong.OpnPeople = c.GetCxtUserName()
 	req.AddCustomerBelong.OpnDatetime = gtime.Now()
 	req.AddCustomerBelong.SaleName = req.SalesName
-	err = belongService.Create(req.AddCustomerBelong)
-	if err != nil {
-		err = gerror.New("合并失败")
-		return
-	}
+	belongService.Create(req.AddCustomerBelong)
 	return
 }
 
 //联系人(合并)
 func (c *CustomerService) Createcontact(id int, Ids []int64, req *model.CustCustomerContactSeq) (err error) {
-	ContactModel := c.ContactDao.M
+	ContactModel := c.ContactDao
 	_, err = ContactModel.Where(c.ContactDao.Columns.CustId+" in (?)", Ids).WhereOr(c.ContactDao.Columns.CustId, id).Delete()
 	if err != nil {
-		err = gerror.New("合并联系人失败")
+		err = myerrors.New("Createcontact  合并删除联系人 Sql执行异常", err)
 		return
 	}
 	contactService := c.ContanctServer //new(CustomercontactService)
 	err = contactService.Create(req)
 	if err != nil {
-		err = gerror.New("合并联系人失败")
+		err = myerrors.New("Createcontact  合并删除并创建联系人 Sql执行异常", err)
 		return
 	}
 	return

+ 20 - 24
opms_parent/app/service/cust/cust_customer_contact.go

@@ -2,10 +2,8 @@ package cust
 
 import (
 	"context"
-	"fmt"
 
-	"github.com/gogf/gf/errors/gerror"
-	"github.com/gogf/gf/frame/g"
+	"dashoo.cn/opms_libary/myerrors"
 	"github.com/gogf/gf/util/gconv"
 
 	"dashoo.cn/micro/app/dao/cust"
@@ -35,28 +33,30 @@ func NewCustomerContactService(ctx context.Context) (svc *CustomercontactService
 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)
+		err = myerrors.NewMsgError(nil, "添加联系人 验证失败")
 		return
 	}
 	service.SetCreatedInfo(contact, c.GetCxtUserId(), c.GetCxtUserName())
-	Model := c.Dao.M
-	res, err := Model.Insert(contact)
+	Model := c.Dao
+	_, err = Model.Insert(contact)
 	if err != nil {
+		err = myerrors.New("添加联系人,Create Sql执行异常", err)
 		return
 	}
-
-	InsertId, _ := res.LastInsertId()
-	fmt.Println(InsertId)
 	return
 }
 
 //修改联系人
 func (c *CustomercontactService) UpdateById(req *model.UpdateCustCustomerContactSeq) (err error) {
 	Model := c.Dao.M
-	record, err := Model.FindOne("Id", req.Id)
-	if err != nil || record.IsEmpty() {
-		err = gerror.New("该数据不存在")
-		return err
+	contactCount, err := Model.Count("Id", req.Id)
+	if err != nil {
+		err = myerrors.New("修改联系人,FindOne Sql执行异常", err)
+		return
+	}
+	if contactCount == 0 {
+		err = myerrors.NewMsgError(nil, "修改联系人信息不存在")
+		return
 	}
 	CustomertData := new(model.CustCustomerContact)
 	if err = gconv.Struct(req, CustomertData); err != nil {
@@ -67,8 +67,7 @@ func (c *CustomercontactService) UpdateById(req *model.UpdateCustCustomerContact
 		WherePri(c.Dao.Columns.Id, req.Id).Update(CustomertData)
 
 	if err != nil {
-		g.Log().Error(err)
-		err = gerror.New("修改用户信息失败")
+		err = myerrors.New("修改联系人,UpdateById Sql执行异常", err)
 		return
 	}
 	return
@@ -76,27 +75,24 @@ func (c *CustomercontactService) UpdateById(req *model.UpdateCustCustomerContact
 
 //获取联系人信息
 func (c *CustomercontactService) GetList(CustId int) (Info []*model.CustCustomerContactInfo, err error) {
-	Model := c.Dao.M
+	Model := c.Dao
 	err = Model.Where(c.Dao.Columns.CustId, CustId).Where(c.Dao.Columns.DeletedTime + " is null").Scan(&Info)
 	if err != nil {
-		g.Log().Error(err)
-		err = gerror.New("获取联系人信息失败")
+		err = myerrors.New("获取联系人信息,GetList Sql执行异常", err)
 		return
+
 	}
 	return
 }
 
 //删除联系人
 func (c *CustomercontactService) DeleteById(id int) error {
-	Model := c.Dao.M
-
-	//deleteTime := gtime.Now()
+	Model := c.Dao
 	// 删除客户联系人表
 	_, err := Model.Where(c.Dao.Columns.Id, id).Delete()
+
 	if err != nil {
-		g.Log().Error(err)
-		err = gerror.New("删除数据失败")
-		return err
+		return myerrors.New("删除联系人,DeleteById Sql执行异常", err)
 	}
 	return nil
 }

BIN
opms_parent/opms_parent