|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- package db
-
- import (
- "code.fnuoos.com/go_rely_warehouse/zyos_go_o2o_business.git/db/model"
- zhios_o2o_business_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_o2o_business.git/utils/logx"
- "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, zhios_o2o_business_logx.Warn(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, zhios_o2o_business_logx.Warn(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, zhios_o2o_business_logx.Warn(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, zhios_o2o_business_logx.Warn(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{})
- }
|