Browse Source

feature(招标记录管理): 招标记录管理开发

ZZH-wl 2 years ago
parent
commit
195b505914

+ 10 - 9
opms_parent/app/model/cust/cust_customer_bid_record.go

@@ -16,15 +16,16 @@ type CustCustomerBidRecord internal.CustCustomerBidRecord
 // Fill with you ideas below.
 type CustCustomerBidRecordListReq struct {
 	request.PageReq
-	SearchText    string      `json:"searchText"`    // 客户名称,招标产品名称,招标信息标题,中标单位
-	CustId        int         `json:"custId"`        // 关联客户
-	CuctName      string      `json:"cuctName"`      // 客户名称
-	ProductName   string      `json:"productName"`   // 招标产品名称
-	PublishedTime *gtime.Time `json:"publishedTime"` // 发布招标日期
-	Budget        float64     `json:"budget"`        // 项目预算
-	Title         string      `json:"title"`         // 招标信息标题
-	InfoType      string      `json:"infoType"`      // 信息分类
-	Bidder        string      `json:"bidder"`        // 中标单位
+	SearchText     string      `json:"searchText"`     // 客户名称,招标产品名称,招标信息标题,中标单位
+	CustId         int         `json:"custId"`         // 关联客户
+	CuctName       string      `json:"cuctName"`       // 客户名称
+	ProductName    string      `json:"productName"`    // 招标产品名称
+	PublishedTime  *gtime.Time `json:"publishedTime"`  // 发布招标日期
+	Budget         float64     `json:"budget"`         // 项目预算
+	Title          string      `json:"title"`          // 招标信息标题
+	InfoType       string      `json:"infoType"`       // 信息分类
+	Bidder         string      `json:"bidder"`         // 中标单位
+	CustProvinceId []string    `json:"custProvinceId"` // 所在省ID
 }
 
 type CustCustomerBidRecordAddReq struct {

+ 25 - 8
opms_parent/app/service/cust/cust_customer_bid_record.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"database/sql"
 	"fmt"
+	"github.com/gogf/gf/frame/g"
 
 	dao "dashoo.cn/micro/app/dao/cust"
 	model "dashoo.cn/micro/app/model/cust"
@@ -20,6 +21,7 @@ type CustCustomerBidRecordService struct {
 	CustomerDao *dao.CustCustomerDao
 	Tenant      string
 	userInfo    request.UserInfo
+	DataScope   g.Map `json:"dataScope"`
 }
 
 func NewCustCustomerBidRecordService(ctx context.Context) (*CustCustomerBidRecordService, error) {
@@ -37,6 +39,7 @@ func NewCustCustomerBidRecordService(ctx context.Context) (*CustCustomerBidRecor
 		CustomerDao: dao.NewCustCustomerDao(tenant),
 		Tenant:      tenant,
 		userInfo:    userInfo,
+		DataScope:   userInfo.DataScope,
 	}, nil
 }
 
@@ -52,22 +55,36 @@ func (s CustCustomerBidRecordService) Get(ctx context.Context, id int) (*model.C
 }
 
 func (s CustCustomerBidRecordService) List(ctx context.Context, req *model.CustCustomerBidRecordListReq) (int, []*model.CustCustomerBidRecord, error) {
-	dao := &s.Dao.CustCustomerBidRecordDao
+	ctx = context.WithValue(ctx, "contextService", s)
+	dao := s.Dao.As("bid").DataScope(ctx, "customer", "sales_id").Unscoped().WhereNull("bid.deleted_time").
+		LeftJoin(s.CustomerDao.Table, "customer", "bid.cust_id=customer.id AND `customer`.`deleted_time` IS NULL ")
 	if req.SearchText != "" {
 		likestr := fmt.Sprintf("%%%s%%", req.SearchText)
-		dao = dao.Where("(cuct_name LIKE ? || product_name LIKE ? || title LIKE ? || bidder LIKE ?)", likestr, likestr, likestr, likestr)
+		dao = dao.Where("(bid.cuct_name LIKE ? || bid.product_name LIKE ? || bid.title LIKE ? || bid.bidder LIKE ?)", likestr, likestr, likestr, likestr)
 	}
 	if req.CustId != 0 {
-		dao = dao.Where("cust_id = ?", req.CustId)
+		dao = dao.Where("bid.cust_id = ?", req.CustId)
 	}
 	if req.InfoType != "" {
-		dao = dao.Where("info_type = ?", req.InfoType)
+		dao = dao.Where("bid.info_type = ?", req.InfoType)
 	}
 	if req.BeginTime != "" {
-		dao = dao.Where("created_time > ?", req.BeginTime)
+		dao = dao.Where("bid.created_time > ?", req.BeginTime)
 	}
 	if req.EndTime != "" {
-		dao = dao.Where("created_time < ?", req.EndTime)
+		dao = dao.Where("bid.created_time < ?", req.EndTime)
+	}
+	if req.Title != "" {
+		dao = dao.WhereLike("bid.title", "%"+req.Title+"%")
+	}
+	if req.ProductName != "" {
+		dao = dao.WhereLike("bid.product_name", "%"+req.ProductName+"%")
+	}
+	if req.CuctName != "" {
+		dao = dao.WhereLike("customer.cuct_name", "%"+req.CuctName+"%")
+	}
+	if len(req.CustProvinceId) != 0 {
+		dao = dao.WhereIn("customer.cust_province_id", req.CustProvinceId)
 	}
 
 	total, err := dao.Count()
@@ -83,8 +100,8 @@ func (s CustCustomerBidRecordService) List(ctx context.Context, req *model.CustC
 	}
 	dao = dao.Order(orderby)
 
-	ents := []*model.CustCustomerBidRecord{}
-	err = dao.Structs(&ents)
+	var ents []*model.CustCustomerBidRecord
+	err = dao.Fields("bid.*").Structs(&ents)
 	if err != nil && err != sql.ErrNoRows {
 		return 0, nil, err
 	}