You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
2.8 KiB
114 lines
2.8 KiB
<?php
|
|
|
|
namespace app\base\model\user;
|
|
|
|
use app\base\model\Base;
|
|
use app\distribution\model\DistributionCommissionMy;
|
|
use app\integral\model\IntegralMy;
|
|
use app\money\model\MoneyMy;
|
|
use think\model\concern\SoftDelete;
|
|
|
|
|
|
class User extends Base
|
|
{
|
|
|
|
use SoftDelete;
|
|
|
|
// 设置当前模型对应的完整数据表名称
|
|
protected $table = 'base_user';
|
|
|
|
/**
|
|
* 通过USER_ID获取USER
|
|
* @param string $mobile_phone 手机号
|
|
* @param string $field
|
|
* @date 2021-03-01
|
|
*/
|
|
public function getUserByMobliePhone($mobile_phone, $field = 'id,mobile_phone')
|
|
{
|
|
return $this->getOneData([
|
|
['mobile_phone', '=', $mobile_phone],
|
|
['status', '<>', 3] //没有注销
|
|
], $field);
|
|
}
|
|
|
|
/**
|
|
* 通过mobile_phone更新user表
|
|
* @param string $data 需要更新的数据
|
|
* @date 2022-03-25
|
|
*/
|
|
public function updateUser($data)
|
|
{
|
|
$where = [
|
|
['mobile_phone', '=', $data['mobile_phone']],
|
|
['status', '<>', 3] //没有注销
|
|
];
|
|
$id = $this->getOneData($where, 'id');
|
|
|
|
if (!empty($id)) {
|
|
$data['id'] = $id;
|
|
}
|
|
|
|
$user_id = $this->dataUpdate($data);
|
|
|
|
return [
|
|
'user_id' => $user_id,
|
|
'type' => empty($id) ? 1 : 2
|
|
];
|
|
}
|
|
|
|
/*
|
|
* @date 2021-03-01
|
|
*/
|
|
public function getOneUser($where = [], $field = '*', $order = '')
|
|
{
|
|
$primary_key_name = $this->getPk();
|
|
|
|
if (empty($order)) {
|
|
$order = (empty($data[$primary_key_name]) ? 'id' : $data[$primary_key_name]) . ' desc';
|
|
}
|
|
|
|
$array = explode(',', $field);
|
|
if ($field != '*') {
|
|
if (count($array) <= 1) {
|
|
return $this->with(['userInfo'])->where($where)->order($order)->value($field);
|
|
} else {
|
|
return $this->with(['userInfo'])->field($field)->where($where)->order($order)->find();
|
|
}
|
|
} else {
|
|
return $this->with(['userInfo'])->where($where)->order($order)->find();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 头像昵称
|
|
*/
|
|
public function userInfo()
|
|
{
|
|
return $this->hasOne(UserInfo::class, 'user_id', 'id')->bind(['head_img', 'nick_name', 'gender', 'birth_day', 'sign', 'gender_text']);
|
|
}
|
|
|
|
/**
|
|
* 用户当前余额
|
|
*/
|
|
public function userMoney()
|
|
{
|
|
return $this->hasOne(MoneyMy::class, 'user_id', 'id')->bind(['money']);
|
|
}
|
|
|
|
/**
|
|
* 用户当前佣金
|
|
*/
|
|
public function userCommission()
|
|
{
|
|
return $this->hasOne(DistributionCommissionMy::class, 'user_id', 'id')->bind(['commission']);
|
|
}
|
|
|
|
/**
|
|
* 用户当前积分
|
|
*/
|
|
public function userIntegral()
|
|
{
|
|
return $this->hasOne(IntegralMy::class, 'user_id', 'id')->bind(['integral']);
|
|
}
|
|
}
|