|
@@ -3,7 +3,10 @@ package cron_controller
|
|
|
import (
|
|
import (
|
|
|
"crypto/md5"
|
|
"crypto/md5"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
|
|
+ "fohow.com/apps/helpers"
|
|
|
|
|
+ "github.com/go-redis/redis"
|
|
|
"io"
|
|
"io"
|
|
|
|
|
+ "strconv"
|
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
|
"fohow.com/apps/models/balance_model"
|
|
"fohow.com/apps/models/balance_model"
|
|
@@ -72,3 +75,66 @@ func takeCash() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+//自动提现打款的定时任务
|
|
|
|
|
+func autoTakeCash() {
|
|
|
|
|
+ db, err := beego.AppConfig.Int("AliRedisDb")
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ beego.BeeLogger.Error("%s", err)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ client := redis.NewClient(&redis.Options{
|
|
|
|
|
+ Addr: beego.AppConfig.String("AliRedisHost"),
|
|
|
|
|
+ Password: beego.AppConfig.String("AliRedisPwd"), //默认空密码
|
|
|
|
|
+ DB: db, //使用默认数据库
|
|
|
|
|
+ })
|
|
|
|
|
+ beego.BeeLogger.Info("take Cash Connect redis name (%s), pwd=%s", beego.AppConfig.String("AliRedisHost"), beego.AppConfig.String("AliRedisPwd"))
|
|
|
|
|
+ defer client.Close() //最后关闭
|
|
|
|
|
+ cashKey := helpers.GetAutoTakeCashList()
|
|
|
|
|
+ list, _ := client.LRange(cashKey, -1000, -1).Result()
|
|
|
|
|
+ for _, takeId := range list {
|
|
|
|
|
+ id, err := strconv.ParseInt(takeId, 10, 64)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ //提现记录状态判断
|
|
|
|
|
+ cashRecord := balance_model.GetTakeCashOrderById(id, false)
|
|
|
|
|
+ //已支付或记录不存在,剔除队列
|
|
|
|
|
+ if cashRecord == nil || cashRecord.State == 1 {
|
|
|
|
|
+ helpers.ThrowOutRedisList(cashKey, takeId)
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ //未审批或者不达处理时间不提现,则下次处理
|
|
|
|
|
+ if cashRecord.AuditState < 1 || cashRecord.ExpcPayAt.Unix() > time.Now().Unix() {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ //微信提现处理
|
|
|
|
|
+ wxUser := user_model.GetWxUserById(cashRecord.WxUId, false)
|
|
|
|
|
+ if wxUser == nil {
|
|
|
|
|
+ beego.BeeLogger.Error("Take cash wxUser[%d] is not exist", cashRecord.WxUId)
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ user := user_model.GetUserById(wxUser.UserId, false)
|
|
|
|
|
+ if user == nil {
|
|
|
|
|
+ beego.BeeLogger.Error("Take cash User[%d] is not exist", wxUser.UserId)
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ var check_state string
|
|
|
|
|
+ check_state = wx_mp.PAY_NO_CHECK
|
|
|
|
|
+ ret := wx_mp.Transfers(wxUser.Openid, cashRecord.Count, cashRecord.OrderId, check_state, user.RealName, "提现")
|
|
|
|
|
+ if ret["result_code"] == wx_mp.PAY_SUCCESS {
|
|
|
|
|
+ cashRecord.State = 1
|
|
|
|
|
+ cashRecord.TradeNo = ret["payment_no"]
|
|
|
|
|
+ // paiedAt, _ := time.Parse("2006-01-02 15:04:05", ret["payment_time"])
|
|
|
|
|
+ cashRecord.Remark = "提现已打款"
|
|
|
|
|
+ cashRecord.PaiedAt = time.Now().Unix()
|
|
|
|
|
+ cashRecord.Save()
|
|
|
|
|
+ //提现成功,剔除队列
|
|
|
|
|
+ helpers.ThrowOutRedisList(cashKey, takeId)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ cashRecord.State = 2
|
|
|
|
|
+ cashRecord.Remark = ret["err_code_des"]
|
|
|
|
|
+ cashRecord.Save()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|