审查视图

pkg/infrastructure/dao/pg_partner_info_dao.go 1.6 KB
.  
tangxvhui authored
1 2 3 4
package dao

import (
	"fmt"
5
	"github.com/go-pg/pg/v10"
.  
tangxvhui authored
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
	"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
	"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)

type PartnerInfoDao struct {
	transactionContext *transaction.TransactionContext
}

func NewPartnerInfoDao(transactionContext *transaction.TransactionContext) (*PartnerInfoDao, error) {
	if transactionContext == nil {
		return nil, fmt.Errorf("transactionContext参数不能为nil")
	} else {
		return &PartnerInfoDao{
			transactionContext: transactionContext,
		}, nil
	}
}
唐旭辉 authored
24
func (dao PartnerInfoDao) PartnerAccountExist(account string, companyId int64) (bool, error) {
.  
tangxvhui authored
25 26 27 28
	tx := dao.transactionContext.PgDd
	m := &models.PartnerInfo{}
	ok, err := tx.Model(m).
		Where("account=?", account).
唐旭辉 authored
29
		Where("company_id=?", companyId).
.  
tangxvhui authored
30 31 32
		Exists()
	return ok, err
}
唐旭辉 authored
33 34 35 36 37 38 39 40 41 42 43

func (dao PartnerInfoDao) UpdatePartnerStatus(ids []int64, companyId int64, status int) error {
	tx := dao.transactionContext.PgDd
	m := &models.PartnerInfo{}
	_, err := tx.Model(m).
		WhereIn("id in (?)", ids).
		Where("company_id=?", companyId).
		Set("status=?", status).
		Update()
	return err
}
44 45 46

/**
 * @Author SteveChan
47
 * @Description // 编号查重
48 49 50 51
 * @Date 17:55 2020/12/28
 * @Param
 * @return
 **/
52 53 54 55 56 57 58 59 60
func (dao PartnerInfoDao) PartnerCodeExist(categoryId int64, code string, companyId int64, id int64) (bool, error) {
	tx := dao.transactionContext.PgDd
	m := &models.PartnerInfo{}
	ok, err := tx.Model(m).
		Where(`partner_category_infos@> '[{"id":?,"code":?}]'`, categoryId, pg.Ident(code)).
		Where("company_id=?", companyId).
		Where("id <> ?", id).
		Exists()
	return ok, err
61
}