1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php namespace App\Http\Controllers\Api;
- use App\Http\Controllers\Api\Api;
- use App\Models\Custom as Model;
- use App\Models\Work\State as WorkState;
- use Vinkla\Hashids\Facades\Hashids;
- use App\Http\Requests\Api\Custom as Request;
- use App\Models\City;
- use App\Models\Work\External as WorkExternal;
- /**
- * 客户接口
- *
- * @author 刘相欣
- *
- * */
- class Custom extends Api{
-
-
- /**
- * 获取客户信息 /api/custom/get_info
- *
- * @param string $code 授权码
- *
- * */
- public function get_info(Model $Model,WorkState $WorkState,City $City,WorkExternal $WorkExternal){
- // 接口验签
- // $this->verify_sign();
- // 检查登录
- $uid = $this->checkLogin();
- // 查询用户
- $custom = $Model->getOne($uid);
- // 用户不存在
- if( empty($custom) ) return json_send(['code'=>'error','msg'=>'用户不存在','data'=>['error'=>'用户不存在']]);
- // 如果不存在企微ID,查询数据库
- if( !$custom['external_userid'] ) $custom['external_userid'] = (string) $WorkExternal->query()->where([['custom_uid', '=',$custom['uid']]])->value('external_userid');
- // 头像
- $custom['uid'] = Hashids::encodeHex($custom['uid']);
- // 头像
- $custom['userpic'] = $custom['userpic'] ? path_compat($custom['userpic']) : '';
- // 手机号
- $custom['phone'] = hide_phone($custom['phone']);
- // 如果没有关联企微,获取二维码,已关联的不验证
- $followQrcode = $custom['external_userid'] ? '' : $WorkState->getFollowQrcode($custom['city_id']);
- // 城市ID换城市名
- $cityId = (string) $City->getOne($custom['city_id'],'name');
- // 所需数组组合
- $custom = [
- 'uid'=>$custom['uid'],
- 'username'=>$custom['username'],
- 'userpic'=>$custom['userpic'],
- 'phone'=>$custom['phone'],
- 'company_id'=>1, // 无需验证资质
- 'show_price'=>$cityId?1:0, // 是否选择了城市处理
- 'city_id'=>$cityId,
- 'follow_qrcode'=>$followQrcode,
- 'follow_linkurl'=>'',
- ];
- // 返回结果
- 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]]);
- }
- }
|