default_service.go 14 KB

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