Exemplo n.º 1
0
def upload_image():
    if 'file' not in request.files:
        raise HttpError(400, "缺少file参数")
    file = request.files['file']
    if file.filename == '':
        raise HttpError(400, "未发现文件")
    content = file.read()

    # 图片格式限制
    extname = file.filename.rsplit('.', 1)[1].lower()
    if extname not in ['png', 'jpg', 'jpeg', 'gif']:
        raise HttpError(400, "不支持此格式图片上传")

    # 图片大小限制
    max_size = 5
    size = int(math.ceil(len(content) / 1024.0))  # size KB
    if size > max_size * 1024:
        raise HttpError(400, u"图片不能超过%sM" % max_size)

    md5sum = md5(content).lower()
    full_path = "%s/%s/%s/%s.%s" % (app.config["IMAGE_UPLOAD_PATH"],
                                    md5sum[:2], md5sum[2:4], md5sum, extname)

    directory = os.path.dirname(full_path)
    if not os.path.exists(directory):
        os.makedirs(directory)

    output_file = open(full_path, 'w+')
    output_file.write(content)

    url = path_to_url(full_path)
    res = rpc.invbox.check_add_image(md5sum,
                                     url,
                                     base_url=app.config["DOMAIN"])
    return jsonify(res)
Exemplo n.º 2
0
def wechat_auth_redirect():
    rdata = RequestData()
    code = rdata.get("code", default="")
    if not code:
        raise HttpError(400, "授权失败")

    url = "https://api.weixin.qq.com/sns/oauth2/access_token"
    params = {
        "appid": APPID,
        "secret": APPSECRET,
        "code": code,
        "grant_type": "authorization_code"
    }
    url = "%s?%s" % (url, urllib.urlencode(params))

    r = requests.get(url, timeout=15)
    data = r.json()
    if "access_token" not in data:
        raise HttpError(400, data["errmsg"])

    # access_token = data["access_token"]
    openid = data["openid"]
    info = rpc.invbox.get_user(openid)
    return jsonify({
        "openid": openid,
        "mobile": info["mobile"],
    })
Exemplo n.º 3
0
    def post(self):
        rdata = RequestData()
        name = rdata.get("name", type=str)
        if not name:
            raise HttpError(400, "名称不能为空")
        new = rpc.invbox.add_device_category(name, rdata["roadList"])

        if new["resultCode"]:
            raise HttpError(400, new["resultMsg"])
        del new["resultCode"]
        del new["resultMsg"]
        return jsonify(new)
Exemplo n.º 4
0
    def put(self):
        rdata = RequestData()

        params = []
        for d in rdata:
            if int(d["basicPrice"]) <= 0 or int(d["costPrice"]) <= 0:
                raise HttpError(400, "价格必须为正数")
            params.append(d)
        res = rpc.invbox.modify_items(params)

        if res["resultCode"]:
            raise HttpError(400, res["resultMsg"])
        return ""
Exemplo n.º 5
0
def post_video():
    rdata = RequestData()
    md5 = rdata["md5"]
    url = rdata["url"]

    if not md5 or not url:
        raise HttpError(400, "非法参数")

    res = rpc.invbox.get_video_detail(md5)
    if res:
        raise HttpError(400, "添加失败,已存在md5为%s的视频" % md5)

    res = rpc.invbox.add_video(md5, url)
    return jsonify(res)
Exemplo n.º 6
0
    def delete(self):
        rdata = RequestData()
        data = rpc.invbox.delete_user_groups(rdata.array)

        if data["resultCode"]:
            raise HttpError(400, data["resultMsg"])
        return ""
Exemplo n.º 7
0
 def get_item_overview(self, ):
     stats = rpc.invbox.stat_overview_of_item(self.start_date,
                                              self.end_date,
                                              item=self.item)
     if stats["resultCode"]:
         raise HttpError(400, stats["resultMsg"])
     panels = [
         {
             "title": "总访问量",
             "value": stats["totalClicks"],
             "subTitle": "日均访问量",
             "subValue": stats["avgClicks"]
         },
         {
             "title": "总访客数",
             "value": stats["totalVisitors"],
             "subTitle": "日均访客数",
             "subValue": stats["avgVisitors"]
         },
         {
             "title": "支付笔数",
             "value": stats["totalOrdersPay"],
             "subTitle": "日支付笔数",
             "subValue": stats["avgOrdersPay"]
         },
         {
             "title": "平均购物转化率",
             "value": stats["conversion"],
             "subTitle": "",
             "subValue": ""
         },
     ]
     return panels
