Exemple #1
0
    def GET(self):
        userid = self.req.input().get('userid')
        if not is_valid_int(userid):
            raise ParamError('userid为空')

        customer_id = self.req.input().get('customer_id')
        if not is_valid_int(customer_id):
            raise ParamError('商户id为空')

        cardno = None
        with get_connection_exception('qf_mchnt') as db:
            member = db.select_one(
                'member',
                where= {
                    'userid': userid,
                    'customer_id': customer_id
                }
            )

        if member:
            cardno = member['id']

        else:
            self.be_member(userid, customer_id, MemDefine.MEMBER_SRC_CARD)
            cardno = getattr(self, '_cardno', '')

        return self.write(success({'cardno': cardno}))
Exemple #2
0
    def check_allow_query(self, aid):
        '''验证能否查看集点活动

        能查看的情况
        1. 自己创建的活动
        2. 自己参与的活动
        3. 自己子商户的活动

        '''
        userid = self.user.userid

        # 子商户可以查看大商户活动
        with get_connection_exception('qf_mchnt') as db:
            actv = db.select_one('card_actv', where={'id': aid})
            if not actv:
                raise ParamError('活动不存在')

        if actv['userid'] != int(userid):
            # 参与活动能查看
            try:
                mchnt_id_list = json.loads(actv['mchnt_id_list'])
            except:
                mchnt_id_list = []
            if str(userid) in mchnt_id_list:
                return actv

            # 活动创建商户的大商户能查看
            re_relates = apcli_ex('getUserReverseRelation', actv['userid'],
                                  'merchant') or []
            userids = [i.userid for i in re_relates]
            if int(userid) not in userids:
                raise ParamError('活动不存在')

        return actv
Exemple #3
0
    def check_allow_change(self, aid):
        '''验证能否修改集点活动

        Params:
            aid: 集点活动id
        Returns:
            返回活动信息
        '''
        userid = self.user.userid
        cate = self.get_cate()

        actv = None
        with get_connection_exception('qf_mchnt') as db:
            actv = db.select_one('card_actv', where={'id': aid})
        if not actv:
            raise ParamError('活动不存在')

        if actv['userid'] != int(userid):
            # 判断登录角色
            cate = self.get_cate()
            if cate in ('merchant', 'submerchant'):
                raise ParamError('子商户不能修改大商户创建的活动')

            # 活动的大商户是否是登录商户
            re_relates = apcli_ex('getUserReverseRelation', actv['userid'],
                                  'merchant') or []
            userids = [i.userid for i in re_relates]
            if int(userid) not in userids:
                raise ParamError('活动不存在')

        now = datetime.datetime.now()
        if actv['expire_time'] < now:
            raise ParamError('活动已停止')

        return actv
Exemple #4
0
    def _trans_input(self):
        d = {k:v.strip() for k, v in self.req.input().iteritems()}
        log.info('d:%s' % d)
        r = {}
        try:
            r['customer_id'] = hids.decode(d.get('customer_id'))[0]
        except:
            if self.customer.customer_id:
                r['customer_id'] = self.customer.customer_id
            else:
                r['customer_id'] = -1

        r['mode'] = d.get('mode', '')
        r['userid'] = d.get('userid', '')
        if is_valid_int(d.get('groupid')):
            r['groupid'] = d.get('groupid')

        if r['mode'] not in ('info', 'list'):
            raise ParamError('请求参数错误')
        elif r['mode'] == 'info':
            r['userid'] = int(r['userid'])
        elif r['mode'] == 'list':
            r['mchnt_id'] = int(d.get('mchnt_id') or 0)
            if r['customer_id'] == -1:
                raise ParamError('消费者id不正确')
            page, pagesize = d.get('page', 0), d.get('pagesize', 10)
            if not all(map(is_valid_int, (pagesize, page))):
                raise ParamError('分页信息错误')
            r['offset'], r['limit'] = int(page)*int(pagesize), int(pagesize)
        return r
