Example #1
0
def user_likes():
    if request.method == 'POST':
        for n in ['user_id', 'dish_id', 'restaurant_id', 'method']:
            if n not in request.form:
                return abort(406)
        try:
            from tools.db_dishlikes import DishLikes
            todo = {'user_id': request.form['user_id'],
                    'dish_id': request.form['dish_id'],
                    'restaurant_id': request.form['restaurant_id']}
            if request.form['method'] == 'like':
                handle = DishLikes().addlike(todo)
            elif request.form['method'] == 'dislike':
                handle = DishLikes().dislike(todo)
            else:
                return abort(403)
            jwtmsg = auto.decodejwt(request.form["jwtstr"])
            if handle['success']:
                result = tool.return_json(0, "success", jwtmsg, True)
            else:
                result = tool.return_json(0, "field", False, handle['error'])
            return json_util.dumps(result, ensure_ascii=False, indent=2)
        except Exception, e:
            print e
            result = tool.return_json(0, "field", False, e)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #2
0
def dishlikes():
    if request.method == 'POST':
        try:
            from tools.db_dishlikes import DishLikes
            if 'restaurant_id' in request.form:
                start = datetime.datetime(*time.strptime(request.form['start_time'], '%Y-%m-%d')[:6])
                end = datetime.datetime(*time.strptime(request.form['end_time'], '%Y-%m-%d')[:6]) + datetime.timedelta(days=1)
                f = {'restaurant_id': request.form['restaurant_id'], 'timestamp': {"$gte": start, "$lte": end}}
                found = DishLikes().shoplikes(f)
            elif 'user_id' in request.form:
                f = {'user_id': request.form['user_id']}
                found = DishLikes().findlikes(f)
            else:
                result = tool.return_json(0, "field", False, 'Request id Not Support')
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            jwtmsg = auto.decodejwt(request.form["jwtstr"])
            if found['success']:
                result = tool.return_json(0, "success", jwtmsg, found['data'])
            else:
                result = tool.return_json(0, "field", False, found['error'])
            return json_util.dumps(result, ensure_ascii=False, indent=2)
        except Exception, e:
            print e
            result = tool.return_json(0, "field", False, e)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
        pass
Example #3
0
def restaurant_comment_list():
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):

            start = datetime.datetime(*time.strptime(request.form['start_time'], '%Y-%m-%d')[:6])
            end = datetime.datetime(*time.strptime(request.form['end_time'], '%Y-%m-%d')[:6]) + datetime.timedelta(days=1)
            try:
                from tools.db_comment import Comment
                m = {'restaurant_id': request.form['restaurant_id'], 'post_date': {"$gte": start, "$lte": end}}
                if 'stars' in request.form:
                    m['rating.total'] = request.form['stars']
                found = Comment().conn.find(m).skip(int(request.form['skip'])).limit(10)
                if found:
                    found = json_util.loads(json_util.dumps(found))
                    for n in found:
                        del n['dish_id']
                        del n['order_id']
                        n['_id'] = str(n['_id'])
                        n['post_date'] = n['post_date'].strftime('%Y年%m月%d日 %H:%M:%S')
                else:
                    found = []
                result = tool.return_json(0, "success", True, found)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            except Exception, e:
                print e
                result = tool.return_json(0, "field", False, e)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            pass
        else:
            result=tool.return_json(0,"field",False,None)
            return json_util.dumps(result,ensure_ascii=False,indent=2)
Example #4
0
def dejwt():
    # print 'adshjfgjahsgjihsalkjghlkadshglkh'
    jsonstr = request.form["msg"]
    # print jsonstr
    a = auto.decodejwt(jsonstr)
    # print a
    return "%s" % a
