Exemplo n.º 1
0
 def get_today_total(self):
     """今日"""
     if not is_partner():
         raise TOKEN_ERROR(u'请使用vip登录')
     usid = request.user.id
     # 今日营业额
     today_orders = self.sorder.get_today_order_by_usid_status(
         usid, finished_pay_status)
     sold_mount_list = [x.OImount for x in today_orders] or [0]
     sold_mount = sum(sold_mount_list)
     # 今日赚
     today_earn = sold_mount * Partner().one_level_divide
     today_earn = round(today_earn, 2)
     # 额外赚
     # todo
     other_earn = 0
     # 新衣币
     new_cloth_bit = self.sraward.get_reward_by_usid(usid)
     bit_num_list = [x.RAnumber for x in new_cloth_bit] or [0]
     bit_num_mount = sum(bit_num_list)
     response = import_status('get_today_earn_success', 'OK')
     data = {
         'sold_mount': sold_mount,
         'today_earn': today_earn,
         'other_earn': other_earn,
         'bit_num_mount': bit_num_mount
     }
     response['data'] = data
     return response
Exemplo n.º 2
0
    def get_all(self):
        """活动所有热文"""
        if is_tourist():
            raise TOKEN_ERROR(u'未登录')
        args = request.args.to_dict()
        logger.debug("get hotmessage args is %s", args)
        lasting = args.get('lasting', 'true')
        htfilter = 1 if is_partner() else 0
        if is_admin():
            htfilter = [0, 1]
        try:
            hot_list = self.s_hotmessage.get_hotmsg_list_by_filter(htfilter)
            if str(lasting) == 'true':
                hot_list = filter(
                    lambda hot: hot.HMstarttime < get_db_time_str() < hot.
                    HMendtime, hot_list)
            for hotmsg in hot_list:
                hotmsg.HMstarttime = get_web_time_str(hotmsg.HMstarttime)
                hotmsg.HMendtime = get_web_time_str(hotmsg.HMendtime)

            data = import_status("get_hotmessage_list_success", "OK")
            data['data'] = hot_list
            return data
        except:
            logger.exception("get hotmessage error")
            raise SYSTEM_ERROR(u'服务器繁忙')
Exemplo n.º 3
0
 def add_useraddress(self):
     if not hasattr(request, 'user'):
         return TOKEN_ERROR(u"未登录, 或token错误")
     parameter_required("areaid", "UAname", "UAphone", "UAtext")
     data = request.json
     logger.info("this is useraddress data %s", data)
     try:
         uaid = str(uuid.uuid1())
         logger.debug("get default address by usid")
         exist_default = self.suesraddress.get_default_address_by_usid(
             request.user.id)
         uadefault = True if not exist_default else data.get("UAdefault")
         if str(uadefault) not in ['True', 'False']:
             raise PARAMS_ERROR(u'uadefault参数不合法')
         if uadefault is True and exist_default:
             self.suesraddress.change_default_address_status(
                 exist_default.UAid, {'UAdefault': False})
         self.suesraddress.add_model(
             "UserAddress", **{
                 "UAid": uaid,
                 "USid": request.user.id,
                 "UAname": data.get("UAname"),
                 "UAphone": data.get("UAphone"),
                 "UAtext": data.get("UAtext"),
                 "areaid": data.get("areaid"),
                 "UAdefault": uadefault
             })
         response = import_status("add_address_success", "OK")
         response['data'] = {"UAid": uaid}
         return response
     except:
         logger.exception("add user address error")
         return SYSTEM_ERROR
Exemplo n.º 4
0
 def get_one_or_default_address(self):
     if is_tourist():
         raise TOKEN_ERROR(u'未登录')
     uaid = request.args.to_dict().get('uaid')
     usid = request.user.id
     logger.debug("get uaid is %s", uaid)
     if uaid is not None:
         uafilter = {'UAid': uaid}
     else:
         uafilter = {'USid': usid, 'UAdefault': True, 'UAisdelete': False}
     default_address = self.suesraddress.get_one_or_default_address(
         uafilter)
     if not default_address:
         any_address = self.suesraddress.get_first_no_default_address(usid)
         if not any_address:
             raise NOT_FOUND(u'该用户未设置地址信息')
     address = default_address or any_address
     if address:
         logger.info("get address success, now to fill detail")
     addressinfoes = self.suesraddress.get_addressinfo_by_areaid(
         address.areaid)
     for addressinfo in addressinfoes:
         address.addressinfo = addressinfo
         address.add("addressinfo")
     response = import_status("messages_get_item_ok", "OK")
     response['data'] = address
     return response