Exemple #5
0
    def _trans_input(self):
        d = {k: v.strip() for k, v in self.req.input().iteritems()}
        r = {}
        r['id'] = d.get('id') or ''

        # actv info
        with get_connection_exception('qf_mchnt') as db:
            info = db.select_one('card_actv', where={'id': r['id']})
        if not info:
            raise ParamError('活动不存在')
        info['start_time'] = int(time.mktime(info['start_time'].timetuple()))
        expire_time = d.get('expire_time', info['expire_time'])
        if not is_valid_date(expire_time):
            raise ParamError('活动截止时间格式不对')
        r['expire_time'] = str_to_tstamp(expire_time, DATE_FMT) + 86399
        #if r['expire_time'] < info['start_time']:
        #raise ParamError('修改活动的截止日期不能小于起始日期')

        r['obtain_amt'] = int(d.get('obtain_amt', info['obtain_amt']) or 0)
        if r['obtain_amt'] <= 0:
            raise ParamError('集点条件大于0元')

        r['goods_name'] = remove_emoji(d.get('goods_name', info['goods_name']))
        if not 1 <= str_len(r['goods_name']) <= 8:
            raise ParamError('商品名长度是1至8位')

        r['goods_amt'] = int(d.get('goods_amt', info['goods_amt']) or 0)
        if r['goods_amt'] <= 0:
            raise ParamError('商品价格应大于0')

        r['content'] = (info['content']
                        or '') + (d.get('content') or '%smis修改' %
                                  (time.strftime(DATETIME_FMT)))

        return r
Exemple #6
0
    def POST(self):
        params = self.req.input()
        userid = int(self.user.userid)

        new_username = params.get('new_username', '').strip()
        if not new_username:
            raise ParamError('新账号不能为空')

        # 验证grant_code
        grant_code = params.get('grant_code') or ''
        self.check_grant_code(userid, grant_code)

        # 验证verify_code
        verify_code = params.get('verify_code') or ''
        if not check_smscode(verify_code, new_username, mode=1):
            raise ParamError('验证信息错误')

        # 验证新账号是否被占用
        with get_connection_exception('qf_core') as db:
            new_user = db.select_one('auth_user',
                                     where={'username': new_username})
        if new_user:
            raise ParamError('新账号已经被占用')

        # apollo接口修改username
        try:
            apcli_ex('changeUsername', userid, new_username)
        except ApolloException as e:
            raise ThirdError(e.respmsg)

        # 将现有设备踢下线
        kick_user(userid, mode='all')

        return success({})
Exemple #7
0
    def POST(self):
        actv = None
        with get_connection('qf_marketing') as db:
            actv = db.select_one(
                    table= 'activity',
                    where= {
                        'id': self.validator.data['coupon_id'],
                    },
                    fields= 'id, create_mchnt_id, status, create_time')
        if not actv:
            raise ParamError('活动不存在')

        if actv['create_mchnt_id'] != str(self.user.userid):
            if actv['create_mchnt_id'] == str(self.get_big_uid()):
                raise ParamError('此活动为总账户创建,你无法执行修改~')
            raise ParamError('暂无修改此活动的权限')

        # 已经进行的活动不能删除
        now = datetime.datetime.now()
        notify_datetime = get_notify_datetime(actv['create_time'])
        if not now < notify_datetime:
                raise ParamError('不能删除已经进行的红包推广活动!')

        if actv['status'] != 3:
            try:
                act = Activity(id=actv['id'], status=3,
                               src='qpos')
                thrift_callex(config.QF_MARKETING_SERVERS, QFMarketing,
                              'activity_change', act)
            except:
                log.warn(traceback.format_exc())
                raise ThirdError('关闭活动失败')

        return self.write(success({}))
Exemple #8
0
    def get_input_userid(self):
        cate = self.get_cate()
        if cate == 'bigmerchant':
            params = self.req.input()
            if params.get('userid'):
                userid = int(params['userid'])

            elif params.get('enuserid'):
                userid = hids.decode(params['enuserid'])
                if not userid:
                    raise ParamError('商户不存在')

                else:
                    userid = userid[0]

            else:
                return int(self.user.userid)

            link_ids = self.get_link_ids()
            if userid not in link_ids:
                raise ParamError('商户不存在')

            return userid
        else:
            return int(self.user.userid)
