Xingyu Xian 2 месяцев назад
Родитель
Сommit
ec89989ae5
3 измененных файлов с 161 добавлено и 17 удалено
  1. 26 1
      db/supplier_withdraw.go
  2. 4 3
      model/http_model/supplier_withdraw_list.go
  3. 131 13
      service/supplier.go

+ 26 - 1
db/supplier_withdraw.go

@@ -2,10 +2,11 @@ package db
 
 import (
 	"context"
+	"github.com/sirupsen/logrus"
 	"youngee_b_api/model/gorm_model"
 )
 
-// CreateSupplierWithdraw 查询服务商收入列表
+// CreateSupplierWithdraw 创建服务商提现信息
 func CreateSupplierWithdraw(ctx context.Context, supplierWithdraw []*gorm_model.YounggeeSupplierWithdraw) error {
 	db := GetWriteDB(ctx)
 	err := db.Create(&supplierWithdraw).Error
@@ -14,3 +15,27 @@ func CreateSupplierWithdraw(ctx context.Context, supplierWithdraw []*gorm_model.
 	}
 	return nil
 }
+
+// GetSupplierWithdrawList 查询服务商提现列表
+func GetSupplierWithdrawList(ctx context.Context, pageSize int32, pageNum int32, supplierId int, withdrawStatus int) ([]*gorm_model.YounggeeSupplierWithdraw, int64, error) {
+	db := GetReadDB(ctx)
+
+	// 1. 根据基本信息过滤
+	db = db.Debug().Model(gorm_model.YounggeeSupplierWithdraw{}).Where("supplier_id = ? and withdraw_status = ?", supplierId, withdrawStatus)
+
+	// 2. 确定查询总数和返回当前页数据
+	var total int64
+	var SupplierWithdrawList []*gorm_model.YounggeeSupplierWithdraw
+	if err := db.Count(&total).Error; err != nil {
+		logrus.WithContext(ctx).Errorf("[SupplierWithdrawList] error query mysql total, err:%+v", err)
+		return nil, 0, err
+	}
+	limit := pageSize
+	offset := pageSize * pageNum // assert pageNum start with 0
+	err := db.Order("supplier_withdraw_id desc").Limit(int(limit)).Offset(int(offset)).Find(&SupplierWithdrawList).Error
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[SupplierWithdrawList] error query mysql total, err:%+v", err)
+		return nil, 0, err
+	}
+	return SupplierWithdrawList, total, nil
+}

+ 4 - 3
model/http_model/supplier_withdraw_list.go

