Exemplo n.º 1
0
def get_order_detail(request):
    order_id = request.GET.get("order_id", "")
    results = OrderService.order_detail(order_id)
    refund_state = results["refund_state"]
    refund_order = ReFundService.get_format_refund_order(order_id)
    if refund_order != "":
        apply_reason = refund_order["reason"]
    else:
        apply_reason = ""
    if refund_state != "":
        refund_button = False
        if refund_state == "apply_refunding":
            refund_button = True
        results["seller_refund_info"] = {
            "refund_info": results["refund_info"],
            "refund_info_color": results["refund_info_color"],
            "refund_button": refund_button,
            "refund_apply_reason": apply_reason,
            "refund_state": results["refund_state"]

        }
    result = {
        "meta": {
            "msg": "",
            "code": 0
        },
        "results": results
    }
    return JsonResponse(result, encoder=DjangoJSONEncoder)
Exemplo n.º 2
0
    def _create_order_report(self, sheet, data_list, flush_bound=500):
        sheet_style_normal = self.get_sheet_style()
        row_index = 1
        with open(OrderReport.report_abs_path_txt, mode="w",
                  encoding="utf-8") as f:
            for item in data_list:
                order_detail = OrderService.order_detail(item.trade_parent_id)
                string = ""
                for order in order_detail["goods"]:
                    sheet.row(row_index).write(0,
                                               str(order_detail["trade_id"]),
                                               style=sheet_style_normal)
                    sheet.row(row_index).write(1,
                                               order["title"],
                                               style=sheet_style_normal)
                    sheet.row(row_index).write(2,
                                               str(order["buy_num"]),
                                               style=sheet_style_normal)
                    sheet.row(row_index).write(3,
                                               str(order["price"]),
                                               style=sheet_style_normal)
                    sheet.row(row_index).write(
                        4,
                        order_detail["address"]["receiver"],
                        style=sheet_style_normal)
                    sheet.row(row_index).write(
                        5,
                        str(order_detail["address"]["tel"]),
                        style=sheet_style_normal)
                    sheet.row(row_index).write(
                        6,
                        order_detail["address"]["address"],
                        style=sheet_style_normal)
                    sheet.row(row_index).write(7,
                                               order_detail["comment"],
                                               style=sheet_style_normal)
                    sheet.row(row_index).write(8,
                                               order_detail["seller_comment"],
                                               style=sheet_style_normal)
                    # str_item = "姓名: %s。\t电话: %s。\t地址: %s。\t商品名称: %s。\t商品数量: %s\n" % (
                    #     order_detail["address"]["receiver"], order_detail["address"]["tel"], order_detail["address"]["address"], order["title"], str(order["buy_num"])
                    # )
                    str_item = "%s。%s。%s。%s * %s\n" % (
                        order_detail["address"]["receiver"],
                        order_detail["address"]["tel"],
                        order_detail["address"]["address"], order["title"],
                        str(order["buy_num"]))
                    string += str_item
                    row_index += 1

                f.write(string)
                if row_index % flush_bound == 0:
                    sheet.flush_row_data()
                # ToDo
                if row_index >= 65535:
                    # Excel 2003格式最大行数
                    print("Warning: excel reach max row num.")
                    break
Exemplo n.º 3
0
    def save_pay_order(cls, order):
        pays = models.WeChatPay.objects.get(
            out_trade_no=order.get("out_trade_no"))
        if not cls.check_pay(pays.order_id):
            logger.info(f"{pays.order_id}已经支付")
            return
        save_dict = {
            "transaction_id": order.get("transaction_id"),
            "out_trade_no": order.get("out_trade_no"),
            "time_end": order.get("time_end"),
            "total_fee": order.get("total_fee"),
            "trade_state": order.get("trade_state", ""),
            "ctime": datetime.strptime(order.get("time_end"), "%Y%m%d%H%M%S")
        }
        models.WeChatPay.objects.update_or_create(
            out_trade_no=order.get("out_trade_no"), defaults=save_dict)

        order_info = OrderService.pay_sccuess(pays.order_id,
                                              save_dict.get("ctime"))
        # send template message
        data = {
            "name": order_info.get("name"),
            "number": order_info.get("number"),
            "money": save_dict.get("total_fee"),
            "create_time":
            save_dict.get("ctime").strftime("%Y-%m-%d %H:%M:%S"),
            "way": "微信支付",
            "order_id": pays.order_id,
        }
        PushOrderMessage.send_message(pays.openid, pays.prepay_id, data)
        try:
            order_detail = OrderService.order_detail(pays.order_id)
            from passport.models import PassportUser
            seller = PassportUser.objects.get(id=order_detail.get("seller_id"))
            we_user = seller.wechatuser
            goods_titles = [d.get("title") for d in order_detail.get("goods")]
            data_tuanzhang = {
                "name": order_info.get("name"),
                "goods": "、".join(goods_titles),
                "price": order_detail.get("order_price"),
                "user_name": we_user.nickname,
                "money": save_dict.get("total_fee"),
                "create_time":
                save_dict.get("ctime").strftime("%Y-%m-%d %H:%M:%S"),
                "order_id": pays.order_id,
            }
            PushTuanZhangMessage.send_message(we_user.openid, pays.prepay_id,
                                              data_tuanzhang)
        except Exception as e:
            import traceback
            logger.exception(f'{e}')
        logger.info("openid%s, pay_id:%s", pays.openid, pays.prepay_id)
