Custom.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php namespace App\Http\Controllers\Api;
  2. use App\Http\Controllers\Api\Api;
  3. use App\Models\Custom as Model;
  4. use App\Models\WeiBan\Qrcode as WeiBanQrcode;
  5. use Vinkla\Hashids\Facades\Hashids;
  6. use App\Http\Requests\Api\Custom as Request;
  7. use App\Models\City;
  8. /**
  9. * 客户接口
  10. *
  11. * @author 刘相欣
  12. *
  13. * */
  14. class Custom extends Api{
  15. /**
  16. * 获取客户信息 /api/custom/get_info
  17. *
  18. * @param string $code 授权码
  19. *
  20. * */
  21. public function get_info(Model $Model,WeiBanQrcode $WeiBanQrcode){
  22. // 接口验签
  23. // $this->verify_sign();
  24. // 检查登录
  25. $uid = $this->checkLogin();
  26. // 查询用户
  27. $custom = $Model->getOne($uid);
  28. // 用户不存在
  29. if( empty($custom) ) return json_send(['code'=>'error','msg'=>'用户不存在','data'=>['error'=>'用户不存在']]);
  30. // 头像
  31. $custom['uid'] = Hashids::encodeHex($custom['uid']);
  32. // 头像
  33. $custom['userpic'] = $custom['userpic'] ? path_compat($custom['userpic']) : '';
  34. // 手机号
  35. $custom['phone'] = hide_phone($custom['phone']);
  36. // 所需数组组合,如果没有关联企微,获取二维码,已添加好友的不验证
  37. $custom = [
  38. 'uid'=>$custom['uid'],
  39. 'username'=>$custom['username'],
  40. 'userpic'=>$custom['userpic'],
  41. 'phone'=>$custom['phone'],
  42. 'company_id'=>1, // 无需验证资质
  43. 'show_price'=>($custom['weiban_extid']?1:0), // 用于判断是否显示价格
  44. 'city_id'=>$custom['city_id'],
  45. 'follow_qrcode'=>($custom['weiban_extid'] ? '' : $WeiBanQrcode->getFollowQrcode())
  46. ];
  47. // 返回结果
  48. return json_send(['code'=>'success','msg'=>'获取成功','data'=>$custom]);
  49. }
  50. /**
  51. * 设置信息 /api/custom/set_city
  52. *
  53. * @param string $code 授权码
  54. *
  55. * */
  56. public function set_city(Request $request,Model $Model,City $City){
  57. // 接口验签
  58. // $this->verify_sign();
  59. // 验证参数
  60. $request->scene('set_city')->validate();
  61. // 检查登录
  62. $uid = $this->checkLogin();
  63. // 接收参数
  64. $city = request('city','');
  65. // 通过城市名获取城市ID
  66. $cityId = $City->getIdByName($city);
  67. // 查询用户
  68. $result = $Model->edit($uid,['city_id'=>$cityId]);
  69. // 用户不存在
  70. if( !$result ) return json_send(['code'=>'error','msg'=>'保存失败','data'=>['error'=>'保存失败,请重试']]);
  71. // 返回结果
  72. return json_send(['code'=>'success','msg'=>'保存成功','data'=>['city_id'=>$cityId]]);
  73. }
  74. }