智慧食堂-队列消费项目
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.

db_shipping_template.go 2.1 KiB

2 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package db
  2. import (
  3. "applet/supply/db/model"
  4. "applet/supply/md"
  5. "errors"
  6. "xorm.io/xorm"
  7. )
  8. func GetMallShippingTemplateList(eg *xorm.Engine, req md.MallShippingTemplateListReq) ([]*model.MallShippingTemplate, int64, error) {
  9. var list []*model.MallShippingTemplate
  10. sess := eg.NewSession()
  11. if req.MerchantId != 0 {
  12. sess.Where("merchant_id = ?", req.MerchantId)
  13. }
  14. if req.Name != "" {
  15. sess.Where("name LIKE ?", "'%"+req.Name+"%'")
  16. }
  17. if req.CalculateType != 0 {
  18. sess.Where("calculate_type = ?", req.CalculateType)
  19. }
  20. if req.P == 0 || req.PSize == 0 {
  21. req.P = 1
  22. req.PSize = 10
  23. }
  24. count, err := sess.Limit(req.PSize, (req.P-1)*req.PSize).FindAndCount(&list)
  25. if err != nil {
  26. return nil, 0, err
  27. }
  28. return list, count, nil
  29. }
  30. func GetMallShippingTemplateById(eg *xorm.Engine, templateId int) (*model.MallShippingTemplate, error) {
  31. var m model.MallShippingTemplate
  32. has, err := eg.Where("id = ?", templateId).Get(&m)
  33. if err != nil {
  34. return nil, err
  35. }
  36. if !has {
  37. return nil, errors.New("没有找到相应的运费模板")
  38. }
  39. return &m, nil
  40. }
  41. func GetMallShippingTemplateByColumn(eg *xorm.Engine, column string, value interface{}) (*model.MallShippingTemplate, error) {
  42. var m model.MallShippingTemplate
  43. sql := "\"" + column + " = ?\""
  44. has, err := eg.Where(sql, value).Get(&m)
  45. if err != nil {
  46. return nil, err
  47. }
  48. if !has {
  49. return nil, errors.New("没有找到相应的运费模板")
  50. }
  51. return &m, nil
  52. }
  53. func InsertOneMallShippingTemplate(eg *xorm.Engine, m *model.MallShippingTemplate) error {
  54. affected, err := eg.InsertOne(m)
  55. if err != nil {
  56. return err
  57. }
  58. if affected == 0 {
  59. return errors.New("插入运费模板数据失败,稍后再试")
  60. }
  61. return nil
  62. }
  63. func UpdateMallShippingTemplateById(eg *xorm.Engine, m *model.MallShippingTemplate, columns ...string) error {
  64. var (
  65. affected int64
  66. err error
  67. )
  68. if columns == nil || len(columns) == 0 {
  69. affected, err = eg.Where("id = ?", m.Id).AllCols().Update(m)
  70. } else {
  71. affected, err = eg.Where("id = ?", m.Id).Cols(columns...).Update(m)
  72. }
  73. if err != nil {
  74. return err
  75. }
  76. if affected == 0 {
  77. return errors.New("插入运费模板数据失败,稍后再试")
  78. }
  79. return nil
  80. }