RecordService.class.php 2.18 KB
<?php
/**
 * Created by PhpStorm.
 * User: yingcai
 * Date: 2018/3/23
 * Time: 下午4:06
 */

namespace Common\Service;

use Common\Common\User;
use Common\Model\RecordModel;

class RecordService extends AbstractService
{
    // 构造方法
    public function __construct()
    {
        $this->_d = new RecordModel();

        parent::__construct();
    }

    /**
     * 组织查询条件
     *
     * @param array $params 传入参数
     * @return array
     */
    public function get_where($params = [])
    {

        $where = [
            'is_prize' => $params['type'],
            'ac_id' => $params['ac_id'],
        ];

        if (!empty($params['username'])) {
            // 用户姓名不为空
            $where['username like ?'] = '%' . $params['username'] . '%';
        }

        if (!empty($params['dp_id'])) {
            // 用户组织ID不为空
            $conds = [
                'dpIdList' => is_array($params['dp_id']) ? $params['dp_id'] : [$params['dp_id']],
                'departmentChildrenFlag' => 1, // 递归查询用户
                'memSubscribeStatus' => 1 // 已关注用户
            ];

            // 递归获取用户列表
            $user_list = User::instance()->listUsersAll($conds);
            $uids = array_column($user_list, 'memUid');

            if (empty($uids)) {

                $where['uid'] = ' ';
            } else {

                $where['uid'] = $uids;
            }

        }

        if (!empty($params['mobile'])) {
            // 用户手机号不为空
            $where['mobile like ?'] = '%' . $params['mobile'] . '%';
        }


        return $where;
    }


    /**
     * 查询总条数
     * @param array $params
     * @return int|mixed
     */
    public function count_by_where($params = [])
    {
        return $this->_d->count_by_where($params);
    }


    /**
     * 查询列表数据
     * @param array $params 查询参数
     * @param array $page_option 分页参数
     * @param string $fields 查询字段
     * @return array|bool
     */
    public function list_by_where($params = [], $page_option = [], $fields = '*')
    {

        return $this->_d->list_by_where($params, $page_option, $fields);
    }
}