package service import ( "errors" "fmt" "strconv" "time" "youngee_b_api/app/dao" "youngee_b_api/app/entity" "youngee_b_api/app/vo" ) type BillService struct{} // 电商带货账单支付 func (s BillService) PaySelection(param *vo.PayParam) error { selectionId := param.ObjectId selectionInfo, err1 := dao.SelectionInfoDAO{}.GetSelectionInfoById(selectionId) if err1 != nil { return err1 } selectionStatus := selectionInfo.SelectionStatus if selectionStatus != 4 { return errors.New("状态异常") } _, err2 := dao.EnterpriseDao{}.UpdateEnterpriseBalanceAndFrozen(selectionInfo.EnterpriseID, selectionInfo.EstimatedCost) if err2 != nil { return err2 } err3 := dao.SelectionInfoDAO{}.UpdateSelectionInfo(entity.SelectionInfo{SelectionID: selectionId, SelectionStatus: 6, PayAt: time.Now()}) if err3 != nil { return err3 } return nil } // 品牌种草账单支付 func (s BillService) PayProject(param *vo.PayParam) error { projectId := param.ObjectId projectInfo, err1 := dao.ProjectDAO{}.GetProjectById(projectId) if err1 != nil { return err1 } projectStatus := projectInfo.ProjectStatus if projectStatus != 6 { return errors.New("状态异常") } _, err2 := dao.EnterpriseDao{}.UpdateEnterpriseBalanceAndFrozen(projectInfo.EnterpriseID, projectInfo.NeedPay) if err2 != nil { return err2 } err3 := dao.ProjectDAO{}.UpdateProject(entity.Project{ProjectId: projectId, ProjectStatus: 8, PayAt: time.Now()}) if err3 != nil { return err3 } return nil } // 本地生活账单支付 func (s BillService) PayLocalLife(param *vo.PayParam) error { localId := param.ObjectId localInfo, err1 := dao.LocalLifeDao{}.GetLocalById(localId) if err1 != nil { return err1 } localStatus := localInfo.TaskStatus if localStatus != 6 { return errors.New("状态异常") } _, err2 := dao.EnterpriseDao{}.UpdateEnterpriseBalanceAndFrozen(localInfo.EnterpriseID, localInfo.NeedPay) if err2 != nil { return err2 } err3 := dao.LocalLifeDao{}.UpdateLocal(entity.LocalLifeInfo{LocalID: localId, TaskStatus: 8, PayAt: time.Now()}) if err3 != nil { return err3 } return nil } // 电商带货账单列表 func (s BillService) GetBillSelectionTaskList(param *vo.SelectionSearchParam) (vo.ResultVO, error) { if param.Page == 0 { param.Page = 1 } if param.PageSize == 0 { param.PageSize = 10 } var result vo.ResultVO reBillSelectionTaskPreviews, total, err := (&dao.SelectionInfoDAO{}).GetBillSelectionPreviews(param) if err != nil { return result, err } for i := range reBillSelectionTaskPreviews { var creatorName string var productName string var productPrice float64 var mainImage string var reward float64 if reBillSelectionTaskPreviews[i].SubAccountId == 0 { enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reBillSelectionTaskPreviews[i].EnterpriseId) if err == nil && enterprise != nil { creatorName = enterprise.BusinessName } } else { subAccount, err := dao.SubAccountDao{}.GetSubAccount(reBillSelectionTaskPreviews[i].SubAccountId) if err == nil && subAccount != nil { creatorName = subAccount.SubAccountName } } product, err := dao.ProductDAO{}.GetProductByID(reBillSelectionTaskPreviews[i].ProductId) if err == nil && product != nil { productName = product.ProductName productPrice = product.ProductPrice } mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByProductID(reBillSelectionTaskPreviews[i].ProductId) rewardStrategys, err := dao.RewardStrategyDao{}.GetRewardStrategyBySelectionId(reBillSelectionTaskPreviews[i].SelectionId) for _, rewardStrategy := range rewardStrategys { reward += rewardStrategy.Reward } reBillSelectionTaskPreviews[i].CreatorName = creatorName reBillSelectionTaskPreviews[i].ProductName = productName reBillSelectionTaskPreviews[i].ProductPrice = productPrice reBillSelectionTaskPreviews[i].MainImage = mainImage reBillSelectionTaskPreviews[i].Reward = reward } result = vo.ResultVO{ Page: param.Page, PageSize: param.PageSize, Total: total, Data: reBillSelectionTaskPreviews, } return result, nil } // 品牌种草账单列表 func (s BillService) GetBillProjectTaskList(param *vo.ProjectSearchParam) (vo.ResultVO, error) { if param.Page == 0 { param.Page = 1 } if param.PageSize == 0 { param.PageSize = 10 } var result vo.ResultVO reBillProjectTaskPreviews, total, err := (&dao.ProjectDAO{}).GetBillProjectPreviews(param) if err != nil { return result, err } for i := range reBillProjectTaskPreviews { var creatorName string var productName string var productPrice float64 var mainImage string if reBillProjectTaskPreviews[i].SubAccountId == 0 { enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reBillProjectTaskPreviews[i].EnterpriseId) if err == nil && enterprise != nil { creatorName = enterprise.BusinessName } } else { subAccount, err := dao.SubAccountDao{}.GetSubAccount(reBillProjectTaskPreviews[i].SubAccountId) if err == nil && subAccount != nil { creatorName = subAccount.SubAccountName } } product, err := dao.ProductDAO{}.GetProductByID(reBillProjectTaskPreviews[i].ProductId) if err == nil && product != nil { productName = product.ProductName productPrice = product.ProductPrice } mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByProductID(reBillProjectTaskPreviews[i].ProductId) reBillProjectTaskPreviews[i].CreatorName = creatorName reBillProjectTaskPreviews[i].ProductName = productName reBillProjectTaskPreviews[i].ProductPrice = productPrice reBillProjectTaskPreviews[i].MainImage = mainImage } result = vo.ResultVO{ Page: param.Page, PageSize: param.PageSize, Total: total, Data: reBillProjectTaskPreviews, } return result, nil } // 品牌种草账单服务商列表 func (s BillService) GetBillProjectSupplierList(param *vo.SearchSupplierBillParam) (vo.ResultVO, error) { if param.Page == 0 { param.Page = 1 } if param.PageSize == 0 { param.PageSize = 10 } var result vo.ResultVO var reBillSuppliers []vo.ReBillSupplier var status int64 if param.Status == 1 { status = 8 } else if param.Status == 2 { status = 10 } sProjectInfos, total, err := dao.SProjectDao{}.GetSProjectByProjectStatus(param.TaskId, status, param.Page, param.PageSize) if err != nil { return result, err } project, err01 := dao.ProjectDAO{}.GetProjectById(param.TaskId) if err01 != nil || project == nil { return result, err01 } serviceRate := project.ServiceChargeRate type SumResult struct { PayAmount float64 `json:"payAmount" gorm:"column:payAmount"` RealAmount float64 `json:"realAmount" gorm:"column:realAmount"` Count int `json:"count" gorm:"column:count"` } var sumResult SumResult _ = dao.Db.Debug(). Model(&entity.ProjectTaskInfo{}). Where("project_id = ? and task_status = ? and supplier_id = ?", param.TaskId, 2, 0). Select("SUM(real_payment) as payAmount, SUM(real_service_charge) as realAmount, count(1) as count"). Scan(&sumResult).Error for _, sProjectInfo := range sProjectInfos { reBillSupplier := vo.ReBillSupplier{ SupplierId: sProjectInfo.SupplierID, TalentNum: sProjectInfo.RecruitNum, ChargeActual: sProjectInfo.ServiceChargeActual, ChargeSettle: sProjectInfo.ServiceChargeSettle, ServiceRate: serviceRate, } supplier, err1 := dao.SupplierDao{}.GetSupplierInfoById(sProjectInfo.SupplierID) if err1 == nil && supplier != nil { reBillSupplier.SupplierName = supplier.SupplierName reBillSupplier.Avatar = supplier.Avatar reBillSupplier.SupplierName = supplier.SupplierName reBillSupplier.CompanyName = supplier.CompanyName reBillSupplier.SupplierType = supplier.SupplierType } if sProjectInfo.BOperatorType == 1 { // 商家主账号 enterprise, err := dao.EnterpriseDao{}.GetEnterprise(sProjectInfo.BOperator) if err == nil && enterprise != nil { reBillSupplier.Inviter = enterprise.BusinessName } } else { // 商家子账号 subId, err2 := strconv.ParseInt(sProjectInfo.BOperator, 10, 64) if err2 != nil { fmt.Println("子账号转换错误:", err) subId = 0 } subAccount, err := dao.SubAccountDao{}.GetSubAccount(subId) if err == nil && subAccount != nil { reBillSupplier.Inviter = subAccount.SubAccountName } } reBillSuppliers = append(reBillSuppliers, reBillSupplier) } resMap := make(map[string]interface{}) resMap["talentNum"] = sumResult.Count resMap["payAmount"] = sumResult.PayAmount resMap["realAmount"] = sumResult.RealAmount resMap["reBillSuppliers"] = reBillSuppliers result = vo.ResultVO{ Page: param.Page, PageSize: param.PageSize, Total: total, Data: resMap, } return result, nil } // 本地生活账单服务商列表 func (s BillService) GetBillLocalSupplierList(param *vo.SearchSupplierBillParam) (vo.ResultVO, error) { if param.Page == 0 { param.Page = 1 } if param.PageSize == 0 { param.PageSize = 10 } var result vo.ResultVO var reBillSuppliers []vo.ReBillSupplier var status int64 if param.Status == 1 { status = 8 } else if param.Status == 2 { status = 10 } sLocalInfos, total, err := dao.SLocalLifeDao{}.GetSLocalByLocalStatus(param.TaskId, status, param.Page, param.PageSize) if err != nil { return result, err } local, err01 := dao.LocalLifeDao{}.GetLocalById(param.TaskId) if err01 != nil || local == nil { return result, err01 } serviceRate := local.ServiceChargeRate type SumResult struct { PayAmount float64 `json:"payAmount" gorm:"column:payAmount"` RealAmount float64 `json:"realAmount" gorm:"column:realAmount"` Count int `json:"count" gorm:"column:count"` } var sumResult SumResult _ = dao.Db.Debug(). Model(&entity.LocalLifeTaskInfo{}). Where("local_id = ? and task_status = ? and supplier_id = ?", param.TaskId, 2, 0). Select("SUM(real_payment) as payAmount, SUM(real_service_charge) as realAmount, count(1) as count"). Scan(&sumResult).Error for _, sLocalInfo := range sLocalInfos { reBillSupplier := vo.ReBillSupplier{ SupplierId: sLocalInfo.SupplierID, TalentNum: sLocalInfo.RecruitNum, ChargeActual: sLocalInfo.ServiceChargeActual, ChargeSettle: sLocalInfo.ServiceChargeSettle, ServiceRate: serviceRate, } supplier, err1 := dao.SupplierDao{}.GetSupplierInfoById(sLocalInfo.SupplierID) if err1 == nil && supplier != nil { reBillSupplier.SupplierName = supplier.SupplierName reBillSupplier.Avatar = supplier.Avatar reBillSupplier.SupplierName = supplier.SupplierName reBillSupplier.CompanyName = supplier.CompanyName reBillSupplier.SupplierType = supplier.SupplierType } if sLocalInfo.BOperatorType == 1 { // 商家主账号 enterprise, err := dao.EnterpriseDao{}.GetEnterprise(sLocalInfo.BOperator) if err == nil && enterprise != nil { reBillSupplier.Inviter = enterprise.BusinessName } } else { // 商家子账号 subId, err2 := strconv.ParseInt(sLocalInfo.BOperator, 10, 64) if err2 != nil { fmt.Println("子账号转换错误:", err) subId = 0 } subAccount, err := dao.SubAccountDao{}.GetSubAccount(subId) if err == nil && subAccount != nil { reBillSupplier.Inviter = subAccount.SubAccountName } } reBillSuppliers = append(reBillSuppliers, reBillSupplier) } resMap := make(map[string]interface{}) resMap["talentNum"] = sumResult.Count resMap["payAmount"] = sumResult.PayAmount resMap["realAmount"] = sumResult.RealAmount resMap["reBillSuppliers"] = reBillSuppliers result = vo.ResultVO{ Page: param.Page, PageSize: param.PageSize, Total: total, Data: resMap, } return result, nil } // 本地生活账单列表 func (s BillService) GetBillLocalLifeTaskList(param *vo.LocalSearchParam) (vo.ResultVO, error) { if param.Page == 0 { param.Page = 1 } if param.PageSize == 0 { param.PageSize = 10 } var result vo.ResultVO reBillLocalTaskPreviews, total, err := (&dao.LocalLifeDao{}).GetBillLocalPreviews(param) if err != nil { return result, err } for i := range reBillLocalTaskPreviews { var creatorName string var storeName string var storeLocation string var mainImage string if reBillLocalTaskPreviews[i].SubAccountId == 0 { enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reBillLocalTaskPreviews[i].EnterpriseId) if err == nil && enterprise != nil { creatorName = enterprise.BusinessName } } else { subAccount, err := dao.SubAccountDao{}.GetSubAccount(reBillLocalTaskPreviews[i].SubAccountId) if err == nil && subAccount != nil { creatorName = subAccount.SubAccountName } } store, err := dao.StoreDao{}.GetStoreByID(reBillLocalTaskPreviews[i].StoreId) if err == nil && store != nil { storeName = store.StoreName storeLocation = store.StoreLocation } mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByStoreID(reBillLocalTaskPreviews[i].StoreId) reBillLocalTaskPreviews[i].CreatorName = creatorName reBillLocalTaskPreviews[i].StoreName = storeName reBillLocalTaskPreviews[i].StoreLocation = storeLocation reBillLocalTaskPreviews[i].MainImage = mainImage } result = vo.ResultVO{ Page: param.Page, PageSize: param.PageSize, Total: total, Data: reBillLocalTaskPreviews, } return result, nil }