Exemple #9
0
    def _trans_input(self):
        d = {k: v.strip() for k, v in self.req.input().iteritems()}
        userid = int(self.user.ses.get('userid', ''))

        # 验证商户付费状态
        check_payinfo = getattr(config, 'MEMBER_CHECK_PAYINFO', True)
        if check_payinfo:
            mchnt = get_payinfo_ex(userid,
                                   service_code='member_manage',
                                   groupid=self.get_groupid())
            if not mchnt:
                raise ParamError('你的会员服务尚未开通,请联系业务员开通后再进行设置。')
            elif str(mchnt['expire_time']) <= time.strftime(DATETIME_FMT):
                raise ParamError('只有续费才能创建哦')

        field = ['title', 'content', 'start_time', 'expire_time', 'bg_url']
        r = {i: remove_emoji(d.get(i, '')) for i in field}

        r['userid'] = userid
        # content
        if not (str_len(r['content']) <= 150):
            raise ParamError('更多信息要小于150位哦')
        # start_time, expire_time
        if not all(map(is_valid_date, [r['start_time'], r['expire_time']])):
            raise ParamError('时间格式不对')
        if r['start_time'] > r['expire_time']:
            raise ParamError('活动开始时间大于截止时间')
        r['start_time'] = str_timestamp(r['start_time'], DATE_FMT)
        r['expire_time'] = str_timestamp(r['expire_time'],
                                         DATE_FMT) + (24 * 60 * 60 - 1)

        return r
Exemple #10
0
    def GET(self):
        if not self.customer.is_login():
            raise SessionError('登录以后才可以使用!')

        customer_id = self.customer.customer_id

        code = self.req.input().get('code')
        if not code:
            raise ParamError('未能获取二维码')

        decode = hids.decode(code)
        if not decode:
            raise ParamError('解析二维码失败')
        cb_id = decode[0]

        # 查询数据库
        status = {}
        with get_connection('qf_marketing') as db:
            status = db.select_one(table='coupon_bind',
                                   fields='status, customer_id',
                                   where={
                                       'id': cb_id,
                                       'customer_id': customer_id
                                   })

        if not status:
            raise ParamError('没能获取到券的状态')

        return self.write(success(status))
Exemple #11
0
    def username_mchnt(self):
        '''商户预注册'''
        d = {k: v.strip() for k, v in self.req.input().iteritems()}
        self.req.inputjson()['password'] = '******'
        # 验证用户名
        username = d.get('username', '')
        if not username:
            raise ParamError('用户名为空')

        # 验证验证码
        code = d.get('code', '')
        if not check_smscode(code, username):
            raise ParamError('验证码错误')

        # 验证是否注册
        if UserUtil.check_profile(**{'auth_user.username': username}):
            raise ParamError('商户已经注册')

        # 获取userid
        user = None
        with get_connection('qf_core') as db:
            user = db.select_one('auth_user',
                                 where={'mobile': username},
                                 fields='id, password')
            log.debug(user)
        if user:
            if (user['password'] and not check_password(
                    d.get('password', ''), user['password'])):
                raise SessionError('该账号已经设置密码')
            return d['username'], user['id']
        return d['username'], None
Exemple #12
0
    def POST(self):

        cate = self.get_cate()

        params = self.req.input()
        sub_mchnt_id = params.get('shopid', '')
        try:
            userid = self.user.userid
            sub_mchnt_id = int(sub_mchnt_id)
            if not sub_mchnt_id:
                raise ParamError("子商户错误")
            else:
                if cate == "bigmerchant":
                    subids = get_linkids(userid)
                    if sub_mchnt_id not in subids:
                        raise ParamError("非大商户的子商户")
        except:
            log.warn('sub merchant error : %s ' % traceback.format_exc())
            raise ParamError("无法识别子商户")

        try:
            thrift_callex(config.APOLLO_SERVERS, ApolloServer, 'unbindRelation', int(userid), int(sub_mchnt_id), 'merchant')
        except:
            log.warn('user ({userid}) remove sub merchant({sub_mchnt_id}) error : {reason}'.format(userid=userid, sub_mchnt_id = sub_mchnt_id, reason = traceback.format_exc()))
            return self.write(error(QFRET.THIRDERR))
        return self.write(success(data={}))
