multi-store/app/api/logic/user/UserLogic.php
2024-06-04 23:15:30 +08:00

94 lines
2.4 KiB
PHP

<?php
namespace app\api\logic\user;
use app\common\{logic\BaseLogic,
model\system_store\SystemStore,
model\user\User,
model\user\UserRecharge,
service\wechat\WeChatMnpService};
/**
* 会员逻辑层
* Class UserLogic
* @package app\shopapi\logic
*/
class UserLogic extends BaseLogic
{
/**
* @notes 获取小程序手机号
* @param array $params
* @return bool
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
* @author 段誉
* @date 2023/2/27 11:49
*/
public static function getMobileByMnp(array $params)
{
try {
$response = (new WeChatMnpService())->getUserPhoneNumber($params['code']);
$phoneNumber = $response['phone_info']['purePhoneNumber'] ?? '';
if (empty($phoneNumber)) {
throw new \Exception('获取手机号码失败');
}
$user = User::where([
['mobile', '=', $phoneNumber],
['id', '<>', $params['user_id']]
])->findOrEmpty();
if (!$user->isEmpty()) {
throw new \Exception('手机号已被其他账号绑定');
}
// 绑定手机号
User::update([
'id' => $params['user_id'],
'mobile' => $phoneNumber
]);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
public static function info($uid)
{
$data = User::where('id',$uid)
->field('avatar,real_name,nickname,account,mobile,sex,login_ip,user_money')
->find();
//判断是不是员工
if($data){
$data = $data->toArray();
$data['is_staff'] = 0;
$data['store_id'] = 0;
if(isset($data['mobile']) && $data['mobile']){
$check = SystemStore::where('phone',$data['mobile'])->find()??[];
if ($check){
$data['is_staff'] = 1;
$data['store_id'] = $check['store_id'];
}
}
}else{
$data = [];
}
return $data;
}
public static function recharge($param)
{
$param['order_id'] = getNewOrderId('rc');
$param['recharge_type'] = 'wechat';
return UserRecharge::create($param);
}
}