customer.py 1.56 KB
Newer Older
pengxiong's avatar
pengxiong committed
1 2 3 4 5 6 7 8 9 10 11
# -*- encoding: utf-8 -*-
# -----------------------------------------------------------------------------
# @File Name  : customer.py
# @Time       : 2021/1/11 下午5:53
# @Author     : X. Peng
# @Email      : acepengxiong@163.com
# @Software   : PyCharm
# -----------------------------------------------------------------------------
from sqlalchemy import and_

from app.api.engine import TAMP_SQL, tamp_diagnose_app_engine
pengxiong's avatar
pengxiong committed
12
from app.model.tamp_diagnose_app import Customer, IfaCustomer, IfaCustomerView, CustomerView
pengxiong's avatar
pengxiong committed
13 14 15 16 17 18 19 20 21 22 23 24


def get_customer_list(args):
    """"""
    pageNumber = args['pageNumber']
    pageSize = args['pageSize']
    offset = (pageNumber - 1) * pageSize
    name = args.get('name')
    ifa_id = args.get('ifa_id')

    with TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app:
        tamp_diagnose_session = tamp_diagnose_app.session
pengxiong's avatar
pengxiong committed
25 26 27
        customer_id_list = tamp_diagnose_session.query(IfaCustomerView.customer_id).filter(and_(
            IfaCustomerView.ifa_id == ifa_id,
            IfaCustomerView.delete_tag == 0,
pengxiong's avatar
pengxiong committed
28 29 30
        )).all()
        customer_id_list = [r[0] for r in customer_id_list]
        conditions = [
pengxiong's avatar
pengxiong committed
31 32
            CustomerView.id.in_(customer_id_list),
            CustomerView.delete_tag == 0,
pengxiong's avatar
pengxiong committed
33 34
        ]
        if name:
pengxiong's avatar
pengxiong committed
35 36
            conditions.append(CustomerView.customer_name.like('%' + name + '%'))
        customer_list = tamp_diagnose_session.query(CustomerView).filter(and_(
pengxiong's avatar
pengxiong committed
37 38 39 40
            *conditions
        )).all()
        allow_field = ['id', 'customer_name', 'valueSex', 'phone']
        return [r.to_dict(allow_field) for r in customer_list]