Exemple #13
0
    def _trans_input(self):
        d = {k: v.strip() for k, v in self.req.input().iteritems()}
        r = {}

        # 修改值
        update_data = {}
        if 'status' in d:
            if d['status'] not in map(str, PROMO_CODE_STATUS.values()):
                raise ParamError('修改的状态不对')
            update_data['status'] = d['status']
        if 'use_limit' in d:
            if not is_valid_int(d['use_limit']):
                raise ParamError('推广码的限制次数为数字')
            update_data['use_limit'] = d['use_limit']

        if not update_data:
            raise ParamError('渠道推广码未做任何修改')
        update_data['utime'] = int(time.time())
        r['update_data'] = update_data

        # 商户userid
        r['code'] = d.get('code')
        if not r['code']:
            raise ParamError('渠道推广码不能为空')

        return r
Exemple #14
0
    def check_promo_code(goods_code, price_code, promo_code, **kw):
        '''
        验证优惠码接口
        v1版本:
        '''
        code_type, code, amt = RechargeUtil.unzip_promo_code(
            promo_code, goods_code)
        # 商品价格
        price = RechargeUtil.get_price(goods_code, price_code)
        if price['promo_code'] != code:
            raise ParamError('该商品不能使用该优惠码')

        # 验证code_type
        if code_type >= 1:
            with get_connection('qf_mchnt') as db:
                where = {
                    'userid': kw['userid'],
                    'promo_code': promo_code,
                    'status': ORDER_STATUS['done']
                }
                r = db.select_one('paying_order', where)
            if r:
                raise ParamError('该优惠码只能使用一次哦')

        # 是否满足条件
        return (price['amt'] - 1) if amt * 100 > price['amt'] else amt * 100
Exemple #15
0
    def POST(self):
        '''
        修改用户权限
        '''
        d = self.validator.data
        userid = int(self.user.userid)

        if not d['opuid']:
            raise ParamError('参数错误')
        if d['status'] is not None and d['status'] not in [0, 1]:
            raise ParamError('状态非法')
        if d['type'] is None:
            type = 'refund'
        else:
            type = d['type']

        # 更新数据
        where = {'userid': userid, 'opuid': int(d['opuid'])}
        perms = {}
        with get_connection('qf_core') as db:
            opuser = db.select_one(table='opuser',
                                   fields=['perms'],
                                   where=where)
            if opuser:
                try:
                    perms = json.loads(opuser['perms'])
                    perms[type] = d['status']
                except:
                    perms[type] = d['status']
                finally:
                    db.update('opuser', {'perms': json.dumps(perms)}, where)

                return self.write(success({}))
            else:
                return self.write(error(QFRET.PARAMERR, respmsg='操作员信息不存在'))
Exemple #16
0
    def POST(self):
        userid = int(self.user.userid)
        actv = None
        with get_connection('qf_mchnt') as db:
            actv = db.select_one(
                    'member_actv',
                    where= {
                        'userid': userid,
                        'type': MemDefine.ACTV_TYPE_PRIVI
                    })
        if actv:
            raise ParamError('已经创建过特权活动了.')


        content = self.validator.data['content']
        content = remove_emoji(content)
        if str_len(content) > 80:
            raise ParamError('活动内容不超过80字')

        now = int(time.time())
        data = {}
        data['id'] = getid()
        data['title'] = ''
        data['content'] = content
        data['userid'] = userid
        data['status'] = MemDefine.ACTV_STATUS_ON
        data['ctime'] = data['utime'] =  now
        data['start_time'] = now
        data['expire_time'] = now + 20 * 365 * 24 * 3600
        data['type'] = MemDefine.ACTV_TYPE_PRIVI
        with get_connection('qf_mchnt') as db:
            db.insert('member_actv', data)

        return self.write(success({}))
