Beispiel #1
0
class ChooseHandler(BaseHandler):

    rule = {
        "user_id": Rule(direct_type=int),
        "offer_id": Rule(direct_type=int)
    }

    @login_required
    @filter_params(post=rule)
    def post(self, params):
        offer = OfferModel.query_offer_mode_with_offer_id(params["offer_id"])

        if offer.user_id != g.account["user_id"]:
            return json_fail_response(2128)

        if offer.offer_status == 3:
            return json_fail_response(2129)

        if offer.winner_user_id:
            return json_fail_response(2130)

        if not OfferListModel.check_offer_enter_status(params["offer_id"],
                                                       params["user_id"]):
            return json_fail_response(2131)

        success, message = OfferModel.choose_winner(params["offer_id"],
                                                    params["user_id"])
        if success:
            return json_success_response({"data": 1, "message": "成功"})
        else:
            return json_success_response({"data": 0, "message": message})
Beispiel #2
0
class EnterHandler(BaseHandler):

    rule = {
        "share_id": Rule(direct_type=int),
        "offer_id": Rule(direct_type=int)
    }

    @login_required
    @filter_params(post=rule)
    def post(self, params):
        enable, msg = OfferModel.check_offer_enter_enable(
            params["offer_id"], g.account["user_id"])
        if not enable:
            return json_success_response({"data": 0, "message": msg})

        offer = OfferModel.query_offer_mode_with_offer_id(params["offer_id"])

        offer_list = OfferListModel()
        offer_list.user_id = offer.user_id
        offer_list.share_id = offer.share_id
        offer_list.offer_id = offer.offer_id
        offer_list.apply_user_id = g.account["user_id"]
        offer_list.status = 1
        db.session.add(offer_list)

        offer.join_number += 1

        db.session.commit()
        return json_success_response({"data": 1, "message": "报名成功"})
Beispiel #3
0
class GetListHandler(BaseHandler):

    rule = {
        "offer_id": Rule(direct_type=int),
        "last_id": Rule(direct_type=int, allow_empty=True, default=0)
    }

    @login_required
    @filter_params(get=rule)
    def get(self, params):
        offer_list = OfferListModel.query_offer_list(params["offer_id"],
                                                     params["last_id"], 20)
        return json_success_response(offer_list)
Beispiel #4
0
class GetMyOfferHandler(BaseHandler):

    rule = {
        "user_id": Rule(direct_type=int, allow_empty=True, default=0),
        "last_id": Rule(direct_type=int, allow_empty=True, default=0)
    }

    @login_required
    @filter_params(get=rule)
    def get(self, params):
        if not params["user_id"]:
            params["user_id"] = g.account["user_id"]

        share_list = ShareModel.query_offer_share_list(params["user_id"],
                                                       params["last_id"])
        return json_success_response(
            ShareModel.format_share_model(share_list, g.account["user_id"]))
Beispiel #5
0
class InfoListHandler(BaseHandler):

    rule = {
        "last_id": Rule(direct_type=int, allow_empty=True, default=0),
        "type": Rule(direct_type=int, enum=[0, 1, 2])
    }

    @login_required
    @filter_params(get=rule)
    def get(self, params):
        # 显示提现中
        if params["type"] == 1:
            params["status"] = [1, 2]
        # 显示已提现
        elif params["type"] == 2:
            params["status"] = 3

        result = WithdrawInfoModel.query_withdraw_info_list(
            g.account["user_id"], params)
        return json_success_response(result)
Beispiel #6
0
class IndexHandler(BaseHandler):

    rule = {
        "report_name_id":
        Rule(direct_type=int),
        "reason":
        Rule(),
        "other_reason":
        Rule(allow_empty=True,
             default="",
             length=Length(min_len=0, max_len=100)),
        "type":
        Rule(direct_type=int)
    }

    @login_required
    @filter_params(post=rule)
    def post(self, params):
        share_report = ShareReportModel.query_share_report(
            g.account["user_id"], params["report_name_id"], params["type"])
        if share_report:
            return json_fail_response(2124)

        share_report = ShareReportModel()
        share_report.user_id = g.account["user_id"]
        share_report.report_name_id = params["report_name_id"]
        share_report.reason = params["reason"]
        share_report.other_reason = params["other_reason"]
        share_report.type = params["type"]

        db.session.add(share_report)

        if share_report.type == 2:
            ShareMetaModel.update_share_meta_model(params["report_name_id"],
                                                   params=["report"])

        db.session.commit()
        return json_success_response({"data": 1, "message": "操作成功"})
