company_product.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. package company
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hz_crm_api/utils"
  5. "time"
  6. )
  7. type CompanyProduct struct {
  8. CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"`
  9. CompanyId int `description:"客户id"`
  10. ProductId int `description:"产品id"`
  11. ProductName string `description:"产品名称"`
  12. CompanyName string `description:"客户名称"`
  13. Source string `description:"来源"`
  14. Reasons string `description:"新增理由"`
  15. Status string `description:"客户状态"`
  16. InitStatus string `description:"客户初始化状态(目前用来处理权益的永续客户使用)"`
  17. IndustryId int `description:"行业id"`
  18. IndustryName string `description:"行业名称"`
  19. SellerId int `description:"销售id"`
  20. SellerName string `description:"销售名称"`
  21. GroupId int `description:"销售分组id"`
  22. DepartmentId int `description:"销售部门id"`
  23. IsSuspend int `description:"1:暂停,0:启用"`
  24. SuspendTime time.Time `description:"暂停启用时间"`
  25. TryOutTime time.Time `description:"正式转试用时间"`
  26. RenewalReason string `description:"正式转试用后的续约情况说明"`
  27. RenewalTodo string `description:"未续约说明中的待办事项说明"`
  28. LastDescriptionTime time.Time `description:"上次添加说明时间"`
  29. RenewalIntention int `description:"是否勾选无续约意向,1:确认,0:未确认"`
  30. ApproveStatus string `description:"审批状态:'审批中','通过','驳回'"`
  31. FreezeTime time.Time `description:"冻结时间"`
  32. FreezeReason time.Time `description:"冻结理由"`
  33. Remark string `description:"备注信息"`
  34. CreateTime time.Time `description:"创建时间"`
  35. ModifyTime time.Time `description:"修改时间"`
  36. StartDate string `description:"开始日期"`
  37. EndDate string `description:"结束日期"`
  38. ContractEndDate time.Time `description:"合同结束日期"`
  39. LoseReason string `description:"流失原因"`
  40. LossTime time.Time `description:"流失时间"`
  41. CompanyType string `description:"客户类型"`
  42. OpenCode string `description:"开放给第三方的编码,不让第三方定位我们的客户信息"`
  43. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。"`
  44. ViewTotal int `description:"总阅读次数"`
  45. RoadShowTotal int `description:"累计路演次数"`
  46. LastViewTime time.Time `description:"最后一次阅读时间"`
  47. PackageType int `description:"套餐类型"`
  48. IsFormal int `description:"是否已经转正式,0是没有转正式,1是已经转过正式"`
  49. TodoStatus string `description:"任务处理状态;枚举值:'无任务','未完成','已完成'"`
  50. TodoCreateTime time.Time `description:"任务创建时间"`
  51. TodoApproveTime time.Time `description:"任务审批时间"`
  52. TryStage int `description:"试用客户子标签:1未分类、2 推进、3 跟踪、4 预备"`
  53. TryOutDayTotal int `description:"客户总试用天数"`
  54. CloseReason string `description:"关闭原因"`
  55. CloseTime time.Time `description:"关闭时间"`
  56. OverseasLabel int `description:"海外客户试用子标签:1未分类、2 推进、3 跟踪、4 预备、"`
  57. IsOverseas int `description:"是否显示在海外客户0:显示,1:不显示"`
  58. }
  59. // 新增客户产品
  60. func AddCompanyProduct(item *CompanyProduct) (newId int64, err error) {
  61. o := orm.NewOrm()
  62. newId, err = o.Insert(item)
  63. return
  64. }
  65. type CompanyProductDetail struct {
  66. CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"`
  67. CompanyId int `description:"客户id"`
  68. ProductId int `description:"产品id"`
  69. ProductName string `description:"产品名称"`
  70. CompanyName string `description:"客户名称"`
  71. Source string `description:"来源"`
  72. Reasons string `description:"新增理由"`
  73. Status string `description:"客户状态"`
  74. IndustryId int `description:"行业id"`
  75. IndustryName string `description:"行业名称"`
  76. SellerId int `description:"销售id"`
  77. SellerName string `description:"销售名称"`
  78. GroupId int `description:"销售分组id"`
  79. DepartmentId int `description:"销售部门id"`
  80. IsSuspend int `description:"1:暂停,0:启用"`
  81. SuspendTime time.Time `description:"暂停启用时间"`
  82. ApproveStatus string `description:"审批状态:'审批中','通过','驳回'"`
  83. FreezeTime time.Time `description:"冻结时间"`
  84. Remark string `description:"备注信息"`
  85. CreateTime time.Time `description:"创建时间"`
  86. ModifyTime time.Time `description:"修改时间"`
  87. StartDate string `description:"开始日期"`
  88. EndDate string `description:"结束日期"`
  89. LoseReason string `description:"流失原因"`
  90. LossTime time.Time `description:"流失时间"`
  91. OpenCode string `description:"开放给第三方的编码,不让第三方定位我们的客户信息"`
  92. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。"`
  93. SpecialSurplus string `description:"专项调研剩余次数"`
  94. Points string `description:"公司研选服务剩余点数"`
  95. PermissionList []*PermissionLookList
  96. }
  97. func GetCompanyProductsByCompanyId(companyId int) (items []*CompanyProductDetail, err error) {
  98. sql := `SELECT * FROM company_product WHERE company_id=? ORDER BY create_time ASC `
  99. o := orm.NewOrm()
  100. _, err = o.Raw(sql, companyId).QueryRows(&items)
  101. return
  102. }
  103. func GetCompanyProductById(companyProductId int) (item *CompanyProduct, err error) {
  104. o := orm.NewOrm()
  105. sql := `SELECT * FROM company_product WHERE company_product_id=? `
  106. err = o.Raw(sql, companyProductId).QueryRow(&item)
  107. return
  108. }
  109. func GetCompanyProductByCompanyIdAndProductId(companyId, productId int) (item *CompanyProduct, err error) {
  110. o := orm.NewOrm()
  111. sql := `SELECT b.* FROM company AS a
  112. INNER JOIN company_product AS b ON a.company_id=b.company_id
  113. WHERE a.company_id=? AND b.product_id=? LIMIT 1 `
  114. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  115. return
  116. }
  117. // 修改客户产品
  118. func ModifyCompanyProduct(item *CompanyProduct) (err error) {
  119. o := orm.NewOrm()
  120. sql := `UPDATE company_product
  121. SET
  122. company_name = ?,
  123. source = ?,
  124. reasons = ?,
  125. status = ?,
  126. industry_id = ?,
  127. industry_name = ?,
  128. seller_id = ?,
  129. seller_name = ?,
  130. group_id = ?,
  131. department_id = ?,
  132. start_date = ?,
  133. end_date = ?,
  134. scale = ?,
  135. modify_time = NOW()
  136. WHERE company_product_id = ? `
  137. _, err = o.Raw(sql, item.CompanyName, item.Source, item.Reasons, item.Status, item.IndustryId, item.IndustryName, item.SellerId,
  138. item.SellerName, item.GroupId, item.DepartmentId, item.StartDate, item.EndDate, item.Scale, item.CompanyProductId).Exec()
  139. return
  140. }
  141. // 更新客户产品信息
  142. func (companyProduct *CompanyProduct) Update(cols []string) (err error) {
  143. o := orm.NewOrm()
  144. _, err = o.Update(companyProduct, cols...)
  145. return
  146. }
  147. func DeleteCompanyProductById(companyId, productId, companyProductId int) (companyProductList []*CompanyProduct, companyReportPermissionList []*CompanyReportPermission, err error) {
  148. o := orm.NewOrm()
  149. to, err := o.Begin()
  150. if err != nil {
  151. return
  152. }
  153. defer func() {
  154. if err != nil {
  155. _ = to.Rollback()
  156. } else {
  157. _ = to.Commit()
  158. }
  159. }()
  160. searchSql := `select * FROM company_product WHERE company_product_id=? `
  161. _, err = to.Raw(searchSql, companyProductId).QueryRows(&companyProductList)
  162. sql := `DELETE FROM company_product WHERE company_product_id=? `
  163. _, err = to.Raw(sql, companyProductId).Exec()
  164. if err != nil {
  165. return
  166. }
  167. searchSql = `select * FROM company_report_permission WHERE company_id=? AND product_id=? `
  168. _, err = to.Raw(searchSql, companyId, productId).QueryRows(&companyReportPermissionList)
  169. sql = `DELETE FROM company_report_permission WHERE company_id=? AND product_id=? `
  170. _, err = to.Raw(sql, companyId, productId).Exec()
  171. return
  172. }
  173. func SuspendCompanyProductById(companyId, productId, suspend int) (err error) {
  174. o := orm.NewOrm()
  175. sql := `UPDATE company_product SET is_suspend=?,suspend_time=NOW(),modify_time=NOW() WHERE company_id=? AND product_id=? `
  176. _, err = o.Raw(sql, suspend, companyId, productId).Exec()
  177. return
  178. }
  179. func GetAllCompanyProducts() (items []*CompanyProductDetail, err error) {
  180. sql := `SELECT * FROM company_product `
  181. o := orm.NewOrm()
  182. _, err = o.Raw(sql).QueryRows(&items)
  183. return
  184. }
  185. type CompanyProductTotalSlice struct {
  186. Total int `description:"总产品数"`
  187. CompanyId int `description:"用户id"`
  188. }
  189. // 根据用户id字符串获取企业用户的产品数
  190. func GetCountProductByCompanyIds(companyIds string) (items []*CompanyProductTotalSlice, err error) {
  191. //如果companyIds是空串,那么直接返回
  192. if companyIds == "" {
  193. return
  194. }
  195. o := orm.NewOrm()
  196. sql := `SELECT count(1) total,company_id FROM company_product WHERE company_id in (` + companyIds + `) group by company_id`
  197. _, err = o.Raw(sql).QueryRows(&items)
  198. return
  199. //return items2,err
  200. }
  201. // TryOutCompanyList 正式转试用的客户
  202. type TryOutCompanyList struct {
  203. CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"`
  204. CompanyId int `description:"客户id"`
  205. ProductId int `description:"产品id"`
  206. ProductName string `description:"产品名称"`
  207. CompanyName string `description:"客户名称"`
  208. CreditCode string `description:"社会统一信用码"`
  209. Status string `description:"客户状态"`
  210. TryOutTime time.Time `description:"正式转试用时间"`
  211. RenewalReason string `description:"正式转试用后的续约情况说明"`
  212. RenewalTodo string `description:"未续约说明中的待办事项说明"`
  213. LastDescriptionTime string `description:"上次添加说明时间"`
  214. RenewalIntention int `description:"是否勾选无续约意向,1:确认,0:未确认"`
  215. CreateTime time.Time `description:"创建时间"`
  216. ModifyTime time.Time `description:"修改时间"`
  217. StartDate string `description:"开始日期"`
  218. EndDate string `description:"结束日期"`
  219. ExpireDays int `description:"到期日期"`
  220. }
  221. // GetTryOutCompanyCount
  222. // 获取今日待办消息数量
  223. func GetTryOutCompanyCount(condition string, pars []interface{}) (total int, err error) {
  224. o := orm.NewOrm()
  225. sql := ` select count(*) count from company_product a
  226. join company b on a.company_id=b.company_id where 1=1 and a.status="试用" `
  227. sql += condition
  228. err = o.Raw(sql, pars).QueryRow(&total)
  229. return
  230. }
  231. // GetTryOutCompanyList
  232. // 获取今日待办消息
  233. func GetTryOutCompanyList(condition string, pars []interface{}, startSize, pageSize int) (items []*TryOutCompanyList, err error) {
  234. o := orm.NewOrm()
  235. 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
  236. join company b on a.company_id=b.company_id where 1=1 and a.status="试用" `
  237. sql += condition
  238. sql += ` LIMIT ?,? `
  239. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  240. return
  241. }
  242. // EditTryOutCompanyReason 编辑续约情况说明
  243. func EditTryOutCompanyReason(companyProduct *CompanyProduct, reason string, renewalTodo string) (err error) {
  244. o := orm.NewOrm()
  245. updateCols := make([]string, 0)
  246. companyProduct.RenewalReason = reason
  247. companyProduct.RenewalTodo = renewalTodo
  248. companyProduct.ModifyTime = time.Now()
  249. companyProduct.LastDescriptionTime = time.Now()
  250. updateCols = append(updateCols, "RenewalReason", "RenewalTodo", "ModifyTime", "LastDescriptionTime", "RenewalIntention")
  251. _, err = o.Update(companyProduct, updateCols...)
  252. return
  253. }
  254. // CompanyRenewalReason 未续约说明
  255. type CompanyRenewalReason struct {
  256. CompanyRenewalReasonId int `orm:"column(company_renewal_reason_id);pk" description:"未续约说明id"`
  257. CompanyId int `description:"客户id"`
  258. ProductId int `description:"产品id"`
  259. ProductName string `description:"产品名称"`
  260. CompanyName string `description:"客户名称"`
  261. TryOutTime time.Time `description:"正式转试用时间"`
  262. RenewalReason string `description:"正式转试用后的续约情况说明"`
  263. RenewalTodo string `description:"未续约说明中的待办事项说明"`
  264. LastDescriptionTime time.Time `description:"上次添加说明时间"`
  265. EndDays time.Time `description:"到期时间"`
  266. ExpirationTimeExceeded int `description:"超出到期时间"`
  267. RenewalIntention int `description:"是否勾选无续约意向,1:确认,0:未确认"`
  268. CreateTime time.Time `description:"创建时间"`
  269. }
  270. // AddRenewalReason 新增续约情况说明
  271. func AddRenewalReason(renewalReason *CompanyRenewalReason) (err error) {
  272. o := orm.NewOrm()
  273. _, err = o.Insert(renewalReason)
  274. return
  275. }
  276. // GetLastDescriptionTime 查询上次添加未续约说明时间
  277. func GetLastDescriptionTime() (items []*TryOutCompanyList, err error) {
  278. o := orm.NewOrm()
  279. sql := "SELECT * FROM company_product ORDER BY last_description_time desc limit 1"
  280. err = o.Raw(sql).QueryRow(&items)
  281. return
  282. }
  283. // UpdateLastDescriptionTime 更新最后一次修改未续约说明时间
  284. func UpdateLastDescriptionTime(companyProduct *CompanyProduct) (err error) {
  285. o := orm.NewOrm()
  286. updateCols := make([]string, 0)
  287. companyProduct.LastDescriptionTime = time.Now()
  288. updateCols = append(updateCols, "LastDescriptionTime")
  289. _, err = o.Update(companyProduct, updateCols...)
  290. return
  291. }
  292. // GetTryOutTimeFromOperationRecord 查询转试用时间
  293. func GetTryOutTimeFromOperationRecord(companyId int) (item *string, err error) {
  294. o := orm.NewOrm()
  295. sql := "SELECT create_time FROM company_operation_record WHERE company_id=? AND operation='try_out' ORDER BY create_time DESC "
  296. err = o.Raw(sql, companyId).QueryRow(&item)
  297. return
  298. }
  299. // GetCompanyProductsByCompanyIds 根据客户id集合字符串获取所有客户产品列表
  300. func GetCompanyProductsByCompanyIds(companyIds, condition string, pars []interface{}) (items []*CompanyProduct, err error) {
  301. if companyIds == `` {
  302. return
  303. }
  304. sql := `SELECT * FROM company_product WHERE company_id in (` + companyIds + `) `
  305. sql += condition
  306. sql += ` ORDER BY create_time ASC `
  307. o := orm.NewOrm()
  308. _, err = o.Raw(sql, pars).QueryRows(&items)
  309. return
  310. }
  311. // 更新最后一次编辑时间
  312. func UpdateCompanyProductModifyTime(companyId, productId int) (err error) {
  313. o := orm.NewOrm()
  314. sql := `UPDATE company_product SET modify_time=NOW() WHERE company_id=? AND product_id=? `
  315. _, err = o.Raw(sql, companyId, productId).Exec()
  316. return
  317. }
  318. // CompanyProductRemark 备注
  319. type CompanyProductRemark struct {
  320. CompanyProductRemarkId int `orm:"column(company_product_remark_id);pk" description:"备注id"`
  321. CompanyId int `description:"客户id"`
  322. ProductId int `description:"产品id"`
  323. ProductName string `description:"产品名称"`
  324. Remark string `description:"备注"`
  325. CreateTime time.Time `description:"创建时间"`
  326. SysUserId int `description:"创建人ID"`
  327. SysRealName string `description:"创建人姓名"`
  328. }
  329. func AddCompanyRemark(remark *CompanyProductRemark) (err error) {
  330. o := orm.NewOrm()
  331. _, err = o.Insert(remark)
  332. return
  333. }
  334. // GetRemarkList 获取备注列表
  335. func GetRemarkList(CompanyId, ProductId string) (items []*CompanyProductRemark, err error) {
  336. o := orm.NewOrm()
  337. sql := "SELECT * FROM company_product_remark WHERE company_id=? AND product_id=? ORDER BY create_time DESC"
  338. _, err = o.Raw(sql, CompanyId, ProductId).QueryRows(&items)
  339. return
  340. }
  341. // GetRemarkList 获取备注列表
  342. func GetRemarkListByCompanyId(CompanyId string) (items []*CompanyProductRemark, err error) {
  343. o := orm.NewOrm()
  344. sql := "SELECT * FROM company_product_remark WHERE company_id=? ORDER BY create_time DESC"
  345. _, err = o.Raw(sql, CompanyId).QueryRows(&items)
  346. return
  347. }
  348. // 冻结客户
  349. //func FreezeCompany(productId, companyId, adminId int, remark, realName string) (msg, errMsg string){
  350. // time.Sleep(time.Second)
  351. // productName := ""
  352. // if productId == 1 {
  353. // productName = "ficc"
  354. // } else if productId == 2 {
  355. // productName = "权益"
  356. // } else {
  357. // productName = "佣金客户"
  358. // }
  359. //
  360. // cp, err := GetCompanyProductByCompanyIdAndProductId(companyId, productId)
  361. // if err != nil {
  362. // msg = "查询该客户产品异常!"
  363. // errMsg = "查询该客户产品异常,err:" + err.Error()
  364. // return
  365. // }
  366. // if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  367. // msg = "客户状态为:" + cp.Status + ";不可冻结"
  368. // errMsg = "客户状态为:" + cp.Status + ";不可冻结"
  369. // return
  370. // }
  371. // //查询客户的产品权限
  372. // companyReportPermissionList, err := GetCompanyReportPermission(companyId, productId)
  373. // if err != nil {
  374. // msg = "查询客户的产品权限异常"
  375. // errMsg = "查询客户的产品权限异常:" + err.Error()
  376. // return
  377. // }
  378. // err = CompanyFreeze(companyId, productId, remark)
  379. // if err != nil {
  380. // msg = "冻结失败!"
  381. // errMsg = "冻结失败,Err:" + err.Error()
  382. // return
  383. // }
  384. // //新增操作记录
  385. // {
  386. // approveContent := remark
  387. // remark := "冻结客户"
  388. // operation := "freeze"
  389. // services.AddCompanyOperationRecord(companyId, cp.SellerId, adminId, productId, adminId, cp.CompanyName,
  390. // productName, "超级管理员", remark, operation, approveContent, realName, "", "冻结")
  391. //
  392. // //新增产品权限冻结操作日志
  393. // for _, companyReportPermission := range companyReportPermissionList {
  394. // record := company_report_permission_log.CompanyReportPermissionLog{
  395. // CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  396. // CompanyId: companyReportPermission.CompanyId,
  397. // ProductId: productId,
  398. // ProductName: companyReportPermission.ProductName,
  399. // SysUserId: adminId,
  400. // SysUserName: "超级管理员",
  401. // Remark: "冻结客户",
  402. // Operation: "freeze",
  403. // Status: companyReportPermission.Status,
  404. // CreateTime: time.Now(),
  405. // }
  406. // _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  407. // }
  408. // }
  409. // if err != nil {
  410. // msg = "编辑失败"
  411. // errMsg = "编辑失败,Err:" + err.Error()
  412. // }
  413. // return
  414. //}
  415. // SellerTryCompanyProductIds 销售对应的客户ID
  416. type SellerTryCompanyProductIds struct {
  417. CompanyIds string `description:"客户ids"`
  418. SellerId int `description:"销售ID"`
  419. }
  420. // GetTryCompanyIdsBySellerIds 获取销售对应的试用客户ID
  421. func GetTryCompanyIdsBySellerIds(productId int, sellerIds string) (list []*SellerTryCompanyProductIds, err error) {
  422. o := orm.NewOrm()
  423. sql := ` SELECT seller_id, GROUP_CONCAT(DISTINCT company_id SEPARATOR ',') AS company_ids
  424. FROM company_product
  425. WHERE product_id=? and status = "试用" and seller_id in ` + sellerIds + ` GROUP BY seller_id
  426. `
  427. _, err = o.Raw(sql, productId).QueryRows(&list)
  428. return
  429. }
  430. // GetCompanyProductsByCompanyIdsAndProductId 根据客户id集合字符串以及品种id获取所有客户产品列表
  431. func GetCompanyProductsByCompanyIdsAndProductId(companyIds []int, productId int) (items []*CompanyProduct, err error) {
  432. lenCompanyId := len(companyIds)
  433. if lenCompanyId == 0 {
  434. return
  435. }
  436. 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 = ? `
  437. o := orm.NewOrm()
  438. _, err = o.Raw(sql, companyIds, productId).QueryRows(&items)
  439. return
  440. }
  441. // GetCompanyProductByCompanyIdAndSellerId 根据客户id和所属销售id获取客户产品信息
  442. func GetCompanyProductByCompanyIdAndSellerId(companyId, sellerId int) (item *CompanyProduct, err error) {
  443. o := orm.NewOrm()
  444. sql := `SELECT b.* FROM company AS a
  445. INNER JOIN company_product AS b ON a.company_id=b.company_id
  446. WHERE a.company_id=? AND b.seller_id=? LIMIT 1 `
  447. err = o.Raw(sql, companyId, sellerId).QueryRow(&item)
  448. return
  449. }
  450. // GetCompanyProductsByCompanyIds 根据客户id集合字符串获取所有客户产品列表
  451. func GetCompanyProductsBySellerId(sellerId string) (items []*CompanyProduct, err error) {
  452. sql := `SELECT * FROM company_product WHERE seller_id in (` + sellerId + `) `
  453. o := orm.NewOrm()
  454. _, err = o.Raw(sql).QueryRows(&items)
  455. return
  456. }
  457. // GetCompanyProductsByCondition 获取客户产品列表
  458. func GetCompanyProductsByCondition(condition string, pars []interface{}) (list []*CompanyProduct, err error) {
  459. sql := `SELECT
  460. b.*
  461. FROM
  462. company AS a
  463. JOIN company_product AS b ON a.company_id = b.company_id
  464. WHERE
  465. 1 = 1 `
  466. if condition != `` {
  467. sql += condition
  468. }
  469. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
  470. return
  471. }
  472. // AddCompanyProductTryOutDayTotal 将客户产品的试用天数+1
  473. func AddCompanyProductTryOutDayTotal(companyId, productId int) (err error) {
  474. o := orm.NewOrm()
  475. sql := `UPDATE company_product
  476. SET
  477. try_out_day_total = try_out_day_total+1
  478. WHERE company_id = ? AND product_id = ?`
  479. _, err = o.Raw(sql, companyId, productId).Exec()
  480. return
  481. }
  482. // 获取详情
  483. func GetCompanyProductDetail(companyId, productId int) (item *CompanyProductDetail, err error) {
  484. sql := ` SELECT * FROM company_product WHERE company_id = ? AND product_id = ?; `
  485. o := orm.NewOrm()
  486. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  487. return
  488. }
  489. // 根据状态获取客户列表
  490. func GetCompanyProductListByStatus(status string, productId int) (items []*CompanyProduct, err error) {
  491. sql := ` SELECT * FROM company_product WHERE status = ? AND product_id = ?; `
  492. o := orm.NewOrm()
  493. _, err = o.Raw(sql, status, productId).QueryRows(&items)
  494. return
  495. }
  496. // 根据规模取客户列表
  497. func GetCompanyProductListByScale(status string, productId int) (items []*CompanyProduct, err error) {
  498. sql := ` SELECT * FROM company_product WHERE scale IN (?) AND product_id = ?; `
  499. o := orm.NewOrm()
  500. _, err = o.Raw(sql, status, productId).QueryRows(&items)
  501. return
  502. }
  503. // GetCompanyRemarkById 获取客户备注
  504. func GetCompanyRemarkById(remarkId int) (item *CompanyProductRemark, err error) {
  505. o := orm.NewOrm()
  506. sql := `SELECT * FROM company_product_remark WHERE company_product_remark_id = ? LIMIT 1`
  507. err = o.Raw(sql, remarkId).QueryRow(&item)
  508. return
  509. }
  510. // DelCompanyRemark 删除客户备注
  511. func DelCompanyRemark(remarkId int) (err error) {
  512. o := orm.NewOrm()
  513. sql := `DELETE FROM company_product_remark WHERE company_product_remark_id = ? LIMIT 1`
  514. _, err = o.Raw(sql, remarkId).Exec()
  515. return
  516. }
  517. // 获取列表
  518. func GetCompanyProductList(condition string, pars []interface{}) (items []*CompanyProduct, err error) {
  519. o := orm.NewOrm()
  520. sql := `SELECT * FROM company_product WHERE 1= 1 `
  521. if condition != "" {
  522. sql += condition
  523. }
  524. _, err = o.Raw(sql, pars).QueryRows(&items)
  525. return
  526. }
  527. // 获取列表
  528. func GetCompanyProductListBycondition(condition string, pars []interface{}) (items []*CompanyProduct, err error) {
  529. o := orm.NewOrm()
  530. sql := ` SELECT a.company_id FROM company AS a INNER JOIN company_product AS b ON a.company_id=b.company_id WHERE 1=1 `
  531. if condition != "" {
  532. sql += condition
  533. }
  534. _, err = o.Raw(sql, pars).QueryRows(&items)
  535. return
  536. }
  537. // CompanyProductItem
  538. // @Description: 客户品种
  539. type CompanyProductItem struct {
  540. CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"`
  541. CompanyId int `description:"客户id"`
  542. ProductId int `description:"产品id"`
  543. ProductName string `description:"产品名称"`
  544. CompanyName string `description:"客户名称"`
  545. Source string `description:"来源"`
  546. Reasons string `description:"新增理由"`
  547. Status string `description:"客户状态"`
  548. IndustryId int `description:"行业id"`
  549. IndustryName string `description:"行业名称"`
  550. SellerId int `description:"销售id"`
  551. SellerName string `description:"销售名称"`
  552. GroupId int `description:"销售分组id"`
  553. DepartmentId int `description:"销售部门id"`
  554. IsSuspend int `description:"1:暂停,0:启用"`
  555. SuspendTime time.Time `description:"暂停启用时间"`
  556. ApproveStatus string `description:"审批状态:'审批中','通过','驳回'"`
  557. FreezeTime time.Time `description:"冻结时间"`
  558. Remark string `description:"备注信息"`
  559. CreateTime time.Time `description:"创建时间"`
  560. ModifyTime time.Time `description:"修改时间"`
  561. StartDate string `description:"开始日期"`
  562. EndDate string `description:"结束日期"`
  563. ContractEndDate string `description:"合同结束日期"`
  564. LoseReason string `description:"流失原因"`
  565. LossTime time.Time `description:"流失时间"`
  566. CompanyType string `description:"客户类型"`
  567. OpenCode string `description:"开放给第三方的编码,不让第三方定位我们的客户信息"`
  568. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。"`
  569. ViewTotal int `description:"总阅读次数"`
  570. RoadShowTotal int `description:"累计路演次数"`
  571. LastViewTime time.Time `description:"最后一次阅读时间"`
  572. PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
  573. IsFormal int `description:"是否已经转正式,0是没有转正式,1是已经转过正式"`
  574. TodoStatus string `description:"任务处理状态;枚举值:'无任务','未完成','已完成'"`
  575. TodoCreateTime time.Time `description:"任务创建时间"`
  576. TodoApproveTime time.Time `description:"任务审批时间"`
  577. TryStage int `description:"试用客户子标签:1未分类、2 推进、3 跟踪、4 预备"`
  578. IsShare int `description:"0:非共享用户,1:共享客户"`
  579. ShareSeller string `description:"共享销售员"`
  580. ShareSellerId int `description:"共享销售员id"`
  581. }
  582. // GetCompanyProductItemByCompanyId
  583. // @Description: 根据客户ID获取客户产品列表
  584. // @author: Roc
  585. // @datetime 2023-12-07 11:06:58
  586. // @param companyIdList []int
  587. // @param productId int
  588. // @return items []*CompanyProductItem
  589. // @return err error
  590. func GetCompanyProductItemByCompanyId(companyId int, productId int) (items *CompanyProductItem, err error) {
  591. o := orm.NewOrm()
  592. sql := `SELECT a.*,b.is_share,b.share_seller,b.share_seller_id FROM company_product as a
  593. JOIN company b on a.company_id=b.company_id
  594. WHERE a.company_id = ? AND a.product_id = ? `
  595. _, err = o.Raw(sql, companyId, productId).QueryRows(&items)
  596. return
  597. }
  598. // GetCompanyProductListByCompanyIds 根据客户id集合以及类型获取所有客户产品列表
  599. func GetCompanyProductListByCompanyIds(companyIds []int, productId int) (items []*CompanyProduct, err error) {
  600. lenArr := len(companyIds)
  601. if lenArr == 0 {
  602. return
  603. }
  604. sql := `SELECT * FROM company_product WHERE 1= 1 AND company_id IN (` + utils.GetOrmInReplace(lenArr) + `)` + ` AND product_id = ?`
  605. o := orm.NewOrm()
  606. _, err = o.Raw(sql, companyIds, productId).QueryRows(&items)
  607. return
  608. }
  609. // 获取权益用户客户数量
  610. func GetCompanyProductRaiForeverCount(companyId int) (count int, err error) {
  611. sqlCount := ` SELECT COUNT(1) AS count FROM company_product WHERE 1= 1 AND product_id = 2 AND status = '永续' AND company_id = ? `
  612. o := orm.NewOrm()
  613. err = o.Raw(sqlCount, companyId).QueryRow(&count)
  614. return
  615. }