Пример #1
0
def orderCreate():
    resp = {'code': 200, 'msg': '操作成功', 'data': {}}
    req = request.values
    type = req['type'] if 'type' in req else ''
    note = req['note'] if 'note' in req else ''
    express_address_id = int(
        req['express_address_id']
    ) if 'express_address_id' in req and req['express_address_id'] else 0
    params_goods = req['goods'] if 'goods' in req else None

    items = []
    if params_goods:
        items = json.loads(params_goods)

    if len(items) < 1:
        resp['code'] = -1
        resp['msg'] = "下单失败:没有选择商品"
        return jsonify(resp)

    address_info = MemberAddress.query.filter_by(id=express_address_id).first()
    app.logger.error("aaaaaaaaaaaaaa")
    app.logger.error(address_info.mobile)
    app.logger.error(address_info.mobile)
    app.logger.error("aaaaaaaaaaaaaa")
    if not address_info or not address_info.status:
        resp['code'] = -1
        resp['msg'] = "下单失败:快递地址不对"
        return jsonify(resp)

    member_info = g.member_info
    target = PayService()
    params = {
        "note": note,
        'express_address_id': address_info.id,
        'express_info': {
            'mobile':
            address_info.mobile,
            'nickname':
            address_info.nickname,
            "address":
            "%s%s%s%s" % (address_info.province_str, address_info.city_str,
                          address_info.area_str, address_info.address)
        }
    }
    # params = {
    # 	"note": note,
    # 	'express_address_id': "1",
    # 	'express_info': {
    # 		'mobile': "address_info.mobile",
    # 		'nickname': "address_info.nickname",
    # 		"address": "%s%s%s%s" % (
    # 		"address_info.province_str", "address_info.city_str", "address_info.area_str", "address_info.address")
    # 	}
    # }
    resp = target.createOrder(member_info.id, items, params)
    #如果是来源购物车的,下单成功将下单的商品去掉
    if resp['code'] == 200 and type == "cart":
        CartService.deleteItem(member_info.id, items)

    return jsonify(resp)
Пример #2
0
def orderCreate():
    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    req = request.values
    type = req['type'] if 'type' in req else ''
    params_goods = req['goods'] if 'goods' in req else None

    if params_goods:
        items = json.loads(params_goods)

    if len(items) < 1:
        resp['code'] = -1
        resp['msg'] = "下单失败:没有选择商品"
        return jsonify(resp)

    # 下单先在主表添加一个数据,再在副表添加数据

    member_info = g.member_info
    params = {}
    target = PayService()
    resp = target.createOrder(member_info.id, items, params)

    if resp['code'] == 200 and type == "cart":
        CartService.deleteItem(member_info.id, items)

    return jsonify(resp)
Пример #3
0
def orderCreate():
    member_info  = g.member_info
    resp = {'code': 200, 'msg': '操作成功', 'data': {}}
    req = request.values

    type = req['type'] if 'type' in req else ''
    params_goods = req['goods'] if 'goods' in req else None

    items = []
    if params_goods:
        items = json.loads(params_goods)
        
    if len(items)<1:
        resp['code'] = -1
        resp['msg'] = '下单失败:没有选择商品'
        return jsonify(resp)

    # 创建一个对象
    target = PayService()
    # params里面可以填充前台获得的数据,用于存粗到数据可
    params = {}
    resp = target.createOrder(member_info.id,items,params)

    # 最后删除对应购物车的数据
    if resp['code'] == 200 and type == 'cart':
        # 删除购物车中的对象
        CartService.deleteItem(member_info.id,items)
    return jsonify(resp)
Пример #4
0
def orderCreate():
    resp = {"code": 200, "msg": "添加成功", "data": {}}
    req = request.values

    type = req['type'] if 'type' in req else ''
    params_goods = req['goods'] if 'goods' in req else None

    items = []
    if params_goods:
        items = json.loads(params_goods)

    if len(items) < 1:
        resp['code'] = -1
        resp['msg'] = '下单失败, 请选择商品'
        return jsonify(resp)

    member_info = g.member_info
    target = PayService()
    params = {}
    resp = target.createOrder(member_info.id, items, params)

    if resp['code'] == 200 and type == 'cart':
        CartService.deleteItems(member_info.id, items)

    return jsonify(resp)
