shop.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. "encoding/json"
  11. pb "sportfitness/base/api/grpc/base"
  12. "sportfitness/base/assembly/base/repository/postgre"
  13. "sportfitness/base/errors"
  14. "sportfitness/base/repository/grpc/bsw/im"
  15. "strconv"
  16. )
  17. type Shop struct {
  18. base
  19. }
  20. func (s Shop) ShopGroupQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  21. optId := s.checkPermission(token, objectShopId)
  22. rst, err := postgre.PGShop{}.ShopGroupQuery(optId, objectShopId, jsonStr, sign)
  23. if err != nil {
  24. panic(errors.PGError)
  25. }
  26. return rst
  27. }
  28. func (s Shop) ManageableShopList(token string, r *pb.ShopListRequest) *pb.ShopListReply {
  29. // 获取商家可用商家列表shopId传入0,因为是通用接口
  30. _ = s.checkPermission(token, 0)
  31. status := s.WebStatusToManageStatus(r.Status)
  32. rst := im.ShopListRequest(r.Name, status, r.SId)
  33. //println(rst)
  34. var info []*pb.ShopInfo
  35. if len(rst.List) > 0 {
  36. for _, v := range rst.List {
  37. l := &pb.ShopInfo{}
  38. l.ShopId = v.ShopId
  39. l.Name = v.Name
  40. l.SId = v.SId
  41. l.Addr = v.Addr
  42. l.Phone = v.Phone
  43. l.Contacts = v.Contacts
  44. l.CreatedAt = strconv.FormatInt(v.CreatedAt, 10)
  45. l.UpdatedAt = strconv.FormatInt(v.UpdatedAt, 10)
  46. l.ShopUUID = strconv.FormatInt(v.ShopId, 10)
  47. l.Status = s.ManageStatusToWebStatus(v.Status)
  48. //println(l.ShopUUID)
  49. info = append(info, l)
  50. }
  51. }
  52. return &pb.ShopListReply{List: info}
  53. }
  54. func (s Shop) ManageableGetShopInfo(token string, r *pb.ShopDetailRequest) *pb.ShopInfo {
  55. optId := s.checkPermission(token, r.GetShopId())
  56. rst := im.ShopDetail(r.ShopId)
  57. navi := im.GetShopNavi(int64(optId), r.GetShopId(), 0)
  58. var isHr, isScore int64 = 0, 0
  59. if len(navi.List) > 0 {
  60. for _, v := range navi.List {
  61. if v.Name == "心率管理" {
  62. isHr = 1
  63. }
  64. if v.Name == "运动评估" {
  65. isScore = 1
  66. }
  67. }
  68. }
  69. info := &pb.ShopInfo{
  70. ShopId: rst.ShopId,
  71. Name: rst.Name,
  72. SId: rst.SId,
  73. Addr: rst.Addr,
  74. Phone: rst.Phone,
  75. Contacts: rst.Contacts,
  76. Status: s.ManageStatusToWebStatus(rst.Status),
  77. CreatedAt: strconv.FormatInt(rst.CreatedAt, 10),
  78. CreatedUser: rst.CreatedUser,
  79. UpdatedAt: strconv.FormatInt(rst.UpdatedAt, 10),
  80. UpdatedUser: rst.UpdatedUser,
  81. IsHr: isHr,
  82. IsScore: isScore,
  83. }
  84. return info
  85. }
  86. func (s Shop) LicenseTypeMap(token string, r *pb.IdList) *pb.LicenseTypeMapReply {
  87. _ = s.checkPermission(token, 0)
  88. rst := im.LicenseTypeMap(r.IdList)
  89. println(rst)
  90. //var info map[int64]pb.LicenseType
  91. //if rst != nil {
  92. // for _, v := range rst.List {
  93. // l := &pb.ShopInfo{}
  94. // l.ShopId = v.ShopId
  95. // l.Name = v.Name
  96. // l.SId = v.SId
  97. // l.Addr = v.Addr
  98. // l.Phone = v.Phone
  99. // l.Contacts = v.Contacts
  100. // l.CreatedAt = v.CreatedAt
  101. // l.UpdatedAt = v.UpdatedAt
  102. // l.Status = s.ManageStatusToWebStatus(v.Status)
  103. // info = append(info, l)
  104. // }
  105. //}
  106. return nil
  107. }
  108. // GetShopNavi 获取商家导航
  109. func (s Shop) GetShopNavi(token string, r *pb.GetShopNaviRequest) *pb.GetShopNaviReply {
  110. optId := s.checkPermission(token, r.GetShopId())
  111. rst := im.GetShopNavi(optId, r.GetShopId(), r.GetParentId())
  112. var info []*pb.Column
  113. if len(rst.List) > 0 {
  114. for _, v := range rst.List {
  115. l := &pb.Column{}
  116. l.Name = v.Name
  117. l.Url = v.Url
  118. l.Code = v.Code
  119. l.Sn = v.Sn
  120. l.NavShow = v.NavShow
  121. l.Id = strconv.FormatInt(v.Id, 10)
  122. l.Status = s.ManageStatusToWebStatus(v.Status)
  123. info = append(info, l)
  124. }
  125. }
  126. column, err := json.Marshal(info)
  127. if err != nil {
  128. println(err)
  129. }
  130. println(string(column))
  131. return &pb.GetShopNaviReply{List: info}
  132. }
  133. type ShopColumn struct {
  134. Navi
  135. Second []Navi
  136. }
  137. type Navi struct {
  138. Name string
  139. Url string
  140. Code string
  141. Sn int32
  142. Status pb.WebStatus
  143. NavShow bool
  144. Id string
  145. }
  146. // GetShopNaviAll 获取全部商家导航
  147. func (s Shop) GetShopNaviAll(token string, r *pb.GetShopNaviAllRequest) *pb.GetShopNaviAllReply {
  148. optId := s.checkPermission(token, r.GetShopId())
  149. rst := im.GetShopNavi(optId, r.GetShopId(), 0)
  150. var info []*ShopColumn
  151. if len(rst.List) > 0 {
  152. for _, v := range rst.List {
  153. l := &ShopColumn{}
  154. l.Name = v.Name
  155. l.Url = v.Url
  156. l.Code = v.Code
  157. l.Sn = v.Sn
  158. l.NavShow = v.NavShow
  159. l.Id = strconv.FormatInt(v.Id, 10)
  160. l.Status = s.ManageStatusToWebStatus(v.Status)
  161. secRs := im.GetShopNavi(optId, r.GetShopId(), v.Id)
  162. if secRs.List != nil {
  163. for _, v := range secRs.List {
  164. n := Navi{}
  165. n.Name = v.Name
  166. n.Url = v.Url
  167. n.Code = v.Code
  168. n.Sn = v.Sn
  169. n.NavShow = v.NavShow
  170. n.Id = strconv.FormatInt(v.Id, 10)
  171. n.Status = s.ManageStatusToWebStatus(v.Status)
  172. l.Second = append(l.Second, n)
  173. }
  174. } else {
  175. l.Second = make([]Navi, 0)
  176. }
  177. info = append(info, l)
  178. }
  179. }
  180. column, err := json.Marshal(info)
  181. if err != nil {
  182. println(err)
  183. }
  184. return &pb.GetShopNaviAllReply{ColumnRs: string(column)}
  185. }
  186. // ShopLicenseList 获取商家许可证
  187. func (s Shop) ShopLicenseList(token string, r *pb.ShopDetailRequest) *pb.LicenseList {
  188. _ = s.checkPermission(token, r.GetShopId())
  189. rst := im.ShopLicenseList(r.ShopId)
  190. var info []*pb.License
  191. if len(rst.List) > 0 {
  192. for _, v := range rst.List {
  193. l := &pb.License{}
  194. l.Id = v.Id
  195. l.LcsTypeId = v.LcsTypeId
  196. l.Name = v.Name
  197. l.ValidPeriod = v.ValidPeriod
  198. l.LcsPrice = v.LcsPrice
  199. l.LcsBeginTime = v.LcsBeginTime
  200. l.LcsEndTime = v.LcsEndTime
  201. l.FeeId = v.FeeId
  202. l.Status = s.ManageStatusToWebStatus(v.Status)
  203. l.Memo = v.Memo
  204. l.CreatedAt = v.CreatedUser
  205. l.UpdatedAt = v.UpdatedAt
  206. info = append(info, l)
  207. }
  208. }
  209. return &pb.LicenseList{List: info}
  210. }
  211. func (s Shop) ShopGroupAdd(token string, objectShopId int64, jsonStr string, sign string) string {
  212. optId := s.checkPermission(token, objectShopId)
  213. rst, err := postgre.PGShop{}.ShopGroupAdd(optId, objectShopId, jsonStr, sign)
  214. if err != nil {
  215. panic(errors.PGError)
  216. }
  217. return rst
  218. }
  219. func (s Shop) ShopGroupEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  220. optId := s.checkPermission(token, objectShopId)
  221. rst, err := postgre.PGShop{}.ShopGroupEdit(optId, objectShopId, jsonStr, sign)
  222. if err != nil {
  223. panic(errors.PGError)
  224. }
  225. return rst
  226. }
  227. func (s Shop) ShopGroupStatusEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  228. optId := s.checkPermission(token, objectShopId)
  229. rst, err := postgre.PGShop{}.ShopGroupStatusEdit(optId, objectShopId, jsonStr, sign)
  230. if err != nil {
  231. panic(errors.PGError)
  232. }
  233. return rst
  234. }
  235. func (s Shop) ShopGroupDetailsQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  236. optId := s.checkPermission(token, objectShopId)
  237. rst, err := postgre.PGShop{}.ShopGroupDetailsQuery(optId, objectShopId, jsonStr, sign)
  238. if err != nil {
  239. panic(errors.PGError)
  240. }
  241. return rst
  242. }
  243. func (s Shop) ShopVenueQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  244. optId := s.checkPermission(token, objectShopId)
  245. rst, err := postgre.PGShop{}.ShopVenueQuery(optId, objectShopId, jsonStr, sign)
  246. if err != nil {
  247. panic(errors.PGError)
  248. }
  249. return rst
  250. }
  251. // ShopVenueAdd 商家区域添加 @token:token
  252. func (s Shop) ShopVenueAdd(token string, objectShopId int64, jsonStr string, sign string) string {
  253. optId := s.checkPermission(token, objectShopId)
  254. rst, err := postgre.PGShop{}.ShopVenueAdd(optId, objectShopId, jsonStr, sign)
  255. if err != nil {
  256. panic(errors.PGError)
  257. }
  258. return rst
  259. }
  260. // ShopVenueEdit 商家区域编辑
  261. func (s Shop) ShopVenueEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  262. optId := s.checkPermission(token, objectShopId)
  263. rst, err := postgre.PGShop{}.ShopVenueEdit(optId, objectShopId, jsonStr, sign)
  264. if err != nil {
  265. panic(errors.PGError)
  266. }
  267. return rst
  268. }
  269. // ShopVenueStatusEdit 商家区域状态修改
  270. func (s Shop) ShopVenueStatusEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  271. optId := s.checkPermission(token, objectShopId)
  272. rst, err := postgre.PGShop{}.ShopVenueStatusEdit(optId, objectShopId, jsonStr, sign)
  273. if err != nil {
  274. panic(errors.PGError)
  275. }
  276. return rst
  277. }
  278. // ShopVenueEquipQuery 商家设备查询
  279. func (s Shop) ShopVenueEquipQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  280. optId := s.checkPermission(token, objectShopId)
  281. rst, err := postgre.PGShop{}.ShopVenueEquipQuery(optId, objectShopId, jsonStr, sign)
  282. if err != nil {
  283. panic(errors.PGError)
  284. }
  285. return rst
  286. }
  287. // ShopVenueEquipAdd 商家设备添加
  288. func (s Shop) ShopVenueEquipAdd(token string, objectShopId int64, jsonStr string, sign string) string {
  289. optId := s.checkPermission(token, objectShopId)
  290. rst, err := postgre.PGShop{}.ShopVenueEquipQuery(optId, objectShopId, jsonStr, sign)
  291. if err != nil {
  292. panic(errors.PGError)
  293. }
  294. return rst
  295. }
  296. // ShopVenueEquipEdit 商家设备编辑
  297. func (s Shop) ShopVenueEquipEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  298. optId := s.checkPermission(token, objectShopId)
  299. rst, err := postgre.PGShop{}.ShopVenueEquipEdit(optId, objectShopId, jsonStr, sign)
  300. if err != nil {
  301. panic(errors.PGError)
  302. }
  303. return rst
  304. }
  305. // ShopVenueEquipStatusEdit 商家设备状态修改
  306. func (s Shop) ShopVenueEquipStatusEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  307. optId := s.checkPermission(token, objectShopId)
  308. rst, err := postgre.PGShop{}.ShopVenueEquipStatusEdit(optId, objectShopId, jsonStr, sign)
  309. if err != nil {
  310. panic(errors.PGError)
  311. }
  312. return rst
  313. }
  314. // ShopVenueEquipStatusDel 商家设备删除
  315. func (s Shop) ShopVenueEquipStatusDel(token string, objectShopId int64, jsonStr string, sign string) string {
  316. optId := s.checkPermission(token, objectShopId)
  317. rst, err := postgre.PGShop{}.ShopVenueEquipStatusDel(optId, objectShopId, jsonStr, sign)
  318. if err != nil {
  319. panic(errors.PGError)
  320. }
  321. return rst
  322. }
  323. // ShopConfigQuery 商家配置查询
  324. func (s Shop) ShopConfigQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  325. optId := s.checkPermission(token, objectShopId)
  326. rst, err := postgre.PGShop{}.ShopConfigQuery(optId, objectShopId, jsonStr, sign)
  327. if err != nil {
  328. panic(errors.PGError)
  329. }
  330. return rst
  331. }
  332. // ShopConfigEdit 商家设备删除
  333. func (s Shop) ShopConfigEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  334. optId := s.checkPermission(token, objectShopId)
  335. rst, err := postgre.PGShop{}.ShopConfigEdit(optId, objectShopId, jsonStr, sign)
  336. if err != nil {
  337. panic(errors.PGError)
  338. }
  339. return rst
  340. }
  341. // GroupSimpleQueryByShopID 商家分组简单查询-通过商家自己ID查询
  342. func (s Shop) GroupSimpleQueryByShopID(token string, objectShopId int64, jsonStr string, sign string) string {
  343. optId := s.checkPermission(token, objectShopId)
  344. rst, err := postgre.PGShop{}.GroupSimpleQuery(optId, objectShopId, jsonStr, sign)
  345. if err != nil {
  346. panic(errors.PGError)
  347. }
  348. return rst
  349. }
  350. // EqSimpleQuery 显示设备简单查询
  351. func (s Shop) EqSimpleQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  352. optId := s.checkPermission(token, objectShopId)
  353. rst, err := postgre.PGShop{}.EqSimpleQuery(optId, objectShopId, jsonStr, sign)
  354. if err != nil {
  355. panic(errors.PGError)
  356. }
  357. return rst
  358. }