Пример #1
0
def _invitation_records():
    secret_user_id = request.args.to_dict().get('secret_usid')
    if not secret_user_id:
        return
    from tickets.extensions.interface.user_interface import is_user
    if not is_user():
        return
    current_app.logger.info('>>>>>>>>record invitation<<<<<<<<')
    try:
        inviter_id = base_decode(secret_user_id)
        current_app.logger.info(f'secret_usid --> inviter_id: {inviter_id}')
    except Exception as e:
        current_app.logger.error(f'解析secret_usid时出错: {e}')
        return
    usid = getattr(request, 'user').id
    if inviter_id == usid:
        current_app.logger.info('inviter == invitee')
        return
    from tickets.models.user import UserInvitation
    from tickets.extensions.register_ext import db
    import uuid
    try:
        with db.auto_commit():
            uin = UserInvitation.create({
                'UINid': str(uuid.uuid1()),
                'USInviter': inviter_id,
                'USInvited': usid,
                'UINapi': request.path
            })
            current_app.logger.info(f'{request.path} 创建邀请记录')
            db.session.add(uin)
    except Exception as e:
        current_app.logger.error(f'存储邀请记录时出错: {e}')
Пример #2
0
 def _invitation_record(self, secret_usid, args):
     try:
         superid = self.cuser._base_decode(secret_usid)
         current_app.logger.info('secret_usid --> superid {}'.format(superid))
         if is_user() and superid != getattr(request, 'user').id:
             with db.auto_commit():
                 today = datetime.now().date()
                 uin_exist = UserInvitation.query.filter(
                     cast(UserInvitation.createtime, Date) == today,
                     UserInvitation.USInviter == superid,
                     UserInvitation.USInvited == getattr(request, 'user').id,
                 ).first()
                 if uin_exist:
                     current_app.logger.info('{}今天已经邀请过这个人了{}'.format(superid, getattr(request, 'user').id))
                     return
                 uin = UserInvitation.create({
                     'UINid': str(uuid.uuid1()),
                     'USInviter': superid,
                     'USInvited': getattr(request, 'user').id,
                     'UINapi': request.path
                 })
                 current_app.logger.info('已创建邀请记录')
                 db.session.add(uin)
                 db.session.add(SharingType.create({
                     'STid': str(uuid.uuid1()),
                     'USid': superid,
                     'STtype': args.get('sttype', 0)
                 }))
                 self.cactivation.add_activation(
                     ActivationTypeEnum.share_old.value, superid, getattr(request, 'user').id)
     except Exception as e:
         current_app.logger.info('secret_usid 记录失败 error = {}'.format(e))
Пример #3
0
 def get(self):
     data = parameter_required('omid')
     omid = data.get('omid')
     filter_args = [OrderMain.OMid == omid, OrderMain.isdelete == false()]
     if is_user():
         filter_args.append(OrderMain.USid == getattr(request, 'user').id)
     om = OrderMain.query.filter(*filter_args).first_('订单不存在')
     user = User.query.filter(User.isdelete == false(), User.USid == om.USid).first_('订单信息错误')
     self._fill_ordermain(om)
     om.fill('usname', user.USname)
     om.fill('usheader', user['USheader'])
     return Success(data=om)
Пример #4
0
    def cancle(self):
        """付款前取消订单"""
        data = parameter_required(('omid',))
        omid = data.get('omid')
        if not is_user():
            raise AuthorityError

        usid = getattr(request, 'user').id
        order_main = OrderMain.query.filter(
            OrderMain.OMid == omid, OrderMain.USid == usid, OrderMain.isdelete == false()).first_('指定订单不存在')
        # if is_supplizer() and order_main.PRcreateId != usid:
        #     raise AuthorityError()
        # if not is_admin() and order_main.USid != usid:
        #     raise NotFound('订单订单不存在')
        self._cancle(order_main)
        return Success('取消成功')
Пример #5
0
    def get_duration_activation(self):
        data = parameter_required('tistarttime', 'tiendtime')
        if is_admin():
            usid = data.get('usid')
        elif is_user():
            usid = getattr(request, 'user').id
        else:
            raise AuthorityError('请登录')
        start = self._trans_time(data.get('tistarttime'))
        end = self._trans_time(data.get('tiendtime'))

        at_list = Activation.query.filter(
            Activation.USid == usid, Activation.createtime >= start, Activation.createtime <= end).all_with_page()
        for at in at_list:
            self._fill_at(at)
        return Success(data=at_list)