Exemple #17
0
    def POST(self):
        params = self.req.input()

        sdk = params.get('sdk') or 'getui'
        if sdk not in ('xiaomi', 'huawei', 'getui'):
            raise ParamError('sdk not support')
        self.sdk = sdk

        data = {}
        data['userid'] = self.get_bind_id()
        data['apptype'] = int(params.get('app_type') or 402)
        data['deviceid'] = params.get('deviceid', '').strip()
        data['clientid'] = params.get('clientid', '').strip()
        data['openid'] = params.get('openid', '')
        data['mobile'] = params.get('mobile', 0)
        data['appver'] = params.get('appver', '')
        data['usertag'] = int(params.get('usertag', '0'))
        data['is_logout'] = int(params.get('is_logout') or 0)
        data['create_time'] = data['update_time'] = 'now()'
        data['token_status'] = 0

        if not data['deviceid']:
            raise ParamError('参数错误')

        for i in and_bind_platform:
            try:
                getattr(self, i + '_bind')(data)
            except:
                log.warn(traceback.format_exc())

        return success({})
Exemple #18
0
    def _trans_input(self):
        d = {k: v.strip() for k, v in self.req.input().iteritems()}
        r = {}
        r['userid'] = int(self.user.ses.get('userid', ''))

        # 排序信息
        allow_order_field = ['num', 'txamt', 'last_txdtm']
        allow_order_type = ['desc', 'asc']
        order_field = d.get('order_field') or 'last_txdtm'
        order_type = d.get('order_type') or 'desc'
        if order_field not in allow_order_field or order_type not in allow_order_type:
            raise ParamError('排序信息错误')
        r['orderby'] = 'order by %s %s' % (order_field, order_type)

        # 分页信息
        page, pagesize = d.get('page', 0), d.get('pagesize', 10)
        if not all(map(is_valid_int, (pagesize, page))):
            raise ParamError('分页信息错误')
        r['offset'], r['limit'] = int(page) * int(pagesize), int(pagesize)

        # 商户付费信息
        r['mchnt_info'] = adjust_payinfo_ex(r['userid'],
                                            service_code='member_manage',
                                            groupid=self.get_groupid())

        return r
Exemple #19
0
    def POST(self):

        params = self.req.input()
        push_status = params.get("push_status", '')
        try:
            push_status = int(push_status)
            if push_status not in (RECEIVE_PUSH, NO_RECEIVE_PUSH):
                raise ParamError("push_status参数错误")
        except:
            raise ParamError("push_status参数错误")

        userid = self.user.userid

        curr_time = time.strftime(DTM_FMT)
        try:
            row = self.db.select_one("mchnt_control", fields="push_master", where={"userid": int(userid), "status": 1})
            if row:
                db_push_status = row['push_master']  # 数据库存储的转态
                if db_push_status == push_status:
                    return self.write(success(data={"result": "fail"}))

                self.db.update("mchnt_control", {"push_master": push_status}, where={"userid": int(userid), "status": 1})
                return self.write(success(data={"result": "success"}))

            else:
                if push_status == RECEIVE_PUSH:
                    self.db.insert("mchnt_control", values={"push_master": RECEIVE_PUSH, "userid": int(userid),
                                                           "push_opuser": 0, "status": 1, "ctime": curr_time})
                    return self.write(success(data={"result": "success"}))
                else:
                    raise ParamError("接收收银员播报已经是关闭状态")
        except:
            log.info(traceback.format_exc())
            raise DBError("数据库执行出错")
