|
|
@@ -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
|
|
|
}
|