コード例 #1
0
ファイル: home_dl.py プロジェクト: y1024/Small
    def buy_oss_data(self):
        dR = {'code': '1', 'MSG': ''}
        oss_flag = self.GP('oss_flag', '')  #
        try:
            if self.usr_id_p != self.usr_id:
                dR['MSG'] = '子帐号不需要购买存储包'
                return dR
            sql = "select usr_id from users where coalesce(qiniu_flag,0)=1 and usr_id=%s"
            lT, iN = self.db.select(sql, [self.usr_id])
            if iN > 0:
                dR['MSG'] = '您是使用自己的自定义存储,不需要购买!'
                return dR
            if oss_flag == '4':
                sql = "select  oss_one_size,oss_one_price,oss_one_day from toll_config"
                l, t = self.db.select(sql)
                if t == 0:
                    dR['MSG'] = '您所要购买的套餐不存在,请重新选择购买'
                    return dR
                dR['code'] = '0'
            elif oss_flag == '5':
                sql = "select  oss_two_size,oss_two_price,oss_two_day from toll_config"
                l, t = self.db.select(sql)
                if t == 0:
                    dR['MSG'] = '您所要购买的套餐不存在,请重新选择购买'
                    return dR
                dR['code'] = '0'
            else:
                sql = "select  oss_thr_size,oss_thr_price,oss_thr_day from toll_config "
                l, t = self.db.select(sql)
                if t == 0:
                    dR['MSG'] = '您所要购买的套餐不存在,请重新选择购买'
                    return dR
                dR['code'] = '0'
            name, price, day = l[0]
            # 如果你是 Python 3的用户,使用默认的字符串即可
            cname = 'OSS存储%sM' % name
            data = {
                'ctype': oss_flag,
                'cname': cname,
                'price': price,
                'days': day,
            }
            sql = "select id,out_trade_no from pingtai_paylog where coalesce(pay_status,0)=0 and usr_id=%s and ctype=%s"
            lT, iN = self.db.select(sql, [self.usr_id, oss_flag])

            if iN == 0:
                timeStamp = time.time()
                timeArray = time.localtime(timeStamp)
                danhao = time.strftime("%Y%m%d%H%M%S", timeArray)
                romcode = str(time.time()).split('.')[-1]  # [3:]
                out_trade_no = 'O' + danhao[2:] + romcode
                data['usr_id'] = self.usr_id
                data['out_trade_no'] = out_trade_no
                data['ctime'] = self.getToday(9)
                self.db.insert('pingtai_paylog', data)
            else:
                data['utime'] = self.getToday(9)
                id, out_trade_no = lT[0]

                self.db.update('pingtai_paylog', data, 'id=%s' % id)

            app_id = self.oTOLL['wx_appid']

            wechat_pay_id = self.oTOLL['mchid']
            wechat_pay_secret = self.oTOLL['mchkey']
            base_url = self.oTOLL['callback_url']

            notify_url = base_url + '/vipnotify'

            data = {
                'appid': app_id,
                'mch_id': wechat_pay_id,
                'body': '简道商城平台-%s' % cname,  # 商品描述
                'out_trade_no': out_trade_no,  # 商户订单号
                'total_fee': int(float(price) * 100),
                'notify_url': notify_url,
                'trade_type': 'NATIVE',
                'timeStamp': str(int(time.time())),
                'product_id': oss_flag
            }

            wxpay = WeixinPay(app_id, wechat_pay_id, wechat_pay_secret,
                              notify_url)
            raw = wxpay.unified_order(**data)
            if raw.get('return_code') == 'SUCCESS':
                dR['code'] = '0'
                dR['code_url'] = raw['code_url']
                return dR

            dR['MSG'] = raw
            return dR

        except Exception as e:
            dR = {'code': '1', 'MSG': '%s' % e}
            return dR