Exemplo n.º 8
0
 def get_order_conversion(self):
     stats = rpc.invbox.stat_conversion_of_order(self.start_date,
                                                 self.end_date)
     if stats["resultCode"]:
         raise HttpError(400, stats["resultMsg"])
     stats = [
         {
             "title": "人流量",
             "name": "flows",
             "value": stats["totalFlows"],
         },
         {
             "title": "停留人数",
             "name": "stays",
             "value": stats["totalStays"],
         },
         {
             "title": "进入结算页",
             "name": "ordersCreate",
             "value": stats["totalOrdersCreate"],
         },
         {
             "title": "付款成功",
             "name": "ordersPay",
             "value": stats["totalOrdersPay"]
         },
     ]
     return stats
Exemplo n.º 9
0
 def get_user_overview(self, ):
     stats = rpc.invbox.stat_overview_of_user(self.start_date,
                                              self.end_date,
                                              user_group=self.user_group)
     if stats["resultCode"]:
         raise HttpError(400, stats["resultMsg"])
     panels = [
         {
             "title": "总用户",
             "value": stats["totalUsers"],
             "subTitle": "",
             "subValue": "",
         },
         {
             "title": "活跃用户",
             "value": stats["totalActives"],
             "subTitle": "日活跃",
             "subValue": stats["avgActives"]
         },
         {
             "title": "净增购买用户",
             "value": stats["totalRegisters"],
             "subTitle": "日净增",
             "subValue": stats["avgRegisters"]
         },
         {
             "title": "留存率",
             "value": stats["retention"],
             "subTitle": "",
             "subValue": ""
         },
     ]
     return panels
Exemplo n.º 10
0
    def get_order_overview(self, ):
        stats = rpc.invbox.stat_overview_of_order(self.start_date,
                                                  self.end_date)
        if stats["resultCode"]:
            raise HttpError(400, stats["resultMsg"])

        panels = [
            {
                "title": "总销售额",
                "value": stats["totalSalesVolume"],
                "subTitle": "日均销售额",
                "subValue": stats["avgSalesVolume"]
            },
            {
                "title": "支付客户数",
                "value": stats["totalUsersPay"],
                "subTitle": "日均客户数",
                "subValue": stats["avgUsersPay"]
            },
            {
                "title": "支付笔数",
                "value": stats["totalOrdersPay"],
                "subTitle": "日支付笔数",
                "subValue": stats["avgOrdersPay"]
            },
            {
                "title": "客单价",
                "value": stats["userUnitPrice"],
                "subTitle": "",
                "subValue": ""
            },
        ]
        return panels
Exemplo n.º 11
0
    def delete(self):
        rdata = RequestData()
        data = rpc.invbox.delete_voice_activities(rdata.array)

        if data["resultCode"]:
            raise HttpError(400, data["resultMsg"])
        return ""
Exemplo n.º 12
0
    def post(self):
        if current_user["role"] != 0:
            return {"resultCode": 1, "resultMsg": "您没有操作权限"}
        rdata = RequestData()

        name = rdata.get('name', type=str)
        mobile = rdata.get('mobile', type=str)
        password = rdata.get('password', type=str)
        com_pwd = rdata.get('comPwd', type=str)
        role = rdata.get('role')
        admin_range = rdata.get('range')
        info_list = rdata.get('infoList')
        if not name:
            raise HttpError(400, "用户名不能为空")
        if not is_mobile(mobile):
            raise HttpError(400, "手机号码格式不正确")
        if not password == com_pwd:
            raise HttpError(400, "两次输入密码不一致")
        if not role:
            raise HttpError(400, "请输入用户角色")
        if str(role) not in ["1", "2", "3"]:
            raise HttpError(400, "不存在的用户角色")
        if not admin_range:
            raise HttpError(400, "请输入管理范围")

        # TODO:检查修改添加人的管理员权限
        # privilege =

        new_account = rpc.invbox.add_account(name, mobile, password, int(role),
                                             admin_range, info_list)
        if new_account.get("resultCode"):
            raise HttpError(400, "%s" % new_account.get("resultMsg"))
        return jsonify(new_account)
