コード例 #1
0
ファイル: main.py プロジェクト: zhuangzp/angle-street
def ordercmd():
    if not is_admin(): return E("没有权限")
    id = flask.request.json['id']
    cmd = flask.request.json['cmd']
    o = Order.objects.with_id(id)
    if cmd == 'print':
        import route_print
        route_print.printOrder(o.id)
        return A("已经加入打印队列")
    if cmd == 'noticeuser':
        weimsg = route_weixin.renderOrder(o)
        r, err = weixin.send_weixin(o.openid, weimsg)
        if r:
            return A("微信通知发送成功")
        elif err == 45015:
            o.detail.append(tool.now() + " " + "微信通知发送不成功")
            return A("由于用户没有关注我们的微信号或者长时间没有操作,微信通知发送不成功.")
        else:
            log.error("服务器错误,请联系管理员" + o.to_json() + str(r))
            return E("微信通知发送不成功,错误编号:" + str(err))
    if cmd == 'noticeshop':
        ok, msg = sendToShop(id)
        if ok: return A(msg)
        else: return E(msg)
    if cmd == 'smsnoticeshop':
        tel = o.info.tel
        ok, msg = weixin.send_sms(tel, "你的店铺有新的订单,请登录微信查看。")
        if ok: return A(msg)
        else: return E(msg)
    if cmd == "cancel":
        o.state = "fail"
        o.save()
        return A("取消订单成功")
    return E("no such cmd")
コード例 #2
0
ファイル: main.py プロジェクト: marslabtron/angle-street
def ordercmd():
    if not is_admin():return E("没有权限") 
    id = flask.request.json['id']
    cmd = flask.request.json['cmd']
    o = Order.objects.with_id(id)
    if cmd=='print':
        import route_print
        route_print.printOrder(o.id)
        return A("已经加入打印队列")
    if cmd=='noticeuser':
        weimsg = route_weixin.renderOrder(o)
        r,err = weixin.send_weixin(o.openid, weimsg)
        if r:
            return A("微信通知发送成功")
        elif err==45015:
            o.detail.append(tool.now()+" "+"微信通知发送不成功")
            return A("由于用户没有关注我们的微信号或者长时间没有操作,微信通知发送不成功.")
        else:
            log.error("服务器错误,请联系管理员"+o.to_json()+str(r))
            return E("微信通知发送不成功,错误编号:"+str(err)) 
    if cmd=='noticeshop':
        ok,msg = sendToShop(id)
        if ok: return A(msg)
        else :return E(msg)
    if cmd=='smsnoticeshop':
        tel = o.info.tel
        ok,msg = weixin.send_sms(tel,"你的店铺有新的订单,请登录微信查看。")
        if ok :return  A(msg)
        else: return E(msg)
    if cmd=="cancel":
        o.state="fail"
        o.save()
        return A("取消订单成功")
    return E("no such cmd")
コード例 #3
0
 def to(content, openid, params):
     if content == '0':
         for i in WeixinQueue.objects(result='pending', openid=openid):
             success, errorcode = weixin.send_weixin(i.openid, i.text, save=False)
             if success:
                 i.result = "success"
                 i.save()
         return "查询成功"
     elif content == "id":
         return openid
     elif content == 'params':
         return str(params)
     elif content == 'info':
         return getinfo(openid)
     elif content == u'所有订单':
         orderall(openid)
         return "查询成功"
     elif re.match(r'^o\s*\d+$', content):
         # confirm order
         id = re.search(r'\d+', content).group()
         return confirmOrder(id, openid)
     elif re.match(r'^p\s*\d+$', content):
         # confirm order
         id = re.search(r'\d+', content).group()
         return completionOrder(id, openid)
     elif content == 'kf':
         weixinhandler.MsgType = 'transfer_customer_service'
         weixinhandler.text('kf')
         return weixinhandler.handle_response()
     else:
         # default reply
         weixinhandler.MsgType = 'transfer_customer_service'
         weixinhandler.text('kf')
         return weixinhandler.handle_response()