Пример #5
0
def orderCreate():

    resp = {'code': 200, 'msg': "下单成功", 'data': {}}
    req = request.values

    Cid = int(req['Cid']) if 'Cid' in req and req['Cid'] else 0
    Shopid = int(req['Shopid']) if 'Shopid' in req and req['Shopid'] else 0
    trolley_result = req['trolley_list'] if 'trolley_list' in req else ''
    OrderAddress = req['OrderAddress'] if 'OrderAddress' in req else ''
    params_goods = req['params_goods'] if 'params_goods' in req else None

    items = []
    if params_goods:
        items = json.loads(params_goods)

    if len(items) < 1:
        resp['code'] = -1
        resp['msg'] = "下单失败: 没有选择商品"
        return jsonify(resp)

    address_info = Address.query.filter_by(Id=OrderAddress).first()
    if not address_info:
        resp['code'] = -1
        resp['msg'] = "下单失败:快递地址不对~~"
        return jsonify(resp)

    target = PayService()

    params = {
        # 地址id
        'express_address_id': address_info.Id,
        # 地址信息
        'express_info': {
            'mobile':
            address_info.AddresseePhone,
            'nickname':
            address_info.Addressee,
            "address":
            "%s%s%s%s" % (address_info.Province, address_info.City,
                          address_info.County, address_info.Details)
        }
    }
    resp = target.createOrder(Cid, Shopid, items, params=params)

    if resp['code'] == 200:
        if trolley_result != '':
            trolley_list = trolley_result.strip(',').split(',')
            if trolley_list:
                for item in trolley_list:
                    result = ShoppingTrolley.query.filter_by(
                        Id=int(item)).first()
                    db.session.delete(result)
                    db.session.commit()
    return jsonify(resp)
Пример #6
0
def orderCreate():
    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    req = request.values
    print(req)
    type = req['type'] if 'type' in req else ''
    #	note = req['note'] if 'note' in req else ''
    #	express_address_id = int( req['express_address_id'] ) if 'express_address_id' in req and req['express_address_id'] else 0
    params_goods = req['goods'] if 'goods' in req else None
    print(params_goods)
    items = []
    if params_goods:
        items = json.loads(params_goods)
    # print("*****####")

    if len(items) < 1:
        resp['code'] = -1
        resp['msg'] = "失败:没有选择讲座~~"
        return jsonify(resp)

    now_time = getFormatDate()
    e_time = time.mktime(time.strptime(now_time, "%Y-%m-%d %H:%M:%S"))
    for item in items:
        item_time = time.strptime(item['lecture_time'], "%Y-%m-%d %H:%M:%S")
        l_time = time.mktime(item_time)
        if int(e_time) < int(l_time):
            resp['code'] = -1
            resp['msg'] = "请选择已经结束的讲座"
            return jsonify(resp)


#	address_info = MemberAddress.query.filter_by( id = express_address_id ).first()
#	if not address_info or not address_info.status:
#		resp['code'] = -1
#		resp['msg'] = "下单失败:快递地址不对~~"
#		return jsonify(resp)

    member_info = g.member_info
    target = PayService()
    #	params = {
    ##		"note":note,
    ##		'express_address_id':address_info.id,
    ##		'express_info':{
    ##			'mobile':address_info.mobile,
    ##			'nickname':address_info.nickname,
    ##			"address":"%s%s%s%s"%( address_info.province_str,address_info.city_str,address_info.area_str,address_info.address )
    ##		}
    #	}
    resp = target.createOrder(member_info.id, items, None)

    #如果是来源购物车的,下单成功将下单的商品去掉
    if resp['code'] == 200 and type == "cart":
        CartService.deleteItem(member_info.id, items)

    return jsonify(resp)
Пример #7
0
def orderCreate():
    resp = {'code': 200, 'msg': '操作成功', 'data': {}}
    req = request.values

    type = req['type'] if 'type' in req else ''
    params_goods = req['goods'] if 'goods' in req else None
    note = req['note'] if 'note' in req else ''
    express_address_id = int(
        req['express_address_id']
    ) if 'express_address_id' in req and req['express_address_id'] else 0

    items = []
    if params_goods:
        items = json.loads(params_goods)

    if len(items) < 1:
        resp['code'] = -1
        resp['msg'] = "下单失败:没有选择商品~"
        return jsonify(resp)

    address_info = MemberAddress.query.filter_by(id=express_address_id).first()
    if not address_info or not address_info.status:
        resp['code'] = -1
        resp['msg'] = "下单失败:快递地址不对~~"
        return jsonify(resp)

    member_info = g.member_info
    params = {
        "note": note,
        'express_address_id': address_info.id,
        'express_info': {
            'mobile':
            address_info.mobile,
            'nickname':
            address_info.nickname,
            "address":
            "%s%s%s%s" % (address_info.province_str, address_info.city_str,
                          address_info.area_str, address_info.address)
        }
    }
    target = PayService()
    resp = target.createOrder(member_info.id, items, params)

    if resp['code'] == 200 and type == "cart":
        CartServer.deleteItem(member_info.id, items)

    return jsonify(resp)
Пример #8
0
def orderCreate():
    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    req = request.values
    type = req['type'] if 'type' in req else ''
    note = req['note'] if 'note' in req else ''
    express_address_id = int(
        req['express_address_id']
    ) if 'express_address_id' in req and req['express_address_id'] else 0
    params_goods = req['goods'] if 'goods' in req else None  # 商品详情,默认过来是 json

    items = []  # 转换成list,方便进行后端提交
    if params_goods:
        items = json.loads(params_goods)

    if len(items) < 1:
        resp['code'] = -1
        resp['msg'] = "下单失败:没有选择商品~~"
        return jsonify(resp)

    # address_info = MemberAddress.query.filter_by(id=express_address_id).first()
    # if not address_info or not address_info.status:
    #     resp['code'] = -1
    #     resp['msg'] = "下单失败:快递地址不对~~"
    #     return jsonify(resp)
    #
    member_info = g.member_info
    target = PayService()
    params = {
        # "note": note,
        # 'express_address_id': address_info.id,
        # 'express_info': {
        #     'mobile': address_info.mobile,
        #     'nickname': address_info.nickname,
        #     "address": "%s%s%s%s" % (
        #     address_info.province_str, address_info.city_str, address_info.area_str, address_info.address)
        # }
    }
    resp = target.createOrder(member_info.id, items, params)
    # 如果是来源购物车的,下单成功将下单的商品去掉
    if resp['code'] == 200 and type == "cart":  # 如果操作成功,并且市场 购物车下的单
        CartService.deleteItem(member_info.id, items)  # 那么购物车,就删除这个商品(购物车商品id)

    return jsonify(resp)