Exemple #20
0
    def POST(self):
        params = {k: str(v).strip() for k, v in self.req.input().iteritems()}
        passwd = params.get("password", '')
        code = params.get("code", '')
        if not passwd:
            raise ParamError("缺少password参数")

        userid = self.user.userid
        uinfo = get_userinfo(userid)
        mobile = uinfo.get("mobile")

        if code and not check_smscode(code, mobile, 1):
            raise ParamError('验证码错误')

        with get_connection("qf_core") as conn:
            row = conn.select_one("extra_mchinfo",
                                  where={"userid": userid},
                                  fields="count(1) as count")
            now = time.strftime(DATETIME_FMT)
            values = {
                "userid": userid,
                "manage_password": enc_password(passwd),
                "ctime": now
            }
            try:
                if row['count']:
                    del values['userid'], values['ctime']
                    conn.update("extra_mchinfo",
                                values=values,
                                where={"userid": userid})
                else:
                    conn.insert("extra_mchinfo", values=values)
                return self.write(success(data={}))
            except:
                raise DBError("数据更新失败")
Exemple #21
0
    def get_big_uid(self):
        params = self.req.input()
        src = self.get_src()
        log.debug('src:%s' % src)

        # 验证登录
        if not self.check_login():
            raise SessionError('用户未登录')

        if src == 'salesman':
            if not is_valid_int(params.get('big_uid')):
                raise ParamError('参数错误')
            sm_uid = self.user.userid
            cates = apcli('getUserCategory', int(sm_uid), '') or []
            cates = [i.code for i in cates]
            if 'saleman' not in cates and 'qudao' not in cates:
                raise ParamError('该用户非业务员')

            big_cates = apcli('getUserCategory', int(params['big_uid']),
                              '') or []
            big_cates = [i.code for i in big_cates]
            if 'bigmerchant' not in big_cates:
                raise ParamError('非大商户')

            return int(params['big_uid'])

        else:
            if self.get_cate() != 'bigmerchant':
                raise ParamError('非大商户')
            return int(self.user.userid)
Exemple #22
0
    def POST(self):
        params = self.req.input()
        shopid = params.get("shopid", '')
        newpwd = params.get("newpwd", '')
        if not shopid or not newpwd:
            raise ParamError("参数错误")

        # 验证是否是当前商户的子商户
        userid = self.user.userid
        cate = self.get_cate()
        if cate == "bigmerchant":
            subids = get_linkids(userid)
            shopid = int(shopid)
            if shopid not in subids:
                raise ParamError("非大商户的子商户")

            try:
                apcli("changePwd", uid=shopid, password=newpwd)

                kick_user(int(shopid), mode = 'not_opuser')
                return self.write(success(data={"result": "success"}))
            except:
                log.debug(traceback.format_exc())
                return self.write(success(data={"result": "fail"}))
        else:
            raise ParamError("角色错误")
Exemple #23
0
    def POST(self):
        actv = None
        with get_connection('qf_marketing') as db:
            actv = db.select_one(table='activity',
                                 where={
                                     'id': self.validator.data['id'],
                                     'src': ACTIVITY_SRC
                                 },
                                 fields='id, create_mchnt_id, status')
        if not actv:
            raise ParamError('活动不存在')

        if actv['create_mchnt_id'] != str(self.user.userid):
            if actv['create_mchnt_id'] == str(self.get_big_uid()):
                raise ParamError('此活动为总账户创建,你无法执行修改~')
            raise ParamError('暂无修改此活动的权限')

        if actv['status'] != COUPON_RULE_STATUS_CLOSE:
            try:
                act = Activity(id=actv['id'],
                               status=COUPON_RULE_STATUS_CLOSE,
                               src=ACTIVITY_SRC)
                thrift_callex(config.QF_MARKETING_SERVERS, QFMarketing,
                              'activity_change', act)
            except:
                log.warn(traceback.format_exc())
                raise ThirdError('关闭活动失败')

        return self.write(success({}))
Exemple #24
0
    def _(self, *args, **kwargs):
        userid = int(self.user.userid)

        params = self.req.input()
        if params.has_key("shopid"):
            shopid = params.get("shopid", '')
            if not shopid:
                raise ParamError("商户id参数错误")

            try:
                shopid = hids.decode(shopid)[0]
            except:
                raise ParamError("商户id参数错误")

            # 验证是否是当前商户的子商户
            cate = self.get_cate()
            if cate == "bigmerchant":
                subids = get_linkids(userid)
                if shopid not in subids:
                    raise ParamError("非大商户的子商户")
                else:
                    userid = shopid

        ret = func(self, userid)
        return ret
