소스 검색

Merge branch 'aj_overseas_custorm' into debug

hongze 1 년 전
부모
커밋
579ea843a7
5개의 변경된 파일232개의 추가작업 그리고 0개의 파일을 삭제
  1. 1 0
      controllers/overseas_custom/custom.go
  2. 138 0
      controllers/overseas_custom/sale.go
  3. 10 0
      models/db.go
  4. 77 0
      models/overseas_custom/overseas_custom_seller.go
  5. 6 0
      routers/router.go

+ 1 - 0
controllers/overseas_custom/custom.go

@@ -0,0 +1 @@
+package overseas_custom

+ 138 - 0
controllers/overseas_custom/sale.go

@@ -0,0 +1,138 @@
+package overseas_custom
+
+import (
+	"encoding/json"
+	"hongze/hz_crm_api/controllers"
+	"hongze/hz_crm_api/models"
+	"hongze/hz_crm_api/models/overseas_custom"
+	"hongze/hz_crm_api/utils"
+	"time"
+)
+
+// 海外客户
+
+type OverseasCustomController struct {
+	controllers.BaseAuthController
+}
+
+// @Title 保存销售
+// @Description 保存销售
+// @Param	request  body  overseas_custom.OverseasCustomerSaleSaveReq  true  "type json string"
+// @Success Ret=200 操作成功
+// @router /sale/save [post]
+func (this *OverseasCustomController) SaleSave() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	var req overseas_custom.OverseasCustomerSaleSaveReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if len(req.AddSellerIdArr) <= 0 && len(req.DelSellerIdArr) <= 0 {
+		br.Msg = "参数错误!"
+		return
+	}
+	obj := new(overseas_custom.OverseasCustomerSale)
+	list, err := obj.GetOverseasCustomerSaleAll()
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "保存失败!"
+		br.ErrMsg = "保存失败,GetOverseasCustomerSaleAll,Err:" + err.Error()
+		return
+	}
+
+	existMap := make(map[int]string)
+	for _, v := range list {
+		existMap[v.SellerId] = v.RealName
+	}
+	if len(req.AddSellerIdArr) > 0 {
+		for _, v := range req.AddSellerIdArr {
+			if _, ok := existMap[v]; !ok {
+				item := new(overseas_custom.OverseasCustomerSale)
+				item.SellerId = v
+				item.CreateTime = time.Now()
+				err = item.Create()
+				if err != nil {
+					br.Msg = "保存失败!"
+					br.ErrMsg = "保存失败,Err:" + err.Error()
+					return
+				}
+				err = obj.HandelOverseasCustomerSale(v, 1)
+				if err != nil {
+					br.Msg = "保存失败!"
+					br.ErrMsg = "保存失败,处理特定销售客户信息失败,Err:" + err.Error()
+					return
+				}
+			}
+		}
+	}
+
+	if len(req.DelSellerIdArr) > 0 {
+		for _, id := range req.DelSellerIdArr {
+			obj.SellerId = id
+			err = obj.Delete()
+			if err != nil {
+				br.Msg = "保存失败!"
+				br.ErrMsg = "删除销售失败,Err:" + err.Error()
+				return
+			}
+			err = obj.HandelOverseasCustomerSale(id, 1)
+			if err != nil {
+				br.Msg = "保存失败!"
+				br.ErrMsg = "保存失败,处理特定销售客户信息失败,Err:" + err.Error()
+				return
+			}
+		}
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "保存成功"
+}
+
+// @Title 获取已保存销售列表
+// @Description 获取已保存销售列表
+// @Success 200 {object} overseas_custom.OverseasCustomerSaleView
+// @router /sale/list [get]
+func (this *OverseasCustomController) SaleList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	obj := new(overseas_custom.OverseasCustomerSale)
+	list, err := obj.GetOverseasCustomerSaleAll()
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取失败!"
+		br.ErrMsg = "获取失败,GetOverseasCustomerSaleAll,Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = list
+}

+ 10 - 0
models/db.go

