Xingyu Xian 5 päivää sitten
vanhempi
commit
706b070627

+ 73 - 0
db/s_project.go

@@ -245,3 +245,76 @@ func GetSProjectTaskList(ctx context.Context, sProjectId int, talentId string, p
 
 	return taskInfos, totalTask, nil
 }
+
+// GetUnifiedTaskList 获取统一的账单列表(合并本地生活和种草任务)
+func GetUnifiedTaskList(ctx context.Context, supplierId int, pageSize, pageNum int32, status int, condition string) ([]*http_model.SupplierAmountBillListData, int64, error) {
+	db := GetReadDB(ctx).Debug()
+
+	var statusCondition string
+	if status == 10 {
+		statusCondition = "= 10"
+	} else {
+		statusCondition = "< 10"
+	}
+
+	localLifeSQL := fmt.Sprintf(`
+        SELECT
+            s_local_id AS s_id,
+            local_id AS id,
+            local_name AS name,
+            3 AS type,
+            local_platform AS platform,
+            apply_num,
+            recruit_num,
+            settle_num,
+            enterprise_id,
+            supplier_id,
+            service_charge,
+            create_time,
+            finish_time,
+            store_id AS product_id
+        FROM younggee_s_local_life_info
+        WHERE supplier_id = ? AND task_status %s
+    `, statusCondition)
+
+	projectSQL := fmt.Sprintf(`
+        SELECT
+            s_project_id AS s_id,
+            project_id AS id,
+            project_name AS name,
+            1 AS type,
+            project_platform AS platform,
+            apply_num,
+            recruit_num,
+            settle_num,
+            enterprise_id,
+            supplier_id,
+            service_charge,
+            create_time,
+            finish_time,
+            product_id
+        FROM younggee_s_project_info
+        WHERE supplier_id = ? AND project_status %s
+    `, statusCondition)
+
+	var total int64
+	countSQL := "SELECT COUNT(*) FROM ((" + localLifeSQL + ") UNION ALL (" + projectSQL + ")) AS combined"
+	if err := db.Raw(countSQL, supplierId, supplierId).Scan(&total).Error; err != nil {
+		logrus.WithContext(ctx).Errorf("[GetUnifiedTaskList] error query total count, err:%+v", err)
+		return nil, 0, err
+	}
+
+	offset := pageSize * pageNum
+	paginatedSQL := `
+        SELECT * FROM ((` + localLifeSQL + `) UNION ALL (` + projectSQL + `)) AS combined
+        ORDER BY create_time DESC
+        LIMIT ? OFFSET ?
+    `
+	var tasks []*http_model.SupplierAmountBillListData
+	if err := db.Raw(paginatedSQL, supplierId, supplierId, pageSize, offset).Scan(&tasks).Error; err != nil {
+		logrus.WithContext(ctx).Errorf("[GetUnifiedTaskList] error query data, err:%+v", err)
+		return nil, 0, err
+	}
+
+	return tasks, total, nil
+}

+ 4 - 1
handler/supplier_amount_bill_list.go

