Usermember.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 成员,就诊人
  7. */
  8. class Usermember extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['*'];
  12. //添加成员
  13. public function add_one(){
  14. $field = [
  15. 'realname',
  16. 'idcard',
  17. 'relation',
  18. 'mobile',
  19. 'gender',
  20. 'birthday',
  21. 'marital_status',
  22. 'allergies_status',
  23. 'allergies_text',
  24. 'familymedical_status',
  25. 'familymedical_text',
  26. 'chronicdisease_status',
  27. 'chronicdisease_text',
  28. ];
  29. $data = request_post_hub($field);
  30. $data['user_id'] = $this->auth->id;
  31. $data['birthday'] = strtotime($data['birthday']);
  32. $id = Db::name('user_member')->insertGetId($data);
  33. $this->success('操作成功',$id);
  34. }
  35. //我的成员列表
  36. public function my_list(){
  37. $list = Db::name('user_member')->field('id,realname,gender,birthday')->where('user_id',$this->auth->id)->order('id desc')->select();
  38. if(!empty($list)){
  39. foreach($list as $key => &$val){
  40. $val['age'] = birthtime_to_age($val['birthday']);
  41. $val['avatar'] = localpath_to_netpath('/assets/img/avatar.png');
  42. }
  43. }
  44. $this->success('success',$list);
  45. }
  46. //获取详情
  47. public function info(){
  48. $id = input('id',0);
  49. $info = Db::name('user_member')->where('id',$id)->find();
  50. if(!empty($info)){
  51. $info['birthday'] = date('Y-m-d',$info['birthday']);
  52. }
  53. $this->success('success',$info);
  54. }
  55. //编辑
  56. public function edit_one(){
  57. $id = input('id',0);
  58. $field = [
  59. 'realname',
  60. 'idcard',
  61. 'relation',
  62. 'mobile',
  63. 'gender',
  64. 'birthday',
  65. 'marital_status',
  66. 'allergies_status',
  67. 'allergies_text',
  68. 'familymedical_status',
  69. 'familymedical_text',
  70. 'chronicdisease_status',
  71. 'chronicdisease_text',
  72. ];
  73. $data = request_post_hub($field);
  74. if(isset($data['birthday'])){
  75. $data['birthday'] = strtotime($data['birthday']);
  76. }
  77. Db::name('user_member')->where('id',$id)->where('user_id',$this->auth->id)->update($data);
  78. $this->success('操作成功');
  79. }
  80. //删除
  81. public function delete(){
  82. $id = input('id',0);
  83. Db::name('user_member')->where('id',$id)->where('user_id',$this->auth->id)->delete();
  84. $this->success('操作成功');
  85. }
  86. }