Ejemplo n.º 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)
Ejemplo n.º 2
0
def memberOrderOps():
    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    req = request.values
    order_sn = req['order_sn'] if 'order_sn' in req else ''
    act = req['action'] if 'action' in req else ''
    pay_order_info = PayOrder.query.filter_by(order_sn=order_sn).first()
    if not pay_order_info:
        resp['code'] = -1
        resp['msg'] = "系统繁忙。请稍后再试~~"
        return jsonify(resp)

    if act == "cancel":
        target_pay = PayService()
        ret = target_pay.closeOrder(pay_order_id=pay_order_info.id)
        if not ret:
            resp['code'] = -1
            resp['msg'] = "系统繁忙。请稍后再试~~"
            return jsonify(resp)
    elif act == "pay":
        pay_order_info.status = -5
        pay_order_info.updated_time = getCurrentDate()
        print(pay_order_info.status, pay_order_info.updated_time)
        db.session.add(pay_order_info)
        db.session.commit()

    return jsonify(resp)
Ejemplo n.º 3
0
def orderOps():
    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    req = request.values
    member_info = g.member_info
    id = req['id'] if 'id' in req else ''
    act = req['act'] if 'act' in req else ''
    pay_order_item_info = PayOrderItem.query.filter_by(
        id=id, member_id=member_info.id).first()
    # print(pay_order_item_info)
    # print("11221211")
    if not pay_order_item_info:
        resp['code'] = -1
        resp['msg'] = "系统繁忙,请稍后再试~~"
        return jsonify(resp)

    if act == "cancel":
        target_pay = PayService()
        ret = target_pay.closeOrder(pay_order_item_id=id)
        if not ret:
            resp['code'] = -1
            resp['msg'] = "系统繁忙。请稍后再试~~"
            return jsonify(resp)
#	elif act == "confirm":
#		pay_order_info.express_status = 1
#		pay_order_info.updated_time = getCurrentDate()
#		db.session.add( pay_order_info )
#		db.session.commit()

    return jsonify(resp)
Ejemplo n.º 4
0
def confirmreceipt():

    # 确认收货
    # 用户冻结金额清零
    # 商户余额增加加入记录

    resp = {'code': 200, 'msg': '确认收货成功'}

    Oid = request.values['Oid'] if 'Oid' in request.values else -1
    Shopid = request.values['Shopid'] if 'Shopid' in request.values else -1

    Pay_info = PayOrder.query.filter_by(id=Oid).first()
    Pay_info.status = -5
    loginfo = Balancelog.query.filter_by(
        receipt_qrcode=Pay_info.order_sn).first()
    Shop_info = Shop.query.filter_by(Shopid=Shopid).first()
    Apply_info = Apply.query.filter_by(Aid=Shop_info.Aid).first()
    # 商户Cid
    Customer_info = Customer.query.filter_by(Cid=Apply_info.Cid).first()

    # 用户冻结金额清零
    freeze_balance = loginfo.freeze_balance
    loginfo.freeze_balance = float(0)

    mybalance = float(Customer_info.MyBalance)
    result = float(freeze_balance)
    mybalance = mybalance + result
    Customer_info.MyBalance = mybalance

    # 销量增加
    pay_order_item_info = PayOrderItem.query.filter_by(
        pay_order_id=Pay_info.id).all()
    for item in pay_order_item_info:
        product_info = Product.query.filter_by(Pid=item.Pid).first()
        sold = int(product_info.ProductSold)
        sold_result = sold + item.quantity
        product_info.ProductSold = sold_result

    # 打款给商家记录
    Balance_log = Balancelog()

    Balance_log.BankCardNumber = -1000
    Balance_log.Cid = Customer_info.Cid
    Balance_log.Openingbank = -1000
    Balance_log.balance = freeze_balance
    Balance_log.operating = 4
    Balance_log.status = 6
    Balance_log.total_balance = freeze_balance
    target_pay = PayService()
    Balance_log.receipt_qrcode = target_pay.geneOrderSn()
    Balancelog.freeze_balance = float(0)
    Balance_log.Accountname = -1000
    Balance_log.createtime = getCurrentDate()
    Balance_log.updatetime = getCurrentDate()
    db.session.add(Balance_log)

    db.session.commit()
    response = jsonify(resp)
    response.headers['Access-Control-Allow-Origin'] = '*'
    return response
