Beispiel #1
0
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")
Beispiel #2
0
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")
Beispiel #3
0
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,"微信发送成功"
Beispiel #4
0
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, "微信发送成功"