Example #5
0
def sendmessage_yh_31():
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):

            try:
                #mfrom-消息来源id|mto-发送给谁id数组,下划线分隔|title-消息标题|info-消息内容|goto("0")-跳转页位置|channel(订单)-调用位置|type-0系统发 1商家发 2用户发|totype-0发给商家 1发给用户
                # appname(foodmap_user,foodmap_shop)-调用的APP|msgtype(message,notice)-是消息还是通知|target(all,device)-全推或单推|ispush(True,False)-是否发送推送|
                item = tool.tuisong(mfrom=request.form['restaurant_id'],
                                    mto=request.form['webuserids'],
                                    title='您的点菜已被安排',
                                    info='快去看看吧!',
                                    goto='12',
                                    channel='接单',
                                    type='1',
                                    totype='1',
                                    appname='foodmap_user',
                                    msgtype='notice',
                                    target='device',
                                    ext='{"goto":"12","id":"' +
                                    request.form['order_id'] + '"}',
                                    ispush=True)
                result = tool.return_json(0, "success", True, item)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            except Exception, e:
                print e
                result = tool.return_json(0, "field", False, None)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #6
0
def frommessages():
    if request.method=='POST':
        if auto.decodejwt(request.form['jwtstr']):
            try:
                start=datetime.datetime(*time.strptime(request.form['start_time'],'%Y-%m-%d')[:6])
                end = datetime.datetime(*time.strptime(request.form['end_time'],'%Y-%m-%d')[:6])+datetime.timedelta(days = 1)
                item = mongo.message.find({'infofrom':ObjectId(request.form["restaurant_id"]),'add_time': {'$gte': start, '$lt': end}})

                data = {}
                list = []
                for i in item:
                    json = {}
                    for key in i.keys():
                        if key == '_id':
                            json['id'] = str(i[key])
                        elif key == 'infos':
                            json['title'] = i['infos']['infotitle']
                        elif key == 'add_time':
                            json['add_time'] = i[key].strftime('%Y年%m月%d日')
                        elif key == 'goto':
                            json['goto'] = i[key]
                    list.append(json)
                data['list'] = list
                result=tool.return_json(0,"success",True,data)
                return json_util.dumps(result,ensure_ascii=False,indent=2)
            except Exception,e:
                print e
                result=tool.return_json(0,"field",False,None)
                return json_util.dumps(result,ensure_ascii=False,indent=2)
        else:
            result=tool.return_json(0,"field",False,None)
            return json_util.dumps(result,ensure_ascii=False,indent=2)
Example #7
0
def deletemembers():
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):

            try:
                idlist = request.form['idlist'].split('_')
                midlist = []
                for mid in idlist:
                    if mid != '' and mid != None:
                        midlist.append(ObjectId(mid))
                mongo.members.update({"_id": {
                    '$in': midlist
                }}, {"$set": {
                    "status": 1
                }},
                                     multi=True)
                json = {"status": 1, "msg": ""}
                result = tool.return_json(0, "success", True, json)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            except Exception, e:
                print e
                result = tool.return_json(0, "field", False, None)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #8
0
def updaterestaurant_discount():
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):
            try:
                pdict = {
                    "restaurant_discount.message":
                    request.form["message"],
                    "restaurant_discount.start_time":
                    datetime.datetime.strptime(request.form["start_time"],
                                               "%Y-%m-%d"),
                    "restaurant_discount.end_time":
                    datetime.datetime.strptime(request.form["end_time"],
                                               "%Y-%m-%d"),
                }
                mongo.restaurant.update_one(
                    {"_id": ObjectId(request.form["restaurant_id"])},
                    {"$set": pdict})
                json = {"status": 1, "msg": ""}
                result = tool.return_json(0, "success", True, json)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            except Exception, e:
                print e
                result = tool.return_json(0, "field", False, None)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #9
