company_product.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. package company
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hongze_cygx/utils"
  6. "time"
  7. )
  8. type CompanyProduct struct {
  9. CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"`
  10. CompanyId int `description:"客户id"`
  11. ProductId int `description:"产品id"`
  12. ProductName string `description:"产品名称"`
  13. CompanyName string `description:"客户名称"`
  14. Source string `description:"来源"`
  15. Reasons string `description:"新增理由"`
  16. Status 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. ShareGroupId int `description:"共享销售分组id"`
  23. DepartmentId int `description:"销售部门id"`
  24. IsSuspend int `description:"1:暂停,0:启用"`
  25. SuspendTime time.Time `description:"暂停启用时间"`
  26. TryOutTime time.Time `description:"正式转试用时间"`
  27. RenewalReason string `description:"正式转试用后的续约情况说明"`
  28. RenewalTodo string `description:"未续约说明中的待办事项说明"`
  29. LastDescriptionTime time.Time `description:"上次添加说明时间"`
  30. RenewalIntention int `description:"是否勾选无续约意向,1:确认,0:未确认"`
  31. ApproveStatus string `description:"审批状态:'审批中','通过','驳回'"`
  32. FreezeTime time.Time `description:"冻结时间"`
  33. FreezeReason time.Time `description:"冻结理由"`
  34. Remark string `description:"备注信息"`
  35. CreateTime time.Time `description:"创建时间"`
  36. ModifyTime time.Time `description:"修改时间"`
  37. StartDate string `description:"开始日期"`
  38. EndDate string `description:"结束日期"`
  39. ContractEndDate time.Time `description:"合同结束日期"`
  40. LoseReason string `description:"流失原因"`
  41. LossTime time.Time `description:"流失时间"`
  42. CompanyType string `description:"客户类型"`
  43. OpenCode string `description:"开放给第三方的编码,不让第三方定位我们的客户信息"`
  44. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。"`
  45. ViewTotal int `description:"总阅读次数"`
  46. RoadShowTotal int `description:"累计路演次数"`
  47. LastViewTime time.Time `description:"最后一次阅读时间"`
  48. PackageType int `description:"套餐类型"`
  49. IsFormal int `description:"是否已经转正式,0是没有转正式,1是已经转过正式"`
  50. TodoStatus string `description:"任务处理状态;枚举值:'无任务','未完成','已完成'"`
  51. TodoCreateTime time.Time `description:"任务创建时间"`
  52. TodoApproveTime time.Time `description:"任务审批时间"`
  53. TryStage int `description:"试用客户子标签:1未分类、2 推进、3 跟踪、4 预备"`
  54. TryOutDayTotal int `description:"客户总试用天数"`
  55. CloseReason string `description:"关闭原因"`
  56. CloseTime time.Time `description:"关闭时间"`
  57. OverseasLabel int `description:"海外客户试用子标签:1未分类、2 推进、3 跟踪、4 预备、"`
  58. IsOverseas int `description:"是否显示在海外客户0:显示,1:不显示"`
  59. ShareSeller string `description:"共享销售员"`
  60. ShareSellerId int `description:"共享销售员id"`
  61. }
  62. func GetCompanyProductByCompanyIdAndProductId(companyId, productId int) (item *CompanyProduct, err error) {
  63. o := orm.NewOrmUsingDB("weekly_report")
  64. sql := `SELECT b.* FROM company AS a
  65. INNER JOIN company_product AS b ON a.company_id=b.company_id
  66. WHERE a.company_id=? AND b.product_id=? LIMIT 1 `
  67. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  68. return
  69. }
  70. func GetCompanyProductCount(companyId, productId int) (count int, err error) {
  71. sql := ` SELECT COUNT(1) AS count FROM company_product WHERE company_id = ? AND product_id = ? `
  72. o := orm.NewOrmUsingDB("weekly_report")
  73. err = o.Raw(sql, companyId, productId).QueryRow(&count)
  74. return
  75. }
  76. func GetCompanyProductDetailByCompanyId(companyId, productId int) (item *CompanyProduct, err error) {
  77. sql := ` SELECT * FROM company_product WHERE company_id = ? AND product_id = ?; `
  78. o := orm.NewOrmUsingDB("weekly_report")
  79. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  80. return
  81. }
  82. func GetCompanyProductAaiServeCount(companyId, groupId int) (count int, err error) {
  83. o := orm.NewOrmUsingDB("weekly_report")
  84. sql := ` SELECT COUNT(1) AS count FROM company_product WHERE company_id = ? AND product_id = 2 AND (group_id = ? OR share_group_id = ?) `
  85. err = o.Raw(sql, companyId, groupId, groupId).QueryRow(&count)
  86. return
  87. }
  88. // 获取列表
  89. func GetCompanyProductAndCompanyListByCondition(condition string, pars []interface{}) (items []*CompanyProduct, err error) {
  90. o := orm.NewOrmUsingDB("weekly_report")
  91. sql := ` SELECT
  92. p.company_id,
  93. p.seller_id,
  94. p.seller_name,
  95. p.start_date,
  96. p.end_date,
  97. p.share_seller_id,
  98. p.share_seller,
  99. p.group_id,
  100. p.share_group_id,
  101. p.status,
  102. c.company_name
  103. FROM
  104. company_product AS p
  105. INNER JOIN company AS c ON c.company_id = p.company_id
  106. WHERE
  107. 1 = 1 `
  108. if condition != "" {
  109. sql += condition
  110. }
  111. _, err = o.Raw(sql, pars).QueryRows(&items)
  112. return
  113. }
  114. type CompanyProductUser struct {
  115. CompanyId int `description:"客户id"`
  116. ProductId int `description:"产品id"`
  117. CompanyName string `description:"客户名称"`
  118. Status string `description:"客户状态"`
  119. SellerId int `description:"销售id"`
  120. SellerName string `description:"销售名称"`
  121. Mobile string `description:"手机号"`
  122. UserId int
  123. RealName string `description:"用户实际名称"`
  124. Email string `description:"邮箱"`
  125. }
  126. // 获取销售信息列表
  127. func GetCompanyProductListByMobiles(mobiles []string) (items []*CompanyProductUser, err error) {
  128. lenArr := len(mobiles)
  129. if lenArr == 0 {
  130. return
  131. }
  132. o := orm.NewOrmUsingDB("weekly_report")
  133. sql := ` SELECT
  134. u.mobile,
  135. u.user_id,
  136. u.email,
  137. u.real_name,
  138. u.company_id,
  139. p.seller_name,
  140. p.status,
  141. c.company_name
  142. FROM
  143. wx_user as u
  144. INNER JOIN company AS c ON c.company_id = u.company_id
  145. LEFT JOIN company_product AS p ON p.company_id = u.company_id
  146. WHERE u.mobile IN (` + utils.GetOrmInReplace(lenArr) + `) AND p.product_id = 2 `
  147. _, err = o.Raw(sql, mobiles).QueryRows(&items)
  148. return
  149. }
  150. // 获取销售信息
  151. func GetCompanyProductListByUserId(userId int) (item *CompanyProductUser, err error) {
  152. o := orm.NewOrmUsingDB("weekly_report")
  153. sql := `SELECT
  154. u.mobile,
  155. u.user_id,
  156. u.email,
  157. u.real_name,
  158. u.company_id,
  159. p.seller_name,
  160. p.status,
  161. c.company_name
  162. FROM
  163. wx_user as u
  164. INNER JOIN company AS c ON c.company_id = u.company_id
  165. INNER JOIN company_product AS p ON p.company_id = u.company_id
  166. WHERE u.user_id = ? AND p.product_id = 2 `
  167. err = o.Raw(sql, userId).QueryRow(&item)
  168. return
  169. }
  170. // 获取权益客户下的正式、试用、永续客户。
  171. func GetRaiCompanyProductCompanyids() (items []*CompanyProduct, err error) {
  172. sql := ` SELECT company_id FROM company_product WHERE product_id = 2 AND status IN ('正式','试用','永续') AND company_id > 1 `
  173. o := orm.NewOrmUsingDB("weekly_report")
  174. _, err = o.Raw(sql).QueryRows(&items)
  175. return
  176. }
  177. // 更新权益客户下近四周之内是否包含决策人(是否有KP互动过)
  178. func UpdateRaiCompanyProductIsUserMakerByCompanyids(companyIds []int) (err error) {
  179. lenArr := len(companyIds)
  180. if lenArr == 0 {
  181. return
  182. }
  183. o, err := orm.NewOrmUsingDB("weekly_report").Begin()
  184. if err != nil {
  185. return
  186. }
  187. defer func() {
  188. fmt.Println(err)
  189. if err == nil {
  190. o.Commit()
  191. } else {
  192. o.Rollback()
  193. }
  194. }()
  195. sql := `UPDATE company_product SET is_user_maker = -1 WHERE product_id=2 AND company_id > 1 `
  196. _, err = o.Raw(sql).Exec()
  197. if err != nil {
  198. return
  199. }
  200. sql = `UPDATE company_product SET is_user_maker = 1 WHERE product_id=2 AND status IN ('正式','试用','永续') AND company_id > 1 AND company_id IN (` + utils.GetOrmInReplace(lenArr) + `) `
  201. _, err = o.Raw(sql, companyIds).Exec()
  202. return
  203. }