Exemplo n.º 13
0
def send_wechat_sms():
    "发送手机验证码"
    rdata = RequestData()
    mobile = rdata["mobile"]
    res = rpc.invbox.send_message_for_wechat(mobile)

    if res["resultCode"]:
        raise HttpError(400, res["resultMsg"])
    return jsonify(res)
Exemplo n.º 14
0
def send_code_sms():
    "发送登录验证码"
    rdata = RequestData()
    mobile = rdata["mobile"]
    res = rpc.invbox.send_login_message(mobile)

    if res["resultCode"]:
        raise HttpError(400, res["resultMsg"])
    return jsonify(res)
Exemplo n.º 15
0
    def post(self):
        rdata = RequestData()

        basic_price = rdata.get("basicPrice", type=int)
        cost_price = rdata.get("costPrice", type=int)
        if basic_price <= 0 or cost_price <= 0:
            raise HttpError(400, "价格必须为正数")

        new = rpc.invbox.add_item(rdata["name"], rdata["no"] or "",
                                  rdata["category"], rdata["brand"],
                                  rdata["thumbnails"], basic_price, cost_price)

        if new["resultCode"]:
            raise HttpError(400, new["resultMsg"])

        del new["resultCode"]
        del new["resultMsg"]
        return jsonify(new)
Exemplo n.º 16
0
    def post(self):
        rdata = RequestData()
        new = rpc.invbox.add_supplylist(rdata["device"], rdata["itemInfo"])

        if new["resultCode"]:
            raise HttpError(400, new["resultMsg"])

        del new["resultCode"]
        del new["resultMsg"]
        return jsonify(new)
Exemplo n.º 17
0
    def post(self):
        rdata = RequestData()
        new = rpc.invbox.add_device_group(rdata["name"], rdata["condition"])

        if new["resultCode"]:
            raise HttpError(400, new["resultMsg"])

        del new["resultCode"]
        del new["resultMsg"]
        return jsonify(new)
Exemplo n.º 18
0
    def post(self):
        rdata = RequestData()
        limit = rdata.get("limit", type=int)

        if limit <= 0:
            raise HttpError(400, "上限值只能输入正数")

        new = rpc.invbox.add_voice_activity(rdata["code"],
                                            rdata["deviceGroup"],
                                            rdata["validStartAt"],
                                            rdata["validEndAt"], limit,
                                            rdata["item"])

        if new["resultCode"]:
            raise HttpError(400, new["resultMsg"])

        del new["resultCode"]
        del new["resultMsg"]

        return jsonify(new)
Exemplo n.º 19
0
    def put(self):
        rdata = RequestData()

        params = []
        for d in rdata:
            params.append(d)
        res = rpc.invbox.modify_ads(params)

        if res["resultCode"]:
            raise HttpError(400, res["resultMsg"])
        return ""
Exemplo n.º 20
0
    def put(self):
        rdata = RequestData()
        params = []
        for d in rdata:
            name = rdata.base_get(d, "name", type=str)
            if not name:
                raise HttpError(400, "名称不能为空")
            params.append({
                "id": rdata.base_get(d, "id"),
                "name": name,
                "roadList": rdata.base_get(d, "roadList"),
            })
            for rd in d["roadList"]:
                rdata.base_get(rd, "upperLimit")
                rdata.base_get(rd, "lowerLimit")

        res = rpc.invbox.modify_device_categories(params)
        if res["resultCode"]:
            raise HttpError(400, res["resultMsg"])
        return ""
Exemplo n.º 21
0
    def delete(self):
        if current_user["role"] != 0:
            print(current_user["role"])
            return jsonify({"resultCode": 1, "resultMsg": "您没有操作权限"})
        rdata = RequestData()
        data = rpc.invbox.delete_account(rdata.array)

        if data["resultCode"]:
            raise HttpError(400, data["resultMsg"])

        return jsonify(data)
Exemplo n.º 22
0
def bind_mobile():
    rdata = RequestData()
    openid = rdata["openid"]
    mobile = rdata["mobile"]
    code = rdata["code"]
    info = rpc.invbox.modify_user(openid, mobile, code)
    if info["resultCode"]:
        raise HttpError(400, info["resultMsg"])
    del info["resultCode"]
    del info["resultMsg"]
    return jsonify(info)
