shop.go 13 KB

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