Ejemplo n.º 5
0
def order_create():
    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)
    member_info = g.member_info

    target = PayService()
    params = {}
    resp = target.create_order(member_info.id, items, params)
    if resp['code'] == 200 and type == "cart":
        CartService.delete_item(member_info.id, items)
    return jsonify(resp)
Ejemplo n.º 6
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)
Ejemplo n.º 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

    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)
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
    def closePingLun(self, params=''):
        now = datetime.datetime.now()
        inter = app.config['JOB_STATUS_CHANGES']['days']

        date_before_days = now + datetime.timedelta(days=int(inter))
        list = PayOrder.query.filter_by( status = 1,express_status = 1, comment_status = 0 ).\
            filter( PayOrder.created_time <= getFormatDate( date = date_before_days ) ).all()
        if not list:
            app.logger.info("no data~~")
            return

        pay_target = PayService()
        for item in list:
            params = {
                'order_sn': item.order_sn,
                'score': 10,
                'content': "系统默认好评!~",
                'member_id': item.member_id,
            }

        ret = pay_target.addComments(params)
        if not ret:
            app.logger.info("error in add pinglun~~")
            return

        app.logger.info("PingLun is over~~")
        return
Ejemplo n.º 10
0
def orderOps():
    resp = {"code": 200, "msg": "操作成功~", "data": {}}
    req = request.values
    member_info = g.member_info
    order_sn = req["order_sn"] if "order_sn" in req else ""
    act = req["act"] if "act" in req else ""

    pay_order_info = PayOrder.query.filter_by(
        order_sn=order_sn, member_id=member_info.id).first()
    if not pay_order_info:
        resp["code"] = -1
        resp["msg"] = "系统繁忙,请稍后重试!"
        return jsonify(resp)

    if act == "cancel":
        target_pay = PayService()
        ret = target_pay.closeOrder(pay_order_id=pay_order_info.id)
        if not ret:
            resp["code"] = -1
            resp["msg"] = "系统繁忙,请稍后重试!"
            return jsonify(resp)

    elif act == "confirm":
        pay_order_info.express_status = 1
        pay_order_info.updated_time = getCurrentDate()
        db.session.add(pay_order_info)
        db.session.commit()

    return jsonify(resp)
Ejemplo n.º 11
0
def orderOps():
    resp = {'code': 200, 'msg': '操作成功', 'data': {}}
    req = request.values
    member_info = g.member_info
    order_sn = req['order_sn'] if 'order_sn' in req else ''
    act = req['act'] if 'act' in req else ''
    pay_order_info = PayOrder.query.filter_by(
        order_sn=order_sn, member_id=member_info.id).first()
    if not pay_order_info:
        resp['code'] = -1
        resp['msg'] = "系统繁忙,请稍后再试"
        return jsonify(resp)

    if act == "cancel":
        target_pay = PayService()
        ret = target_pay.closeOrder(pay_order_id=pay_order_info.id)
        if not ret:
            resp['code'] = -1
            resp['msg'] = "系统繁忙,请稍后再试"
            return jsonify(resp)
    elif act == "confirm":
        pay_order_info.express_status = 1
        pay_order_info.updated_time = getCurrentDate()
        db.session.add(pay_order_info)
        db.session.commit()

    return jsonify(resp)
Ejemplo n.º 12
0
def orderCallback2():
	req = request.values
	id = int(req['id']) if 'id' in req else 0
	if not id:
		return "fail"

	target_pay = PayService()
	target_pay.orderSuccess(pay_order_id= id , params={ "pay_sn": "" } )
	return "success"
Ejemplo n.º 13
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)
Ejemplo n.º 14
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)
Ejemplo n.º 15
0
    def run(self, params):
        id = params['param'][0] if params['param'] and len(
            params['param']) else 0
        if not id:
            app.logger.info(" fail ")
            return

        target_pay = PayService()
        target_pay.orderSuccess(pay_order_id=id, params={"pay_sn": ""})

        app.logger.info("it's over~~")
Ejemplo n.º 16
0
    def run(self, params):
        now = datetime.datetime.now()
        date_before_30min = now + datetime.timedelta(minutes=-30)
        list = PayOrder.query.filter_by( status = -8 ).\
         filter(PayOrder.created_time <= get_format_date(date = date_before_30min)).all()
        if not list:
            app.logger.info("no data~~")
            return

        pay_target = PayService()
        for item in list:
            pay_target.close_order(pay_order_id=item.id)
        app.logger.info("it's over~~")
