|
- package db
-
- import (
- "code.fnuoos.com/go_rely_warehouse/zyos_go_o2o_business.git/db/model"
- "errors"
- "xorm.io/xorm"
- )
-
- func UpdateMerchant(engine *xorm.Engine, merchant *model.O2oMerchant) error {
- update, err := engine.ID(merchant.Id).AllCols().Update(merchant)
- if err != nil || update == 0 {
- if err == nil {
- err = errors.New("更新数据异常!")
- }
- return err
- }
- return nil
- }
-
- func MerchantExistByPhoneAndPassword(Db *xorm.Engine, username string, password string) (bool, error) {
-
- has, err := Db.Where("phone = ? AND password = ?", username, password).Exist(&model.O2oMerchant{})
-
- if err != nil {
- return false, err
- }
- return has, nil
- }
-
- func MerchantFindByMobileOrId(Db *xorm.Engine, mobileOrId string) (*model.O2oMerchant, error) {
- var m model.O2oMerchant
- if has, err := Db.Where("(phone = ? OR id = ?)", mobileOrId, mobileOrId).
- Get(&m); err != nil || has == false {
- return nil, err
- }
- return &m, nil
- }
-
- func MerchantUpdateWithSession(sess *xorm.Session, merchant *model.O2oMerchant, forceCols ...string) (int64, error) {
- var (
- affected int64
- err error
- )
- if forceCols != nil {
- affected, err = sess.Where("id = ?", merchant.Id).Cols(forceCols...).Update(merchant)
- } else {
- affected, err = sess.Where("id = ?", merchant.Id).Update(merchant)
- }
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
- func MerchantFindByUId(Db *xorm.Engine, uid string) (*model.O2oMerchant, error) {
- var m model.O2oMerchant
- if has, err := Db.Where("uid = ?", uid).
- Get(&m); err != nil || has == false {
- return nil, err
- }
- return &m, nil
- }
-
- // UserisExistByMobile is exist
- func MerchantExistByMobile(Db *xorm.Engine, n string) (bool, error) {
- has, err := Db.Where("phone = ?", n).Exist(&model.O2oMerchant{})
-
- if err != nil {
- return false, err
- }
- return has, nil
- }
-
- // MerchantGetByMobileIgnoreDelete search merchant by mobile ignore delete
- func MerchantGetByMobileIgnoreDelete(Db *xorm.Engine, mobile string) (*model.O2oMerchant, bool, error) {
- m := new(model.O2oMerchant)
- has, err := Db.Where("phone = ?", mobile).Get(m)
- if err != nil {
- return nil, false,err
- }
- return m, has, nil
- }
-
- func MerchantUpdate(Db *xorm.Engine, merchant *model.O2oMerchant, forceCols ...string) (int64, error) {
- var (
- affected int64
- err error
- )
- if forceCols != nil {
- affected, err = Db.ID(merchant.Id).Cols(forceCols...).Update(merchant)
- } else {
- affected, err = Db.ID(merchant.Id).Update(merchant)
- }
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
-
- //MerchantInsert is insert user
- func MerchantInsert(Db *xorm.Engine, user *model.O2oMerchant) (int64, error) {
- affected, err := Db.Insert(user)
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
-
- // MerchantDelete is delete user
- func MerchantDelete(Db *xorm.Engine, uid interface{}) (int64, error) {
- return Db.ID(uid).Delete(model.O2oMerchant{})
- }
|