Exemplo n.º 4
0
def get_my_join_jielong_detail(request):
    order_id = request.GET.get("order_id", "")
    results = OrderService.order_detail(order_id)
    if results:
        jielong_id = results["activity_id"]
        jielong = JieLong.objects.get(id=jielong_id)
        p_nickname = jielong.passport_user.wechatuser.nickname
        p_avatar_url = jielong.passport_user.wechatuser.avatar_url
        wechat_no = jielong.wechat_no
        results["nickname"] = p_nickname
        results["avatar_url"] = p_avatar_url
        results["wechat_no"] = wechat_no
        results["time_info"] = "%s发起" % (get_time_span(
            UtilDateTime.utc2local(jielong.create_time)))
        results["title"] = jielong.title
        results["order_time"] = results["order_time"].strftime(
            "%Y-%m-%d %H:%M:%S")
        results["activity_status"] = jielong_service.get_jielong_status(
            jielong_id)

    result = {"meta": {"msg": "", "code": 0}, "results": results}
    return JsonResponse(result, encoder=DjangoJSONEncoder)
Exemplo n.º 5
0
def get_order_copy_info(request,**kwargs):
    order_id = request.GET.get("order_id",None)
    if not order_id:
        result = {
            "meta": {
                "msg": "缺少订单id参数",
                "code": 1
            },
            "results": {}
        }
        return JsonResponse(result, encoder=DjangoJSONEncoder)


    delivery = []
    order_detail = OrderService.order_detail(order_id = order_id)
    receiver = order_detail["address"]["receiver"]
    tel =  order_detail["address"]["tel"]
    address =  order_detail["address"]["address"]
    goods = order_detail["goods"]
    if len(goods) > 0:
        for g in goods:
            title = g["title"]
            buy_num = g["buy_num"]
            delivery_info = "%s。%s。%s。%s * %s " % (receiver,tel,address,title,buy_num)
            delivery.append(delivery_info)
    delivery_info = "\n".join(delivery)
    result = {
        "meta": {
            "msg": "",
            "code": 0
        },
        "results": {
            # "order_data":"姓名,电话,地址,商品名称,商品数量\n姓名,电话,地址,商品名称,商品数量"
            "order_data":delivery_info
        }
    }
    return JsonResponse(result, encoder=DjangoJSONEncoder)
Exemplo n.º 6
0
def get_delivery_order_list(request,**kwargs):
    user_id = kwargs.get("userid")
    jielong_id = request.GET.get("jielong_id",None)
    if not jielong_id:
        result = {
            "meta": {
                "msg": "缺少接龙活动id参数",
                "code": 1
            },
            "results": {}
        }
        return JsonResponse(result, encoder=DjangoJSONEncoder)

    kwargs = {
        "seller_id": user_id,
        "jielong_id":jielong_id
    }
    page_size = int(request.GET.get("page_size", 500))
    page_no = int(request.GET.get("page_no", 1))
    list_data, count = OrderService.order_list(page_size, page_no, **kwargs)
    has_next = False if len(list_data) <= page_size else True

    delivery = []
    if len(list_data) > 0:
        for o in list_data:
            order_id = o["trade_id"]
            order_detail = OrderService.order_detail(order_id = order_id)
            receiver = order_detail["address"]["receiver"]
            tel =  order_detail["address"]["tel"]
            address =  order_detail["address"]["address"]
            goods = order_detail["goods"]
            if len(goods) > 0:
                for g in goods:
                    title = g["title"]
                    buy_num = g["buy_num"]
                    delivery_info = "%s。%s。%s。%s * %s " % (receiver,tel,address,title,buy_num)
                    delivery.append(delivery_info)
            else:
                continue
        delivery_info = "\n".join(delivery)
        result = {
            "meta": {
                "msg": "",
                "code": 0
            },
            "results": {
                # "order_data":"姓名,电话,地址,商品名称,商品数量\n姓名,电话,地址,商品名称,商品数量"
                "order_data":delivery_info
            }
        }
        return JsonResponse(result, encoder=DjangoJSONEncoder)
    else:
        result = {
            "meta": {
                "msg": "",
                "code": 0
            },
            "results": {
                }
        }
        return JsonResponse(result, encoder=DjangoJSONEncoder)