コード例 #4
0
ファイル: main.py プロジェクト: marslabtron/angle-street
def sendToShop(id):
    o = Order.objects.with_id(id)
    if not o:
        log("send to shop not find id")
        return False,""
    shop = Shop.objects.with_id(o.shopId)
    openid = shop.info.weixin
    tel = shop.info.tel
    ok,msg = weixin.send_weixin(openid,renderToShopOrder(o))
    if ok==False:
        if msg==45015:
            ok,msg = weixin.send_sms(tel,"你的店铺有新的订单,请登录微信查看。")
            if ok : return True,"微信发送失败,用短信通知成功"
            else :return False,"微信发送失败,短信发送失败,错误编号"+str(msg)
        else :
            return False,"微信发送失败"+str(msg)
    return True,"微信发送成功"
コード例 #5
0
ファイル: main.py プロジェクト: zhuangzp/angle-street
def sendToShop(id):
    o = Order.objects.with_id(id)
    if not o:
        log("send to shop not find id")
        return False, ""
    shop = Shop.objects.with_id(o.shopId)
    openid = shop.info.weixin
    tel = shop.info.tel
    ok, msg = weixin.send_weixin(openid, renderToShopOrder(o))
    if ok == False:
        if msg == 45015:
            ok, msg = weixin.send_sms(tel, "你的店铺有新的订单,请登录微信查看。")
            if ok: return True, "微信发送失败,用短信通知成功"
            else: return False, "微信发送失败,短信发送失败,错误编号" + str(msg)
        else:
            return False, "微信发送失败" + str(msg)
    return True, "微信发送成功"
コード例 #6
0
ファイル: route_weixin.py プロジェクト: zhuangzp/angle-street
 def to(content, openid, params):
     if content == '0':
         for i in WeixinQueue.objects(result='pending', openid=openid):
             success, errorcode = weixin.send_weixin(i.openid,
                                                     i.text,
                                                     save=False)
             if success:
                 i.result = "success"
                 i.save()
         return "查询成功"
     elif content == "id":
         return openid
     elif content == 'params':
         return str(params)
     elif content == 'info':
         return getinfo(openid)
     elif content == u'所有订单':
         orderall(openid)
         return "查询成功"
     elif re.match(r'^o\s*\d+$', content):
         # confirm order
         id = re.search(r'\d+', content).group()
         return confirmOrder(id, openid)
     elif re.match(r'^p\s*\d+$', content):
         # confirm order
         id = re.search(r'\d+', content).group()
         return completionOrder(id, openid)
     elif content == 'kf':
         weixinhandler.MsgType = 'transfer_customer_service'
         weixinhandler.text('kf')
         return weixinhandler.handle_response()
     else:
         # default reply
         weixinhandler.MsgType = 'transfer_customer_service'
         weixinhandler.text('kf')
         return weixinhandler.handle_response()
コード例 #7
0
ファイル: main.py プロジェクト: marslabtron/angle-street
def submitorder():

    if not flask.session.has_key('openid'):
        return E("找不到你的微信用户信息,请点击右上角关注我们的服务号“爱上天使街”")
    # flask.session['openid']='oqxGSuCUGMmLWehQxCbg9O-XqPzk'
    # flask.session['weixinname']='weixinname'
    c = flask.request.json
    o = Order()
    o.allcount = c['allcount']
    o.allprice = c['allprice']
    o.addr = c['addr']
    o.msg = c['msg']
    o.name = c['name']
    o.shopId = c['shopId']
    o.tel = c['tel']
    o.openid = flask.session['openid']
    o.weixinname = flask.session['weixinname']
    w = Shop.objects.with_id(c['shopId'])
    # 限制下单间隔时间
    oo = Order.objects(openid=o.openid).order_by("-_id").first()
    if oo:
        if (datetime.datetime.now() - oo.time).total_seconds() < 10:
            return E("下单太频繁,请稍后再试")
    for i in w.goods:
        if str(i.id) in c['goods']:
            b = Buy()
            b.category = i.category
            b.name = i.name
            b.price = i.price
            b.point = i.point 
            b.id = i.id
            b.count = int(c['goods'][str(i.id)])
            o.goods.append(b)

    o.info = w.info
    o.state = "verify"

    allcount = 0
    allprice = 0
    for i in o.goods:
        allcount += i.count
        allprice += i.price * i.count
    if allcount!=o.allcount or allprice!=o.allprice:
        return E("订单验证错误,可能在选购商品的时候店家修改了商品信息,建议重新从微信菜单进入购买")
    if allprice <=0:
        return E("订单金额太少")
    import json
    import random
    o.pid = len(Order.objects)*10+random.randrange(10)
    try:
        o.validate()
    except ValidationError as e:
        log.error(str(e))
        return E("你填写的信息不合法")
    o.detail.append(tool.now() + "成功下单,系统正在处理中")
    o.save()
    w.info.salesVolume += 1
    w.save()
    route_print.printOrder(o.id)
    weimsg = route_weixin.renderOrder(o)
    r,err = weixin.send_weixin(o.openid, weimsg)
    if r:
        o.state = 'pending'
        thread.start_new_thread(sendToShop, (o.id,) )
        o.save()
        return A("你的订单已经成功提交,订单详情已经发送的你的微信上,请查收")
    elif err==45015:
        o.state = "waiting"
        o.detail.append(tool.now()+" "+"微信通知发送不成功")
        o.save()
        return A("你的订单已经成功提交,由于你没有关注我们的微信号或者长时间没有操作,请关注我们的微信号并点击任意菜单。")
    else:
        log.error("服务器错误,请联系管理员"+o.to_json()+"\nweixinre:"+str(err))
        return E("服务器错误,请联系管理员") 
