| | |
| | | import os.path
|
| | | import zipfile
|
| | | import time
|
| | | import traceback
|
| | |
|
| | | # get: request.query.username request.GET.get('username','')
|
| | | # post: request.forms.get('username') request.POST.get('username')
|
| | |
| | | # GM端口
|
| | | PushPort = ConfigIO.GetValue("Coupon", "PushPort")
|
| | | PushKey = ConfigIO.GetValue("Coupon", "PushKey")
|
| | | PushTimeout = ConfigIO.GetInt("Coupon", "PushTimeout", 5)
|
| | | CommonCards = eval(ConfigIO.GetValue("Coupon", "CommonCards"))
|
| | |
|
| | | # 发放奖励邮件内容json,utf8编码
|
| | |
| | | if msgEx:
|
| | | errmsg = "%s : %s" % (errmsg, msgEx)
|
| | | resData = {"errcode":errcode, "errmsg":errmsg}
|
| | | mylog.debug("resData: %s" % str(resData))
|
| | | #mylog.info("resData: %s" % str(resData))
|
| | | if errcode != ErrCode_OK:
|
| | | mylog.error("resError: %s" % str(resData))
|
| | | else:
|
| | | mylog.debug("resData: %s" % str(resData))
|
| | | #mylog.info("resData: %s" % str(resData))
|
| | | return json.dumps(resData, ensure_ascii=False)
|
| | |
|
| | |
|
| | |
| | | result, commondata = dbController.find_one(CouponDB.CouponCodeColName + "_Common", {"code":codeStr, "accid":accid})
|
| | | if commondata:
|
| | | # 已使用
|
| | | return SendGm(ErrCode_Used, gmresult, pushurl)
|
| | | return SendGm(ErrCode_Used, gmresult, pushurl)[1]
|
| | |
|
| | | commCheckStatus = CommCheck(dataDict, codeStr)
|
| | | if commCheckStatus != None:
|
| | | return SendGm(commCheckStatus, gmresult, pushurl)
|
| | | return SendGm(commCheckStatus, gmresult, pushurl)[1]
|
| | |
|
| | | gmresult['code'] = codeStr
|
| | | gmresult['coupontype'] = codeStr # 统一格式,服务器不一定有用,固定码根据 codeStr 发奖励
|
| | |
|
| | | dbController.insert(CouponDB.CouponCodeColName + "_Common", {"code":codeStr, "accid":accid})
|
| | | mylog.debug("common ok")
|
| | | return SendGm(ErrCode_OK, gmresult, pushurl)
|
| | | retCode, retMsg = SendGm(ErrCode_OK, gmresult, pushurl)
|
| | | if retCode == ErrCode_OK:
|
| | | dbController.insert(CouponDB.CouponCodeColName + "_Common", {"code":codeStr, "accid":accid})
|
| | | mylog.debug("common ok")
|
| | | return retMsg
|
| | |
|
| | | #-----------微信商城----------------------
|
| | | if codeStr.startswith('wx'):
|
| | |
| | |
|
| | | if int(wxdata['status']) == 1:
|
| | | mylog.debug("wxcard used!")
|
| | | return SendGm(ErrCode_Used, gmresult, pushurl)
|
| | | return SendGm(ErrCode_Used, gmresult, pushurl)[1]
|
| | |
|
| | | wxdata['status'] = 1
|
| | | wxdata['accid'] = dataDict.get("accid", "") # 此处用原始账号
|
| | |
| | | if not data:
|
| | | #无此卡
|
| | | mylog.debug("no card")
|
| | | return SendGm(ErrCode_Invalid, gmresult, pushurl)
|
| | | return SendGm(ErrCode_Invalid, gmresult, pushurl)[1]
|
| | | if int(data['status']) == 1:
|
| | | #已使用,同卡号记录默认可用,避免断线发送失败的情况(未返回结果验证情况下)
|
| | | mylog.debug("card used!")
|
| | | return SendGm(ErrCode_Used, gmresult, pushurl)
|
| | | return SendGm(ErrCode_Used, gmresult, pushurl)[1]
|
| | |
|
| | | couponType = data["coupontype"]
|
| | | commCheckStatus = CommCheck(dataDict, data["coupontype"])
|
| | | if commCheckStatus != None:
|
| | | return SendGm(commCheckStatus, gmresult, pushurl)
|
| | | return SendGm(commCheckStatus, gmresult, pushurl)[1]
|
| | |
|
| | | result, data2 = dbController.find_one(CouponDB.CouponBatchColName, {"couponid":data["couponid"]})
|
| | | if not data2:
|
| | | #此批次卡已删除
|
| | | mylog.debug("no couponid")
|
| | | return SendGm(ErrCode_Invalid, gmresult, pushurl)
|
| | | return SendGm(ErrCode_Invalid, gmresult, pushurl)[1]
|
| | | if int(data2['status']) == 1:
|
| | | #暂停使用该批次卡
|
| | | mylog.debug("couponid frozed")
|
| | | return SendGm(ErrCode_Invalid, gmresult, pushurl)
|
| | | return SendGm(ErrCode_Invalid, gmresult, pushurl)[1]
|
| | | if (data2["minserverno"] != 0 and data2["maxserverno"] != 0):
|
| | | if int(data2["minserverno"]) > sid or int(data2["maxserverno"]) < sid:
|
| | | #不在指定区
|
| | | mylog.debug("no sid")
|
| | | return SendGm(ErrCode_Invalid, gmresult, pushurl)
|
| | | return SendGm(ErrCode_Invalid, gmresult, pushurl)[1]
|
| | | if data2["expiretime"] != "" and datetime.datetime.today() > GetDateTimeByStr(data2["expiretime"]):
|
| | | #已过期
|
| | | mylog.debug("time pass")
|
| | | return SendGm(ErrCode_Invalid, gmresult, pushurl)
|
| | | return SendGm(ErrCode_Invalid, gmresult, pushurl)[1]
|
| | |
|
| | | prefix = "" # 固定前缀
|
| | | if couponType in MailJson:
|
| | |
| | | gmresult['coupontype'] = data["coupontype"]
|
| | | gmresult['code'] = codeStr
|
| | | mylog.debug("use again")
|
| | | return SendGm(ErrCode_TypeUsed, gmresult, pushurl)
|
| | | return SendGm(ErrCode_TypeUsed, gmresult, pushurl)[1]
|
| | |
|
| | | data['status'] = 1
|
| | | data['accid'] = accid
|
| | | data['usetime'] = str(datetime.datetime.today())
|
| | |
|
| | | dbController.update(CouponDB.CouponCodeColName + "_" + agentName, {"code":codeStr, "channel":agentName}, data)
|
| | | gmresult['code'] = codeStr
|
| | | gmresult['coupontype'] = data["coupontype"]
|
| | |
|
| | | mylog.debug("card ok!")
|
| | | return SendGm(ErrCode_OK, gmresult, pushurl)
|
| | | retCode, retMsg = SendGm(ErrCode_OK, gmresult, pushurl)
|
| | | if retCode == ErrCode_OK:
|
| | | dbController.update(CouponDB.CouponCodeColName + "_" + agentName, {"code":codeStr, "channel":agentName}, data)
|
| | | mylog.debug("card ok!")
|
| | | return retMsg
|
| | |
|
| | | def CommCheck(dataDict, coupontype):
|
| | | ## 通用常规检查
|
| | |
| | | else:
|
| | | gmurl = "http://%s:%s/Server/Tool.php" % (pushurl, PushPort)
|
| | | gmkey = PushKey
|
| | | mylog.debug("SendGm:%s" % gmurl)
|
| | | if not gmkey or not PushPort:
|
| | | return CouponCodeResponse(ErrCode_OtherErr, "no PushKey or not PushPort")
|
| | | return ErrCode_OtherErr, CouponCodeResponse(ErrCode_OtherErr, "no PushKey or not PushPort")
|
| | | mylog.debug("SendGm:%s" % gmurl)
|
| | |
|
| | | notifyMsg = ""
|
| | | if errcode in ErrCodeMsgInfo:
|
| | |
| | | SendGMTCMD(gmurl, gmtData, gmkey, "GMT_MediaCard")
|
| | |
|
| | | if errcode != ErrCode_OK:
|
| | | return CouponCodeResponse(errcode)
|
| | | return errcode, CouponCodeResponse(errcode)
|
| | |
|
| | | coupontype = gmresult["coupontype"]
|
| | | if coupontype in MailJson:
|
| | |
| | |
|
| | | pack_data["Detail"] = "cardCode:" + gmresult["code"]
|
| | |
|
| | | SendGMTCMD(gmurl, pack_data, gmkey, "GMT_AddPersonalCompensation")
|
| | | return CouponCodeResponse(ErrCode_OK)
|
| | | except Exception, e:
|
| | | mylog.debug("SendGm error %s" % e)
|
| | | return CouponCodeResponse(ErrCode_OtherErr, "gm error")
|
| | | |
| | | return
|
| | | |
| | | ResultType = SendGMTCMD(gmurl, pack_data, gmkey, "GMT_AddPersonalCompensation")
|
| | | if ResultType == 0:
|
| | | return ErrCode_OK, CouponCodeResponse(ErrCode_OK)
|
| | | else:
|
| | | return ErrCode_OtherErr, CouponCodeResponse(ErrCode_OtherErr, "ResultType error is %s" % ResultType)
|
| | | except BaseException:
|
| | | mylog.error("SendGm error %s" % traceback.format_exc())
|
| | | return ErrCode_OtherErr, CouponCodeResponse(ErrCode_OtherErr, "gm error")
|
| | |
|
| | | def SendGMTCMD(gmurl, gmtData, gmkey, pack_type):
|
| | | ## 发送GM工具命令
|
| | | pack_data = {}
|
| | |
| | | post = {}
|
| | | post['pack'] = pack_data_dict;
|
| | | post['sign'] = sign;
|
| | | result = urllib2.urlopen(gmurl, urllib.urlencode(post), 3)
|
| | | #content = result.read()
|
| | | result = urllib2.urlopen(gmurl, urllib.urlencode(post), PushTimeout)
|
| | | retContent = result.read()
|
| | | resultDict = json.loads(retContent)
|
| | | result.close()
|
| | | return
|
| | | ResultType = resultDict.get("ResultType", 5) # 5未知错误
|
| | | return ResultType
|
| | |
|
| | |
|
| | | def GetDateTimeByStr(timeStr, timeFomat="%Y-%m-%d"):
|