Ejemplo n.º 17
0
    def closeFuKuan(self, params=''):
        now = datetime.datetime.now()
        inter = app.config['JOB_STATUS_CHANGES']['minutes']
        date_before_30min = now + datetime.timedelta(minutes=int(inter))
        list = PayOrder.query.filter_by( status = -8 ).\
            filter( PayOrder.created_time <= getFormatDate( date = date_before_30min ) ).all()
        if not list:
            app.logger.info("no data~~")
            return

        pay_target = PayService()
        for item in list:
            pay_target.closeOrder(pay_order_id=item.id)
        app.logger.info("FuKuan is over~~")
        return
Ejemplo n.º 18
0
def recharge_callback():
    # logging.info('进入回调函数')
    result_data = {
        'return_code': 'SUCCESS',
        'return_msg': 'OK'
    }

    header = {'Content-Type': 'application/xml'}
    config_mina = app.config['MINA_APP']

    # logging.info(request.data)

    target_wechat = WeChatService(merchant_key=config_mina['paykey'])
    # print(request.data)

    callback_data = target_wechat.xml_to_dict(request.data)

    sign = callback_data['sign']
    callback_data.pop('sign')
    gene_sign = target_wechat.create_sign(callback_data)

    if sign != gene_sign:
        # logging.info('sing!=gene_sign')
        result_data['return_code'] = result_data['return_msg'] = "FAIL"
        return target_wechat.dict_to_xml(result_data), header

    order_sn = callback_data['out_trade_no']
    pay_order_info = PayOrder.query.filter_by(order_sn=order_sn).first()
    if not pay_order_info:
        # logging.info('not pay_order_info')
        result_data['return_code'] = result_data['return_msg'] = "FAIL"
        return target_wechat.dict_to_xml(result_data), header

    # if int(pay_order_info.total_price * 100) == int(callback_data['total_fee']):
    #     result_data['return_code'] = result_data['return_msg'] = "FAIL"
    #     return target_wechat.dict_to_xml(result_data), header

    if pay_order_info.status == 12:
        # logging.info('pay_order_info.status == 1')
        return target_wechat.dict_to_xml(result_data), header

    target_pay = PayService()
    target_pay.rechargeorderSuccess(pay_order_info.member_id, pay_order_info.id, params={'pay_sn': callback_data['transaction_id']})

    # # 微信回调加入日志
    # target_pay.addPayCallbackData(pay_order_id=pay_order_info.id, data=request.data)

    return target_wechat.dict_to_xml(result_data), header
Ejemplo n.º 19
0
    def closeQuCan(self, params=''):
        now = datetime.datetime.now()
        inter = app.config['JOB_STATUS_CHANGES']['hours']

        date_before_hours = now + datetime.timedelta(hours=int(inter))
        list = PayOrder.query.filter_by( status = 1, express_status = -6 ).\
            filter( PayOrder.created_time <= getFormatDate( date = date_before_hours ) ).all()
        if not list:
            app.logger.info("no data~~")
            return

        pay_target = PayService()
        for item in list:
            pay_target.confirmOrder(pay_order_id=item.id)
        app.logger.info("QuCan is over~~")
        return
Ejemplo n.º 20
0
def orderCallback():
    """模拟支付"""
    resp = {'code': 0, 'msg': '支付成功', 'data': {}}
    req = request.values
    order_sn = req['order_sn']
    pay_order_info = PayOrder.query.filter_by(order_sn=order_sn).first()
    #模拟第三方支付流水信息,pay_sn
    transaction_id = "1004400740201409030005092168"
    target_pay = PayService()
    order_suc = target_pay.orderSuccess(pay_order_id=pay_order_info.id, params={"pay_sn": transaction_id})
    # 将微信回掉结果放入记录表
    callback = target_pay.addPayCallbackData(pay_order_id=pay_order_info.id, data=pay_order_info)
    if order_suc and callback:
        resp['code'] = 200

    return jsonify(resp)