Beispiel #7
0
class CreateHandler(BaseHandler):

    rule = {
        "to_uid": Rule(),
        "content": Rule(),
        "msg_type": Rule(direct_type=int),
        "type": Rule(direct_type=int),
        "pub_time": Rule(),
        "image": Rule(direct_type=int, allow_empty=True, default=0),
        "video": Rule(direct_type=int, allow_empty=True, default=0),
        "audio": Rule(direct_type=int, allow_empty=True, default=0)
    }

    @login_required
    @filter_params(post=rule)
    def post(self, params):
        # 查询用户uid
        user_id_relation_model = UserIdRelationModel.query_user_by_ease_mob_id(
            params["to_uid"])
        params[
            "to_uid"] = user_id_relation_model.user_id if user_id_relation_model else params[
                "to_uid"]

        params["chatfrom"] = g.account["user_id"]
        params["chatto"] = params["to_uid"]
        params["type"] = 1

        if params["msg_type"] == 2:
            json_data = {"image": params["image"]}
        elif params["msg_type"] == 3:
            json_data = {"audio": params["audio"]}
        elif params["msg_type"] == 4:
            json_data = {"video": params["video"]}
        else:
            json_data = {}
        if json_data:
            params["json_data"] = json.dumps(json_data)

        im_model = IMMsgModel(params=params)
        return json_success_response(im_model.to_dict())
