123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- package wechat
-
- import (
- "wechat-conf/models"
- "wechat-conf/models/model"
- "wechat-conf/utils"
-
- "github.com/astaxie/beego"
- "github.com/go-xorm/xorm"
- )
-
- // WechatDAO 当前数据库操作对象
- type WechatDAO struct {
- ctx *utils.Context
- db *xorm.Session
- }
-
- // NewWechatDAO New Inst
- func NewWechatDAO(ctx *utils.Context) *WechatDAO {
- return &WechatDAO{
- ctx: ctx,
- db: ctx.DB,
- }
- }
-
- // GetWechatConfByAppID 根据appid获取配置信息
- func (m *WechatDAO) GetWechatConfByAppID(appid string) (*model.SysWechatConf, error) {
- var conf model.SysWechatConf
- _, err := m.db.Where("appid=?", appid).And("status>?", models.STATUS_DEL).Get(&conf)
- return &conf, err
- }
-
- // AddWechatConf 保存微信配置信息
- func (m *WechatDAO) AddWechatConf(conf model.SysWechatConf) error {
- conf.ConfId = utils.GetGUID()
- conf.Status = models.STATUS_READY
- _, err := m.db.Insert(conf)
- return err
- }
-
- // UpdateWechatConf 更新微信配置信息
- func (m *WechatDAO) UpdateWechatConf(conf model.SysWechatConf, cols []string) error {
- _, err := m.db.Cols(cols...).Where("conf_id = ?", conf.ConfId).Update(conf)
- return err
- }
-
- // SaveWechatConf 保存微信配置
- func (m *WechatDAO) SaveWechatConf(conf model.SysWechatConf) error {
- // wechatConf, err := m.GetWechatConfByAppID(conf.Appid)
- // if err != nil {
- // utils.LogError("根据appid获取微信配置失败:", err)
- // return err
- // }
- // if wechatConf != nil && wechatConf.ConfId != "" {
- // // 修改
- // beego.Error("修改wechatConf,", conf)
- // conf.ConfId = wechatConf.ConfId
- // var cols = []string{
- // "refresh_token",
- // "token",
- // }
- // if conf.AuthorizationInfo != "" {
- // cols = append(cols, "authorization_info")
- // }
- // err := m.UpdateWechatConf(conf, cols)
- // if err != nil {
- // utils.LogError("修改微信配置失败:", err)
- // return err
- // }
- // } else {
- // // 新增
- beego.Error("开始新增:", conf)
- err := m.AddWechatConf(conf)
- if err != nil {
- utils.LogError("新增微信配置失败:", err)
- return err
- }
- // }
- return nil
- }
-
- // GetComponentInfo 获取第三方conf
- func (m *WechatDAO) GetComponentInfo() (*model.SysComponentConf, error) {
- var conf = model.SysComponentConf{}
- _, err := m.db.Get(&conf)
- return &conf, err
- }
-
- // UpdateComponentTicket 更新第三方ticket
- func (m *WechatDAO) UpdateComponentTicket(conf *model.SysComponentConf) error {
- _, err := m.db.Cols([]string{
- "ticket",
- }...).Where("appid = ?", conf.Appid).Update(conf)
- return err
- }
-
- // GetWxByCode 根据code获取微信信息
- func (m *WechatDAO) GetWxByCode(code string) (*model.SysWechatConf, error) {
- var conf model.SysWechatConf
- _, err := m.db.Where("authorization_code=?", code).And("status>?", models.STATUS_DEL).Get(&conf)
- return &conf, err
- }
-
- // GetWechatConfByConfId 根据confid获取微信信息
- func (m *WechatDAO) GetWechatConfByConfId(confid string) (*model.SysWechatConf, error) {
- var conf model.SysWechatConf
- _, err := m.db.Where("conf_id=?", confid).And("status>?", models.STATUS_DEL).Get(&conf)
- return &conf, err
- }
-
- // DelWechatConf 删除微信信息
- func (m *WechatDAO) DelWechatConf(confid string) error {
- sql := `delete from sys_wechat_conf where conf_id=?`
- _, err := m.db.Exec(sql, confid)
- return err
- }
|