Exemplo n.º 5
0
 def update_address(self):
     if not hasattr(request, 'user'):
         return TOKEN_ERROR(u"未登录, 或token错误")
     args = request.args.to_dict()
     logger.debug("this is address args %s", args)
     data = request.json
     logger.debug("this is address data %s", data)
     uaid = args.get('uaid')
     uadefault = data.get("UAdefault")
     try:
         exist_default = self.suesraddress.get_default_address_by_usid(
             request.user.id)
         parameter_required("uaid", "areaid", "UAname", "UAphone", "UAtext",
                            "UAdefault")
         if uadefault == True and exist_default:
             self.suesraddress.change_default_address_status(
                 exist_default.UAid, {'UAdefault': False})
         update_address = self.suesraddress.update_address(
             uaid, {
                 "areaid": data.get("areaid"),
                 "UAname": data.get("UAname"),
                 "UAphone": data.get("UAphone"),
                 "UAtext": data.get("UAtext"),
                 "UAdefault": uadefault
             })
         logger.info("update address succress ")
         if not update_address:
             raise SYSTEM_ERROR(u'数据更新错误')
         response = import_status("update_useraddress_success", "OK")
         response['data'] = {"uaid": args["uaid"]}
         return response
     except:
         logger.exception("update address error")
         return SYSTEM_ERROR
Exemplo n.º 6
0
    def get_complain_by_usid(self):
        """后台管理查看投诉记录"""
        if not hasattr(request, 'user'):
            raise TOKEN_ERROR()  # 未登录, 或token错误
        args = request.args.to_dict()
        logger.debug("get complain args is %s", args)
        page_size = args.get('page_size')
        page_size = 10 if not page_size else int(page_size)
        page_num = args.get('page_num')
        page_num = 1 if not page_num else int(page_num)
        try:
            complain_list = self.scomplain.admin_get_all_complain(
                page_size, page_num)
            complain_list_length = self.scomplain.admin_get_complain_count()
            from WeiDian.config.enums import complain_type
            data = import_status("get_complain_success", "OK")
            for complain in complain_list:
                colist = str(complain.COtype).split(",")
                logger.debug('get colist %s', colist)
                complaintype = ",".join([complain_type.get(i) for i in colist])
                logger.debug('convert complain type %s', complaintype)
                complain.COtype = complaintype
                user_info = self.suser.get_user_by_user_id(complain.USid)
                complain.fill(user_info.USname, 'usname')
                complain.COcreatetime = get_web_time_str(complain.COcreatetime)

            data['data'] = complain_list
            data['count'] = complain_list_length
            logger.debug("get complain by usid %s", complain_list)
            return data
        except:
            logger.exception("get complain by usid error")
            raise SYSTEM_ERROR(u'获取数据错误')
Exemplo n.º 7
0
 def del_address(self):
     if is_tourist():
         return TOKEN_ERROR(u"未登录, 或token错误")
     data = request.json
     logger.info("this is del address data %s", data)
     parameter_required("UAid")
     try:
         logger.debug("del address")
         del_address = self.suesraddress.delete_address(data.get("UAid"))
         if not del_address:
             return SYSTEM_ERROR
         exist_default = self.suesraddress.get_default_address_by_usid(
             request.user.id)
         if not exist_default:
             no_default_address = self.suesraddress.get_first_no_default_address(
                 request.user.id)
             if no_default_address:
                 self.suesraddress.change_default_address_status(
                     no_default_address.UAid, {'UAdefault': True})
         response = import_status("delete_useraddress_success", "OK")
         response['data'] = {"uaid": data.get("UAid")}
         return response
     except:
         logger.exception("del address error")
         return SYSTEM_ERROR
Exemplo n.º 8
0
 def add_bankcard(self):
     if not hasattr(request, 'user'):
         return TOKEN_ERROR(u"未登录, 或token错误")
     data = request.json
     logger.info("this add bankcard info %s", data)
     parameter_required('BCusername', 'BCnumber', 'BCbankname', 'BCaddress')
     banknumber = str(data.get('BCnumber')).strip()
     self._verify_cardnum(banknumber, error='raise')
     usid = request.user.id
     try:
         bankcard = self.sbankcard.update_bankcard_by_usid(
             usid, {'BCisdelete': True})
         logger.debug("bankcard count is %s", bankcard)
         bcid = str(uuid.uuid1())
         self.sbankcard.add_model(
             "BankCard", **{
                 "BCid": bcid,
                 "USid": usid,
                 "BCusername": data.get("BCusername"),
                 "BCnumber": banknumber,
                 "BCbankname": data.get("BCbankname"),
                 "BCaddress": data.get("BCaddress")
             })
         response = import_status("add_bank_card_success", "OK")
         response['data'] = {"BCid": bcid}
         return response
     except:
         logger.exception("add bankcard error")
         return SYSTEM_ERROR