Пример #6
0
    def list(self):
        data = parameter_required()
        omstatus = data.get('omstatus')
        filter_args = [OrderMain.isdelete == false()]
        order_by_list = [OrderMain.updatetime.desc(), OrderMain.createtime.desc()]
        if is_user():
            user = self._current_user('请重新登录')

            try:
                omstatus = OrderStatus(int(str(omstatus))).value
            except ValueError:
                current_app.logger.error('omstatus error')
                omstatus = OrderStatus.pending.value
            filter_args.append(OrderMain.USid == user.USid)
            filter_args.append(OrderMain.OMstatus == omstatus)
        else:
            if omstatus:
                try:
                    omstatus = OrderStatus(int(str(omstatus))).value
                except:
                    omstatus = OrderStatus.pending.value
                filter_args.append(OrderMain.OMstatus == omstatus)
            omno = data.get('omno')
            prname = data.get('prname')
            ompaytype = data.get('ompaytype', PayType.cash.value)
            try:
                ompaytype = PayType(int(str(ompaytype))).value
            except:
                ompaytype = PayType.cash.value
            filter_args.append(OrderMain.OMpayType == ompaytype)
            createtime_start = self._check_date(data.get('createtime_start'))
            createtime_end = self._check_date(data.get('createtime_end'))
            if createtime_start:
                filter_args.append(cast(OrderMain.createtime, Date) >= createtime_start)
            if createtime_end:
                filter_args.append(cast(OrderMain.createtime, Date) <= createtime_end)
            if omno:
                filter_args.append(OrderMain.OMno.ilike('%{}%'.format(omno)))
            if prname:
                filter_args.append(OrderMain.PRname.ilike('%{}%'.format(prname)))
            if is_supplizer():
                filter_args.append(OrderMain.PRcreateId == getattr(request, 'user').id)
        omlist = OrderMain.query.filter(*filter_args).order_by(*order_by_list).all_with_page()

        now = datetime.now()

        user_list = db.session.query(User.USid, User.USname, User.USheader).filter(
            User.isdelete == false(), OrderMain.USid == User.USid, *filter_args).all()
        user_dict = {user_info[0]: user_info for user_info in user_list}
        for om in omlist:
            self._fill_ordermain(om)
            if om.OMstatus == OrderStatus.wait_pay.value:
                duration = om.createtime + timedelta(minutes=30) - now
                om.fill('duration', str(duration))
            # todo 填充商品信息
            # 填充用户信息
            user_info = user_dict.get(om.USid)
            # current_app.logger.info('get user info {}'.format(user_info))
            # current_app.logger.info('get user id {}'.format(om.USid))
            # current_app.logger.info('get om id {}'.format(om.OMid))

            om.fill('usname', user_info[1])
            om.fill('USheader', user_info[2])

        return Success(data=omlist)
Пример #7
0
    def _fill_product(self, product):
        product.hide('CreatorId', 'CreatorType')
        product.fill('prstatus_zh', ProductStatus(product.PRstatus).zh_value)
        product.fill('interrupt', False if product.PRstatus < ProductStatus.interrupt.value else True)  # 是否中止
        now = datetime.now()
        role_type = 'productrole'
        countdown = None
        if product.PRtimeLimeted:
            role_type = 'ticketrole'
            if product.PRstatus == ProductStatus.ready.value and product.PRissueStartTime > now:  # 距抢票开始倒计时
                countdown = product.PRissueStartTime - now
            elif product.PRstatus == ProductStatus.active.value and product.PRissueEndTime > now:  # 距抢票结束倒计时
                countdown = product.PRissueEndTime - now
            if countdown:
                hours = str(countdown.days * 24 + (countdown.seconds // 3600))
                minutes = str((countdown.seconds % 3600) // 60)
                seconds = str((countdown.seconds % 3600) % 60)
                countdown = "{}:{}:{}".format('0' + hours if len(hours) == 1 else hours,
                                              '0' + minutes if len(minutes) == 1 else minutes,
                                              '0' + seconds if len(seconds) == 1 else seconds)
                # product.fill('triptime', '{} - {}'.format(product.PRuseStartTime.strftime("%Y/%m/%d %H:%M:%S"),
                #                                           product.PRuseEndTime.strftime("%Y/%m/%d %H:%M:%S")))
        product.fill('countdown', countdown)
        product.fill('prstatus_zh', ProductStatus(product.PRstatus).zh_value)
        product.fill('interrupt', False if product.PRstatus < ProductStatus.interrupt.value else True)
        product.fill('tirules', self._query_rules(getattr(RoleType, role_type).value))
        product.fill('scorerule', self._query_rules(RoleType.activationrole.value))
        apply_num = self._query_award_num(product)
        product.fill('apply_num', apply_num)  # 已申请人数

        # ------ 0624 前台改版后补充字段 ------
        apply_num_str = f'{round(apply_num / 10000, 1)}w人参与' if apply_num > 10000 else f'{apply_num}人已参与'
        product.fill('apply_num_str', apply_num_str)
        buyer_avatar = []
        if apply_num:
            buyer_avatar = [i[0] if i[0].startswith('http') else API_HOST + i[0]
                            for i in db.session.query(User.USheader
                                                      ).filter(OrderMain.OMstatus >= OrderStatus.pending.value,
                                                               OrderMain.PRid == product.PRid,
                                                               OrderMain.USid == User.USid).limit(2).all()]
        product.fill('buyer_avatar', buyer_avatar)
        start_time_str = product.PRissueStartTime.strftime(
            '%m月%d日%H:%M') if product.PRtimeLimeted and product.PRstatus == ProductStatus.ready.value else ''
        product.fill('start_time_str', start_time_str)
        # -----------------------------------

        # show_record = True if product.PRstatus == ProductStatus.over.value else False
        # product.fill('show_record', show_record)  # 0618 fix 目前无需"动态"区域出现
        current_user = User.query.filter(User.isdelete == false(),
                                         User.USid == getattr(request, 'user').id).first() if is_user() else None
        verified = True if current_user and getattr(current_user, 'USidentification') else False
        product.fill('verified', verified)  # 是否已信用认证
        product.fill('position', {'tiaddress': product.address,
                                  'longitude': product.longitude,
                                  'latitude': product.latitude})
        traded = False
        if is_user() and product.PRtimeLimeted:
            traded = self._query_traded(product.PRid, getattr(request, 'user').id)
            if traded:
                scorerank, rank = self._query_single_score(traded, product)
                product.fill('scorerank', scorerank)  # 活跃分排名array
                product.fill('rank', rank)  # 自己所在排名
        product.fill('traded', bool(traded))  # 打开限时商品时检测是否已购买