shop.go 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. // Package service
  2. /**
  3. * @ File: shop
  4. * @ Date: 2021/4/13 10:41
  5. * @ Author: JYQ
  6. * @ Description:
  7. */
  8. package service
  9. import (
  10. pb "sportfitness/base/api/grpc/base"
  11. "sportfitness/base/assembly/base/repository/postgre"
  12. "sportfitness/base/errors"
  13. "sportfitness/base/repository/grpc/bsw/im"
  14. "strconv"
  15. )
  16. type Shop struct {
  17. base
  18. }
  19. func (s Shop) ShopGroupQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  20. optId := s.checkPermission(token, objectShopId)
  21. rst, err := postgre.PGShop{}.ShopGroupQuery(optId, objectShopId, jsonStr, sign)
  22. if err != nil {
  23. panic(errors.PGError)
  24. }
  25. return rst
  26. }
  27. func (s Shop) ManageableShopList(token string, r *pb.ShopListRequest) *pb.ShopListReply {
  28. // 获取商家可用商家列表shopId传入0,因为是通用接口
  29. _ = s.checkPermission(token, 0)
  30. status := s.WebStatusToManageStatus(r.Status)
  31. rst := im.ShopListRequest(r.Name, status, r.SId)
  32. //println(rst)
  33. var info []*pb.ShopInfo
  34. if len(rst.List) > 0 {
  35. for _, v := range rst.List {
  36. l := &pb.ShopInfo{}
  37. l.ShopId = v.ShopId
  38. l.Name = v.Name
  39. l.SId = v.SId
  40. l.Addr = v.Addr
  41. l.Phone = v.Phone
  42. l.Contacts = v.Contacts
  43. l.CreatedAt = strconv.FormatInt(v.CreatedAt, 10)
  44. l.UpdatedAt = strconv.FormatInt(v.UpdatedAt, 10)
  45. l.ShopUUID = strconv.FormatInt(v.ShopId, 10)
  46. l.Status = s.ManageStatusToWebStatus(v.Status)
  47. //println(l.ShopUUID)
  48. info = append(info, l)
  49. }
  50. }
  51. return &pb.ShopListReply{List: info}
  52. }
  53. func (s Shop) ManageableGetShopInfo(token string, r *pb.ShopDetailRequest) *pb.ShopInfo {
  54. optId := s.checkPermission(token, r.GetShopId())
  55. rst := im.ShopDetail(r.ShopId)
  56. navi := im.GetShopNavi(int64(optId), r.GetShopId(), 0)
  57. var isHr, isScore int64 = 0, 0
  58. if len(navi.List) > 0 {
  59. for _, v := range navi.List {
  60. if v.Name == "心率管理" {
  61. isHr = 1
  62. }
  63. if v.Name == "运动评估" {
  64. isScore = 1
  65. }
  66. }
  67. }
  68. info := &pb.ShopInfo{
  69. ShopId: rst.ShopId,
  70. Name: rst.Name,
  71. SId: rst.SId,
  72. Addr: rst.Addr,
  73. Phone: rst.Phone,
  74. Contacts: rst.Contacts,
  75. Status: s.ManageStatusToWebStatus(rst.Status),
  76. CreatedAt: strconv.FormatInt(rst.CreatedAt, 10),
  77. CreatedUser: rst.CreatedUser,
  78. UpdatedAt: strconv.FormatInt(rst.UpdatedAt, 10),
  79. UpdatedUser: rst.UpdatedUser,
  80. IsHr: isHr,
  81. IsScore: isScore,
  82. }
  83. return info
  84. }
  85. func (s Shop) LicenseTypeMap(token string, r *pb.IdList) *pb.LicenseTypeMapReply {
  86. _ = s.checkPermission(token, 0)
  87. rst := im.LicenseTypeMap(r.IdList)
  88. println(rst)
  89. //var info map[int64]pb.LicenseType
  90. //if rst != nil {
  91. // for _, v := range rst.List {
  92. // l := &pb.ShopInfo{}
  93. // l.ShopId = v.ShopId
  94. // l.Name = v.Name
  95. // l.SId = v.SId
  96. // l.Addr = v.Addr
  97. // l.Phone = v.Phone
  98. // l.Contacts = v.Contacts
  99. // l.CreatedAt = v.CreatedAt
  100. // l.UpdatedAt = v.UpdatedAt
  101. // l.Status = s.ManageStatusToWebStatus(v.Status)
  102. // info = append(info, l)
  103. // }
  104. //}
  105. return nil
  106. }
  107. // GetShopNavi 获取商家导航
  108. func (s Shop) GetShopNavi(token string, r *pb.GetShopNaviRequest) *pb.GetShopNaviReply {
  109. optId := s.checkPermission(token, r.GetShopId())
  110. rst := im.GetShopNavi(int64(optId), r.GetShopId(), r.GetParentId())
  111. var info []*pb.Column
  112. if len(rst.List) > 0 {
  113. for _, v := range rst.List {
  114. l := &pb.Column{}
  115. l.Name = v.Name
  116. l.Url = v.Url
  117. l.Code = v.Code
  118. l.Sn = v.Sn
  119. l.NavShow = v.NavShow
  120. l.Id = strconv.FormatInt(v.Id, 10)
  121. l.Status = s.ManageStatusToWebStatus(v.Status)
  122. info = append(info, l)
  123. }
  124. }
  125. return &pb.GetShopNaviReply{List: info}
  126. }
  127. // ShopLicenseList 获取商家许可证
  128. func (s Shop) ShopLicenseList(token string, r *pb.ShopDetailRequest) *pb.LicenseList {
  129. _ = s.checkPermission(token, r.GetShopId())
  130. rst := im.ShopLicenseList(r.ShopId)
  131. var info []*pb.License
  132. if len(rst.List) > 0 {
  133. for _, v := range rst.List {
  134. l := &pb.License{}
  135. l.Id = v.Id
  136. l.LcsTypeId = v.LcsTypeId
  137. l.Name = v.Name
  138. l.ValidPeriod = v.ValidPeriod
  139. l.LcsPrice = v.LcsPrice
  140. l.LcsBeginTime = v.LcsBeginTime
  141. l.LcsEndTime = v.LcsEndTime
  142. l.FeeId = v.FeeId
  143. l.Status = s.ManageStatusToWebStatus(v.Status)
  144. l.Memo = v.Memo
  145. l.CreatedAt = v.CreatedUser
  146. l.UpdatedAt = v.UpdatedAt
  147. info = append(info, l)
  148. }
  149. }
  150. return &pb.LicenseList{List: info}
  151. }
  152. func (s Shop) ShopGroupAdd(token string, objectShopId int64, jsonStr string, sign string) string {
  153. optId := s.checkPermission(token, objectShopId)
  154. rst, err := postgre.PGShop{}.ShopGroupAdd(optId, objectShopId, jsonStr, sign)
  155. if err != nil {
  156. panic(errors.PGError)
  157. }
  158. return rst
  159. }
  160. func (s Shop) ShopGroupEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  161. optId := s.checkPermission(token, objectShopId)
  162. rst, err := postgre.PGShop{}.ShopGroupEdit(optId, objectShopId, jsonStr, sign)
  163. if err != nil {
  164. panic(errors.PGError)
  165. }
  166. return rst
  167. }
  168. func (s Shop) ShopGroupStatusEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  169. optId := s.checkPermission(token, objectShopId)
  170. rst, err := postgre.PGShop{}.ShopGroupStatusEdit(optId, objectShopId, jsonStr, sign)
  171. if err != nil {
  172. panic(errors.PGError)
  173. }
  174. return rst
  175. }
  176. func (s Shop) ShopGroupDetailsQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  177. optId := s.checkPermission(token, objectShopId)
  178. rst, err := postgre.PGShop{}.ShopGroupDetailsQuery(optId, objectShopId, jsonStr, sign)
  179. if err != nil {
  180. panic(errors.PGError)
  181. }
  182. return rst
  183. }
  184. func (s Shop) ShopVenueQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  185. optId := s.checkPermission(token, objectShopId)
  186. rst, err := postgre.PGShop{}.ShopVenueQuery(optId, objectShopId, jsonStr, sign)
  187. if err != nil {
  188. panic(errors.PGError)
  189. }
  190. return rst
  191. }
  192. // ShopVenueAdd 商家区域添加 @token:token
  193. func (s Shop) ShopVenueAdd(token string, objectShopId int64, jsonStr string, sign string) string {
  194. optId := s.checkPermission(token, objectShopId)
  195. rst, err := postgre.PGShop{}.ShopVenueAdd(optId, objectShopId, jsonStr, sign)
  196. if err != nil {
  197. panic(errors.PGError)
  198. }
  199. return rst
  200. }
  201. // ShopVenueEdit 商家区域编辑
  202. func (s Shop) ShopVenueEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  203. optId := s.checkPermission(token, objectShopId)
  204. rst, err := postgre.PGShop{}.ShopVenueEdit(optId, objectShopId, jsonStr, sign)
  205. if err != nil {
  206. panic(errors.PGError)
  207. }
  208. return rst
  209. }
  210. // ShopVenueStatusEdit 商家区域状态修改
  211. func (s Shop) ShopVenueStatusEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  212. optId := s.checkPermission(token, objectShopId)
  213. rst, err := postgre.PGShop{}.ShopVenueStatusEdit(optId, objectShopId, jsonStr, sign)
  214. if err != nil {
  215. panic(errors.PGError)
  216. }
  217. return rst
  218. }
  219. // ShopVenueEquipQuery 商家设备查询
  220. func (s Shop) ShopVenueEquipQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  221. optId := s.checkPermission(token, objectShopId)
  222. rst, err := postgre.PGShop{}.ShopVenueEquipQuery(optId, objectShopId, jsonStr, sign)
  223. if err != nil {
  224. panic(errors.PGError)
  225. }
  226. return rst
  227. }
  228. // ShopVenueEquipAdd 商家设备添加
  229. func (s Shop) ShopVenueEquipAdd(token string, objectShopId int64, jsonStr string, sign string) string {
  230. optId := s.checkPermission(token, objectShopId)
  231. rst, err := postgre.PGShop{}.ShopVenueEquipQuery(optId, objectShopId, jsonStr, sign)
  232. if err != nil {
  233. panic(errors.PGError)
  234. }
  235. return rst
  236. }
  237. // ShopVenueEquipEdit 商家设备编辑
  238. func (s Shop) ShopVenueEquipEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  239. optId := s.checkPermission(token, objectShopId)
  240. rst, err := postgre.PGShop{}.ShopVenueEquipEdit(optId, objectShopId, jsonStr, sign)
  241. if err != nil {
  242. panic(errors.PGError)
  243. }
  244. return rst
  245. }
  246. // ShopVenueEquipStatusEdit 商家设备状态修改
  247. func (s Shop) ShopVenueEquipStatusEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  248. optId := s.checkPermission(token, objectShopId)
  249. rst, err := postgre.PGShop{}.ShopVenueEquipStatusEdit(optId, objectShopId, jsonStr, sign)
  250. if err != nil {
  251. panic(errors.PGError)
  252. }
  253. return rst
  254. }
  255. // ShopVenueEquipStatusDel 商家设备删除
  256. func (s Shop) ShopVenueEquipStatusDel(token string, objectShopId int64, jsonStr string, sign string) string {
  257. optId := s.checkPermission(token, objectShopId)
  258. rst, err := postgre.PGShop{}.ShopVenueEquipStatusDel(optId, objectShopId, jsonStr, sign)
  259. if err != nil {
  260. panic(errors.PGError)
  261. }
  262. return rst
  263. }
  264. // ShopConfigQuery 商家配置查询
  265. func (s Shop) ShopConfigQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  266. optId := s.checkPermission(token, objectShopId)
  267. rst, err := postgre.PGShop{}.ShopConfigQuery(optId, objectShopId, jsonStr, sign)
  268. if err != nil {
  269. panic(errors.PGError)
  270. }
  271. return rst
  272. }
  273. // ShopConfigEdit 商家设备删除
  274. func (s Shop) ShopConfigEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  275. optId := s.checkPermission(token, objectShopId)
  276. rst, err := postgre.PGShop{}.ShopConfigEdit(optId, objectShopId, jsonStr, sign)
  277. if err != nil {
  278. panic(errors.PGError)
  279. }
  280. return rst
  281. }