コード例 #1
0
    def GET(self):
        userid = self.user.userid

        now = time.strftime(DTM_FMT)

        # 开始时间 和 引用计数
        info = (
            redis_pool.hget(receipt_key, userid) or
            future(days = -1, fmt_type = 'str', fmt = DTM_FMT) + ',' + '1'
        )

        start_time, ref_num = info.split(',')

        log.debug(start_time)
        if str_diffdays(now, start_time, DTM_FMT) >= RECEIPT_MAX_DAYS:
            start_time = future(days = -1, fmt_type = 'str', fmt = DTM_FMT)

        # 支付方式
        groupid = self.get_groupid()
        pay_seq = get_qd_conf_value(
            groupid = groupid, mode = 'service', key = 'PAY_SEQUENCE',
            default_key = int(groupid not in config.QF_GROUPIDS),
            default_val = config.PAY_SEQUENCE
        )

        ret = {
            'start_time': start_time,
            'end_time': now,
            'ref_num': ref_num,
            'stat':  [],
        }
        for i in receipt_pay_type:
            if i['name'] in pay_seq:
                tmp = {'paytype': i['name']}
                tmp.update(self.get_stat(
                    i['busicd'], i['refund_busicd'],
                    start_time, now
                ))
                ret['stat'].append(tmp)

        # 如果大于1种支付方式, 需要加总结列
        if len(ret['stat']) >= 1:
            tmp = {}
            fields = (
                'consume_num', 'consume_amt', 'refund_num', 'refund_amt',
                'net_amount_num', 'net_amount_amt'
            )
            for field in fields:
                tmp[field] = sum(i.get(field, 0) for i in ret['stat'])
            tmp['paytype'] = 'total'
            ret['stat'].append(tmp)

        return success(ret)
コード例 #2
0
        def param():
            td = time.strftime(DATETIME_FMT)
            update_userids = {i['userid'] for i in mchnts}
            insert_userids = list(set(d['userid']) - update_userids)
            outdate_userids = {
                i['userid']
                for i in mchnts if str(i['expire_time']) < td
            }
            indate_userids = {
                i['userid']
                for i in mchnts if str(i['expire_time']) > td
            }

            # 默认免费体验时间
            free = 0
            for services in (old_services, new_services):
                if d['goods_code'] in services:
                    free = services[d['goods_code']]
                    break

            st = datetime.date.today()
            expire_time = str_to_tstamp(
                str(
                    future(
                        st, years=d['year'], months=d['month'], days=d['day']))
                + ' 23:59:59', DATETIME_FMT)
            _insert(insert_userids, expire_time + free * 24 * 3600)

            # 更新会员(已过期)
            _update(outdate_userids, expire_time=expire_time)

            # 更新会员(未过期)
            exp = (d['year'] * 365 + d['month'] * 30 + d['day']) * 24 * 3600
            expire_time = DBFunc('expire_time+%d' % exp)
            _update(indate_userids, expire_time=expire_time)
コード例 #3
0
    def get_where(self):
        params = self.req.input()

        customer_id = self.get_cid()

        where = {'cb.customer_id': str(customer_id)}

        now = int(time.time())
        userids = self.get_query_userids(params)
        if userids is not None:
            where['cb.mchnt_id'] = ('in', map(str, userids))

        # 红包是否过期 1未过期 2过期
        is_expire = params.get('is_expire', '1')
        if is_expire == '1':
            where['cb.expire_time'] = ('>', now)
        elif is_expire == '2':
            where['cb.expire_time'] = ('<', now)

        # 查询模式
        mode = params.get('mode', 'exclude_expire')
        # 查询将要过期红包
        if mode == 'expire':
            limit_days = getattr(config, 'COUPON_LIMIT_DAY', 7)
            expire_time = future(datetime.date.today(),
                                 days=limit_days,
                                 fmt_type='timestamp')
            where['`cb.expire_time`'] = ('<', expire_time)

        # 排除将要过期红包
        elif mode == 'exclude_expire':
            limit_days = getattr(config, 'COUPON_LIMIT_DAY', 7)
            expire_time = future(datetime.date.today(),
                                 days=limit_days,
                                 fmt_type='timestamp')
            where['`cb.expire_time`'] = ('>=', expire_time)

        # 状态  0:全部 1:未使用 2:已使用 3:作废
        state = params.get('state', '1')
        if state == '1':
            where['cb.status'] = ('in', (1, 2))
        elif state == '2':
            where['cb.status'] = 3
        elif state == '3':
            where['cb.status'] = 4

        return where
