初始化
缺陷:主题配色需要优化整体的同风格
This commit is contained in:
67
app/Service/wx/WxUserCenterService.php
Normal file
67
app/Service/wx/WxUserCenterService.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\wx;
|
||||
|
||||
use App\BaseApp\BaseWxService;
|
||||
use App\Models\business\ListModel;
|
||||
use App\Models\business\OrderModel;
|
||||
use App\Models\business\WxUserModel;
|
||||
|
||||
/**
|
||||
* 小程序「我的」
|
||||
*/
|
||||
class WxUserCenterService extends BaseWxService
|
||||
{
|
||||
/**
|
||||
* 我的信息 + 清单/订单计数
|
||||
*/
|
||||
public function myInfo(): array
|
||||
{
|
||||
$listCount = ListModel::where('user_id', $this->userId)->where('deleted_at', 0)->count();
|
||||
$orderCount = OrderModel::where('user_id', $this->userId)->where('deleted_at', 0)->count();
|
||||
$user = WxUserModel::with('enterprise')->where('id', $this->userId)->first();
|
||||
$user = $user ? $user->toArray() : $this->userInfo;
|
||||
unset($user['session_key']);
|
||||
return [
|
||||
'count' => $listCount,
|
||||
'order_count' => $orderCount,
|
||||
'user' => $user,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定手机号
|
||||
*
|
||||
* 优先用微信手机号快速验证的 code 换真实号码(用户填的可能是假号);
|
||||
* 只有客户端拿不到 code 时才退回直接写入。
|
||||
*/
|
||||
public function bandPhone(array $params): array
|
||||
{
|
||||
$phone = trim((string) ($params['phone'] ?? ''));
|
||||
$phoneCode = trim((string) ($params['phone_code'] ?? ''));
|
||||
if ($phoneCode !== '') {
|
||||
$phone = WxMiniService::getInstance()->getPhoneNumber($phoneCode);
|
||||
}
|
||||
if ($phone === '') {
|
||||
$this->utils->errorThrow('手机号不能为空');
|
||||
}
|
||||
WxUserModel::where('id', $this->userId)->update([
|
||||
'phone' => $phone,
|
||||
'updated_at' => time(),
|
||||
]);
|
||||
return ['phone' => $phone];
|
||||
}
|
||||
|
||||
public function updateNickName(string $nickName): array
|
||||
{
|
||||
$nickName = trim($nickName);
|
||||
if ($nickName === '') {
|
||||
$this->utils->errorThrow('昵称不能为空');
|
||||
}
|
||||
WxUserModel::where('id', $this->userId)->update([
|
||||
'nick_name' => $nickName,
|
||||
'updated_at' => time(),
|
||||
]);
|
||||
return ['nick_name' => $nickName];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user