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