Files
2021-07-05 09:56:27 +08:00

244 lines
6.3 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: xuxb
* Date: 2020/9/29
* Time: 16:09
*/
class User_service extends HD_Service{
protected $app_id;
protected $app_user_model;
public $model;
public function __construct($params = array())
{
parent::__construct();
$params && $this->init($params);
}
public function init($params){
$app_id = $params['app_id'];
$this->app_id = $app_id;
$this->log_dir = lcfirst(get_class($this)) . $this->app_id;
switch($app_id){
case 1:
$this->load->model('app/liche/app_liche_users_model');
$this->app_user_model = $this->app_liche_users_model;
break;
}
}
/**
* 获取马甲列表
* @param int $page
* @param int $size
* @return array {"total":1, "list":[{"id":1, "title":"明"}]}
*/
public function majia($page = 0, $size = 0){
$total = 0;
$list = array();
switch($this->app_id){
case 1://尚柏卡
case 3://飞鱼
$where = array(
'group_id' => 4,
'status >=' => 0,
);
$total = $this->app_user_model->count($where);
if($total){
$select = 'id, nickname as title';
$list = $this->app_user_model->select($where, 'id DESC', $page, $size, $select);
}
break;
}
return array('total' => $total, 'list' => $list);
}
/**
* 获取用户信息
* @param $uid
* @return mixed
*/
public function info($uid){
return $this->app_user_model->get(array('id' => $uid));
}
/**
* 数量
* @param array $where
* @param string $distinct
* @return mixed
*/
public function count($where = array(), $distinct = ''){
return $this->app_user_model->count($where, $distinct);
}
/*
* 列表
* @param array $where
* @param string $order
* @param int $page
* @param int $size
* @param string $select
* @return mixed
*/
public function select($where = array(), $order = '', $page = 0, $size = 20, $select = ''){
return $this->app_user_model->select($where, $order, $page, $size, $select);
}
/*
* 列表
* @param array $where
* @param string $order
* @param int $page
* @param int $size
* @param string $select
* @return mixed
*/
public function select_wechat($where = array(), $order = '', $page = 0, $size = 20, $select = ''){
return $this->app_user_model->select_wechat($where, $order, $page, $size, $select);
}
/**
* @param string $map_key
* @param string $map_value
* @param array $where
* @param string $order
* @param int $page
* @param int $size
* @param string $select
* @return mixed
*/
public function map($map_key = 'id', $map_value = '', $where = array(), $order = '', $page = 0, $size = 20, $select = ''){
return $this->app_user_model->map($map_key, $map_value, $where, $order, $page, $size, $select);
}
/**
* 联表微信服务
* @param string $map_key
* @param string $map_value
* @param array $where
* @param string $order
* @param int $page
* @param int $size
* @param string $select
* @return array
*/
public function map_wechat($map_key = 'id', $map_value = '', $where = array(), $order = '', $page = 0, $size = 20, $select = ''){
$map = array();
$list = $this->select_wechat($where, $order, $page, $size, $select);
if($list)
{
foreach($list as $item)
{
//指定列, map格式为{k:v}
if($map_value)
{
//指定列存在取具体值,格式为{k:v},指定列不存在取全部列,格式为{k:{k1:v1,k2:v2}}
$map[$item[$map_key]] = null !== $item[$map_value] ? $item[$map_value] : $item;
}
else
{//不指定列,表示一个k对应多个v,格式为{k:[{k1:v1,k2:v2},{k1:v1,k2:v2}]}
$map[$item[$map_key]][] = $item;
}
}
}
return $map;
}
/**
* 获取用户信息
* @param $where
* @param string $select
* @return mixed
*/
public function get($where, $select = ''){
return $this->app_user_model->get($where, $select);
}
/**
* 更新用户信息
* @param $data
* @param $where
* @return mixed
*/
function update($data, $where){
$ret = $this->app_user_model->update($data, $where);
if(is_bool($ret)){
debug_log("[error]# ret={$ret};" . $this->app_user_model->db->last_query(), __FUNCTION__, $this->log_dir);
}
return $ret;
}
/**
* 新增
* @param $data
* @return mixed
*/
function add($data){
return $this->app_user_model->add($data);
}
/**
* 删除
* @param $where
* @return mixed
*/
function delete($where){
return $this->app_user_model->delete($where);
}
/**
* 手机号是否在黑名单内
* @param $mobile
* @return bool
*/
function is_black($mobile){
$cache_dir = APPPATH. '../admin/cache';
if (!file_exists($cache_dir)) {
debug_log("[error] ". __FUNCTION__ . "# {$cache_dir} not exist", $this->log_file);
return false;
}
$filename = "moblack_{$this->app_id}.txt";
$cache_dir = $cache_dir . '/';
if (!$filename) {
$filename = $cache_dir;
} else {
$filename = $cache_dir . $filename;
}
if (!file_exists($filename)) {
$oldumask = umask(0);
touch($filename);
chmod($filename, 0666);
umask($oldumask);
}
$res = file_get_contents($filename);
$blacks = $res ? json_decode($res, true) : array();
if(in_array($mobile, $blacks)){
return true;
}
return false;
}
/**
* 返回最后的sql
* @return mixed
*/
function last_query(){
return $this->app_user_model->db->last_query();
}
}