|
|
@@ -0,0 +1,46 @@ |
|
|
|
package implement |
|
|
|
|
|
|
|
import ( |
|
|
|
"code.fnuoos.com/zhimeng/model.git/src/super/dao" |
|
|
|
"code.fnuoos.com/zhimeng/model.git/src/super/model" |
|
|
|
"xorm.io/xorm" |
|
|
|
) |
|
|
|
|
|
|
|
func NewAgentWithMediumDb(engine *xorm.Engine) dao.AgentWithMediumDao { |
|
|
|
return &AgentWithMediumDb{Db: engine} |
|
|
|
} |
|
|
|
|
|
|
|
type AgentWithMediumDb struct { |
|
|
|
Db *xorm.Engine |
|
|
|
} |
|
|
|
|
|
|
|
func (a AgentWithMediumDb) GetAgentWithMediumByMediumIdAndAgentId(mediumId, agentId int) (medium *model.AgentWithMedium) { |
|
|
|
medium = new(model.AgentWithMedium) |
|
|
|
get, err := a.Db.Where("medium_id=? and agent_id=?", mediumId, agentId).Get(medium) |
|
|
|
if get == false || err != nil { |
|
|
|
return nil |
|
|
|
} |
|
|
|
return medium |
|
|
|
} |
|
|
|
func (a AgentWithMediumDb) FindAgentWithMediumList(name, state string, agentId, mediumId, page, limit int) (list []dao.AgentWithMediumGroup, total int64, err error) { |
|
|
|
sess := a.Db.Desc("agent_with_medium.id").Limit(limit, (page-1)*limit) |
|
|
|
if name != "" { |
|
|
|
sess.And("medium_list.company_name like ?", "%"+name+"%") |
|
|
|
} |
|
|
|
if state != "" { |
|
|
|
sess.And("medium_list.state = ?", state) |
|
|
|
} |
|
|
|
if agentId > 0 { |
|
|
|
sess.And("agent_with_medium.agent_id = ?", agentId) |
|
|
|
} |
|
|
|
if mediumId > 0 { |
|
|
|
sess.And("agent_with_medium.medium_id = ?", mediumId) |
|
|
|
} |
|
|
|
sess.Join("LEFT", "medium_list", "medium_list.medium_id = agent_with_medium.medium_id") |
|
|
|
sess.Join("LEFT", "agent_list", "agent_list.agent_id = agent_with_medium.agent_id") |
|
|
|
total, err = sess.FindAndCount(&list) |
|
|
|
if err != nil { |
|
|
|
return nil, 0, err |
|
|
|
} |
|
|
|
return |
|
|
|
} |