<?php
/**
 * 用户管理Model
 * Created by PhpStorm.
 * User: 小威
 * Date: 2020/03/28
 * Time: 14:33
 */

namespace JinDouYun\Model\Manage;

use Exception;

use Mall\Framework\Core\ErrorCode;
use Mall\Framework\Core\StatusCode;
use Mall\Framework\Core\ResultWrapper;

use JinDouYun\Dao\UserCenter\DUserCenter;
use JinDouYun\Dao\Enterprise\DUserBindEnterprise;

class MUser
{
    protected $objDUser;
    protected $objDUserBindEnterprise;


    public function __construct()
    {
        $this->objDUser = new DUserCenter('default');
        $this->objDUserBindEnterprise = new DUserBindEnterprise('default');

    }

    /**
     * 用户列表
     * @param $params
     * @return ResultWrapper
     */
    public function getAllUser($params)
    {
        $where = ['isCustomer' => StatusCode::$customerType['user']];
        $dbResult = $this->objDUser->select($where, 'id,mobile,deleteStatus', 'id desc', $params['limit'] , $params['offset']);
        if($dbResult === false){
            return ResultWrapper::fail($this->objDUser->error(), ErrorCode::$dberror);
        }
        $total = $this->objDUser->count($where);

        $returnDta = [
            'total' => $total ? $total : 0,
            'data' => $dbResult,
        ];
        return ResultWrapper::success($returnDta);
    }
}