コード例 #4
0
ファイル: order.py プロジェクト: zcxey2911/api_rpc
    def _update_v1():
        '''
        老版本更新
        '''
        with get_connection('qf_mchnt') as db:
            # 获取当前的信息
            upwhere = {
                'goods_code': order['goods_code'],
                'userid': order['userid']
            }
            try:
                info = db.select_one('recharge', where=upwhere)
            except:
                info = None

            # 更新当前级别的信息
            try:
                price = RechargeUtil.get_price(order['goods_code'],
                                               order['price_code'])
                st = datetime.date.today()
                if info:
                    exptm = info['expire_time']
                    if str(exptm) > time.strftime(DATETIME_FMT):
                        st = datetime.date(year=exptm.year,
                                           month=exptm.month,
                                           day=exptm.day)
                add_conf = {price['alidity']['unit']: price['alidity']['key']}
                end = str_to_tstamp(
                    str(future(st, **add_conf)) + ' 23:59:59', DATETIME_FMT)
                # 若不存在,则直接插入
                if info:
                    updata = {
                        'expire_time': end,
                        'utime': int(time.time()),
                        'status': 2
                    }
                    db.update('recharge', updata, upwhere)
                else:
                    indata = {}
                    indata['id'] = getid()
                    indata['userid'] = order['userid']
                    indata['goods_code'] = order['goods_code']
                    indata['status'] = 2
                    indata['expire_time'] = end + config.PAYING_GOODS[
                        'free'] * 24 * 3600
                    indata['ctime'] = indata['utime'] = int(time.time())
                    db.insert('recharge', indata)
            except:
                log.warn('更新消费者有效期失败:%s' % traceback.format_exc())
コード例 #5
0
ファイル: promo.py プロジェクト: zcxey2911/api_rpc
    def update_mchnt(self, userid, goods_codes, months):
        st = datetime.date.today()
        with get_connection('qf_mchnt') as db:
            # 获取当前的信息
            infos = db.select(table='recharge',
                              where={
                                  'goods_code': ('in', goods_codes),
                                  'userid': userid
                              }) or []
            infos = {i['goods_code']: i for i in infos}

            for code in goods_codes:
                try:
                    if code in infos:
                        exptm = infos[code]['expire_time']
                        if str(exptm) > time.strftime(DATETIME_FMT):
                            st = datetime.date(year=exptm.year,
                                               month=exptm.month,
                                               day=exptm.day)
                    end = str_to_tstamp(
                        str(future(st, months=months)) + ' 23:59:59',
                        DATETIME_FMT)

                    if code in infos:
                        db.update(table='recharge',
                                  values={
                                      'expire_time': end,
                                      'utime': int(time.time()),
                                      'status': 2
                                  },
                                  where={
                                      'userid': userid,
                                      'goods_code': code
                                  })
                    else:
                        db.insert(table='recharge',
                                  values={
                                      'id': getid(),
                                      'userid': userid,
                                      'goods_code': code,
                                      'status': 2,
                                      'expire_time': end,
                                      'ctime': int(time.time()),
                                      'utime': int(time.time()),
                                  })
                except:
                    log.warn('更新消费者有效期失败:%s' % traceback.format_exc())
