company_product.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package models
  2. import (
  3. "hongze/hongze_task/utils"
  4. "rdluck_tools/orm"
  5. "time"
  6. )
  7. type CompanyOperationRecord struct {
  8. Id int `orm:"column(id);pk"`
  9. CompanyId int `description:"客户id"`
  10. CompanyName string `description:"客户名称"`
  11. SysUserId int `description:"操作者id"`
  12. SysRealName string `description:"操作者名称"`
  13. Remark string `description:"备注"`
  14. Operation string `description:"操作"`
  15. CreateTime time.Time `description:"操作时间"`
  16. ProductId int `description:"产品id"`
  17. ProductName string `description:"产品名称"`
  18. ApproveUserId int `description:"审批人id"`
  19. ApproveRealName string `description:"审批人姓名"`
  20. ApproveContent string `description:"审批人内容"`
  21. ApproveRemark string `description:"审批人内容"`
  22. Status string `description:"状态"`
  23. }
  24. //新增操作记录
  25. func AddCompanyOperationRecord(item *CompanyOperationRecord) (lastId int64, err error) {
  26. o := orm.NewOrm()
  27. lastId, err = o.Insert(item)
  28. return
  29. }
  30. func CompanyFreeze(companyId, productId int) (err error) {
  31. o := orm.NewOrm()
  32. freezeStartDate := time.Now().Format(utils.FormatDate)
  33. freezeEndDate := time.Now().AddDate(0, 3, 0).Format(utils.FormatDate)
  34. sql := `UPDATE company_product SET status='冻结',freeze_time=NOW(),modify_time=NOW(),start_date=?,end_date=?,freeze_start_date=?,freeze_end_date=? WHERE company_id=? AND product_id=? `
  35. _, err = o.Raw(sql, freezeStartDate, freezeEndDate, freezeStartDate, freezeEndDate, companyId, productId).Exec()
  36. if err != nil {
  37. return err
  38. }
  39. sql = `UPDATE company SET type=3,last_updated_time=NOW(),start_date=?,end_date=? WHERE company_id=? `
  40. _, err = o.Raw(sql, freezeStartDate, freezeEndDate, companyId).Exec()
  41. if err != nil {
  42. return err
  43. }
  44. return
  45. }
  46. func CompanyLoss(companyId, productId int) (err error) {
  47. o := orm.NewOrm()
  48. sql := `UPDATE company_product SET status='流失',loss_time=NOW(),modify_time=NOW(),lose_reason=‘冻结到期系统自动流失’ WHERE company_id=? AND product_id=? `
  49. _, err = o.Raw(sql, companyId, productId).Exec()
  50. if err != nil {
  51. return err
  52. }
  53. sql = `UPDATE company SET type=3,last_updated_time=NOW() WHERE company_id=? `
  54. _, err = o.Raw(sql, companyId).Exec()
  55. if err != nil {
  56. return err
  57. }
  58. return
  59. }
  60. func CompanyTryOut(companyId, productId int) (err error) {
  61. o := orm.NewOrm()
  62. startDate := time.Now().Format(utils.FormatDate)
  63. endDate := time.Now().AddDate(0, 2, 0).Format(utils.FormatDate)
  64. sql := `UPDATE company_product SET status='试用',start_date=?,end_date=?,modify_time=NOW() WHERE company_id=? AND product_id=? `
  65. _, err = o.Raw(sql, startDate, endDate, companyId, productId).Exec()
  66. if err != nil {
  67. return err
  68. }
  69. sql = `UPDATE company SET type=2,last_updated_time=NOW(),start_date=?,end_date=? WHERE company_id=? `
  70. _, err = o.Raw(sql, startDate, endDate, companyId).Exec()
  71. if err != nil {
  72. return err
  73. }
  74. return
  75. }
  76. func GetCompanyOldDataSync() (items []*Company, err error) {
  77. sql := `SELECT * FROM company WHERE company_id NOT IN(
  78. SELECT company_id FROM company_product
  79. )
  80. AND company_id<>1 `
  81. o := orm.NewOrm()
  82. _, err = o.Raw(sql).QueryRows(&items)
  83. return
  84. }
  85. type CompanyProduct struct {
  86. CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"`
  87. CompanyId int `description:"客户id"`
  88. ProductId int `description:"产品id"`
  89. ProductName string `description:"产品名称"`
  90. CompanyName string `description:"客户名称"`
  91. Source string `description:"来源"`
  92. Reasons string `description:"新增理由"`
  93. Status string `description:"客户状态"`
  94. IndustryId int `description:"行业id"`
  95. IndustryName string `description:"行业名称"`
  96. SellerId int `description:"销售id"`
  97. SellerName string `description:"销售名称"`
  98. GroupId int `description:"销售分组id"`
  99. DepartmentId int `description:"销售部门id"`
  100. IsSuspend int `description:"1:暂停,0:启用"`
  101. SuspendTime time.Time `description:"暂停启用时间"`
  102. ApproveStatus string `description:"审批状态:'审批中','通过','驳回'"`
  103. FreezeTime time.Time `description:"冻结时间"`
  104. Remark string `description:"备注信息"`
  105. CreateTime time.Time `description:"创建时间"`
  106. ModifyTime time.Time `description:"修改时间"`
  107. StartDate string `description:"开始日期"`
  108. EndDate string `description:"结束日期"`
  109. LoseReason string `description:"流失原因"`
  110. LossTime time.Time `description:"流失时间"`
  111. CompanyType string `description:"客户类型"`
  112. }
  113. //新增客户产品
  114. func AddCompanyProduct(item *CompanyProduct) (newId int64, err error) {
  115. o := orm.NewOrm()
  116. newId, err = o.Insert(item)
  117. return
  118. }
  119. type Sellers struct {
  120. AdminId int `description:"销售id"`
  121. RealName string `description:"销售姓名"`
  122. Email string `description:"销售邮箱"`
  123. OpenId string `description:"销售openid"`
  124. Mobile string `description:"销售电话"`
  125. RoleTypeCode string `description:"角色编码"`
  126. }
  127. func GetSellers() (items []*Sellers, err error) {
  128. o := orm.NewOrm()
  129. sql := `SELECT a.real_name,a.email,b.open_id,a.mobile,b.mobile,a.role_type_code,a.admin_id
  130. FROM admin AS a
  131. LEFT JOIN wx_user AS b ON a.mobile=b.mobile
  132. WHERE role_type_code IN('ficc_seller','ficc_admin','rai_seller','rai_admin')
  133. AND b.open_id<>'' `
  134. _, err = o.Raw(sql).QueryRows(&items)
  135. return
  136. }
  137. func GetRemindCompany(sellerId int, endDate string) (items []*CompanyProduct, err error) {
  138. o := orm.NewOrm()
  139. sql := ` SELECT b.end_date,a.company_name,b.status,b.seller_id,b.seller_name
  140. FROM company a
  141. INNER JOIN company_product AS b ON a.company_id=b.company_id
  142. WHERE b.seller_id=? AND b.end_date = ?
  143. AND b.status IN('正式','试用') ORDER BY b.status DESC `
  144. _,err=o.Raw(sql, sellerId, endDate).QueryRows(&items)
  145. return
  146. }