|
@@ -5,6 +5,7 @@ import (
|
|
|
"gorm.io/gorm"
|
|
|
"time"
|
|
|
"youngee_b_api/app/entity"
|
|
|
+ "youngee_b_api/app/vo"
|
|
|
)
|
|
|
|
|
|
type LocalLifeDao struct{}
|
|
@@ -73,3 +74,80 @@ func (d LocalLifeDao) UpdateInvoiceStatus(localIDs []string) error {
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
+
|
|
|
+// 获取本地生活任务列表
|
|
|
+func (d LocalLifeDao) GetLocalPreviews(param *vo.LocalSearchParam) ([]vo.ReLocalTaskPreview, int64, error) {
|
|
|
+ var reLocalTaskPreviews []vo.ReLocalTaskPreview
|
|
|
+ var localLifes []entity.LocalLifeInfo
|
|
|
+ var total int64
|
|
|
+ query := Db.Model(&entity.LocalLifeInfo{})
|
|
|
+ // 动态添加查询条件
|
|
|
+ if param.SubAccountId == 0 {
|
|
|
+ if param.EnterpriseId == "" {
|
|
|
+ return reLocalTaskPreviews, 0, errors.New("enterpriseId is empty")
|
|
|
+ }
|
|
|
+ query = query.Where("enterprise_id = ?", param.EnterpriseId)
|
|
|
+ } else {
|
|
|
+ query = query.Where("sub_account_id = ?", param.SubAccountId)
|
|
|
+ }
|
|
|
+ if param.LocalType != 0 {
|
|
|
+ query = query.Where("local_type = ?", param.LocalType)
|
|
|
+ }
|
|
|
+ if param.LocalPlatform != 0 {
|
|
|
+ query = query.Where("local_platform = ?", param.LocalPlatform)
|
|
|
+ }
|
|
|
+ if param.LocalStatus != 0 {
|
|
|
+ query = query.Where("task_status = ?", param.LocalStatus)
|
|
|
+ }
|
|
|
+ if param.LocalForm != 0 {
|
|
|
+ query = query.Where("task_form = ?", param.LocalForm)
|
|
|
+ }
|
|
|
+ if param.ContentType != 0 {
|
|
|
+ query = query.Where("content_type = ?", param.ContentType)
|
|
|
+ }
|
|
|
+ if param.LocalId != "" {
|
|
|
+ query = query.Where("local_id = ?", param.LocalId)
|
|
|
+ }
|
|
|
+ if param.LocalName != "" {
|
|
|
+ query = query.Where("local_name LIKE ?", "%"+param.LocalName+"%")
|
|
|
+ }
|
|
|
+ query.Count(&total)
|
|
|
+ query = query.Select("enterprise_id, sub_account_id, local_id, local_platform, task_status, estimated_cost, task_form, content_type, need_review, need_quality, need_calculate, store_id, team_buying_id, tools")
|
|
|
+ offset := (param.Page - 1) * param.PageSize
|
|
|
+ if err := query.Order("created_at asc").Offset(offset).Limit(param.PageSize).Find(&localLifes).Error; err != nil {
|
|
|
+ return nil, 0, err
|
|
|
+ }
|
|
|
+ for _, localLife := range localLifes {
|
|
|
+ reLocalTaskPreview := vo.ReLocalTaskPreview{
|
|
|
+ EnterpriseId: localLife.EnterpriseID,
|
|
|
+ SubAccountId: localLife.SubAccountID,
|
|
|
+ LocalId: localLife.LocalID,
|
|
|
+ LocalPlatform: localLife.LocalPlatform,
|
|
|
+ LocalStatus: localLife.TaskStatus,
|
|
|
+ EstimatedCost: localLife.EstimatedCost,
|
|
|
+ LocalForm: localLife.TaskForm,
|
|
|
+ ContentType: localLife.ContentType,
|
|
|
+ NeedReview: localLife.NeedReview,
|
|
|
+ NeedQuality: localLife.NeedQuality,
|
|
|
+ NeedCalculate: localLife.NeedCalculate,
|
|
|
+ StoreId: localLife.StoreID,
|
|
|
+ TeamBuyingId: localLife.TeamBuyingId,
|
|
|
+ Tools: localLife.Tools,
|
|
|
+ }
|
|
|
+ reLocalTaskPreviews = append(reLocalTaskPreviews, reLocalTaskPreview)
|
|
|
+ }
|
|
|
+
|
|
|
+ return reLocalTaskPreviews, total, nil
|
|
|
+}
|
|
|
+
|
|
|
+// 删除本地生活任务
|
|
|
+func (d LocalLifeDao) DeleteLocalLife(localId string) (*string, error) {
|
|
|
+ if localId == "" {
|
|
|
+ return &localId, nil
|
|
|
+ }
|
|
|
+ err := Db.Where("local_id = ?", localId).Delete(&entity.LocalLifeInfo{}).Error
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ return &localId, nil
|
|
|
+}
|