12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package one
- import (
- "errors"
- "zhiyuan/models"
- "zhiyuan/pkg/app"
- "zhiyuan/pkg/db"
- "zhiyuan/services/admin"
- "zhiyuan/services/form"
- )
- var Bm models.ActivityOneBm
- func AddBm(f form.ActivityBmForm) (int64, error) {
- if bmInfo, _ := Bm.GetOne(map[string]interface{}{"user_id": f.UserID, "act_id": f.ActID}, nil, nil); bmInfo != nil {
- return 0, errors.New("每个微信号只能报名一次")
- }
- if bmInfo, _ := Bm.GetOne(map[string]interface{}{"phone": f.Phone, "act_id": f.ActID}, nil, nil); bmInfo != nil {
- return 0, errors.New("每个手机号只能报名一次")
- }
- if f.RefID > 0 {
- if _, err := admin.GetInfoByID(f.RefID, nil, nil); err != nil {
- f.RefID = 0
- }
- }
- bmMap := map[string]interface{}{
- "user_id": f.UserID,
- "name": f.Name,
- "phone": f.Phone,
- "act_id": f.ActID,
- "ref_id": f.RefID,
- }
- return db.InsertOne(Bm.TableName(), bmMap)
- }
- func CountBm(where map[string]interface{}) (int64, error) {
- return db.Count(Bm.TableName(), where)
- }
- func GetBms(where map[string]interface{}, fields []string, page app.Page, retVal interface{}) ([]*models.ActivityOneBm, error) {
- if page.PageNum > 0 && page.PageSize > 0 {
- where["_limit"] = db.GetOffset(uint(page.PageNum), uint(page.PageSize))
- }
- return Bm.GetMulti(where, fields, retVal)
- }
|