company_product.go 27 KB

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