Exemplo n.º 9
0
    def set_schedual_show(self):
        """设置个人主页升级进度显示(vip数据统计), 素材圈显示, 待评价"""
        if not is_admin():
            raise TOKEN_ERROR(u'请使用管理员登录')
        # data = parameter_required(u'vip_match', u'material', u'wait_apply')
        data = request.json
        paras_list = ['vip_match', 'material', 'wait_apply']
        if not data or not filter(lambda x: x in paras_list, data):
            raise PARAMS_MISS()
        if 'vip_match' in data:  # vip进度, 写在model里
            vip_match_show = False if str(
                data.get('vip_match')) == '1' else True
            updated = self.spartnermatch.update_partner_match(
                1,
                {  # 更改: 这里的level没有用
                    'PSIMisclose': vip_match_show
                })
        if 'material' in data:  # 素材圈是否显示, 写在model里
            material_show = False if str(data.get('material')) == '1' else True
            updated = self.stopnav.update_topnav_by_tnidorname(
                data={'Tisdelete': material_show}, name='素材圈')

        if 'wait_apply' in data:  # 写在配置文件里
            wait_apply_show = data.get('wait_apply')
            wait_apply_show = '0' if str(wait_apply_show) == '0' else '1'
            Partner().set_item('show', 'wait_apply', wait_apply_show)
        msg = 'update_success'
        data = import_status(msg, "OK")
        return data
Exemplo n.º 10
0
    def share_activity(self):
        if is_tourist():
            raise TOKEN_ERROR(u'未登录')
        data = request.json
        logger.debug("share qrcode data is %s", data)
        # data_url = data.get("dataurl")
        data_url = self.get_share_url(data.get("dataurl"))
        try:
            logger.info("get user info")
            user = self.suser.get_user_by_user_id(request.user.id)
            if not user:
                raise SYSTEM_ERROR(u'找不到该用户')
            save_path = LinuxRoot + LinuxImgs + "/qrcode/" + user.openid + '.png' if platform.system(
            ) == "Linux" else WindowsRoot + "qrcode/" + user.openid + '.png'
            make_qrcode(user.USheader, data_url, save_path)
            response = import_status("make_qrcode_success", "OK")
            response[
                "qrcodeurl"] = QRCODEHOSTNAME + '/' + LinuxImgs + '/qrcode/' + user.openid + '.png'
            response[
                "components"] = QRCODEHOSTNAME + '/' + LinuxImgs + '/components.png'
            logger.debug('response url is %s', response["qrcodeurl"])

            url = data_url.split('#')[-1]
            from WeiDian.common.get_url_params import GetUrlParams
            parse_dict = GetUrlParams.url_params_to_dict(url)
            if 'baid' in parse_dict or 'prid' in parse_dict:
                # 分享时更改转发数
                paramstype = bool(not 'baid' in parse_dict)
                filter_parameter = {
                    'AClinkvalue':
                    parse_dict['prid'] if paramstype else parse_dict['baid'],
                    'ACSkipType':
                    2 if paramstype else 1,
                    'ACisdelete':
                    False
                }
                act_list = self.sactivity.get_acid_by_filterid(
                    filter_parameter)
                for act in act_list:
                    if act.ACforwardFakenum != 0:
                        self.sactivity.update_forward_fakenum(act.ACid)
                    else:
                        self.sactivity.add_model(
                            'ActivityFoward', **{
                                'AFid': str(uuid.uuid1()),
                                'USid': request.user.id,
                                'ACid': act.ACid
                            })

                if is_partner():

                    self.do_shoppingtask_or_forwardtask(1)
            return response
        except:
            logger.exception("make qrcode error")
            return SYSTEM_ERROR(u'服务器繁忙')
Exemplo n.º 11
0
 def set_show_type(self):
     if not is_admin():
         raise TOKEN_ERROR(u'请使用管理员登录')
     data = parameter_required('skip_type')
     try:
         skip_type = str(data.get('skip_type'))
         if skip_type not in ['0', '1', '2']:
             raise TypeError()
     except TypeError as e:
         raise PARAMS_ERROR(u'参数skip_type错误')
     Partner().set_item('skip', 'skip_type', skip_type)
     response = import_status('set_success', 'OK')
     return response
