Device.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\api\controller\tvuser;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 健康档案设备数据,使用自动注册的用户
  7. */
  8. class Device extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['*'];
  12. public function index(){
  13. $ids = Db::name('user')->where('tv_userid',$this->auth->tv_userid)->column('id');//自动注册的用户 和 app注册并绑定盒子的app用户,理论上只需要第二个
  14. $device_number = Db::name('user_device')->where('user_id','IN',$ids)->count('sn');//两个用户绑定的设备号
  15. $result = [
  16. 'device_number' => $device_number,
  17. 'text_1' => config('site.tv_device_index_text1'),
  18. 'text_2' => config('site.tv_device_index_text2'),
  19. 'qrcode' => localpath_to_netpath(config('site.tv_device_index_image')),
  20. 'device' => [
  21. ['type_id' => 1,'type' => 'GLUC','name'=>'血糖'],
  22. ['type_id' => 2,'type' => 'UA','name'=>'尿酸'],
  23. ['type_id' => 3,'type' => 'CHOL','name'=>'总胆固醇'],
  24. ],
  25. ];
  26. $this->success(1,$result);
  27. }
  28. //
  29. public function lists(){
  30. $ids = Db::name('user')->where('tv_userid',$this->auth->tv_userid)->column('id');//自动注册的用户 和 app注册并绑定盒子的app用户,理论上只需要第二个
  31. $sn_arr = Db::name('user_device')->where('user_id','IN',$ids)->column('sn');//两个用户绑定的设备号
  32. //数据类型
  33. $type = input('type',1);
  34. $type_arr = [
  35. 1 => 'GLUC',
  36. 2 => 'UA',
  37. 3 => 'CHOL',
  38. ];
  39. $list = Db::name('device_sanheyi')->field('id,createtime,type,type_text,value')->where('sn','IN',$sn_arr)->where('type',$type_arr[$type])->autopage()->select();
  40. $this->success(1,$list);
  41. }
  42. }