@@ -19,6 +19,7 @@ import (
 	"hongze/hz_crm_api/models/eta_training_video"
 	"hongze/hz_crm_api/models/eta_trial"
 	"hongze/hz_crm_api/models/help_doc"
+	"hongze/hz_crm_api/models/overseas_custom"
 	"hongze/hz_crm_api/models/roadshow"
 	"hongze/hz_crm_api/models/seal"
 	"hongze/hz_crm_api/models/system"
@@ -204,6 +205,9 @@ func init() {
 
 	// ETA培训视频
 	initEtaTrainingVideo()
+
+	//海外客户
+	initOverseasCustom()
 }
 
 // initSystem 系统表 数据表
@@ -721,3 +725,9 @@ func initEtaTrainingVideo() {
 		new(eta_training_video.EtaTrainingVideoClassifyRelate), // 分类关联表
 	)
 }
+
+func initOverseasCustom() {
+	orm.RegisterModel(
+		new(overseas_custom.OverseasCustomerSale),
+	)
+}

+ 77 - 0
models/overseas_custom/overseas_custom_seller.go

@@ -0,0 +1,77 @@
+package overseas_custom
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+// 海外客户销售
+type OverseasCustomerSale struct {
+	OverseasCustomSellerId int       `orm:"column(overseas_custorm_seller_id);pk"`
+	SellerId               int       `description:"销售id"`
+	CreateTime             time.Time `description:"创建时间"`
+}
+
+// 海外客户销售
+type OverseasCustomerSaleView struct {
+	SellerId int    `description:"销售id"`
+	RealName string `description:"销售姓名"`
+}
+
+func (m *OverseasCustomerSale) Create() (err error) {
+	o := orm.NewOrm()
+	id, err := o.Insert(m)
+	if err != nil {
+		return
+	}
+	m.OverseasCustomSellerId = int(id)
+	return
+}
+
+func (m *OverseasCustomerSale) Delete() (err error) {
+	o := orm.NewOrm()
+	sql := ` DELETE FROM overseas_custom_seller WHERE seller_id=? `
+	_, err = o.Raw(sql, m.SellerId).Exec()
+	return
+}
+
+func (m *OverseasCustomerSale) TableName() string {
+	return "overseas_custom_seller"
+}
+
+// OverseasCustomerSaleSaveReq 保存销售
+type OverseasCustomerSaleSaveReq struct {
+	AddSellerIdArr []int `description:"新增销售id,数组"`
+	DelSellerIdArr []int `description:"删除销售id,数组"`
+}
+
+func (m *OverseasCustomerSale) GetOverseasCustomerSaleAll() (list []*OverseasCustomerSaleView, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT a.*,b.real_name FROM overseas_custom_seller AS a
+			INNER JOIN admin AS b ON a.seller_id=b.admin_id `
+	_, err = o.Raw(sql).QueryRows(&list)
+	return
+}
+
+type AdminItem struct {
+	AdminId   int    `description:"系统用户id"`
+	AdminName string `description:"系统用户名称"`
+	RealName  string `description:"系统用户姓名"`
+	Mobile    string `description:"手机号"`
+}
+
+func (m *OverseasCustomerSale) HandelOverseasCustomerSale(sellerId, isOverseas int) (err error) {
+	o := orm.NewOrm()
+	sellerItem := new(AdminItem)
+	sql := ` SELECT * FROM admin WHERE admin_id=? `
+	err = o.Raw(sql, sellerId).QueryRow(&sellerItem)
+	if err != nil {
+		return err
+	}
+	if sellerItem.Mobile == "13065778668" {
+		sql = ` UPDATE company_product SET is_overseas = ? WHERE seller_id=? `
+		_, err = o.Raw(sql, isOverseas, sellerId).Exec()
+		return err
+	}
+	return err
+}

+ 6 - 0
routers/router.go

@@ -24,6 +24,7 @@ import (
 	"hongze/hz_crm_api/controllers/eta_business"
 	"hongze/hz_crm_api/controllers/eta_training_video"
 	"hongze/hz_crm_api/controllers/help_doc"
+	"hongze/hz_crm_api/controllers/overseas_custom"
 	"hongze/hz_crm_api/controllers/roadshow"
 	"hongze/hz_crm_api/controllers/seal"
 	"hongze/hz_crm_api/controllers/yb"
@@ -338,6 +339,11 @@ func init() {
 				&eta_training_video.EtaTrainingVideoTagController{},
 			),
 		),
+		web.NSNamespace("/overseas_custom",
+			web.NSInclude(
+				&overseas_custom.OverseasCustomController{},
+			),
+		),
 	)
 	web.AddNamespace(ns)
 }