overseas_custom_seller.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. package overseas_custom
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hz_crm_api/models/company"
  6. "hongze/hz_crm_api/utils"
  7. "time"
  8. )
  9. // 海外客户销售
  10. type OverseasCustomerSale struct {
  11. OverseasCustomSellerId int `orm:"column(overseas_custom_seller_id);pk"`
  12. SellerId int `description:"销售id"`
  13. CreateTime time.Time `description:"创建时间"`
  14. }
  15. // 海外客户销售
  16. type OverseasCustomerSaleView struct {
  17. SellerId int `description:"销售id"`
  18. RealName string `description:"销售姓名"`
  19. }
  20. func (m *OverseasCustomerSale) Create() (err error) {
  21. o := orm.NewOrm()
  22. id, err := o.Insert(m)
  23. if err != nil {
  24. return
  25. }
  26. m.OverseasCustomSellerId = int(id)
  27. return
  28. }
  29. func (m *OverseasCustomerSale) Delete() (err error) {
  30. o := orm.NewOrm()
  31. sql := ` DELETE FROM overseas_custom_seller WHERE seller_id=? `
  32. _, err = o.Raw(sql, m.SellerId).Exec()
  33. return
  34. }
  35. func (m *OverseasCustomerSale) TableName() string {
  36. return "overseas_custom_seller"
  37. }
  38. // OverseasCustomerSaleSaveReq 保存销售
  39. type OverseasCustomerSaleSaveReq struct {
  40. AddSellerIdArr []int `description:"新增销售id,数组"`
  41. DelSellerIdArr []int `description:"删除销售id,数组"`
  42. }
  43. func (m *OverseasCustomerSale) GetOverseasCustomerSaleAll() (list []*OverseasCustomerSaleView, err error) {
  44. o := orm.NewOrm()
  45. sql := ` SELECT a.*,b.real_name FROM overseas_custom_seller AS a
  46. INNER JOIN admin AS b ON a.seller_id=b.admin_id `
  47. _, err = o.Raw(sql).QueryRows(&list)
  48. return
  49. }
  50. type AdminItem struct {
  51. AdminId int `description:"系统用户id"`
  52. AdminName string `description:"系统用户名称"`
  53. RealName string `description:"系统用户姓名"`
  54. Mobile string `description:"手机号"`
  55. }
  56. func (m *OverseasCustomerSale) HandelOverseasCustomerSale(sellerId, isOverseas int) (err error) {
  57. o := orm.NewOrm()
  58. sellerItem := new(AdminItem)
  59. sql := ` SELECT * FROM admin WHERE admin_id=? `
  60. err = o.Raw(sql, sellerId).QueryRow(&sellerItem)
  61. if err != nil {
  62. return err
  63. }
  64. if sellerItem.Mobile == "13065778668" {
  65. sql = ` UPDATE company_product SET is_overseas = ? WHERE seller_id=? AND company_id IN (SELECT company_id FROM company WHERE region_type='国内') `
  66. _, err = o.Raw(sql, isOverseas, sellerId).Exec()
  67. return err
  68. }
  69. return err
  70. }
  71. // EnglishCompany 英文客户
  72. type EnglishCompany struct {
  73. CompanyId int `orm:"column(company_id);pk" description:"英文客户ID"`
  74. CompanyName string `description:"客户名称"`
  75. CountryCode string `description:"国家Code"`
  76. Country string `description:"国家"`
  77. SellerId int `description:"销售ID"`
  78. SellerName string `description:"销售姓名"`
  79. ViewTotal int `description:"累计点击量/阅读量"`
  80. IsDeleted int `description:"删除状态:0-正常;1-已删除"`
  81. CreateTime time.Time `description:"创建时间"`
  82. ModifyTime time.Time `description:"更新时间"`
  83. Enabled int `description:"0-禁用; 1-启用; 2-部分禁用"`
  84. Status int `description:"1:正式,2:临时,3:终止"`
  85. Nation string `description:"所属国家"`
  86. IsHide int `description:"是否隐藏:0:不隐藏,1:隐藏"`
  87. OverseasStatus string `description:"海外客户状态:'正式','试用','关闭'"`
  88. OverseasLabel int `description:"海外客户试用子标签:1未分类、2 推进、3 跟踪、4 预备、"`
  89. }
  90. func (m *OverseasCustomerSale) HandelCompanyStatus(sellerId int) (err error) {
  91. var databaseName string
  92. if utils.RunMode == "debug" {
  93. databaseName = "test_v2_hongze_rddp"
  94. } else {
  95. databaseName = "hongze_rddp"
  96. }
  97. o := orm.NewOrm()
  98. enCompanyList := make([]*EnglishCompany, 0)
  99. sql := ` SELECT * FROM %s.english_company WHERE seller_id=? AND is_deleted=0 `
  100. sql = fmt.Sprintf(sql, databaseName)
  101. _, err = o.Raw(sql, sellerId).QueryRows(&enCompanyList)
  102. if err != nil {
  103. return err
  104. }
  105. if len(enCompanyList) > 0 {
  106. for _, v := range enCompanyList {
  107. var overseasStatus string
  108. var resetBtn int
  109. if v.Enabled == 0 {
  110. overseasStatus = "关闭"
  111. resetBtn = 0
  112. } else {
  113. overseasStatus = "试用"
  114. resetBtn = 1
  115. }
  116. sql = ` UPDATE %s.english_company SET overseas_status=?,reset_btn=? WHERE company_id=? `
  117. sql = fmt.Sprintf(sql, databaseName)
  118. _, err = o.Raw(sql, overseasStatus, resetBtn, v.CompanyId).Exec()
  119. if err != nil {
  120. return err
  121. }
  122. }
  123. }
  124. companyList := make([]*company.CompanyProduct, 0)
  125. sql = ` SELECT * FROM company_product WHERE seller_id=? `
  126. _, err = o.Raw(sql, sellerId).QueryRows(&companyList)
  127. if err != nil {
  128. return err
  129. }
  130. if len(companyList) > 0 {
  131. for _, v := range companyList {
  132. var overseasStatus string
  133. var resetBtn int
  134. if v.Status == "正式" || v.Status == "永续" {
  135. overseasStatus = "正式"
  136. resetBtn = 0
  137. } else if v.Status == "试用" {
  138. overseasStatus = "试用"
  139. resetBtn = 1
  140. } else {
  141. overseasStatus = "关闭"
  142. resetBtn = 0
  143. }
  144. sql = ` UPDATE company SET overseas_status=?,reset_btn=? WHERE company_id=? `
  145. _, err = o.Raw(sql, overseasStatus, resetBtn, v.CompanyId).Exec()
  146. if err != nil {
  147. return err
  148. }
  149. }
  150. }
  151. return err
  152. }