0
def coupons_info():
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):
            try:
                item = mongo.restaurant.find(
                    {"_id": ObjectId(request.form['restaurant_id'])})
                data = {}
                for i in item:
                    data['id'] = str(i['_id'])
                    data['open'] = i['open']
                    data['guide_image'] = i['guide_image']
                    data['name'] = i['name']
                    dishes_type = []
                    for type in i['dishes_type']:
                        dishes_type.append(type['name'])
                    data['dishes_type'] = '  '.join(dishes_type)
                    data['kind1'] = getcoupons('1', str(i['_id']))['content']
                    data['kind2'] = getcoupons('2', str(i['_id']))['content']
                    data['kind3'] = getcoupons('3', str(i['_id']), flag='0')
                    data['address'] = i['address']
                    data['phone'] = i['phone']
                result = tool.return_json(0, "success", True, data)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            except Exception, e:
                print e
                result = tool.return_json(0, "field", True, str(e))
                return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #10
0
def send_sms():
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):
            try:
                # if mongo.find({"phone":request.form['phone']}):
                # data = {'sign': '美食地图',
                #         'tpl': 'SMS_8161119',
                #         'param': json.dumps({"code": str(random.randint(1000000, 9999999))[1:]}),
                #         'tel': request.form['phone'],
                #         'ex': '#foodmap.mobile'
                #         }
                # req = requests.post(SMSnetgate + '/sms.send', data)
                send = make_sure_sms_send(request.form['phone'], "")
                result = tool.return_json(0, "success", True, {
                    "ispass": send['success'],
                    "message": "成功"
                })
                # else:
                #     result=tool.return_json(0,"field",True,{"ispass":False,"message":"请先注册"})
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            except Exception, e:
                print e
                result = tool.return_json(0, "field", True, str(e))
                return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #11
0
def updatedishs():
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):
            try:
                redish = {
                    str(request.form['dish_id']): {
                        'price': float(request.form['price']),
                        'name': request.form['name'],
                        'guide_image': request.form['guide_image'],
                        'type': request.form['type']
                    }
                }
                # redish = request.form['redish']
                # jsonredish = json.loads(redish)
                first = tool.Discount(request.form["restaurant_id"])
                first.re_dish(redish)
                first.submit2db()
                jsons = {"status": 1, "msg": ""}
                result = tool.return_json(0, "success", True, jsons)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            except Exception, e:
                print e
                result = tool.return_json(0, "field", False, None)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #12
0
def menutypes():
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):
            try:
                pdict = {'_id': request.form["restaurant_id"]}
                item = mongo.restaurant.find(tools.orderformate(pdict, table),
                                             {
                                                 "menu.name": 1,
                                                 "menu.id": 1,
                                                 "_id": 0
                                             })
                data = {}
                list = []
                for i in item:
                    for j in i['menu']:
                        #如果需要修改优惠菜和推荐菜 就取消下面这句判断 暂定只修改菜品和酒水
                        if j['name'] != '优惠菜' and j['name'] != '推荐菜':
                            list.append(j)
                data['list'] = list
                result = tool.return_json(0, "success", True, data)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            except Exception, e:
                print e
                result = tool.return_json(0, "field", False, None)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #13
0
def sendmess():
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):

            try:

                if sendmes(mfrom=request.form['restaurant_id'],
                           mto=request.form['webuserids'],
                           title=request.form['title'],
                           info=request.form['info']):
                    json = {"status": 1, "msg": ""}
                    result = tool.return_json(0, "success", True, json)
                    return json_util.dumps(result,
                                           ensure_ascii=False,
                                           indent=2)
                else:
                    result = tool.return_json(0, "field", False, None)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            except Exception, e:
                print e
                result = tool.return_json(0, "field", False, None)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #14
0
def checkphonetype():
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):
            try:
                user_id = request.form['user_id']
                user = conn.mongo_conn().webuser.find(
                    {"_id": ObjectId(user_id)})
                u_id = ''
                for u in user:
                    u_id = u['automembers_id']
                phonetype = request.form['phonetype']
                msg = ""
                item = mongouser.user_web.find({"_id": ObjectId(u_id)})
                for i in item:
                    if "type" not in i['lastlogin'].keys():
                        mongouser.user_web.update_one(
                            {"_id": ObjectId(u_id)},
                            {"$set": {
                                "lastlogin.type": phonetype
                            }})
                        msg = "修改成功"
                    else:
                        msg = "无需修改"
                        pass
                result = tool.return_json(0, "success", True, msg)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            except Exception, e:
                print e
                result = tool.return_json(0, "field", True, str(e))
                return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #15
