default_service.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. package service
  2. import (
  3. "strconv"
  4. "time"
  5. "youngee_b_api/app/dao"
  6. "youngee_b_api/app/entity"
  7. "youngee_b_api/app/vo"
  8. )
  9. type DefaultService struct{}
  10. // 违约管理——违约公开任务列表
  11. func (s DefaultService) GetPublicDefaultList(param *vo.DefaultSearchParam) (vo.ResultVO, error) {
  12. if param.Page <= 0 {
  13. param.Page = 1
  14. }
  15. if param.PageSize <= 0 {
  16. param.PageSize = 10
  17. }
  18. var result vo.ResultVO
  19. // 以下代码只考虑了种草
  20. reTaskDefaultPublics, total, err := (&dao.ProjectDAO{}).GetProjectPublicList(param)
  21. if err != nil {
  22. return result, err
  23. }
  24. for i := range reTaskDefaultPublics {
  25. // 获取商品详情字段
  26. var creatorName string
  27. var productName string
  28. var productPrice float64
  29. var mainImage string
  30. if reTaskDefaultPublics[i].SubAccountId == 0 {
  31. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reTaskDefaultPublics[i].EnterpriseId)
  32. if err == nil && enterprise != nil {
  33. creatorName = enterprise.BusinessName
  34. }
  35. } else {
  36. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reTaskDefaultPublics[i].SubAccountId)
  37. if err == nil && subAccount != nil {
  38. creatorName = subAccount.SubAccountName
  39. }
  40. }
  41. product, err := dao.ProductDAO{}.GetProductByID(reTaskDefaultPublics[i].ProductId)
  42. if err == nil && product != nil {
  43. productName = product.ProductName
  44. productPrice = product.ProductPrice
  45. }
  46. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByProductID(reTaskDefaultPublics[i].ProductId)
  47. reTaskDefaultPublics[i].CreatorName = creatorName
  48. reTaskDefaultPublics[i].ProductName = productName
  49. reTaskDefaultPublics[i].ProductPrice = productPrice
  50. reTaskDefaultPublics[i].MainImage = mainImage
  51. // 获取未传数量字段 0-10分别表示未违约、脚本超时违约、脚本未上传违约、初稿超时违约、初稿未上传违约、链接超时违约、链接未上传违约、数据超时违约、数据未上传违约、解约待处理、解约
  52. projectId := reTaskDefaultPublics[i].TaskId
  53. noSketchNum := dao.ProjectTaskInfoDao{}.CountByDefaultType(projectId, 4)
  54. noLinkNum := dao.ProjectTaskInfoDao{}.CountByDefaultType(projectId, 6)
  55. noDataNum := dao.ProjectTaskInfoDao{}.CountByDefaultType(projectId, 8)
  56. // 终止合作还是解约字段待确认
  57. endCooperationNum := dao.ProjectTaskInfoDao{}.CountByTaskStage(projectId, 17)
  58. reTaskDefaultPublics[i].NoSketchNum = noSketchNum
  59. reTaskDefaultPublics[i].NoLinkNum = noLinkNum
  60. reTaskDefaultPublics[i].NoDataNum = noDataNum
  61. reTaskDefaultPublics[i].EndCooperationNum = endCooperationNum
  62. }
  63. result = vo.ResultVO{
  64. Page: param.Page,
  65. PageSize: param.PageSize,
  66. Total: total,
  67. Data: reTaskDefaultPublics,
  68. }
  69. return result, nil
  70. }
  71. // 违约管理——违约定向任务列表
  72. func (s DefaultService) GetTargetDefaultList(param *vo.DefaultSearchParam) (vo.ResultVO, error) {
  73. if param.Page <= 0 {
  74. param.Page = 1
  75. }
  76. if param.PageSize <= 0 {
  77. param.PageSize = 10
  78. }
  79. var result vo.ResultVO
  80. // 以下代码只考虑了种草
  81. reTaskDefaultTargets, total, err := (&dao.ProjectDAO{}).GetProjectTargetList(param)
  82. if err != nil {
  83. return result, err
  84. }
  85. for i := range reTaskDefaultTargets {
  86. // 获取商品详情字段
  87. var creatorName string
  88. var productName string
  89. var productPrice float64
  90. var mainImage string
  91. if reTaskDefaultTargets[i].SubAccountId == 0 {
  92. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reTaskDefaultTargets[i].EnterpriseId)
  93. if err == nil && enterprise != nil {
  94. creatorName = enterprise.BusinessName
  95. }
  96. } else {
  97. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reTaskDefaultTargets[i].SubAccountId)
  98. if err == nil && subAccount != nil {
  99. creatorName = subAccount.SubAccountName
  100. }
  101. }
  102. product, err := dao.ProductDAO{}.GetProductByID(reTaskDefaultTargets[i].ProductId)
  103. if err == nil && product != nil {
  104. productName = product.ProductName
  105. productPrice = product.ProductPrice
  106. }
  107. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByProductID(reTaskDefaultTargets[i].ProductId)
  108. reTaskDefaultTargets[i].CreatorName = creatorName
  109. reTaskDefaultTargets[i].ProductName = productName
  110. reTaskDefaultTargets[i].ProductPrice = productPrice
  111. reTaskDefaultTargets[i].MainImage = mainImage
  112. // 终止合作还是解约字段待确认
  113. endCooperationNum := dao.ProjectTaskInfoDao{}.CountByTaskStage(reTaskDefaultTargets[i].TaskId, 17)
  114. reTaskDefaultTargets[i].EndCooperationNum = endCooperationNum
  115. }
  116. result = vo.ResultVO{
  117. Page: param.Page,
  118. PageSize: param.PageSize,
  119. Total: total,
  120. Data: reTaskDefaultTargets,
  121. }
  122. return result, nil
  123. }
  124. // 违约管理——公开任务-违约达人列表
  125. func (s DefaultService) GetPublicDefaultTalentList(param *vo.DefaultSearchParam) (vo.ResultVO, error) {
  126. if param.Page <= 0 {
  127. param.Page = 1
  128. }
  129. if param.PageSize <= 0 {
  130. param.PageSize = 10
  131. }
  132. var result vo.ResultVO
  133. var reTalentDefaults []*vo.ReTalentDefault
  134. // 以下代码只考虑了种草
  135. var projectTaskInfos []entity.ProjectTaskInfo
  136. var total int64
  137. var err error
  138. var cutRate int64
  139. defaultType := param.DefaultType
  140. if defaultType == 1 { // 未传初稿
  141. projectTaskInfos, total, err = dao.ProjectTaskInfoDao{}.GetListBySketchDefault(param)
  142. autoDefaultId, _ := dao.ProjectDAO{}.GetAutoDefaultId(param.TaskId)
  143. cutRate = dao.InfoAutoDefaultDao{}.GetValueByIdFieldName(*autoDefaultId, "sketch_replace_not_upload")
  144. } else if defaultType == 2 { // 未发作品
  145. projectTaskInfos, total, err = dao.ProjectTaskInfoDao{}.GetListByLinkDefault(param)
  146. autoDefaultId, _ := dao.ProjectDAO{}.GetAutoDefaultId(param.TaskId)
  147. cutRate = dao.InfoAutoDefaultDao{}.GetValueByIdFieldName(*autoDefaultId, "link_replace_not_upload")
  148. } else if defaultType == 3 { // 未传数据
  149. projectTaskInfos, total, err = dao.ProjectTaskInfoDao{}.GetListByDataDefault(param)
  150. autoDefaultId, _ := dao.ProjectDAO{}.GetAutoDefaultId(param.TaskId)
  151. cutRate = dao.InfoAutoDefaultDao{}.GetValueByIdFieldName(*autoDefaultId, "data_replace_not_upload")
  152. } else if defaultType == 4 { // 终止合作
  153. projectTaskInfos, total, err = dao.ProjectTaskInfoDao{}.GetListByTerminateDefault(param)
  154. } else if defaultType == 5 { // 已解约
  155. projectTaskInfos, total, err = dao.ProjectTaskInfoDao{}.GetListByCancelDefault(param)
  156. }
  157. if err != nil {
  158. return result, err
  159. }
  160. for _, projectTaskInfo := range projectTaskInfos {
  161. talentId := projectTaskInfo.TalentID
  162. talentPhone, _ := dao.TalentInfoDao{}.SelectTalentPhone(talentId)
  163. platformKuaishouUserInfo, _ := dao.PlatformKuaishouUserInfoDao{}.SelectUserInfo(talentId)
  164. reTalentDefault := &vo.ReTalentDefault{
  165. TalentId: talentId,
  166. TalentPhone: *talentPhone,
  167. TaskId: projectTaskInfo.TaskID,
  168. DraftFee: projectTaskInfo.DraftFee,
  169. OpenId: platformKuaishouUserInfo.OpenId,
  170. NickName: platformKuaishouUserInfo.NickName,
  171. HeadUri: platformKuaishouUserInfo.HeadUri,
  172. City: "-",
  173. }
  174. if defaultType == 1 {
  175. reTalentDefault.DefaultTime = projectTaskInfo.SketchMissingTime.Format("2006-01-02 15:04:05")
  176. reTalentDefault.SettleAmount = projectTaskInfo.SettleAmount
  177. } else if defaultType == 2 {
  178. reTalentDefault.DefaultTime = projectTaskInfo.LinkMissingTime.Format("2006-01-02 15:04:05")
  179. reTalentDefault.SettleAmount = projectTaskInfo.SettleAmount
  180. } else if defaultType == 3 {
  181. reTalentDefault.DefaultTime = projectTaskInfo.DataMissingTime.Format("2006-01-02 15:04:05")
  182. reTalentDefault.SettleAmount = projectTaskInfo.SettleAmount
  183. } else if defaultType == 4 {
  184. reTalentDefault.DefaultTime = projectTaskInfo.TerminateTime.Format("2006-01-02 15:04:05")
  185. reTalentDefault.Reason = projectTaskInfo.TerminateReason
  186. terminateOperatorType := projectTaskInfo.TerminateOperatorType
  187. if terminateOperatorType == 1 {
  188. enterprise, _ := dao.EnterpriseDao{}.GetEnterprise(projectTaskInfo.TerminateOperator)
  189. reTalentDefault.OperatorName = enterprise.BusinessName
  190. } else if terminateOperatorType == 2 {
  191. operatorId, _ := strconv.ParseInt(projectTaskInfo.TerminateOperator, 10, 64)
  192. subAccount, _ := dao.SubAccountDao{}.GetSubAccount(operatorId)
  193. reTalentDefault.OperatorName = subAccount.SubAccountName
  194. } else if terminateOperatorType == 3 {
  195. operatorId, _ := strconv.ParseInt(projectTaskInfo.TerminateOperator, 10, 64)
  196. userName, _ := dao.UserDao{}.GetNameByUserId(operatorId)
  197. reTalentDefault.OperatorName = userName
  198. }
  199. } else if defaultType == 5 {
  200. reTalentDefault.DefaultTime = projectTaskInfo.CancelTime.Format("2006-01-02 15:04:05")
  201. reTalentDefault.SettleAmount = projectTaskInfo.SettleAmount
  202. reTalentDefault.Reason = projectTaskInfo.CancelReason
  203. cancelOperatorType := projectTaskInfo.CancelOperatorType
  204. if cancelOperatorType == 1 {
  205. enterprise, _ := dao.EnterpriseDao{}.GetEnterprise(projectTaskInfo.CancelOperator)
  206. reTalentDefault.OperatorName = enterprise.BusinessName
  207. } else if cancelOperatorType == 2 {
  208. operatorId, _ := strconv.ParseInt(projectTaskInfo.CancelOperator, 10, 64)
  209. subAccount, _ := dao.SubAccountDao{}.GetSubAccount(operatorId)
  210. reTalentDefault.OperatorName = subAccount.SubAccountName
  211. } else if cancelOperatorType == 3 {
  212. operatorId, _ := strconv.ParseInt(projectTaskInfo.CancelOperator, 10, 64)
  213. userName, _ := dao.UserDao{}.GetNameByUserId(operatorId)
  214. reTalentDefault.OperatorName = userName
  215. }
  216. }
  217. reTalentDefaults = append(reTalentDefaults, reTalentDefault)
  218. }
  219. resultMap := make(map[string]interface{})
  220. resultMap["cutRate"] = cutRate
  221. resultMap["reTalentDefaults"] = reTalentDefaults
  222. result = vo.ResultVO{
  223. Page: param.Page,
  224. PageSize: param.PageSize,
  225. Total: total,
  226. Data: resultMap,
  227. }
  228. return result, nil
  229. }
  230. // 违约管理——定向任务-违约达人列表
  231. func (s DefaultService) GetTargetDefaultTalentList(param *vo.DefaultSearchParam) (vo.ResultVO, error) {
  232. if param.Page <= 0 {
  233. param.Page = 1
  234. }
  235. if param.PageSize <= 0 {
  236. param.PageSize = 10
  237. }
  238. var result vo.ResultVO
  239. var reTalentDefaults []*vo.ReTalentDefault
  240. // 以下代码只考虑了种草
  241. var projectTaskInfos []entity.ProjectTaskInfo
  242. var total int64
  243. var err error
  244. defaultType := param.DefaultType
  245. if defaultType == 4 { // 终止合作
  246. projectTaskInfos, total, err = (&dao.ProjectTaskInfoDao{}).GetListByTerminateDefault(param)
  247. } else if defaultType == 5 { // 已解约
  248. projectTaskInfos, total, err = (&dao.ProjectTaskInfoDao{}).GetListByCancelDefault(param)
  249. }
  250. if err != nil {
  251. return result, err
  252. }
  253. for _, projectTaskInfo := range projectTaskInfos {
  254. talentId := projectTaskInfo.TalentID
  255. talentPhone, _ := dao.TalentInfoDao{}.SelectTalentPhone(talentId)
  256. platformKuaishouUserInfo, _ := dao.PlatformKuaishouUserInfoDao{}.SelectUserInfo(talentId)
  257. reTalentDefault := &vo.ReTalentDefault{
  258. TalentId: talentId,
  259. TalentPhone: *talentPhone,
  260. DraftFee: projectTaskInfo.DraftFee,
  261. OpenId: platformKuaishouUserInfo.OpenId,
  262. NickName: platformKuaishouUserInfo.NickName,
  263. HeadUri: platformKuaishouUserInfo.HeadUri,
  264. City: "-",
  265. }
  266. if defaultType == 4 {
  267. reTalentDefault.DefaultTime = projectTaskInfo.TerminateTime.Format("2006-01-02 15:04:05")
  268. reTalentDefault.Reason = projectTaskInfo.TerminateReason
  269. terminateOperatorType := projectTaskInfo.TerminateOperatorType
  270. if terminateOperatorType == 1 {
  271. enterprise, _ := dao.EnterpriseDao{}.GetEnterprise(projectTaskInfo.TerminateOperator)
  272. reTalentDefault.OperatorName = enterprise.BusinessName
  273. } else if terminateOperatorType == 2 {
  274. operatorId, _ := strconv.ParseInt(projectTaskInfo.TerminateOperator, 10, 64)
  275. subAccount, _ := dao.SubAccountDao{}.GetSubAccount(operatorId)
  276. reTalentDefault.OperatorName = subAccount.SubAccountName
  277. } else if terminateOperatorType == 3 {
  278. operatorId, _ := strconv.ParseInt(projectTaskInfo.TerminateOperator, 10, 64)
  279. userName, _ := dao.UserDao{}.GetNameByUserId(operatorId)
  280. reTalentDefault.OperatorName = userName
  281. }
  282. } else if defaultType == 5 {
  283. reTalentDefault.DefaultTime = projectTaskInfo.CancelTime.Format("2006-01-02 15:04:05")
  284. reTalentDefault.SettleAmount = projectTaskInfo.SettleAmount
  285. cancelOperatorType := projectTaskInfo.CancelOperatorType
  286. if cancelOperatorType == 1 {
  287. enterprise, _ := dao.EnterpriseDao{}.GetEnterprise(projectTaskInfo.CancelOperator)
  288. reTalentDefault.OperatorName = enterprise.BusinessName
  289. } else if cancelOperatorType == 2 {
  290. operatorId, _ := strconv.ParseInt(projectTaskInfo.CancelOperator, 10, 64)
  291. subAccount, _ := dao.SubAccountDao{}.GetSubAccount(operatorId)
  292. reTalentDefault.OperatorName = subAccount.SubAccountName
  293. } else if cancelOperatorType == 3 {
  294. operatorId, _ := strconv.ParseInt(projectTaskInfo.CancelOperator, 10, 64)
  295. userName, _ := dao.UserDao{}.GetNameByUserId(operatorId)
  296. reTalentDefault.OperatorName = userName
  297. }
  298. }
  299. reTalentDefaults = append(reTalentDefaults, reTalentDefault)
  300. }
  301. result = vo.ResultVO{
  302. Page: param.Page,
  303. PageSize: param.PageSize,
  304. Total: total,
  305. Data: reTalentDefaults,
  306. }
  307. return result, nil
  308. }
  309. // 违约管理——达人解约
  310. func (s DefaultService) CancelTalent(param *vo.TalentCancelParam) error {
  311. updateData := map[string]interface{}{
  312. "task_stage": 16,
  313. "settle_amount": param.RealPayment,
  314. "real_payment": param.RealPayment,
  315. "cancel_reason": param.CancelReason,
  316. "cancel_time": time.Now(),
  317. }
  318. err := dao.ProjectTaskInfoDao{}.UpdateField(param.TaskId, updateData)
  319. if err != nil {
  320. return err
  321. }
  322. return nil
  323. }
  324. // 违约管理——达人批量解约
  325. func (s DefaultService) CancelTalentList(param *vo.TalentCancelParam) error {
  326. updateData := map[string]interface{}{
  327. "task_stage": 16,
  328. "settle_amount": param.RealPayment,
  329. "real_payment": param.RealPayment,
  330. "cancel_reason": param.CancelReason,
  331. "cancel_time": time.Now(),
  332. }
  333. err := dao.ProjectTaskInfoDao{}.UpdateFieldBatch(param.TaskIds, updateData)
  334. if err != nil {
  335. return err
  336. }
  337. return nil
  338. }