Exemple #1
0
def run(cardid,mid,people_count,hardwareid,recommend_uid=None):
    with dbconfig.Session() as session:
        sm=session.query(StoreMerchandise).filter(StoreMerchandise.mid==mid).first()
        if sm is None:
            return Res(errno=2,error="not exist")
        usr=session.query(User).filter(User.uid==BackEndEnvData.uid).first()
        if usr is None:
            return Res(errno=2,error="this bug can not happen")
        price=get_price(sm,people_count=people_count)

        transtime=int(time.time())
        od=u"%d-%d"%(transtime,random.randint(100, 999))
        paystate=StorePayState()
        paystate.orderid=od
        paystate.paystate=0
        paystate.mid=mid
        paystate.uid=BackEndEnvData.uid
        paystate.remain=price
        paystate.ex_people=people_count
        if recommend_uid is not None:
            paystate.recommend_uid=recommend_uid
        session.merge(paystate)
        session.commit()
        mer=MerchantAPI()
        res=mer.BindPaysignAsync(cardid,od,transtime,156,price,str(sm.productcatalog),
                                 sm.productname,sm.productdesc,BackEndEnvData.client_ip,
                                 usr.phone,4,"IMEI:"+hardwareid,"http://%s/payresult/Paybackend"%website_config.hostname,
                                 "http://%s/payresult/Paybackend"%website_config.hostname)
        if res.get('error_code',None) is None:
            if res['accept']==1:
                return Res({'orderid':od})
            else:
                return Res(errno=3,error="pay not accept")
        else:
            return Res({'src_error':res},errno=3,error="pay fail")
def run(mid,people_count,hardwareid,recommend_uid=None):
    with dbconfig.Session() as session:
        sm=session.query(StoreMerchandise).filter(StoreMerchandise.mid==mid).first()
        if sm is None:
            return Res(errno=2,error="not exist")
        usr=session.query(User).filter(User.uid==BackEndEnvData.uid).first()
        if usr is None:
            return Res(errno=2,error="this bug can not happen")

        price=get_price(sm,people_count=people_count)

        transtime=int(time.time())
        od=u"%d-%d"%(transtime,random.randint(100, 999))
        paystate=StorePayState()
        paystate.orderid=od
        paystate.paystate=0
        paystate.mid=mid
        paystate.uid=BackEndEnvData.uid
        paystate.ex_people=people_count
        paystate.remain=price
        if recommend_uid is not None:
            paystate.recommend_uid=recommend_uid
        session.merge(paystate)
        session.commit()

        msg_content=u"%s(%s) 正在预订 %s (%s)"%(usr.phone,usr.nick,sm.productdesc,
                                                              time.strftime("%m-%d %H:%M",time.localtime()))
        to_sendsms=session.query(StoreSmsNotify).filter(or_(StoreSmsNotify.mid==0,StoreSmsNotify.mid==None,StoreSmsNotify.mid==mid)).all()
        for ssn in to_sendsms:
            BackEndEnvData.queue_producer.publish(DefJsonEncoder.encode({'content':msg_content,'phone':ssn.phone}),routing_key='sms.ad',exchange='sys.sms')

        to_notifys=session.query(StoreWeixinNotify).filter(or_(StoreWeixinNotify.mid==0,StoreWeixinNotify.mid==None,StoreWeixinNotify.mid==mid)).all()
        to_weixin_user=set()
        for noti_one in to_notifys:
            to_weixin_user.add(noti_one.openid)
        if to_weixin_user:
            json_msg=DefJsonEncoder.encode({
                'weixin_users':list(to_weixin_user),
                'content':msg_content
                })
            BackEndEnvData.queue_producer.publish(body=json_msg,delivery_mode=2,
                                            routing_key='sys.sendweixin',
                                            compression='gzip')

        gourl=None
        if price>0:
            mer=MerchantAPI()
            gourl=mer.wap_credit(od,transtime,156,price,str(sm.productcatalog),
                                     "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)",
                                     sm.productname,sm.productdesc,BackEndEnvData.client_ip,
                                     usr.phone,4,"IMEI:"+hardwareid,"http://%s/payresult/Paybackend"%website_config.hostname,
                                     "http://%s/payresult/Paybackend"%website_config.hostname,"1|2")
        return Res({'gourl':gourl,'orderid':od})
Exemple #3
0
def run(mid):
    with dbconfig.Session() as session:
        transtime = int(time.time())
        od = u"%d-%d" % (transtime, random.randint(100, 999))
        paystate = StorePayState()
        paystate.orderid = od
        paystate.paystate = 3
        paystate.mid = mid
        paystate.uid = BackEndEnvData.uid
        paystate.remain = 0
        session.merge(paystate)
        session.commit()

        # sm=session.query(StoreMerchandise).filter(StoreMerchandise.mid==mid).first()

        return Res({"orderid": od, "msg": u"您已经成功参与“装来信 送酒店”活动,很荣幸您获得茗汉铂尔曼酒店高级房一晚使用权。消费完毕后会有专车在门口迎接您,祝您消费愉快。"})