server.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. // Package server generate by warden_gen
  2. package server
  3. import (
  4. "context"
  5. "encoding/json"
  6. "net"
  7. colv1 "go-common/app/service/main/coupon/api"
  8. col "go-common/app/service/main/coupon/model"
  9. v1 "go-common/app/service/main/vip/api"
  10. "go-common/app/service/main/vip/model"
  11. service "go-common/app/service/main/vip/service"
  12. "go-common/library/log"
  13. "go-common/library/net/rpc/warden"
  14. )
  15. // New VipInfo warden rpc server
  16. func New(c *warden.ServerConfig, svr *service.Service) *warden.Server {
  17. ws := warden.NewServer(c)
  18. v1.RegisterVipServer(ws.Server(), &server{svr})
  19. ws, err := ws.Start()
  20. if err != nil {
  21. panic(err)
  22. }
  23. return ws
  24. }
  25. type server struct {
  26. svr *service.Service
  27. }
  28. var _ v1.VipServer = &server{}
  29. // RegisterOpenID register open id.
  30. func (s *server) RegisterOpenID(c context.Context, req *v1.RegisterOpenIDReq) (res *v1.RegisterOpenIDReply, err error) {
  31. var ro *model.RegisterOpenIDResp
  32. if ro, err = s.svr.RegisterOpenID(c, &model.ArgRegisterOpenID{
  33. AppID: req.AppId,
  34. Mid: req.Mid,
  35. }); err != nil {
  36. return
  37. }
  38. return &v1.RegisterOpenIDReply{OpenId: ro.OpenID}, nil
  39. }
  40. // OpenBindByOutOpenID associate user bind by out_open_id [third -> bilibili].
  41. func (s *server) OpenBindByOutOpenID(c context.Context, req *v1.OpenBindByOutOpenIDReq) (res *v1.OpenBindByOutOpenIDReply, err error) {
  42. if err = s.svr.OpenBindByOutOpenID(c, &model.ArgBind{
  43. AppID: req.AppId,
  44. OpenID: req.OpenId,
  45. OutOpenID: req.OutOpenId,
  46. }); err != nil {
  47. return
  48. }
  49. return &v1.OpenBindByOutOpenIDReply{}, nil
  50. }
  51. // UserInfoByOpenID get userinfo by open_id.
  52. func (s *server) UserInfoByOpenID(c context.Context, req *v1.UserInfoByOpenIDReq) (res *v1.UserInfoByOpenIDReply, err error) {
  53. var u *model.UserInfoByOpenIDResp
  54. if u, err = s.svr.UserInfoByOpenID(c, &model.ArgUserInfoByOpenID{
  55. AppID: req.AppId,
  56. OpenID: req.OpenId,
  57. IP: req.Ip,
  58. }); err != nil {
  59. return
  60. }
  61. return &v1.UserInfoByOpenIDReply{
  62. Name: u.Name,
  63. BindState: u.BindState,
  64. OutOpenId: u.OutOpenID,
  65. }, nil
  66. }
  67. // BindInfoByMid bind info by mid[bilibili->third].
  68. func (s *server) BindInfoByMid(c context.Context, req *v1.BindInfoByMidReq) (res *v1.BindInfoByMidReply, err error) {
  69. var (
  70. b *model.BindInfo
  71. o *v1.BindOuter
  72. a *v1.Account
  73. )
  74. if b, err = s.svr.BindInfoByMid(c, &model.ArgBindInfo{
  75. AppID: req.AppId,
  76. Mid: req.Mid,
  77. }); err != nil {
  78. return
  79. }
  80. if b.Account != nil {
  81. a = &v1.Account{
  82. Mid: b.Account.Mid,
  83. Face: b.Account.Face,
  84. Name: b.Account.Name,
  85. }
  86. }
  87. if b.Outer != nil {
  88. o = &v1.BindOuter{
  89. Tel: b.Outer.Tel,
  90. BindState: b.Outer.BindState,
  91. }
  92. }
  93. return &v1.BindInfoByMidReply{
  94. Account: a,
  95. Outer: o,
  96. }, nil
  97. }
  98. // BilibiliPrizeGrant vip prize grant for third [third->bilibili].
  99. func (s *server) BilibiliPrizeGrant(c context.Context, req *v1.BilibiliPrizeGrantReq) (res *v1.BilibiliPrizeGrantReply, err error) {
  100. var sr *col.SalaryCouponForThirdResp
  101. if sr, err = s.svr.BilibiliPrizeGrant(c, &model.ArgBilibiliPrizeGrant{
  102. AppID: req.AppId,
  103. OpenID: req.OpenId,
  104. PrizeKey: req.PrizeKey,
  105. UniqueNo: req.UniqueNo,
  106. }); err != nil {
  107. return
  108. }
  109. return &v1.BilibiliPrizeGrantReply{
  110. Amount: sr.Amount,
  111. FullAmount: sr.FullAmount,
  112. Description: sr.Description,
  113. }, nil
  114. }
  115. // BilibiliVipGrant bilibili associate vip grant [third -> bilibili]
  116. func (s *server) BilibiliVipGrant(c context.Context, req *v1.BilibiliVipGrantReq) (res *v1.BilibiliVipGrantReply, err error) {
  117. if err = s.svr.BilibiliVipGrant(c, &model.ArgBilibiliVipGrant{
  118. AppID: req.AppId,
  119. OpenID: req.OpenId,
  120. OutOpenID: req.OutOpenId,
  121. OutOrderNO: req.OutOrderNo,
  122. Duration: req.Duration,
  123. }); err != nil {
  124. return
  125. }
  126. return &v1.BilibiliVipGrantReply{}, nil
  127. }
  128. // CreateAssociateOrder create associate order.
  129. func (s *server) CreateAssociateOrder(c context.Context, req *v1.CreateAssociateOrderReq) (res *v1.CreateAssociateOrderReply, err error) {
  130. var cr *model.CreateOrderRet
  131. if cr, err = s.svr.CreateAssociateOrder(c, &model.ArgCreateOrder2{
  132. Mid: req.Mid,
  133. Month: req.Month,
  134. Platform: req.Platform,
  135. MobiApp: req.MobiApp,
  136. Device: req.Device,
  137. AppID: req.AppId,
  138. AppSubID: req.AppSubId,
  139. OrderType: int8(req.OrderType),
  140. Dtype: int8(req.Dtype),
  141. ReturnURL: req.ReturnUrl,
  142. CouponToken: req.CouponToken,
  143. Bmid: req.Bmid,
  144. PanelType: req.PanelType,
  145. Build: req.Build,
  146. IP: net.ParseIP(req.IP),
  147. }); err != nil {
  148. return
  149. }
  150. marshal, err := json.Marshal(cr.PayParam)
  151. if err != nil {
  152. log.Error("json.Marshal(%+v) err(%+v)", cr.PayParam, err)
  153. return &v1.CreateAssociateOrderReply{}, err
  154. }
  155. return &v1.CreateAssociateOrderReply{PayParam: string(marshal)}, nil
  156. }
  157. // AssociatePanel associate panel.
  158. func (s *server) AssociatePanel(c context.Context, req *v1.AssociatePanelReq) (res *v1.AssociatePanelReply, err error) {
  159. var (
  160. pl []*model.AssociatePanelInfo
  161. list = []*v1.AssociatePanelInfo{}
  162. )
  163. if pl, err = s.svr.AssociatePanel(c, &model.ArgAssociatePanel{
  164. Mid: req.Mid,
  165. SortTP: int8(req.SortTp),
  166. IP: req.IP,
  167. MobiApp: req.MobiApp,
  168. Device: req.Device,
  169. Platform: req.Platform,
  170. PanelType: req.PanelType,
  171. Build: req.Build,
  172. }); err != nil {
  173. return
  174. }
  175. for _, v := range pl {
  176. list = append(list, &v1.AssociatePanelInfo{
  177. Id: v.ID,
  178. Month: v.Month,
  179. ProductName: v.PdName,
  180. ProductId: v.PdID,
  181. SubType: v.SubType,
  182. SuitType: v.SuitType,
  183. OriginalPrice: v.OPrice,
  184. DiscountPrice: v.DPrice,
  185. DiscountRate: v.DRate,
  186. Remark: v.Remark,
  187. Selected: v.Selected,
  188. PayState: int32(v.PayState),
  189. PayMessage: v.PayMessage,
  190. })
  191. }
  192. return &v1.AssociatePanelReply{List: list}, nil
  193. }
  194. // OpenAuthCallBack third open call back.
  195. func (s *server) OpenAuthCallBack(c context.Context, req *v1.OpenAuthCallBackReq) (res *v1.OpenAuthCallBackReply, err error) {
  196. if err = s.svr.OpenAuthCallBack(c, &model.ArgOpenAuthCallBack{
  197. Mid: req.Mid,
  198. AppID: req.AppId,
  199. ThirdCode: req.ThirdCode,
  200. }); err != nil {
  201. return
  202. }
  203. return &v1.OpenAuthCallBackReply{}, nil
  204. }
  205. // EleRedPackages red packages.
  206. func (s *server) EleRedPackages(c context.Context, req *v1.EleRedPackagesReq) (res *v1.EleRedPackagesReply, err error) {
  207. var data []*model.EleRedPackagesResp
  208. if data, err = s.svr.EleRedPackages(c); err != nil {
  209. return
  210. }
  211. list := []*v1.ModelEleRedPackage{}
  212. for _, v := range data {
  213. list = append(list, &v1.ModelEleRedPackage{
  214. Name: v.Name,
  215. Amount: v.Amount,
  216. SumCondition: v.SumCondition,
  217. })
  218. }
  219. return &v1.EleRedPackagesReply{List: list}, nil
  220. }
  221. // EleSpecailFoods specail foods.
  222. func (s *server) EleSpecailFoods(c context.Context, req *v1.EleSpecailFoodsReq) (res *v1.EleSpecailFoodsReply, err error) {
  223. var data []*model.EleSpecailFoodsResp
  224. if data, err = s.svr.EleSpecailFoods(c); err != nil {
  225. return
  226. }
  227. list := []*v1.ModelEleSpecailFoods{}
  228. for _, v := range data {
  229. list = append(list, &v1.ModelEleSpecailFoods{
  230. RestaurantName: v.RestaurantName,
  231. FoodName: v.FoodName,
  232. FoodUrl: v.FoodURL,
  233. Discount: v.Discount,
  234. Amount: v.Amount,
  235. OriginalAmount: v.OriginalAmount,
  236. RatingPoint: v.RatingPoint,
  237. })
  238. }
  239. return &v1.EleSpecailFoodsReply{List: list}, nil
  240. }
  241. // EleVipGrant vip grant.
  242. func (s *server) EleVipGrant(c context.Context, req *v1.EleVipGrantReq) (res *v1.EleVipGrantReply, err error) {
  243. if err = s.svr.EleVipGrant(c, &model.ArgEleVipGrant{OrderNO: req.OrderNo}); err != nil {
  244. return
  245. }
  246. return &v1.EleVipGrantReply{}, nil
  247. }
  248. // CouponBySuitID get coupon by mid and suit info.
  249. func (s *server) CouponBySuitID(c context.Context, req *v1.CouponBySuitIDReq) (res *v1.CouponBySuitIDReply, err error) {
  250. var data *colv1.UsableAllowanceCouponV2Reply
  251. res = new(v1.CouponBySuitIDReply)
  252. if data, err = s.svr.CouponBySuitIDV2(c, req); err != nil {
  253. return
  254. }
  255. if data == nil {
  256. return
  257. }
  258. res.CouponTip = data.CouponTip
  259. if data.CouponInfo == nil {
  260. return
  261. }
  262. res.CouponInfo = &v1.ModelCouponAllowancePanelInfo{
  263. CouponToken: data.CouponInfo.CouponToken,
  264. CouponAmount: data.CouponInfo.CouponAmount,
  265. State: data.CouponInfo.State,
  266. FullAmount: data.CouponInfo.FullAmount,
  267. FullLimitExplain: data.CouponInfo.FullLimitExplain,
  268. ScopeExplain: data.CouponInfo.ScopeExplain,
  269. CouponDiscountPrice: data.CouponInfo.CouponDiscountPrice,
  270. StartTime: data.CouponInfo.StartTime,
  271. ExpireTime: data.CouponInfo.ExpireTime,
  272. Selected: data.CouponInfo.Selected,
  273. DisablesExplains: data.CouponInfo.DisablesExplains,
  274. OrderNo: data.CouponInfo.OrderNo,
  275. Name: data.CouponInfo.Name,
  276. Usable: data.CouponInfo.Usable,
  277. }
  278. return
  279. }
  280. // VipUserPanel vip user panel
  281. func (s *server) VipUserPanel(c context.Context, req *v1.VipUserPanelReq) (res *v1.VipUserPanelReply, err error) {
  282. var data *model.VipPirceRespV9
  283. res = new(v1.VipUserPanelReply)
  284. if data, err = s.svr.VipUserPanelV9(c, req); err != nil {
  285. return
  286. }
  287. if data == nil {
  288. return
  289. }
  290. res.CouponSwitch = int32(data.CodeSwitch)
  291. res.CodeSwitch = int32(data.CodeSwitch)
  292. res.GiveSwitch = int32(data.GiveSwitch)
  293. priceList := []*v1.ModelVipPanelInfo{}
  294. for _, v := range data.Vps {
  295. priceList = append(priceList, &v1.ModelVipPanelInfo{
  296. Month: v.Month,
  297. ProductName: v.PdName,
  298. ProductId: v.PdID,
  299. SubType: v.SubType,
  300. SuitType: v.SuitType,
  301. OriginalPrice: v.OPrice,
  302. DiscountPrice: v.DPrice,
  303. DiscountRate: v.DRate,
  304. Remark: v.Remark,
  305. Selected: v.Selected,
  306. Id: v.Id,
  307. Type: v.Type,
  308. })
  309. }
  310. res.PriceList = priceList
  311. if data.Coupon != nil {
  312. res.Coupon = &v1.CouponBySuitIDReply{
  313. CouponTip: data.Coupon.CouponTip,
  314. }
  315. if data.Coupon.CouponInfo != nil {
  316. res.Coupon.CouponInfo = &v1.ModelCouponAllowancePanelInfo{
  317. CouponToken: data.Coupon.CouponInfo.CouponToken,
  318. CouponAmount: data.Coupon.CouponInfo.CouponAmount,
  319. State: data.Coupon.CouponInfo.State,
  320. FullAmount: data.Coupon.CouponInfo.FullAmount,
  321. FullLimitExplain: data.Coupon.CouponInfo.FullLimitExplain,
  322. ScopeExplain: data.Coupon.CouponInfo.ScopeExplain,
  323. CouponDiscountPrice: data.Coupon.CouponInfo.CouponDiscountPrice,
  324. StartTime: data.Coupon.CouponInfo.StartTime,
  325. ExpireTime: data.Coupon.CouponInfo.ExpireTime,
  326. Selected: data.Coupon.CouponInfo.Selected,
  327. DisablesExplains: data.Coupon.CouponInfo.DisablesExplains,
  328. OrderNo: data.Coupon.CouponInfo.OrderNo,
  329. Name: data.Coupon.CouponInfo.Name,
  330. Usable: data.Coupon.CouponInfo.Usable,
  331. }
  332. }
  333. }
  334. privileges := map[int32]*v1.ModelPrivilegeResp{}
  335. for k, v := range data.Privileges {
  336. list := []*v1.ModelPrivilege{}
  337. for _, p := range v.List {
  338. list = append(list, &v1.ModelPrivilege{
  339. Name: p.Name,
  340. IconUrl: p.IconURL,
  341. Type: int32(p.Type),
  342. })
  343. }
  344. privileges[int32(k)] = &v1.ModelPrivilegeResp{
  345. Title: v.Title,
  346. List: list,
  347. }
  348. }
  349. res.Privileges = privileges
  350. return
  351. }
  352. // EleVipGrant get welfare list.
  353. func (s *server) WelfareList(c context.Context, req *v1.WelfareReq) (res *v1.WelfareReply, err error) {
  354. var (
  355. data []*model.WelfareListResp
  356. count int64
  357. list = []*v1.WelfareListDetail{}
  358. )
  359. if data, count, err = s.svr.WelfareList(c, &model.ArgWelfareList{
  360. Tid: req.Tid,
  361. Recommend: req.Recommend,
  362. Ps: req.Ps,
  363. Pn: req.Pn,
  364. }); err != nil {
  365. return
  366. }
  367. for _, v := range data {
  368. list = append(list, &v1.WelfareListDetail{
  369. Id: v.ID,
  370. Name: v.Name,
  371. HomepageUri: v.HomepageUri,
  372. BackdropUri: v.BackdropUri,
  373. Tid: v.Tid,
  374. Rank: v.Rank,
  375. })
  376. }
  377. return &v1.WelfareReply{Count: count, List: list}, nil
  378. }
  379. // WelfareTypeList get welfare type list.
  380. func (s *server) WelfareTypeList(c context.Context, req *v1.WelfareTypeReq) (res *v1.WelfareTypeReply, err error) {
  381. var (
  382. data []*model.WelfareTypeListResp
  383. list = []*v1.WelfareTypeListDetail{}
  384. )
  385. if data, err = s.svr.WelfareTypeList(c); err != nil {
  386. return
  387. }
  388. for _, v := range data {
  389. list = append(list, &v1.WelfareTypeListDetail{
  390. Id: v.ID,
  391. Name: v.Name,
  392. })
  393. }
  394. return &v1.WelfareTypeReply{List: list}, nil
  395. }
  396. // WelfareInfo get welfare info.
  397. func (s *server) WelfareInfo(c context.Context, req *v1.WelfareInfoReq) (res *v1.WelfareInfoReply, err error) {
  398. var data *model.WelfareInfoResp
  399. if data, err = s.svr.WelfareInfo(c, &model.ArgWelfareInfo{ID: req.Id, MID: req.Mid}); err != nil {
  400. return
  401. }
  402. return &v1.WelfareInfoReply{
  403. Id: data.ID,
  404. Name: data.Name,
  405. Desc: data.Desc,
  406. HomepageUri: data.HomepageUri,
  407. BackdropUri: data.BackdropUri,
  408. Finished: data.Finished,
  409. Received: data.Received,
  410. VipType: data.VipType,
  411. Stime: int64(data.Stime),
  412. Etime: int64(data.Etime),
  413. }, nil
  414. }
  415. // WelfareReceive receive welfare.
  416. func (s *server) WelfareReceive(c context.Context, req *v1.WelfareReceiveReq) (res *v1.WelfareReceiveReply, err error) {
  417. if err = s.svr.WelfareReceive(c, &model.ArgWelfareReceive{Wid: req.Wid, Mid: req.Mid}); err != nil {
  418. return
  419. }
  420. return &v1.WelfareReceiveReply{}, nil
  421. }
  422. // MyWelfare get my welfare
  423. func (s *server) MyWelfare(c context.Context, req *v1.MyWelfareReq) (res *v1.MyWelfareReply, err error) {
  424. var (
  425. data []*model.MyWelfareResp
  426. list = []*v1.MyWelfareDetail{}
  427. )
  428. if data, err = s.svr.MyWelfare(c, req.Mid); err != nil {
  429. return
  430. }
  431. for _, v := range data {
  432. list = append(list, &v1.MyWelfareDetail{
  433. Wid: v.Wid,
  434. Name: v.Name,
  435. Desc: v.Desc,
  436. UsageForm: v.UsageForm,
  437. ReceiveUri: v.ReceiveUri,
  438. Code: v.Code,
  439. Expired: v.Expired,
  440. Stime: int64(v.Stime),
  441. Etime: int64(v.Etime),
  442. })
  443. }
  444. return &v1.MyWelfareReply{List: list}, nil
  445. }