Exemplo n.º 12
0
    def get_hand_out_reward(self):
        """获取平台发放在页面中的优惠券"""
        if is_tourist():
            raise TOKEN_ERROR(u'未登录')
        horewards = self.sraward.get_all_hand_out()
        for horeward in horewards:
            reward = self.sraward.get_raward_by_id(horeward.RAid)
            reward_detail = self.fill_reward_detail(reward)
            horeward.fill(reward_detail, 'reward_detail')

        data = import_status("messages_get_item_ok", "OK")
        data['data'] = horewards
        return data
Exemplo n.º 13
0
 def get_useraddress(self):
     if not hasattr(request, 'user'):
         return TOKEN_ERROR(u"未登录, 或token错误")
     try:
         adderss_list = self.suesraddress.get_address_list_by_usid(
             request.user.id)
         logger.debug("get address list")
         self.fill_areainfo_by_areaid(adderss_list)
         data = import_status("get_useraddress_success", "OK")
         data['data'] = adderss_list
         return data
     except:
         logger.exception("get useraddress by usid error ")
         return SYSTEM_ERROR
Exemplo n.º 14
0
 def get_user_sub(self):
     data = request.args.to_dict()
     sub = data.get('sub')
     usid = data.get('usid')
     if sub == None:
         if not is_admin():
             raise TOKEN_ERROR(u'权限不足')
     else:
         if not is_partner():
             raise TOKEN_ERROR(u'当前非合伙人')
     logger.debug('get user sub args: %s', data)
     # parameter_required('usid')
     pagenum, pagesize = self.get_pagesize_pagenum(data)
     if usid:
         user = self.suser.get_user_by_user_id(usid)
     else:
         user = self.suser.get_user_by_user_id(request.user.id)
     user_sub, count = self.suser.get_sub_user(user.openid, pagesize,
                                               pagenum)
     response = import_status('messages_get_item_ok', 'OK')
     response['data'] = user_sub
     response['count'] = count
     return response
Exemplo n.º 15
0
 def batch_delete_prlike(self):
     if is_tourist():
         return TOKEN_ERROR(u'未登录')
     data = request.json
     plid_list = data.get("plid").split(
         ',') if data and 'plid' in data else None
     logger.info("batch del prlike data is %s", data)
     print plid_list
     try:
         self.sproductlike.batch_delete_prlike(plid_list)
         response = import_status('delete_activity_success', 'OK')
         response['data'] = {"plidlist": plid_list}
         return response
     except:
         logger.exception("batch del prlike error")
         return SYSTEM_ERROR
Exemplo n.º 16
0
    def set_share_params(self):
        if not is_admin():
            raise TOKEN_ERROR(u'请使用管理员登录')
        data = request.json
        title = data.get('title')
        # title = title.encode("utf8") if isinstance(title, unicode) else title

        content = data.get('content')
        img = data.get('img')

        parameter_required('title', 'content', 'img')
        Partner().set_item('share', 'title', title)
        Partner().set_item('share', 'content', content)
        Partner().set_item('share', 'img', img)
        response = import_status('set_success', 'OK')
        return response
Exemplo n.º 17
0
 def verify_inforcode(self):
     if not hasattr(request, 'user'):
         return TOKEN_ERROR(u"未登录, 或token错误")
     data = request.json
     user = self.suser.get_user_by_user_id(request.user.id)
     codeinfo = self.smycenter.get_inforcode_by_usphone(user.USphone)
     if not codeinfo:
         return SYSTEM_ERROR(u"用户验证信息错误")
     iccode = data.get("ICcode")
     verifystatus = True if iccode == codeinfo.ICcode else False
     verifymessage = u"验证码正确" if verifystatus is True else u"验证码错误"
     response = import_status("verify_inforcode_access", "OK")
     response["data"] = {
         "verifystatus": verifystatus,
         "verifymessage": verifymessage
     }
     return response
Exemplo n.º 18
0
    def get_all_user(self):
        if not is_admin():
            raise TOKEN_ERROR(u'权限不足')
        data = request.args.to_dict()
        logger.debug('get all user args : %s', data)
        pagenum, pagesize = self.get_pagesize_pagenum(data)

        user_list, count = self.suser.get_all_user(pagesize, pagenum)
        map(self.fill_user_level, user_list)
        map(self.fill_user_perd, user_list)
        # map(self.fill_user_sub, user_list)
        map(self.fill_user_order_amout, user_list)
        response = import_status('messages_get_item_ok', 'OK')
        response['data'] = user_list
        response['count'] = count

        return response