コード例 #2
0
ファイル: home_dl.py プロジェクト: y1024/Small
    def buy_vip_data(self):
        dR = {'code': '1', 'MSG': ''}
        vip_flag = self.GP('vip_flag', '')  #
        try:
            if vip_flag == '2':
                sql = "select  combo_two_name,combo_two_price,combo_two_day from toll_config where coalesce(combo_two_status,0)=1"
                l, t = self.db.select(sql)
                if t == 0:
                    dR['MSG'] = '您所要购买的套餐不存在,请重新选择购买'
                    return dR
                dR['code'] = '0'
            elif vip_flag == '3':
                sql = "select  combo_thr_name,combo_thr_price,combo_thr_day from toll_config where coalesce(combo_thr_status,0)=1"
                l, t = self.db.select(sql)
                if t == 0:
                    dR['MSG'] = '您所要购买的套餐不存在,请重新选择购买'
                    return dR
                dR['code'] = '0'
            else:
                sql = "select  combo_one_name,combo_one_price,combo_one_day from toll_config "
                l, t = self.db.select(sql)
                dR['code'] = '0'
            name, price, day = l[0]
            # 如果你是 Python 3的用户,使用默认的字符串即可

            data = {
                'ctype': vip_flag,
                'cname': name,
                'price': price,
                'days': day,
            }

            sql = """select ctype from pingtai_paylog 
                where coalesce(pay_status,0)=1 and usr_id=%s and ctype in (1,2,3) order by id desc limit 1;"""
            lT1, iN1 = self.db.select(sql, [self.usr_id])
            if iN1 > 0:
                ctype = lT1[0][0]
                if str(vip_flag) != str(ctype):
                    dR['MSG'] = '您上一次购买的套餐与现在有冲突,请联系管理员'
                    return dR
                    # sqlr = "select role_id from usr_role where usr_id=%s"
                    # lr, tr = self.db.select(sqlr, [self.usr_id])
                    # if tr == 1:
                    #     role_id = lr[0][0]  # role_id 2基础,3营销
                    #     if str(vip_flag) == '1' and role_id != 2:  # 基础
                    #         self.db.query("update usr_role set role_id=2 where id=%s", [urid])
                    #     elif str(vip_flag) == '2' and role_id != 3:  # 营销
                    #         self.db.query("update usr_role set role_id=3 where id=%s", [urid])
                    #     elif str(vip_flag) == 3:  # 未知
                    #         pass

            sql = "select id,out_trade_no from pingtai_paylog where coalesce(pay_status,0)=0 and usr_id=%s and ctype=%s"
            lT, iN = self.db.select(sql, [self.usr_id, vip_flag])
            if iN == 0:
                timeStamp = time.time()
                timeArray = time.localtime(timeStamp)
                danhao = time.strftime("%Y%m%d%H%M%S", timeArray)
                romcode = str(time.time()).split('.')[-1]  # [3:]
                out_trade_no = 'V' + danhao[2:] + romcode
                data['usr_id'] = self.usr_id
                data['out_trade_no'] = out_trade_no
                data['ctime'] = self.getToday(9)
                self.db.insert('pingtai_paylog', data)
            else:
                data['utime'] = self.getToday(9)
                id, out_trade_no = lT[0]

                self.db.update('pingtai_paylog', data, 'id=%s' % id)

            app_id = self.oTOLL['wx_appid']

            wechat_pay_id = self.oTOLL['mchid']
            wechat_pay_secret = self.oTOLL['mchkey']
            base_url = self.oTOLL['callback_url']

            notify_url = base_url + '/vipnotify'

            data = {
                'appid': app_id,
                'mch_id': wechat_pay_id,
                'body': '简道商城平台-%s' % name,  # 商品描述
                'out_trade_no': out_trade_no,  # 商户订单号
                'total_fee': int(float(price) * 100),
                'notify_url': notify_url,
                'trade_type': 'NATIVE',
                'timeStamp': str(int(time.time())),
                'product_id': vip_flag
            }

            wxpay = WeixinPay(app_id, wechat_pay_id, wechat_pay_secret,
                              notify_url)
            raw = wxpay.unified_order(**data)
            if raw.get('return_code') == 'SUCCESS':
                dR['code'] = '0'
                dR['code_url'] = raw['code_url']
                return dR

            dR['MSG'] = raw
            return dR

        except Exception as e:
            dR = {'code': '1', 'MSG': '%s' % e}
            return dR
