123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php namespace App\Http\Controllers\Api;
- use App\Facades\Servers\WeiBan\OpenApi;
- use App\Http\Controllers\Api\Api;
- use App\Models\Custom as Model;
- use App\Models\WeiBan\Qrcode as WeiBanQrcode;
- use Vinkla\Hashids\Facades\Hashids;
- use App\Http\Requests\Api\Custom as Request;
- use App\Models\City;
- use App\Models\WeiBan\Follow as WeiBanFollow;
- use App\Models\CustomAmount;
- /**
- * 客户接口
- *
- * @author 刘相欣
- *
- * */
- class Custom extends Api{
-
-
- /**
- * 获取客户信息 /api/custom/get_info
- *
- * @param string $code 授权码
- *
- * */
- public function get_info(Model $Model,WeiBanQrcode $WeiBanQrcode,City $City,WeiBanFollow $WeiBanFollow,CustomAmount $CustomAmount){
- // 接口验签
- // $this->verify_sign();
- // 检查登录
- $uid = $this->checkLogin();
- // 查询用户
- $custom = $Model->getOne($uid);
- // 用户不存在
- if( empty($custom) ) return json_send(['code'=>'error','msg'=>'用户不存在','data'=>['error'=>'用户不存在']]);
- // 如果不存在微伴ID
- if( !$custom['weiban_extid'] ) {
- // 通过手机号查询注册的账号
- $custom['weiban_extid'] = (string) $WeiBanFollow->query()->where([['phone_number','=',$custom['phone']]])->value('weiban_extid');
- // 不存在,通过接口获取数据
- if( !$custom['weiban_extid'] ) {
- // 获取用户列表
- $userList = OpenApi::getUserListByPhone($custom['phone']);
- // 如果有的话
- if( $userList ) {
- // 获取第一个
- $extUser = array_shift($userList);
- // 获取对应的ID
- $custom['weiban_extid'] = empty($extUser['id']) ? '' : $extUser['id'];
- }
- }
- // 存在则修正
- if( $custom['weiban_extid'] ) $Model->edit($custom['uid'],['weiban_extid'=>$custom['weiban_extid']]);
- }
- // 头像
- $custom['uid'] = Hashids::encodeHex($custom['uid']);
- // 头像
- $custom['userpic'] = $custom['userpic'] ? path_compat($custom['userpic']) : '';
- // 手机号
- $custom['phone'] = hide_phone($custom['phone']);
- // 如果没有关联企微,获取二维码,已关联的不验证
- $followQrcode = $custom['weiban_extid'] ? ['thumb'=>'','link_url'=>''] : $WeiBanQrcode->getFollowQrcode($custom['city_id']);
- // 城市ID换城市名
- $cityName = (string) $City->getOne($custom['city_id'],'name');
- //获取用户余额
- $amountInfo = $CustomAmount::query()->where([['custom_id','=',$custom['uid']]])->first(['amount','transfer_amount']);
- if (!$amountInfo){
- $amountInfo = [
- 'amount'=>0,
- 'transfer_amount'=>0,
- ];
- }
- // 所需数组组合
- $custom = [
- 'uid'=>$custom['uid'],
- 'username'=>$custom['username'],
- 'userpic'=>$custom['userpic'],
- 'phone'=>$custom['phone'],
- 'is_manager'=>$custom['is_manager'],
- 'company_id'=>1, // 无需验证资质
- 'show_price'=>$cityName?1:0, // 是否选择了城市处理
- 'city_id'=>$cityName,
- 'follow_qrcode'=>$followQrcode['thumb'],
- 'follow_linkurl'=>$followQrcode['link_url'],
- 'amount'=>$amountInfo['amount'],
- 'transfer_amount'=>$amountInfo['transfer_amount'],
- ];
- // 返回结果
- return json_send(['code'=>'success','msg'=>'获取成功','data'=>$custom]);
- }
- /**
- * 设置信息 /api/custom/set_city
- *
- * @param string $code 授权码
- *
- * */
- public function set_city(Request $request,Model $Model,City $City){
- // 接口验签
- // $this->verify_sign();
- // 验证参数
- $request->scene('set_city')->validate();
- // 检查登录
- $uid = $this->checkLogin();
- // 接收参数
- $city = request('city','');
- // 通过城市名获取城市ID
- $cityId = $City->getIdByName($city);
- // 查询用户
- $result = $Model->edit($uid,['city_id'=>$cityId]);
- // 用户不存在
- if( !$result ) return json_send(['code'=>'error','msg'=>'保存失败','data'=>['error'=>'保存失败,请重试']]);
- // 返回结果
- return json_send(['code'=>'success','msg'=>'保存成功','data'=>['city_id'=>$cityId]]);
- }
- /**
- * 设置信息 /api/custom/get_city
- *
- * @param string $code 授权码
- *
- * */
- public function get_city(Request $request,Model $Model,City $City){
- // 接口验签
- // $this->verify_sign();
- // 验证参数
- $request->scene('get_city')->validate();
- // 检查登录
- $uid = $this->checkLogin();
- // 查询用户
- $custom = $Model->getOne($uid);
- // 用户不存在
- if( empty($custom) ) return json_send(['code'=>'success','msg'=>'获取成功','data'=>['province'=>'','city'=>'']]);
- // 获取城市ID
- $cityId = $custom['city_id'];
- $cityName = $City->getOne($cityId,'name');
- $pid = $City->getOne($cityId,'pid');
- $province = $City->getOne($pid,'name');
- // 返回结果
- return json_send(['code'=>'success','msg'=>'获取成功','data'=>['province'=>(string)$province,'city'=>(string)$cityName]]);
- }
- }
|