1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package roadshow
- import (
- "context"
- "github.com/beego/beego/v2/client/orm"
- )
- func RoadShow(cont context.Context) (err error) {
- roadShowTotalList, _ := GetRoadShowTotal()
- for _, roadShowTotal := range roadShowTotalList {
- err := updateProduct(roadShowTotal.Total, roadShowTotal.CompanyId)
- if err != nil {
- return err
- }
- }
- return
- }
- func GetRoadShowTotal() (items []*RoadShowTotalSlice, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- a.company_id,
- COUNT(DISTINCT a.rs_calendar_id) total
- FROM
- rs_calendar AS a
- INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id = b.rs_calendar_id
- WHERE
- a.source = 0
- AND a.company_id > 0
- AND b.status = 2
- AND NOW()> DATE_FORMAT( CONCAT( end_date, " ", end_time ), '%Y-%m-%d %H:%i:%S' )
- GROUP BY
- a.company_id `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- func updateProduct(total, companyId int) (err error){
- o := orm.NewOrm()
- sql := `UPDATE company_product SET road_show_total=? WHERE company_id=? AND product_name="ficc" `
- _, err = o.Raw(sql,total, companyId).Exec()
- return
- }
- type RoadShowTotalSlice struct {
- Total int `description:"总路演数"`
- CompanyId int `description:"用户id"`
- }
|