mcn.go 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  1. package service
  2. import (
  3. "context"
  4. "sort"
  5. "strings"
  6. "time"
  7. "go-common/app/admin/main/mcn/dao/up"
  8. "go-common/app/admin/main/mcn/model"
  9. accgrpc "go-common/app/service/main/account/api"
  10. memgrpc "go-common/app/service/main/member/api"
  11. blkmdl "go-common/app/service/main/member/model/block"
  12. xsql "go-common/library/database/sql"
  13. "go-common/library/ecode"
  14. "go-common/library/log"
  15. xtime "go-common/library/time"
  16. "github.com/pkg/errors"
  17. )
  18. // McnSignEntry .
  19. func (s *Service) McnSignEntry(c context.Context, arg *model.MCNSignEntryReq) error {
  20. var (
  21. err error
  22. count, lastID int64
  23. stime, etime xtime.Time
  24. blockInfo *memgrpc.BlockInfoReply
  25. tx *xsql.Tx
  26. now = time.Now()
  27. date = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
  28. )
  29. if tx, err = s.dao.BeginTran(c); err != nil {
  30. return err
  31. }
  32. defer func() {
  33. if err != nil {
  34. tx.Rollback()
  35. } else {
  36. tx.Commit()
  37. }
  38. }()
  39. if blockInfo, err = s.memGRPC.BlockInfo(c, &memgrpc.MemberMidReq{Mid: arg.MCNMID}); err != nil {
  40. return err
  41. }
  42. if blockInfo.BlockStatus > int32(blkmdl.BlockStatusFalse) {
  43. return ecode.MCNSignIsBlocked
  44. }
  45. if count, err = s.dao.McnSignNoOKState(c, arg.MCNMID); err != nil {
  46. return err
  47. }
  48. if count > 0 {
  49. return ecode.MCNSignNoOkState
  50. }
  51. if stime, etime, err = arg.ParseTime(); err != nil {
  52. return err
  53. }
  54. if etime.Time().Before(date) || etime.Time().Equal(date) {
  55. return ecode.MCNSignEtimeNLEQNowTime
  56. }
  57. if count, err = s.dao.McnSignCountUQTime(c, arg.MCNMID, stime, etime); err != nil {
  58. return err
  59. }
  60. if count > 0 {
  61. return ecode.MCNSignCycleNotUQErr
  62. }
  63. arg.AttrPermitSet()
  64. if lastID, err = s.dao.TxAddMcnSignEntry(tx, arg.MCNMID, arg.BeginDate, arg.EndDate, arg.Permission); err != nil {
  65. return err
  66. }
  67. for _, v := range arg.SignPayInfo {
  68. if _, err = s.dao.TxAddMcnSignPay(tx, arg.MCNMID, lastID, v.PayValue, v.DueDate, ""); err != nil {
  69. return err
  70. }
  71. }
  72. s.worker.Add(func() {
  73. index := []interface{}{int8(model.MCNSignStateNoApply), lastID}
  74. content := map[string]interface{}{
  75. "sign_id": lastID,
  76. "mcn_mid": arg.MCNMID,
  77. "state": int8(model.MCNSignStateNoApply),
  78. "begin_date": arg.BeginDate,
  79. "end_date": arg.EndDate,
  80. "permission": arg.Permission,
  81. }
  82. s.AddAuditLog(context.Background(), model.MCNLogBizID, int8(model.MCNSignActionEntry), model.MCNSignActionEntry.String(), arg.UID, arg.UserName, []int64{arg.MCNMID}, index, content)
  83. })
  84. s.worker.Add(func() {
  85. index := []interface{}{arg.MCNMID}
  86. content := map[string]interface{}{
  87. "sign_id": lastID,
  88. "mcn_mid": arg.MCNMID,
  89. "sign_pay_info": arg.SignPayInfo,
  90. }
  91. s.AddAuditLog(context.Background(), model.MCNPayDateLogBizID, int8(model.MCNSignCycleActionAdd), model.MCNSignCycleActionAdd.String(), arg.UID, arg.UserName, []int64{lastID}, index, content)
  92. })
  93. s.worker.Add(func() {
  94. s.dao.DelMcnSignCache(context.Background(), arg.MCNMID)
  95. })
  96. return nil
  97. }
  98. // McnSignList .
  99. func (s *Service) McnSignList(c context.Context, arg *model.MCNSignStateReq) (res *model.MCNSignListReply, err error) {
  100. var (
  101. count int64
  102. signIDs, mids []int64
  103. accsReply *accgrpc.InfosReply
  104. accInfos map[int64]*accgrpc.Info
  105. mcns []*model.MCNSignInfoReply
  106. sm map[int64][]*model.SignPayInfoReply
  107. )
  108. res = new(model.MCNSignListReply)
  109. res.Page = arg.Page
  110. if count, err = s.dao.McnSignTotal(c, arg); err != nil {
  111. return res, err
  112. }
  113. if count <= 0 {
  114. return
  115. }
  116. res.TotalCount = int(count)
  117. if mcns, err = s.dao.McnSigns(c, arg); err != nil {
  118. return res, err
  119. }
  120. for _, v := range mcns {
  121. v.AttrPermitVal()
  122. signIDs = append(signIDs, v.SignID)
  123. mids = append(mids, v.McnMid)
  124. }
  125. if accsReply, err = s.accGRPC.Infos3(c, &accgrpc.MidsReq{Mids: mids}); err != nil {
  126. log.Error("s.accGRPC.Infos3(%+v) error(%+v)", &accgrpc.MidsReq{Mids: mids}, err)
  127. err = nil
  128. } else {
  129. accInfos = accsReply.Infos
  130. }
  131. if sm, err = s.dao.McnSignPayMap(c, signIDs); err != nil {
  132. return res, err
  133. }
  134. for _, v := range mcns {
  135. if info, ok := accInfos[v.McnMid]; ok {
  136. v.McnName = info.Name
  137. }
  138. v.ContractLink = model.BuildBfsURL(v.ContractLink, s.c.BFS.Key, s.c.BFS.Secret, s.c.BFS.Bucket, model.BfsEasyPath)
  139. v.CompanyLicenseLink = model.BuildBfsURL(v.CompanyLicenseLink, s.c.BFS.Key, s.c.BFS.Secret, s.c.BFS.Bucket, model.BfsEasyPath)
  140. if sp, ok := sm[v.SignID]; ok {
  141. v.SignPayInfo = sp
  142. }
  143. sort.Slice(v.SignPayInfo, func(i int, j int) bool {
  144. return v.SignPayInfo[i].DueDate < v.SignPayInfo[j].DueDate
  145. })
  146. }
  147. res.List = mcns
  148. return res, nil
  149. }
  150. // McnSignOP .
  151. func (s *Service) McnSignOP(c context.Context, arg *model.MCNSignStateOpReq) error {
  152. var (
  153. err error
  154. ok bool
  155. accReply *accgrpc.InfoReply
  156. m *model.MCNSignInfoReply
  157. payInfo []*model.SignPayInfoReply
  158. sm map[int64][]*model.SignPayInfoReply
  159. now = xtime.Time(time.Now().Unix())
  160. state model.MCNSignState
  161. )
  162. if !arg.Action.NotRightAction() {
  163. return ecode.MCNSignUnknownReviewErr
  164. }
  165. if m, err = s.dao.McnSign(c, arg.SignID); err != nil {
  166. return err
  167. }
  168. if m == nil {
  169. return ecode.MCNCSignUnknownInfoErr
  170. }
  171. state = arg.Action.GetState(m.State)
  172. if state == model.MCNSignStateUnKnown {
  173. log.Warn("mcn_sign action(%d) old state(%d) to new err state(-1)", arg.Action, m.State)
  174. return ecode.MCNSignStateFlowErr
  175. }
  176. if m.State.IsOnReviewState(arg.Action) {
  177. return ecode.MCNSignOnlyReviewOpErr
  178. }
  179. if now < m.BeginDate && arg.Action == model.MCNSignActionPass {
  180. state = model.MCNSignStateOnPreOpen
  181. }
  182. if arg.Action != model.MCNSignActionReject {
  183. now = 0
  184. arg.RejectReason = ""
  185. }
  186. if _, err = s.dao.UpMcnSignOP(c, arg.SignID, int8(state), now, arg.RejectReason); err != nil {
  187. return err
  188. }
  189. if accReply, err = s.accGRPC.Info3(c, &accgrpc.MidReq{Mid: m.McnMid}); err != nil {
  190. log.Error("s.accGRPC.Info3(%+v) error(%+v)", &accgrpc.MidReq{Mid: m.McnMid}, err)
  191. err = nil
  192. }
  193. if sm, err = s.dao.McnSignPayMap(c, []int64{arg.SignID}); err != nil {
  194. log.Error("s.dao.McnSignPayMap(%+v) error(%+v)", []int64{arg.SignID}, err)
  195. err = nil
  196. }
  197. if payInfo, ok = sm[arg.SignID]; !ok {
  198. payInfo = nil
  199. }
  200. s.worker.Add(func() {
  201. var name string
  202. if accReply.Info != nil {
  203. name = accReply.Info.Name
  204. }
  205. index := []interface{}{int8(state), arg.SignID, time.Now().Unix(), name}
  206. content := map[string]interface{}{
  207. "sign_id": arg.SignID,
  208. "mcn_mid": m.McnMid,
  209. "mcn_name": name,
  210. "begin_date": m.BeginDate,
  211. "end_date": m.EndDate,
  212. "reject_reason": arg.RejectReason,
  213. "reject_time": now,
  214. "contract_link": m.ContractLink,
  215. "sign_pay_info": payInfo,
  216. "permission": m.Permission,
  217. }
  218. s.AddAuditLog(context.Background(), model.MCNLogBizID, int8(arg.Action), arg.Action.String(), arg.UID, arg.UserName, []int64{m.McnMid}, index, content)
  219. })
  220. s.worker.Add(func() {
  221. s.sendMsg(context.Background(), &model.ArgMsg{MSGType: arg.Action.GetmsgType(state), MIDs: []int64{m.McnMid}, Reason: arg.RejectReason})
  222. })
  223. s.worker.Add(func() {
  224. s.dao.DelMcnSignCache(context.Background(), m.McnMid)
  225. })
  226. return nil
  227. }
  228. // McnUPReviewList .
  229. func (s *Service) McnUPReviewList(c context.Context, arg *model.MCNUPStateReq) (res *model.MCNUPReviewListReply, err error) {
  230. var (
  231. count int64
  232. mids []int64
  233. ups []*model.MCNUPInfoReply
  234. mbi map[int64]*model.UpBaseInfo
  235. accsReply *accgrpc.InfosReply
  236. accInfos map[int64]*accgrpc.Info
  237. )
  238. res = new(model.MCNUPReviewListReply)
  239. res.Page = arg.Page
  240. if count, err = s.dao.McnUpTotal(c, arg); err != nil {
  241. return res, err
  242. }
  243. if count <= 0 {
  244. return
  245. }
  246. res.TotalCount = int(count)
  247. if ups, err = s.dao.McnUps(c, arg); err != nil {
  248. return res, err
  249. }
  250. for _, v := range ups {
  251. v.AttrPermitVal()
  252. mids = append(mids, v.McnMid)
  253. mids = append(mids, v.UpMid)
  254. }
  255. if mbi, err = s.dao.UpBaseInfoMap(c, mids); err != nil {
  256. return res, err
  257. }
  258. if accsReply, err = s.accGRPC.Infos3(c, &accgrpc.MidsReq{Mids: mids}); err != nil {
  259. log.Error("s.accGRPC.Infos3(%+v) error(%+v)", &accgrpc.MidsReq{Mids: mids}, err)
  260. err = nil
  261. } else {
  262. accInfos = accsReply.Infos
  263. }
  264. for _, v := range ups {
  265. if up, ok := mbi[v.McnMid]; ok {
  266. v.FansCount = up.FansCount
  267. v.ActiveTid = up.ActiveTid
  268. }
  269. if info, ok := accInfos[v.McnMid]; ok {
  270. v.McnName = info.Name
  271. }
  272. if info, ok := accInfos[v.UpMid]; ok {
  273. v.UpName = info.Name
  274. }
  275. v.UpAuthLink = model.BuildBfsURL(v.UpAuthLink, s.c.BFS.Key, s.c.BFS.Secret, s.c.BFS.Bucket, model.BfsEasyPath)
  276. v.ContractLink = model.BuildBfsURL(v.ContractLink, s.c.BFS.Key, s.c.BFS.Secret, s.c.BFS.Bucket, model.BfsEasyPath)
  277. }
  278. res.List = ups
  279. return res, nil
  280. }
  281. // McnUPOP .
  282. func (s *Service) McnUPOP(c context.Context, arg *model.MCNUPStateOpReq) error {
  283. var (
  284. err error
  285. upName, mcnName string
  286. accsReply *accgrpc.InfosReply
  287. accInfos map[int64]*accgrpc.Info
  288. up *model.MCNUPInfoReply
  289. m *model.MCNSignInfoReply
  290. now = time.Now()
  291. xnow = xtime.Time(now.Unix())
  292. date = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
  293. state model.MCNUPState
  294. )
  295. state = arg.Action.GetState()
  296. if state == model.MCNUPStateUnKnown {
  297. log.Warn("mcn_up action(%d) to new err state(-1)", arg.Action)
  298. return ecode.MCNSignStateFlowErr
  299. }
  300. if !arg.Action.NotRightAction() {
  301. return ecode.MCNUpUnknownReviewErr
  302. }
  303. if arg.Action.NoRejectState() {
  304. xnow = 0
  305. arg.RejectReason = ""
  306. }
  307. if up, err = s.dao.McnUp(c, arg.SignUpID); err != nil {
  308. return err
  309. }
  310. if up == nil {
  311. return ecode.MCNCUpUnknownInfoErr
  312. }
  313. if m, err = s.dao.McnSign(c, up.SignID); err != nil {
  314. return err
  315. }
  316. if m.State != model.MCNSignStateOnSign && arg.Action.NoRejectState() {
  317. return ecode.MCNUpPassOnEffectSign
  318. }
  319. if up.State.IsOnReviewState() {
  320. return ecode.MCNUpOnlyReviewOpErr
  321. }
  322. if up.BeginDate.Time().After(date) && state == model.MCNUPStateOnSign {
  323. state = model.MCNUPStateOnPreOpen
  324. }
  325. if _, err = s.dao.UpMcnUpOP(c, arg.SignUpID, int8(state), xnow, arg.RejectReason); err != nil {
  326. return err
  327. }
  328. if accsReply, err = s.accGRPC.Infos3(c, &accgrpc.MidsReq{Mids: []int64{up.McnMid, up.UpMid}}); err != nil {
  329. log.Error("s.accGRPC.Infos3(%+v) error(%+v)", &accgrpc.MidsReq{Mids: []int64{up.McnMid, up.UpMid}}, err)
  330. err = nil
  331. } else {
  332. accInfos = accsReply.Infos
  333. }
  334. if info, ok := accInfos[up.McnMid]; ok {
  335. mcnName = info.Name
  336. }
  337. if info, ok := accInfos[up.UpMid]; ok {
  338. upName = info.Name
  339. }
  340. if arg.Action == model.MCNUPActionPass {
  341. s.dao.UpMcnUpsRecommendOP(c, []int64{up.UpMid}, model.MCNUPRecommendStateDel)
  342. }
  343. s.worker.Add(func() {
  344. index := []interface{}{int8(state), arg.SignUpID, up.McnMid, mcnName, upName}
  345. content := map[string]interface{}{
  346. "sign_up_id": arg.SignUpID,
  347. "sign_id": up.SignID,
  348. "mcn_mid": up.McnMid,
  349. "up_mid": up.UpMid,
  350. "begin_date": up.BeginDate,
  351. "end_date": up.EndDate,
  352. "contract_link": up.ContractLink,
  353. "up_auth_link": up.UpAuthLink,
  354. "reject_reason": arg.RejectReason,
  355. "reject_time": now,
  356. "permission": up.Permission,
  357. }
  358. s.AddAuditLog(context.Background(), model.MCNLogBizID, int8(arg.Action), arg.Action.String(), arg.UID, arg.UserName, []int64{up.UpMid}, index, content)
  359. })
  360. s.worker.Add(func() {
  361. argMsg := &model.ArgMsg{
  362. MSGType: arg.Action.GetmsgType(true),
  363. MIDs: []int64{up.McnMid},
  364. Reason: arg.RejectReason,
  365. CompanyName: m.CompanyName,
  366. McnName: mcnName,
  367. McnMid: up.McnMid,
  368. UpName: upName,
  369. UpMid: up.UpMid,
  370. }
  371. s.sendMsg(context.Background(), argMsg)
  372. argMsg.MSGType = arg.Action.GetmsgType(false)
  373. argMsg.MIDs = []int64{up.UpMid}
  374. s.sendMsg(context.Background(), argMsg)
  375. })
  376. return nil
  377. }
  378. // McnPermitOP .
  379. func (s *Service) McnPermitOP(c context.Context, arg *model.MCNSignPermissionReq) (err error) {
  380. var (
  381. open, closed []string
  382. m *model.MCNSignInfoReply
  383. )
  384. if m, err = s.dao.McnSign(c, arg.SignID); err != nil {
  385. return err
  386. }
  387. if m == nil {
  388. return ecode.MCNCSignUnknownInfoErr
  389. }
  390. m.AttrPermitVal()
  391. arg.AttrPermitSet()
  392. open, closed = s.getPermitOpenOrClosed(arg.Permission, m.Permission)
  393. if len(open) == 0 && len(closed) == 0 {
  394. return
  395. }
  396. if _, err = s.dao.UpMCNPermission(c, arg.SignID, arg.Permission); err != nil {
  397. return
  398. }
  399. s.worker.Add(func() {
  400. index := []interface{}{arg.SignID}
  401. content := map[string]interface{}{
  402. "sign_id": arg.SignID,
  403. "mcn_mid": m.McnMid,
  404. "state": m.State,
  405. "begin_date": m.BeginDate,
  406. "end_date": m.EndDate,
  407. "permission": arg.Permission,
  408. }
  409. s.AddAuditLog(context.Background(), model.MCNLogBizID, int8(model.MCNSignActionPermit), model.MCNSignActionPermit.String(), arg.UID, arg.UserName, []int64{m.McnMid}, index, content)
  410. })
  411. s.worker.Add(func() {
  412. argMsg := &model.ArgMsg{
  413. MIDs: []int64{m.McnMid},
  414. }
  415. if len(open) > 0 {
  416. argMsg.MSGType = model.McnPermissionOpen
  417. argMsg.Permission = strings.Join(open, "、")
  418. s.sendMsg(context.Background(), argMsg)
  419. }
  420. if len(closed) > 0 {
  421. argMsg.MSGType = model.McnPermissionClosed
  422. argMsg.Permission = strings.Join(closed, "、")
  423. s.sendMsg(context.Background(), argMsg)
  424. }
  425. })
  426. s.worker.Add(func() {
  427. s.dao.DelMcnSignCache(context.Background(), m.McnMid)
  428. })
  429. return
  430. }
  431. func (s *Service) getPermitOpenOrClosed(a, b uint32) (open, closed []string) {
  432. for permit := range model.PermitMap {
  433. var c, d = model.AttrVal(a, uint(permit)), model.AttrVal(b, uint(permit))
  434. if c == d {
  435. continue
  436. }
  437. if c > d {
  438. open = append(open, permit.String())
  439. } else {
  440. closed = append(closed, permit.String())
  441. }
  442. }
  443. return
  444. }
  445. func (s *Service) getUpPermitString(permission uint32) (ps []string) {
  446. for permit := range model.PermitMap {
  447. var p = model.AttrVal(permission, uint(permit))
  448. if p <= 0 {
  449. continue
  450. }
  451. ps = append(ps, permit.String())
  452. }
  453. return
  454. }
  455. // McnUPPermitList .
  456. func (s *Service) McnUPPermitList(c context.Context, arg *model.MCNUPPermitStateReq) (res *model.McnUpPermitApplyListReply, err error) {
  457. var (
  458. count int64
  459. upMids, mids, tids []int64
  460. accsReply *accgrpc.InfosReply
  461. accInfos map[int64]*accgrpc.Info
  462. mbi map[int64]*model.UpBaseInfo
  463. ms []*model.McnUpPermissionApply
  464. )
  465. res = new(model.McnUpPermitApplyListReply)
  466. res.Page = arg.Page
  467. if count, err = s.dao.McnUpPermitTotal(c, arg); err != nil {
  468. return
  469. }
  470. if count <= 0 {
  471. return
  472. }
  473. res.TotalCount = int(count)
  474. if ms, err = s.dao.McnUpPermits(c, arg); err != nil {
  475. return
  476. }
  477. for _, m := range ms {
  478. upMids = append(upMids, m.UpMid)
  479. mids = append(mids, m.UpMid)
  480. mids = append(mids, m.McnMid)
  481. }
  482. if mbi, err = s.dao.UpBaseInfoMap(c, upMids); err != nil {
  483. return
  484. }
  485. for _, v := range mbi {
  486. tids = append(tids, int64(v.ActiveTid))
  487. }
  488. for _, m := range ms {
  489. if bi, ok := mbi[m.UpMid]; ok {
  490. m.ActiveTID = bi.ActiveTid
  491. m.FansCount = bi.FansCount
  492. }
  493. }
  494. if len(mids) > 0 {
  495. if accsReply, err = s.accGRPC.Infos3(c, &accgrpc.MidsReq{Mids: mids}); err != nil {
  496. log.Error("s.accGRPC.Infos3(%+v) err(%v)", mids, err)
  497. err = nil
  498. } else {
  499. accInfos = accsReply.Infos
  500. }
  501. }
  502. tpNames := s.videoup.GetTidName(tids)
  503. for _, v := range ms {
  504. v.AttrPermitVal()
  505. if info, ok := accInfos[v.McnMid]; ok {
  506. v.McnName = info.Name
  507. }
  508. if info, ok := accInfos[v.UpMid]; ok {
  509. v.UpName = info.Name
  510. }
  511. if tyName, ok := tpNames[int64(v.ActiveTID)]; ok {
  512. v.TypeName = tyName
  513. } else {
  514. v.TypeName = model.DefaultTyName
  515. }
  516. }
  517. res.List = ms
  518. return
  519. }
  520. // McnUPPermitOP .
  521. func (s *Service) McnUPPermitOP(c context.Context, arg *model.MCNUPPermitOPReq) (err error) {
  522. var (
  523. tx *xsql.Tx
  524. ps []string
  525. accReply *accgrpc.InfoReply
  526. now = xtime.Time(time.Now().Unix())
  527. m *model.McnUpPermissionApply
  528. )
  529. if !arg.Action.NotRightAction() {
  530. return ecode.MCNSignUnknownReviewErr
  531. }
  532. if m, err = s.dao.McnUpPermit(c, arg.ID); err != nil {
  533. return err
  534. }
  535. if m == nil {
  536. return ecode.MCNUpAbnormalDataErr
  537. }
  538. state := arg.Action.GetState()
  539. if state == model.MCNUPPermissionStateUnKnown {
  540. log.Warn("mcn-up permit action(%d) old state(%d) to new err state(-1)", arg.Action, m.State)
  541. return ecode.MCNUpPermitStateFlowErr
  542. }
  543. if tx, err = s.dao.BeginTran(c); err != nil {
  544. return err
  545. }
  546. defer func() {
  547. if err != nil {
  548. tx.Rollback()
  549. } else {
  550. tx.Commit()
  551. }
  552. }()
  553. if arg.Action != model.MCNUPPermissionActionFail {
  554. now = 0
  555. arg.RejectReason = ""
  556. }
  557. m.State = state
  558. m.RejectReason = arg.RejectReason
  559. m.RejectTime = now
  560. m.AdminName = arg.UserName
  561. m.AdminID = arg.UID
  562. if _, err = s.dao.TxUpPermitApplyOP(tx, m); err != nil {
  563. return err
  564. }
  565. if state == model.MCNUPPermissionStatePass {
  566. if _, err = s.dao.TxMcnUpPermitOP(tx, m.SignID, m.McnMid, m.UpMid, m.NewPermission, m.UpAuthLink); err != nil {
  567. return err
  568. }
  569. ps = s.getUpPermitString(m.NewPermission)
  570. }
  571. if accReply, err = s.accGRPC.Info3(c, &accgrpc.MidReq{Mid: m.UpMid}); err != nil {
  572. log.Error("s.accGRPC.Info3(%+v) error(%+v)", &accgrpc.MidReq{Mid: m.McnMid}, err)
  573. err = nil
  574. }
  575. var name string
  576. if accReply.Info != nil {
  577. name = accReply.Info.Name
  578. }
  579. s.worker.Add(func() {
  580. argMsg := &model.ArgMsg{
  581. MIDs: []int64{m.McnMid},
  582. }
  583. if state == model.MCNUPPermissionStatePass {
  584. argMsg.UpName = name
  585. argMsg.MSGType = model.McnOperAgreeChangePermit
  586. argMsg.Permission = strings.Join(ps, "、")
  587. } else {
  588. argMsg.UpName = name
  589. argMsg.MSGType = model.McnOperNotAgreeChangePermit
  590. argMsg.Reason = m.RejectReason
  591. }
  592. s.sendMsg(context.Background(), argMsg)
  593. })
  594. s.worker.Add(func() {
  595. s.dao.DelMcnUpperCache(context.Background(), m.SignID, m.UpMid)
  596. })
  597. return
  598. }
  599. // MCNList .
  600. func (s *Service) MCNList(c context.Context, arg *model.MCNListReq) (res *model.MCNListReply, err error) {
  601. var (
  602. count int64
  603. signIDs, mids []int64
  604. mcns []*model.MCNListOne
  605. accsReply *accgrpc.InfosReply
  606. accInfos map[int64]*accgrpc.Info
  607. payInfos map[int64][]*model.SignPayInfoReply
  608. )
  609. res = new(model.MCNListReply)
  610. res.Page = arg.Page
  611. count, err = s.dao.MCNListTotal(c, arg)
  612. if err != nil {
  613. return
  614. }
  615. if count <= 0 {
  616. return
  617. }
  618. res.TotalCount = int(count)
  619. if mcns, signIDs, mids, err = s.dao.MCNList(c, arg); err != nil {
  620. return
  621. }
  622. if len(signIDs) <= 0 {
  623. return
  624. }
  625. if accsReply, err = s.accGRPC.Infos3(c, &accgrpc.MidsReq{Mids: mids}); err != nil {
  626. log.Error("s.accGRPC.Infos3(%+v) err(%v)", mids, err)
  627. err = nil
  628. } else {
  629. accInfos = accsReply.Infos
  630. }
  631. if payInfos, err = s.dao.MCNPayInfos(c, signIDs); err != nil {
  632. return
  633. }
  634. for k, v := range mcns {
  635. v.AttrPermitVal()
  636. mcns[k].PayInfos = payInfos[v.ID]
  637. if info, ok := accInfos[v.MCNMID]; ok {
  638. v.MCNName = info.Name
  639. }
  640. }
  641. res.List = mcns
  642. return
  643. }
  644. // MCNPayEdit .
  645. func (s *Service) MCNPayEdit(c context.Context, arg *model.MCNPayEditReq) error {
  646. if _, err := s.dao.UpMCNPay(c, arg); err != nil {
  647. return err
  648. }
  649. s.worker.Add(func() {
  650. index := []interface{}{arg.ID, arg.MCNMID}
  651. content := map[string]interface{}{
  652. "id": arg.ID,
  653. "mcn_mid": arg.MCNMID,
  654. "sign_id": arg.SignID,
  655. "due_date": arg.DueDate,
  656. "pay_value": arg.PayValue,
  657. }
  658. s.AddAuditLog(context.Background(), model.MCNPayDateLogBizID, int8(model.MCNSignCycleActionUp), model.MCNSignCycleActionUp.String(), arg.UID, arg.UserName, []int64{arg.SignID}, index, content)
  659. })
  660. s.worker.Add(func() {
  661. s.dao.DelMcnSignCache(context.Background(), arg.MCNMID)
  662. })
  663. return nil
  664. }
  665. // MCNPayStateEdit .
  666. func (s *Service) MCNPayStateEdit(c context.Context, arg *model.MCNPayStateEditReq) error {
  667. var (
  668. err error
  669. PayInfo *model.SignPayInfoReply
  670. )
  671. if _, err = s.dao.UpMCNPayState(c, arg); err != nil {
  672. return err
  673. }
  674. if PayInfo, err = s.dao.MCNPayInfo(c, arg); err != nil {
  675. log.Error("s.dao.MCNPayInfo(%+v) err(%v)", arg, err)
  676. err = nil
  677. }
  678. s.worker.Add(func() {
  679. index := []interface{}{arg.ID, arg.MCNMID}
  680. content := map[string]interface{}{
  681. "id": arg.ID,
  682. "mcn_mid": arg.MCNMID,
  683. "sign_id": arg.SignID,
  684. "due_date": PayInfo.DueDate,
  685. "pay_value": PayInfo.PayValue,
  686. "state": arg.State,
  687. }
  688. s.AddAuditLog(context.Background(), model.MCNPayDateLogBizID, int8(model.MCNSignCycleActionUp), model.MCNSignCycleActionUp.String(), arg.UID, arg.UserName, []int64{arg.SignID}, index, content)
  689. })
  690. s.worker.Add(func() {
  691. s.dao.DelMcnSignCache(context.Background(), arg.MCNMID)
  692. })
  693. return err
  694. }
  695. // MCNStateEdit .
  696. func (s *Service) MCNStateEdit(c context.Context, arg *model.MCNStateEditReq) error {
  697. if arg.Action != model.MCNSignActionBlock && arg.Action != model.MCNSignActionClear && arg.Action != model.MCNSignActionRestore {
  698. return ecode.RequestErr
  699. }
  700. var (
  701. err error
  702. ms *model.MCNSignInfoReply
  703. )
  704. if ms, err = s.dao.McnSign(c, arg.ID); err != nil {
  705. return err
  706. }
  707. arg.State = arg.Action.GetState(ms.State)
  708. if arg.State == model.MCNSignStateUnKnown {
  709. log.Warn("mcn_sign action(%d) old state(%d) to new err state(-1)", arg.Action, ms.State)
  710. return ecode.MCNSignStateFlowErr
  711. }
  712. if _, err = s.dao.UpMCNState(c, arg); err != nil {
  713. return err
  714. }
  715. s.worker.Add(func() {
  716. index := []interface{}{arg.State, arg.ID}
  717. content := map[string]interface{}{
  718. "sign_id": arg.ID,
  719. "mcn_mid": ms.McnMid,
  720. "begin_date": ms.BeginDate,
  721. "end_date": ms.EndDate,
  722. "contract_link": ms.ContractLink,
  723. "company_name": ms.CompanyName,
  724. "company_license_id": ms.CompanyLicenseID,
  725. "company_license_link": ms.CompanyLicenseLink,
  726. "contact_title": ms.ContactTitle,
  727. "contact_idcard": ms.ContactIdcard,
  728. "contact_phone": ms.ContactPhone,
  729. "contact_name": ms.ContactName,
  730. "state": arg.State,
  731. "permission": ms.Permission,
  732. }
  733. s.AddAuditLog(context.Background(), model.MCNLogBizID, int8(arg.Action), arg.Action.String(), arg.UID, arg.UserName, []int64{arg.MCNMID}, index, content)
  734. })
  735. s.worker.Add(func() {
  736. s.dao.DelMcnSignCache(context.Background(), arg.MCNMID)
  737. })
  738. s.worker.Add(func() {
  739. s.sendMsg(context.Background(), &model.ArgMsg{MSGType: arg.Action.GetmsgType(ms.State), MIDs: []int64{arg.MCNMID}})
  740. })
  741. return err
  742. }
  743. // MCNRenewal .
  744. func (s *Service) MCNRenewal(c context.Context, arg *model.MCNRenewalReq) (err error) {
  745. var (
  746. signID int64
  747. tx *xsql.Tx
  748. stime, etime time.Time
  749. m *model.MCNSignInfoReply
  750. ms = &model.MCNSign{}
  751. ups = make([]*model.MCNUP, 0)
  752. )
  753. if stime, err = time.ParseInLocation(model.TimeFormatDay, arg.BeginDate, time.Local); err != nil {
  754. err = errors.Errorf("time.ParseInLocation(%s) error(%+v)", arg.BeginDate, err)
  755. return err
  756. }
  757. if etime, err = time.ParseInLocation(model.TimeFormatDay, arg.EndDate, time.Local); err != nil {
  758. err = errors.Errorf("time.ParseInLocation(%s) error(%+v)", arg.EndDate, err)
  759. return err
  760. }
  761. if m, err = s.dao.McnSignByMCNMID(c, arg.MCNMID); err != nil {
  762. return err
  763. }
  764. if arg.ID != m.SignID {
  765. return ecode.MCNRenewalAlreadyErr
  766. }
  767. if stime.Before(m.EndDate.Time()) || etime.Before(stime) {
  768. return ecode.MCNRenewalDateErr
  769. }
  770. if m.State.IsRenewalState() && m.EndDate.Time().AddDate(0, 0, 1).After(time.Now()) && m.EndDate.Time().AddDate(0, 0, -30).Before(time.Now()) {
  771. return ecode.MCNRenewalNotInRangeErr
  772. }
  773. if tx, err = s.dao.BeginTran(c); err != nil {
  774. return err
  775. }
  776. defer func() {
  777. if err != nil {
  778. tx.Rollback()
  779. } else {
  780. tx.Commit()
  781. }
  782. }()
  783. arg.AttrPermitSet()
  784. ms.MCNMID = m.McnMid
  785. ms.CompanyName = m.CompanyName
  786. ms.CompanyLicenseID = m.CompanyLicenseID
  787. ms.CompanyLicenseLink = m.CompanyLicenseLink
  788. ms.ContractLink = arg.ContractLink
  789. ms.ContactName = m.ContactName
  790. ms.ContactTitle = m.ContactTitle
  791. ms.ContactIdcard = m.ContactIdcard
  792. ms.ContactPhone = m.ContactPhone
  793. ms.BeginDate = xtime.Time(stime.Unix())
  794. ms.EndDate = xtime.Time(etime.Unix())
  795. ms.Permission = arg.Permission
  796. if signID, err = s.dao.TxAddMCNRenewal(tx, ms); err != nil {
  797. return err
  798. }
  799. if len(arg.SignPayInfo) > 0 {
  800. if err = s.dao.TxAddMCNPays(tx, signID, m.McnMid, arg.SignPayInfo); err != nil {
  801. return err
  802. }
  803. }
  804. if ups, err = s.dao.TxMCNRenewalUPs(tx, arg.ID, m.McnMid); err != nil {
  805. return err
  806. }
  807. if len(ups) > 0 {
  808. if err = s.dao.TxAddMCNUPs(tx, signID, m.McnMid, ups); err != nil {
  809. return err
  810. }
  811. }
  812. s.worker.Add(func() {
  813. index := []interface{}{int8(model.MCNSignStateOnSign), signID}
  814. content := map[string]interface{}{
  815. "sign_id": signID,
  816. "mcn_mid": m.McnMid,
  817. "begin_date": ms.BeginDate,
  818. "end_date": ms.EndDate,
  819. "contract_link": m.ContractLink,
  820. "company_name": m.CompanyName,
  821. "company_license_id": m.CompanyLicenseID,
  822. "company_license_link": m.CompanyLicenseLink,
  823. "contact_title": m.ContactTitle,
  824. "contact_idcard": m.ContactIdcard,
  825. "contact_phone": m.ContactPhone,
  826. "permission": m.Permission,
  827. }
  828. s.AddAuditLog(context.Background(), model.MCNLogBizID, int8(model.MCNSignStateOnSign), model.MCNSignStateOnSign.String(), arg.UID, arg.UserName, []int64{arg.MCNMID}, index, content)
  829. })
  830. s.worker.Add(func() {
  831. index := []interface{}{arg.MCNMID}
  832. content := map[string]interface{}{
  833. "sign_id": signID,
  834. "mcn_mid": arg.MCNMID,
  835. "sign_pay_info": arg.SignPayInfo,
  836. }
  837. s.AddAuditLog(context.Background(), model.MCNPayDateLogBizID, int8(model.MCNSignCycleActionAdd), model.MCNSignCycleActionAdd.String(), arg.UID, arg.UserName, []int64{signID}, index, content)
  838. })
  839. s.worker.Add(func() {
  840. s.dao.DelMcnSignCache(context.Background(), arg.MCNMID)
  841. })
  842. s.worker.Add(func() {
  843. s.sendMsg(context.Background(), &model.ArgMsg{MSGType: model.McnRenewcontract, MIDs: []int64{arg.MCNMID}})
  844. })
  845. return
  846. }
  847. // MCNInfo .
  848. func (s *Service) MCNInfo(c context.Context, arg *model.MCNInfoReq) (res *model.MCNInfoReply, err error) {
  849. var accReply *accgrpc.InfoReply
  850. if res, err = s.dao.MCNInfo(c, arg); err != nil || res == nil {
  851. return
  852. }
  853. if accReply, err = s.accGRPC.Info3(c, &accgrpc.MidReq{Mid: res.MCNMID}); err != nil {
  854. log.Error("s.accGRPC.Infos3(%+v) err(%v)", arg, err)
  855. err = nil
  856. }
  857. if accReply.Info != nil {
  858. res.MCNName = accReply.Info.Name
  859. }
  860. res.CompanyLicenseLink = model.BuildBfsURL(res.CompanyLicenseLink, s.c.BFS.Key, s.c.BFS.Secret, s.c.BFS.Bucket, model.BfsEasyPath)
  861. res.ContractLink = model.BuildBfsURL(res.ContractLink, s.c.BFS.Key, s.c.BFS.Secret, s.c.BFS.Bucket, model.BfsEasyPath)
  862. return
  863. }
  864. // MCNUPList .
  865. func (s *Service) MCNUPList(c context.Context, arg *model.MCNUPListReq) (res *model.MCNUPListReply, err error) {
  866. var (
  867. count int64
  868. upMIDs, tids []int64
  869. tpNames map[int64]string
  870. mcn *model.MCNSignInfoReply
  871. mcnUPs []*model.MCNUPInfoReply
  872. accsReply *accgrpc.InfosReply
  873. accInfos map[int64]*accgrpc.Info
  874. )
  875. res = new(model.MCNUPListReply)
  876. res.Page = arg.Page
  877. if count, err = s.dao.MCNUPListTotal(c, arg); err != nil {
  878. return
  879. }
  880. if count <= 0 {
  881. return
  882. }
  883. res.TotalCount = int(count)
  884. if mcnUPs, err = s.dao.MCNUPList(c, arg); err != nil {
  885. return
  886. }
  887. if mcn, err = s.dao.McnSign(c, arg.SignID); err != nil {
  888. log.Error("s.dao.McnSign(%d) err(%v)", arg.SignID, err)
  889. err = nil
  890. }
  891. for _, v := range mcnUPs {
  892. if mcn != nil {
  893. v.Permission = v.Permission & mcn.Permission
  894. }
  895. v.AttrPermitVal()
  896. upMIDs = append(upMIDs, v.UpMid)
  897. tids = append(tids, int64(v.ActiveTid))
  898. }
  899. if accsReply, err = s.accGRPC.Infos3(c, &accgrpc.MidsReq{Mids: upMIDs}); err != nil {
  900. log.Error("s.accGRPC.Infos3(%+v) err(%v)", upMIDs, err)
  901. err = nil
  902. } else {
  903. accInfos = accsReply.Infos
  904. }
  905. tpNames = s.videoup.GetTidName(tids)
  906. for _, v := range mcnUPs {
  907. if info, ok := accInfos[v.UpMid]; ok {
  908. v.UpName = info.Name
  909. }
  910. if tyName, ok := tpNames[int64(v.ActiveTid)]; ok {
  911. v.TpName = tyName
  912. } else {
  913. v.TpName = model.DefaultTyName
  914. }
  915. v.UpAuthLink = model.BuildBfsURL(v.UpAuthLink, s.c.BFS.Key, s.c.BFS.Secret, s.c.BFS.Bucket, model.BfsEasyPath)
  916. v.ContractLink = model.BuildBfsURL(v.ContractLink, s.c.BFS.Key, s.c.BFS.Secret, s.c.BFS.Bucket, model.BfsEasyPath)
  917. }
  918. res.List = mcnUPs
  919. return
  920. }
  921. // MCNUPStateEdit .
  922. func (s *Service) MCNUPStateEdit(c context.Context, arg *model.MCNUPStateEditReq) error {
  923. if arg.Action != model.MCNUPActionFreeze && arg.Action != model.MCNUPActionRelease && arg.Action != model.MCNUPActionRestore {
  924. return ecode.RequestErr
  925. }
  926. var (
  927. err error
  928. up *model.MCNUPInfoReply
  929. m *model.MCNSignInfoReply
  930. upName, mcnName string
  931. accsReply *accgrpc.InfosReply
  932. accInfos map[int64]*accgrpc.Info
  933. )
  934. arg.State = arg.Action.GetState()
  935. if arg.State == model.MCNUPStateUnKnown {
  936. log.Warn("mcn_up action(%d) to new err state(-1)", arg.Action)
  937. return ecode.MCNSignStateFlowErr
  938. }
  939. if _, err = s.dao.UpMCNUPState(c, arg); err != nil {
  940. return err
  941. }
  942. if up, err = s.dao.McnUp(c, arg.ID); err != nil {
  943. log.Error("s.dao.McnUp(%v) err(%v)", arg.ID, err)
  944. }
  945. if m, err = s.dao.McnSign(c, up.SignID); err != nil {
  946. log.Error("s.dao.McnSign error(%+v)", err)
  947. err = nil
  948. }
  949. if accsReply, err = s.accGRPC.Infos3(c, &accgrpc.MidsReq{Mids: []int64{up.McnMid, up.UpMid}}); err != nil {
  950. log.Error("s.accGRPC.Infos3(%+v) error(%+v)", &accgrpc.MidsReq{Mids: []int64{up.McnMid, up.UpMid}}, err)
  951. err = nil
  952. } else {
  953. accInfos = accsReply.Infos
  954. }
  955. if info, ok := accInfos[up.McnMid]; ok {
  956. mcnName = info.Name
  957. }
  958. if info, ok := accInfos[up.UpMid]; ok {
  959. upName = info.Name
  960. }
  961. s.worker.Add(func() {
  962. index := []interface{}{int8(arg.State), arg.ID, up.McnMid, up.SignID}
  963. content := map[string]interface{}{
  964. "sign_up_id": arg.ID,
  965. "sign_id": up.SignID,
  966. "mcn_mid": up.McnMid,
  967. "up_mid": up.UpMid,
  968. "begin_date": up.BeginDate,
  969. "end_date": up.EndDate,
  970. "contract_link": up.ContractLink,
  971. "up_auth_link": up.UpAuthLink,
  972. "state": arg.State,
  973. "reject_reason": up.RejectReason,
  974. "reject_time": up.RejectTime,
  975. }
  976. s.AddAuditLog(context.Background(), model.MCNLogBizID, int8(arg.Action), arg.Action.String(), arg.UID, arg.UserName, []int64{arg.UPMID}, index, content)
  977. })
  978. s.worker.Add(func() {
  979. argMsg := &model.ArgMsg{
  980. MSGType: arg.Action.GetmsgType(true),
  981. MIDs: []int64{up.McnMid},
  982. CompanyName: m.CompanyName,
  983. McnName: mcnName,
  984. McnMid: up.McnMid,
  985. UpName: upName,
  986. UpMid: up.UpMid,
  987. }
  988. s.sendMsg(context.Background(), argMsg)
  989. argMsg.MSGType = arg.Action.GetmsgType(false)
  990. argMsg.MIDs = []int64{up.UpMid}
  991. s.sendMsg(context.Background(), argMsg)
  992. })
  993. return nil
  994. }
  995. // MCNCheatList .
  996. func (s *Service) MCNCheatList(c context.Context, arg *model.MCNCheatListReq) (res *model.MCNCheatListReply, err error) {
  997. var (
  998. count int64
  999. mids []int64
  1000. mcnCheats []*model.MCNCheatReply
  1001. accsReply *accgrpc.InfosReply
  1002. accInfos map[int64]*accgrpc.Info
  1003. )
  1004. res = new(model.MCNCheatListReply)
  1005. res.Page = arg.Page
  1006. if count, err = s.dao.MCNCheatListTotal(c, arg); err != nil {
  1007. return
  1008. }
  1009. if count <= 0 {
  1010. return
  1011. }
  1012. res.TotalCount = int(count)
  1013. if mcnCheats, mids, err = s.dao.MCNCheatList(c, arg); err != nil {
  1014. return
  1015. }
  1016. if len(mcnCheats) <= 0 || len(mids) <= 0 {
  1017. return
  1018. }
  1019. if accsReply, err = s.accGRPC.Infos3(c, &accgrpc.MidsReq{Mids: mids}); err != nil {
  1020. log.Error("s.accGRPC.Infos3(%+v) err(%v)", mids, err)
  1021. err = nil
  1022. } else {
  1023. accInfos = accsReply.Infos
  1024. }
  1025. for _, v := range mcnCheats {
  1026. if info, ok := accInfos[v.UpMID]; ok {
  1027. v.UpName = info.Name
  1028. }
  1029. if info, ok := accInfos[v.MCNMID]; ok {
  1030. v.MCNName = info.Name
  1031. }
  1032. }
  1033. res.List = mcnCheats
  1034. return
  1035. }
  1036. // MCNCheatUPList .
  1037. func (s *Service) MCNCheatUPList(c context.Context, arg *model.MCNCheatUPListReq) (res *model.MCNCheatUPListReply, err error) {
  1038. var (
  1039. count int64
  1040. cheatUPInfos []*model.MCNCheatUPReply
  1041. )
  1042. res = new(model.MCNCheatUPListReply)
  1043. res.Page = arg.Page
  1044. if count, err = s.dao.MCNCheatUPListTotal(c, arg); err != nil {
  1045. return
  1046. }
  1047. if count <= 0 {
  1048. return
  1049. }
  1050. res.TotalCount = int(count)
  1051. if cheatUPInfos, err = s.dao.MCNCheatUPList(c, arg); err != nil {
  1052. return
  1053. }
  1054. var mids []int64
  1055. for _, v := range cheatUPInfos {
  1056. mids = append(mids, v.MCNMID)
  1057. }
  1058. mids = up.SliceUnique(mids)
  1059. var (
  1060. accInfos map[int64]*accgrpc.Info
  1061. accsReply *accgrpc.InfosReply
  1062. )
  1063. if accsReply, err = s.accGRPC.Infos3(c, &accgrpc.MidsReq{Mids: mids}); err != nil {
  1064. log.Error("s.accGRPC.Infos3(%+v) err(%v)", mids, err)
  1065. err = nil
  1066. } else {
  1067. accInfos = accsReply.Infos
  1068. }
  1069. for _, v := range cheatUPInfos {
  1070. if info, ok := accInfos[v.MCNMID]; ok {
  1071. v.MCNName = info.Name
  1072. }
  1073. }
  1074. res.List = cheatUPInfos
  1075. return
  1076. }
  1077. // MCNImportUPInfo .
  1078. func (s *Service) MCNImportUPInfo(c context.Context, arg *model.MCNImportUPInfoReq) (res *model.MCNImportUPInfoReply, err error) {
  1079. var profileRepley *accgrpc.ProfileReply
  1080. if res, err = s.dao.MCNImportUPInfo(c, arg); err != nil {
  1081. return
  1082. }
  1083. res.UpMID = arg.UPMID
  1084. if profileRepley, err = s.accGRPC.Profile3(c, &accgrpc.MidReq{Mid: arg.UPMID}); err != nil {
  1085. log.Error("s.accGRPC.Profile3(%d) err(%v)", arg.UPMID, err)
  1086. err = nil
  1087. }
  1088. if profileRepley.Profile != nil {
  1089. res.UpName = profileRepley.Profile.Name
  1090. res.JoinTime = profileRepley.Profile.JoinTime
  1091. }
  1092. return
  1093. }
  1094. // MCNImportUPRewardSign .
  1095. func (s *Service) MCNImportUPRewardSign(c context.Context, arg *model.MCNImportUPRewardSignReq) (err error) {
  1096. _, err = s.dao.UpMCNImportUPRewardSign(c, arg)
  1097. return
  1098. }
  1099. // MCNIncreaseList .
  1100. func (s *Service) MCNIncreaseList(c context.Context, arg *model.MCNIncreaseListReq) (res *model.MCNIncreaseListReply, err error) {
  1101. var (
  1102. count int64
  1103. increaseDatas []*model.MCNIncreaseReply
  1104. )
  1105. res = new(model.MCNIncreaseListReply)
  1106. res.Page = arg.Page
  1107. if count, err = s.dao.MCNIncreaseListTotal(c, arg); err != nil {
  1108. return
  1109. }
  1110. if count <= 0 {
  1111. return
  1112. }
  1113. res.TotalCount = int(count)
  1114. if increaseDatas, err = s.dao.MCNIncreaseList(c, arg); err != nil {
  1115. return
  1116. }
  1117. res.List = increaseDatas
  1118. return
  1119. }