|
@@ -0,0 +1,734 @@
|
|
|
+package cygx
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "fmt"
|
|
|
+ "github.com/rdlucklib/rdluck_tools/paging"
|
|
|
+ "hongze/hz_crm_api/controllers"
|
|
|
+ "hongze/hz_crm_api/models"
|
|
|
+ "hongze/hz_crm_api/models/company"
|
|
|
+ "hongze/hz_crm_api/models/contract"
|
|
|
+ "hongze/hz_crm_api/models/cygx"
|
|
|
+ "hongze/hz_crm_api/models/system"
|
|
|
+ "hongze/hz_crm_api/utils"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+// ContractAllocationController 权益合同派单
|
|
|
+type ContractAllocationController struct {
|
|
|
+ controllers.BaseAuthController
|
|
|
+}
|
|
|
+
|
|
|
+// getQueryParams 获取基础查询信息
|
|
|
+func getQueryParams(condition string, pars []interface{}, sysUser *system.Admin, tableAlias string) (newCondition string, newPars []interface{}) {
|
|
|
+ if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
|
|
|
+ condition += " AND " + tableAlias + "product_id=?"
|
|
|
+ pars = append(pars, 1)
|
|
|
+ } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
|
|
|
+ condition += " AND " + tableAlias + "product_id=?"
|
|
|
+ pars = append(pars, 2)
|
|
|
+ } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FINANCE {
|
|
|
+ //超级管理员账户,不做条件限制
|
|
|
+ } else {
|
|
|
+ //如果不是研究员,那么去找对应的 部门、小组、销售
|
|
|
+ if sysUser.Authority == 0 {
|
|
|
+ //普通用户
|
|
|
+ condition += " AND " + tableAlias + "seller_id=?"
|
|
|
+ pars = append(pars, sysUser.AdminId)
|
|
|
+ } else if sysUser.Authority == 1 {
|
|
|
+ //部门主管
|
|
|
+ condition += " AND " + tableAlias + "department_id=?"
|
|
|
+ pars = append(pars, sysUser.DepartmentId)
|
|
|
+ } else if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
|
|
|
+ //权益小组负责人
|
|
|
+ condition += " AND " + tableAlias + "group_id=?"
|
|
|
+ pars = append(pars, sysUser.GroupId)
|
|
|
+ } else if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
|
|
|
+ //ficc销售主管
|
|
|
+ pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var ids []*string
|
|
|
+ if pid != nil && *pid != 0 {
|
|
|
+ ids, err = company.GetGroupIdsByParentId(*pid)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err.Error())
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err.Error())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var idSlice []string
|
|
|
+ var sid string
|
|
|
+ for _, id := range ids {
|
|
|
+ idSlice = append(idSlice, *id)
|
|
|
+ }
|
|
|
+ //加入父级groupId
|
|
|
+ if *pid > 0 {
|
|
|
+ idSlice = append(idSlice, strconv.Itoa(*pid))
|
|
|
+ } else {
|
|
|
+ idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
|
|
|
+ }
|
|
|
+ sid = strings.Join(idSlice, ",")
|
|
|
+ condition += " AND " + tableAlias + `group_id IN (` + sid + `) `
|
|
|
+ fmt.Println("condition:", condition)
|
|
|
+ //pars = append(pars, sysUser.GroupId)
|
|
|
+ } else if sysUser.Authority == 4 {
|
|
|
+ //ficc小组负责人
|
|
|
+ condition += " AND " + tableAlias + "group_id=?"
|
|
|
+ pars = append(pars, sysUser.GroupId)
|
|
|
+ } else {
|
|
|
+ //不知道什么类型的用户(后面新增的位置类型客户)
|
|
|
+ condition += " AND " + tableAlias + "seller_id=?"
|
|
|
+ pars = append(pars, sysUser.AdminId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ newCondition = condition
|
|
|
+ newPars = pars
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 合同列表
|
|
|
+// @Description 合同列表接口
|
|
|
+// @Param PageSize query int true "每页数据条数"
|
|
|
+// @Param CurrentIndex query int true "当前页页码,从1开始"
|
|
|
+// @Param Keyword query string true "客户名称"
|
|
|
+// @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
|
|
|
+// @Param StartDate query string false "开始日期"
|
|
|
+// @Param EndDate query string false "结束日期"
|
|
|
+// @Param ContractType query string false "合同类型,枚举值:“,`新签合同`,`续约合同`,`补充协议`"
|
|
|
+// @Param FormalType query string false "转正类型,枚举值:“,`标准`,`非标`"
|
|
|
+// @Param IsExport query bool false "是否导出excel,默认是false"
|
|
|
+// @Param IsAllocation query int false "派点状态: -1-默认全部; 0-未派点; 1-已派点"
|
|
|
+// @Success 200 {object} cygx.CompanyContractListResp
|
|
|
+// @router /allocation/company_contract_list [get]
|
|
|
+func (this *ContractAllocationController) CompanyContractList() {
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
+ pageSize, _ := this.GetInt("PageSize")
|
|
|
+ currentIndex, _ := this.GetInt("CurrentIndex")
|
|
|
+ adminId := this.GetString("AdminId")
|
|
|
+ formalType := this.GetString("FormalType")
|
|
|
+ contractType := this.GetString("ContractType")
|
|
|
+ keyword := this.GetString("Keyword")
|
|
|
+ startDate := this.GetString("StartDate")
|
|
|
+ endDate := this.GetString("EndDate")
|
|
|
+ isAllocation, _ := this.GetInt("IsAllocation", -1) // CRM 13.9
|
|
|
+ if startDate == "" {
|
|
|
+ startDate = "2015-01-01"
|
|
|
+ }
|
|
|
+ if endDate == "" {
|
|
|
+ endDate = time.Now().Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ var startSize int
|
|
|
+ if pageSize <= 0 {
|
|
|
+ pageSize = utils.PageSize20
|
|
|
+ }
|
|
|
+ if currentIndex <= 0 {
|
|
|
+ currentIndex = 1
|
|
|
+ }
|
|
|
+ startSize = utils.StartIndex(currentIndex, pageSize)
|
|
|
+ //是否导出报表
|
|
|
+ isExport, _ := this.GetBool("IsExport")
|
|
|
+ if isExport {
|
|
|
+ pageSize = 10000
|
|
|
+ currentIndex = 1
|
|
|
+ }
|
|
|
+
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+
|
|
|
+ //条件
|
|
|
+ if adminId != "" {
|
|
|
+ condition += ` AND c.seller_id in (` + adminId + `) `
|
|
|
+ //pars = append(pars, adminId)
|
|
|
+ } else {
|
|
|
+
|
|
|
+ //根据当前角色来获取查询条件
|
|
|
+ condition, pars = getQueryParams(condition, pars, sysUser, "c.")
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //关键字搜索
|
|
|
+ if keyword != "" {
|
|
|
+ condition += ` and b.company_name like "%` + keyword + `%" `
|
|
|
+ }
|
|
|
+
|
|
|
+ //是否派点
|
|
|
+ if isAllocation != -1 {
|
|
|
+ condition += ` AND a.product_id = ? `
|
|
|
+ pars = append(pars, isAllocation)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 标准非标查询
|
|
|
+ switch formalType {
|
|
|
+ case "标准":
|
|
|
+ condition += ` AND a.source = ? `
|
|
|
+ pars = append(pars, "系统合同")
|
|
|
+ case "非标":
|
|
|
+ condition += ` AND a.source = ? `
|
|
|
+ pars = append(pars, "上传附件")
|
|
|
+ }
|
|
|
+
|
|
|
+ if contractType != "" {
|
|
|
+ condition += ` AND a.contract_type = ? `
|
|
|
+ pars = append(pars, contractType)
|
|
|
+ }
|
|
|
+
|
|
|
+ //默认只查询权益 2023-06-01 之后的合同
|
|
|
+ condition += ` AND c.product_id = ? AND a.start_date > ? `
|
|
|
+ pars = append(pars, 2, "2023-06-01")
|
|
|
+
|
|
|
+ var list []*cygx.CompanyContractResp
|
|
|
+
|
|
|
+ total, err := cygx.GetCompanyContractCountJoinCompany(condition, pars)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //列表页数据
|
|
|
+ list, err = cygx.GetCompanyContractListJoinCompany(condition, pars, startSize, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ listLen := len(list)
|
|
|
+ if listLen == 0 {
|
|
|
+ list = make([]*cygx.CompanyContractResp, 0)
|
|
|
+ } else {
|
|
|
+
|
|
|
+ var contractCodes []string
|
|
|
+ for _, v := range list {
|
|
|
+ switch v.Source {
|
|
|
+ case "系统合同":
|
|
|
+ v.FormalType = "标准"
|
|
|
+ case "上传附件":
|
|
|
+ v.FormalType = "非标"
|
|
|
+ }
|
|
|
+ contractCodes = append(contractCodes, v.ContractCode)
|
|
|
+ }
|
|
|
+
|
|
|
+ lencontractCodes := len(contractCodes)
|
|
|
+ if lencontractCodes > 0 {
|
|
|
+ //获取标准合同的ID,这里上面的查询已经关联了三张表,拆分吧。。。
|
|
|
+ condition = ""
|
|
|
+ joinStr := ""
|
|
|
+ pars = make([]interface{}, 0)
|
|
|
+ condition = " AND a.contract_code IN (" + utils.GetOrmInReplace(lencontractCodes) + ") "
|
|
|
+ pars = append(pars, contractCodes)
|
|
|
+ listContract, err := contract.GetContractList(condition, joinStr, pars, 0, lencontractCodes)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取合同列表失败!"
|
|
|
+ br.ErrMsg = "获取合同列表失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ mapContractCode := make(map[string]int)
|
|
|
+ for _, v := range listContract {
|
|
|
+ mapContractCode[v.ContractCode] = v.ContractId
|
|
|
+ }
|
|
|
+ for _, v := range list {
|
|
|
+ v.ContractId = mapContractCode[v.ContractCode]
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ page := paging.GetPaging(currentIndex, pageSize, total)
|
|
|
+ resp := cygx.CompanyContractListResp{
|
|
|
+ Paging: page,
|
|
|
+ List: list,
|
|
|
+ }
|
|
|
+
|
|
|
+ //导出excel
|
|
|
+ if isExport {
|
|
|
+ //IncrementalCompanyListExport(this, dataType, resp, br)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = resp
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 详情
|
|
|
+// @Description 获取详情接口
|
|
|
+// @Param CompanyContractId query int true "ID"
|
|
|
+// @Param ShowDetail query bool false "是否是派点详情展示"
|
|
|
+// @Success Ret=200 {object} cygx.CygxAllocationCompanyContractDetailResp
|
|
|
+// @router /allocation/detail [get]
|
|
|
+func (this *ContractAllocationController) CompanyContracDetail() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ AdminUser := this.SysUser
|
|
|
+ if AdminUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,用户信息为空"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp := new(cygx.CygxAllocationCompanyContractDetailResp)
|
|
|
+ companyContractId, _ := this.GetInt("CompanyContractId")
|
|
|
+ if companyContractId < 1 {
|
|
|
+ br.Msg = "请输入详情ID"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ showDetail, _ := this.GetBool("ShowDetail", false)
|
|
|
+ contractItem, err := company.GetCompanyContractById(companyContractId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取信息失败"
|
|
|
+ br.ErrMsg = "获取合同信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ total, err := cygx.GetCygxAllocationCompanyContractCountByCompanyContractId(companyContractId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取信息失败"
|
|
|
+ br.ErrMsg = "获取合同信息失败,GetCygxAllocationCompanyContractCountByCompanyContractId Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //var contractPermissionList []*company.ContractPermissionList
|
|
|
+ expMap := map[int]string{0: "(3w)", 1: "(5w)"} // 买方研选价格
|
|
|
+
|
|
|
+ //classifyName := "权益"
|
|
|
+
|
|
|
+ //plist := new(company.ContractPermissionList)
|
|
|
+ hasPermissions, e := company.GetCompanyContractPermissionByCompanyContractId(companyContractId)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取合同权限信息失败,Err:" + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ hasMap := make(map[int]*company.CompanyContractPermission)
|
|
|
+ for _, p := range hasPermissions {
|
|
|
+ hasMap[p.ChartPermissionId] = p
|
|
|
+ }
|
|
|
+ checkItems := make([]*company.PermissionLookItem, 0)
|
|
|
+ // PS:本来想把这个移到循环外面去优化一下...但是发现有指针引用变量被改掉的问题, BUG太多了改不完了先这样吧=_=!
|
|
|
+ raiPermissions, e := company.GetPermissionLookItemsExt("2", utils.COMPANY_PRODUCT_RAI_NAME)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取权益权限列表失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ mapPermissionNameHave := make(map[string]bool) // 判断合同是否存在某一行业权限种类
|
|
|
+ var expensiveYx int
|
|
|
+ for _, n := range raiPermissions {
|
|
|
+ match := hasMap[n.ChartPermissionId]
|
|
|
+ if match == nil {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ // 升级
|
|
|
+ if match.IsUpgrade == 1 {
|
|
|
+ n.IsUpgrade = 1
|
|
|
+ checkItems = append(checkItems, n)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ mapPermissionNameHave[n.PermissionName] = true
|
|
|
+ // 买方研选(3w/5w)
|
|
|
+ if n.PermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
|
|
|
+ expensiveYx = match.ExpensiveYx
|
|
|
+ n.PermissionName += expMap[match.ExpensiveYx]
|
|
|
+ checkItems = append(checkItems, n)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ checkItems = append(checkItems, n)
|
|
|
+ }
|
|
|
+ //plist.Items = checkItems
|
|
|
+ //plist.ClassifyName = utils.COMPANY_PRODUCT_RAI_NAME
|
|
|
+ //contractPermissionList = append(contractPermissionList, plist)
|
|
|
+
|
|
|
+ //// CRM8.8-权限主客观合并
|
|
|
+ //newPermissionLookList := contractService.HandleEquityContractPermissionList(contractPermissionList)
|
|
|
+ //for _, v := range newPermissionLookList {
|
|
|
+ // for _, v2 := range v.Items {
|
|
|
+ // fmt.Println(v2.PermissionName)
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ resp.Money = contractItem.Money / 10000
|
|
|
+ //有研选时,对研选套餐类型做文案处理
|
|
|
+ respItemYx := new(cygx.AllocationPermissionListResp)
|
|
|
+ if mapPermissionNameHave[utils.CHART_PERMISSION_NAME_MF_YANXUAN] {
|
|
|
+ var moneyYx float64
|
|
|
+ if expensiveYx == 0 {
|
|
|
+ moneyYx = 3
|
|
|
+ }
|
|
|
+ if expensiveYx == 1 {
|
|
|
+ moneyYx = 5
|
|
|
+ }
|
|
|
+ resp.TotalPointsContent = fmt.Sprint(resp.Money, "W,", "其中", moneyYx, "w默认归属买方研选,请对剩余", resp.Money-moneyYx, "w按照100%进行比值分配")
|
|
|
+ resp.Money = resp.Money - moneyYx
|
|
|
+ respItemYx.Proportion = moneyYx
|
|
|
+ respItemYx.ChartPermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
|
|
|
+ respItemYx.List = append(respItemYx.List, &cygx.AllocationRealNameListResp{utils.CHART_PERMISSION_NAME_MF_YANXUAN, 0, 0})
|
|
|
+ } else {
|
|
|
+ resp.TotalPointsContent = fmt.Sprint(resp.Money, "W")
|
|
|
+ }
|
|
|
+
|
|
|
+ sysUserList, err := cygx.GetAskEmailList()
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,GetAskEmailList Err: " + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ mapPermissionUser := make(map[string][]*cygx.AllocationRealNameListResp)
|
|
|
+
|
|
|
+ var respList []*cygx.AllocationPermissionListResp
|
|
|
+ if total == 0 {
|
|
|
+ for _, v := range sysUserList {
|
|
|
+ if !mapPermissionNameHave[v.ChartPermissionName] {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ item := new(cygx.AllocationRealNameListResp)
|
|
|
+ item.RealName = v.Name
|
|
|
+ mapPermissionUser[v.ChartPermissionName] = append(mapPermissionUser[v.ChartPermissionName], item)
|
|
|
+ }
|
|
|
+
|
|
|
+ for k, v := range mapPermissionUser {
|
|
|
+ respItem := new(cygx.AllocationPermissionListResp)
|
|
|
+ respItem.ChartPermissionName = k
|
|
|
+ respItem.List = v
|
|
|
+ respList = append(respList, respItem)
|
|
|
+ }
|
|
|
+ if respItemYx.ChartPermissionName != "" {
|
|
|
+ respList = append(respList, respItemYx)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ listUser, err := cygx.GetCygxAllocationCompanyContractListById(companyContractId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,GetCygxAllocationCompanyContractListById Err: " + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range listUser {
|
|
|
+ if showDetail && v.Proportion == 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ item := new(cygx.AllocationRealNameListResp)
|
|
|
+ item.RealName = v.RealName
|
|
|
+ item.Money = v.Money
|
|
|
+ item.Proportion = v.Proportion
|
|
|
+ mapPermissionUser[v.ChartPermissionName] = append(mapPermissionUser[v.ChartPermissionName], item)
|
|
|
+ }
|
|
|
+ listPermission, err := cygx.GetCygxAllocationCompanyContractPermissionListById(companyContractId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,GetCygxAllocationCompanyContractPermissionListById Err: " + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range listPermission {
|
|
|
+ if showDetail && v.Proportion == 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ respItem := new(cygx.AllocationPermissionListResp)
|
|
|
+ respItem.ChartPermissionName = v.ChartPermissionName
|
|
|
+ respItem.Money = v.Money
|
|
|
+ respItem.Proportion = v.Proportion
|
|
|
+ respItem.List = mapPermissionUser[v.ChartPermissionName]
|
|
|
+ respList = append(respList, respItem)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ resp.List = respList
|
|
|
+ resp.CompanyContractId = companyContractId
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = resp
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 更新派点
|
|
|
+// @Description 更新派点接口
|
|
|
+// @Param request body cygx.AddProductInteriorReq true "type json string"
|
|
|
+// @Success 200 {object} "保存成功"
|
|
|
+// @router /allocation/update [post]
|
|
|
+func (this *ContractAllocationController) CompanyContracUpdate() {
|
|
|
+ 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 cygx.UpdateAllocationCompanyContractReq
|
|
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ companyContractId := req.CompanyContractId
|
|
|
+ if companyContractId == 0 {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "参数错误,id不可为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ list := req.List
|
|
|
+ var items []*cygx.CygxAllocationCompanyContract
|
|
|
+ var itemsPermission []*cygx.CygxAllocationCompanyContractPermission
|
|
|
+
|
|
|
+ for _, v := range list {
|
|
|
+ itemPermission := new(cygx.CygxAllocationCompanyContractPermission)
|
|
|
+ itemPermission.CompanyContractId = companyContractId
|
|
|
+ itemPermission.AdminId = sysUser.AdminId
|
|
|
+ itemPermission.AdminName = sysUser.RealName
|
|
|
+ itemPermission.Proportion = v.Proportion
|
|
|
+ itemPermission.Money = v.Money
|
|
|
+ itemPermission.ChartPermissionName = v.ChartPermissionName
|
|
|
+ itemPermission.CreateTime = time.Now()
|
|
|
+ itemPermission.ModifyTime = time.Now()
|
|
|
+ itemsPermission = append(itemsPermission, itemPermission)
|
|
|
+
|
|
|
+ for _, v2 := range v.List {
|
|
|
+ item := new(cygx.CygxAllocationCompanyContract)
|
|
|
+ item.CompanyContractId = companyContractId
|
|
|
+ item.AdminId = sysUser.AdminId
|
|
|
+ item.AdminName = sysUser.RealName
|
|
|
+ item.Proportion = v2.Proportion
|
|
|
+ item.Money = v2.Money
|
|
|
+ item.RealName = v2.RealName
|
|
|
+ item.ChartPermissionName = v.ChartPermissionName
|
|
|
+ item.CreateTime = time.Now()
|
|
|
+ item.ModifyTime = time.Now()
|
|
|
+ items = append(items, item)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ err = cygx.AddAndUpdateCygxAllocationCompanyContract(items, itemsPermission, companyContractId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "操作失败,AddAndUpdateCygxAllocationCompanyContract Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.IsAddLog = true
|
|
|
+ br.Msg = "操作成功"
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 研究员派点统计
|
|
|
+// @Description 研究员派点统计接口
|
|
|
+// @Param PageSize query int true "每页数据条数"
|
|
|
+// @Param CurrentIndex query int true "当前页页码,从1开始"
|
|
|
+// @Param Keyword query string true "客户名称"
|
|
|
+// @Param StartDate query string false "开始日期"
|
|
|
+// @Param EndDate query string false "结束日期"
|
|
|
+// @Param IsExport query bool false "是否导出excel,默认是false"
|
|
|
+// @Success 200 {object} cygx.CompanyContractListResp
|
|
|
+// @router /allocation/statistics [get]
|
|
|
+func (this *ContractAllocationController) CompanyContractStatistics() {
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
+ keyword := this.GetString("Keyword")
|
|
|
+ startDate := this.GetString("StartDate")
|
|
|
+ endDate := this.GetString("EndDate")
|
|
|
+ if startDate == "" {
|
|
|
+ startDate = "2015-01-01"
|
|
|
+ }
|
|
|
+ if endDate == "" {
|
|
|
+ endDate = time.Now().Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+
|
|
|
+ //是否导出报表
|
|
|
+ isExport, _ := this.GetBool("IsExport")
|
|
|
+
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+
|
|
|
+ //根据当前角色来获取查询条件
|
|
|
+ condition, pars = getQueryParams(condition, pars, sysUser, "c.")
|
|
|
+
|
|
|
+ //关键字搜索
|
|
|
+ if keyword != "" {
|
|
|
+ condition += ` and b.company_name like "%` + keyword + `%" `
|
|
|
+ }
|
|
|
+
|
|
|
+ //默认只查询权益 2023-06-01 之后的合同
|
|
|
+ condition += ` AND c.product_id = ? AND a.start_date > ? `
|
|
|
+ pars = append(pars, 2, "2023-06-01")
|
|
|
+
|
|
|
+ //列表页数据
|
|
|
+ listContract, err := cygx.GetCompanyContractListJoinCompany(condition, pars, 0, 1000)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var companyContractIds []int
|
|
|
+ for _, v := range listContract {
|
|
|
+ companyContractIds = append(companyContractIds, v.CompanyContractId)
|
|
|
+ }
|
|
|
+
|
|
|
+ lenArr := len(companyContractIds)
|
|
|
+ mapUserAllocation := make(map[string]float64) // 关联合同
|
|
|
+ mapUserMoney := make(map[string]float64) // 派点金额
|
|
|
+ mapPermissionAllocation := make(map[string]float64)
|
|
|
+ mapPermissionMoney := make(map[string]float64)
|
|
|
+
|
|
|
+ totalContract := lenArr //所有的关联合同
|
|
|
+ var totalMoney float64 //所有的关联合同的金额 单位万
|
|
|
+ if lenArr > 0 {
|
|
|
+ var conditionAllocation string
|
|
|
+ var parsAllocation []interface{}
|
|
|
+ allocationCompanyContractList, err := cygx.GetCygxAllocationCompanyContractList(conditionAllocation, parsAllocation)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range allocationCompanyContractList {
|
|
|
+ if v.Proportion != 0 {
|
|
|
+ mapUserAllocation[v.RealName] += 1
|
|
|
+ mapUserMoney[v.RealName] += v.Money
|
|
|
+ mapPermissionAllocation[v.ChartPermissionName] += 1
|
|
|
+ mapPermissionMoney[v.ChartPermissionName] += v.Money
|
|
|
+
|
|
|
+ totalMoney += v.Money
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sysUserList, err := cygx.GetAskEmailList()
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,GetAskEmailList Err: " + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ mapPermissionUser := make(map[string][]*cygx.AllocationRealNameStatisticsListResp)
|
|
|
+
|
|
|
+ for _, v := range sysUserList {
|
|
|
+ item := new(cygx.AllocationRealNameStatisticsListResp)
|
|
|
+ item.RealName = v.Name
|
|
|
+ item.TotalRelatedContract = mapUserAllocation[v.Name]
|
|
|
+ item.TotalDispatchPoint = fmt.Sprint(mapUserMoney[v.Name])
|
|
|
+ if item.TotalDispatchPoint == "" {
|
|
|
+ item.TotalDispatchPoint = "0"
|
|
|
+ }
|
|
|
+ //组内占比
|
|
|
+ item.GroupProportion = fmt.Sprint(mapUserMoney[v.Name] / mapPermissionMoney[v.ChartPermissionName] * 100)
|
|
|
+ if item.GroupProportion == "" {
|
|
|
+ item.GroupProportion = "0"
|
|
|
+ }
|
|
|
+ item.GroupProportion += "%"
|
|
|
+
|
|
|
+ //部门占比
|
|
|
+ item.DepartmentProportion = fmt.Sprint(mapUserMoney[v.Name] / totalMoney * 100)
|
|
|
+ if item.DepartmentProportion == "" {
|
|
|
+ item.DepartmentProportion = "0"
|
|
|
+ }
|
|
|
+ item.DepartmentProportion += "%"
|
|
|
+
|
|
|
+ mapPermissionUser[v.ChartPermissionName] = append(mapPermissionUser[v.ChartPermissionName], item)
|
|
|
+ }
|
|
|
+
|
|
|
+ for k, v := range mapPermissionUser {
|
|
|
+ lenUser := len(v)
|
|
|
+ item := new(cygx.AllocationRealNameStatisticsListResp)
|
|
|
+ item.RealName = "合计"
|
|
|
+ item.TotalRelatedContract = mapPermissionAllocation[k]
|
|
|
+
|
|
|
+ item.TotalDispatchPoint = fmt.Sprint(mapPermissionMoney[k], "/", "300")
|
|
|
+ item.GroupProportion = "100%"
|
|
|
+
|
|
|
+ // 部门占比
|
|
|
+ item.DepartmentProportion = fmt.Sprint(mapPermissionMoney[k] / totalMoney * 100)
|
|
|
+ if item.DepartmentProportion == "" {
|
|
|
+ item.DepartmentProportion = "0"
|
|
|
+ }
|
|
|
+ item.DepartmentProportion += "%"
|
|
|
+
|
|
|
+ mapPermissionUser[k] = append(mapPermissionUser[k], item)
|
|
|
+
|
|
|
+ item = new(cygx.AllocationRealNameStatisticsListResp)
|
|
|
+ item.RealName = "平均"
|
|
|
+ item.TotalRelatedContract = mapPermissionAllocation[k] / float64(lenUser)
|
|
|
+ item.TotalDispatchPoint = fmt.Sprint(mapPermissionMoney[k] / float64(lenUser))
|
|
|
+
|
|
|
+ //组内占比
|
|
|
+ item.GroupProportion = fmt.Sprint(float64(lenUser) / mapPermissionMoney[k] * 100)
|
|
|
+ if item.GroupProportion == "" {
|
|
|
+ item.GroupProportion = "0"
|
|
|
+ }
|
|
|
+ item.GroupProportion += "%"
|
|
|
+
|
|
|
+ // 部门占比
|
|
|
+ item.DepartmentProportion = fmt.Sprint(mapPermissionMoney[k] / totalMoney * 100)
|
|
|
+ if item.DepartmentProportion == "" {
|
|
|
+ item.DepartmentProportion = "0"
|
|
|
+ }
|
|
|
+ item.DepartmentProportion += "%"
|
|
|
+
|
|
|
+ mapPermissionUser[k] = append(mapPermissionUser[k], item)
|
|
|
+ }
|
|
|
+
|
|
|
+ var list []*cygx.AllocationPermissionStatisticsListResp
|
|
|
+
|
|
|
+ permissionNameArr := []string{"医药", "消费", "科技", "智造", "策略"}
|
|
|
+
|
|
|
+ for _, v := range permissionNameArr {
|
|
|
+ item := new(cygx.AllocationPermissionStatisticsListResp)
|
|
|
+ item.ChartPermissionName = v
|
|
|
+ item.List = mapPermissionUser[v]
|
|
|
+ list = append(list, item)
|
|
|
+ }
|
|
|
+
|
|
|
+ resp := cygx.CygxAllocationCompanyContractDetailStatisticsResp{
|
|
|
+ List: list,
|
|
|
+ }
|
|
|
+ resp.TotalContract = totalContract
|
|
|
+ resp.TotalMoney = totalMoney
|
|
|
+ //导出excel
|
|
|
+ if isExport {
|
|
|
+ //IncrementalCompanyListExport(this, dataType, resp, br)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = resp
|
|
|
+}
|