package task import ( "q5" "f5" "main/constant" "main/service" "fmt" "jccommon" ) type recharge struct { } func (this *recharge) init() { go this.process() } func (this *recharge) unInit() { } func (this *recharge) process() { f5.GetGoStyleDb().LoopLoadNew( constant.BCNFT_DB, "recharge_order", "t_recharge_order", 0, func (lastIdx int64, maxIdx int64) (string, []string) { sql := fmt.Sprintf(` SELECT * FROM t_recharge_order WHERE idx > %d AND idx <= %d AND pay_status = %d AND delivery_status = %d ORDER BY idx LIMIT 1000 `, lastIdx, maxIdx, jccommon.RECHARGE_ORDER_PAY_STATUS_OK, jccommon.RECHARGE_ORDER_DELIVERY_STATUS_PENDING) params := []string{ } return sql, params }, this.deliverGoods) } func (this *recharge) deliverGoods(ds *f5.DataSet) bool { idx := q5.ToInt64(ds.GetByName("idx")) orderId := ds.GetByName("order_id") shortOrderId := q5.ToInt64(ds.GetByName("short_order_id")) passportAddress := ds.GetByName("passport_address") srcDiamond := q5.ToInt64(ds.GetByName("diamond")) presentDiamond := q5.ToInt64(ds.GetByName("present_diamond")) returnContribution := q5.ToFloat64(ds.GetByName("return_contribution")) netId := q5.ToInt32(ds.GetByName("net_id")) payTime := q5.ToInt32(ds.GetByName("pay_time")) email := ds.GetByName("lower_case_email") diamond := srcDiamond + presentDiamond accountId := "" userIdentity := "" if email != "" { userIdentity = email accountId = service.GetAccountIdByEmail(email) } else { userIdentity = passportAddress accountId = service.GetAccountIdByAddress(passportAddress) } if accountId == "" { return true } if !service.AccountIdExistsAndIgnoreError(accountId) { return true } if this.markOk(idx, accountId) != nil { return true } if returnContribution > 0.0 { if this.returnContribution(netId, shortOrderId, userIdentity, returnContribution, payTime) != nil { return true } } service.UserAddDiamond(accountId, diamond, netId, orderId) return true } func (this *recharge) markOk(idx int64, deliveryAccountId string) error { var resultErr error f5.GetGoStyleDb().Update( constant.BCNFT_DB, "t_recharge_order", [][]string{ {"idx", q5.ToString(idx)}, }, [][]string{ {"delivery_status", q5.ToString(jccommon.RECHARGE_ORDER_DELIVERY_STATUS_OK)}, {"delivery_time", q5.ToString(f5.GetApp().GetRealSeconds())}, {"receiver_account_id", deliveryAccountId}, }, func (err error, lastInsertId int64, rowsAffected int64) { resultErr = err }) return resultErr } func (this *recharge) returnContribution(netId int32, shortOrderId int64, userIdentity string, contribution float64, payTime int32) error { var resultErr error f5.GetGoStyleDb().Upsert( constant.BCNFT_DB, "t_recharge_return_contribution", [][]string{ }, [][]string{ }, [][]string{ {"delivery_status", q5.ToString(jccommon.RECHARGE_ORDER_DELIVERY_STATUS_OK)}, {"delivery_time", q5.ToString(f5.GetApp().GetRealSeconds())}, }, func (err error, lastInsertId int64, rowsAffected int64) { resultErr = err }) return resultErr }