shop.go 8.8 KB

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