Exemplo n.º 23
0
    def put(self):
        rdata = RequestData()

        params = []
        for d in rdata:
            name = d["name"].strip()
            if not name:
                raise HttpError(400, "名字不能为空")
            if not is_mobile(d["mobile"]):
                raise HttpError(400, "手机号码格式不正确")
            params.append({
                "id": d["id"],
                "name": name,
                "mobile": d["mobile"],
            })

        res = rpc.invbox.modify_supplyers(params)

        if res["resultCode"]:
            raise HttpError(400, res["resultMsg"])
        return ""
Exemplo n.º 24
0
    def put(self):
        rdata = RequestData()

        params = []
        for d in rdata:
            if int(d["limit"]) <= 0:
                raise HttpError(400, "上限值只能输入正数")
            params.append({
                "id": d["id"],
                "code": d["code"],
                "validStartAt": d["validStartAt"],
                "validEndAt": d["validEndAt"],
                "item": d["item"],
                "limit": d["limit"],
                "deviceGroup": d["deviceGroup"],
            })

        res = rpc.invbox.modify_voice_activities(params)

        if res["resultCode"]:
            raise HttpError(400, res["resultMsg"])
        return ""
Exemplo n.º 25
0
    def post(self):
        rdata = RequestData()
        new = rpc.invbox.add_address_type(rdata.get("name", type=str))

        if new["resultCode"]:
            raise HttpError(400, new["resultMsg"])

        result = {
            "id": new["id"],
            "name": new["name"] or "",
            "createdAt": new["createdAt"],
        }
        return jsonify(result)
Exemplo n.º 26
0
    def post(self):
        rdata = RequestData()
        new = rpc.invbox.add_brand(rdata["name"].strip())

        if new["resultCode"]:
            raise HttpError(400, new["resultMsg"])

        result = {
            "id": new["id"],
            "name": new["name"] or "",
            "createdAt": new["createdAt"],
        }
        return jsonify(result)
Exemplo n.º 27
0
    def put(self):
        if current_user["role"] != 0:
            return {"resultCode": 1, "resultMsg": "您没有操作权限"}
        rdata = RequestData()

        params = []
        for d in rdata:
            id = d.get("id")
            mobile = d.get("mobile")
            name = d.get("name")
            new_pwd = d.get("password")
            com_pwd = d.get("comPwd")
            role = d.get("role")
            admin_range = d.get("range")
            info_list = d.get("infoList")
            if mobile:
                if not is_mobile(d["mobile"]):
                    raise HttpError(400, "手机号码格式不正确")
            if new_pwd:
                if not new_pwd == com_pwd:
                    raise HttpError(400, "两次输入密码不一致")
            if role:
                if int(role) not in [1, 2, 3]:
                    raise HttpError(400, "不存在的角色")
            params.append({
                "id": id,
                "name": name,
                "mobile": mobile,
                "password": new_pwd,
                "role": int(role),
                "admin_range": admin_range,
                "info_list": info_list
            })
        res = rpc.invbox.modify_accounts(params)

        if res["resultCode"]:
            raise HttpError(400, res["resultMsg"])
        return jsonify(res)
Exemplo n.º 28
0
    def post(self):
        rdata = RequestData()
        new = rpc.invbox.add_redeem_activity(rdata["name"], rdata["userGroup"],
                                             rdata["validStartAt"],
                                             rdata["validEndAt"],
                                             rdata["item"])

        if new["resultCode"]:
            raise HttpError(400, new["resultMsg"])

        del new["resultCode"]
        del new["resultMsg"]

        return jsonify(new)
Exemplo n.º 29
0
    def get(self):
        self.init_params()
        stype = self.stype
        if stype == "item":
            columns, values = self.get_item_table()
        if stype == "user":
            columns, values = self.get_user_table()
        else:
            raise HttpError(400, "未实现")

        return jsonify({
            "columns": columns,
            "values": values,
        })
Exemplo n.º 30
0
    def get(self):
        self.init_params()
        stype = self.stype

        if stype == "order":
            stats = self.get_order_conversion()
        else:
            raise HttpError(400, "未实现")

        return jsonify({
            "startDate": self.start_date,
            "endDate": self.end_date,
            "stats": stats
        })