@@ -1,9 +1,10 @@
 package http_model
 
 type SupplierWithdrawListRequest struct {
-	SupplierId int   `json:"supplier_id"` // 服务商ID
-	PageNum    int32 `json:"page_num"`
-	PageSize   int32 `json:"page_size"`
+	SupplierId     int   `json:"supplier_id"`     // 服务商ID
+	WithdrawStatus int   `json:"withdraw_status"` // 提现状态:2提现中,3已提现,4已驳回
+	PageNum        int32 `json:"page_num"`
+	PageSize       int32 `json:"page_size"`
 }
 
 type SupplierWithdrawListData struct {

+ 131 - 13
service/supplier.go

@@ -18,10 +18,10 @@ var Supplier *supplier
 type supplier struct {
 }
 
-// CreateSupplier 创建younggee平台用户账号与服务商信息
+// CreateSupplier 创建younggee平台用户账号与服务商用户信息
 func (*supplier) CreateSupplier(ctx context.Context, phone string) (*http_model.RegisterData, error) {
 	// 1. 创建YG平台用户
-	user := gorm_model.YounggeeUser{
+	userInfo := gorm_model.YounggeeUser{
 		Phone:         phone,
 		User:          "1003",
 		Username:      phone,
@@ -31,22 +31,22 @@ func (*supplier) CreateSupplier(ctx context.Context, phone string) (*http_model.
 		Email:         "",
 		LastLoginTime: time.Now().UTC().Local(),
 	}
-	userId, err := db.CreateUser(ctx, user)
-	if err != nil {
-		log.Infof("[CreateEnterpriseUser] fail,err:%+v", err)
-		return nil, err
+	userId, createUserErr := db.CreateUser(ctx, userInfo)
+	if createUserErr != nil {
+		log.Infof("[CreateSupplierUser] fail,err:%+v", createUserErr)
+		return nil, createUserErr
 	} else {
 		// 2. 创建服务商信息
-		supplier := &gorm_model.YoungeeSupplier{
+		supplierInfo := &gorm_model.YoungeeSupplier{
 			SupplierName: phone,
 			PhoneNumber:  phone,
 			UserId:       *userId,
 		}
-		supplierId, err := db.CreateSupplier(ctx, *supplier)
+		supplierId, createSupplierErr := db.CreateSupplier(ctx, *supplierInfo)
 		fmt.Println(supplierId)
-		if err != nil {
-			log.Infof("[CreateEnterpriseUser] fail,err:%+v", err)
-			return nil, err
+		if createSupplierErr != nil {
+			log.Infof("[CreateSupplierUser] fail,err:%+v", createSupplierErr)
+			return nil, createSupplierErr
 		}
 		res := &http_model.RegisterData{
 			UserID: *userId,
@@ -519,11 +519,129 @@ func (*supplier) CreateSupplierWithdraw(ctx context.Context, req *http_model.Cre
 	if err != nil {
 		return err
 	}
-
 	return nil
 }
 
 // GetSupplierWithdrawList 服务商提现列表
 func (*supplier) GetSupplierWithdrawList(ctx context.Context, req *http_model.SupplierWithdrawListRequest) (*http_model.SupplierWithdrawListData, error) {
-	
+
+	var supplierWithdrawListData *http_model.SupplierWithdrawListData
+	supplierWithdrawListData = &http_model.SupplierWithdrawListData{}
+
+	// 1. 根据服务商ID和提现状态去查找提现信息列表
+	supplierWithdrawList, total, supplierWithdrawErr := db.GetSupplierWithdrawList(ctx, req.PageSize, req.PageNum, req.SupplierId, req.WithdrawStatus)
+	if supplierWithdrawErr != nil {
+		return nil, supplierWithdrawErr
+	}
+	if supplierWithdrawList != nil {
+		supplierWithdrawListData.Total = total
+		supplierInfo, supplierErr := db.GetSupplierById(ctx, req.SupplierId)
+		if supplierErr != nil {
+			return nil, supplierErr
+		}
+		if supplierInfo != nil {
+			if supplierInfo.SupplierId == 1 {
+				// 2. 个人服务商
+				var supplierWithdrawInfo *http_model.SupplierWithdrawInfo
+				supplierWithdrawInfo = &http_model.SupplierWithdrawInfo{}
+				for _, withdrawInfo := range supplierWithdrawList {
+					IncomeId, IncomeIdErr := strconv.Atoi(withdrawInfo.IncomeIds)
+					if IncomeIdErr != nil {
+						return nil, IncomeIdErr
+					}
+					incomeInfo, incomeErr := db.GetIncomeInfoByIncomeId(ctx, IncomeId)
+					if incomeErr != nil {
+						return nil, incomeErr
+					}
+					if incomeInfo != nil {
+						var sTaskInfo *http_model.STaskInfo
+						sTaskInfo = &http_model.STaskInfo{}
+						if incomeInfo.IncomeType == 1 {
+							sTaskInfo.Id = incomeInfo.SProjectID
+							sTaskInfo.ServiceCharge = incomeInfo.ServiceChargeSettle
+						} else if incomeInfo.IncomeType == 3 {
+							sTaskInfo.Id = incomeInfo.SLocalID
+							sTaskInfo.ServiceCharge = incomeInfo.ServiceChargeSettle
+						}
+						supplierWithdrawInfo.STaskInfo = append(supplierWithdrawInfo.STaskInfo, sTaskInfo)
+					}
+					supplierWithdrawInfo.SupplierType = 1
+					supplierWithdrawInfo.SupplierWithdrawId = withdrawInfo.SupplierWithdrawId
+					supplierWithdrawInfo.WithdrawAmount = withdrawInfo.WithdrawAmount
+					supplierWithdrawInfo.AmountPayable = withdrawInfo.AmountPayable
+					supplierWithdrawInfo.Name = withdrawInfo.Name
+					supplierWithdrawInfo.IDNumber = withdrawInfo.IDNumber
+					supplierWithdrawInfo.BankName = withdrawInfo.BankName
+					supplierWithdrawInfo.BankNumber = withdrawInfo.BankNumber
+					supplierWithdrawInfo.Phone = withdrawInfo.Phone
+					// supplierWithdrawInfo.Company = withdrawInfo.Company
+					supplierWithdrawInfo.SupplyTime = conv.MustString(withdrawInfo.SupplyTime)
+					supplierWithdrawInfo.AgreeTime = conv.MustString(withdrawInfo.AgreeTime)
+					supplierWithdrawInfo.RejectTime = conv.MustString(withdrawInfo.RejectTime)
+					supplierWithdrawInfo.FailReason = withdrawInfo.FailReason
+					supplierWithdrawListData.WithdrawList = append(supplierWithdrawListData.WithdrawList, supplierWithdrawInfo)
+				}
+			} else if supplierInfo.SupplierId == 2 {
+				// 3. 企业服务商
+				for _, withdrawInfo := range supplierWithdrawList {
+					var supplierWithdrawInfo *http_model.SupplierWithdrawInfo
+					supplierWithdrawInfo = &http_model.SupplierWithdrawInfo{}
+					InvoiceId, InvoiceIdErr := strconv.Atoi(withdrawInfo.InvoiceIds)
+					if InvoiceIdErr != nil {
+						return nil, InvoiceIdErr
+					}
+					incomeIds, incomeIdsErr := db.GetIncomeIdsByInvoiceId(ctx, InvoiceId)
+					if incomeIdsErr != nil {
+						return nil, incomeIdsErr
+					}
+					if incomeIds != "" {
+						strSlice := strings.Split(incomeIds, ",")
+						intSlice := make([]int, len(strSlice))
+						for i, s := range strSlice {
+							num, err := strconv.Atoi(s)
+							if err != nil {
+								fmt.Println("转换错误:", err)
+								return nil, err
+							}
+							intSlice[i] = num
+						}
+						for _, incomeId := range intSlice {
+							var sTaskInfo *http_model.STaskInfo
+							sTaskInfo = &http_model.STaskInfo{}
+							currIncome, incomeInfoErr := db.GetIncomeInfoByIncomeId(ctx, incomeId)
+							if incomeInfoErr != nil {
+								return nil, incomeInfoErr
+							}
+							if currIncome != nil {
+								if currIncome.IncomeType == 1 {
+									sTaskInfo.Id = currIncome.SProjectID
+									sTaskInfo.ServiceCharge = currIncome.ServiceChargeSettle
+								} else if currIncome.IncomeType == 3 {
+									sTaskInfo.Id = currIncome.SLocalID
+									sTaskInfo.ServiceCharge = currIncome.ServiceChargeSettle
+								}
+								supplierWithdrawInfo.STaskInfo = append(supplierWithdrawInfo.STaskInfo, sTaskInfo)
+							}
+						}
+					}
+					supplierWithdrawInfo.SupplierType = 1
+					supplierWithdrawInfo.SupplierWithdrawId = withdrawInfo.SupplierWithdrawId
+					supplierWithdrawInfo.WithdrawAmount = withdrawInfo.WithdrawAmount
+					supplierWithdrawInfo.AmountPayable = withdrawInfo.AmountPayable
+					supplierWithdrawInfo.Name = withdrawInfo.Name
+					supplierWithdrawInfo.IDNumber = withdrawInfo.IDNumber
+					supplierWithdrawInfo.BankName = withdrawInfo.BankName
+					supplierWithdrawInfo.BankNumber = withdrawInfo.BankNumber
+					supplierWithdrawInfo.Phone = withdrawInfo.Phone
+					supplierWithdrawInfo.Company = withdrawInfo.Company
+					supplierWithdrawInfo.SupplyTime = conv.MustString(withdrawInfo.SupplyTime)
+					supplierWithdrawInfo.AgreeTime = conv.MustString(withdrawInfo.AgreeTime)
+					supplierWithdrawInfo.RejectTime = conv.MustString(withdrawInfo.RejectTime)
+					supplierWithdrawInfo.FailReason = withdrawInfo.FailReason
+					supplierWithdrawListData.WithdrawList = append(supplierWithdrawListData.WithdrawList, supplierWithdrawInfo)
+				}
+			}
+		}
+	}
+	return supplierWithdrawListData, nil
 }