company_product.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package roadshow
  2. import (
  3. "context"
  4. "github.com/beego/beego/v2/client/orm"
  5. )
  6. func RoadShow(cont context.Context) (err error) {
  7. roadShowTotalList, _ := GetRoadShowTotal()
  8. for _, roadShowTotal := range roadShowTotalList {
  9. err := updateProduct(roadShowTotal.Total, roadShowTotal.CompanyId)
  10. if err != nil {
  11. return err
  12. }
  13. }
  14. return
  15. }
  16. func GetRoadShowTotal() (items []*RoadShowTotalSlice, err error) {
  17. o := orm.NewOrm()
  18. sql := `SELECT
  19. a.company_id,
  20. COUNT(DISTINCT a.rs_calendar_id) total
  21. FROM
  22. rs_calendar AS a
  23. INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id = b.rs_calendar_id
  24. WHERE
  25. a.source = 0
  26. AND a.company_id > 0
  27. AND b.status = 2
  28. AND NOW()> DATE_FORMAT( CONCAT( end_date, " ", end_time ), '%Y-%m-%d %H:%i:%S' )
  29. GROUP BY
  30. a.company_id `
  31. _, err = o.Raw(sql).QueryRows(&items)
  32. return
  33. }
  34. func updateProduct(total, companyId int) (err error){
  35. o := orm.NewOrm()
  36. sql := `UPDATE company_product SET road_show_total=? WHERE company_id=? AND product_name="ficc" `
  37. _, err = o.Raw(sql,total, companyId).Exec()
  38. return
  39. }
  40. type RoadShowTotalSlice struct {
  41. Total int `description:"总路演数"`
  42. CompanyId int `description:"用户id"`
  43. }