local_life_dao.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  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 LocalLifeDao struct{}
  11. // 根据localId获取localLife信息
  12. func (d LocalLifeDao) GetLocalById(localId string) (*entity.LocalLifeInfo, error) {
  13. var localLife entity.LocalLifeInfo
  14. err := Db.Model(&entity.LocalLifeInfo{}).Where("local_id = ?", localId).First(&localLife).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 &localLife, err
  23. }
  24. // 根据localId获取违约状态id
  25. func (d LocalLifeDao) GetAutoDefaultId(localId string) (*int64, error) {
  26. var autoDefaultId int64
  27. err := Db.Model(&entity.LocalLifeInfo{}).Where("local_id = ?", localId).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 LocalLifeDao) GetLocalListOfDay(enterpriseId string, date time.Time) ([]entity.LocalLifeInfo, error) {
  35. var localLifes []entity.LocalLifeInfo
  36. // 构建查询
  37. query := Db.Model(&entity.LocalLifeInfo{})
  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(&localLifes).Error
  44. return localLifes, err
  45. }
  46. // 创建本地生活任务
  47. func (d LocalLifeDao) CreateLocalLife(localLife entity.LocalLifeInfo) error {
  48. err := Db.Omit("auto_fail_at", "pay_at", "submit_at", "pass_at", "finish_at", "fail_at").Create(&localLife).Error
  49. if err != nil {
  50. return err
  51. }
  52. return nil
  53. }
  54. // 更新本地生活任务
  55. func (d LocalLifeDao) UpdateLocal(localLife entity.LocalLifeInfo) error {
  56. err := Db.Model(&entity.LocalLifeInfo{}).Where("local_id = ?", localLife.LocalID).Updates(localLife).Error
  57. if err != nil {
  58. return err
  59. }
  60. return nil
  61. }
  62. // 更新开票状态字段
  63. func (d LocalLifeDao) UpdateInvoiceStatus(localIDs []string) error {
  64. err := Db.Debug().Model(&entity.LocalLifeInfo{}).Where("local_id IN ?", localIDs).Updates(entity.LocalLifeInfo{InvoiceStatus: 1}).Error
  65. if err != nil {
  66. return err
  67. }
  68. return nil
  69. }
  70. // 获取本地生活任务列表
  71. func (d LocalLifeDao) GetLocalPreviews(param *vo.LocalSearchParam) ([]vo.ReLocalTaskPreview, int64, error) {
  72. var reLocalTaskPreviews []vo.ReLocalTaskPreview
  73. var localLifes []entity.LocalLifeInfo
  74. var total int64
  75. query := Db.Model(&entity.LocalLifeInfo{})
  76. // 动态添加查询条件
  77. if param.SubAccountId == 0 {
  78. if param.EnterpriseId == "" {
  79. return reLocalTaskPreviews, 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.LocalType != 0 {
  86. query = query.Where("local_type = ?", param.LocalType)
  87. }
  88. if param.LocalPlatform != 0 {
  89. query = query.Where("local_platform = ?", param.LocalPlatform)
  90. }
  91. if param.LocalStatus != 0 {
  92. query = query.Where("task_status = ?", param.LocalStatus)
  93. } else {
  94. query = query.Where("task_status not in ?", []int{1, 3})
  95. }
  96. if param.LocalForm != 0 {
  97. query = query.Where("task_form = ?", param.LocalForm)
  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 local_id = ? or local_name LIKE ?", param.Others, param.Others, "%"+param.Others+"%")
  104. }
  105. query.Count(&total)
  106. query = query.Select("enterprise_id, sub_account_id, local_id, local_name, local_platform, task_status, estimated_cost, need_pay, task_form, content_type, need_review, need_quality, need_calculate, store_id, team_buying_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(&localLifes).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(&localLifes).Error; err != nil {
  114. return nil, 0, err
  115. }
  116. }
  117. for _, localLife := range localLifes {
  118. reLocalTaskPreview := vo.ReLocalTaskPreview{
  119. EnterpriseId: localLife.EnterpriseID,
  120. SubAccountId: localLife.SubAccountID,
  121. LocalId: localLife.LocalID,
  122. LocalName: localLife.LocalName,
  123. LocalPlatform: localLife.LocalPlatform,
  124. LocalStatus: localLife.TaskStatus,
  125. LocalForm: localLife.TaskForm,
  126. ContentType: localLife.ContentType,
  127. NeedReview: localLife.NeedReview,
  128. NeedQuality: localLife.NeedQuality,
  129. NeedCalculate: localLife.NeedCalculate,
  130. StoreId: localLife.StoreID,
  131. TeamBuyingId: localLife.TeamBuyingId,
  132. Tools: localLife.Tools,
  133. }
  134. if localLife.TaskStatus < 6 {
  135. reLocalTaskPreview.EstimatedCost = localLife.EstimatedCost
  136. } else {
  137. reLocalTaskPreview.EstimatedCost = localLife.NeedPay
  138. }
  139. reLocalTaskPreviews = append(reLocalTaskPreviews, reLocalTaskPreview)
  140. }
  141. return reLocalTaskPreviews, total, nil
  142. }
  143. // 删除本地生活任务
  144. func (d LocalLifeDao) DeleteLocalLife(localId string) (*string, error) {
  145. if localId == "" {
  146. return &localId, nil
  147. }
  148. err := Db.Model(&entity.LocalLifeInfo{}).Where("local_id = ?", localId).Delete(&entity.LocalLifeInfo{}).Error
  149. if err != nil {
  150. return nil, err
  151. }
  152. return &localId, nil
  153. }
  154. // 获取草稿箱——本地生活任务列表
  155. func (d LocalLifeDao) GetLocalDraftList(param *vo.LocalDraftParam) ([]vo.ReLocalTaskPreview, int64, error) {
  156. var reLocalTaskPreviews []vo.ReLocalTaskPreview
  157. var localLifeInfos []entity.LocalLifeInfo
  158. var total int64
  159. query := Db.Model(&entity.LocalLifeInfo{}).Where("task_status = ?", 1)
  160. // 动态添加查询条件
  161. if param.SubAccountId == 0 {
  162. if param.EnterpriseId == "" {
  163. return reLocalTaskPreviews, 0, errors.New("enterpriseId is empty")
  164. }
  165. query = query.Where("enterprise_id = ?", param.EnterpriseId)
  166. } else {
  167. query = query.Where("sub_account_id = ?", param.SubAccountId)
  168. }
  169. if param.LocalType != 0 {
  170. query = query.Where("local_type = ?", param.LocalType)
  171. }
  172. if param.LocalPlatform != 0 {
  173. query = query.Where("local_platform = ?", param.LocalPlatform)
  174. }
  175. if param.Others != "" {
  176. query = query.Where("enterprise_id = ? or local_id = ? or local_name LIKE ?", param.Others, param.Others, "%"+param.Others+"%")
  177. }
  178. query.Count(&total)
  179. query = query.Select("enterprise_id, sub_account_id, local_id, local_name, local_platform, local_type, created_at, store_id")
  180. offset := (param.Page - 1) * param.PageSize
  181. if err := query.Order("created_at asc").Offset(offset).Limit(param.PageSize).Find(&localLifeInfos).Error; err != nil {
  182. return nil, 0, err
  183. }
  184. for _, localLifeInfo := range localLifeInfos {
  185. reLocalTaskPreview := vo.ReLocalTaskPreview{
  186. EnterpriseId: localLifeInfo.EnterpriseID,
  187. SubAccountId: localLifeInfo.SubAccountID,
  188. LocalId: localLifeInfo.LocalID,
  189. LocalName: localLifeInfo.LocalName,
  190. LocalPlatform: localLifeInfo.LocalPlatform,
  191. LocalType: localLifeInfo.LocalType,
  192. CreatedAt: localLifeInfo.CreatedAt.Format("2006-01-02 15:04:05"),
  193. StoreId: localLifeInfo.StoreID,
  194. }
  195. reLocalTaskPreviews = append(reLocalTaskPreviews, reLocalTaskPreview)
  196. }
  197. return reLocalTaskPreviews, total, nil
  198. }
  199. // 获取公开本地生活中全部指定状态值的项目
  200. func (d LocalLifeDao) GetLocalLifeList(value int64, fieldName string) ([]*entity.LocalLifeInfo, error) {
  201. var localLifeInfos []*entity.LocalLifeInfo
  202. err := Db.Model(entity.LocalLifeInfo{}).Where(fmt.Sprintf("%s = ? ", fieldName), value).Find(&localLifeInfos).Error
  203. if err != nil {
  204. return nil, err
  205. }
  206. return localLifeInfos, nil
  207. }
  208. // 违约管理——违约公开本地生活任务列表
  209. func (d LocalLifeDao) GetLocalPublicList(param *vo.DefaultSearchParam) ([]vo.ReTaskDefaultPublic, int64, error) {
  210. var reTaskDefaultPublics []vo.ReTaskDefaultPublic
  211. var localLifeInfos []entity.LocalLifeInfo
  212. var total int64
  213. query := Db.Model(&entity.LocalLifeInfo{}).Where("local_type = ?", 1)
  214. // 动态添加查询条件
  215. if param.SubAccountId == 0 {
  216. if param.EnterpriseId == "" {
  217. return reTaskDefaultPublics, 0, errors.New("enterpriseId is empty")
  218. }
  219. query = query.Where("enterprise_id = ?", param.EnterpriseId)
  220. } else {
  221. query = query.Where("sub_account_id = ?", param.SubAccountId)
  222. }
  223. if param.Platform != 0 {
  224. query = query.Where("local_platform = ?", param.Platform)
  225. }
  226. if param.Others != "" {
  227. query = query.Where("enterprise_id = ? or local_id = ? or local_name LIKE ?", param.Others, param.Others, "%"+param.Others+"%")
  228. }
  229. query.Count(&total)
  230. query = query.Select("enterprise_id, sub_account_id, local_id, local_platform, task_form, content_type, store_id")
  231. offset := (param.Page - 1) * param.PageSize
  232. if err := query.Order("created_at asc").Offset(offset).Limit(param.PageSize).Find(&localLifeInfos).Error; err != nil {
  233. return nil, 0, err
  234. }
  235. for _, localLife := range localLifeInfos {
  236. reTaskDefaultPublic := vo.ReTaskDefaultPublic{
  237. EnterpriseId: localLife.EnterpriseID,
  238. SubAccountId: localLife.SubAccountID,
  239. TaskId: localLife.LocalID,
  240. Platform: localLife.LocalPlatform,
  241. TaskForm: localLife.TaskForm,
  242. ContentType: localLife.ContentType,
  243. TaskType: 1,
  244. StoreId: localLife.StoreID,
  245. }
  246. reTaskDefaultPublics = append(reTaskDefaultPublics, reTaskDefaultPublic)
  247. }
  248. return reTaskDefaultPublics, total, nil
  249. }
  250. // 探店本地生活列表
  251. func (d LocalLifeDao) GetLocalStoreExplorePreviews(param *vo.LocalSearchParam) ([]vo.ReLocalStoreExplorePreview, int64, error) {
  252. var reLocalStoreExplorePreviews []vo.ReLocalStoreExplorePreview
  253. var localLifes []entity.LocalLifeInfo
  254. var total int64
  255. query := Db.Model(&entity.LocalLifeInfo{})
  256. // 动态添加查询条件
  257. if param.SubAccountId == 0 {
  258. if param.EnterpriseId == "" {
  259. return reLocalStoreExplorePreviews, 0, errors.New("enterpriseId is empty")
  260. }
  261. query = query.Where("enterprise_id = ?", param.EnterpriseId)
  262. } else {
  263. query = query.Where("sub_account_id = ?", param.SubAccountId)
  264. }
  265. if param.LocalType != 0 {
  266. query = query.Where("local_type = ?", param.LocalType)
  267. }
  268. if param.LocalPlatform != 0 {
  269. query = query.Where("local_platform = ?", param.LocalPlatform)
  270. }
  271. if param.Others != "" {
  272. query = query.Where("enterprise_id = ? or local_id = ? or local_name LIKE ?", param.Others, param.Others, "%"+param.Others+"%")
  273. }
  274. query = query.Where("task_status = ? AND task_form = ?", 8, 1)
  275. query.Count(&total)
  276. query = query.Select("enterprise_id, sub_account_id, local_id, local_name, local_type, local_platform, need_reserve, need_confirm, need_explore, explored_num, store_id, team_buying_id")
  277. offset := (param.Page - 1) * param.PageSize
  278. if err := query.Order("pay_at asc").Offset(offset).Limit(param.PageSize).Find(&localLifes).Error; err != nil {
  279. return nil, 0, err
  280. }
  281. for _, localLife := range localLifes {
  282. reLocalStoreExplorePreview := vo.ReLocalStoreExplorePreview{
  283. EnterpriseId: localLife.EnterpriseID,
  284. SubAccountId: localLife.SubAccountID,
  285. LocalId: localLife.LocalID,
  286. LocalName: localLife.LocalName,
  287. LocalPlatform: localLife.LocalPlatform,
  288. LocalType: localLife.LocalType,
  289. NeedReserve: localLife.NeedReserve,
  290. NeedConfirm: localLife.NeedConfirm,
  291. NeedExplore: localLife.NeedExplore,
  292. ExploredNum: localLife.ExploredNum,
  293. StoreId: localLife.StoreID,
  294. TeamBuyingId: localLife.TeamBuyingId,
  295. }
  296. reLocalStoreExplorePreviews = append(reLocalStoreExplorePreviews, reLocalStoreExplorePreview)
  297. }
  298. return reLocalStoreExplorePreviews, total, nil
  299. }
  300. // 获取本地生活账单列表
  301. func (d LocalLifeDao) GetBillLocalPreviews(param *vo.LocalSearchParam) ([]vo.ReBillLocalTaskPreview, int64, error) {
  302. var reBillLocalTaskPreviews []vo.ReBillLocalTaskPreview
  303. var localLifes []entity.LocalLifeInfo
  304. var total int64
  305. query := Db.Model(&entity.LocalLifeInfo{})
  306. // 动态添加查询条件
  307. if param.SubAccountId == 0 {
  308. if param.EnterpriseId == "" {
  309. return reBillLocalTaskPreviews, 0, errors.New("enterpriseId is empty")
  310. }
  311. query = query.Where("enterprise_id = ?", param.EnterpriseId)
  312. } else {
  313. query = query.Where("sub_account_id = ?", param.SubAccountId)
  314. }
  315. if param.LocalType != 0 {
  316. query = query.Where("local_type = ?", param.LocalType)
  317. }
  318. if param.LocalPlatform != 0 {
  319. query = query.Where("local_platform = ?", param.LocalPlatform)
  320. }
  321. if param.LocalStatus != 0 {
  322. query = query.Where("task_status = ?", param.LocalStatus)
  323. }
  324. if param.Others != "" {
  325. query = query.Where("enterprise_id = ? or local_id = ? or local_name LIKE ?", param.Others, param.Others, "%"+param.Others+"%")
  326. }
  327. query.Count(&total)
  328. query = query.Select("enterprise_id, sub_account_id, local_id, local_name, local_platform, task_status, estimated_cost, need_pay, task_form, content_type, store_id, team_buying_id, settlement_amount")
  329. offset := (param.Page - 1) * param.PageSize
  330. if err := query.Order("created_at asc").Offset(offset).Limit(param.PageSize).Find(&localLifes).Error; err != nil {
  331. return nil, 0, err
  332. }
  333. for _, localLife := range localLifes {
  334. reBillLocalTaskPreview := vo.ReBillLocalTaskPreview{
  335. EnterpriseId: localLife.EnterpriseID,
  336. SubAccountId: localLife.SubAccountID,
  337. LocalId: localLife.LocalID,
  338. LocalName: localLife.LocalName,
  339. LocalPlatform: localLife.LocalPlatform,
  340. LocalStatus: localLife.TaskStatus,
  341. LocalForm: localLife.TaskForm,
  342. ContentType: localLife.ContentType,
  343. StoreId: localLife.StoreID,
  344. TeamBuyingId: localLife.TeamBuyingId,
  345. CashAmount: localLife.SettlementAmount,
  346. }
  347. if localLife.TaskStatus < 6 {
  348. reBillLocalTaskPreview.EstimatedCost = localLife.EstimatedCost
  349. } else {
  350. reBillLocalTaskPreview.EstimatedCost = localLife.NeedPay
  351. }
  352. reBillLocalTaskPreviews = append(reBillLocalTaskPreviews, reBillLocalTaskPreview)
  353. }
  354. return reBillLocalTaskPreviews, total, nil
  355. }
  356. // 本地生活任务待办
  357. func (d LocalLifeDao) GetLocalLifeToDo(enterpriseId string, subAccountId int64, platform int64, taskType int64) (map[string]int64, error) {
  358. resultMap := make(map[string]int64)
  359. var needReview int64 // 待审核
  360. var needPay int64
  361. var needProcess int64
  362. var needCheck int64 // 初稿待审
  363. var needQuality int64 // 链接待审
  364. var needCalculate int64 // 待结算
  365. var localInfos []entity.LocalLifeInfo
  366. //query := Db.Model(&entity.LocalLifeInfo{}).Where("enterprise_id = ? and local_platform = ? and local_type = ?", enterpriseId, platform, taskType)
  367. if subAccountId == 0 {
  368. // 待审核、待支付、达人未处理、初稿待审、链接待审、待结算
  369. query1 := Db.Model(&entity.LocalLifeInfo{}).Where("enterprise_id = ? and local_platform = ? and local_type = ?", enterpriseId, platform, taskType)
  370. query1.Where("task_status = ?", 2).Count(&needReview)
  371. query2 := Db.Model(&entity.LocalLifeInfo{}).Where("enterprise_id = ? and local_platform = ? and local_type = ?", enterpriseId, platform, taskType)
  372. query2.Where("task_status = ?", 6).Count(&needPay)
  373. query3 := Db.Model(&entity.LocalLifeInfo{}).Where("enterprise_id = ? and local_platform = ? and local_type = ?", enterpriseId, platform, taskType)
  374. err := query3.Where("task_status = ?", 8).Select("local_id").Find(&localInfos).Error
  375. if err != nil {
  376. if errors.Is(err, gorm.ErrRecordNotFound) {
  377. needProcess = 0
  378. } else {
  379. return resultMap, err
  380. }
  381. } else if len(localInfos) > 0 {
  382. var localIDs []string
  383. for _, info := range localInfos {
  384. localIDs = append(localIDs, info.LocalID)
  385. }
  386. if len(localIDs) > 0 {
  387. err1 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and task_status = ?", localIDs, 1).Count(&needProcess).Error // task_status=1待选
  388. if err1 != nil {
  389. needProcess = 0
  390. }
  391. }
  392. }
  393. query4 := Db.Model(&entity.LocalLifeInfo{}).Where("enterprise_id = ? and local_platform = ? and local_type = ?", enterpriseId, platform, taskType)
  394. err1 := query4.Select("need_review, need_quality, need_calculate").Find(&localInfos).Error
  395. if err1 != nil {
  396. return resultMap, err1
  397. } else if len(localInfos) > 0 {
  398. for _, info := range localInfos {
  399. needCheck += info.NeedReview
  400. needQuality += info.NeedQuality
  401. needCalculate += info.NeedCalculate
  402. }
  403. }
  404. } else {
  405. // 待审核、待支付、达人未处理
  406. query1 := Db.Model(&entity.LocalLifeInfo{}).Where("enterprise_id = ? and local_platform = ? and local_type = ?", enterpriseId, platform, taskType)
  407. query1.Where("sub_account_id = ? and task_status = ?", subAccountId, 2).Count(&needReview)
  408. query2 := Db.Model(&entity.LocalLifeInfo{}).Where("enterprise_id = ? and local_platform = ? and local_type = ?", enterpriseId, platform, taskType)
  409. query2.Where("sub_account_id = ? and task_status = ?", subAccountId, 6).Count(&needPay)
  410. query3 := Db.Model(&entity.LocalLifeInfo{}).Where("enterprise_id = ? and local_platform = ? and local_type = ?", enterpriseId, platform, taskType)
  411. err := query3.Where("sub_account_id = ? and task_status = ?", subAccountId, 8).Select("local_id").Find(&localInfos).Error
  412. if err != nil {
  413. if errors.Is(err, gorm.ErrRecordNotFound) {
  414. needProcess = 0
  415. } else {
  416. return resultMap, err
  417. }
  418. } else {
  419. var localIDs []string
  420. for _, info := range localInfos {
  421. localIDs = append(localIDs, info.LocalID)
  422. }
  423. if len(localIDs) > 0 {
  424. err1 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and task_status = ?", localIDs, 1).Count(&needProcess).Error // task_status=1待选
  425. if err1 != nil {
  426. needProcess = 0
  427. }
  428. }
  429. }
  430. query4 := Db.Model(&entity.LocalLifeInfo{}).Where("enterprise_id = ? and local_platform = ? and local_type = ?", enterpriseId, platform, taskType)
  431. err1 := query4.Select("need_review, need_quality, need_calculate").Find(&localInfos).Error
  432. if err1 != nil {
  433. return resultMap, err1
  434. } else if len(localInfos) > 0 {
  435. for _, info := range localInfos {
  436. needCheck += info.NeedReview
  437. needQuality += info.NeedQuality
  438. needCalculate += info.NeedCalculate
  439. }
  440. }
  441. }
  442. resultMap["needReview"] = needReview
  443. resultMap["needPay"] = needPay
  444. resultMap["needProcess"] = needProcess
  445. resultMap["needCheck"] = needCheck
  446. resultMap["needQuality"] = needQuality
  447. resultMap["needCalculate"] = needCalculate
  448. return resultMap, nil
  449. }
  450. // 探店邀约任务待办
  451. func (d LocalLifeDao) GetExploreToDo(enterpriseId string, subAccountId int64, platform int64) (map[string]int64, error) {
  452. resultMap := make(map[string]int64)
  453. var needBook int64 // 待预约探店时间
  454. var needConfirm int64 // 探店时间待确认
  455. var needExplore int64 // 达人待探店
  456. var localInfos []entity.LocalLifeInfo
  457. //query := Db.Model(&entity.LocalLifeInfo{}).Where("enterprise_id = ? and local_platform = ? and local_type = ?", enterpriseId, platform, taskType)
  458. if subAccountId == 0 {
  459. // 待预约探店时间、探店时间待确认、达人待探店
  460. query1 := Db.Model(&entity.LocalLifeInfo{}).Where("enterprise_id = ? and local_platform = ? and task_form = ?", enterpriseId, platform, 1)
  461. err := query1.Where("task_status = ?", 8).Select("local_id").Find(&localInfos).Error
  462. if err != nil {
  463. if errors.Is(err, gorm.ErrRecordNotFound) {
  464. needBook = 0
  465. needConfirm = 0
  466. needExplore = 0
  467. } else {
  468. return resultMap, err
  469. }
  470. } else if len(localInfos) > 0 {
  471. var localIDs []string
  472. for _, info := range localInfos {
  473. localIDs = append(localIDs, info.LocalID)
  474. }
  475. if len(localIDs) > 0 {
  476. err1 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and task_stage = ?", localIDs, 4).Count(&needBook).Error // task_stage=4待预约探店
  477. if err1 != nil {
  478. needBook = 0
  479. }
  480. err2 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and task_stage = ?", localIDs, 5).Count(&needConfirm).Error // task_stage=4预约确认中
  481. if err2 != nil {
  482. needConfirm = 0
  483. }
  484. err3 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and book_status = ?", localIDs, 5).Count(&needExplore).Error // book_status=5达人待探店
  485. if err3 != nil {
  486. needExplore = 0
  487. }
  488. }
  489. }
  490. } else {
  491. // 待预约探店时间、探店时间待确认、达人待探店
  492. query1 := Db.Model(&entity.LocalLifeInfo{}).Where("enterprise_id = ? and local_platform = ? and task_form = ?", enterpriseId, platform, 1)
  493. err := query1.Where("sub_account_id = ? and task_status = ?", subAccountId, 8).Select("local_id").Find(&localInfos).Error
  494. if err != nil {
  495. if errors.Is(err, gorm.ErrRecordNotFound) {
  496. needBook = 0
  497. needConfirm = 0
  498. needExplore = 0
  499. } else {
  500. return resultMap, err
  501. }
  502. } else if len(localInfos) > 0 {
  503. var localIDs []string
  504. for _, info := range localInfos {
  505. localIDs = append(localIDs, info.LocalID)
  506. }
  507. if len(localIDs) > 0 {
  508. err1 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and task_stage = ?", localIDs, 4).Count(&needBook).Error // task_stage=4待预约探店
  509. if err1 != nil {
  510. needBook = 0
  511. }
  512. err2 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and task_stage = ?", localIDs, 5).Count(&needConfirm).Error // task_stage=4预约确认中
  513. if err2 != nil {
  514. needConfirm = 0
  515. }
  516. err3 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and book_status = ?", localIDs, 5).Count(&needExplore).Error // book_status=5达人待探店
  517. if err3 != nil {
  518. needExplore = 0
  519. }
  520. }
  521. }
  522. }
  523. resultMap["needBook"] = needBook
  524. resultMap["needConfirm"] = needConfirm
  525. resultMap["needExplore"] = needExplore
  526. return resultMap, nil
  527. }
  528. // 违约管理任务待办
  529. func (d LocalLifeDao) GetDefaultToDo(enterpriseId string, subAccountId int64, platform int64, taskType int64) (map[string]int64, error) {
  530. resultMap := make(map[string]int64)
  531. var noSketch int64 // 未传初稿
  532. var noWork int64 // 未发作品
  533. var noData int64 // 未传数据
  534. var cooperateOver int64 // 终止合作
  535. var localInfos []entity.LocalLifeInfo
  536. //query := Db.Model(&entity.LocalLifeInfo{}).Where("enterprise_id = ? and local_platform = ? and local_type = ?", enterpriseId, platform, taskType)
  537. if subAccountId == 0 {
  538. // 未传初稿、未发作品、未传数据、终止合作
  539. query1 := Db.Model(&entity.LocalLifeInfo{}).Where("enterprise_id = ? and local_platform = ? and local_type = ?", enterpriseId, platform, taskType)
  540. err := query1.Where("task_status = ?", 8).Select("local_id").Find(&localInfos).Error
  541. if err != nil {
  542. if errors.Is(err, gorm.ErrRecordNotFound) {
  543. noSketch = 0
  544. noWork = 0
  545. noData = 0
  546. cooperateOver = 0
  547. } else {
  548. return resultMap, err
  549. }
  550. } else if len(localInfos) > 0 {
  551. var localIDs []string
  552. for _, info := range localInfos {
  553. localIDs = append(localIDs, info.LocalID)
  554. }
  555. if len(localIDs) > 0 {
  556. err1 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and cur_default_type = ?", localIDs, 4).Count(&noSketch).Error // cur_default_type=4 初稿未上传违约
  557. if err1 != nil {
  558. noSketch = 0
  559. }
  560. err2 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and cur_default_type = ?", localIDs, 6).Count(&noWork).Error // cur_default_type=6 链接未上传违约
  561. if err2 != nil {
  562. noWork = 0
  563. }
  564. err3 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and cur_default_type = ?", localIDs, 8).Count(&noData).Error // cur_default_type=8 数据未上传违约
  565. if err3 != nil {
  566. noData = 0
  567. }
  568. err4 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and cur_default_type = ?", localIDs, 10).Count(&cooperateOver).Error // cur_default_type=10 解约
  569. if err4 != nil {
  570. cooperateOver = 0
  571. }
  572. }
  573. }
  574. } else {
  575. // 未传初稿、未发作品、未传数据、终止合作
  576. query1 := Db.Model(&entity.LocalLifeInfo{}).Where("enterprise_id = ? and local_platform = ? and local_type = ?", enterpriseId, platform, taskType)
  577. err := query1.Where("sub_account_id = ? and task_status = ?", subAccountId, 8).Select("local_id").Find(&localInfos).Error
  578. if err != nil {
  579. if errors.Is(err, gorm.ErrRecordNotFound) {
  580. noSketch = 0
  581. noWork = 0
  582. noData = 0
  583. cooperateOver = 0
  584. } else {
  585. return resultMap, err
  586. }
  587. } else if len(localInfos) > 0 {
  588. var localIDs []string
  589. for _, info := range localInfos {
  590. localIDs = append(localIDs, info.LocalID)
  591. }
  592. if len(localIDs) > 0 {
  593. err1 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and cur_default_type = ?", localIDs, 4).Count(&noSketch).Error // cur_default_type=4 初稿未上传违约
  594. if err1 != nil {
  595. noSketch = 0
  596. }
  597. err2 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and cur_default_type = ?", localIDs, 6).Count(&noWork).Error // cur_default_type=6 链接未上传违约
  598. if err2 != nil {
  599. noWork = 0
  600. }
  601. err3 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and cur_default_type = ?", localIDs, 8).Count(&noData).Error // cur_default_type=8 数据未上传违约
  602. if err3 != nil {
  603. noData = 0
  604. }
  605. err4 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and cur_default_type = ?", localIDs, 10).Count(&cooperateOver).Error // cur_default_type=10 解约
  606. if err4 != nil {
  607. cooperateOver = 0
  608. }
  609. }
  610. }
  611. }
  612. resultMap["noSketch"] = noSketch
  613. resultMap["noWork"] = noWork
  614. resultMap["noData"] = noData
  615. resultMap["cooperateOver"] = cooperateOver
  616. return resultMap, nil
  617. }
  618. // 获取指定商家已结案的指定开票状态数据
  619. func (d LocalLifeDao) GetLocalLifeFinished(enterpriseId string, invoiceStatus int64) (float64, error) {
  620. var localLifeAmount float64
  621. err := Db.Model(&entity.LocalLifeInfo{}).Where("enterprise_id = ? and task_status = ? and invoice_status = ?", enterpriseId, 10, invoiceStatus).Select("COALESCE(SUM(settlement_amount), 0)").Find(&localLifeAmount).Error
  622. if err != nil {
  623. return 0, err
  624. }
  625. return localLifeAmount, err
  626. }
  627. // 合作待办-任务邀约
  628. func (d LocalLifeDao) GetTaskInviteToDo(enterpriseId string, subAccountId int64, platform int64) (map[string]int64, error) {
  629. resultMap := make(map[string]int64)
  630. var availInvitationNum int64 //
  631. var invitingNum int64 //
  632. var cooperatingNum int64 //
  633. //var localInfos []entity.LocalLifeInfo
  634. ////query := Db.Model(&entity.LocalLifeInfo{}).Where("enterprise_id = ? and local_platform = ? and local_type = ?", enterpriseId, platform, taskType)
  635. //if subAccountId == 0 {
  636. // // 待预约探店时间、探店时间待确认、达人待探店
  637. // query1 := Db.Model(&entity.LocalLifeInfo{}).Where("enterprise_id = ? and local_platform = ? and task_form = ?", enterpriseId, platform, 1)
  638. // err := query1.Where("task_status = ?", 8).Select("local_id").Find(&localInfos).Error
  639. // if err != nil {
  640. // if errors.Is(err, gorm.ErrRecordNotFound) {
  641. // needBook = 0
  642. // needConfirm = 0
  643. // needExplore = 0
  644. // } else {
  645. // return resultMap, err
  646. // }
  647. // } else if len(localInfos) > 0 {
  648. // var localIDs []string
  649. // for _, info := range localInfos {
  650. // localIDs = append(localIDs, info.LocalID)
  651. // }
  652. // if len(localIDs) > 0 {
  653. // err1 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and task_stage = ?", localIDs, 4).Count(&needBook).Error // task_stage=4待预约探店
  654. // if err1 != nil {
  655. // needBook = 0
  656. // }
  657. // err2 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and task_stage = ?", localIDs, 5).Count(&needConfirm).Error // task_stage=4预约确认中
  658. // if err2 != nil {
  659. // needConfirm = 0
  660. // }
  661. // err3 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and book_status = ?", localIDs, 5).Count(&needExplore).Error // book_status=5达人待探店
  662. // if err3 != nil {
  663. // needExplore = 0
  664. // }
  665. // }
  666. // }
  667. //} else {
  668. // // 待预约探店时间、探店时间待确认、达人待探店
  669. // query1 := Db.Model(&entity.LocalLifeInfo{}).Where("enterprise_id = ? and local_platform = ? and task_form = ?", enterpriseId, platform, 1)
  670. // err := query1.Where("sub_account_id = ? and task_status = ?", subAccountId, 8).Select("local_id").Find(&localInfos).Error
  671. // if err != nil {
  672. // if errors.Is(err, gorm.ErrRecordNotFound) {
  673. // needBook = 0
  674. // needConfirm = 0
  675. // needExplore = 0
  676. // } else {
  677. // return resultMap, err
  678. // }
  679. // } else if len(localInfos) > 0 {
  680. // var localIDs []string
  681. // for _, info := range localInfos {
  682. // localIDs = append(localIDs, info.LocalID)
  683. // }
  684. // if len(localIDs) > 0 {
  685. // err1 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and task_stage = ?", localIDs, 4).Count(&needBook).Error // task_stage=4待预约探店
  686. // if err1 != nil {
  687. // needBook = 0
  688. // }
  689. // err2 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and task_stage = ?", localIDs, 5).Count(&needConfirm).Error // task_stage=4预约确认中
  690. // if err2 != nil {
  691. // needConfirm = 0
  692. // }
  693. // err3 := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id in ? and book_status = ?", localIDs, 5).Count(&needExplore).Error // book_status=5达人待探店
  694. // if err3 != nil {
  695. // needExplore = 0
  696. // }
  697. // }
  698. // }
  699. //}
  700. resultMap["availInvitationNum"] = availInvitationNum
  701. resultMap["invitingNum"] = invitingNum
  702. resultMap["cooperatingNum"] = cooperatingNum
  703. return resultMap, nil
  704. }