123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- package crm
- import (
- "fmt"
- "github.com/gin-gonic/gin"
- "github.com/go-playground/validator/v10"
- "hongze/fms_api/controller/resp"
- "hongze/fms_api/global"
- "hongze/fms_api/models/crm"
- "hongze/fms_api/models/fms"
- crmService "hongze/fms_api/services/crm"
- )
- // CompanySellerController CRM销售
- type CompanySellerController struct{}
- // List
- // @Title 销售列表
- // @Description 销售列表
- // @Success 200 {object} crm.SellerAdminWithGroupList
- // @router /crm/company_seller/list [get]
- func (rg *CompanySellerController) List(c *gin.Context) {
- // 此处调整为只取销售部门的人员, 而不是原先的根据角色取
- list, e := crmService.GetSellerDepartmentList()
- if e != nil {
- resp.FailData("获取失败", "获取销售列表失败, Err:"+e.Error(), c)
- return
- }
- resp.OkData("获取成功", list, c)
- }
- // GroupList
- // @Title 销售组别列表
- // @Description 销售组别列表
- // @Success 200 {object} crm.SysGroup
- // @router /crm/company_seller/group_list [get]
- func (rg *CompanySellerController) GroupList(c *gin.Context) {
- var req crm.SysGroupListReq
- if e := c.BindQuery(&req); e != nil {
- err, ok := e.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+e.Error(), c)
- return
- }
- resp.FailData("参数解析失败", err.Translate(global.Trans), c)
- return
- }
- var departmentId int
- if req.SellerType == 1 {
- departmentId = crm.SellerDepartmentId
- }else if req.SellerType == 2 {
- departmentId = crm.RaiSellerDepartmentId
- }else if req.SellerType == 0 {
- resp.Fail("请选择销售类型", c)
- return
- }else {
- resp.Fail("请选择正确的销售类型", c)
- return
- }
- groupOB := new(crm.SysGroup)
- cond := `department_id = ? AND parent_id = 0`
- pars := make([]interface{}, 0)
- pars = append(pars, departmentId)
- list, e := groupOB.List(cond, pars)
- if e != nil {
- resp.FailData("获取失败", "获取销售组别列表失败, Err:"+e.Error(), c)
- return
- }
- resp.OkData("获取成功", list, c)
- }
- // List
- // @Title 销售列表
- // @Description 销售列表
- // @Success 200 {object} crm.SellerAdminWithGroupList
- // @router /crm/company_seller/all_list [get]
- func (rg *CompanySellerController) AllList(c *gin.Context) {
- ficcList, raiLits, e := crmService.GetSellerDepartmentListWithGroupAndTeamByDepartment()
- if e != nil {
- resp.FailData("获取销售失败", "Err:"+e.Error(), c)
- return
- }
- respItem := crm.AllSellerResp{
- FiccSeller: ficcList,
- RaiSeller: raiLits,
- }
- resp.OkData("获取成功", respItem, c)
- }
- // List
- // @Title 销售列表
- // @Description 销售列表
- // @Success 200 {object} crm.SellerAdminWithGroupList
- // @router /crm/company_seller/team_list [get]
- func (rg *CompanySellerController) TeamList(c *gin.Context) {
- // 此处调整为只取销售部门的人员, 而不是原先的根据角色取
- list, e := crmService.GetSellerList()
- if e != nil {
- resp.FailData("获取销售失败", "Err:"+e.Error(), c)
- return
- }
- resp.OkData("获取成功", list, c)
- }
- // 修复历史数据表中导入的销售seller_id
- func FIXIncomeHistorySellerId() (err error) {
- //adminCond := ``
- //adminPars := make([]interface{}, 0)
- //adminOB := new(crm.Admin)
- //adminList, e := adminOB.List(adminCond, adminPars)
- //if e != nil {
- // return
- //}
- //sellerMap := make(map[int]*crm.Admin)
- //for i := range adminList {
- // sellerMap[adminList[i].AdminId] = adminList[i]
- //}
- list,err := fms.GetIncomeHistoryList()
- if err != nil {
- return
- }
- sellerList, e := crmService.GetSellerDepartmentListWithEnable()
- if e != nil {
- resp.FailData("获取销售失败", "Err:"+e.Error(), nil)
- return
- }
- sellerMap := make(map[int]*crm.SellerAdminWithGroupTeam)
- for i := range sellerList {
- sellerMap[sellerList[i].SellerId] = sellerList[i]
- }
- for _, v := range list {
- fmt.Println("v:", v.IncomeId)
- if seller, ok := sellerMap[v.SellerId]; ok{
- fmt.Println("更新销售:",v.SellerName)
- v.SellerId = seller.SellerId
- v.GroupId = seller.GroupId
- v.GroupName = seller.GroupName
- v.DepartmentId = seller.DepartmentId
- if e = v.Update([]string{"GroupId","GroupName","DepartmentId"}); e != nil {
- fmt.Println("更新销售失败, Err: " + e.Error())
- return
- }
- }
- }
- return
- }
- // 修复
- func FixContractInvoiceSellerInfoV2() (err error) {
- sellerList, e := crmService.GetSellerDepartmentListWithEnable()
- if e != nil {
- fmt.Println("获取销售列表失败, Err: " + e.Error())
- return
- }
- sellerMap := make(map[int]*crm.SellerAdminWithGroupTeam)
- for i := range sellerList {
- sellerMap[sellerList[i].SellerId] = sellerList[i]
- }
- list,err := fms.GetInvoiceListByFix()
- if err != nil {
- return
- }
- queryRegisterIds := make([]int, 0)
- for i := range list {
- queryRegisterIds = append(queryRegisterIds, list[i].ContractRegisterId)
- }
- cond := `1 = 1`
- pars := make([]interface{}, 0)
- summaryCond := cond
- summaryCond += ` AND a.register_id IN ?`
- summaryPars := pars
- summaryPars = append(summaryPars, queryRegisterIds)
- summaryData, e := fms.GetInvoicePaymentCensusSummaryData(summaryCond, summaryPars)
- if e != nil {
- fmt.Println("err1:",e)
- return
- }
- contractRegisters, err := fms.GetContractInfoByRegisterIds(queryRegisterIds)
- if err != nil {
- fmt.Println("err3:",e)
- return
- }
- registerMap := make(map[int]fms.ContractRegister, 0)
- for _, v := range contractRegisters {
- registerMap[v.ContractRegisterId] = v
- }
- summaryMap := make(map[int]*fms.InvoicePaymentSummaryItem, 0)
- for _, v := range summaryData {
- summaryMap[v.InvoiceId] = v
- summaryMap[v.PaymentId] = v
- }
- for _, v := range list {
- paymentItem := fms.ContractInvoice{}
- paymentItem.ContractInvoiceId = v.ContractInvoiceId
- fmt.Println("paymentItem.ContractInvoiceId:", paymentItem.ContractInvoiceId)
- var seller *crm.SellerAdminWithGroupTeam
- //if v.InvoiceType == 2 || v.InvoiceType == 4 {
- // seller = sellerMap[v.SellerId]
- //} else {
- // seller = sellerMap[v.ContractInvoiceId]
- //}
- if item, ok := summaryMap[v.ContractInvoiceId]; ok{
- seller = sellerMap[item.SellerId]
- }
- if seller == nil {
- register := registerMap[v.ContractRegisterId]
- seller = sellerMap[register.SellerId]
- if seller == nil {
- seller = sellerMap[register.RaiSellerId]
- }
- }
- if seller != nil {
- fmt.Println("SellerName:", seller.SellerName)
- paymentItem.SellerId = seller.SellerId
- paymentItem.SellerName = seller.SellerName
- paymentItem.SellerGroupId = seller.GroupId
- paymentItem.SellerGroupName = seller.GroupName
- paymentItem.SellerTeamId = seller.TeamId
- paymentItem.SellerTeamName = seller.TeamName
- e = paymentItem.Update([]string{"SellerId", "SellerName", "SellerGroupId", "SellerGroupName", "SellerTeamId", "SellerTeamName"})
- if e != nil {
- fmt.Println("err2:",e)
- return
- }
- }
- }
- fmt.Println(len(summaryData))
- return
- }
|