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