bm.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package one
  2. import (
  3. "errors"
  4. "zhiyuan/models"
  5. "zhiyuan/pkg/app"
  6. "zhiyuan/pkg/db"
  7. "zhiyuan/services/admin"
  8. "zhiyuan/services/form"
  9. )
  10. var Bm models.ActivityOneBm
  11. func AddBm(f form.ActivityBmForm) (int64, error) {
  12. if bmInfo, _ := Bm.GetOne(map[string]interface{}{"user_id": f.UserID, "act_id": f.ActID}, nil, nil); bmInfo != nil {
  13. return 0, errors.New("每个微信号只能报名一次")
  14. }
  15. if bmInfo, _ := Bm.GetOne(map[string]interface{}{"phone": f.Phone, "act_id": f.ActID}, nil, nil); bmInfo != nil {
  16. return 0, errors.New("每个手机号只能报名一次")
  17. }
  18. if f.RefID > 0 {
  19. if _, err := admin.GetInfoByID(f.RefID, nil, nil); err != nil {
  20. f.RefID = 0
  21. }
  22. }
  23. bmMap := map[string]interface{}{
  24. "user_id": f.UserID,
  25. "name": f.Name,
  26. "phone": f.Phone,
  27. "act_id": f.ActID,
  28. "ref_id": f.RefID,
  29. }
  30. return db.InsertOne(Bm.TableName(), bmMap)
  31. }
  32. func CountBm(where map[string]interface{}) (int64, error) {
  33. return db.Count(Bm.TableName(), where)
  34. }
  35. func GetBms(where map[string]interface{}, fields []string, page app.Page, retVal interface{}) ([]*models.ActivityOneBm, error) {
  36. if page.PageNum > 0 && page.PageSize > 0 {
  37. where["_limit"] = db.GetOffset(uint(page.PageNum), uint(page.PageSize))
  38. }
  39. return Bm.GetMulti(where, fields, retVal)
  40. }