company_product.go 29 KB

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