feat:完善信息,增加需求指派功能
This commit is contained in:
@ -291,6 +291,19 @@ func (*Manage) Agent(c *gin.Context) {
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Manage) AgentSelect(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.TenantIDStringForm
|
||||
Keyword string `json:"keyword" form:"keyword"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := manage.NewAgent()(api.GetSession()(c).(*session.Admin)).Select(form.Convert(), form.Keyword)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Manage) AgentDetail(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
|
@ -355,6 +355,19 @@ func (*Technology) DemandDelete(c *gin.Context) {
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Technology) DemandAssign(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
AgentID string `json:"agent_id" form:"agent_id" binding:"required"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology.NewDemand()(api.GetSession()(c).(*session.Admin)).Assign(form.Convert(), (&api.IDStringForm{ID: form.AgentID}).Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Technology) Project(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.TenantIDStringForm
|
||||
|
@ -42,6 +42,12 @@ type (
|
||||
*model2.ManageAgent
|
||||
IDImage *model2.ManageAgentIDImage `json:"id_image"`
|
||||
}
|
||||
// AgentSelect 经纪人筛选信息
|
||||
AgentSelect struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Mobile string `json:"mobile"`
|
||||
}
|
||||
// AgentParams 经纪人参数信息
|
||||
AgentParams struct {
|
||||
ID, TenantID uint64
|
||||
@ -105,6 +111,35 @@ func (c *Agent) Instance(tenantID uint64, name string, status int, page, pageSiz
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
// Select 筛选信息
|
||||
func (c *Agent) Select(tenantID uint64, keyword string) ([]*AgentSelect, error) {
|
||||
mManageAgent := model.NewManageAgent()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if tenantID > 0 {
|
||||
where = append(where, model2.NewWhere("tenant_id", tenantID))
|
||||
}
|
||||
if keyword != "" {
|
||||
where = append(where, model2.NewWhereValue("(name LIKE '%"+keyword+"%') OR (mobile LIKE '%"+keyword+"%')"))
|
||||
}
|
||||
out, err := mManageAgent.Agent(where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*AgentSelect, len(out))
|
||||
|
||||
for k, v := range out {
|
||||
list[k] = &AgentSelect{
|
||||
ID: v.GetEncodeID(),
|
||||
Name: v.Name,
|
||||
Mobile: v.Mobile,
|
||||
}
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// Detail 详细信息
|
||||
func (c *Agent) Detail(id uint64) (*AgentDetail, error) {
|
||||
mManageAgent := model.NewManageAgent()
|
||||
|
@ -123,6 +123,36 @@ func (c *Demand) Delete(id uint64) error {
|
||||
return model2.Delete(mTechnologyDemand.TechnologyDemand)
|
||||
}
|
||||
|
||||
// Assign 指派经纪人
|
||||
func (c *Demand) Assign(id, agentID uint64) error {
|
||||
mTechnologyDemand := model.NewTechnologyDemand()
|
||||
mTechnologyDemand.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mTechnologyDemand.TechnologyDemand, []string{"id", "tenant_id"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,需求信息不存在或已被删除")
|
||||
} else if c.TenantID > 0 && mTechnologyDemand.TenantID != c.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
// 查询该需求是否已经指派
|
||||
mTechnologyDemandService := model.NewTechnologyDemandService()
|
||||
|
||||
var count int64
|
||||
|
||||
if err = model2.Count(mTechnologyDemandService.TechnologyDemandService, &count, model2.NewWhere("demand_id", id)); err != nil {
|
||||
return err
|
||||
} else if count > 0 {
|
||||
return errors.New("操作错误,该需求信息已指派,请勿重复指派")
|
||||
}
|
||||
mTechnologyDemandService.DemandID = id
|
||||
mTechnologyDemandService.AgentID = agentID
|
||||
|
||||
return model2.Create(mTechnologyDemandService.TechnologyDemandService)
|
||||
}
|
||||
|
||||
func NewDemand() DemandHandle {
|
||||
return func(session *session.Admin) *Demand {
|
||||
return &Demand{session}
|
||||
|
@ -16,6 +16,27 @@ type ManageAgentInfo struct {
|
||||
model.Area
|
||||
}
|
||||
|
||||
func (m *ManageAgent) Agent(where ...*model.ModelWhere) ([]*model.ManageAgent, error) {
|
||||
db := orm.GetDB().Table(m.TableName()).
|
||||
Select("id", "name", "mobile")
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
if v.Condition == "" {
|
||||
db.Where(v.Value)
|
||||
continue
|
||||
}
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*model.ManageAgent, 0)
|
||||
|
||||
if err := db.Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Agents 经纪人信息
|
||||
func (m *ManageAgent) Agents(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageAgentInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS a").
|
||||
|
11
app/api/admin/model/technology_demand_service.go
Normal file
11
app/api/admin/model/technology_demand_service.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type TechnologyDemandService struct {
|
||||
*model.TechnologyDemandService
|
||||
}
|
||||
|
||||
func NewTechnologyDemandService() *TechnologyDemandService {
|
||||
return &TechnologyDemandService{model.NewTechnologyDemandService()}
|
||||
}
|
Reference in New Issue
Block a user