Exemple #25
0
    def _trans_input(self):
        d = {k: v.strip() for k, v in self.req.input().iteritems()}
        r = {}
        # 修改值
        update_data = {}
        if 'status' in d:
            if d['status'] not in map(str, PROMO_STATUS.values()):
                raise ParamError('修改的状态不对')
            update_data['status'] = d['status']

        if 'balance' in d:
            if d['mode'] not in ('fixed', 'addon'):
                raise ParamError('修改余额的模式不对')
            if not is_valid_int(d['balance']):
                raise ParamError('余额必须为数字')

            if d['mode'] == 'fixed':
                update_data['balance'] = d['balance']
            else:
                update_data['balance'] = DBFunc('balance+%d' %
                                                int(d['balance']))

        if not update_data:
            raise ParamError('商户未做任何修改')
        update_data['utime'] = int(time.time())
        r['update_data'] = update_data

        # 商户userid
        r['userid'] = d.get('userid')
        if not r['userid']:
            raise ParamError('渠道商户ID不能为空')

        return r
Exemple #26
0
    def POST(self):
        d = {k: v.strip() for k, v in self.req.input().iteritems()}

        if d.get('mobile'):
            checkcode = d.get('mobile', '')
            if not re.match(MOBILE_PATTERN, checkcode):
                raise ParamError('手机号码不合法')

        elif d.get('email'):
            checkcode = d.get('email', '')
            if not re.match(EMAIL_PATTERN, checkcode):
                raise ParamError('邮箱不合法')

        else:
            raise ParamError('参数错误')

        code = d.get('code', '')
        if not code:
            raise ParamError('验证码为空')

        # 验证验证码
        if check_smscode(code, checkcode):
            return self.write(success({}))

        raise ParamError('验证码错误')
Exemple #27
0
    def POST(self):
        userid = self.user.userid
        if not SpecialApi.check_allow_create(userid):
            raise ParamError('禁止创建特卖通知!')

        args = self.req.input()
        # 参数
        params = {i : args.get(i) for i in ['title', 'descr', 'redeem_start_date',
                                            'redeem_end_date', 'img'] }

        params['redeem_start_time'] = args.get('redeem_start_time', "05:00")
        params['redeem_end_time'] = args.get('redeem_end_time', "23:00")
        params['quantity'] = int(args['quantity'])

        # 价格
        price, origin_price = int(args['price']), int(args['origin_price'])
        price_limit = int(redis_pool.get('_mchnt_api_sale_price_limit_') or 70000)
        if price > price_limit:
            raise ParamError('创建特卖失败')
        if price > origin_price * 0.8:
            raise ParamError('至少8折才有吸引力')
        params['price'] = price
        params['origin_price'] = origin_price

        result = self.create(**params)

        return self.write(success({'activity_id' : result}))
Exemple #28
0
    def GET(self):
        d = self.req.input()
        userid = d.get('userid', '').strip()
        type = d.get('type', '').strip()

        if (not userid) or (not type):
            raise ParamError('参数错误')

        with get_connection('qf_core') as db:
            opuser = db.select_one(table='profile',
                                   where={'userid': int(userid)},
                                   fields='user_type')

        if not opuser:
            raise ParamError('该商户非法')

        with get_connection('qf_audit') as db:
            rows_type = db.select(table='salesman_event',
                                  where={'userid': ('in', [int(userid)])},
                                  fields='userid,state,ext,memo,type',
                                  other='order by ctime desc')

        with get_connection('qf_audit') as db:
            rows = db.select(table='salesman_event',
                             where={
                                 'userid': ('in', [int(userid)]),
                                 'type': ('in', [int(type)])
                             },
                             fields='userid,state')

        with get_connection('qf_audit') as db:
            rows_old = db.select(table='salesman_event',
                                 where={'userid': ('in', [int(userid)])},
                                 fields='userid,state')

        ret = {}

        if not rows_old:
            ret['oldusertype'] = opuser['user_type']
        else:
            ext_public = json.loads(rows_type[0]['ext'])
            ret['oldusertype'] = ext_public.get("oldusertype",
                                                opuser['user_type'])

        resperr = ''

        ret['usertype'] = opuser['user_type']

        enuserid = UserUtil.o2_syssn_encode(
            int(userid) + UserDefine.o2_BASE_MAGIC_NUMBER)

        ret['enuserid'] = enuserid

        if rows:
            ret['status'] = rows[0]['state']
        else:
            ret['status'] = 0

        return self.write(success(ret, resperr))
