shop.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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, s.WebStatusToManageStatus(pb.WebStatus_On))
  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(), s.WebStatusToManageStatus(pb.WebStatus_On))
  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.Icon = v.Icon
  122. l.Id = strconv.FormatInt(v.Id, 10)
  123. l.Status = s.ManageStatusToWebStatus(v.Status)
  124. info = append(info, l)
  125. }
  126. }
  127. column, err := json.Marshal(info)
  128. if err != nil {
  129. println(err)
  130. }
  131. println(string(column))
  132. return &pb.GetShopNaviReply{List: info}
  133. }
  134. type ShopColumn struct {
  135. Navi
  136. Second []Navi
  137. }
  138. type Navi struct {
  139. Name string
  140. Url string
  141. Code string
  142. Sn int32
  143. Status pb.WebStatus
  144. NavShow bool
  145. Id string
  146. Icon string
  147. }
  148. // GetShopNaviAll 获取全部商家导航
  149. func (s Shop) GetShopNaviAll(token string, r *pb.GetShopNaviAllRequest) *pb.GetShopNaviAllReply {
  150. optId := s.checkPermission(token, r.GetShopId())
  151. rst := im.GetShopNavi(optId, r.GetShopId(), 0, s.WebStatusToManageStatus(pb.WebStatus_On))
  152. var info []*ShopColumn
  153. if len(rst.List) > 0 {
  154. for _, v := range rst.List {
  155. l := &ShopColumn{}
  156. l.Name = v.Name
  157. l.Url = v.Url
  158. l.Code = v.Code
  159. l.Sn = v.Sn
  160. l.NavShow = v.NavShow
  161. l.Id = strconv.FormatInt(v.Id, 10)
  162. l.Status = s.ManageStatusToWebStatus(v.Status)
  163. l.Icon = v.Icon
  164. secRs := im.GetShopNavi(optId, r.GetShopId(), v.Id, s.WebStatusToManageStatus(pb.WebStatus_On))
  165. if secRs.List != nil {
  166. for _, v := range secRs.List {
  167. n := Navi{}
  168. n.Name = v.Name
  169. n.Url = v.Url
  170. n.Code = v.Code
  171. n.Sn = v.Sn
  172. n.NavShow = v.NavShow
  173. n.Id = strconv.FormatInt(v.Id, 10)
  174. n.Status = s.ManageStatusToWebStatus(v.Status)
  175. n.Icon = v.Icon
  176. l.Second = append(l.Second, n)
  177. }
  178. } else {
  179. l.Second = make([]Navi, 0)
  180. }
  181. info = append(info, l)
  182. }
  183. }
  184. column, err := json.Marshal(info)
  185. if err != nil {
  186. println(err)
  187. }
  188. return &pb.GetShopNaviAllReply{ColumnRs: string(column)}
  189. }
  190. // ShopLicenseList 获取商家许可证
  191. func (s Shop) ShopLicenseList(token string, r *pb.ShopDetailRequest) *pb.LicenseList {
  192. _ = s.checkPermission(token, r.GetShopId())
  193. rst := im.ShopLicenseList(r.ShopId)
  194. var info []*pb.License
  195. if len(rst.List) > 0 {
  196. for _, v := range rst.List {
  197. l := &pb.License{}
  198. l.Id = v.Id
  199. l.LcsTypeId = v.LcsTypeId
  200. l.Name = v.Name
  201. l.ValidPeriod = v.ValidPeriod
  202. l.LcsPrice = v.LcsPrice
  203. l.LcsBeginTime = v.LcsBeginTime
  204. l.LcsEndTime = v.LcsEndTime
  205. l.FeeId = v.FeeId
  206. l.Status = s.ManageStatusToWebStatus(v.Status)
  207. l.Memo = v.Memo
  208. l.CreatedAt = v.CreatedUser
  209. l.UpdatedAt = v.UpdatedAt
  210. info = append(info, l)
  211. }
  212. }
  213. return &pb.LicenseList{List: info}
  214. }
  215. func (s Shop) ShopGroupAdd(token string, objectShopId int64, jsonStr string, sign string) string {
  216. optId := s.checkPermission(token, objectShopId)
  217. rst, err := postgre.PGShop{}.ShopGroupAdd(optId, objectShopId, jsonStr, sign)
  218. if err != nil {
  219. panic(errors.PGError)
  220. }
  221. return rst
  222. }
  223. func (s Shop) ShopGroupEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  224. optId := s.checkPermission(token, objectShopId)
  225. rst, err := postgre.PGShop{}.ShopGroupEdit(optId, objectShopId, jsonStr, sign)
  226. if err != nil {
  227. panic(errors.PGError)
  228. }
  229. return rst
  230. }
  231. func (s Shop) ShopGroupStatusEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  232. optId := s.checkPermission(token, objectShopId)
  233. rst, err := postgre.PGShop{}.ShopGroupStatusEdit(optId, objectShopId, jsonStr, sign)
  234. if err != nil {
  235. panic(errors.PGError)
  236. }
  237. return rst
  238. }
  239. func (s Shop) ShopGroupDetailsQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  240. optId := s.checkPermission(token, objectShopId)
  241. rst, err := postgre.PGShop{}.ShopGroupDetailsQuery(optId, objectShopId, jsonStr, sign)
  242. if err != nil {
  243. panic(errors.PGError)
  244. }
  245. return rst
  246. }
  247. func (s Shop) ShopVenueQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  248. optId := s.checkPermission(token, objectShopId)
  249. rst, err := postgre.PGShop{}.ShopVenueQuery(optId, objectShopId, jsonStr, sign)
  250. if err != nil {
  251. panic(errors.PGError)
  252. }
  253. return rst
  254. }
  255. // ShopVenueAdd 商家区域添加 @token:token
  256. func (s Shop) ShopVenueAdd(token string, objectShopId int64, jsonStr string, sign string) string {
  257. optId := s.checkPermission(token, objectShopId)
  258. rst, err := postgre.PGShop{}.ShopVenueAdd(optId, objectShopId, jsonStr, sign)
  259. if err != nil {
  260. panic(errors.PGError)
  261. }
  262. return rst
  263. }
  264. // ShopVenueEdit 商家区域编辑
  265. func (s Shop) ShopVenueEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  266. optId := s.checkPermission(token, objectShopId)
  267. rst, err := postgre.PGShop{}.ShopVenueEdit(optId, objectShopId, jsonStr, sign)
  268. if err != nil {
  269. panic(errors.PGError)
  270. }
  271. return rst
  272. }
  273. // ShopVenueStatusEdit 商家区域状态修改
  274. func (s Shop) ShopVenueStatusEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  275. optId := s.checkPermission(token, objectShopId)
  276. rst, err := postgre.PGShop{}.ShopVenueStatusEdit(optId, objectShopId, jsonStr, sign)
  277. if err != nil {
  278. panic(errors.PGError)
  279. }
  280. return rst
  281. }
  282. // ShopVenueEquipQuery 商家设备查询
  283. func (s Shop) ShopVenueEquipQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  284. optId := s.checkPermission(token, objectShopId)
  285. rst, err := postgre.PGShop{}.ShopVenueEquipQuery(optId, objectShopId, jsonStr, sign)
  286. if err != nil {
  287. panic(errors.PGError)
  288. }
  289. return rst
  290. }
  291. // ShopVenueEquipAdd 商家设备添加
  292. func (s Shop) ShopVenueEquipAdd(token string, objectShopId int64, jsonStr string, sign string) string {
  293. optId := s.checkPermission(token, objectShopId)
  294. rst, err := postgre.PGShop{}.ShopVenueEquipQuery(optId, objectShopId, jsonStr, sign)
  295. if err != nil {
  296. panic(errors.PGError)
  297. }
  298. return rst
  299. }
  300. // ShopVenueEquipEdit 商家设备编辑
  301. func (s Shop) ShopVenueEquipEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  302. optId := s.checkPermission(token, objectShopId)
  303. rst, err := postgre.PGShop{}.ShopVenueEquipEdit(optId, objectShopId, jsonStr, sign)
  304. if err != nil {
  305. panic(errors.PGError)
  306. }
  307. return rst
  308. }
  309. // ShopVenueEquipStatusEdit 商家设备状态修改
  310. func (s Shop) ShopVenueEquipStatusEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  311. optId := s.checkPermission(token, objectShopId)
  312. rst, err := postgre.PGShop{}.ShopVenueEquipStatusEdit(optId, objectShopId, jsonStr, sign)
  313. if err != nil {
  314. panic(errors.PGError)
  315. }
  316. return rst
  317. }
  318. // ShopVenueEquipStatusDel 商家设备删除
  319. func (s Shop) ShopVenueEquipStatusDel(token string, objectShopId int64, jsonStr string, sign string) string {
  320. optId := s.checkPermission(token, objectShopId)
  321. rst, err := postgre.PGShop{}.ShopVenueEquipStatusDel(optId, objectShopId, jsonStr, sign)
  322. if err != nil {
  323. panic(errors.PGError)
  324. }
  325. return rst
  326. }
  327. // ShopConfigQuery 商家配置查询
  328. func (s Shop) ShopConfigQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  329. optId := s.checkPermission(token, objectShopId)
  330. rst, err := postgre.PGShop{}.ShopConfigQuery(optId, objectShopId, jsonStr, sign)
  331. if err != nil {
  332. panic(errors.PGError)
  333. }
  334. return rst
  335. }
  336. // ShopConfigEdit 商家设备删除
  337. func (s Shop) ShopConfigEdit(token string, objectShopId int64, jsonStr string, sign string) string {
  338. optId := s.checkPermission(token, objectShopId)
  339. rst, err := postgre.PGShop{}.ShopConfigEdit(optId, objectShopId, jsonStr, sign)
  340. if err != nil {
  341. panic(errors.PGError)
  342. }
  343. return rst
  344. }
  345. // GroupSimpleQueryByShopID 商家分组简单查询-通过商家自己ID查询
  346. func (s Shop) GroupSimpleQueryByShopID(token string, objectShopId int64, jsonStr string, sign string) string {
  347. optId := s.checkPermission(token, objectShopId)
  348. rst, err := postgre.PGShop{}.GroupSimpleQuery(optId, objectShopId, jsonStr, sign)
  349. if err != nil {
  350. panic(errors.PGError)
  351. }
  352. return rst
  353. }
  354. // EqSimpleQuery 显示设备简单查询
  355. func (s Shop) EqSimpleQuery(token string, objectShopId int64, jsonStr string, sign string) string {
  356. optId := s.checkPermission(token, objectShopId)
  357. rst, err := postgre.PGShop{}.EqSimpleQuery(optId, objectShopId, jsonStr, sign)
  358. if err != nil {
  359. panic(errors.PGError)
  360. }
  361. return rst
  362. }