コード例 #6
0
    def GET(self):
        userid = self.user.userid

        mode = self.validator.data['filter_key']
        ret = {}
        summary = {}
        summary['total_num'] = summary['td_num'] = 0
        with get_connection('qf_mchnt') as db:
            where = {'userid': userid}
            if mode in ('all', 'lose'):
                # 总数
                if mode == 'lose':
                    where['last_txdtm'] = ('<=',
                            future(days=-60, fmt_type='timestamp'))
                summary['total_num']= db.select_one(
                        table= 'member',
                        where= where,
                        fields= 'count(1) as num')['num']

            elif mode in ('card', 'prepaid', 'submit'):
                summary['total_num'] = db.select_one(
                        'member_tag',
                        where= {
                            'userid': userid,
                            mode: ('>=', 1)
                        },
                        fields= 'count(1) as num')['num']


            summary['td_num']= db.select_one(
                    table= 'member',
                    where= {
                        'userid': userid,
                        'ctime': ('>', get_day_begin_ts())
                    },
                    fields= 'count(1) as num')['num']
        ret['summary'] = summary

        for k in ('filters', 'sorts', 'flags'):
            ret[k] = get_qd_conf_value(mode='member_'+k, key='service',
                                       groupid=self.get_groupid())
        ret['filters'] = ret['filters'] or config.MEMBER_FILTERS
        ret['sorts'] = ret['sorts'] or config.MEMBER_SORTS
        ret['flags'] = ret['flags'] or config.MEMBER_FLAGS

        return self.write(success(ret))
コード例 #7
0
    def POST(self):
        try:
            userid = self.user.userid

            now = time.strftime(DTM_FMT)

            # 开始时间 和 引用计数
            info = (
                redis_pool.hget(receipt_key, userid) or
                future(days = -1, fmt_type = 'str', fmt = DTM_FMT) + ',' + '1'
            )

            start_time, ref_num = info.split(',')

            redis_pool.hset(receipt_key, userid, ','.join([now, str(int(ref_num) + 1)]))
        except:
            log.warn(traceback.format_exc())

        return success({})
コード例 #8
0
    def get_members_ext(self, mode):
        data = self.validator.data
        userid = int(self.user.userid)

        orderby = 'order by m.{}'.format(' '.join(data['sort_key'].split('|')))
        if mode in ('all', 'lose'):
            where = {'userid': userid}
            if mode == 'lose':
                where['last_txdtm'] = ('<=',
                    future(days=-60, fmt_type='timestamp'))
            with get_connection('qf_mchnt') as db:
                members = db.select(
                        table= 'member m',
                        where= where,
                        other= '{} limit {} offset {}'.format(
                               orderby, data['pagesize'],
                               data['page']*data['pagesize']),
                        fields= 'customer_id, txamt, num, last_txdtm, userid')

        # 需要联member_tag表查询
        elif mode in ('card', 'prepaid', 'submit'):
            with get_connection('qf_mchnt') as db:
                members = db.select_join(
                        table1= 'member m',
                        table2= 'member_tag mt',
                        on= {
                            'm.userid': 'mt.userid',
                            'm.customer_id': 'mt.customer_id'
                        },
                        where= {
                            'm.userid': userid,
                            'mt.userid': userid,
                            'mt.'+mode: ('>', 0),
                        },
                        other= '{} limit {} offset {}'.format(
                               orderby, data['pagesize'],
                               data['page']*data['pagesize']),
                        fields= ('m.customer_id, m.txamt, m.num, '
                                 'm.last_txdtm, m.userid'))
        return members