Exemplo n.º 19
0
 def add_comment(self):
     """添加评论数据"""
     if is_tourist():
         return AUTHORITY_ERROR(u'未登录')
     data = parameter_required(u'ACtext')
     acid = data.get('acid')
     acoid = data.get('acoid')
     usid = request.user.id
     actext = data.get('ACtext')
     # 添加评论
     if acid:
         activity = self.sactivity.get_activity_by_acid(acid)
         if not activity:
             raise NOT_FOUND(u'推文不存在')
         model_data = {
             'ACOid': str(uuid.uuid4()),
             'ACid': acid,
             'USid': usid,
             'ACtext': actext,
             'ACOcreatetime': datetime.strftime(datetime.now(),
                                                format_for_db)
         }
     # 如果是添加回复
     elif acoid:
         if not is_admin():
             raise TOKEN_ERROR(u'请使用管理员回复')
         comment = self.sactivitycomment.get_comment_by_acoid(acoid)
         if not comment:
             raise NOT_FOUND(u'不存在的评论')
         acid = comment.ACid
         model_data = {
             'ACOid': str(uuid.uuid4()),
             'ACid': acid,
             'ACOparentid': acoid,
             'USid': request.user.id,
             'ACtext': actext,
             'ACOcreatetime': datetime.strftime(datetime.now(),
                                                format_for_db)
         }
     else:
         raise PARAMS_MISS(u'请指定回复类型')
     self.sactivity.add_model('ActivityComment', **model_data)
     data = import_status('add_activity_comment_success', 'OK')
     data['data'] = {'acoid': model_data['ACOid']}
     return data
Exemplo n.º 20
0
    def get_like_list(self):
        """获取用户的收藏列表"""
        if is_tourist():
            return TOKEN_ERROR(u'未登录')
        args = request.args.to_dict()
        logger.debug("get like list args is %s", args)
        parameter_required("page_size", "page_num")
        page_num = args.get("page_num")
        page_size = args.get("page_size")
        page_num = 1 if not page_num else int(page_num)
        page_size = 5 if not page_size else int(page_size)
        try:
            productlike_list = self.sproductlike.get_productlike_list_by_usid(
                request.user.id, page_num, page_size)
            if not productlike_list:
                raise NOT_FOUND(u'用户无收藏信息')
            logger.info("get product like list success")
            map(self.fill_productinfo, productlike_list)
            # 获取转发数
            from WeiDian.service.SActivity import SActivity
            from WeiDian.service.SActivityFoward import SActivityFoward
            total_forward = 0
            for prlike in productlike_list:
                forward_act = SActivity().get_acid_by_filterid({
                    'AClinkvalue':
                    prlike.PRid,
                    'ACSkipType':
                    2,
                })
                for act in forward_act:
                    forward_num = SActivityFoward().get_fowardnum_by_acid(
                        act.ACid)
                    total_forward = total_forward + forward_num

                prlike.forwardnum = total_forward
                prlike.add("forwardnum")
            prlikecount = self.sproductlike.get_prlike_count_by_usid(
                request.user.id)
            data = import_status("get_product_like_success", "OK")
            data["count"] = prlikecount
            data["data"] = productlike_list
            return data
        except Exception as e:
            logger.exception("get product like error")
            raise SYSTEM_ERROR(u'收藏信息不存在')
Exemplo n.º 21
0
 def del_bankcard(self):
     if not hasattr(request, 'user'):
         return TOKEN_ERROR(u"未登录, 或token错误")
     data = request.json
     logger.info("this is del bankcard data %s", data)
     parameter_required("BCid")
     try:
         logger.debug("del bankcard")
         del_bankcard = self.sbankcard.del_bankcard(data.get("BCid"),
                                                    request.user.id)
         if not del_bankcard:
             return SYSTEM_ERROR
         response = import_status("delete_bankcard_success", "OK")
         response['data'] = {"bcid": data.get("BCid")}
         return response
     except:
         logger.exception("del address error")
         return SYSTEM_ERROR
