238 lines
6.9 KiB
PHP
238 lines
6.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2021-4-17
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
|
|
namespace app\modules\api\models;
|
|
|
|
|
|
use app\models\User;
|
|
use app\components\SiteHelper;
|
|
use app\models\UserInformation;
|
|
use app\models\UserLogoutReview;
|
|
use app\modules\api\components\ApiHelper;
|
|
use app\models\District;
|
|
|
|
|
|
class UserBasicInfoForm extends ApiModel
|
|
{
|
|
public $user_id;
|
|
|
|
public $cx_mch_id;
|
|
|
|
public $avatar_url;
|
|
public $gender;
|
|
public $city_id;
|
|
public $nickname;
|
|
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['avatar_url','nickname'], 'trim'],
|
|
[['avatar_url','nickname'], 'string'],
|
|
[['user_id', 'cx_mch_id', 'gender', 'city_id'], 'integer'],
|
|
[['user_id', 'cx_mch_id'], 'required'],
|
|
// [['avatar_url'], 'required', 'on' => 'avatar'],
|
|
[['gender'], 'in', 'range' => [0, 1, 2, 3]],
|
|
[['gender'], 'required', 'on' => 'gender'],
|
|
[['city_id'], 'required', 'on' => 'city'],
|
|
];
|
|
}
|
|
|
|
//用户信息
|
|
public function search()
|
|
{
|
|
if (!$this->validate()) {
|
|
return $this->getModelError();
|
|
}
|
|
$user = ApiHelper::findOneUser($this->user_id, $this->cx_mch_id);
|
|
if ($user == null) {
|
|
return [
|
|
'code' => 1,
|
|
'msg' => '用户不存在'
|
|
];
|
|
}
|
|
$data = [];
|
|
$data['user_id'] = $user->id;
|
|
$data['nickname'] = $user->nickname;
|
|
$data['avatar_url'] = SiteHelper::getFullUrl($user->avatar_url);
|
|
$data['gender'] = $user->gender;
|
|
$data['gender_cn'] = User::getGender($user->gender);
|
|
$data['is_modify_un'] = $user->is_modify_un == 1 ? true : false;
|
|
$data['type_cn'] = User::getType($user->type);
|
|
$data['is_bind_phone'] = $user->isBindPhone;
|
|
$data['is_view'] = $user->is_view;
|
|
$review = UserLogoutReview::findOne(['user_id' => $user->id,'status' => 0,'is_delete' => 0]);
|
|
$data['is_logout'] = $review == null ? 0 : 1;
|
|
return $this->apiReturnSuccess('ok', $data);
|
|
}
|
|
|
|
//修改头像
|
|
public function modify_avatar()
|
|
{
|
|
if (!$this->validate()) {
|
|
return $this->getModelError();
|
|
}
|
|
$user = ApiHelper::findOneUser($this->user_id, $this->cx_mch_id);
|
|
if ($user == null) {
|
|
return [
|
|
'code' => 1,
|
|
'msg' => '用户不存在'
|
|
];
|
|
}
|
|
$user->avatar_url = SiteHelper::getRelativeUrl($this->avatar_url);
|
|
/*$res = User::resizeAvatar($user->avatar_url);
|
|
if ($res['code'] != 0) {
|
|
return $res;
|
|
}*/
|
|
if (!$user->save())
|
|
return $this->getModelError($user);
|
|
return [
|
|
'code' => 0,
|
|
'msg' => '修改成功'
|
|
];
|
|
}
|
|
|
|
//修改昵称
|
|
public function modify_nickname()
|
|
{
|
|
if (!$this->validate()) {
|
|
return $this->getModelError();
|
|
}
|
|
$user = ApiHelper::findOneUser($this->user_id, $this->cx_mch_id);
|
|
if ($user == null) {
|
|
return [
|
|
'code' => 1,
|
|
'msg' => '用户不存在'
|
|
];
|
|
}
|
|
$user->nickname = $this->nickname;
|
|
if (!$user->save())
|
|
return $this->getModelError($user);
|
|
return [
|
|
'code' => 0,
|
|
'msg' => '修改成功'
|
|
];
|
|
}
|
|
|
|
//修改性别
|
|
public function modify_gender()
|
|
{
|
|
if (!$this->validate()) {
|
|
return $this->getModelError();
|
|
}
|
|
$user = ApiHelper::findOneUser($this->user_id, $this->cx_mch_id);
|
|
if ($user == null) {
|
|
return [
|
|
'code' => 1,
|
|
'msg' => '用户不存在'
|
|
];
|
|
}
|
|
$user->gender = $this->gender;
|
|
if (!$user->save())
|
|
return $this->getModelError($user);
|
|
return [
|
|
'code' => 0,
|
|
'msg' => '修改成功'
|
|
];
|
|
}
|
|
|
|
//修改城市
|
|
public function modify_city()
|
|
{
|
|
if (!$this->validate()) {
|
|
return $this->getModelError();
|
|
}
|
|
$user = ApiHelper::findOneUser($this->user_id, $this->cx_mch_id);
|
|
if ($user == null) {
|
|
return [
|
|
'code' => 1,
|
|
'msg' => '用户不存在'
|
|
];
|
|
}
|
|
$city = District::getDistrict($this->city_id);
|
|
if (!$city) {
|
|
return $this->apiReturnError("无效城市ID");
|
|
}
|
|
$user->city_id = $this->city_id;
|
|
if (!$user->save())
|
|
return $this->getModelError($user);
|
|
return [
|
|
'code' => 0,
|
|
'msg' => '修改成功'
|
|
];
|
|
}
|
|
|
|
public function find_video()
|
|
{
|
|
if (!$this->validate()) {
|
|
return $this->getModelError();
|
|
}
|
|
$user = ApiHelper::findOneUser($this->user_id, $this->cx_mch_id);
|
|
if ($user == null) {
|
|
return [
|
|
'code' => 1,
|
|
'msg' => '用户不存在'
|
|
];
|
|
}
|
|
$user->is_view = 1;
|
|
if (!$user->save()){
|
|
return $this->getModelError($user);
|
|
}
|
|
return [
|
|
'code' => 0,
|
|
'msg' => 'ok'
|
|
];
|
|
|
|
}
|
|
|
|
//申请注销
|
|
public function account_logout()
|
|
{
|
|
if (!$this->validate()) {
|
|
return $this->getModelError();
|
|
}
|
|
$user = UserLogoutReview::findOne(['user_id' => $this->user_id,'status' => 0,'is_delete' => 0]);
|
|
if($user != null){
|
|
return ['code' => 1,'msg' => '您已提交注销申请,等待管理员确认'];
|
|
}
|
|
$review = new UserLogoutReview();
|
|
$review->user_id = $this->user_id;
|
|
$review->status = 0;
|
|
$review->status_time = 0;
|
|
$review->content = '';
|
|
$review->is_delete = 0;
|
|
$review->created_at = time();
|
|
$review->updated_at = 0;
|
|
if(!$review->save()){
|
|
return ['code' => 1,'msg' => '提交注销申请失败'];
|
|
}
|
|
return ['code' => 0,'msg' => '已提交注销申请,等待管理员确认'];
|
|
|
|
}
|
|
|
|
public function account_logout_revocation()
|
|
{
|
|
if (!$this->validate()) {
|
|
return $this->getModelError();
|
|
}
|
|
$review = UserLogoutReview::findOne(['user_id' => $this->user_id,'status' => 0,'is_delete' => 0]);
|
|
if($review == null){
|
|
return ['code' => 1,'msg' => '未提交注销申请,无法撤销'];
|
|
}
|
|
$review->status = 3;
|
|
$review->updated_at = time();
|
|
if(!$review->save()){
|
|
return ['code' => 1,'msg' => '撤销注销申请失败'];
|
|
}
|
|
return ['code' => 0,'msg' => '成功撤销申请'];
|
|
}
|
|
} |