0
def app_comment_submit():
    if request.method == 'POST':
        for n in ['restaurant_id', 'user_id', 'user_name', 'user_head', 'comment_text', 'comment_pic', 'rating_total',
                  'rating_taste', 'rating_env', 'rating_service']:
            if n not in request.form:
                return abort(406)
        data = {
            'restaurant_id': is_one('restaurant_id', request.form),
            'dish_id': is_one('dish_id', request.form),
            'order_id': is_one('order_id', request.form),
            'user_id': is_one('user_id', request.form),
            'user_info': {'user_name': is_one('user_name', request.form),
                          'user_head': is_one('user_head', request.form)},
            'post_date': datetime.now(),
            'rating': {'total': int(is_one('rating_total', request.form)),
                       'taste': int(is_one('rating_taste', request.form)),
                       'env': int(is_one('rating_env', request.form)),
                       'service': int(is_one('rating_service', request.form))},
            'comment_text': is_one('comment_text', request.form),
            'comment_pic': json.loads(is_one('comment_pic', request.form))
        }
        if Comment().add(data):
            jwtmsg = auto.decodejwt(request.form["jwtstr"])
            result = tool.return_json(0, "success", jwtmsg, '')
            return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
    else:
        return abort(403)
    pass
Example #16
0
def redishslist():
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):
            try:
                pdict = {'_id': request.form["restaurant_id"]}
                item = mongo.restaurant.find(tools.orderformate(pdict, table),
                                             {"menu": 1})
                dishs_dict = {}
                dishs_list = []
                for i in item:

                    for dishs in i['menu']:
                        if dishs['name'] == request.form[
                                'name'] and dishs['name'] != '优惠菜' and dishs[
                                    'name'] != '推荐菜' and dishs[
                                        'dish_type'] == '1' and dishs[
                                            'dishs'] != []:
                            for dish in dishs['dishs']:
                                json = {}
                                json['dish_id'] = dish['id']
                                json['price'] = dish['price']
                                json['name'] = dish['name']
                                json['discount_price'] = dish['discount_price']
                                json['type'] = dish['type']
                                dishs_list.append(json)
                dishs_dict['dishs_list'] = dishs_list
                result = tool.return_json(0, "success", True, dishs_dict)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            except Exception, e:
                print e
                result = tool.return_json(0, "field", False, None)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #17
0
def notification(order_id):
    item = mongo.order.update_one({"_id": ObjectId(order_id)},
                                  {"$set": {
                                      "status": 2
                                  }})
    json = {"order_id": item, "status": 2, "msg": ""}
    jwtmsg = auto.decodejwt(request.form["jwtstr"])
    result = tool.return_json(0, "success", jwtmsg, json)
    return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #18
