504 lines
18 KiB
PHP
504 lines
18 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2021-4-17
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
|
|
namespace app\modules\api\models;
|
|
|
|
|
|
use app\components\Oss;
|
|
use app\models\Level;
|
|
use app\models\Store;
|
|
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;
|
|
use yii\data\Pagination;
|
|
|
|
|
|
class UserBasicInfoForm extends ApiModel
|
|
{
|
|
public $user_id;
|
|
|
|
public $cx_mch_id;
|
|
|
|
public $avatar_url;
|
|
public $gender;
|
|
public $city_id;
|
|
public $nickname;
|
|
|
|
public $birthday;
|
|
|
|
public $pid;
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['avatar_url', 'nickname'], 'trim'],
|
|
[['avatar_url', 'nickname'], 'string'],
|
|
[['user_id', 'cx_mch_id', 'gender', 'city_id', 'pid'], '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'],
|
|
[['avatar_url', 'gender', 'birthday'], 'required', 'on' => 'info'],
|
|
[['user_id', 'cx_mch_id'], 'required', 'on' => 'recharge_remind_minute'],
|
|
];
|
|
}
|
|
|
|
//用户信息
|
|
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' => '用户不存在'
|
|
];
|
|
}
|
|
$account_balance = empty($user->balance) ? 0 : $user->balance->account_balance;
|
|
$account_balance_with = empty($user->balance) ? 0 : $user->balance->account_balance_with;
|
|
|
|
$account_balance_freeze = sprintf('%.2f', $account_balance - $account_balance_with);
|
|
$account_integral = empty($user->integral) ? 0 : $user->integral->account_integral;
|
|
$account_integral_floor = substr(sprintf("%.3f", $account_integral), 0, -1);
|
|
$account_integral = floor($account_integral);
|
|
$account_balance = substr(sprintf("%.3f", $account_balance), 0, -1);
|
|
$account_balance_with = substr(sprintf("%.3f", $account_balance_with), 0, -1);
|
|
|
|
|
|
$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;
|
|
$data['mobile_phone'] = $user->mobile_phone;
|
|
$data['birthday'] = $user->birthday;
|
|
$review = UserLogoutReview::findOne(['user_id' => $user->id, 'status' => 0, 'is_delete' => 0]);
|
|
$data['is_logout'] = $review == null ? 0 : 1;
|
|
$data['account_balance'] = $account_balance;//账户余额
|
|
$data['account_balance_with'] = $account_balance_with;//可提现金额
|
|
$data['account_balance_freeze'] = $account_balance_freeze <= 0 ? 0 : $account_balance_freeze;//冻结金额
|
|
$data['account_integral'] = $account_integral;//积分账户:整数,[首页、我的]页面使用
|
|
$data['account_integral_floor'] = $account_integral_floor;//积分账户:浮点型,[订单、积分明细]页面使用
|
|
$data['level'] = Level::getUserLevel($user);
|
|
$data['level_id'] = $user->level_id;
|
|
$data['is_up_img'] = ($user->avatar_url == '/statics/images/avatar.jpg') ? 1 : 2; # 判断是否为更新过的操作
|
|
// 获取上级用户
|
|
$data['up_user'] = (object)[];
|
|
|
|
if(!empty($this->pid) && empty($user->parent_id) && $user->id !== $this->pid){
|
|
// 存在上级
|
|
$user->parent_id = $this->pid;
|
|
$user->save();
|
|
}
|
|
$data['t'] = [
|
|
'pid' => $this->pid,
|
|
'parent_id' => $user->parent_id,
|
|
'r' => !empty($this->pid) && empty($user->parent_id) && $user->id !== $this->pid,
|
|
];
|
|
if (!empty($user->parent_id)) {
|
|
$up_user = User::findOne([
|
|
'id' => $user->parent_id,
|
|
]);
|
|
$data['up_user'] = [
|
|
'id' => $up_user->id,
|
|
'nickname' => $up_user->nickname,
|
|
'avatar_url' => SiteHelper::getFullUrl($up_user->avatar_url),
|
|
'mobile_phone' => $up_user->mobile_phone,
|
|
];
|
|
}
|
|
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' => '成功撤销申请'];
|
|
}
|
|
|
|
public function modify_info()
|
|
{
|
|
|
|
if (!$this->validate()) {
|
|
return $this->getModelError();
|
|
}
|
|
$user = ApiHelper::findOneUser($this->user_id, $this->cx_mch_id);
|
|
if ($user == null) {
|
|
return [
|
|
'code' => 1,
|
|
'msg' => '用户不存在'
|
|
];
|
|
}
|
|
if (!empty($this->avatar_url)) {
|
|
$user->avatar_url = SiteHelper::getRelativeUrl($this->avatar_url);
|
|
}
|
|
if (!empty($this->gender)) {
|
|
$user->gender = $this->gender;
|
|
}
|
|
if (!empty($this->birthday)) {
|
|
$user->birthday = $this->birthday;
|
|
}
|
|
if (!empty($this->nickname)) {
|
|
$user->nickname = $this->nickname;
|
|
}
|
|
if (!$user->save())
|
|
return $this->getModelError($user);
|
|
return [
|
|
'code' => 0,
|
|
'msg' => '修改成功'
|
|
];
|
|
}
|
|
|
|
//充值弹框提醒
|
|
public function recharge_remind_minute()
|
|
{
|
|
if (!$this->validate()) {
|
|
return $this->getModelError();
|
|
}
|
|
$rechargeRemindMinute = SiteHelper::getCustomiseOptionByKey("rechargeRemindMinute", "hump");
|
|
if (empty($rechargeRemindMinute) || $rechargeRemindMinute <= 0) {
|
|
return ['code' => 0, 'msg' => '无需弹框'];
|
|
}
|
|
$rechargeRemindMinute = ceil($rechargeRemindMinute * 60);
|
|
$user = ApiHelper::findOneUser($this->user_id, $this->cx_mch_id);
|
|
if ($user == null) {
|
|
return ['code' => 1, 'msg' => '用户异常'];
|
|
}
|
|
$redis = \Yii::$app->redis;
|
|
$key = "api:cxaibc:user:remind:recharge" . $user->id;
|
|
$value = $redis->get($key);
|
|
if (($value + $rechargeRemindMinute) >= time()) {
|
|
return ['code' => 0, 'msg' => '无需弹框'];
|
|
}
|
|
|
|
$level = Level::find()->select('id,name,recharge_number,discount')
|
|
->where(['status' => 1])
|
|
->orderBy(['id' => SORT_ASC])
|
|
->asArray()
|
|
->all();
|
|
if (empty($level) || $user->level_id == 3) {
|
|
return ['code' => 0, 'msg' => '会员未设置'];
|
|
}
|
|
|
|
$lock1 = SiteHelper::getFullUrl(Level::LOCK_V1);
|
|
$lock2 = SiteHelper::getFullUrl(Level::LOCK_V2);
|
|
$lock3 = SiteHelper::getFullUrl(Level::LOCK_V3);
|
|
|
|
$pic1 = SiteHelper::getFullUrl(Level::PIC_V1);
|
|
|
|
$pic2_1 = SiteHelper::getFullUrl(Level::PIC_V2_1);
|
|
$pic2_2 = SiteHelper::getFullUrl(Level::PIC_V2_2);
|
|
|
|
$pic3_1 = SiteHelper::getuFllUrl(Level::PIC_V3_1);
|
|
$pic3_2 = SiteHelper::getFullUrl(Level::PIC_V3_2);
|
|
$pic3_3 = SiteHelper::getFullUrl(Level::PIC_V3_3);
|
|
|
|
$discount_cn1 = 100 - $level[0]['discount'];
|
|
$discount_cn2 = 100 - $level[1]['discount'];
|
|
$discount_cn3 = 100 - $level[2]['discount'];
|
|
|
|
$levelDetails = SiteHelper::getCustomiseOptionByKey("levelDetails", "hump");
|
|
$levelDetails = SiteHelper::repairContent($levelDetails);
|
|
|
|
$level_data = [
|
|
['pic' => $lock1, 'name' => '见习会员', 'subheading' => '尊享' . $discount_cn1 . '折优惠', 'desc' => '升至见习会员可解锁'],
|
|
['pic' => $lock2, 'name' => '进阶会员', 'subheading' => '尊享' . $discount_cn2 . '折优惠', 'desc' => '升至进阶会员可解锁'],
|
|
['pic' => $lock3, 'name' => '高阶会员', 'subheading' => '尊享' . $discount_cn3 . '折优惠', 'desc' => '升至高阶会员可解锁'],
|
|
];
|
|
|
|
if ($user->level_id == 1) {
|
|
$level_data[0]['pic'] = $pic1;
|
|
$level_data[0]['desc'] = '';
|
|
}
|
|
if ($user->level_id == 2) {
|
|
$level_data[0]['pic'] = $pic2_1;
|
|
$level_data[0]['desc'] = '';
|
|
$level_data[1]['pic'] = $pic2_2;
|
|
$level_data[1]['desc'] = '';
|
|
}
|
|
|
|
$data['level_data'] = $level_data;
|
|
$data['levelDetails'] = $levelDetails;
|
|
$redis->set($key, time());
|
|
return ['code' => 0, 'msg' => 'ok', 'data' => $data];
|
|
}
|
|
|
|
|
|
/**
|
|
* showdoc
|
|
* @catalog 用户信息
|
|
* @title 获取分销列表
|
|
* @description 获取分销列表
|
|
*/
|
|
public function actionUserNextList($page, $limit)
|
|
{
|
|
$query = User::find()
|
|
->where([
|
|
'is_delete' => 0,
|
|
'parent_id' => $this->user_id,
|
|
]);
|
|
$query = $query->select('id,nickname,avatar_url,mobile_phone,created_at');
|
|
$count_query = clone $query;
|
|
$count = $count_query->count();
|
|
$pagination = new Pagination(['pageSize' => $limit, 'totalCount' => $count, 'page' => $page - 1]);
|
|
$list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['id' => SORT_DESC])->asArray()->all();
|
|
$id = 0;
|
|
foreach ($list as $index => $item) {
|
|
$list[$index]['created_at_cn'] = date('Y/m/d H:i:s', $item['created_at']);
|
|
$list[$index]['avatar_url'] = SiteHelper::getFullUrl($item['avatar_url']);
|
|
}
|
|
//是否已经全部加载
|
|
$end_flag = $page > $pagination->pageCount ? true : false;
|
|
return [
|
|
'code' => 0,
|
|
'msg' => 'ok',
|
|
'data' => $list,
|
|
'count' => $count,
|
|
'page_size' => $limit,
|
|
'page_count' => $pagination->pageCount,
|
|
'page_no' => $page,
|
|
'end_flag' => $end_flag,
|
|
];
|
|
}
|
|
|
|
public function getDistribution()
|
|
{
|
|
try {
|
|
$store = Store::findOne(['id' => \Yii::$app->user->identity->store_id]);
|
|
$province = $store->province == '' ? '' : $store->province;
|
|
$city = $store->city == '' ? '' : $store->city;
|
|
$region = $store->region == '' ? '' : $store->region;
|
|
$location_detail = $store->location_detail == '' ? '' : $store->location_detail;
|
|
|
|
$distributionPoster = SiteHelper::getCustomiseOptionByKey("distributionPoster", "hump");
|
|
if (!is_array($distributionPoster)) {
|
|
$distributionPoster = json_decode($distributionPoster, true);
|
|
foreach ($distributionPoster as &$item) {
|
|
$item = substr($item, 0, 7) == 'http://' ? $item : SiteHelper::getFullUrl($item);
|
|
// $item = SiteHelper::getFullUrl($item);
|
|
}
|
|
}
|
|
$data['distributionPoster'] = $distributionPoster;
|
|
$data['address'] = $province . $city . $region . $location_detail;
|
|
$data['phone'] = $store->store_mobile;
|
|
$data['site_name'] = SiteHelper::getCustomiseOptionByKey("siteName", "hump");
|
|
|
|
$path = 'wxqrcode/distribution_qrcode';
|
|
if (!is_dir(\Yii::$app->basePath . "/web/" . $path)) {
|
|
mkdir(\Yii::$app->basePath . "/web/" . $path, 0777, true);
|
|
}
|
|
$body['path'] = "pages/index/index?id={$this->user_id}";
|
|
$body['is_hyaline'] = true;
|
|
$body = json_encode($body);
|
|
$json_body = md5($body);
|
|
$path .= '/' . $json_body . '.png';
|
|
|
|
$oss = new Oss();
|
|
|
|
if (file_exists(\Yii::$app->basePath . "/web/" . $path)) {
|
|
$path = $oss->upload(\Yii::$app->basePath . "/web/" . $path);
|
|
$data['qrcode_path'] = $path == false ? SiteHelper::getFullUrl($path) : $path;
|
|
return ['code' => 0, 'msg' => 'ok', 'data' => $data];
|
|
}
|
|
$plugin = new \app\models\common\PluginService();
|
|
$wxmpService = $plugin->getWxmpService(0);
|
|
$accessToken = $wxmpService->getAccessToken();
|
|
if (empty($accessToken)) {
|
|
$accessToken = $wxmpService->getAccessToken(true);
|
|
}
|
|
$res = $wxmpService->Qrcode->getWxappQrcodeLong($accessToken, $body);
|
|
if (json_encode($res) !== false) {
|
|
$res = json_decode($res, true);
|
|
return ['code' => 1, 'msg' => $res['errmsg']];
|
|
}
|
|
$file = fopen(\Yii::$app->basePath . "/web/" . $path, "w");//打开文件准备写入
|
|
fwrite($file, $res);//写入,$res为图片二进制内容
|
|
fclose($file);//关闭
|
|
//图片是否存在
|
|
if (!file_exists(\Yii::$app->basePath . "/web/" . $path)) {
|
|
return ['code' => 1, 'msg' => '生成二维码失败'];
|
|
}
|
|
$oss_path = $oss->upload(\Yii::$app->basePath . "/web/" . $path);
|
|
$data['qrcode_path'] = $oss_path == false ? SiteHelper::getFullUrl($path) : $oss_path;
|
|
$data['user_id'] = $this->user_id;
|
|
|
|
return ['code' => 0, 'msg' => 'ok', 'data' => $data];
|
|
} catch (\Exception $e) {
|
|
return ['code' => 1, 'msg' => $e->getMessage()];
|
|
}
|
|
}
|
|
} |