コード例 #3
0
ファイル: I001_dl.py プロジェクト: mynamebin/Small
    def Search_data(self):

        dR={'code':'','MSG':'查询成功'}
        uid=self.GP('uid','')
        if uid=='':
            dR['MSG']='查询数据用误'
            return dR

        sql="select out_trade_no,usr_id,days,ctype from pingtai_paylog  where id=%s"
        l,t=self.db.select(sql,[uid])
        if t==0:
            dR['MSG'] = '查询数据不存在'
            return dR
        out_trade_no, usr_id,days,ctype=l[0]
        import datetime
        from basic.pay import WeixinPay
        app_id = self.oTOLL['wx_appid']
        wechat_pay_id = self.oTOLL['mchid']
        wechat_pay_secret = self.oTOLL['mchkey']
        base_url = self.oTOLL['callback_url']
        notify_url = base_url + '/vipnotify'

        wxpay = WeixinPay(app_id, wechat_pay_id, wechat_pay_secret, notify_url)
        data = {
            'out_trade_no': out_trade_no,  # 商户订单号
        }
        raw = wxpay.order_query(**data)
        if raw.get('trade_state') == 'SUCCESS':
            transaction_id = raw['transaction_id']
            openid = raw['openid']
            sql = "update pingtai_paylog set openid=%s,transaction_id=%s,pay_status=1,pay_time=now() where id=%s"
            self.db.query(sql, [openid, transaction_id, uid])

            if ctype in (1, 2, 3):
                sqlu = """select to_char(expire_time,'YYYY-MM-DD HH24:MI'),
                        to_char(now(),'YYYY-MM-DD HH24:MI'),
                        case when to_char(expire_time,'YYYY-MM-DD HH24:MI')>to_char(now(),'YYYY-MM-DD HH24:MI') 
                        then 1 else 0 end,coalesce(inviteid,1) from users  where usr_id=%s"""
                lT, iN = self.db.select(sqlu, [usr_id])
                if iN > 0:
                    time_1, time_2, flag,inviteid = lT[0]
                    if flag == 1:
                        expire_time = time_1
                    else:
                        expire_time = time_2
                    now = datetime.datetime.strptime(expire_time, "%Y-%m-%d %H:%M")
                    delta = datetime.timedelta(days=days)
                    n_days = now + delta
                    e_time = n_days.strftime('%Y-%m-%d %H:%M:%S')
                    sql = "update users set expire_time=%s,vip_flag=%s,expire_flag=0 where usr_id=%s"
                    self.db.query(sql, [e_time, ctype, usr_id])
                    sql = "update pingtai_paylog set etime=%s where out_trade_no=%s"
                    self.db.query(sql, [e_time, out_trade_no])

                    pay_days = self.oTOLL.get('pay_days')
                    if inviteid != 1 and pay_days != 0:

                        sqlu = """select to_char(expire_time,'YYYY-MM-DD HH24:MI'),
                            to_char(now(),'YYYY-MM-DD HH24:MI'),
                            case when to_char(expire_time,'YYYY-MM-DD HH24:MI')>to_char(now(),'YYYY-MM-DD HH24:MI') 
                            then 1 else 0 end from users  where usr_id=%s"""
                        lT, iN = self.db.select(sqlu, [inviteid])
                        if iN > 0:
                            time1, time2, flag_ = lT[0]
                            if flag_ == 1:
                                expiretime = time1
                            else:
                                expiretime = time2
                            now = datetime.datetime.strptime(expiretime, "%Y-%m-%d %H:%M")
                            delta = datetime.timedelta(days=pay_days)
                            n_days = now + delta
                            etime = n_days.strftime('%Y-%m-%d %H:%M:%S')
                            sql = "update users set expire_time=%s,expire_flag=0 where usr_id=%s"
                            self.db.query(sql, [etime, inviteid])
                            isql = """insert into invite_log(ctype,return_id,usr_id,openid,return_days,return_time,ctime)
                                       values(2,%s,%s,%s,%s,%s,now())"""
                            iparm = [inviteid, usr_id, openid, pay_days, etime]
                            self.db.query(isql, iparm)
                    sqlr = "select id,role_id from usr_role where usr_id=%s"
                    lr, tr = self.db.select(sqlr, [usr_id])
                    if tr == 1:
                        urid, role_id = lr[0]  # role_id 2基础,3营销
                        if ctype == 1 and role_id != 2:  # 基础
                            self.db.query("update usr_role set role_id=2 where id=%s", [urid])
                        elif ctype == 2 and role_id != 3:  # 营销
                            self.db.query("update usr_role set role_id=3 where id=%s", [urid])
                        elif ctype == 3:  # 未知
                            pass

                dR['code'] = '0'
                dR['MSG'] = '查询到已支付,已对数据进行更新。'
                return dR

            if ctype == 4:
                sqlu = "select  oss_one_size from toll_config"
            elif ctype == 5:
                sqlu = "select  oss_two_size from toll_config"
            else:
                sqlu = "select  oss_thr_size from toll_config"
            lT, iN = self.db.select(sqlu)
            if iN > 0:
                size = lT[0][0]
                now = datetime.datetime.now()
                delta = datetime.timedelta(days=days)
                n_days = now + delta
                e_time = n_days.strftime('%Y-%m-%d %H:%M:%S')
                sql = "update users set oss_time=%s,oss_flag=%s,oss_all=coalesce(oss_all,0)+%s where usr_id=%s"
                self.db.query(sql, [e_time, ctype, size, usr_id])
                sql = "update pingtai_paylog set etime=%s,utime=now() where out_trade_no=%s"
                self.db.query(sql, [e_time, out_trade_no])

            dR['code'] = '0'
            dR['MSG'] = '查询到已支付,已对数据进行更新。'
            return dR
        dR['MSG'] ='trade_state_desc'
        return dR