0
def updateorder():
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):

            try:
                pdict = {
                    'username':
                    request.form["username"],
                    'phone':
                    request.form["phone"],
                    'demand':
                    request.form["demand"],
                    'numpeople':
                    request.form["numpeople"],
                    'room_id':
                    request.form["room_id"],
                    'preset_time':
                    datetime.datetime.strptime(request.form["preset_time"],
                                               "%Y-%m-%d %H:%M:%S")
                }
                mongo.order.update_one(
                    {'_id': ObjectId(request.form['id'])},
                    {"$set": tools.orderformate(pdict, table)})
                #mfrom-消息来源id|mto-发送给谁id数组,下划线分隔|title-消息标题|info-消息内容|goto("0")-跳转页位置|channel(订单)-调用位置|type-0系统发 1商家发 2用户发|totype-0发给商家 1发给用户
                # appname(foodmap_user,foodmap_shop)-调用的APP|msgtype(message,notice)-是消息还是通知|target(all,device)-全推或单推|ispush(True,False)-是否发送推送|
                order = mongo.order.find({"_id": ObjectId(request.form['id'])})
                r_id = ''
                user_id = ''
                for o in order:
                    r_id = o['restaurant_id']
                    user_id = o['webuser_id']
                flag = request.form.get('flag', '')
                if user_id != '' and flag != '1':
                    item = tool.tuisong(mfrom=str(r_id),
                                        mto=str(user_id),
                                        title='您的餐位预订已修改',
                                        info='快去看看吧',
                                        goto='19',
                                        channel='商家拒单',
                                        type='1',
                                        totype='1',
                                        appname='foodmap_user',
                                        msgtype='notice',
                                        target='device',
                                        ext='{"goto":"19","id":"' +
                                        request.form['id'] + '"}',
                                        ispush=True)
                json = {"status": 1, "msg": ""}
                result = tool.return_json(0, "success", True, json)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            except Exception, e:
                print e
                result = tool.return_json(0, "field", False, None)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #19
0
def aboutus1():
    if auto.decodejwt(request.form['jwtstr']):
        json={
            "url":"/fm/merchant/v1/me/abouthtml/"
        }
        result=tool.return_json(0,"success",True,json)
        return json_util.dumps(result,ensure_ascii=False,indent=2)
    else:
        result=tool.return_json(0,"field",False,None)
        return json_util.dumps(result,ensure_ascii=False,indent=2)
Example #20
0
def updatealldis():
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):
            try:
                type = int(request.form['type'])
                if type == 1:
                    pdict = {
                        "dishes_discount.discount":
                        float(request.form["dishes_discount"]),
                        "dishes_discount.message":
                        request.form["dishes_message"],
                        "dishes_discount.start_time":
                        datetime.datetime.strptime(
                            request.form["dishes_start_time"], "%Y-%m-%d"),
                        "dishes_discount.end_time":
                        datetime.datetime.strptime(
                            request.form["dishes_end_time"], "%Y-%m-%d")
                    }
                else:
                    pdict = {
                        "wine_discount.discount":
                        float(request.form["wine_discount"]),
                        "wine_discount.message":
                        request.form["wine_message"],
                        "wine_discount.start_time":
                        datetime.datetime.strptime(
                            request.form["wine_start_time"], "%Y-%m-%d"),
                        "wine_discount.end_time":
                        datetime.datetime.strptime(
                            request.form["wine_end_time"], "%Y-%m-%d")
                    }
                mongo.restaurant.update_one(
                    {"_id": ObjectId(request.form["restaurant_id"])},
                    {"$set": pdict})
                # redish = {'201605111041429997':{'discount_price': 5555.00},'201605111040002332':{'discount_price':2222.00}}
                redish = request.form['redish']
                jsonredish = json.loads(redish)
                first = tool.Discount(request.form["restaurant_id"])
                first.re_dish(jsonredish)
                first.submit2db()
                jsons = {"status": 1, "msg": ""}
                result = tool.return_json(0, "success", True, jsons)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            except Exception, e:
                print e
                result = tool.return_json(0, "field", False, None)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #21
0
def accept(order_id):
    room_id = request.form["room_id"]
    deposit = request.form["deposit"]  # 订金:之后需要根据指定规则进行修改
    item = mongo.order.update_one(
        {"_id": ObjectId(order_id)},
        {"$set": {
            "room_id": room_id,
            "deposit": deposit,
            "status": 1
        }})
    json = {"order_id": item, "status": 1, "msg": ""}
    jwtmsg = auto.decodejwt(request.form["jwtstr"])
    result = tool.return_json(0, "success", jwtmsg, json)
    return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #22