Ejemplo n.º 21
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)
Ejemplo n.º 22
0
def orderOps():
    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    req = request.values
    order_id = req['id'] if 'id' in req else 0
    act = req['act'] if 'act' in req else ''

    # pay_order_info = PayOrder.query.filter_by( id = id ).first()
    # if not pay_order_info:
    #     resp['code'] = -1
    #     resp['msg'] = "系统繁忙。请稍后再试~~"
    #     return jsonify(resp)

    app.logger.info("test 1")
    target = PayService()

    if act == "take":
        # 确认取餐
        result = target.confirmOrder(pay_order_id=order_id)

    if act == "express":
        # 确认到账——进行sale和成功回调
        # pay_order_info.express_status = -6  # -6
        # pay_order_info.updated_time = getCurrentDate()
        # db.session.add( pay_order_info )

        # 修改新增售卖记录 和 销售量
        result = target.addPayCallbackData(pay_order_id=order_id,
                                           type='pay',
                                           data='审核确认')
        app.logger.info("result is1 {}".format(result))

    if act == "cancel":
        # 取消订单——归还库存
        result = target.addPayCallbackData(pay_order_id=order_id,
                                           type='cancel',
                                           data='审核取消')
    if not result:
        app.logger.info("result is 2{}".format(result))

        resp['code'] = -1
        resp['msg'] = "系统繁忙。请稍后再试~~"
        return jsonify(resp)

    return jsonify(resp)
Ejemplo n.º 23
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)
Ejemplo n.º 24
0
def withdraw():
    resp = {'code': 200, 'msg': "提交申请成功"}
    req = request.values

    Cid = int(req['Cid']) if 'Cid' in req and req['Cid'] else 0
    BankCardNumber = req['BankCardNumber'] if 'BankCardNumber' in req and req['BankCardNumber'] else 0
    Openingbank = req['Openingbank'] if 'Openingbank' in req and req['Openingbank'] else 0
    Accountname = req['Accountname'] if 'Accountname' in req and req['Accountname'] else 0
    balance = req['balance'] if 'balance' in req and req['balance'] else 0

    info = Customer.query.filter_by(Cid=Cid).first()

    mybalance = float(info.MyBalance)
    result = float(balance)
    if mybalance < result:
        resp['code'] = -1
        resp['msg'] = '余额不足'
        return jsonify(resp)

    mybalance = mybalance - result
    info.MyBalance = mybalance
    db.session.add(info)

    Balance_log = Balancelog()

    Balance_log.BankCardNumber = BankCardNumber
    Balance_log.Cid = Cid
    Balance_log.Openingbank = Openingbank
    Balance_log.balance = balance
    Balance_log.operating = 3
    Balance_log.status = 1
    Balance_log.total_balance = -1000
    target_pay = PayService()
    Balance_log.receipt_qrcode = target_pay.geneOrderSn()
    Balancelog.freeze_balance = balance
    Balance_log.Accountname = Accountname
    Balance_log.createtime = getCurrentDate()
    Balance_log.updatetime = getCurrentDate()
    db.session.add(Balance_log)
    db.session.commit()

    return jsonify(resp)
Ejemplo n.º 25
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)
Ejemplo n.º 26
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)
Ejemplo n.º 27
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)
Ejemplo n.º 28
0
def callBack():

    # 返回给微信使用
    result_data = {
        'return_code':'SUCCESS',
        'return_msg':'OK'
    }
    header = {'content-Type':'application/xml'}

    # 对微信下单成功后的返回给我们的信息(xml)进行验证
    config_mina = app.config['MINA_APP']
    target_wechat = WeChatService(merchant_key=config_mina['paykey'])

    # 取出微信给我们的xml信息,并转换成dict数据格式
    callback_data = target_wechat.xml_to_dict(request.data)
    app.logger.info(callback_data)

    # 取出sign值(签名),再生成一次sign值,做比较,防止伪造 ******************************
    sign = callback_data['sign']
    callback_data.pop('sign')
    gene_sign = target_wechat.create_sign(callback_data)
    app.logger.info(gene_sign)

    # 两次sign值做比较,如果测试官网的回调函数代码,这个步骤就要省略
    # if sign != gene_sign:
    #     result_data['return_code'] = result_data['return_msg'] = 'FAIL'
    #     return target_wechat.dict_to_xml(result_data),header

    # 对比金钱的数量是否正确 ****************************

    # 取出订单号查询对应的订单信息
    order_sn = callback_data['out_trade_no']
    pay_order_info = PayOrder.query.filter_by(order_sn=order_sn).first()
    app.logger.info('牛逼',pay_order_info)
    if not pay_order_info:
        result_data['return_code'] = result_data['return_msg'] = 'FAIL'
        return target_wechat.dict_to_xml(result_data), header

    if int(pay_order_info.total_price * 100) != int(callback_data['total_fee']):
        result_data['return_code'] = result_data['return_msg'] = 'FAIL'
        return target_wechat.dict_to_xml(result_data), header

    # 微信会有间隔的返回数据,如果订单的状态已经置为1,则直接返回
    if pay_order_info.status == 1:
        return target_wechat.dict_to_xml(result_data), header

    # 下单成功(微信支付回调成功的操作:pay_order的状态置为1,其他状态值也要修改)
    target_pay = PayService()
    target_pay.orderSuccess(pay_order_id=pay_order_info.id,params={'pay_sn':callback_data['transaction_id']})

    # 将微信回调的信息存表
    target_pay.addPayCallbackData(pay_order_id=pay_order_info.id,data=request.data)

    return target_wechat.dict_to_xml(result_data),header
