user.go 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. package service
  2. import (
  3. "fmt"
  4. pb "sportfitness/base/api/grpc/base"
  5. "sportfitness/base/assembly/base/repository/postgre"
  6. "sportfitness/base/errors"
  7. "sportfitness/base/repository/grpc/bsw/im"
  8. im2 "sportfitness/base/repository/grpc/bsw/im/im"
  9. "github.com/qiniu/api.v7/v7/auth/qbox"
  10. "github.com/qiniu/api.v7/v7/storage"
  11. )
  12. type User struct {
  13. base
  14. }
  15. var (
  16. accessKey = "JvRT6F0pbWwfTwRZOeYCLcTFBwtE_E0CFp6DZklk"
  17. secretKey = "vgYd-QjeAk9v5QrIU1z4427xJi_nao4LCuXgWfgJ"
  18. bucket = "beswell"
  19. )
  20. func (User) SignInUserCodePassword(userCode, password, ip, ClientInfo,
  21. codeId, verifyCode string) (token string) {
  22. token, userId := im.SignInUserCodePassword(userCode, password, ip, ClientInfo,
  23. codeId, verifyCode)
  24. println(token, userId)
  25. return token
  26. }
  27. func (User) SignOut(token string) {
  28. im.SignOut(token)
  29. }
  30. func (User) GenVerifyImage(height, width int32) (string, string) {
  31. codeId, imageBase64 := im.GenVerifyImage(height, width)
  32. return codeId, imageBase64
  33. }
  34. func (User) SubSessionCheck(token string) int64 {
  35. userId := im.SubSessionCheck(token)
  36. return userId
  37. }
  38. // SubPermissionListCheck 页面批量鉴权
  39. func (User) SubPermissionListCheck(token string, shopID int64, serviceList []string) (rs *im2.PermissionCheckReply) {
  40. rs = im.SubPermissionListCheck(token, shopID, serviceList)
  41. return
  42. }
  43. // ShopVipUserQuery 商家会员查询
  44. func (u User) ShopVipUserQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  45. optId := u.checkPermission(token, objectShopId)
  46. rst, err := postgre.PGShop{}.VipUserListQuery(optId, objectShopId, jsonStr, sign)
  47. if err != nil {
  48. panic(errors.PGError)
  49. }
  50. return rst
  51. }
  52. // ShopVipUserAdd 商家会员添加
  53. func (u User) ShopVipUserAdd(token string, objectShopId int64, jsonStr string, sign string) string {
  54. optId := u.checkPermission(token, objectShopId)
  55. rst, err := postgre.PGShop{}.VipUserAdd(optId, objectShopId, jsonStr, sign)
  56. if err != nil {
  57. panic(errors.PGError)
  58. }
  59. return rst
  60. }
  61. // ShopVipUserEdit 商家会员编辑
  62. func (u User) ShopVipUserEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  63. optId := u.checkPermission(token, objectShopId)
  64. rst, err := postgre.PGShop{}.VipUserEdit(optId, objectShopId, jsonStr, sign)
  65. if err != nil {
  66. panic(errors.PGError)
  67. }
  68. return rst
  69. }
  70. // ShopVipUserStatusEdit 商家会状态员编辑
  71. func (u User) ShopVipUserStatusEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  72. optId := u.checkPermission(token, objectShopId)
  73. rst, err := postgre.PGShop{}.VipUserStatusEdit(optId, objectShopId, jsonStr, sign)
  74. if err != nil {
  75. panic(errors.PGError)
  76. }
  77. return rst
  78. }
  79. // AcrossVipUserQuery 商家跨店会员查询
  80. func (u User) AcrossVipUserQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  81. optId := u.checkPermission(token, objectShopId)
  82. rst, err := postgre.PGShop{}.AcrossVipUserListQuery(optId, objectShopId, jsonStr, sign)
  83. if err != nil {
  84. panic(errors.PGError)
  85. }
  86. return rst
  87. }
  88. // AcrossVipUserAdd 商家跨店会员添加
  89. func (u User) AcrossVipUserAdd(token string, objectShopId int64, jsonStr string, sign string) string {
  90. optId := u.checkPermission(token, objectShopId)
  91. rst, err := postgre.PGShop{}.AcrossVipUserAdd(optId, objectShopId, jsonStr, sign)
  92. if err != nil {
  93. panic(errors.PGError)
  94. }
  95. return rst
  96. }
  97. // AcrossVipUserDel 商家跨店会员删除
  98. func (u User) AcrossVipUserDel(token string, objectShopId int64, jsonStr string, sign string) string {
  99. optId := u.checkPermission(token, objectShopId)
  100. rst, err := postgre.PGShop{}.AcrossVipUserDel(optId, objectShopId, jsonStr, sign)
  101. if err != nil {
  102. panic(errors.PGError)
  103. }
  104. return rst
  105. }
  106. // VipPhoneQuery 商家跨店会员删除
  107. func (u User) VipPhoneQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  108. optId := u.checkPermission(token, objectShopId)
  109. rst, err := postgre.PGShop{}.VipUserPhoneQuery(optId, objectShopId, jsonStr, sign)
  110. if err != nil {
  111. panic(errors.PGError)
  112. }
  113. return rst
  114. }
  115. // VipMainPhoneCheck 商家会员主手机号校验
  116. func (u User) VipMainPhoneCheck(token string, objectShopId int64, jsonStr string, sign string) string {
  117. optId := u.checkPermission(token, objectShopId)
  118. rst, err := postgre.PGShop{}.VipUserQueryByPhone(optId, objectShopId, jsonStr, sign)
  119. if err != nil {
  120. panic(errors.PGError)
  121. }
  122. return rst
  123. }
  124. // VipOtherPhoneAdd 商家会员其他手机号添加
  125. func (u User) VipOtherPhoneAdd(token string, objectShopId int64, jsonStr string, sign string) string {
  126. optId := u.checkPermission(token, objectShopId)
  127. rst, err := postgre.PGShop{}.VipUserOtherPhoneAdd(optId, objectShopId, jsonStr, sign)
  128. if err != nil {
  129. panic(errors.PGError)
  130. }
  131. return rst
  132. }
  133. // VipOtherPhoneEdit 商家会员其他手机号编辑
  134. func (u User) VipOtherPhoneEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  135. optId := u.checkPermission(token, objectShopId)
  136. rst, err := postgre.PGShop{}.VipUserOtherPhoneEdit(optId, objectShopId, jsonStr, sign)
  137. if err != nil {
  138. panic(errors.PGError)
  139. }
  140. return rst
  141. }
  142. // VipOtherPhoneStatusEdit 商家会员其他手机号状态修改
  143. func (u User) VipOtherPhoneStatusEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  144. optId := u.checkPermission(token, objectShopId)
  145. rst, err := postgre.PGShop{}.VipUserOtherPhoneStatusEdit(optId, objectShopId, jsonStr, sign)
  146. if err != nil {
  147. panic(errors.PGError)
  148. }
  149. return rst
  150. }
  151. // TempVipUserQuery 商家临时会员查询
  152. func (u User) TempVipUserQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  153. optId := u.checkPermission(token, objectShopId)
  154. rst, err := postgre.PGShop{}.TmpVipUserQuery(optId, objectShopId, jsonStr, sign)
  155. if err != nil {
  156. panic(errors.PGError)
  157. }
  158. return rst
  159. }
  160. // TempVipUserAdd 商家临时会员添加
  161. func (u User) TempVipUserAdd(token string, objectShopId int64, jsonStr string, sign string) string {
  162. optId := u.checkPermission(token, objectShopId)
  163. rst, err := postgre.PGShop{}.TmpUserAdd(optId, objectShopId, jsonStr, sign)
  164. if err != nil {
  165. panic(errors.PGError)
  166. }
  167. return rst
  168. }
  169. // TempVipUserEdit 商家临时会员编辑
  170. func (u User) TempVipUserEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  171. optId := u.checkPermission(token, objectShopId)
  172. rst, err := postgre.PGShop{}.TmpVipUserEdit(optId, objectShopId, jsonStr, sign)
  173. if err != nil {
  174. panic(errors.PGError)
  175. }
  176. return rst
  177. }
  178. // TempVipUserStatusEdit 商家临时会员状态修改
  179. func (u User) TempVipUserStatusEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  180. optId := u.checkPermission(token, objectShopId)
  181. rst, err := postgre.PGShop{}.TmpVipUserStatusEdit(optId, objectShopId, jsonStr, sign)
  182. if err != nil {
  183. panic(errors.PGError)
  184. }
  185. return rst
  186. }
  187. // VipHourEdit 商家会员课时编辑
  188. func (u User) VipHourEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  189. optId := u.checkPermission(token, objectShopId)
  190. rst, err := postgre.PGShop{}.VipUserHourEdit(optId, objectShopId, jsonStr, sign)
  191. if err != nil {
  192. panic(errors.PGError)
  193. }
  194. return rst
  195. }
  196. // VipConsumeListQuery 商家会员消费课时查询
  197. func (u User) VipConsumeListQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  198. optId := u.checkPermission(token, objectShopId)
  199. rst, err := postgre.PGShop{}.VipUserConsumeListQuery(optId, objectShopId, jsonStr, sign)
  200. if err != nil {
  201. panic(errors.PGError)
  202. }
  203. return rst
  204. }
  205. // VipConsumeDetailQuery 商家会员消费课时详情查询
  206. func (u User) VipConsumeDetailQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  207. optId := u.checkPermission(token, objectShopId)
  208. rst, err := postgre.PGShop{}.VipUserConsumeDetailQuery(optId, objectShopId, jsonStr, sign)
  209. if err != nil {
  210. panic(errors.PGError)
  211. }
  212. return rst
  213. }
  214. // VipClassRelationEdit 商家会员消费课时详情查询
  215. func (u User) VipClassRelationEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  216. optId := u.checkPermission(token, objectShopId)
  217. rst, err := postgre.PGShop{}.VipUserClassEdit(optId, objectShopId, jsonStr, sign)
  218. if err != nil {
  219. panic(errors.PGError)
  220. }
  221. return rst
  222. }
  223. // VipHourChgQuery 商家会员消费课时详情查询
  224. func (u User) VipHourChgQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  225. optId := u.checkPermission(token, objectShopId)
  226. rst, err := postgre.PGShop{}.VipUserClassEdit(optId, objectShopId, jsonStr, sign)
  227. if err != nil {
  228. panic(errors.PGError)
  229. }
  230. return rst
  231. }
  232. // GetSimpleQiNiuToken 获取七牛简单Token
  233. func (u User) GetSimpleQiNiuToken(token string) *pb.QiNiuTokenReply {
  234. _ = u.checkPermission(token, 0)
  235. putPolicy := storage.PutPolicy{
  236. Scope: bucket,
  237. }
  238. mac := qbox.NewMac(accessKey, secretKey)
  239. t := putPolicy.UploadToken(mac)
  240. return &pb.QiNiuTokenReply{Token: t}
  241. }
  242. // GetOverlayImgQiNiuToken 获取七牛可覆盖文件Token
  243. func (u User) GetOverlayImgQiNiuToken(token, fileName string) *pb.QiNiuTokenReply {
  244. _ = u.checkPermission(token, 0)
  245. putPolicy := storage.PutPolicy{
  246. Scope: fmt.Sprintf("%s:%s", bucket, fileName),
  247. }
  248. mac := qbox.NewMac(accessKey, secretKey)
  249. t := putPolicy.UploadToken(mac)
  250. return &pb.QiNiuTokenReply{Token: t}
  251. }