Exemplo n.º 22
0
    def get_bankcard(self):
        if not hasattr(request, 'user'):
            return TOKEN_ERROR(u"未登录, 或token错误")
        args = request.args.to_dict()
        logger.info("get bankcard this is args %s", args)
        try:
            logger.debug("get bankcard")
            my_bankcard = self.sbankcard.get_bankcard_by_usid(request.user.id)

            if not my_bankcard or not my_bankcard.BCnumber or not my_bankcard.BCusername:
                my_bankcard = None

            response = import_status("get_bankcard_success", "OK")
            response['data'] = my_bankcard
            return response
        except:
            logger.exception("get bankcard error")
            return SYSTEM_ERROR
Exemplo n.º 23
0
 def get_reward_packet_detail(self):
     """获取单个集合详情"""
     if is_tourist():
         raise TOKEN_ERROR(u"未登录")
     args = request.args.to_dict()
     rptid = args.get('rptid')
     logger.debug("get reward packet detail args is %s", args)
     reward_packet = self.sraward.get_reward_packet_detail(rptid)
     for reward_one in reward_packet:
         raid = reward_one.RAid
         reward = self.sraward.get_raward_by_id(raid)
         reward_detail = self.fill_reward_detail(reward)
         reward_one.fill(reward_detail, 'reward_detail')
         packet_contact = self.sraward.get_is_where_packet(raid)
         if packet_contact:
             packet_info = self.sraward.get_reward_in_packet_info(packet_contact.RPTid)
             reward.fill(packet_info.RPTname, 'rptname')
     data = import_status("messages_get_item_ok", "OK")
     data['data'] = reward_packet
     return data
Exemplo n.º 24
0
    def user_receive_reward(self):
        """用户自己领取页面内的优惠券"""
        if is_tourist():
            raise TOKEN_ERROR(u'未登录')
        data = request.json
        parameter_required('raid')
        logger.debug("user recevive data is", data)
        usid = request.user.id
        raid = data.get('raid')

        # 判断发放的优惠券是否还有领取数量
        hang_out = self.sraward.is_hand_out({'RAid': raid})
        if hang_out:
            if hang_out.RTcount <= 0:
                raise NOT_FOUND(u'该优惠券已领取完毕')
            else:
                self.sraward.update_is_hand_out({'RAid': hang_out.RAid}, {'RTcount': hang_out.RTcount - 1})

        # 判断用户是否已持有
        is_hold = self.sraward.is_user_hold_reward({'USid': usid, 'RAid': raid})
        if is_hold:
            logger.info("The user already has this type of reward ")
            reward_info = self.sraward.get_raward_by_id(raid)
            urid = is_hold.URid
            if is_hold.RAnumber < reward_info.RAmaxholdnum:
                self.sraward.update_user_reward({'RAid': raid}, {'RAnumber': is_hold.RAnumber + 1})
            else:
                raise PARAMS_REDUNDANCE(u'已拥有该券最大可持有数量')
        else:
            logger.info("New reward to user")
            urid = str(uuid.uuid1())
            self.sraward.add_model('UserRaward', **{
                'URid': urid,
                'USid': usid,
                'RAid': raid,
            })

        data = import_status("receive_reward_success", "OK")
        data['data'] = {'urid': urid
                        }
        return data
Exemplo n.º 25
0
 def update_bankcard(self):
     if not hasattr(request, 'user'):
         return TOKEN_ERROR(u"未登录, 或token错误")
     args = request.args.to_dict()
     logger.info("this is update bankcard args %s", args)
     data = request.json
     logger.info("this is update bankcard data %s", data)
     try:
         parameter_required("bcid", "BCusername", "BCnumber", "BCbankname",
                            "BCaddress")
         update_bankcard = self.sbankcard.update_bankcard(
             args["bcid"], data)
         logger.debug("update bankcard accress")
         if not update_bankcard:
             return SYSTEM_ERROR
         response = import_status("update_bankcard_success", "OK")
         response["data"] = {"bcid": args["bcid"]}
         return response
     except:
         logger.exception("update bankcard error")
         return SYSTEM_ERROR
Exemplo n.º 26
0
 def add_like(self):
     """添加(删除)喜欢(收藏)"""
     if is_tourist():
         return TOKEN_ERROR()
     json_data = parameter_required('prid')
     prid = json_data.get('prid')
     # 该用户是否已经收藏了此商品
     already_like = self.sproductlike.get_productlike_by_usidprid(
         request.user.id, prid)
     if not already_like:
         pl_dict = dict(plid=str(uuid.uuid4()),
                        usid=request.user.id,
                        prid=prid)
         dict_add_models('ProductLike', pl_dict)
         self.sproduct.update_like_num(prid)
         data = import_status('add_productlike_success', 'OK')
     else:
         # 删除
         self.sproductlike.del_productlike_usidprid(request.user.id, prid)
         self.sproduct.update_like_num(prid, -1)
         data = import_status('cancel_product_like_success', 'OK')
     plid = already_like.PLid if already_like else pl_dict['plid']
     data['data'] = {'plid': plid}
     return data
