Procházet zdrojové kódy

任务结案-商家解冻&服务商到账

Ethan před 1 týdnem
rodič
revize
1a2559b919

+ 24 - 5
app/dao/enterprise_dao.go

@@ -59,19 +59,38 @@ func (d EnterpriseDao) UpdateEnterpriseBalance(enterpriseId string, amount float
 }
 
 // 支付-更新账户余额、冻结金额
-func (d EnterpriseDao) UpdateEnterpriseBalanceAndFrozen(enterpriseId string, amount float64) (*string, error) {
+func (d EnterpriseDao) UpdateEnterpriseBalanceAndFrozen(enterpriseId string, needPay float64) (*string, error) {
 	var enterprise entity.Enterprise
 	var err error
 	err = Db.Debug().Model(&entity.Enterprise{}).Where("enterprise_id = ?", enterpriseId).Find(&enterprise).Error
 	if err != nil {
 		return nil, err
 	}
-	if enterprise.AvailableBalance < amount {
+	if enterprise.AvailableBalance < needPay {
 		return nil, errors.New("可用余额不足")
 	}
-	newBalance := enterprise.Balance - amount
-	newAvailableBalance := enterprise.AvailableBalance - amount
-	newFrozenBalance := enterprise.FrozenBalance + amount
+	newAvailableBalance := enterprise.AvailableBalance - needPay
+	newFrozenBalance := enterprise.FrozenBalance + needPay
+	err = Db.Model(&entity.Enterprise{}).Where("enterprise_id = ?", enterpriseId).Updates(entity.Enterprise{
+		AvailableBalance: newAvailableBalance,
+		FrozenBalance:    newFrozenBalance}).Error
+	if err != nil {
+		return nil, err
+	}
+	return &enterpriseId, nil
+}
+
+// 解冻-更新账户余额、冻结金额
+func (d EnterpriseDao) UpdateEnterpriseBalanceAndFrozen2(enterpriseId string, needPay float64, realPayments float64) (*string, error) {
+	var enterprise entity.Enterprise
+	var err error
+	err = Db.Model(&entity.Enterprise{}).Where("enterprise_id = ?", enterpriseId).Find(&enterprise).Error
+	if err != nil {
+		return nil, err
+	}
+	newBalance := enterprise.Balance - realPayments
+	newAvailableBalance := enterprise.AvailableBalance + (needPay - realPayments)
+	newFrozenBalance := enterprise.FrozenBalance - needPay
 	err = Db.Debug().Model(&entity.Enterprise{}).Where("enterprise_id = ?", enterpriseId).Updates(entity.Enterprise{
 		Balance:          newBalance,
 		AvailableBalance: newAvailableBalance,

+ 1 - 1
app/dao/local_life_dao.go

@@ -211,7 +211,7 @@ func (d LocalLifeDao) GetLocalDraftList(param *vo.LocalDraftParam) ([]vo.ReLocal
 // 获取公开本地生活中全部指定状态值的项目
 func (d LocalLifeDao) GetLocalLifeList(value int64, fieldName string) ([]*entity.LocalLifeInfo, error) {
 	var localLifeInfos []*entity.LocalLifeInfo
-	err := Db.Model(entity.LocalLifeInfo{}).Where(fmt.Sprintf("local_type = ? AND %s = ? ", fieldName), 1, value).Find(&localLifeInfos).Error
+	err := Db.Model(entity.LocalLifeInfo{}).Where(fmt.Sprintf("%s = ? ", fieldName), value).Find(&localLifeInfos).Error
 	if err != nil {
 		return nil, err
 	}

+ 1 - 1
app/dao/project_dao.go

@@ -218,7 +218,7 @@ func (d ProjectDAO) GetProjectDraftList(param *vo.ProjectDraftParam) ([]vo.RePro
 // 获取公开种草中全部指定状态值的项目
 func (d ProjectDAO) GetProjectList(value int64, fieldName string) ([]*entity.Project, error) {
 	var projectInfos []*entity.Project
-	err := Db.Model(entity.Project{}).Where(fmt.Sprintf("project_type = ? AND %s = ? ", fieldName), 1, value).Find(&projectInfos).Error
+	err := Db.Model(entity.Project{}).Where(fmt.Sprintf("%s = ? ", fieldName), value).Find(&projectInfos).Error
 	if err != nil {
 		return nil, err
 	}

+ 16 - 0
app/dao/s_local_dao.go → app/dao/s_local_life_dao.go

@@ -28,6 +28,22 @@ func (d SLocalLifeDao) GetSLocalLifeByStatus(localId string, status int64, page
 	return sLocalLifeInfos, total, nil
 }
 
+// 获取某个 local_id 任务涉及到的服务商
+func (d SLocalLifeDao) GetSLocalLifeByLocalId(localId string) ([]*entity.SLocalLifeInfo, error) {
+	var sLocalLifeInfos []*entity.SLocalLifeInfo
+	err := Db.Debug().Model(&entity.SLocalLifeInfo{}).Where("local_id = ?", localId).Select("s_local_id, local_id, supplier_id, service_charge_settle, supplier_type").Find(&sLocalLifeInfos).Error
+	return sLocalLifeInfos, err
+}
+
+// 更新任务
+func (d SLocalLifeDao) UpdateSLocalLife(sLocalLifeInfo entity.SLocalLifeInfo) error {
+	err := Db.Model(&entity.SLocalLifeInfo{}).Where("s_local_id = ?", sLocalLifeInfo.SLocalID).Updates(sLocalLifeInfo).Error
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
 //// 检查给定的服务商是否在该商家库中
 //func (d SupplierDao) EnterpriseDatabaseCheck(enterpriseId string, supplierId int64) (bool, error) {
 //	var count int64

+ 16 - 0
app/dao/s_project_dao.go

@@ -28,6 +28,22 @@ func (d SProjectDao) GetSProjectByStatus(projectId string, status int64, page in
 	return sProjectInfos, total, nil
 }
 
+// 获取某个 project_id 任务涉及到的服务商
+func (d SProjectDao) GetSProjectByProjectId(projectId string) ([]*entity.SProjectInfo, error) {
+	var sProjectInfos []*entity.SProjectInfo
+	err := Db.Debug().Model(&entity.SProjectInfo{}).Where("project_id = ?", projectId).Select("s_project_id, project_id, supplier_id, service_charge_settle, supplier_type").Find(&sProjectInfos).Error
+	return sProjectInfos, err
+}
+
+// 更新任务
+func (d SProjectDao) UpdateSProject(sProject entity.SProjectInfo) error {
+	err := Db.Model(&entity.SProjectInfo{}).Where("s_project_id = ?", sProject.SProjectID).Updates(sProject).Error
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
 //// 检查给定的服务商是否在该商家库中
 //func (d SupplierDao) EnterpriseDatabaseCheck(enterpriseId string, supplierId int64) (bool, error) {
 //	var count int64

+ 9 - 9
app/dao/sec_task_info_dao.go

@@ -4,31 +4,31 @@ import (
 	"youngee_b_api/app/entity"
 )
 
-type SecTaskInfoDao struct{}
+type SelectionTaskInfoDao struct{}
 
-func (s SecTaskInfoDao) CountBySelectionId(selectionId string) (int64, error) {
+func (s SelectionTaskInfoDao) CountBySelectionId(selectionId string) (int64, error) {
 	var count int64
-	err := Db.Model(&entity.SecTaskInfo{}).Where("selection_id = ?", selectionId).Count(&count).Error
+	err := Db.Model(&entity.SelectionTaskInfo{}).Where("selection_id = ?", selectionId).Count(&count).Error
 	return count, err
 }
 
 // 获取带货子任务中指定悬赏阶段的数据
-func (s SecTaskInfoDao) GetRewardDetailByRewardStage(selectionId string, rewardStage int64, order int64, page int, pageSize int) ([]*entity.SecTaskInfo, int64, error) {
-	secTaskInfos := []*entity.SecTaskInfo{}
+func (s SelectionTaskInfoDao) GetRewardDetailByRewardStage(selectionId string, rewardStage int64, order int64, page int, pageSize int) ([]*entity.SelectionTaskInfo, int64, error) {
+	selectionTaskInfos := []*entity.SelectionTaskInfo{}
 	var total int64
-	query := Db.Debug().Model(&entity.SecTaskInfo{}).Where("selection_id = ? AND reward_stage = ?", selectionId, rewardStage)
+	query := Db.Debug().Model(&entity.SelectionTaskInfo{}).Where("selection_id = ? AND reward_stage = ?", selectionId, rewardStage)
 	query.Count(&total)
 	query = query.Select("talent_id, sale_actual, withdraw_date")
 	offset := (page - 1) * pageSize
 	var err error
 	if order == 1 {
-		err = query.Order("withdraw_date asc").Offset(offset).Limit(pageSize).Find(&secTaskInfos).Error
+		err = query.Order("withdraw_date asc").Offset(offset).Limit(pageSize).Find(&selectionTaskInfos).Error
 	} else {
-		err = query.Order("withdraw_date desc").Offset(offset).Limit(pageSize).Find(&secTaskInfos).Error
+		err = query.Order("withdraw_date desc").Offset(offset).Limit(pageSize).Find(&selectionTaskInfos).Error
 	}
 	if err != nil {
 		return nil, 0, err
 	}
 
-	return secTaskInfos, total, nil
+	return selectionTaskInfos, total, nil
 }

+ 6 - 6
app/dao/selection_info_dao.go

@@ -306,7 +306,7 @@ func (d SelectionInfoDAO) GetSelectionToDo(enterpriseId string, subAccountId int
 				selectionIDs = append(selectionIDs, info.SelectionID)
 			}
 			if len(selectionIDs) > 0 {
-				err1 := Db.Model(&entity.SecTaskInfo{}).Where("selection_id in ? and task_status = ?", selectionIDs, 1).Count(&needProcess).Error // task_status=1待选
+				err1 := Db.Model(&entity.SelectionTaskInfo{}).Where("selection_id in ? and task_status = ?", selectionIDs, 1).Count(&needProcess).Error // task_status=1待选
 				if err1 != nil {
 					needProcess = 0
 				}
@@ -332,7 +332,7 @@ func (d SelectionInfoDAO) GetSelectionToDo(enterpriseId string, subAccountId int
 				selectionIDs = append(selectionIDs, info.SelectionID)
 			}
 			if len(selectionIDs) > 0 {
-				err1 := Db.Model(&entity.SecTaskInfo{}).Where("selection_id in ? and task_status = ?", selectionIDs, 1).Count(&needProcess).Error // task_status=1待选
+				err1 := Db.Model(&entity.SelectionTaskInfo{}).Where("selection_id in ? and task_status = ?", selectionIDs, 1).Count(&needProcess).Error // task_status=1待选
 				if err1 != nil {
 					needProcess = 0
 				}
@@ -370,11 +370,11 @@ func (d SelectionInfoDAO) GetLogisticsToDo(enterpriseId string, subAccountId int
 				selectionIDs = append(selectionIDs, info.SelectionID)
 			}
 			if len(selectionIDs) > 0 {
-				err1 := Db.Model(&entity.SecTaskInfo{}).Where("selection_id in ? and logistics_status = ?", selectionIDs, 1).Count(&needDelivery).Error // logistics_status=1待发货
+				err1 := Db.Model(&entity.SelectionTaskInfo{}).Where("selection_id in ? and logistics_status = ?", selectionIDs, 1).Count(&needDelivery).Error // logistics_status=1待发货
 				if err1 != nil {
 					needDelivery = 0
 				}
-				err2 := Db.Model(&entity.SecTaskInfo{}).Where("selection_id in ? and logistics_status = ?", selectionIDs, 2).Count(&needReceive).Error // logistics_status=2待签收
+				err2 := Db.Model(&entity.SelectionTaskInfo{}).Where("selection_id in ? and logistics_status = ?", selectionIDs, 2).Count(&needReceive).Error // logistics_status=2待签收
 				if err2 != nil {
 					needReceive = 0
 				}
@@ -396,11 +396,11 @@ func (d SelectionInfoDAO) GetLogisticsToDo(enterpriseId string, subAccountId int
 				selectionIDs = append(selectionIDs, info.SelectionID)
 			}
 			if len(selectionIDs) > 0 {
-				err1 := Db.Model(&entity.SecTaskInfo{}).Where("selection_id in ? and logistics_status = ?", selectionIDs, 1).Count(&needDelivery).Error // logistics_status=1待发货
+				err1 := Db.Model(&entity.SelectionTaskInfo{}).Where("selection_id in ? and logistics_status = ?", selectionIDs, 1).Count(&needDelivery).Error // logistics_status=1待发货
 				if err1 != nil {
 					needDelivery = 0
 				}
-				err2 := Db.Model(&entity.SecTaskInfo{}).Where("selection_id in ? and logistics_status = ?", selectionIDs, 2).Count(&needReceive).Error // logistics_status=2待签收
+				err2 := Db.Model(&entity.SelectionTaskInfo{}).Where("selection_id in ? and logistics_status = ?", selectionIDs, 2).Count(&needReceive).Error // logistics_status=2待签收
 				if err2 != nil {
 					needReceive = 0
 				}

+ 13 - 0
app/dao/supplier_income_dao.go

@@ -0,0 +1,13 @@
+package dao
+
+import (
+	"youngee_b_api/app/entity"
+)
+
+type SupplierIncomeDao struct{}
+
+// 创建服务商收入记录
+func (d SupplierIncomeDao) CreateSupplierIncome(supplierIncome entity.SupplierIncome) (int64, error) {
+	err := Db.Create(&supplierIncome).Error
+	return supplierIncome.IncomeID, err
+}

+ 1 - 0
app/entity/local_life_info.go

@@ -53,6 +53,7 @@ type LocalLifeInfo struct {
 	ExploredNum         int64     `gorm:"column:explored_num;default:0;NOT NULL"`           // 已探店
 	InvoiceStatus       int64     `gorm:"column:invoice_status;default:0;NOT NULL"`         // 开票状态(1开票中 2已开票)
 	NeedPay             float64   `gorm:"column:need_pay"`                                  // 待支付金额
+	SettleFlag          int64     `gorm:"column:settle_flag"`
 }
 
 func (m *LocalLifeInfo) TableName() string {

+ 1 - 0
app/entity/project.go

@@ -54,6 +54,7 @@ type Project struct {
 	DeliveryNum       int64     `gorm:"column:delivery_num"`
 	AfterDeliveryNum  int64     `gorm:"column:after_delivery_num"`
 	NeedPay           float64   `gorm:"column:need_pay"` // 待支付金额
+	SettleFlag        int64     `gorm:"column:settle_flag"`
 }
 
 func (m *Project) TableName() string {

+ 4 - 2
app/entity/s_local.go → app/entity/s_local_life.go

@@ -22,8 +22,9 @@ type SLocalLifeInfo struct {
 	RecruitNum          int64     `gorm:"column:recruit_num"`                           // 已招募人数
 	SettleNum           int64     `gorm:"column:settle_num;default:0"`                  // 已结算人数
 	SubAccountID        int64     `gorm:"column:sub_account_id"`                        // 服务商子账号ID
-	ServiceCharge       string    `gorm:"column:service_charge"`                        // 服务商预估可赚服务费
-	ServiceChargeActual string    `gorm:"column:service_charge_actual"`                 // 服务商实际可赚服务费
+	ServiceCharge       float64   `gorm:"column:service_charge"`                        // 服务商预估可赚服务费
+	ServiceChargeActual float64   `gorm:"column:service_charge_actual"`                 // 服务商实际可赚服务费
+	ServiceChargeSettle float64   `gorm:"column:service_charge_settle"`                 // 服务商已结算服务费
 	OperatorType        int64     `gorm:"column:operator_type;default:0"`               // 添加商单操作人类型,1为服务商主账号,2为服务商子账号
 	SLocalStatus        int64     `gorm:"column:s_local_status;default:0"`              // 服务商本地生活任务状态,1待确认,2已确认,3已拒绝
 	StrategyStatus      int64     `gorm:"column:strategy_status;default:2"`             // 定向本地生活任务是否替换招募策略,1是,2否
@@ -34,6 +35,7 @@ type SLocalLifeInfo struct {
 	CreateStrategyType  int64     `gorm:"column:create_strategy_type"`                  // 服务商替换招募策略操作人类型:1服务商主账号,2子账号
 	ShareCode           string    `gorm:"column:share_code"`                            // 分享码url
 	FinishTime          time.Time `gorm:"column:finish_time"`                           // 结案时间
+	SupplierType        int64     `gorm:"column:supplier_type"`                         // 服务商类型,1个人,2企业
 }
 
 func (m *SLocalLifeInfo) TableName() string {

+ 4 - 3
app/entity/s_project.go

@@ -24,9 +24,9 @@ type SProjectInfo struct {
 	SettleNum           int64     `gorm:"column:settle_num;default:0"`               // 已结算人数
 	QuitNum             int64     `gorm:"column:quit_num;default:0"`                 // 已解约人数
 	SubAccountID        int64     `gorm:"column:sub_account_id;default:0"`           // 服务商子账号ID
-	ServiceCharge       string    `gorm:"column:service_charge;default:0.00"`        // 服务商预估可赚服务费
-	ServiceChargeActual string    `gorm:"column:service_charge_actual;default:0.00"` // 服务商实际可赚服务费
-	ServiceChargeSettle string    `gorm:"column:service_charge_settle"`              // 服务商已结算服务费
+	ServiceCharge       float64   `gorm:"column:service_charge;default:0.00"`        // 服务商预估可赚服务费
+	ServiceChargeActual float64   `gorm:"column:service_charge_actual;default:0.00"` // 服务商实际可赚服务费
+	ServiceChargeSettle float64   `gorm:"column:service_charge_settle"`              // 服务商已结算服务费
 	OperatorType        int64     `gorm:"column:operator_type;default:0"`            // 添加商单操作人类型,1为服务商主账号,2为服务商子账号
 	SProjectStatus      int64     `gorm:"column:s_project_status;default:0"`         // 服务商种草任务状态,1待确认,2已确认,3已拒绝
 	StrategyStatus      int64     `gorm:"column:strategy_status;default:0"`          // 定向种草任务是否替换招募策略
@@ -36,6 +36,7 @@ type SProjectInfo struct {
 	CreateStrategyID    int64     `gorm:"column:create_strategy_id"`                 // 服务商修改服务费操作人ID
 	CreateStrategyType  int64     `gorm:"column:create_strategy_type"`               // 服务商修改服务费操作人类型:1服务商主账号,2子账号
 	FinishTime          time.Time `gorm:"column:finish_time"`                        // 结案时间
+	SupplierType        int64     `gorm:"column:supplier_type"`                      // 服务商类型,1个人,2企业
 }
 
 func (m *SProjectInfo) TableName() string {

+ 0 - 46
app/entity/sec_task_info.go

@@ -1,46 +0,0 @@
-package entity
-
-// Code generated by sql2gorm. DO NOT EDIT.
-
-import (
-	"time"
-)
-
-type SecTaskInfo struct {
-	ID                     int64     `gorm:"column:id;primary_key"`              // 递增id
-	TaskID                 string    `gorm:"column:task_id"`                     // 选品任务id
-	SelectionID            string    `gorm:"column:selection_id"`                // 选品id
-	TalentID               string    `gorm:"column:talent_id"`                   // 达人id
-	AccountID              int64     `gorm:"column:account_id"`                  // 账号id
-	TalentPlatformInfoSnap string    `gorm:"column:talent_platform_info_snap"`   // 达人平台信息快照
-	TalentPersonalInfoSnap string    `gorm:"column:talent_personal_info_snap"`   // 达人个人信息快照
-	TalentPostAddrSnap     string    `gorm:"column:talent_post_addr_snap"`       // 收货地址快照
-	TaskReward             string    `gorm:"column:task_reward"`                 //  达人赏金
-	TalentPayment          string    `gorm:"column:talent_payment"`              // 达人垫付金额
-	IsPayPayment           int64     `gorm:"column:is_pay_payment"`              // 企业是否返样品钱
-	IsPayReward            int64     `gorm:"column:is_pay_reward"`               // 企业是否结算悬赏
-	TaskMode               int64     `gorm:"column:task_mode"`                   // 任务形式,1、2分别表示纯佣带货、悬赏任务
-	SampleMode             int64     `gorm:"column:sample_mode"`                 // 领样形式,1-3分别表示免费领样、垫付买样、不提供样品
-	TaskStatus             int64     `gorm:"column:task_status;default:1"`       // 任务状态 1待选 2已选 3落选
-	TaskStage              int64     `gorm:"column:task_stage"`                  // 任务阶段,详情见info_sec_task_stage表
-	CreateDate             time.Time `gorm:"column:create_date"`                 // 创建时间
-	SelectDate             time.Time `gorm:"column:select_date"`                 // 反选时间
-	DeliveryDate           time.Time `gorm:"column:delivery_date"`               // 发货时间
-	CompleteDate           time.Time `gorm:"column:complete_date"`               // 结束时间
-	WithdrawDate           time.Time `gorm:"column:withdraw_date"`               // 提现时间
-	CompleteStatus         int64     `gorm:"column:complete_status;default:1"`   // 结束方式 1未结束 2正常结束 3反选失败
-	LogisticsStatus        int64     `gorm:"column:logistics_status;default:1"`  // 发货状态 1 待发货 2已发货 3 已签收
-	AssignmentStatus       uint64    `gorm:"column:assignment_status;default:1"` // 作业上传状态 1-5分别代表待添加、已添加、待修改、已修改、已通过
-	UpdateAt               time.Time `gorm:"column:update_at"`                   // 更新时间
-	WithdrawStatus         int64     `gorm:"column:withdraw_status;default:1"`   // 提现状态,1-4分别代表不可提现、可提现、提现中、已提现
-	LeadTeamID             string    `gorm:"column:lead_team_id"`                // 作为团长的young之团id,对应younggee_talent_team中的team_id字段
-	TeamID                 string    `gorm:"column:team_id"`                     // 作为团员的young之团id,对应younggee_talent_team中的team_id字段
-	TeamIncome             int64     `gorm:"column:team_income"`                 // young之团团长现金收益
-	TeamPoint64            int64     `gorm:"column:team_point64"`                // young之团团长积分收益
-	SaleActual             int64     `gorm:"column:sale_actual"`                 // 实际带货量
-
-}
-
-func (m *SecTaskInfo) TableName() string {
-	return "younggee_sec_task_info"
-}

+ 1 - 0
app/entity/selection_info.go

@@ -46,6 +46,7 @@ type SelectionInfo struct {
 	EnrollNum        int64     `gorm:"column:enroll_num"`                    // 报名数量
 	ChooseNum        int64     `gorm:"column:choose_num"`                    // 已选数量
 	InvoiceStatus    int64     `gorm:"column:invoice_status"`                // 开票状态(1开票中 2已开票)
+	SettleFlag       int64     `gorm:"column:settle_flag"`
 }
 
 func (m *SelectionInfo) TableName() string {

+ 1 - 0
app/entity/selection_task_info.go

@@ -37,6 +37,7 @@ type SelectionTaskInfo struct {
 	TeamID                 string    `gorm:"column:team_id"`                     // 作为团员的young之团id,对应younggee_talent_team中的team_id字段
 	TeamIncome             int       `gorm:"column:team_income"`                 // young之团团长现金收益
 	TeamPoint              int       `gorm:"column:team_point"`                  // young之团团长积分收益
+	SaleActual             int64     `gorm:"column:sale_actual"`                 // 实际带货量
 }
 
 func (m *SelectionTaskInfo) TableName() string {

+ 18 - 0
app/entity/supplier_income.go

@@ -0,0 +1,18 @@
+package entity
+
+// Code generated by sql2gorm. DO NOT EDIT.
+
+type SupplierIncome struct {
+	IncomeID            int64   `gorm:"column:income_id;primary_key;AUTO_INCREMENT"` // 服务商收入表ID
+	SupplierID          int64   `gorm:"column:supplier_id"`                          // 服务商ID
+	SupplierType        int64   `gorm:"column:supplier_type"`                        // 服务商用户类型,1为个人PR,2为机构
+	SProjectID          int64   `gorm:"column:s_project_id"`                         // 服务商加入商单后的种草任务ID
+	SLocalLifeID        int64   `gorm:"column:s_local_life_id"`                      // 服务商加入商单后的本地生活ID
+	IncomeType          int64   `gorm:"column:income_type"`                          // 服务商收入类型,1种草,2带货,3本地生活
+	IncomeStatus        int64   `gorm:"column:income_status;default:1"`              // 收入状态:1可回发票,2待传发票,3平台确认中,4平台已确认,5可提现,6提现中,7平台确认中,8已提现(个人服务商>=5;企业服务商>=1)
+	ServiceChargeSettle float64 `gorm:"column:service_charge_settle"`                // 服务费已结算
+}
+
+func (m *SupplierIncome) TableName() string {
+	return "younggee_supplier_income"
+}

+ 1 - 1
app/schedule/auto_task_invalid.go

@@ -18,7 +18,7 @@ func AutoTaskInvalid() error {
 
 	// 添加定时任务
 	// 定时任务1  品牌种草失效自动处理
-	_, err1 := crontab.AddFunc(spec, AutoSelectionInvalidTask)
+	_, err1 := crontab.AddFunc(spec, AutoProjectInvalidTask)
 	if err1 != nil {
 		return err1
 	}

+ 1 - 1
app/schedule/auto_task_review.go

@@ -13,7 +13,7 @@ import (
 func AutoTaskReview() error {
 	// 新建一个定时任务对象
 	crontab := cron.New(cron.WithSeconds()) // 精确到秒
-	spec := "0 */1 * * * ?"                 //cron表达式,每5分钟一次
+	spec := "0 */1 * * * ?"                 //cron表达式,每1分钟一次
 	// "0 0 12 * * ?" 每天中午12点执行
 
 	// 添加定时任务

+ 188 - 0
app/schedule/auto_task_settle.go

@@ -0,0 +1,188 @@
+package schedule
+
+import (
+	"github.com/robfig/cron/v3"
+	"log"
+	"time"
+	"youngee_b_api/app/dao"
+	"youngee_b_api/app/entity"
+)
+
+func AutoTaskSettle() error {
+	// 新建一个定时任务对象
+	crontab := cron.New(cron.WithSeconds()) // 精确到秒
+	spec := "0 */1 * * * ?"                 //cron表达式,每5分钟一次
+
+	// 添加定时任务
+	// 定时任务1  电商带货结案与解冻处理
+	_, err2 := crontab.AddFunc(spec, AutoSelectionSettleTask)
+	if err2 != nil {
+		return err2
+	}
+	// 定时任务2  品牌种草结案与解冻处理
+	_, err1 := crontab.AddFunc(spec, AutoProjectSettleTask)
+	if err1 != nil {
+		return err1
+	}
+	// 定时任务3  本地生活结案与解冻处理
+	_, err3 := crontab.AddFunc(spec, AutoLocalLifeSettleTask)
+	if err3 != nil {
+		return err3
+	}
+
+	// 启动定时器
+	crontab.Start()
+	// 定时任务是另起协程执行的,这里使用 select 简单阻塞.需要根据实际情况进行控制
+	//select {} //阻塞主线程停止
+	return nil
+}
+
+// 定时任务1  电商带货结案与解冻处理
+func AutoSelectionSettleTask() {
+	log.Println("AutoSelectionSettleTask running Start, Time :", time.Now())
+	var selectionInfos []*entity.SelectionInfo
+	err1 := dao.Db.Model(&entity.SelectionInfo{}).Where("selection_status = ? and settle_flag = ? ", 8, 0).Select("selection_id, enterprise_id, estimated_cost, settlement_amount").Find(&selectionInfos).Error
+	if err1 != nil {
+		return
+	}
+	for _, selectionInfo := range selectionInfos {
+		selectionID := selectionInfo.SelectionID
+		// 解冻资金
+		_, err3 := dao.EnterpriseDao{}.UpdateEnterpriseBalanceAndFrozen2(selectionInfo.EnterpriseID, selectionInfo.EstimatedCost, selectionInfo.SettlementAmount)
+		if err3 != nil {
+			continue
+		}
+		// 更新任务状态
+		err4 := dao.SelectionInfoDAO{}.UpdateSelectionInfo(entity.SelectionInfo{SelectionID: selectionID, SettleFlag: 1})
+		if err4 != nil {
+			return
+		}
+	}
+	log.Println("AutoSelectionSettleTask running End, Time :", time.Now())
+}
+
+// 定时任务2  品牌种草结案与解冻处理
+func AutoProjectSettleTask() {
+	log.Println("AutoProjectSettleTask running Start, Time :", time.Now())
+	var projectInfos []*entity.Project
+	err1 := dao.Db.Model(&entity.Project{}).Where("project_status = ? and settle_flag = ? ", 8, 1).Select("project_id, enterprise_id, need_pay").Find(&projectInfos).Error
+	if err1 != nil {
+		return
+	}
+	// 对于所有子任务结案但未解冻的品牌种草项目进行处理
+	for _, projectInfo := range projectInfos {
+		projectId := projectInfo.ProjectId
+		// 1. 处理商家账户金额
+		var realPayments float64
+		var projectTaskInfos []*entity.ProjectTaskInfo
+		err2 := dao.Db.Model(&entity.ProjectTaskInfo{}).Where("project_id = ? and task_stage = ? ", projectId, 15).Select("real_payment").Find(&projectTaskInfos).Error
+		if err2 != nil {
+			continue
+		}
+		for _, projectTaskInfo := range projectTaskInfos {
+			realPayments += projectTaskInfo.RealPayment
+		}
+		// 解冻资金
+		_, err3 := dao.EnterpriseDao{}.UpdateEnterpriseBalanceAndFrozen2(projectInfo.EnterpriseID, projectInfo.NeedPay, realPayments)
+		if err3 != nil {
+			return
+		}
+		// 更新任务状态为结案
+		err4 := dao.ProjectDAO{}.UpdateProject(entity.Project{ProjectId: projectId, ProjectStatus: 10})
+		if err4 != nil {
+			return
+		}
+		// 2、处理涉及到的服务商账户金额
+		sProjectInfos, err5 := dao.SProjectDao{}.GetSProjectByProjectId(projectId)
+		if err5 != nil {
+			return
+		}
+		for _, sProjectInfo := range sProjectInfos {
+			var incomeStatus int64
+			if sProjectInfo.SupplierType == 1 {
+				incomeStatus = 5
+			} else {
+				incomeStatus = 1
+			}
+			_, err6 := dao.SupplierIncomeDao{}.CreateSupplierIncome(entity.SupplierIncome{
+				SupplierID:          sProjectInfo.SupplierID,
+				SupplierType:        sProjectInfo.SupplierType,
+				SProjectID:          sProjectInfo.SProjectID,
+				IncomeType:          1,
+				IncomeStatus:        incomeStatus,
+				ServiceChargeSettle: sProjectInfo.ServiceChargeSettle,
+			})
+			if err6 != nil {
+				return
+			}
+			err7 := dao.SProjectDao{}.UpdateSProject(entity.SProjectInfo{SProjectID: sProjectInfo.SProjectID, ProjectStatus: 10})
+			if err7 != nil {
+				return
+			}
+		}
+	}
+	log.Println("AutoProjectSettleTask running End, Time :", time.Now())
+}
+
+// 定时任务3  本地生活结案与解冻处理
+func AutoLocalLifeSettleTask() {
+	log.Println("AutoLocalLifeSettleTask running Start, Time :", time.Now())
+	var localLifeInfos []*entity.LocalLifeInfo
+	err1 := dao.Db.Model(&entity.LocalLifeInfo{}).Where("task_status = ? and settle_flag = ? ", 8, 1).Select("local_id, enterprise_id, need_pay").Find(&localLifeInfos).Error
+	if err1 != nil {
+		return
+	}
+	// 对于所有子任务结案但未解冻的品牌种草项目进行处理
+	for _, localLifeInfo := range localLifeInfos {
+		localId := localLifeInfo.LocalID
+		// 1. 处理商家账户金额
+		var realPayments float64
+		var localTaskInfos []*entity.LocalLifeTaskInfo
+		err2 := dao.Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id = ? and task_stage = ? ", localId, 15).Select("real_payment").Find(&localTaskInfos).Error
+		if err2 != nil {
+			continue
+		}
+		for _, localTaskInfo := range localTaskInfos {
+			realPayments += localTaskInfo.RealPayment
+		}
+		// 解冻资金
+		_, err3 := dao.EnterpriseDao{}.UpdateEnterpriseBalanceAndFrozen2(localLifeInfo.EnterpriseID, localLifeInfo.NeedPay, realPayments)
+		if err3 != nil {
+			continue
+		}
+		// 更新任务状态为结案
+		err4 := dao.LocalLifeDao{}.UpdateLocal(entity.LocalLifeInfo{LocalID: localId, TaskStatus: 10})
+		if err4 != nil {
+			return
+		}
+		// 2、处理涉及到的服务商账户金额
+		sLocalLifeInfos, err5 := dao.SLocalLifeDao{}.GetSLocalLifeByLocalId(localId)
+		if err5 != nil {
+			return
+		}
+		for _, sLocalLifeInfo := range sLocalLifeInfos {
+			var incomeStatus int64
+			if sLocalLifeInfo.SupplierType == 1 {
+				incomeStatus = 5
+			} else {
+				incomeStatus = 1
+			}
+			_, err6 := dao.SupplierIncomeDao{}.CreateSupplierIncome(entity.SupplierIncome{
+				SupplierID:          sLocalLifeInfo.SupplierID,
+				SupplierType:        sLocalLifeInfo.SupplierType,
+				SLocalLifeID:        sLocalLifeInfo.SLocalID,
+				IncomeType:          3,
+				IncomeStatus:        incomeStatus,
+				ServiceChargeSettle: sLocalLifeInfo.ServiceChargeSettle,
+			})
+			if err6 != nil {
+				return
+			}
+			err7 := dao.SLocalLifeDao{}.UpdateSLocalLife(entity.SLocalLifeInfo{SLocalID: sLocalLifeInfo.SLocalID, TaskStatus: 10})
+			if err7 != nil {
+				return
+			}
+		}
+	}
+	log.Println("AutoLocalLifeSettleTask running End, Time :", time.Now())
+}

+ 1 - 1
app/service/enterprise_service.go

@@ -82,7 +82,7 @@ func calcTakegoodsInfo(dates []time.Time, enterpriseId string) vo.ReWorkspaceTak
 				currentCommission += enterprise.EstimatedCost * enterprise.CommissionRate
 				currentOrder += enterprise.SampleNum - enterprise.RemainNum
 				// 出单数量
-				currentPerson, _ = (&dao.SecTaskInfoDao{}).CountBySelectionId(enterprise.SelectionID)
+				currentPerson, _ = (&dao.SelectionTaskInfoDao{}).CountBySelectionId(enterprise.SelectionID)
 				currentCommissionRate = enterprise.SettlementAmount / float64(currentPerson)
 			}
 			// 带货数据

+ 1 - 1
app/service/selection_info_service.go

@@ -900,7 +900,7 @@ func (s SelectionInfoService) CloseSelection(selectionId string) (string, error)
 	var needProcess int64
 	if selectionInfo.SelectionStatus == 6 {
 		// 达人未处理 or 物流待办
-		_ = dao.Db.Model(&entity.SecTaskInfo{}).Where("selection_id = ? and (task_status = ? or logistics_status != ?)", selectionId, 1, 3).Count(&needProcess).Error // task_status=1待选
+		_ = dao.Db.Model(&entity.SelectionTaskInfo{}).Where("selection_id = ? and (task_status = ? or logistics_status != ?)", selectionId, 1, 3).Count(&needProcess).Error // task_status=1待选
 	}
 	if selectionInfo.SelectionStatus == 2 || selectionInfo.SelectionStatus == 4 || needProcess > 0 {
 		// 存在待办不可结束

+ 5 - 5
app/service/task_info_service.go

@@ -131,20 +131,20 @@ func (t TaskInfoService) SelectionRewardCashDetail(param *vo.SelectionRewardCash
 	}
 	rewardPoolAmount := selectionInfo.EstimatedCost
 	rewardPoolCashed := selectionInfo.TaskReward
-	secTaskInfos, total, err1 := dao.SecTaskInfoDao{}.GetRewardDetailByRewardStage(param.SelectionId, 2, param.Order, param.Page, param.PageSize)
+	selectionTaskInfos, total, err1 := dao.SelectionTaskInfoDao{}.GetRewardDetailByRewardStage(param.SelectionId, 2, param.Order, param.Page, param.PageSize)
 	if err1 != nil {
 		return nil, err1
 	}
 	var talentRewardMsgs []vo.TalentRewardMsg
-	for _, secTaskInfo := range secTaskInfos {
-		talentInfo, _ := dao.TalentInfoDao{}.SelectTalentInfo(secTaskInfo.TalentID)
+	for _, selectionTaskInfo := range selectionTaskInfos {
+		talentInfo, _ := dao.TalentInfoDao{}.SelectTalentInfo(selectionTaskInfo.TalentID)
 		talentRewardMsg := vo.TalentRewardMsg{
 			PhotoUrl: talentInfo.Avatar,
 			Nickname: talentInfo.TalentNickname,
 			Account:  talentInfo.TalentWxOpenid,
 			Gender:   talentInfo.Sex,
-			OrderNum: secTaskInfo.SaleActual,
-			CashTime: secTaskInfo.WithdrawDate.Format("2006-01-02 15:04:05"),
+			OrderNum: selectionTaskInfo.SaleActual,
+			CashTime: selectionTaskInfo.WithdrawDate.Format("2006-01-02 15:04:05"),
 		}
 		talentRewardMsgs = append(talentRewardMsgs, talentRewardMsg)
 	}

+ 8 - 4
main.go

@@ -22,19 +22,23 @@ func main() {
 	addr := fmt.Sprintf("%v:%v", config.Host, config.Port)
 	err := service.AutoTask()
 	if err != nil {
-		log.Println("service AutoTask error:", err)
+		log.Println("service AutoTask error:", err.Error())
 	}
 	err1 := schedule.AutoTaskInvalid()
 	if err1 != nil {
-		log.Println("schedule AutoTaskInvalid error:", err1)
+		log.Println("schedule AutoTaskInvalid error:", err1.Error())
 	}
 	err2 := schedule.AutoTaskRecharge()
 	if err2 != nil {
-		log.Println("schedule AutoTaskRecharge error:", err2)
+		log.Println("schedule AutoTaskRecharge error:", err2.Error())
 	}
 	err3 := schedule.AutoTaskReview()
 	if err3 != nil {
-		log.Println("schedule AutoTaskReview error:", err3)
+		log.Println("schedule AutoTaskReview error:", err3.Error())
+	}
+	err4 := schedule.AutoTaskSettle()
+	if err4 != nil {
+		log.Println("schedule AutoTaskSettle error:", err4.Error())
 	}
 	r.Run(addr) // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
 }