0
def groupinvite_neworder():
    # 抢资格
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):
            # try:
            data = GroupInvite(request.form['group_id']).new_invite(request.form['user_id'])
            info = GroupInvite(request.form['group_id']).the_invite
            code = mongo.order_groupinvite.find({"master_id":request.form['user_id'],"group_id":request.form['group_id']})
            for c in code:
                data['code'] = c['invite_code']
            data['size'] = info['group_info']['size'] - 1
            print data
            print info
            # 消息3
            # mfrom-消息来源id|mto-发送给谁id数组,下划线分隔|title-消息标题|info-消息内容|goto("0")-跳转页位置|channel(订单)-调用位置|type-0系统发 1商家发 2用户发|totype-0发给商家 1发给用户
            # appname(foodmap_user,foodmap_shop)-调用的APP|msgtype(message,notice)-是消息还是通知|target(all,device)-全推或单推|ispush(True,False)-是否发送推送|
            webuser = mongo.webuser.find({"_id": ObjectId(request.form['user_id'])})
            nickname = ''
            phone = ''
            for w in webuser:
                nickname = w['nickname']
                phone = w['phone']
            content = '抢单人:' + nickname + ',抢单类型:' + str(
                info['group_info']['size']) + '人餐,抢单时间:' + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + \
                      ',联系电话:' + phone + ',剩余开团请客名额:' + str(info['group_info']['available'])
            tool.tuisong(mfrom=request.form['user_id'],
                         mto=info['restaurant']['rid'],
                         title='您发起的开团请客活动被抢了',
                         info=content,
                         goto='0',
                         channel='开团抢优惠',
                         type='0',
                         totype='0',
                         appname='foodmap_user',
                         msgtype='message',
                         target='device',
                         ext='',
                         ispush=False)
            result = tool.return_json(0, "success", True, data)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
            # except Exception, e:
            #     print e
            #     result = tool.return_json(0, "field", True, str(e))
            #     return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
    else:
        return abort(403)
Example #23
0
def updatestatus():
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):
            try:
                mongo.order.update_one(
                    {'_id': ObjectId(request.form['order_id'])},
                    {"$set": {
                        "status": int(request.form["status"])
                    }})
                #mfrom-消息来源id|mto-发送给谁id数组,下划线分隔|title-消息标题|info-消息内容|goto("0")-跳转页位置|channel(订单)-调用位置|type-0系统发 1商家发 2用户发|totype-0发给商家 1发给用户
                # appname(foodmap_user,foodmap_shop)-调用的APP|msgtype(message,notice)-是消息还是通知|target(all,device)-全推或单推|ispush(True,False)-是否发送推送|
                if request.form['status'] == '7':
                    rest = mongo.restaurant.find(
                        {"_id": ObjectId(request.form['restaurant_id'])})
                    phone = ''
                    r_name = ''
                    for r in rest:
                        phone = r['phone']
                        r_name = r['name']
                    order = mongo.order.find(
                        {"_id": ObjectId(request.form['order_id'])})
                    addtime = ''
                    for o in order:
                        addtime = o['addtime']
                    item = tool.tuisong(mfrom=request.form['restaurant_id'],
                                        mto=request.form['webuserids'],
                                        title='您的餐位预订已取消',
                                        info='您原定在' + addtime + r_name +
                                        '用餐,现在您预定的餐位已经取消,如有疑问请拨打商家电话:' + phone,
                                        goto='17',
                                        channel='商家退单',
                                        type='1',
                                        totype='1',
                                        appname='foodmap_user',
                                        msgtype='notice',
                                        target='device',
                                        ext='{"goto":"11","id":"' +
                                        request.form['order_id'] + '"}',
                                        ispush=True)
                json = {"status": 1, "msg": ""}
                result = tool.return_json(0, "success", True, json)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            except Exception, e:
                print e
                result = tool.return_json(0, "field", False, None)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #24