Exemplo n.º 27
0
    def get_inforcode(self):
        # return TIME_ERROR
        if not hasattr(request, 'user'):
            return TOKEN_ERROR(u"未登录, 或token错误")
        user = self.suser.get_user_by_user_id(request.user.id)
        if not user:
            return SYSTEM_ERROR
        Utel = user.USphone
        # 拼接验证码字符串(6位)
        code = ""
        while len(code) < 6:
            import random
            item = random.randint(1, 9)
            code = code + str(item)

        # 获取当前时间,与上一次获取的时间进行比较,小于60秒的获取直接报错
        import datetime
        from WeiDian.common.timeformat import format_for_db
        time_time = datetime.datetime.now()
        time_str = datetime.datetime.strftime(time_time, format_for_db)

        # 根据电话号码获取时间
        time_up = self.smycenter.get_uptime_by_utel(Utel)
        logger.debug("this is time up %s", time_up)

        if time_up:
            time_up_time = datetime.datetime.strptime(time_up.ICtime,
                                                      format_for_db)
            delta = time_time - time_up_time
            if delta.seconds < 60:
                return import_status("ERROR_MESSAGE_GET_CODE_FAST",
                                     "WEIDIAN_ERROR",
                                     "ERROR_CODE_GET_CODE_FAST")

        new_inforcode = self.smycenter.add_inforcode(Utel, code, time_str)

        logger.debug("this is new inforcode %s ", new_inforcode)

        if not new_inforcode:
            return SYSTEM_ERROR
        from WeiDian.config.Inforcode import SignName, TemplateCode
        from WeiDian.common.Inforsend import send_sms
        params = '{\"code\":\"' + code + '\",\"product\":\"etech\"}'

        # params = u'{"name":"wqb","code":"12345678","address":"bz","phone":"13000000000"}'
        __business_id = uuid.uuid1()
        response_send_message = send_sms(__business_id, Utel, SignName,
                                         TemplateCode, params)

        response_send_message = json.loads(response_send_message)
        logger.debug("this is response %s", response_send_message)

        if response_send_message["Code"] == "OK":
            status = 200
        else:
            status = 405
        # 手机号中四位替换为星号
        # response_ok = {"usphone": Utel[:3] + '****' + Utel[-4: ]}
        response_ok = {"usphone": Utel}
        response_ok["status"] = status
        response_ok["messages"] = response_send_message["Message"]

        return response_ok
Exemplo n.º 28
0
 def get_bankname_list(self):
     if not hasattr(request, 'user'):
         return TOKEN_ERROR(u"未登录, 或token错误")
     data = import_status("get_useraddress_success", "OK")
     data['data'] = BANK_MAP
     return data
Exemplo n.º 29
0
    def get_user_reward(self):
        """获取用户(可转赠)优惠券"""
        if is_tourist():
            raise TOKEN_ERROR(u'未登录')
        args = request.args.to_dict()
        logger.debug("get reward args is %s", args)
        allow_transfer = args.get('transfer')
        reward_info = self.sraward.get_reward_by_usid(request.user.id)

        from WeiDian.models.model import RewardTransfer
        gift_reward_info = self.sraward.get_gifts_by_usfrom_or_usid(
            (RewardTransfer.USid == request.user.id, RewardTransfer.RFfrom == request.user.id))

        reward_list = []
        for reward in reward_info:
            reward_detail = self.sraward.get_raward_by_id(reward.RAid)
            reward_detail = self.fill_reward_detail(reward_detail)
            reward.fill(reward_detail, 'reward_detail')
            reward = dict(reward)

            lower_reward = {}
            for i, j in reward.items():
                lower_reward[i.lower()] = j

            lower_reward['urcreatetime'] = get_web_time_str(lower_reward.get('urcreatetime'))
            reward_list.append(lower_reward)
        for gift in gift_reward_info:
            gift = self.fill_transfer_detail(gift)
            gift_detail = self.sraward.get_raward_by_id(gift.RAid)
            gift_detail = self.fill_reward_detail(gift_detail)
            # 检验转赠券在各情况下的有效性
            gift_detail.valid = gift_detail.valid and gift.transfer_valid
            gift.fill(gift_detail, 'reward_detail')

            gift.RFcreatetime = get_web_time_str(gift.RFcreatetime)
            gift.RFendtime = get_web_time_str(gift.RFendtime)
            gift_dict = {
                'urid': gift.RFid,
                'usid': gift.USid,
                'raid': gift.RAid,
                'ranumber': gift.RAnumber,
                'urcreatetime': gift.RFcreatetime,
                'reendtime': gift.RFendtime,
                'rffrom': gift.RFfrom,
                'rfstatus': gift.RFstatus,
                'urusetime': gift.RFusetime,
                'remarks': gift.remarks,
                'tag': gift.tag,
                'usheader': gift.usheader,
                'reward_detail': gift.reward_detail
            }
            reward_list.append(gift_dict)

        # reward_info = filter(lambda r: r.get('reward_detail')['RAtype'] in [0, 2], reward_list)
        reward_info = filter(lambda k: k.get('ranumber') != 0, reward_list)

        if str(allow_transfer) == 'true':
            reward_info = filter(lambda r: r.get('reward_detail')['valid'] == True, reward_info)
            reward_info = filter(lambda r: r.get('reward_detail')['RAtransfer'] == True, reward_info)

        data = import_status('messages_get_item_ok', "OK")
        data['data'] = reward_info
        return data
