local_life_dao.go 28 KB

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