0
def groupinvite_order_used():
    # 获取订单详情
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):
            try:
                data = GroupInvite(request.form['code']).mark_used()
                result = tool.return_json(0, "success", True, data)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            except Exception, e:
                print e
                result = tool.return_json(0, "field", True, str(e))
                return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #25
0
def get_groupinvite_detail():
    # 获取请客详情
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):
            try:
                data = GroupInvite(request.form['group_id']).the_invite
                result = tool.return_json(0, "success", True, data)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            except Exception, e:
                print e
                result = tool.return_json(0, "field", True, str(e))
                return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #26
0
def groupinvite_add_friend():
    # 接受邀请
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):
            try:
                print request.form['code'], request.form['user_id']
                kaituan = GroupInvite(request.form['code'])
                info = kaituan.the_invite
                info2 = kaituan.invite_order
                if  request.form['user_id'] not in info2['friends']:
                    if request.form['user_id'] != info2['master_id']:
                        data = kaituan.follow(request.form['user_id'])
                        print data
                        if data['success']:
                        # 推送8
                        # mfrom-消息来源id|mto-发送给谁id数组,下划线分隔|title-消息标题|info-消息内容|goto("0")-跳转页位置|channel(订单)-调用位置|type-0系统发 1商家发 2用户发|totype-0发给商家 1发给用户
                        # appname(foodmap_user,foodmap_shop)-调用的APP|msgtype(message,notice)-是消息还是通知|target(all,device)-全推或单推|ispush(True,False)-是否发送推送|
                            content = '快去看看吧!'
                            tool.tuisong(mfrom='',
                                         mto='' if info2 == None else info2['master_id'],
                                         title='有人加入了您的' + info.get("restaurant",{}).get("name","") + '开团请客活动',
                                         info=content,
                                         goto='1',
                                         channel='应邀开团',
                                         type='0',
                                         totype='1',
                                         appname='foodmap_user',
                                         msgtype='notice',
                                         target='device',
                                         ext='{"goto":"8","id":"' + request.form['code'] + '"}',
                                         ispush=True)
                        else:
                            data = {"success":False,"error":"邀请码错误或已满"}
                    else:
                        data = {"success":False,"error":"您是此活动的发起人,快去邀请好友吧"}
                else:
                    data = {"success":False,"error":"已加入该活动,勿重复操作"}
                result = tool.return_json(0, "success", True, data)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            except Exception, e:
                print e
                data = {"success":False,"error":"邀请码错误或已满"}
                result = tool.return_json(0, "success", True, data)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #27
0
def orderbypreset():
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):

            try:
                data = public.getroomslist(
                    ObjectId(request.form['restaurant_id']),
                    request.form['preset_time'])
                result = tool.return_json(0, "success", True, data)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            except Exception, e:
                print e
                result = tool.return_json(0, "field", False, None)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #28
0
def groupinvite_order():
    # 获取订单详情
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):
            try:
                # 'wait_friends', 'wait_pay', 'already_payment', 'already_used', 'time_out'
                data = GroupInvite(request.form['code']).invite_order
                kaituan = GroupInvite(data['group_id']).the_invite
                data['price'] = kaituan['price']['now']
                data['msg'] = ''
                # print type(data)
                # print time.strptime(data['addtime'], "%Y-%m-%d %H:%M:%S")
                # song
                if data['status'] == 'wait_friends':
                    data['msg'] = "还有" + str(45 - int((datetime.datetime.now() - datetime.datetime.strptime(
                        data['start_time'], "%Y-%m-%d %H:%M:%S")).total_seconds() / 60)) + "分钟,还需要" + str(
                        data['max_group'] - 1 - len(data['friends'])) + "位客人"
                elif data['status'] == 'wait_pay':
                    data['msg'] = "还有" + str(45 - int((datetime.datetime.now() - datetime.datetime.strptime(
                        data['start_time'], "%Y-%m-%d %H:%M:%S")).total_seconds() / 60)) + "分钟付款时间"
                elif data['status'] == 'timeout':
                    if data['max_group'] - 1 - len(data['friends']) == 0:
                        data['msg'] = "付款超时"
                    else:
                        data['msg'] = "45分钟内未邀请到" + str(data['max_group']) + "位好友"
                uid_list = [data['master_id']]
                for user in data['friends']:
                    uid_list.append(ObjectId(user))
                item = mongo_conn().webuser.find({"_id":{"$in":uid_list}})
                headimage_list = []
                for i in item:
                    json ={}
                    json['id'] = str(i['_id'])
                    json['nickname'] = i['nickname']
                    json['headimage'] = i['headimage']
                    headimage_list.append(json)
                data['img_list'] = headimage_list
                result = tool.return_json(0, "success", True, data)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            except Exception, e:
                print e
                result = tool.return_json(0, "field", True, str(e))
                return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #29