コード例 #9
0
    def GET(self):
        userid = int(self.user.userid)

        # 验证信息
        info = RechargeUtil.check_recharge_info(userid, **self.validator.data)
        upgoods = info['goods']

        # 获取当前支付信息
        code = self.validator.data['goods_code']
        cur_amt, cur_expire = RechargeUtil.get_cur_payinfo(userid, code)
        add_conf = {upgoods['price']['alidity']['unit']: upgoods['price']['alidity']['key']}
        expire_time = future(cur_expire, **add_conf)

        # 付费服务信息
        goods_info = copy.deepcopy(upgoods)
        goods_info['price'] = {i:goods_info['price'][i]
                                   for i in ['code', 'goods_name', 'amt']}
        goods_info['services'] = [{i: service.get(i, '') for i in ['title', 'icon_url', 'info_url']}
                                   for service in goods_info['services']]
        goods_info['pg_name'] = '{}权益'.format(goods_info['name'])

        fields = ['services', 'color', 'pg_name', 'code', 'logo_url', 'price', 'desc']
        goods_info = {field:goods_info[field] for field in fields}
        goods_amt = goods_info['price']['amt']


        promo_amt = info.get('promo_amt', 0)
        promo_amt = min(promo_amt, goods_amt - 1)
        ret = {}
        ret['goods_info'] = goods_info
        ret['promo_amt'] = promo_amt
        ret['cur_amt'] = (cur_amt if (promo_amt + cur_amt) < goods_amt
                          else (goods_amt - promo_amt - 1))
        ret['txamt'] = max(goods_amt - promo_amt - cur_amt, 1)
        ret['expire_time'] = expire_time

        return self.write(success(ret))
コード例 #10
0
ファイル: order.py プロジェクト: zcxey2911/api_rpc
    def _update():
        '''
         最新版本
        '''
        # 获取当前服务
        cur_goods = err = None
        for goods in config.GOODS:
            if goods['code'] == goods_code:
                if goods.get('is_gratis'):
                    err = '服务是免费'
                    break
                cur_goods = goods
                break
        else:
            err = '未找到服务'
        if cur_goods['price']['code'] != order['price_code']:
            err = '服务没有该价格'
        if err:
            log.debug(err)
            return

        with get_connection('qf_mchnt') as db:
            # 获取当前的信息
            upwhere = {
                'goods_code': order['goods_code'],
                'userid': order['userid']
            }
            try:
                info = db.select_one('recharge', where=upwhere)
            except:
                info = None

            # 更新当前级别的信息
            try:
                st = datetime.date.today()
                if info:
                    exptm = info['expire_time']
                    if str(exptm) > time.strftime(DATETIME_FMT):
                        st = datetime.date(year=exptm.year,
                                           month=exptm.month,
                                           day=exptm.day)
                add_conf = {
                    cur_goods['price']['alidity']['unit']:
                    cur_goods['price']['alidity']['key']
                }
                end = str_to_tstamp(
                    str(future(st, **add_conf)) + ' 23:59:59', DATETIME_FMT)
                # 若不存在,则直接插入
                if info:
                    updata = {
                        'expire_time': end,
                        'utime': int(time.time()),
                        'status': 2
                    }
                    db.update('recharge', updata, upwhere)
                else:
                    indata = {}
                    indata['id'] = getid()
                    indata['userid'] = order['userid']
                    indata['goods_code'] = order['goods_code']
                    indata['status'] = 2
                    indata['expire_time'] = end + cur_goods.get('free',
                                                                0) * 24 * 3600
                    indata['ctime'] = indata['utime'] = int(time.time())
                    db.insert('recharge', indata)
            except:
                log.warn('更新消费者有效期失败:%s' % traceback.format_exc())

            # 更新低级别的服务
            low_codes = {
                goods['code']
                for goods in config.GOODS if not goods.get('is_gratis')
                and goods['vip'] < cur_goods['vip']
            }
            if low_codes:
                content = '{}购买了{}高级服务,将所有低级服务折算'.format(
                    time.strftime(DATETIME_FMT), order['goods_code'])
                now = int(time.time())
                db.update(table='recharge',
                          where={
                              'goods_code': ('in', low_codes),
                              'userid': order['userid'],
                              'expire_time': ('>', now),
                          },
                          values={
                              'content': content,
                              'expire_time': now,
                              'utime': now
                          })