附近小店
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

189 rivejä
5.5 KiB

  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/md"
  5. "applet/app/utils"
  6. "applet/app/utils/logx"
  7. "time"
  8. "xorm.io/xorm"
  9. )
  10. func GetPrinterIndexAll(Db *xorm.Engine, storeId string) ([]model.CommunityTeamStorePrinter, error) {
  11. var list []model.CommunityTeamStorePrinter
  12. session := Db.Where("store_id= ? ", storeId)
  13. //排序
  14. err := session.Desc("create_time").Find(&list)
  15. if err != nil {
  16. return nil, err
  17. }
  18. return list, err
  19. }
  20. func GetPrinterIndexById(Db *xorm.Engine, id, storeId string) (*model.CommunityTeamStorePrinter, error) {
  21. var list model.CommunityTeamStorePrinter
  22. session := Db.Where("id=? and store_id=?", id, storeId)
  23. //排序
  24. has, err := session.Desc("create_time").Get(&list)
  25. if has == false || err != nil {
  26. return nil, err
  27. }
  28. return &list, err
  29. }
  30. func GetPrinterIndexByBluetooth(Db *xorm.Engine, storeId string) (*model.CommunityTeamStorePrinter, error) {
  31. var list model.CommunityTeamStorePrinter
  32. session := Db.Where("type=? and store_id=?", "bluetooth", storeId)
  33. //排序
  34. has, err := session.Desc("create_time").Get(&list)
  35. if has == false || err != nil {
  36. return nil, err
  37. }
  38. return &list, err
  39. }
  40. // 分页查询方案
  41. func GetPrinterIndexList(Db *xorm.Engine, parameter *md.IndexRequest) ([]md.IndexResList, error) {
  42. var list []model.CommunityTeamStorePrinter
  43. var webList []md.IndexResList
  44. session := Db.Where("store_id= ? ", parameter.StoreId)
  45. //分页
  46. if utils.StrToInt(parameter.P) > 0 && utils.StrToInt(parameter.PageSize) > 0 {
  47. session = session.Limit(utils.StrToInt(parameter.PageSize), (utils.StrToInt(parameter.P)-1)*utils.StrToInt(parameter.PageSize))
  48. }
  49. //排序
  50. err := session.Desc("create_time").Find(&list)
  51. if err != nil {
  52. return nil, err
  53. }
  54. var typeList = map[string]string{
  55. "ordinary": "普通打印机",
  56. "cloud": "云打印机",
  57. "bluetooth": "蓝牙打印机",
  58. }
  59. var locationTypeList = map[string]string{
  60. "reception": "前台",
  61. "kitchen": "后厨",
  62. }
  63. for _, v := range list {
  64. var tmp = md.IndexResList{
  65. Id: utils.IntToStr(v.Id),
  66. Name: v.Name,
  67. IsUse: utils.IntToStr(v.IsUse),
  68. StoreId: utils.IntToStr(v.StoreId),
  69. SnNum: v.SnNum,
  70. IdentificationCode: v.IdentificationCode,
  71. ModuleId: utils.IntToStr(v.ModuleId),
  72. Type: v.Type,
  73. TypeStr: typeList[v.Type],
  74. LocationType: v.LocationType,
  75. LocationTypeStr: locationTypeList[v.LocationType],
  76. }
  77. webList = append(webList, tmp)
  78. }
  79. return webList, nil
  80. }
  81. func indexGetCount(Db *xorm.Engine, parameter *md.IndexRequest) int {
  82. var ord model.CommunityTeamStorePrinter
  83. session := Db.Where("store_id= ? ", parameter.StoreId)
  84. count, err := session.Count(&ord)
  85. if err != nil {
  86. return 0
  87. }
  88. return int(count)
  89. }
  90. func IndexExists(Db *xorm.Engine, parameter *md.IndexSaveRequest) int {
  91. var ord model.CommunityTeamStorePrinter
  92. session := Db.Where("sn_num= ? ", parameter.SnNum)
  93. count, err := session.Count(&ord)
  94. if err != nil {
  95. return 0
  96. }
  97. return int(count)
  98. }
  99. func IndexById(Db *xorm.Engine, parameter *md.IndexSaveRequest) (*model.CommunityTeamStorePrinter, error) {
  100. var ord model.CommunityTeamStorePrinter
  101. session := Db.Where("id= ? ", parameter.Id)
  102. _, err := session.Get(&ord)
  103. return &ord, err
  104. }
  105. // 写入数据
  106. func IndexInsert(eg *xorm.Engine, m *model.CommunityTeamStorePrinter) (int64, error) {
  107. if m.Id > 0 { //编辑
  108. id, err := IndexUpdate(eg, m, "type,is_use,sn_num,identification_code,name,update_time,location_type")
  109. if id == 0 || err != nil {
  110. return 0, logx.Warn("cannot insert data :", err)
  111. }
  112. return id, nil
  113. }
  114. m.CreateTime = time.Now()
  115. //写入
  116. id, err := eg.InsertOne(m)
  117. if id == 0 || err != nil {
  118. return 0, logx.Warn("cannot insert data :", err)
  119. }
  120. return id, nil
  121. }
  122. // 修改数据
  123. func IndexUpdate(eg *xorm.Engine, m *model.CommunityTeamStorePrinter, cols ...string) (int64, error) {
  124. update, err := eg.ID(m.Id).Cols(cols...).Update(m)
  125. if err != nil || update == 0 {
  126. return int64(m.Id), err
  127. }
  128. return int64(m.Id), nil
  129. }
  130. // 分页查询打印明细
  131. func GetPrinterRecordList(Db *xorm.Engine, parameter *md.RecordRequest) ([]md.RecordResList, error) {
  132. var list []model.CommunityTeamStorePrinterDetail
  133. var webList []md.RecordResList
  134. session := Db.Where("store_id >0 and store_id=?", parameter.StoreId)
  135. if utils.StrToInt(parameter.PrinterId) > 0 {
  136. session.And("printer_id=? ", parameter.PrinterId)
  137. }
  138. if parameter.StartTime != "" {
  139. session.And("create_time>=? ", parameter.StartTime)
  140. }
  141. if parameter.EndTime != "" {
  142. session.And("create_time<=? ", parameter.EndTime)
  143. }
  144. //分页
  145. if utils.StrToInt(parameter.P) > 0 && utils.StrToInt(parameter.PageSize) > 0 {
  146. session = session.Limit(utils.StrToInt(parameter.PageSize), (utils.StrToInt(parameter.P)-1)*utils.StrToInt(parameter.PageSize))
  147. }
  148. //排序
  149. if parameter.Sort == "printer_time_desc" {
  150. session.Desc("create_time")
  151. } else if parameter.Sort == "printer_time_asc" {
  152. session.Asc("create_time")
  153. } else {
  154. session.Desc("id")
  155. }
  156. //排序
  157. err := session.Find(&list)
  158. if err != nil {
  159. return nil, err
  160. }
  161. for _, v := range list {
  162. var tmp = md.RecordResList{
  163. Id: utils.IntToStr(v.Id),
  164. OrdId: v.OrdId,
  165. OrdType: utils.IntToStr(v.OrdType),
  166. PrintContent: v.PrintContent,
  167. State: utils.IntToStr(v.State),
  168. PrintTime: v.PrintTime.Format("2006-01-02 15:04:05"),
  169. CreateTime: v.CreateTime.Format("2006-01-02 15:04:05"),
  170. }
  171. if tmp.PrintTime == "0001-01-01 00:00:00" {
  172. tmp.PrintTime = ""
  173. }
  174. webList = append(webList, tmp)
  175. }
  176. return webList, nil
  177. }