0
def special_type():
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):
            try:
                data = {}
                f_list = []
                item = mongo.assortment.find(
                    {"parent": {
                        "$in": [1, 35, 59, 50, 46]
                    }})
                for i in item:
                    f_json = {}
                    if i['parent'] == 1:
                        f_json['id'] = str(i['_id'])
                        f_json['name'] = i['name']
                        f_list.append(f_json)
                    else:
                        pass
                data['fenlei'] = f_list
                data['youhui'] = [{
                    'id': 'dish',
                    'name': '菜品优惠'
                }, {
                    'id': 'wine',
                    'name': '酒水优惠'
                }, {
                    'id': 'other',
                    'name': '其他优惠'
                }]
                list = []
                for d in district_list():
                    json = {}
                    json['district_id'] = d['id']
                    json['district_name'] = d['district_name']
                    json['district_list'] = business_dist_byid(d['id'])
                    list.append(json)
                data['business_list'] = list
                result = tool.return_json(0, "success", True, data)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            except Exception, e:
                print e
                result = tool.return_json(0, "field", True, str(e))
                return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)
Example #30
0
def special_restaurant_info():
    if request.method == 'POST':
        if auto.decodejwt(request.form['jwtstr']):

            try:
                pass
                item = mongo.shop_recommend.find({
                    "type":
                    2,
                    "restaurant_id":
                    ObjectId(request.form['restaurant_id'])
                }).sort("addtime", pymongo.DESCENDING)[0:1]
                data = {}
                if request.form['webuser_id'] != '-1':
                    data['concern'] = getconcern(request.form['restaurant_id'],
                                                 request.form['webuser_id'])
                else:
                    data['concern'] = '0'
                for i in item:
                    data['restaurant_id'] = request.form['restaurant_id']
                    data['headimage'] = i['headimage']
                    data['restaurant_name'] = i['restaurant_name']
                    data['district'] = getxingzhengqu(
                        i['business_dist'][0]['id'])
                    data['restaurant_sq'] = i['restaurant_sq']
                    data['summary'] = i['summary']
                    dishes_type = ''
                    # data['url'] = 'https://www.msdt.cn/fm/user/v1/coupons/special_restaurant_html/'+request.form['restaurant_id']+'/'
                    # data['url'] = 'http://125.211.222.237:11087/fm/user/v1/coupons/special_restaurant_html/'+request.form['restaurant_id']+'/'
                    data[
                        'url'] = 'https://www.msdt.cn/m/tsmsxxiOS/' + request.form[
                            'restaurant_id']

                    for dish in i['dishes_type']:
                        dishes_type += dish['name'] + ' '
                    data['dishes_type'] = dishes_type
                result = tool.return_json(0, "success", True, data)
                return json_util.dumps(result, ensure_ascii=False, indent=2)
            except Exception, e:
                print e
                result = tool.return_json(0, "field", True, str(e))
                return json_util.dumps(result, ensure_ascii=False, indent=2)
        else:
            result = tool.return_json(0, "field", False, None)
            return json_util.dumps(result, ensure_ascii=False, indent=2)