Exemple #29
0
    def POST(self):

        params = {
            k.strip(): str(v).strip()
            for k, v in self.req.inputjson().items()
        }
        name = params.get("name", '')
        contact_mobile = params.get("contact_mobile", '')
        city = params.get("city", '')
        company = params.get('company', '')
        coop_type = params.get("coop_type", '1')  # 合作方式

        medium = params.get("medium", "")
        campaign = params.get("campaign", "")
        source = params.get("source", "")
        content = params.get("content", "")
        term = params.get("term", "")

        if not name or not contact_mobile or not city or not coop_type:
            raise ParamError("参数不能为空")
        try:
            coop_type = int(coop_type)
            if coop_type not in INTENT_COOP_TYPE:
                raise ParamError("coop_type参数错误")
        except:
            raise ParamError("coop_type参数错误")

        if not re.match(MOBILE_PATTERN, contact_mobile):
            raise ParamError("手机格式错误")

        curr_time = time.strftime(DTM_FMT)
        if self.db.select("intent_coopman",
                          where={"contact_mobile": contact_mobile},
                          fields="id"):
            raise ParamError("此手机号已提交过")
        else:
            pri_id = getid()
            try:
                self.db.insert("intent_coopman",
                               values={
                                   "id": pri_id,
                                   "name": name,
                                   "contact_mobile": contact_mobile,
                                   "city": city,
                                   "coop_type": coop_type,
                                   "source": source,
                                   "medium": medium,
                                   "campaign": campaign,
                                   "content": content,
                                   "term": term,
                                   "company": company,
                                   "ctime": curr_time
                               })
                return self.write(success(data={}))
            except:
                log.warning(traceback.format_exc())
                raise DBError("操作失败")
Exemple #30
0
    def check_recharge_info(userid,
                            goods_code='v1',
                            price_code='12month',
                            promo_code=None,
                            **kw):
        '''验证提交的信息

        支付预览和优惠码是验证

        Args:
            goods_code: 服务code
            price_code: 价格code
            promo_code: 当promo_code为空时, 不验证优惠码信息

        Raise:
            当服务,价格,优惠码不存在时会抛出ParamError

        Returns:
            cur_goods, promo_amt

        '''
        # 获取当前服务
        cur_goods = None
        for goods in config.GOODS:
            if goods['code'] == goods_code:
                if goods.get('is_gratis'):
                    raise ParamError('该服务免费')
                cur_goods = goods
                break
        else:
            raise ParamError('未找到服务')
        if cur_goods['price']['code'] != price_code:
            raise ParamError('服务没有该价格')

        # 若无优惠码
        if not promo_code:
            return {'goods': cur_goods}

        # 验证优惠码
        code_type, code, amt = RechargeUtil.unzip_promo_code(
            promo_code, goods['code'], 1)
        if goods['price']['promo_code'] != code:
            raise ParamError('该商品不能使用该优惠码')
        if code_type >= 1:
            with get_connection('qf_mchnt') as db:
                r = db.select_one('paying_order',
                                  where={
                                      'userid': userid,
                                      'promo_code': promo_code[2:],
                                      'status': 2
                                  })
            if r:
                raise ParamError('该优惠码只能使用一次哦')

        return {'goods': cur_goods, 'promo_amt': amt * 100}