Exemplo n.º 1
0
    def appeal_to_wish_support(self):
        """
        将消息上诉给WishSupport处理

        参数仅仅需要正确的 ticket id
        :return:
        """
        ticket_id = self.params.get("ticket_id", "")
        ticket_handler = WishTicket(self.shop)
        with sessionCM() as session:
            channel = Channel.find_by_origin_id(session, ticket_id)
        if not channel:
            return {"status": 0, "data": "\"ticket_id\"不存在!"}

        result = ticket_handler.appeal_support_ticket_by_id(
            ticket_id=ticket_id)

        if result.get("success", ""):
            return {"status": 1, "data": "处理成功!"}
        else:
            return {
                "status": 0,
                "data": "处理失败!",
                "errors": result.get("message", "")
            }
Exemplo n.º 2
0
    def sync_message_list(self, msg_source, current_page=1, page_size=100):
        """
        同步订单留言
        :return:
        """
        with sessionCM() as session:
            while True:
                result = self.msg_handler.get_msg_relation_list(
                    msg_source, current_page, page_size)
                print type(result), len(result)
                print result
                if not result["success"]:
                    return  # result["exception"]
                current_page += 1
                for relation in result.get("result", []):
                    print relation
                    # 判断当前同步下来的Channel是否存在
                    chanel = Channel.find_by_origin_id(session,
                                                       relation["channelId"])
                    # 若和上次lastMessageId相同,就不用再获取详情
                    if chanel and relation["lastMessageId"] == chanel[
                            "last_msg_id"]:
                        continue
                    if len(str(relation["messageTime"])) == 13:
                        last_msg_date_timestamp = long(
                            str(relation["messageTime"])[:-3])
                    else:
                        last_msg_date_timestamp = relation["messageTime"]

                    # seller_id 只有在卖家发送一条消息之后从summary中获取到,relation["childId"] 只是子账号ID 并不是loginId
                    chanel = Channel.update(
                        session,
                        chanel,
                        shop_id=self.shop.id,
                        seller_id=relation["childId"],
                        seller_name=relation["childName"],
                        buyer_id=relation["otherLoginId"],
                        buyer_name=relation["otherName"],
                        read_stat=relation["readStat"],
                        deal_stat=relation["dealStat"],
                        open_date="",
                        close_date="",
                        closed_by="",
                        flag=relation["rank"],
                        origin_id=relation["channelId"],
                        msg_source=msg_source,
                        relation_type="",
                        relation_id="",
                        last_msg_id=relation["lastMessageId"],
                        last_msg_date=time.strftime(
                            "%Y-%m-%d %H:%M:%S",
                            time.localtime(last_msg_date_timestamp)),
                        last_msg_content=relation["lastMessageContent"])
                    # sync_smt_customer_detail.delay(self, chanel.id, msg_source)
                    print chanel.id, chanel.seller_id, chanel.seller_name, chanel.last_msg_content
                    yield chanel.id
                if len(result["result"]) == 0:
                    break
Exemplo n.º 3
0
 def _deal_with_result(datas):
     if isinstance(datas, dict):
         datas = [datas]
     print "处理Ticket ... "
     for ticket in datas:
         print ticket
         ticket = ticket["Ticket"]
         print shop_id
         kw = {
             "shop_id":
             shop_id,
             "seller_id":
             ticket["merchant_id"],
             "seller_name":
             "",
             "buyer_id":
             ticket["UserInfo"]["id"],
             "buyer_name":
             ticket["UserInfo"]["name"],
             "read_stat":
             "0",
             "deal_stat":
             0 if ticket["state_id"] == '4' else 1,
             "open_date":
             ticket["open_date"],
             "close_date":
             ticket.get("close-date", ""),
             "closed_by":
             "",
             "flag":
             "",
             "msg_source":
             "",
             "origin_id":
             ticket["id"],
             "relation_id":
             ticket["transaction_id"],
             "relation_type":
             "transaction",
             "last_msg_date":
             ticket["last_update_date"],
             "last_msg_id":
             "",
             "last_msg_content":
             ticket["subject"] + ";" + ticket["sublabel"]
         }
         with sessionCM() as session:
             channel = Channel.find_by_origin_id(session, ticket["id"])
             print "更新/生成Ticket ... "
             channel = Channel.update(session, channel, **kw)
             print "更新Replies ... "
             # 直接同步消息内容
             self.sync_message_detail(channel, ticket["replies"])
             print "更新Replies 完成!"