Beispiel #8
0
class AliHandler(BaseHandler):

    rule = {
        "notify_time": Rule(allow_empty=True),
        "notify_type": Rule(allow_empty=True),
        "notify_id": Rule(allow_empty=True),
        "sign_type": Rule(allow_empty=True),
        "sign": Rule(allow_empty=True),
        "out_trade_no": Rule(allow_empty=True),
        "subject": Rule(allow_empty=True),
        "payment_type": Rule(allow_empty=True),
        "trade_no": Rule(allow_empty=True),
        "trade_status": Rule(allow_empty=True),
        "seller_id": Rule(allow_empty=True),
        "seller_email": Rule(allow_empty=True),
        "buyer_id": Rule(allow_empty=True),
        "buyer_email": Rule(allow_empty=True),
        "total_fee": Rule(allow_empty=True),
        "quantity": Rule(allow_empty=True),
        "price": Rule(allow_empty=True),
        "body": Rule(allow_empty=True),
        "gmt_create": Rule(allow_empty=True),
        "gmt_payment": Rule(allow_empty=True),
        "is_total_fee_adjust": Rule(allow_empty=True),
        "use_coupon": Rule(allow_empty=True),
        "discount": Rule(allow_empty=True),
        "refund_status": Rule(allow_empty=True),
        "gmt_refund": Rule(allow_empty=True),
    }

    @filter_params(post=rule)
    def post(self, params):
        # 支付宝参数验证不通过
        if not PaymentOrderModel.verify_ali_order(params):
            return json_fail_response(2121)

        # 验证是否支付成功
        if not params["trade_status"] in ["TRADE_SUCCESS", "TRADE_FINISHED"]:
            return json_fail_response(2122)

        order_info = OrderInfoModel.query_order_info_with_order_no(
            params["out_trade_no"])
        if not order_info:
            return json_fail_response(2123)

        # 检查订单是否已经支付完成
        order_meta = OrderMetaModel.query_order_meta_with_order_id(
            order_info.order_id)
        if order_meta.order_status >= 2 or order_meta.pay_status in [
                1, 2, 4, 5, 6
        ]:
            return json_success_response({})

        params["pay_time"] = params["gmt_payment"]
        params["attach"] = ""
        params["message"] = params["body"]
        params["price"] = params["total_fee"] * 100

        # 更新订单信息
        AliHandler.update_order(params, order_info, order_meta)

        # 额外更新数据
        if order_meta.product_type == 80:
            AliHandler.send_remind_sms_for_wx(order_meta)
        elif order_meta.product_type == 90:
            pass

    @staticmethod
    def update_order(params, order_info, meta_info):
        # 更新OrderInfoModel
        AliHandler.update_order_info(params, order_info)
        # 更新OrderMeta
        AliHandler.update_order_meta(meta_info)
        # 更新Payment
        payment_info = AliHandler.update_payment(meta_info, order_info)

        if meta_info.share_id:
            AliHandler.update_share_meta(params, meta_info)

        # 想卖家推送新订单消息
        if meta_info.product_type in (50, 51, 60, 70, 80, 90):
            RedisModel.push_list(RedisModel.order_push_list,
                                 order_info.order_id)

        # 通知卖家有新订单消息
        if meta_info.product_type in (50, 51):
            RedisModel.add_new_message(meta_info.seller_id,
                                       RedisModel.new_order)

    @staticmethod
    def update_order_info(params, order_info):
        """
        更新订单信息
        :param params:
        :param order_info:
        :return:
        """
        order_info.pay_time = params["pay_time"]
        db.session.commit()

    @staticmethod
    def update_order_meta(meta_info):
        """
        更新订单中间信息
        """
        # 红包照片、私密视频、打赏、红包 支付完成,订单即为完成
        if meta_info.product_type in [11, 31, 40, 70]:
            meta_info.order_status = 6
            meta_info.pay_status = 1
            meta_info.ship_status = 3
        # 其它情况订单状态变更为支付完成
        else:
            meta_info.order_status = 2
            meta_info.pay_status = 1
        db.session.commit()

    @staticmethod
    def update_payment(meta_info, order_info):
        """
        更新订单支付信息
        :param meta_info:
        :param order_info:
        :return:
        """
        # 查询支付订单
        payment_info = PaymentModel.query_payment(meta_info.pay_id)

        # 变更支付订单状态
        payment_info.status = 1
        db.session.commit()

        # 插入对应的收款记录
        params = {
            "user_id": meta_info.seller_id,
            "purpose": payment_pay_type.get(order_info.order_type),
            "order_id": meta_info.order_id,
            "order_no": order_info.order_no,
            "fee_type": payment_info.fee_type,
            "total_fee": payment_info.total_fee,
            "cash_fee": payment_info.cash_fee,
            "coupon_fee": payment_info.coupon_fee,
            "coupon_count": payment_info.coupon_count,
            "pay_method": payment_info.pay_method,
            "pay_desc": payment_info.pay_desc,
            "status": 1,
        }
        PaymentModel(params)
        return payment_info

    @staticmethod
    def insert_payment_log(params, payment_info):
        """
        插入第三方交易流水
        """
        insert_params = {
            "user_id": payment_info.user_id,
            "pay_id": payment_info.pay_id,
            "channel_type": payment_info.pay_method,
            "transaction_type": "PAY",
            "transaction_id": params["trade_no"],
            "transaction_fee": payment_info.total_fee,
            "trade_success": 1,
            "optional": params["attach"],
            "message_detail": params.get("message", "")
        }
        PaymentLogModel(params=insert_params)

    @staticmethod
    def update_share_meta(params, meta_info):
        share_meta = ShareMetaModel.query_share_meta_model(meta_info.share_id)
        if not share_meta:
            share_meta = ShareMetaModel()
            share_meta.share_id = meta_info.share_id
            share_meta.user_id = meta_info.seller_id
            share_meta.reward = 1
            share_meta.reward_money = params["price"]

            db.session.add(share_meta)
        else:
            share_meta.reward += 1
            share_meta.reward_money += params["price"]

        db.session.commit()
        return share_meta

    @staticmethod
    def send_remind_sms_for_wx(meta_info):
        """
        微信出售后,给卖家一个短信提醒
        """
        pass

    @staticmethod
    def update_offer(params, meta_info):
        """
        更新悬赏信息
        """
        # 更新悬赏动态,悬赏付过钱后才真正发布成功
        ShareModel.query.filter_by(share_id=meta_info.share_id).update(
            dict(status=1))
        # 更新用户动态统计数字
        SocialMetaModel.update_social_meta_model(meta_info.buyer_id, ["share"])

        offer_update = {
            "status":
            1,
            "offer_status":
            2,
            "start_time":
            params["pay_time"],
            "due_time":
            (datetime.datetime.strptime(params["pay_time"]) +
             datetime.timedelta(seconds=86400)).strftime("%Y-%m-%d %H:%M:%S")
        }
        OfferModel.query.filter_by(
            share_id=meta_info.share_id).update(offer_update)