Ejemplo n.º 29
0
def orderCallback():
    result_data = {'return_code': 'SUCCESS', 'return_msg': 'OK'}

    header = {'Content-Type': 'application/xml'}
    config_mina = app.config['MINA_APP']
    target_wechat = WeChatService(merchant_key=config_mina['paykey'])
    callback_data = target_wechat.xml_to_dict(request.data)

    app.logger.info(callback_data)

    sign = callback_data['sign']
    callback_data.pop('sign')

    gene_sign = target_wechat.create_sign(callback_data)

    app.logger.info(gene_sign)

    if sign != gene_sign:
        result_data['return_code'] = result_data['return_msg'] = "FAIL"
        return target_wechat.dict_to_xml(result_data), header

    if callback_data['result_code'] != 'SUCCESS':
        result_data['return_code'] = result_data['return_msg'] = 'FAIL'
        return target_wechat.dict_to_xml(result_data), header

        order_sn = callback_data['out_trade_no']
        pay_order_info = PayOrder.query.filter_by(order_sn=order_sn).first()
        if not pay_order_info:
            result_data['return_code'] = result_data['return_msg'] = 'FAIL'
            return target_wechat.dict_to_xml(result_data), header

        if int(pay_order_info.total_price * 100) != int(
                callback_data['total_price']):
            result_data['return_code'] = result_data['return_msg'] = 'FAIL'
            return target_wechat.dict_to_xml(result_data), header

    if pay_order_info.status == 1:
        return target_wechat.dict_to_xml(result_data), header

    target_pay = PayService()
    target_pay.orderSuccess(pay_order_id=pay_order_info.id,
                            params={'pay_sn': callback_data['transaction_id']})

    # 将微信回调的结果放入记录表
    target_pay.addPayCallbackData(pay_order_id=pay_order_info.id,
                                  data=request.data)

    return target_wechat.dict_to_xml(result_data), header
Ejemplo n.º 30
0
def orderCallback():
    """
	如何模拟调用此函数   用 postman 将数据放入 post数据中
	https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_7&index=8   小程序回调返回的数据 xml格式
	:return:
	"""
    result_data = {'return_code': 'SUCCESS', 'return_msg': 'OK'}
    header = {'Content-Type': 'application/xml'}
    config_mina = app.config['MINA_APP']
    target_wechat = WeChatService(merchant_key=config_mina['paykey'])
    callback_data = target_wechat.xml_to_dict(
        request.data)  # request.data 整个post请求的所有数据
    app.logger.info(callback_data)
    sign = callback_data['sign']
    callback_data.pop('sign')
    # 检测这个签名是否和对应的一样
    gene_sign = target_wechat.create_sign(callback_data)
    app.logger.info(gene_sign)
    if sign != gene_sign:
        result_data['return_code'] = result_data['return_msg'] = 'FAIL'
        return target_wechat.dict_to_xml(result_data), header
    if callback_data['result_code'] != 'SUCCESS':
        result_data['return_code'] = result_data['return_msg'] = 'FAIL'
        return target_wechat.dict_to_xml(result_data), header

    order_sn = callback_data['out_trade_no']
    pay_order_info = PayOrder.query.filter_by(order_sn=order_sn).first()
    if not pay_order_info:
        result_data['return_code'] = result_data['return_msg'] = 'FAIL'
        return target_wechat.dict_to_xml(result_data), header

    if int(pay_order_info.total_price * 100) != int(
            callback_data['total_fee']):
        result_data['return_code'] = result_data['return_msg'] = 'FAIL'
        return target_wechat.dict_to_xml(result_data), header

    if pay_order_info.status == 1:
        return target_wechat.dict_to_xml(result_data), header

    target_pay = PayService()
    # 处理parorder 更新状态值
    target_pay.orderSuccess(pay_order_id=pay_order_info.id,
                            params={"pay_sn": callback_data['transaction_id']})
    # 回调结果放入记录表里
    target_pay.addPayCallbackData(pay_order_id=pay_order_info.id,
                                  data=request.data)
    return target_wechat.dict_to_xml(result_data), header