123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package accounting
- import (
- "context"
- "encoding/json"
- "fmt"
- "gd_management/apis"
- "gd_management/common.in/config"
- "gd_management/common.in/storage"
- "gd_management/common.in/utils"
- "gd_management/errors"
- "gd_management/thirdparty"
- "github.com/astaxie/beego/orm"
- "github.com/tidwall/gjson"
- "go.uber.org/zap"
- "time"
- )
- func RobotMsg(content string) (err error) {
- body := map[string]interface{}{
- "msgtype": "text",
- "text": map[string]interface{}{"content": content},
- }
- bytes, _ := json.Marshal(body)
- h := thirdparty.HttpRequestWithHeadCommon{
- Method: "POST",
- Url: config.Conf.ThirdPart.RobotUrl,
- Body: bytes,
- TimeOut: 10 * time.Second,
- }
- bytes, err = h.Request()
- if err != nil {
- l.Error("func",
- zap.String("call", "RobotMsg"),
- zap.String("params", content),
- zap.String("error", err.Error()))
- return errors.VendorError
- }
- errcode := gjson.GetBytes(bytes, "errcode").Int()
- errmsg := gjson.GetBytes(bytes, "errmsg").String()
- if errcode != 0 {
- l.Error("func",
- zap.String("call", "RobotMsg"),
- zap.String("params", content),
- zap.String("error", errmsg))
- return errors.VendorError
- }
- return nil
- }
- func BillConfirm(ctx context.Context, req *apis.BillConfirmReq, reply *apis.BillConfirmReply) error {
- // update t_gd_merchants set merchant_type=1 where id=8
- if req.Uid == 0 || req.BillId == 0 {
- return errors.ArgsError
- }
- task := func(o orm.Ormer) error {
- sql := fmt.Sprintf("update t_gd_bill set bill_status=1,uid=%d where id=%d", req.Uid, req.BillId)
- _, err := o.Raw(sql).Exec()
- if err != nil {
- l.Error("func",
- zap.String("call", "BillConfirm"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.DataBaseError
- }
- month := ""
- merchantId := int64(0)
- sql = "select bill_time,merchant_id from t_gd_bill where id=?"
- err = o.Raw(sql, req.BillId).QueryRow(&month, &merchantId)
- if err != nil {
- l.Error("func",
- zap.String("call", "BillConfirm"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.DataBaseError
- }
- merhcnatName := ""
- sql = "select merchant_name from t_gd_merchants where id=?"
- err = o.Raw(sql, merchantId).QueryRow(&merhcnatName)
- if err != nil {
- l.Error("func",
- zap.String("call", "BillConfirm"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.DataBaseError
- }
- // 发送企业微信消息(注册)
- //d := ding.Webhook{AccessToken: config.Conf.ThirdPart.DingDing.AccessToken, Secret: config.Conf.ThirdPart.DingDing.Secret}
- msg := fmt.Sprintf("用户(%s)已确认%s(月份)账单,请关注。", merhcnatName, month)
- _ = RobotMsg(msg)
- //_ = d.SendMessage(msg)
- return nil
- }
- tasks := []storage.DbaTasker{}
- tasks = append(tasks, storage.GenerateDbaTask(task))
- storage.ExecTrans(tasks...)
- //l.Debug(utils.MarshalJsonString(req, reply))
- return nil
- }
|