コード例 #8
0
ファイル: route_weixin.py プロジェクト: zhuangzp/angle-street
def orderall(openid):
    w = Order.objects(openid=openid).order_by("-_id")[0:5]
    for i in w:
        weixin.send_weixin(openid, renderOrder(i))
コード例 #9
0
ファイル: main.py プロジェクト: zhuangzp/angle-street
def submitorder():

    if not flask.session.has_key('openid'):
        return E("找不到你的微信用户信息,请点击右上角关注我们的服务号“爱上天使街”")
    # flask.session['openid']='oqxGSuCUGMmLWehQxCbg9O-XqPzk'
    # flask.session['weixinname']='weixinname'
    c = flask.request.json
    o = Order()
    o.allcount = c['allcount']
    o.allprice = c['allprice']
    o.addr = c['addr']
    o.msg = c['msg']
    o.name = c['name']
    o.shopId = c['shopId']
    o.tel = c['tel']
    o.openid = flask.session['openid']
    o.weixinname = flask.session['weixinname']
    w = Shop.objects.with_id(c['shopId'])
    # 限制下单间隔时间
    oo = Order.objects(openid=o.openid).order_by("-_id").first()
    if oo:
        if (datetime.datetime.now() - oo.time).total_seconds() < 10:
            return E("下单太频繁,请稍后再试")
    for i in w.goods:
        if str(i.id) in c['goods']:
            b = Buy()
            b.category = i.category
            b.name = i.name
            b.price = i.price
            b.point = i.point
            b.id = i.id
            b.count = int(c['goods'][str(i.id)])
            o.goods.append(b)

    o.info = w.info
    o.state = "verify"

    allcount = 0
    allprice = 0
    for i in o.goods:
        allcount += i.count
        allprice += i.price * i.count
    if allcount != o.allcount or allprice != o.allprice:
        return E("订单验证错误,可能在选购商品的时候店家修改了商品信息,建议重新从微信菜单进入购买")
    if allprice <= 0:
        return E("订单金额太少")
    import json
    import random
    o.pid = len(Order.objects) * 10 + random.randrange(10)
    try:
        o.validate()
    except ValidationError as e:
        log.error(str(e))
        return E("你填写的信息不合法")
    o.detail.append(tool.now() + "成功下单,系统正在处理中")
    o.save()
    w.info.salesVolume += 1
    w.save()
    route_print.printOrder(o.id)
    weimsg = route_weixin.renderOrder(o)
    r, err = weixin.send_weixin(o.openid, weimsg)
    if r:
        o.state = 'pending'
        thread.start_new_thread(sendToShop, (o.id, ))
        o.save()
        return A("你的订单已经成功提交,订单详情已经发送的你的微信上,请查收")
    elif err == 45015:
        o.state = "waiting"
        o.detail.append(tool.now() + " " + "微信通知发送不成功")
        o.save()
        return A("你的订单已经成功提交,由于你没有关注我们的微信号或者长时间没有操作,请关注我们的微信号并点击任意菜单。")
    else:
        log.error("服务器错误,请联系管理员" + o.to_json() + "\nweixinre:" + str(err))
        return E("服务器错误,请联系管理员")
コード例 #10
0
def orderall(openid):
    w = Order.objects(openid=openid).order_by("-_id")[0:5]
    for i in w:
        weixin.send_weixin(openid, renderOrder(i))