Beispiel #1
0
 def paytype_query(self, request, *args, **kwargs):
     return {
         "data":
         PayTypeModelSerializer(
             PayType.objects.filter().order_by('createtime'),
             many=True).data
     }
Beispiel #2
0
    def paypasslinktype_query(self, request, *args, **kwargs):

        print(self.request.query_params_format)
        query_format = str()
        query_params = list()
        if self.request.query_params_format.get("id"):
            query_format = query_format + " and t2.to_id=%s"
            query_params.append(self.request.query_params_format.get("id"))
        if self.request.query_params_format.get("type"):
            query_format = query_format + " and t2.type=%s"
            query_params.append(self.request.query_params_format.get("type"))

        if self.request.query_params_format.get("isAgent") == 1:
            if not self.request.query_params_format.get("userid"):
                raise PubErrorCustom("用户ID不能为空")
            query_format = query_format + " and t2.userid in (%s,0)"
            query_params.append(self.request.query_params_format.get("userid"))
        elif not self.request.query_params_format.get(
                "isAgent") and self.request.query_params_format.get("userid"):
            query_format = query_format + " and t2.userid ='%s'"
            query_params.append(self.request.query_params_format.get("userid"))
        else:
            query_format = query_format + " and t2.userid ='0'"

        paytype = PayType.objects.raw(
            """
            SELECT t1.*,t2.rate,t2.passid,t2.userid FROM paytype as t1 
            INNER JOIN paypasslinktype as t2 on t1.paytypeid = t2.paytypeid
            WHERE 1=1 %s order by t1.createtime
        """ % (query_format), query_params)

        data = PayTypeModelSerializer(paytype, many=True).data

        r_data = []

        if self.request.query_params_format.get("isAgent") == 1:
            for item in data:
                if len(r_data):
                    isFlag = False
                    for item_r_data in r_data:
                        if item_r_data['paytypeid'] == item[
                                'paytypeid'] and item_r_data['type'] == item[
                                    'type']:
                            if int(item_r_data['userid']) > 0:
                                isFlag = True
                                break
                            else:
                                item_r_data['rate'] = item['rate']
                                item_r_data['userid'] = item['userid']
                                item_r_data['createtime'] = item['createtime']
                                isFlag = True
                                break
                    if isFlag:
                        continue
                r_data.append(item)

            return {"data": r_data}
        else:
            return {"data": data}
    def get_paytypes(self, obj):
        paytype = PayType.objects.raw(
            """
            SELECT t1.*,t2.rate,t2.passid,t3.name as paypassname FROM paytype as t1 
            INNER JOIN paypasslinktype as t2 on t1.paytypeid = t2.paytypeid
            INNER JOIN paypass as t3 on t2.passid = t3.paypassid and t3.status='0'
            WHERE 1=1  and t2.to_id=%s  and t2.type=1 order by t1.createtime
        """, [obj.userid])

        return PayTypeModelSerializer(paytype, many=True).data
Beispiel #4
0
    def paypasslinktype_query(self, request, *args, **kwargs):

        query_format=str()
        query_params=list()
        if self.request.query_params_format.get("id"):
            query_format = query_format + " and t2.to_id=%s"
            query_params.append(self.request.query_params_format.get("id"))
        if self.request.query_params_format.get("type"):
            query_format = query_format + " and t2.type=%s"
            query_params.append(self.request.query_params_format.get("type"))

        paytype = PayType.objects.raw("""
            SELECT t1.*,t2.rate,t2.passid FROM paytype as t1 
            INNER JOIN paypasslinktype as t2 on t1.paytypeid = t2.paytypeid
            WHERE 1=1 %s order by t1.createtime
        """%(query_format),query_params)

        return {"data":PayTypeModelSerializer(paytype, many=True).data}