123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552 |
- package company
- import (
- "github.com/beego/beego/v2/client/orm"
- "hongze/hz_crm_api/utils"
- "time"
- )
- type CompanyProduct struct {
- CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"`
- CompanyId int `description:"客户id"`
- ProductId int `description:"产品id"`
- ProductName string `description:"产品名称"`
- CompanyName string `description:"客户名称"`
- Source string `description:"来源"`
- Reasons string `description:"新增理由"`
- Status string `description:"客户状态"`
- IndustryId int `description:"行业id"`
- IndustryName string `description:"行业名称"`
- SellerId int `description:"销售id"`
- SellerName string `description:"销售名称"`
- GroupId int `description:"销售分组id"`
- DepartmentId int `description:"销售部门id"`
- IsSuspend int `description:"1:暂停,0:启用"`
- SuspendTime time.Time `description:"暂停启用时间"`
- TryOutTime time.Time `description:"正式转试用时间"`
- RenewalReason string `description:"正式转试用后的续约情况说明"`
- RenewalTodo string `description:"未续约说明中的待办事项说明"`
- LastDescriptionTime time.Time `description:"上次添加说明时间"`
- RenewalIntention int `description:"是否勾选无续约意向,1:确认,0:未确认"`
- ApproveStatus string `description:"审批状态:'审批中','通过','驳回'"`
- FreezeTime time.Time `description:"冻结时间"`
- FreezeReason time.Time `description:"冻结理由"`
- Remark string `description:"备注信息"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- StartDate string `description:"开始日期"`
- EndDate string `description:"结束日期"`
- ContractEndDate time.Time `description:"合同结束日期"`
- LoseReason string `description:"流失原因"`
- LossTime time.Time `description:"流失时间"`
- CompanyType string `description:"客户类型"`
- OpenCode string `description:"开放给第三方的编码,不让第三方定位我们的客户信息"`
- Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。"`
- ViewTotal int `description:"总阅读次数"`
- RoadShowTotal int `description:"累计路演次数"`
- LastViewTime time.Time `description:"最后一次阅读时间"`
- PackageType int `description:"套餐类型"`
- IsFormal int `description:"是否已经转正式,0是没有转正式,1是已经转过正式"`
- TodoStatus string `description:"任务处理状态;枚举值:'无任务','未完成','已完成'"`
- TodoCreateTime time.Time `description:"任务创建时间"`
- TodoApproveTime time.Time `description:"任务审批时间"`
- TryStage int `description:"试用客户子标签:1未分类、2 推进、3 跟踪、4 预备"`
- TryOutDayTotal int `description:"客户总试用天数"`
- CloseReason string `description:"关闭原因"`
- CloseTime time.Time `description:"关闭时间"`
- }
- func AddCompanyProduct(item *CompanyProduct) (newId int64, err error) {
- o := orm.NewOrm()
- newId, err = o.Insert(item)
- return
- }
- type CompanyProductDetail struct {
- CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"`
- CompanyId int `description:"客户id"`
- ProductId int `description:"产品id"`
- ProductName string `description:"产品名称"`
- CompanyName string `description:"客户名称"`
- Source string `description:"来源"`
- Reasons string `description:"新增理由"`
- Status string `description:"客户状态"`
- IndustryId int `description:"行业id"`
- IndustryName string `description:"行业名称"`
- SellerId int `description:"销售id"`
- SellerName string `description:"销售名称"`
- GroupId int `description:"销售分组id"`
- DepartmentId int `description:"销售部门id"`
- IsSuspend int `description:"1:暂停,0:启用"`
- SuspendTime time.Time `description:"暂停启用时间"`
- ApproveStatus string `description:"审批状态:'审批中','通过','驳回'"`
- FreezeTime time.Time `description:"冻结时间"`
- Remark string `description:"备注信息"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- StartDate string `description:"开始日期"`
- EndDate string `description:"结束日期"`
- LoseReason string `description:"流失原因"`
- LossTime time.Time `description:"流失时间"`
- OpenCode string `description:"开放给第三方的编码,不让第三方定位我们的客户信息"`
- Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。"`
- SpecialSurplus string `description:"专项调研剩余次数"`
- Points string `description:"公司研选服务剩余点数"`
- PermissionList []*PermissionLookList
- }
- func GetCompanyProductsByCompanyId(companyId int) (items []*CompanyProductDetail, err error) {
- sql := `SELECT * FROM company_product WHERE company_id=? ORDER BY create_time ASC `
- o := orm.NewOrm()
- _, err = o.Raw(sql, companyId).QueryRows(&items)
- return
- }
- func GetCompanyProductById(companyProductId int) (item *CompanyProduct, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM company_product WHERE company_product_id=? `
- err = o.Raw(sql, companyProductId).QueryRow(&item)
- return
- }
- func GetCompanyProductByCompanyIdAndProductId(companyId, productId int) (item *CompanyProduct, err error) {
- o := orm.NewOrm()
- sql := `SELECT b.* FROM company AS a
- INNER JOIN company_product AS b ON a.company_id=b.company_id
- WHERE a.company_id=? AND b.product_id=? LIMIT 1 `
- err = o.Raw(sql, companyId, productId).QueryRow(&item)
- return
- }
- func ModifyCompanyProduct(item *CompanyProduct) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE company_product
- SET
- company_name = ?,
- source = ?,
- reasons = ?,
- status = ?,
- industry_id = ?,
- industry_name = ?,
- seller_id = ?,
- seller_name = ?,
- group_id = ?,
- department_id = ?,
- start_date = ?,
- end_date = ?,
- scale = ?,
- modify_time = NOW()
- WHERE company_product_id = ? `
- _, err = o.Raw(sql, item.CompanyName, item.Source, item.Reasons, item.Status, item.IndustryId, item.IndustryName, item.SellerId,
- item.SellerName, item.GroupId, item.DepartmentId, item.StartDate, item.EndDate, item.Scale, item.CompanyProductId).Exec()
- return
- }
- func (companyProduct *CompanyProduct) Update(cols []string) (err error) {
- o := orm.NewOrm()
- _, err = o.Update(companyProduct, cols...)
- return
- }
- func DeleteCompanyProductById(companyId, productId, companyProductId int) (companyProductList []*CompanyProduct, companyReportPermissionList []*CompanyReportPermission, err error) {
- o := orm.NewOrm()
- to, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- searchSql := `select * FROM company_product WHERE company_product_id=? `
- _, err = to.Raw(searchSql, companyProductId).QueryRows(&companyProductList)
- sql := `DELETE FROM company_product WHERE company_product_id=? `
- _, err = to.Raw(sql, companyProductId).Exec()
- if err != nil {
- return
- }
- searchSql = `select * FROM company_report_permission WHERE company_id=? AND product_id=? `
- _, err = to.Raw(searchSql, companyId, productId).QueryRows(&companyReportPermissionList)
- sql = `DELETE FROM company_report_permission WHERE company_id=? AND product_id=? `
- _, err = to.Raw(sql, companyId, productId).Exec()
- return
- }
- func SuspendCompanyProductById(companyId, productId, suspend int) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE company_product SET is_suspend=?,suspend_time=NOW(),modify_time=NOW() WHERE company_id=? AND product_id=? `
- _, err = o.Raw(sql, suspend, companyId, productId).Exec()
- return
- }
- func GetAllCompanyProducts() (items []*CompanyProductDetail, err error) {
- sql := `SELECT * FROM company_product `
- o := orm.NewOrm()
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- type CompanyProductTotalSlice struct {
- Total int `description:"总产品数"`
- CompanyId int `description:"用户id"`
- }
- func GetCountProductByCompanyIds(companyIds string) (items []*CompanyProductTotalSlice, err error) {
-
- if companyIds == "" {
- return
- }
- o := orm.NewOrm()
- sql := `SELECT count(1) total,company_id FROM company_product WHERE company_id in (` + companyIds + `) group by company_id`
- _, err = o.Raw(sql).QueryRows(&items)
- return
-
- }
- type TryOutCompanyList struct {
- CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"`
- CompanyId int `description:"客户id"`
- ProductId int `description:"产品id"`
- ProductName string `description:"产品名称"`
- CompanyName string `description:"客户名称"`
- CreditCode string `description:"社会统一信用码"`
- Status string `description:"客户状态"`
- TryOutTime time.Time `description:"正式转试用时间"`
- RenewalReason string `description:"正式转试用后的续约情况说明"`
- RenewalTodo string `description:"未续约说明中的待办事项说明"`
- LastDescriptionTime string `description:"上次添加说明时间"`
- RenewalIntention int `description:"是否勾选无续约意向,1:确认,0:未确认"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- StartDate string `description:"开始日期"`
- EndDate string `description:"结束日期"`
- ExpireDays int `description:"到期日期"`
- }
- func GetTryOutCompanyCount(condition string, pars []interface{}) (total int, err error) {
- o := orm.NewOrm()
- sql := ` select count(*) count from company_product a
- join company b on a.company_id=b.company_id where 1=1 and a.status="试用" `
- sql += condition
- err = o.Raw(sql, pars).QueryRow(&total)
- return
- }
- func GetTryOutCompanyList(condition string, pars []interface{}, startSize, pageSize int) (items []*TryOutCompanyList, err error) {
- o := orm.NewOrm()
- sql := ` select a.company_product_id,a.company_id,a.product_id,a.product_name,a.status,b.credit_code,b.company_name,a.try_out_time,a.renewal_reason,a.renewal_todo,a.last_description_time,a.create_time,a.modify_time,a.start_date,a.end_date from company_product a
- join company b on a.company_id=b.company_id where 1=1 and a.status="试用" `
- sql += condition
- sql += ` LIMIT ?,? `
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
- return
- }
- func EditTryOutCompanyReason(companyProduct *CompanyProduct, reason string, renewalTodo string) (err error) {
- o := orm.NewOrm()
- updateCols := make([]string, 0)
- companyProduct.RenewalReason = reason
- companyProduct.RenewalTodo = renewalTodo
- companyProduct.ModifyTime = time.Now()
- companyProduct.LastDescriptionTime = time.Now()
- updateCols = append(updateCols, "RenewalReason", "RenewalTodo", "ModifyTime", "LastDescriptionTime", "RenewalIntention")
- _, err = o.Update(companyProduct, updateCols...)
- return
- }
- type CompanyRenewalReason struct {
- CompanyRenewalReasonId int `orm:"column(company_renewal_reason_id);pk" description:"未续约说明id"`
- CompanyId int `description:"客户id"`
- ProductId int `description:"产品id"`
- ProductName string `description:"产品名称"`
- CompanyName string `description:"客户名称"`
- TryOutTime time.Time `description:"正式转试用时间"`
- RenewalReason string `description:"正式转试用后的续约情况说明"`
- RenewalTodo string `description:"未续约说明中的待办事项说明"`
- LastDescriptionTime time.Time `description:"上次添加说明时间"`
- EndDays time.Time `description:"到期时间"`
- ExpirationTimeExceeded int `description:"超出到期时间"`
- RenewalIntention int `description:"是否勾选无续约意向,1:确认,0:未确认"`
- CreateTime time.Time `description:"创建时间"`
- }
- func AddRenewalReason(renewalReason *CompanyRenewalReason) (err error) {
- o := orm.NewOrm()
- _, err = o.Insert(renewalReason)
- return
- }
- func GetLastDescriptionTime() (items []*TryOutCompanyList, err error) {
- o := orm.NewOrm()
- sql := "SELECT * FROM company_product ORDER BY last_description_time desc limit 1"
- err = o.Raw(sql).QueryRow(&items)
- return
- }
- func UpdateLastDescriptionTime(companyProduct *CompanyProduct) (err error) {
- o := orm.NewOrm()
- updateCols := make([]string, 0)
- companyProduct.LastDescriptionTime = time.Now()
- updateCols = append(updateCols, "LastDescriptionTime")
- _, err = o.Update(companyProduct, updateCols...)
- return
- }
- func GetTryOutTimeFromOperationRecord(companyId int) (item *string, err error) {
- o := orm.NewOrm()
- sql := "SELECT create_time FROM company_operation_record WHERE company_id=? AND operation='try_out' ORDER BY create_time DESC "
- err = o.Raw(sql, companyId).QueryRow(&item)
- return
- }
- func GetCompanyProductsByCompanyIds(companyIds, condition string, pars []interface{}) (items []*CompanyProduct, err error) {
- if companyIds == `` {
- return
- }
- sql := `SELECT * FROM company_product WHERE company_id in (` + companyIds + `) `
- sql += condition
- sql += ` ORDER BY create_time ASC `
- o := orm.NewOrm()
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- func UpdateCompanyProductModifyTime(companyId, productId int) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE company_product SET modify_time=NOW() WHERE company_id=? AND product_id=? `
- _, err = o.Raw(sql, companyId, productId).Exec()
- return
- }
- type CompanyProductRemark struct {
- CompanyProductRemakrId int `orm:"column(company_product_remark_id);pk" description:"备注id"`
- CompanyId int `description:"客户id"`
- ProductId int `description:"产品id"`
- ProductName string `description:"产品名称"`
- Remark string `description:"备注"`
- CreateTime time.Time `description:"创建时间"`
- Mark int `description:"是否标记 0不是 1是"`
- }
- func AddCompanyRemark(remark *CompanyProductRemark) (err error) {
- o := orm.NewOrm()
- _, err = o.Insert(remark)
- return
- }
- func GetRemarkList(CompanyId, ProductId string) (items []*CompanyProductRemark, err error) {
- o := orm.NewOrm()
- sql := "SELECT * FROM company_product_remark WHERE company_id=? AND product_id=? ORDER BY create_time DESC"
- _, err = o.Raw(sql, CompanyId, ProductId).QueryRows(&items)
- return
- }
- func GetRemarkListByCompanyId(CompanyId string) (items []*CompanyProductRemark, err error) {
- o := orm.NewOrm()
- sql := "SELECT * FROM company_product_remark WHERE company_id=? ORDER BY create_time DESC"
- _, err = o.Raw(sql, CompanyId).QueryRows(&items)
- return
- }
- func UpdateCompanyProductRemark(remarkId, mark int) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE company_product_remark SET mark=? WHERE company_product_remark_id=? `
- _, err = o.Raw(sql, mark, remarkId).Exec()
- return
- }
- type SellerTryCompanyProductIds struct {
- CompanyIds string `description:"客户ids"`
- SellerId int `description:"销售ID"`
- }
- func GetTryCompanyIdsBySellerIds(productId int, sellerIds string) (list []*SellerTryCompanyProductIds, err error) {
- o := orm.NewOrm()
- sql := ` SELECT seller_id, GROUP_CONCAT(DISTINCT company_id SEPARATOR ',') AS company_ids
- FROM company_product
- WHERE product_id=? and status = "试用" and seller_id in ` + sellerIds + ` GROUP BY seller_id
- `
- _, err = o.Raw(sql, productId).QueryRows(&list)
- return
- }
- func GetCompanyProductsByCompanyIdsAndProductId(companyIds []int, productId int) (items []*CompanyProduct, err error) {
- lenCompanyId := len(companyIds)
- if lenCompanyId == 0 {
- return
- }
- sql := `SELECT b.* FROM company a left join company_product b on a.company_id=b.company_id WHERE a.company_id in (` + utils.GetOrmInReplace(lenCompanyId) + `) AND b.product_id = ? `
- o := orm.NewOrm()
- _, err = o.Raw(sql, companyIds, productId).QueryRows(&items)
- return
- }
- func GetCompanyProductByCompanyIdAndSellerId(companyId, sellerId int) (item *CompanyProduct, err error) {
- o := orm.NewOrm()
- sql := `SELECT b.* FROM company AS a
- INNER JOIN company_product AS b ON a.company_id=b.company_id
- WHERE a.company_id=? AND b.seller_id=? LIMIT 1 `
- err = o.Raw(sql, companyId, sellerId).QueryRow(&item)
- return
- }
- func GetCompanyProductsBySellerId(sellerId string) (items []*CompanyProduct, err error) {
- sql := `SELECT * FROM company_product WHERE seller_id in (` + sellerId + `) `
- o := orm.NewOrm()
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- func GetCompanyProductsByCondition(condition string, pars []interface{}) (list []*CompanyProduct, err error) {
- sql := `SELECT
- b.*
- FROM
- company AS a
- JOIN company_product AS b ON a.company_id = b.company_id
- WHERE
- 1 = 1 `
- if condition != `` {
- sql += condition
- }
- _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
- return
- }
- func AddCompanyProductTryOutDayTotal(companyId, productId int) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE company_product
- SET
- try_out_day_total = try_out_day_total+1
- WHERE company_id = ? AND product_id = ?`
- _, err = o.Raw(sql, companyId, productId).Exec()
- return
- }
- func GetCompanyProductDetail(companyId, productId int) (item *CompanyProductDetail, err error) {
- sql := ` SELECT * FROM company_product WHERE company_id = ? AND product_id = ?; `
- o := orm.NewOrm()
- err = o.Raw(sql, companyId, productId).QueryRow(&item)
- return
- }
- func GetCompanyProductListByStatus(status string, productId int) (items []*CompanyProduct, err error) {
- sql := ` SELECT * FROM company_product WHERE status = ? AND product_id = ?; `
- o := orm.NewOrm()
- _, err = o.Raw(sql, status, productId).QueryRows(&items)
- return
- }
- func GetCompanyProductListByScale(status string, productId int) (items []*CompanyProduct, err error) {
- sql := ` SELECT * FROM company_product WHERE scale IN (?) AND product_id = ?; `
- o := orm.NewOrm()
- _, err = o.Raw(sql, status, productId).QueryRows(&items)
- return
- }
|