Exemplo n.º 30
0
    def get_user_pay_reward(self):
        """查看用户支付时的优惠券"""
        if is_tourist():
            raise TOKEN_ERROR(u'未登录')
        data = request.json
        logger.debug("get pay reward data is %s", data)
        skus = data.get('sku')
        # parameter_required('sku')
        from WeiDian.service.SProductSkuKey import SProductSkuKey
        if skus:
            total_price = 0
            for sku in skus:
                price = SProductSkuKey().get_true_price(sku.get('pskid')) * int(sku.get('num'))
                total_price = total_price + price

        reward_info = self.sraward.get_reward_by_usid(request.user.id)
        from WeiDian.models.model import RewardTransfer
        gift_reward_info = self.sraward.get_gifts_by_usfrom_or_usid((RewardTransfer.USid==request.user.id, RewardTransfer.RFfrom==request.user.id))

        try:
            reward_list = []
            for reward in reward_info:
                if reward:
                    reward_detail = self.sraward.get_raward_by_id(reward.RAid)
                    reward_detail = self.fill_reward_detail(reward_detail, total_price)
                    reward.fill(reward_detail, 'reward_detail')
                    reward = dict(reward)

                lower_reward = {}
                for i, j in reward.items():
                    lower_reward[i.lower()] = j

                lower_reward['urcreatetime'] = get_web_time_str(lower_reward.get('urcreatetime'))
                reward_list.append(lower_reward)
            for gift in gift_reward_info:
                if gift not in ['', [], {}, None]:
                    gift = self.fill_transfer_detail(gift)
                    gift_detail = self.sraward.get_raward_by_id(gift.RAid)
                    gift_detail = self.fill_reward_detail(gift_detail, total_price)
                    # 检验转赠券在各情况下的有效性
                    gift_detail.valid = gift_detail.valid and gift.transfer_valid
                    gift.fill(gift_detail, 'reward_detail')

                    gift.RFcreatetime = get_web_time_str(gift.RFcreatetime)
                    gift.RFendtime = get_web_time_str(gift.RFendtime)
                    gift_dict = {
                        'urid': gift.RFid,
                        'usid': gift.USid,
                        'raid': gift.RAid,
                        'ranumber': gift.RAnumber,
                        'urcreatetime': gift.RFcreatetime,
                        'reendtime': gift.RFendtime,
                        'rffrom': gift.RFfrom,
                        'rfstatus': gift.RFstatus,
                        'urusetime': gift.RFusetime,
                        'remarks': gift.remarks,
                        'tag': gift.tag,
                        'usheader': gift.usheader,
                        'reward_detail': gift.reward_detail
                    }
                    reward_list.append(gift_dict)
            if reward_list not in [None, [], {}]:
                reward_info = filter(lambda r: r.get('reward_detail')['RAtype'] in [0, 2], reward_list)
                reward_info = filter(lambda k: k.get('ranumber') != 0, reward_info)

            data = import_status('messages_get_item_ok', "OK")
            data['data'] = reward_info
            return data
        except Exception as e:
            logger.exception("get user reward error")
            raise SYSTEM_ERROR(u'获取数据错误')