@@ -38,9 +38,12 @@ func (h *SupplierAmountBillListHandler) run() {
 	data, err := service.Supplier.GetSupplierAmountBillList(h.ctx, h.req)
 	if err != nil {
 		h.resp.Message = err.Error()
+		h.resp.Status = 40000
+		return
 	}
 	h.resp.Data = data
-	h.resp.Message = "成功查询"
+	h.resp.Message = "ok"
+	h.resp.Status = 20000
 }
 
 func (h *SupplierAmountBillListHandler) checkParam() error {

+ 4 - 1
handler/supplier_bill_amount.go

@@ -38,10 +38,13 @@ func (h *SupplierBillAmountHandler) run() {
 	data, err := service.Supplier.GetSupplierBillAmount(h.ctx, h.req)
 	if err != nil {
 		h.resp.Message = err.Error()
+		h.resp.Status = 40000
+		return
 	}
 	h.resp.Data = data
 	// fmt.Println(data)
-	h.resp.Message = "成功查询"
+	h.resp.Message = "ok"
+	h.resp.Status = 20000
 }
 
 func (h *SupplierBillAmountHandler) checkParam() error {

+ 28 - 6
model/http_model/supplier_amount_bill_list.go

@@ -1,22 +1,21 @@
 package http_model
 
 type SupplierAmountBillListRequest struct {
+	PageNum    int32  `json:"page"`
+	PageSize   int32  `json:"page_size"`
 	SupplierId int    `json:"supplier_id"` // 服务商ID
-	Status     int    `json:"status"`      // 账单状态
+	Status     int    `json:"status"`      // 列表状态,1进行中,2已入账
 	Condition  string `json:"condition"`   // 筛选条件
-	PageNum    int32  `json:"page_num"`
-	PageSize   int32  `json:"page_size"`
 }
 
 type SupplierAmountBillData struct {
 	SupplierAmountBillList []*SupplierAmountBillListData `json:"supplier_amount_bill_list"` // 任务账单信息
-	FullAmount             float64                       `json:"full_amount"`               // 总余额
-	Settle                 float64                       `json:"settle"`                    // 可提现
 	Total                  int64                         `json:"total"`                     // 数量
 }
 
+/*
 type SupplierAmountBillListData struct {
-	Type int `json:"type"` // 任务类型
+	Type int `json:"type"` // 任务类型 1种草,2带货,3本地生活
 
 	// 种草
 	SProjectId         int     `json:"s_project_id"`         // 服务商加入商单后的种草任务ID
@@ -53,6 +52,29 @@ type SupplierAmountBillListData struct {
 	CreateTime          string  `json:"create_time"`           // 加入商单时间
 }
 
+*/
+
+type SupplierAmountBillListData struct {
+	SId                 int     `json:"s_id"`                  // 统一ID字段,s_local_id 或 s_project_id
+	Id                  string  `json:"id"`                    // local_id 或 project_id
+	Name                string  `json:"name"`                  // local_name 或 project_name
+	Type                int     `json:"type"`                  // 任务类型 1种草,2带货,3本地生活
+	Platform            int64   `json:"platform"`              // local_platform 或 project_platform
+	ApplyNum            int     `json:"apply_num"`             //
+	RecruitNum          int     `json:"recruit_num"`           //
+	SettleNum           int     `json:"settle_num"`            //
+	EnterpriseId        string  `json:"enterprise_id"`         //
+	SupplierId          int     `json:"supplier_id"`           //
+	ServiceChargeActual float64 `json:"service_charge_actual"` // 服务商实际可赚服务费
+	ServiceChargeSettle float64 `json:"service_charge_settle"` // 已结算服务费
+	CreateTime          string  `json:"create_time"`           // 创建时间
+	FinishTime          string  `json:"finish_time"`           // 结案时间
+	MainPhotoUrl        string  `json:"main_photo_url"`        // 主图url
+	Price               float64 `json:"price"`                 // 价格
+	Location            string  `json:"location"`              // 地址
+	ProductId           int     `json:"product_id"`            // 商品或门店ID
+}
+
 func SupplierAmountBillRequest() *SupplierAmountBillListRequest {
 	return new(SupplierAmountBillListRequest)
 }

+ 63 - 1
service/supplier.go

@@ -1062,7 +1062,69 @@ func (*supplier) GetSupplierWithdrawList(ctx context.Context, req *http_model.Su
 }
 
 func (*supplier) GetSupplierAmountBillList(ctx context.Context, req *http_model.SupplierAmountBillListRequest) (*http_model.SupplierAmountBillData, error) {
-	return nil, nil
+
+	var supplierAmountList *http_model.SupplierAmountBillData
+	supplierAmountList = &http_model.SupplierAmountBillData{}
+	var tag int
+	if req.Status == 2 {
+		tag = 10
+	}
+
+	// 1. 账单列表
+	sProjectList, sProjectTotal, sProjectListErr := db.GetUnifiedTaskList(ctx, req.SupplierId, req.PageSize, req.PageNum, tag, req.Condition)
+	if sProjectListErr != nil {
+		return nil, sProjectListErr
+	}
+	// 2. 拼接门店、商品信息
+	if sProjectList != nil {
+		supplierAmountList.Total = sProjectTotal
+		// supplierAmountList.SupplierAmountBillList = sProjectList
+
+		for _, billInfo := range sProjectList {
+			if billInfo.Type == 1 {
+				productInfo, productInfoErr := db.GetProductByID(ctx, int64(billInfo.ProductId))
+				if productInfoErr != nil {
+					return nil, productInfoErr
+				}
+				if productInfo != nil {
+					billInfo.Price = productInfo.ProductPrice
+				}
+				productPhotoInfo, productPhotoErr := db.GetProductPhotoByProductID(ctx, int64(billInfo.ProductId))
+				if productPhotoErr != nil {
+					return nil, productPhotoErr
+				}
+				if productPhotoInfo != nil {
+					for _, photoInfo := range productPhotoInfo {
+						if photoInfo.Symbol == 1 {
+							billInfo.MainPhotoUrl = photoInfo.PhotoUrl
+						}
+					}
+				}
+			} else if billInfo.Type == 3 {
+				storeInfo, storeInfoErr := db.FindStoreById(ctx, billInfo.ProductId)
+				if storeInfoErr != nil {
+					return nil, storeInfoErr
+				}
+				if storeInfo != nil {
+					billInfo.Location = storeInfo.StoreLocation
+				}
+
+				storePhotoInfo, storePhotoErr := db.GetStorePhotoByStoreID(ctx, billInfo.ProductId)
+				if storePhotoErr != nil {
+					return nil, storePhotoErr
+				}
+				if storePhotoInfo != nil {
+					for _, photoInfo := range storePhotoInfo {
+						if photoInfo.Symbol == 1 {
+							billInfo.MainPhotoUrl = photoInfo.PhotoUrl
+						}
+					}
+				}
+			}
+		}
+		supplierAmountList.SupplierAmountBillList = sProjectList
+	}
+	return supplierAmountList, nil
 }
 
 // GetManageInvoiceInfo 查找后台回票信息