예제 #1
0
    def GET(self):
        i = web.input()
        oid = i.get('oid')
        order = model.get_order(oid)
        orderdate = list(order)[0].OrderDate
        details = model.get_details(oid)
        for detail in details:
            model.upd_meal_sold(detail.lunchid,orderdate,-detail.num)
            
        model.update_order(oid, 2, time.strftime('%Y-%m-%d %X', time.localtime()))                
        #print oid
        #refund = Refund_pub()
        #refund.setParameter('transaction_id')
        #refund.setParameter('out_trade_no',str(session.out_trade_no))
        #refund.setParameter('out_trade_no','1234567890')
        #refund.setParameter('total_fee','1')
        #refund.setParameter('refund_fee','1')
        #refund.setParameter('out_refund_no','1234567890')
        #refund.setParameter('op_user_id','1240046802')

        #res = refund.getResult()
        #print res["return_code"]
        #print res["return_msg"]
        return web.seeother('/orders')
예제 #2
0
    def GET(self):
        shopping_basket = web.ctx.session.shoppingbasket
        shopping_list = web.ctx.session.shoppinglist
        user_info = web.ctx.session.userinfo
        shopping_cost = web.ctx.session.shoppingcost
        seed_no = int(time.time())
        invoice = user_info["Invoice"]

        i = web.input()
        param = i.get("param")
        # print param
        order_info = {}
        order_list = param.split("|")
        for order in order_list:
            if order:
                id,tm = order.split("_")
                order_info[str(id)] = tm
        # print order_info.keys()

        id = 0
        for _date in shopping_basket:
            id = id + 1
            _id = str(id) 
            if order_info.has_key(_id):
                rand_suffix = random.randint(100,1000)
                orderid = seed_no * 1000 + rand_suffix
                shopping_list.append(str(orderid))
                allcnt = 0
                for item in shopping_basket[_date]:
                    allcnt += int(shopping_basket[_date][item]["Count"])
                #if failed in next steps, the order should be deleted!!!
                model.new_order(orderid,user_info["Tel"], user_info["Contact"], user_info["OfficeId"], _date, \
                            float(shopping_cost[_date]["price"]), float(shopping_cost[_date]["price0"]),float(shopping_cost[_date]["price1"]),\
                            float(shopping_cost[_date]["price2"]), allcnt , time.strftime('%Y-%m-%d %X', time.localtime()),\
                            time.strftime('%Y-%m-%d %X', time.localtime()),user_info["ID"],\
                            invoice, user_info["UnitAddr"], order_info[_id])
                lidict = {}
                for _lunchid in shopping_basket[_date]:
                    cnt = shopping_basket[_date][_lunchid]["Count"]
                    meal_it = model.get_meal_detail(_lunchid, _date)
                    meal_dtl = list(meal_it)

                    if int(meal_dtl[0].stock) >= int(cnt):
                            #新增订单详情
                        model.new_detail(orderid, _lunchid, cnt)
                            #库存修改
                        ret = model.upd_meal_sold(_lunchid,_date,cnt)
                            #print 'upd_meal_sold return:'+str(ret)
                        if ret == -1:
                            web.ctx.session.failreason = "stock"
                            model.del_order(orderid)
                            model.del_detail(orderid)
                            for (k,v) in lidict.items():
                                model.upd_meal_sold(k,_date,-int(v))
                            return web.seeother('/orderfail')
                        elif ret == 0:
                                #暂存已更新的库存信息
                            lidict[_lunchid] = cnt
                    else:
                        web.ctx.session.failreason="stock"
                        model.del_order(orderid)
                        model.del_detail(orderid)
                        for (k,v) in lidict.items():
                            model.upd_meal_sold(k,_date,-int(v))
                        return web.seeother('/orderfail')
        #print shopping_list
        oids = "_".join(shopping_list)

        # clear shopping_basket and shopping cost
        if web.ctx.session.shoppingbasket:
            web.ctx.session.shoppingbasket.clear()
        if web.ctx.session.shoppingcost:
            web.ctx.session.shoppingcost.clear()

        logging.info("[pay][uid:%s]", str(web.ctx.session.openid))
        return web.seeother('/webchatpay?oids=' + oids)