// +---------------------------------------------------------------------- namespace App\Services\Common; use App\Models\MemberModel; use App\Models\UserModel; use App\Services\BaseService; use Earnp\GoogleAuthenticator\GoogleAuthenticator; /** * 会员管理-服务类 * @author laravel开发员 * @since 2020/11/11 * Class MemberService * @package App\Services\Common */ class MemberService extends BaseService { // 静态对象 protected static $instance = null; /** * 构造函数 * @author laravel开发员 * @since 2020/11/11 * MemberService constructor. */ public function __construct() { $this->model = new MemberModel(); } /** * 静态入口 * @return static|null */ public static function make() { if (!self::$instance) { self::$instance = (new static()); } return self::$instance; } /** * 获取资料详情 * @param $where * @param array $field */ public function getInfo($where, array $field = []) { $field = $field ? $field : ['id', 'username', 'realname', 'credit','trade_password', 'nickname', 'openid', 'idcard', 'trc_address', 'erc_address', 'erc_hexaddress', 'source', 'idcard_check', 'idcard_front_img', 'idcard_back_img', 'idcard_hand_img','bank_front_img','bank_back_img','credit_score_img', 'safe_level', 'user_type', 'member_level', 'usdt_num', 'user_type', 'status', 'credit', 'avatar']; if (is_array($where)) { $info = $this->model->where($where)->select($field)->first(); } else { $info = $this->model->where(['id' => (int)$where])->select($field)->first(); } $info = $info ? $info->toArray() : []; if ($info) { $info['avatar'] = $info['avatar'] ? get_image_url($info['avatar']) : ''; $info['idcard_front_img'] = $info['idcard_front_img'] ? get_image_url($info['idcard_front_img']) : ''; $info['idcard_back_img'] = $info['idcard_back_img'] ? get_image_url($info['idcard_back_img']) : ''; $info['usdt_num'] = isset($info['usdt_num']) ? moneyFormat($info['usdt_num'], 4) : '0.0000'; $bond = UserModel::where(['user_id'=> $info['id']])->value('bond'); $info['bond'] = moneyFormat($bond, 2); // 收款二维码 $qrcode = \App\Services\Api\MemberService::make()->makeQrcode($info['trc_address']); $info['trc_qrcode'] = $qrcode? get_image_url($qrcode) : ''; $ercQrcode = \App\Services\Api\MemberService::make()->makeQrcode($info['erc_hexaddress']); $info['erc_qrcode'] = $ercQrcode? get_image_url($ercQrcode) : ''; // 谷歌验证码 $info['google_qrcode'] = ''; $googleSecret = UserModel::where(['user_id'=> $info['id']])->value('google_secret'); if(empty($googleSecret)){ $google = GoogleAuthenticator::CreateSecret(); $googleSecret = isset($google['secret'])? $google['secret'] : ''; UserModel::where(['user_id'=> $info['id']])->update(['google_secret'=>$googleSecret]); } if($googleSecret){ $url = "otpauth://totp/".'otc168('.$info['username'].")?secret=".$googleSecret; $googleQrcode = \App\Services\Api\MemberService::make()->makeQrcode($url); $info['google_qrcode'] = $googleQrcode? get_image_url($googleQrcode) : ''; } } return $info; } /** * 获取承兑商 * @return mixed */ public function getBusiness() { $params = request()->all(); $list = $this->model->where(['status'=> 1,'mark'=>1,'user_type'=> 2]) ->where(function($query) use($params){ $keyword = isset($params['keyword'])? trim($params['keyword']) : ''; if($keyword){ $query->where('username','like',"%{$keyword}%"); } $userId = isset($params['user_id'])? $params['user_id'] : 0; if($userId){ $query->whereNotIn('id',[$userId]); } }) ->select(['id','username']) ->take(100) ->orderBy('id','desc') ->get(); return $list; } /** * 获取接口注册的用户 * @param $apiId * @param int $userType * @return mixed */ public function getCountByApi($apiId, $userType=0) { $where = ['api_id'=> $apiId,'status'=> 1,'mark'=>1]; if($userType){ $where['user_type'] = $userType; } return $this->model->where($where) ->whereIn('user_type',[3,5]) ->count('id'); } /** * 添加会编辑会员 * @return array * @since 2020/11/11 * @author laravel开发员 */ public function edit() { // 请求参数 $data = request()->all(); // 头像处理 $avatar = isset($data['avatar'])? trim($data['avatar']) : ''; if ($avatar && strpos($avatar, "temp")) { $data['avatar'] = save_image($avatar, 'member'); } else if($avatar){ $data['avatar'] = str_replace(IMG_URL, "", $data['avatar']); } // 出生日期 if ($data['birthday']) { $data['birthday'] = strtotime($data['birthday']); } // 登录密码 if ($data['password']) { $data['password'] = get_password($data['password'] . $data['username']); } // 城市处理 $city = isset($data['city']) ? $data['city'] : [3]; if (!empty($data['city'])) { // 省份 $data['province_id'] = $city[0]; // 城市 $data['city_id'] = $city[1]; // 县区 $data['district_id'] = $city[2]; } $id = isset($data['id'])? $data['id'] : 0; if($id && $this->model->where(['id'=> $id])->value('trade_password')){ $data['safe_level'] = 2; } if(isset($data['idcard_check']) && $data['idcard_check']==1){ $safeLevel = isset($data['safe_level'])? isset($data['safe_level']) : 2; $data['safe_level'] = $safeLevel==2? 3 : $safeLevel; } unset($data['city']); return parent::edit($data); // TODO: Change the autogenerated stub } }