123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- package cygxService
- import (
- "fmt"
- "errors"
- "hongze/hongze_mobile_admin/models/tables/company_contract_permission"
- "hongze/hongze_mobile_admin/models/tables/cygx_allocation_company_contract"
- "hongze/hongze_mobile_admin/services/alarm_msg"
- "hongze/hongze_mobile_admin/utils"
- "time"
- "hongze/hongze_mobile_admin/models/tables/company_contract"
- )
- // 如果合同只有研选的时候,自动处理派点
- func HandleAllocationCompanyContractByYanXuan(companyContractId int) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- go alarm_msg.SendAlarmMsg(fmt.Sprint("如果合同只有研选的时候,自动处理派点失败,Err:", err.Error(), "companyContractId", companyContractId), 2)
- }
- }()
- var condition string
- var pars []interface{}
- pars = make([]interface{}, 0)
- condition = " AND company_contract_id = ? "
- pars = append(pars, companyContractId)
- companyContractPermissionList, e := company_contract_permission.GetCompanyContractPermissionList(condition, pars)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCompanyContractPermissionList, Err: " + e.Error())
- return
- }
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCygxAllocationCompanyContractPermissionListById, Err: " + e.Error())
- return
- }
- if len(companyContractPermissionList) > 1 {
- return
- }
- var expensiveYxmoney float64
- for _, v := range companyContractPermissionList {
- if v.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
- err = errors.New("没有发现研选权限: ")
- return
- }
- if v.ExpensiveYx == 1 {
- expensiveYxmoney = 5
- } else if v.ExpensiveYx == 2 {
- expensiveYxmoney = 10
- } else{
- expensiveYxmoney = 3
- }
- }
- var items []*cygx_allocation_company_contract.CygxAllocationCompanyContract
- var itemsPermission []*cygx_allocation_company_contract.CygxAllocationCompanyContractPermission
- itemPermission := new(cygx_allocation_company_contract.CygxAllocationCompanyContractPermission)
- itemPermission.CompanyContractId = companyContractId
- //itemPermission.AdminId = sysUser.AdminId
- //itemPermission.AdminName = sysUser.RealName
- itemPermission.Proportion = 0
- itemPermission.Money = expensiveYxmoney
- itemPermission.MoneyAvg = 0
- itemPermission.ChartPermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
- itemPermission.CreateTime = time.Now()
- itemPermission.ModifyTime = time.Now()
- itemsPermission = append(itemsPermission, itemPermission)
- item := new(cygx_allocation_company_contract.CygxAllocationCompanyContract)
- item.CompanyContractId = companyContractId
- //item.AdminId = sysUser.AdminId
- //item.AdminName = sysUser.RealName
- item.Proportion = 0
- item.Money = expensiveYxmoney
- item.RealName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
- item.ChartPermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- items = append(items, item)
- e = cygx_allocation_company_contract.AddAndUpdateCygxAllocationCompanyContract(items, itemsPermission, companyContractId)
- if e != nil {
- err = errors.New("AddAndUpdateCygxAllocationCompanyContract, Err: " + e.Error())
- return
- }
- return
- }
- // HandleCompanyContractPackageDifference 更新与上一份合同的金额的对比 '增加套餐','减少套餐','维持套餐'
- func HandleCompanyContractPackageDifference(companyContractId int) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- go alarm_msg.SendAlarmMsg(fmt.Sprint("如果合同只有研选的时候,自动处理派点失败,Err:", err.Error(), "companyContractId", companyContractId), 2)
- }
- }()
- var condition string
- var pars []interface{}
- condition = " AND company_contract_id = ? "
- pars = append(pars, companyContractId)
- detail, e := company_contract.GetCompanyContracDetail(condition, pars)
- if e != nil {
- err = errors.New("GetCompanyContracDetail,detail Err: " + e.Error())
- return
- }
- //如果不是续约合同就不做对比处理
- if detail.ContractType != "续约合同" {
- return
- }
- //获取前一份合同的信息
- pars = make([]interface{}, 0)
- condition = " AND company_id = ? AND company_contract_id < ? AND status = 1 AND product_id = ? ORDER BY company_contract_id DESC LIMIT 1 "
- pars = append(pars, detail.CompanyId, companyContractId, detail.ProductId)
- detailPrevious, e := company_contract.GetCompanyContracDetail(condition, pars)
- if e != nil {
- err = errors.New("GetCompanyContracDetail,detailPrevious Err: " + e.Error())
- return
- }
- var packageDifference string
- if detail.Money > detailPrevious.Money {
- packageDifference = "增加套餐"
- } else if detail.Money < detailPrevious.Money {
- packageDifference = "减少套餐"
- } else {
- packageDifference = "维持套餐"
- }
- e = company_contract.UpdateCompanyContractPackageDifference(packageDifference, companyContractId)
- fmt.Println(packageDifference)
- if e != nil {
- err = errors.New("UpdateCompanyContractPackageDifference, Err: " + e.Error())
- return
- }
- return
- }
|