Пример #9
0
def orderCreate():
    resp = {'code': 200, 'msg': '操作成功', 'data': {}}
    req = request.values
    print("*************************")
    print(req)
    type = req['type'] if 'type' in req else ''
    params_goods = req['goods'] if 'goods' in req else None
    items = []
    if params_goods:
        items = json.loads(params_goods)
    if len(items) < 1:
        resp['code'] = -1
        resp['msg'] = '下单失败:没有选择商品'
        return jsonify(resp)

    member_info = g.member_info
    target = PayService()
    params = {}
    resp = target.createOrder(member_info.id, items, params)
    print("^^^^^^^^^^^^^^^^^^^^^^^^^^", resp)
    if resp['code'] == 200 and type == 'cart':
        CartService.deleteItem(member_info.id, items)
    return jsonify(resp)
Пример #10
0
def orderCreate():
    resp = {"code": 200, "msg": "操作成功", "data": {}}
    req = request.values

    type = req.get('type', '')
    params_goods = req.get('goods', None)
    # 解析数据
    items = []
    if params_goods:
        items = json.loads(params_goods)

    if len(items) < 1:
        resp['code'] = -1
        resp['msg'] = '下单失败, 无商品'
        return jsonify(resp)

    member_info = g.member_info
    target = PayService()
    params = {}
    resp = target.createOrder(member_info.id, items, params)
    if resp['code'] == 200 and type == 'cart':
        # 删购物车
        CartService.deleteItem(member_info.id, items)
    return jsonify(resp)
Пример #11
0
def orderCreate():
    resp = {"code": 200, "msg": "操作成功~", "data": {}}
    req = request.values
    type = req["type"] if "type" in req else ""
    params_goods = req["goods"] if "goods" in req else None

    items = []
    if params_goods:
        items = json.loads(params_goods)

    if len(items) < 1:
        resp["code"] = -1
        resp["msg"] = "下单失败,没有选择商品"
        return jsonify(resp)

    member_info = g.member_info
    target = PayService()
    params = {}
    resp = target.createOrder(member_info.id, items, params)

    if resp["code"] == 200 and type == "cart":
        CartService.deleteItem(member_info.id, items)

    return jsonify(resp)
Пример #12
0
def recharge():
    resp = {'code': 200, 'msg': "下单成功", 'data': {}}
    req = request.values

    recharge = 'recharge'
    Cid = int(req['Cid']) if 'Cid' in req and req['Cid'] else 0
    Shopid = -200
    trolley_result = -200
    # OrderAddress = -200
    # 只放金额
    params_goods = req['params_goods'] if 'params_goods' in req else None

    items = []
    if params_goods:
        items = json.loads(params_goods)

    if len(items) < 1:
        resp['code'] = -1
        resp['msg'] = "没有金额"
        return jsonify(resp)

    target = PayService()

    params = {}

    resp = target.createOrder(Cid, Shopid, items, recharge=recharge, params=params)

    # --------------------------------------------------------------------------------

    order_sn = resp['data']['order_sn']
    pay_order_info = PayOrder.query.filter_by(order_sn=order_sn).first()
    if not pay_order_info:
        resp['code'] = -1
        resp['code'] = "系统繁忙"
        return jsonify(resp)

    oauth_bind_info = CustomerLogin.query.filter_by(Cid=Cid).first()
    if not oauth_bind_info:
        resp['code'] = -1
        resp['code'] = "系统繁忙"
        return jsonify(resp)

    config_mina = app.config["MINA_APP"]
    notify_url = app.config["APP"]["domain"] + config_mina['recharge_callback_url']
    target_wechat =WeChatService(merchant_key=config_mina["paykey"])

    data = {
        'appid': config_mina['appid'],
        'mch_id': config_mina['mch_id'],
        'nonce_str': target_wechat.get_nonce_str(),
        'body': "购买",
        'out_trade_no': pay_order_info.order_sn,
        'total_fee': int(pay_order_info.total_price * 100),
        'spbill_create_ip': '132.232.139.186',
        'notify_url': notify_url,
        'trade_type':'JSAPI',
        'openid': oauth_bind_info.openid

    }

    pay_info = target_wechat.get_pay_info(data)

    # 保存prepay_id
    pay_order_info.prepay_id = pay_info['prepay_id']
    db.session.add(pay_order_info)
    db.session.commit()

    resp['data']['pay_info'] = pay_info

    return jsonify(resp)