project_dao.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. package dao
  2. import (
  3. "errors"
  4. "fmt"
  5. "gorm.io/gorm"
  6. "time"
  7. "youngee_b_api/app/entity"
  8. "youngee_b_api/app/vo"
  9. )
  10. type ProjectDAO struct{}
  11. // 根据projectId获取project信息
  12. func (d ProjectDAO) GetProjectById(projectId string) (*entity.Project, error) {
  13. var project entity.Project
  14. err := Db.Where("project_id = ?", projectId).First(&project).Error
  15. if err != nil {
  16. if errors.Is(err, gorm.ErrRecordNotFound) {
  17. return nil, nil
  18. } else {
  19. return nil, err
  20. }
  21. }
  22. return &project, err
  23. }
  24. // 根据projectId获取违约状态id
  25. func (d ProjectDAO) GetAutoDefaultId(projectId string) (*int64, error) {
  26. var autoDefaultId int64
  27. err := Db.Model(&entity.Project{}).Where("project_id = ?", projectId).Select("auto_default_id").Find(&autoDefaultId).Error
  28. if err != nil {
  29. return nil, nil
  30. }
  31. return &autoDefaultId, nil
  32. }
  33. // 根据enterpriseId查询指定某天的所有带货数据
  34. func (d ProjectDAO) GetProjectListOfDay(enterpriseId string, date time.Time) ([]entity.Project, error) {
  35. var projects []entity.Project
  36. // 构建查询
  37. query := Db.Model(&entity.Project{})
  38. if enterpriseId != "" {
  39. query = query.Where("enterprise_id = ?", enterpriseId)
  40. }
  41. // 将日期部分提取出来进行匹配
  42. query = query.Where("DATE(created_at) = ?", date.Format("2006-01-02"))
  43. err := query.Find(&projects).Error
  44. return projects, err
  45. }
  46. // 创建种草任务
  47. func (d ProjectDAO) CreateProject(project entity.Project) error {
  48. err := Db.Omit("auto_fail_at", "auto_script_break_at", "auto_sketch_break_at", "pay_at", "pass_at", "finish_at", "submit_at").Create(&project).Error
  49. if err != nil {
  50. return err
  51. }
  52. return nil
  53. }
  54. // 更新种草任务
  55. func (d ProjectDAO) UpdateProject(project entity.Project) error {
  56. err := Db.Model(&entity.Project{}).Where("project_id = ?", project.ProjectId).Updates(project).Error
  57. if err != nil {
  58. return err
  59. }
  60. return nil
  61. }
  62. // 更新开票状态字段
  63. func (d ProjectDAO) UpdateInvoiceStatus(projectIDs []string) error {
  64. err := Db.Debug().Model(&entity.Project{}).Where("project_id IN ?", projectIDs).Updates(entity.Project{InvoiceStatus: 1}).Error
  65. if err != nil {
  66. return err
  67. }
  68. return nil
  69. }
  70. // 获取种草任务列表
  71. func (d ProjectDAO) GetProjectPreviews(param *vo.ProjectSearchParam) ([]vo.ReProjectTaskPreview, int64, error) {
  72. var reProjectTaskPreviews []vo.ReProjectTaskPreview
  73. var projects []entity.Project
  74. var total int64
  75. query := Db.Model(&entity.Project{})
  76. // 动态添加查询条件
  77. if param.SubAccountId == 0 {
  78. if param.EnterpriseId == "" {
  79. return reProjectTaskPreviews, 0, errors.New("enterpriseId is empty")
  80. }
  81. query = query.Where("enterprise_id = ?", param.EnterpriseId)
  82. } else {
  83. query = query.Where("sub_account_id = ?", param.SubAccountId)
  84. }
  85. if param.ProjectType != 0 {
  86. query = query.Where("project_type = ?", param.ProjectType)
  87. }
  88. if param.ProjectPlatform != 0 {
  89. query = query.Where("project_platform = ?", param.ProjectPlatform)
  90. }
  91. if param.ProjectStatus != 0 {
  92. query = query.Where("project_status = ?", param.ProjectStatus)
  93. } else {
  94. query = query.Where("project_status not in ?", []int{1, 3})
  95. }
  96. if param.ProjectForm != 0 {
  97. query = query.Where("project_form = ?", param.ProjectForm)
  98. }
  99. if param.ContentType != 0 {
  100. query = query.Where("content_type = ?", param.ContentType)
  101. }
  102. if param.Others != "" {
  103. query = query.Where("enterprise_id = ? or project_id = ? or project_name LIKE ?", param.Others, param.Others, "%"+param.Others+"%")
  104. }
  105. query.Count(&total)
  106. query = query.Select("enterprise_id, sub_account_id, project_id, project_platform, project_status, estimated_cost, need_pay, project_form, content_type, need_review, need_quality, need_calculate, before_delivery_num, delivery_num, after_delivery_num, product_id, tools")
  107. offset := (param.Page - 1) * param.PageSize
  108. if param.Order == 1 {
  109. if err := query.Order("created_at asc").Offset(offset).Limit(param.PageSize).Find(&projects).Error; err != nil {
  110. return nil, 0, err
  111. }
  112. } else {
  113. if err := query.Order("created_at desc").Offset(offset).Limit(param.PageSize).Find(&projects).Error; err != nil {
  114. return nil, 0, err
  115. }
  116. }
  117. for _, project := range projects {
  118. // 获取种草待筛选达人数
  119. projectId := project.ProjectId
  120. needFilter := ProjectTaskInfoDao{}.CountByTaskStage(projectId, 1)
  121. reProjectTaskPreview := vo.ReProjectTaskPreview{
  122. EnterpriseId: project.EnterpriseID,
  123. SubAccountId: project.SubAccountId,
  124. ProjectId: project.ProjectId,
  125. ProjectPlatform: project.ProjectPlatform,
  126. ProjectStatus: project.ProjectStatus,
  127. ProjectForm: project.ProjectForm,
  128. ContentType: project.ContentType,
  129. NeedReview: project.NeedReview,
  130. NeedQuality: project.NeedQuality,
  131. NeedCalculate: project.NeedCalculate,
  132. ProductId: project.ProductID,
  133. Tools: project.Tools,
  134. NeedDelivery: project.BeforeDeliveryNum,
  135. NeedReceive: project.DeliveryNum,
  136. Received: project.AfterDeliveryNum,
  137. NeedFilter: needFilter,
  138. }
  139. if project.ProjectStatus < 6 {
  140. reProjectTaskPreview.EstimatedCost = project.EstimatedCost
  141. } else {
  142. reProjectTaskPreview.EstimatedCost = project.NeedPay
  143. }
  144. reProjectTaskPreviews = append(reProjectTaskPreviews, reProjectTaskPreview)
  145. }
  146. return reProjectTaskPreviews, total, nil
  147. }
  148. // 删除种草任务
  149. func (d ProjectDAO) DeleteProject(projectId string) (*string, error) {
  150. if projectId == "" {
  151. return &projectId, nil
  152. }
  153. err := Db.Model(&entity.Project{}).Where("project_id = ?", projectId).Delete(&entity.Project{}).Error
  154. if err != nil {
  155. return nil, err
  156. }
  157. return &projectId, nil
  158. }
  159. // 获取草稿箱——种草任务列表
  160. func (d ProjectDAO) GetProjectDraftList(param *vo.ProjectDraftParam) ([]vo.ReProjectTaskPreview, int64, error) {
  161. var reProjectTaskPreviews []vo.ReProjectTaskPreview
  162. var projects []entity.Project
  163. var total int64
  164. query := Db.Model(&entity.Project{}).Where("project_status = ?", 1)
  165. // 动态添加查询条件
  166. if param.SubAccountId == 0 {
  167. if param.EnterpriseId == "" {
  168. return reProjectTaskPreviews, 0, errors.New("enterpriseId is empty")
  169. }
  170. query = query.Where("enterprise_id = ?", param.EnterpriseId)
  171. } else {
  172. query = query.Where("sub_account_id = ?", param.SubAccountId)
  173. }
  174. if param.ProjectType != 0 {
  175. query = query.Where("project_type = ?", param.ProjectType)
  176. }
  177. if param.ProjectPlatform != 0 {
  178. query = query.Where("project_platform = ?", param.ProjectPlatform)
  179. }
  180. if param.Others != "" {
  181. query = query.Where("enterprise_id = ? or project_id = ? or project_name LIKE ?", param.Others, param.Others, "%"+param.Others+"%")
  182. }
  183. query.Count(&total)
  184. query = query.Select("enterprise_id, sub_account_id, project_id, project_platform, project_type, created_at, product_id")
  185. offset := (param.Page - 1) * param.PageSize
  186. if err := query.Order("created_at asc").Offset(offset).Limit(param.PageSize).Find(&projects).Error; err != nil {
  187. return nil, 0, err
  188. }
  189. for _, project := range projects {
  190. reProjectTaskPreview := vo.ReProjectTaskPreview{
  191. EnterpriseId: project.EnterpriseID,
  192. SubAccountId: project.SubAccountId,
  193. ProjectId: project.ProjectId,
  194. ProjectPlatform: project.ProjectPlatform,
  195. ProjectType: project.ProjectType,
  196. CreatedAt: project.CreatedAt.Format("2006-01-02 15:04:05"),
  197. ProductId: project.ProductID,
  198. }
  199. reProjectTaskPreviews = append(reProjectTaskPreviews, reProjectTaskPreview)
  200. }
  201. return reProjectTaskPreviews, total, nil
  202. }
  203. // 获取公开种草中全部指定状态值的项目
  204. func (d ProjectDAO) GetProjectList(value int64, fieldName string) ([]*entity.Project, error) {
  205. var projectInfos []*entity.Project
  206. err := Db.Model(entity.Project{}).Where(fmt.Sprintf("%s = ? ", fieldName), value).Find(&projectInfos).Error
  207. if err != nil {
  208. return nil, err
  209. }
  210. return projectInfos, nil
  211. }
  212. // 违约管理——违约公开种草任务列表
  213. func (d ProjectDAO) GetProjectPublicList(param *vo.DefaultSearchParam) ([]vo.ReTaskDefaultPublic, int64, error) {
  214. var reTaskDefaultPublics []vo.ReTaskDefaultPublic
  215. var projects []entity.Project
  216. var total int64
  217. query := Db.Model(&entity.Project{}).Where("project_type = ?", 1)
  218. // 动态添加查询条件
  219. if param.SubAccountId == 0 {
  220. if param.EnterpriseId == "" {
  221. return reTaskDefaultPublics, 0, errors.New("enterpriseId is empty")
  222. }
  223. query = query.Where("enterprise_id = ?", param.EnterpriseId)
  224. } else {
  225. query = query.Where("sub_account_id = ?", param.SubAccountId)
  226. }
  227. if param.Platform != 0 {
  228. query = query.Where("project_platform = ?", param.Platform)
  229. }
  230. if param.TaskId != "" {
  231. query = query.Where("project_id = ?", param.TaskId)
  232. }
  233. query.Count(&total)
  234. query = query.Select("enterprise_id, sub_account_id, project_id, project_platform, project_form, content_type, product_id")
  235. offset := (param.Page - 1) * param.PageSize
  236. if err := query.Order("created_at asc").Offset(offset).Limit(param.PageSize).Find(&projects).Error; err != nil {
  237. return nil, 0, err
  238. }
  239. for _, project := range projects {
  240. reTaskDefaultPublic := vo.ReTaskDefaultPublic{
  241. EnterpriseId: project.EnterpriseID,
  242. SubAccountId: project.SubAccountId,
  243. TaskId: project.ProjectId,
  244. Platform: project.ProjectPlatform,
  245. TaskForm: project.ProjectForm,
  246. ContentType: project.ContentType,
  247. TaskType: 1,
  248. ProductId: project.ProductID,
  249. }
  250. reTaskDefaultPublics = append(reTaskDefaultPublics, reTaskDefaultPublic)
  251. }
  252. return reTaskDefaultPublics, total, nil
  253. }
  254. // 违约管理——违约定向种草任务列表
  255. func (d ProjectDAO) GetProjectTargetList(param *vo.DefaultSearchParam) ([]vo.ReTaskDefaultTarget, int64, error) {
  256. var reTaskDefaultTargets []vo.ReTaskDefaultTarget
  257. var projects []entity.Project
  258. var total int64
  259. query := Db.Model(&entity.Project{}).Where("project_type = ?", 2)
  260. // 动态添加查询条件
  261. if param.SubAccountId == 0 {
  262. if param.EnterpriseId == "" {
  263. return reTaskDefaultTargets, 0, errors.New("enterpriseId is empty")
  264. }
  265. query = query.Where("enterprise_id = ?", param.EnterpriseId)
  266. } else {
  267. query = query.Where("sub_account_id = ?", param.SubAccountId)
  268. }
  269. if param.Platform != 0 {
  270. query = query.Where("project_platform = ?", param.Platform)
  271. }
  272. if param.TaskId != "" {
  273. query = query.Where("project_id = ?", param.TaskId)
  274. }
  275. query.Count(&total)
  276. query = query.Select("enterprise_id, sub_account_id, project_id, project_platform, tools, content_type, product_id")
  277. offset := (param.Page - 1) * param.PageSize
  278. if err := query.Order("created_at asc").Offset(offset).Limit(param.PageSize).Find(&projects).Error; err != nil {
  279. return nil, 0, err
  280. }
  281. for _, project := range projects {
  282. reTaskDefaultPublic := vo.ReTaskDefaultTarget{
  283. EnterpriseId: project.EnterpriseID,
  284. SubAccountId: project.SubAccountId,
  285. TaskId: project.ProjectId,
  286. Platform: project.ProjectPlatform,
  287. Tools: project.Tools,
  288. ContentType: project.ContentType,
  289. TaskType: 1,
  290. ProductId: project.ProductID,
  291. }
  292. reTaskDefaultTargets = append(reTaskDefaultTargets, reTaskDefaultPublic)
  293. }
  294. return reTaskDefaultTargets, total, nil
  295. }
  296. // 获取品牌种草冻结中的任务
  297. func (d ProjectDAO) GetProjectFrozenList(enterpriseId string) ([]*entity.Project, error) {
  298. var projects []*entity.Project
  299. query := Db.Debug().Model(entity.Project{})
  300. query.Select("project_id, product_id, enterprise_id, sub_account_id, project_platform, payment_amount, pay_at") // 冻结金额:payment_amount
  301. err := query.Where(fmt.Sprintf("enterprise_id = ? AND project_type = ? AND (project_status between 7 and 8) "), enterpriseId, 1).Find(&projects).Error
  302. if err != nil {
  303. if errors.Is(err, gorm.ErrRecordNotFound) {
  304. return projects, nil
  305. } else {
  306. return nil, err
  307. }
  308. }
  309. return projects, nil
  310. }
  311. // 获取品牌种草冻结解除的任务
  312. func (d ProjectDAO) GetProjectFrozenCancelList(enterpriseId string) ([]*entity.Project, error) {
  313. var projects []*entity.Project
  314. query := Db.Debug().Model(entity.Project{})
  315. query.Select("project_id, product_id, enterprise_id, sub_account_id, project_platform, settlement_amount, pay_at") // 解冻金额:settlement_amount
  316. err := query.Where(fmt.Sprintf("enterprise_id = ? AND project_type = ? AND (project_status between 9 and 10) "), enterpriseId, 1).Find(&projects).Error
  317. if err != nil {
  318. if errors.Is(err, gorm.ErrRecordNotFound) {
  319. return projects, nil
  320. } else {
  321. return nil, err
  322. }
  323. }
  324. return projects, nil
  325. }
  326. // 获取品牌种草账单列表
  327. func (d ProjectDAO) GetBillProjectPreviews(param *vo.ProjectSearchParam) ([]vo.ReBillProjectTaskPreview, int64, error) {
  328. var reBillProjectTaskPreviews []vo.ReBillProjectTaskPreview
  329. var projects []entity.Project
  330. var total int64
  331. query := Db.Model(&entity.Project{})
  332. // 动态添加查询条件
  333. if param.SubAccountId == 0 {
  334. if param.EnterpriseId == "" {
  335. return reBillProjectTaskPreviews, 0, errors.New("enterpriseId is empty")
  336. }
  337. query = query.Where("enterprise_id = ?", param.EnterpriseId)
  338. } else {
  339. query = query.Where("sub_account_id = ?", param.SubAccountId)
  340. }
  341. if param.ProjectType != 0 {
  342. query = query.Where("project_type = ?", param.ProjectType)
  343. }
  344. if param.ProjectPlatform != 0 {
  345. query = query.Where("project_platform = ?", param.ProjectPlatform)
  346. }
  347. if param.ProjectStatus != 0 {
  348. query = query.Where("project_status = ?", param.ProjectStatus)
  349. }
  350. if param.Others != "" {
  351. query = query.Where("enterprise_id = ? or project_id = ? or project_name LIKE ?", param.Others, param.Others, "%"+param.Others+"%")
  352. }
  353. query.Count(&total)
  354. query = query.Select("enterprise_id, sub_account_id, project_id, project_platform, project_status, estimated_cost, need_pay, project_form, content_type, product_id, settlement_amount")
  355. offset := (param.Page - 1) * param.PageSize
  356. if err := query.Order("created_at asc").Offset(offset).Limit(param.PageSize).Find(&projects).Error; err != nil {
  357. return nil, 0, err
  358. }
  359. for _, project := range projects {
  360. reBillProjectTaskPreview := vo.ReBillProjectTaskPreview{
  361. EnterpriseId: project.EnterpriseID,
  362. SubAccountId: project.SubAccountId,
  363. ProjectId: project.ProjectId,
  364. ProjectPlatform: project.ProjectPlatform,
  365. ProjectStatus: project.ProjectStatus,
  366. ProjectForm: project.ProjectForm,
  367. ContentType: project.ContentType,
  368. ProductId: project.ProductID,
  369. EstimatedCost: project.EstimatedCost, // 应付金额
  370. CashAmount: project.SettlementAmount, //实际结算金额
  371. }
  372. if project.ProjectStatus < 6 {
  373. reBillProjectTaskPreview.EstimatedCost = project.EstimatedCost
  374. } else {
  375. reBillProjectTaskPreview.EstimatedCost = project.NeedPay
  376. }
  377. reBillProjectTaskPreviews = append(reBillProjectTaskPreviews, reBillProjectTaskPreview)
  378. }
  379. return reBillProjectTaskPreviews, total, nil
  380. }
  381. // 种草任务待办
  382. func (d ProjectDAO) GetProjectToDo(enterpriseId string, subAccountId int64, platform int64, taskType int64) (map[string]int64, error) {
  383. resultMap := make(map[string]int64)
  384. var needReview int64 // 待审核
  385. var needPay int64
  386. var needProcess int64
  387. var needCheck int64 // 初稿待审
  388. var needQuality int64 // 链接待审
  389. var needCalculate int64 // 待结算
  390. var projectInfos []entity.Project
  391. //query := Db.Model(&entity.Project{}).Where("enterprise_id = ? and project_platform = ? and project_type = ?", enterpriseId, platform, taskType)
  392. if subAccountId == 0 {
  393. // 待审核、待支付、达人未处理、初稿待审、链接待审、待结算
  394. query1 := Db.Model(&entity.Project{}).Where("enterprise_id = ? and project_platform = ? and project_type = ?", enterpriseId, platform, taskType)
  395. query1.Where("project_status = ?", 2).Count(&needReview)
  396. query2 := Db.Model(&entity.Project{}).Where("enterprise_id = ? and project_platform = ? and project_type = ?", enterpriseId, platform, taskType)
  397. query2.Debug().Where("project_status = ?", 6).Count(&needPay)
  398. query3 := Db.Model(&entity.Project{}).Where("enterprise_id = ? and project_platform = ? and project_type = ?", enterpriseId, platform, taskType)
  399. err := query3.Where("project_status = ?", 8).Select("project_id").Find(&projectInfos).Error
  400. if err != nil {
  401. if errors.Is(err, gorm.ErrRecordNotFound) {
  402. needProcess = 0
  403. } else {
  404. return resultMap, err
  405. }
  406. } else if len(projectInfos) > 0 {
  407. var projectIDs []string
  408. for _, info := range projectInfos {
  409. projectIDs = append(projectIDs, info.ProjectId)
  410. }
  411. if len(projectIDs) > 0 {
  412. err1 := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id in ? and task_status = ?", projectIDs, 1).Count(&needProcess).Error // task_status=1待选
  413. if err1 != nil {
  414. needProcess = 0
  415. }
  416. }
  417. }
  418. query4 := Db.Model(&entity.Project{}).Where("enterprise_id = ? and project_platform = ? and project_type = ?", enterpriseId, platform, taskType)
  419. err1 := query4.Select("need_review, need_quality, need_calculate").Find(&projectInfos).Error
  420. if err1 != nil {
  421. return resultMap, err1
  422. } else if len(projectInfos) > 0 {
  423. for _, info := range projectInfos {
  424. needCheck += info.NeedReview
  425. needQuality += info.NeedQuality
  426. needCalculate += info.NeedCalculate
  427. }
  428. }
  429. } else {
  430. // 待审核、待支付、达人未处理、初稿待审、链接待审、待结算
  431. query1 := Db.Model(&entity.Project{}).Where("enterprise_id = ? and project_platform = ? and project_type = ?", enterpriseId, platform, taskType)
  432. query1.Where("sub_account_id = ? and project_status = ?", subAccountId, 2).Count(&needReview)
  433. query2 := Db.Model(&entity.Project{}).Where("enterprise_id = ? and project_platform = ? and project_type = ?", enterpriseId, platform, taskType)
  434. query2.Where("sub_account_id = ? and project_status = ?", subAccountId, 6).Count(&needPay)
  435. query3 := Db.Model(&entity.Project{}).Where("enterprise_id = ? and project_platform = ? and project_type = ?", enterpriseId, platform, taskType)
  436. err := query3.Where("sub_account_id = ? and project_status = ?", subAccountId, 8).Select("project_id").Find(&projectInfos).Error
  437. if err != nil {
  438. if errors.Is(err, gorm.ErrRecordNotFound) {
  439. needProcess = 0
  440. } else {
  441. return resultMap, err
  442. }
  443. } else {
  444. var projectIDs []string
  445. for _, info := range projectInfos {
  446. projectIDs = append(projectIDs, info.ProjectId)
  447. }
  448. if len(projectIDs) > 0 {
  449. err1 := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id in ? and task_status = ?", projectIDs, 1).Count(&needProcess).Error // task_status=1待选
  450. if err1 != nil {
  451. needProcess = 0
  452. }
  453. }
  454. }
  455. query4 := Db.Model(&entity.Project{}).Where("enterprise_id = ? and project_platform = ? and project_type = ?", enterpriseId, platform, taskType)
  456. err1 := query4.Select("need_review, need_quality, need_calculate").Find(&projectInfos).Error
  457. if err1 != nil {
  458. return resultMap, err1
  459. } else if len(projectInfos) > 0 {
  460. for _, info := range projectInfos {
  461. needCheck += info.NeedReview
  462. needQuality += info.NeedQuality
  463. needCalculate += info.NeedCalculate
  464. }
  465. }
  466. }
  467. resultMap["needReview"] = needReview
  468. resultMap["needPay"] = needPay
  469. resultMap["needProcess"] = needProcess
  470. resultMap["needCheck"] = needCheck
  471. resultMap["needQuality"] = needQuality
  472. resultMap["needCalculate"] = needCalculate
  473. return resultMap, nil
  474. }
  475. // 寄样物流任务待办
  476. func (d ProjectDAO) GetLogisticsToDo(enterpriseId string, subAccountId int64, platform int64) (map[string]int64, error) {
  477. resultMap := make(map[string]int64)
  478. var needDelivery int64
  479. var needReceive int64
  480. var projectInfos []entity.Project
  481. //query := Db.Model(&entity.Project{}).Where("enterprise_id = ? and project_platform = ? and project_type = ?", enterpriseId, platform, taskType)
  482. if subAccountId == 0 {
  483. // 待发货、待签收
  484. query1 := Db.Model(&entity.Project{}).Where("enterprise_id = ? and project_platform = ? and project_form = ?", enterpriseId, platform, 1)
  485. err := query1.Where("project_status = ?", 8).Select("project_id").Find(&projectInfos).Error
  486. if err != nil {
  487. if errors.Is(err, gorm.ErrRecordNotFound) {
  488. needDelivery = 0
  489. needReceive = 0
  490. } else {
  491. return resultMap, err
  492. }
  493. } else if len(projectInfos) > 0 {
  494. var projectIDs []string
  495. for _, info := range projectInfos {
  496. projectIDs = append(projectIDs, info.ProjectId)
  497. }
  498. if len(projectIDs) > 0 {
  499. err1 := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id in ? and task_stage = ?", projectIDs, 4).Count(&needDelivery).Error // task_stage=4待发货
  500. if err1 != nil {
  501. needDelivery = 0
  502. }
  503. err2 := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id in ? and task_stage = ?", projectIDs, 5).Count(&needReceive).Error // task_stage=5已发货
  504. if err2 != nil {
  505. needReceive = 0
  506. }
  507. }
  508. }
  509. } else {
  510. // 待发货、待签收
  511. query1 := Db.Model(&entity.Project{}).Where("enterprise_id = ? and project_platform = ? and project_form = ?", enterpriseId, platform, 1)
  512. err := query1.Where("sub_account_id = ? and project_status = ?", subAccountId, 8).Select("project_id").Find(&projectInfos).Error
  513. if err != nil {
  514. if errors.Is(err, gorm.ErrRecordNotFound) {
  515. needDelivery = 0
  516. needReceive = 0
  517. } else {
  518. return resultMap, err
  519. }
  520. } else {
  521. var projectIDs []string
  522. for _, info := range projectInfos {
  523. projectIDs = append(projectIDs, info.ProjectId)
  524. }
  525. if len(projectIDs) > 0 {
  526. err1 := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id in ? and task_stage = ?", projectIDs, 4).Count(&needDelivery).Error // task_stage=4待发货
  527. if err1 != nil {
  528. needDelivery = 0
  529. }
  530. err2 := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id in ? and task_stage = ?", projectIDs, 5).Count(&needReceive).Error // task_stage=5已发货
  531. if err2 != nil {
  532. needReceive = 0
  533. }
  534. }
  535. }
  536. }
  537. resultMap["needDelivery"] = needDelivery
  538. resultMap["needReceive"] = needReceive
  539. return resultMap, nil
  540. }
  541. // 违约管理任务待办
  542. func (d ProjectDAO) GetDefaultToDo(enterpriseId string, subAccountId int64, platform int64, taskType int64) (map[string]int64, error) {
  543. resultMap := make(map[string]int64)
  544. var noSketch int64 // 未传初稿
  545. var noWork int64 // 未发作品
  546. var noData int64 // 未传数据
  547. var cooperateOver int64 // 终止合作
  548. var projectInfos []entity.Project
  549. //query := Db.Model(&entity.Project{}).Where("enterprise_id = ? and project_platform = ? and project_type = ?", enterpriseId, platform, taskType)
  550. if subAccountId == 0 {
  551. // 未传初稿、未发作品、未传数据、终止合作
  552. query1 := Db.Model(&entity.Project{}).Where("enterprise_id = ? and project_platform = ? and project_type = ?", enterpriseId, platform, taskType)
  553. err := query1.Where("project_status >= ?", 8).Select("project_id").Find(&projectInfos).Error
  554. if err != nil {
  555. if errors.Is(err, gorm.ErrRecordNotFound) {
  556. noSketch = 0
  557. noWork = 0
  558. noData = 0
  559. cooperateOver = 0
  560. } else {
  561. return resultMap, err
  562. }
  563. } else if len(projectInfos) > 0 {
  564. var projectIDs []string
  565. for _, info := range projectInfos {
  566. projectIDs = append(projectIDs, info.ProjectId)
  567. }
  568. if len(projectIDs) > 0 {
  569. err1 := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id in ? and cur_default_type = ?", projectIDs, 4).Count(&noSketch).Error // cur_default_type=4 初稿未上传违约
  570. if err1 != nil {
  571. noSketch = 0
  572. }
  573. err2 := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id in ? and cur_default_type = ?", projectIDs, 6).Count(&noWork).Error // cur_default_type=6 链接未上传违约
  574. if err2 != nil {
  575. noWork = 0
  576. }
  577. err3 := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id in ? and cur_default_type = ?", projectIDs, 8).Count(&noData).Error // cur_default_type=8 数据未上传违约
  578. if err3 != nil {
  579. noData = 0
  580. }
  581. err4 := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id in ? and cur_default_type = ?", projectIDs, 10).Count(&cooperateOver).Error // cur_default_type=10 解约
  582. if err4 != nil {
  583. cooperateOver = 0
  584. }
  585. }
  586. }
  587. } else {
  588. // 未传初稿、未发作品、未传数据、终止合作
  589. query1 := Db.Model(&entity.Project{}).Where("enterprise_id = ? and project_platform = ? and project_type = ?", enterpriseId, platform, taskType)
  590. err := query1.Where("sub_account_id = ? and project_status >= ?", subAccountId, 8).Select("project_id").Find(&projectInfos).Error
  591. if err != nil {
  592. if errors.Is(err, gorm.ErrRecordNotFound) {
  593. noSketch = 0
  594. noWork = 0
  595. noData = 0
  596. cooperateOver = 0
  597. } else {
  598. return resultMap, err
  599. }
  600. } else if len(projectInfos) > 0 {
  601. var projectIDs []string
  602. for _, info := range projectInfos {
  603. projectIDs = append(projectIDs, info.ProjectId)
  604. }
  605. if len(projectIDs) > 0 {
  606. err1 := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id in ? and cur_default_type = ?", projectIDs, 4).Count(&noSketch).Error // cur_default_type=4 初稿未上传违约
  607. if err1 != nil {
  608. noSketch = 0
  609. }
  610. err2 := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id in ? and cur_default_type = ?", projectIDs, 6).Count(&noWork).Error // cur_default_type=6 链接未上传违约
  611. if err2 != nil {
  612. noWork = 0
  613. }
  614. err3 := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id in ? and cur_default_type = ?", projectIDs, 8).Count(&noData).Error // cur_default_type=8 数据未上传违约
  615. if err3 != nil {
  616. noData = 0
  617. }
  618. err4 := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id in ? and cur_default_type = ?", projectIDs, 10).Count(&cooperateOver).Error // cur_default_type=10 解约
  619. if err4 != nil {
  620. cooperateOver = 0
  621. }
  622. }
  623. }
  624. }
  625. resultMap["noSketch"] = noSketch
  626. resultMap["noWork"] = noWork
  627. resultMap["noData"] = noData
  628. resultMap["cooperateOver"] = cooperateOver
  629. return resultMap, nil
  630. }
  631. // 获取指定商家已结案的指定开票状态数据
  632. func (d ProjectDAO) GetProjectFinished(enterpriseId string, invoiceStatus int64) (float64, error) {
  633. var projectAmount float64
  634. err := Db.Model(&entity.Project{}).Where("enterprise_id = ? and project_status = ? and invoice_status = ?", enterpriseId, 10, invoiceStatus).Select("COALESCE(SUM(settlement_amount), 0)").Find(&projectAmount).Error
  635. if err != nil {
  636. return 0, err
  637. }
  638. return projectAmount, err
  639. }
  640. // 寄样物流任务待办
  641. func (d ProjectDAO) GetTaskInviteToDo(enterpriseId string, subAccountId int64, platform int64) (map[string]int64, error) {
  642. resultMap := make(map[string]int64)
  643. var availInvitationNum int64
  644. var invitingNum int64
  645. var cooperatingNum int64
  646. //var projectInfos []entity.Project
  647. ////query := Db.Model(&entity.Project{}).Where("enterprise_id = ? and project_platform = ? and project_type = ?", enterpriseId, platform, taskType)
  648. //if subAccountId == 0 {
  649. // // 待发货、待签收
  650. // query1 := Db.Model(&entity.Project{}).Where("enterprise_id = ? and project_platform = ? and project_form = ?", enterpriseId, platform, 1)
  651. // err := query1.Where("project_status = ?", 8).Select("project_id").Find(&projectInfos).Error
  652. // if err != nil {
  653. // if errors.Is(err, gorm.ErrRecordNotFound) {
  654. // needDelivery = 0
  655. // needReceive = 0
  656. // } else {
  657. // return resultMap, err
  658. // }
  659. // } else if len(projectInfos) > 0 {
  660. // var projectIDs []string
  661. // for _, info := range projectInfos {
  662. // projectIDs = append(projectIDs, info.ProjectId)
  663. // }
  664. // if len(projectIDs) > 0 {
  665. // err1 := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id in ? and task_stage = ?", projectIDs, 4).Count(&needDelivery).Error // task_stage=4待发货
  666. // if err1 != nil {
  667. // needDelivery = 0
  668. // }
  669. // err2 := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id in ? and task_stage = ?", projectIDs, 5).Count(&needReceive).Error // task_stage=5已发货
  670. // if err2 != nil {
  671. // needReceive = 0
  672. // }
  673. // }
  674. // }
  675. //} else {
  676. // // 待发货、待签收
  677. // query1 := Db.Model(&entity.Project{}).Where("enterprise_id = ? and project_platform = ? and project_form = ?", enterpriseId, platform, 1)
  678. // err := query1.Where("sub_account_id = ? and project_status = ?", subAccountId, 8).Select("project_id").Find(&projectInfos).Error
  679. // if err != nil {
  680. // if errors.Is(err, gorm.ErrRecordNotFound) {
  681. // needDelivery = 0
  682. // needReceive = 0
  683. // } else {
  684. // return resultMap, err
  685. // }
  686. // } else {
  687. // var projectIDs []string
  688. // for _, info := range projectInfos {
  689. // projectIDs = append(projectIDs, info.ProjectId)
  690. // }
  691. // if len(projectIDs) > 0 {
  692. // err1 := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id in ? and task_stage = ?", projectIDs, 4).Count(&needDelivery).Error // task_stage=4待发货
  693. // if err1 != nil {
  694. // needDelivery = 0
  695. // }
  696. // err2 := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id in ? and task_stage = ?", projectIDs, 5).Count(&needReceive).Error // task_stage=5已发货
  697. // if err2 != nil {
  698. // needReceive = 0
  699. // }
  700. // }
  701. // }
  702. //}
  703. resultMap["availInvitationNum"] = availInvitationNum
  704. resultMap["invitingNum"] = invitingNum
  705. resultMap["cooperatingNum"] = cooperatingNum
  706. return resultMap, nil
  707. }