Family.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 家庭乐园
  7. */
  8. class Family extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['*'];
  12. //图片,视频的列表
  13. public function lists(){
  14. $type = input('type',1);
  15. $list = Db::name('family')->where('user_id',$this->auth->id)->where('type',$type)->order('id desc')->autopage()->select();
  16. if(!empty($list)){
  17. foreach($list as $key => &$val){
  18. $val['media_file'] = localpath_to_netpath($val['media_file']);
  19. if($val['type'] == 2){
  20. $images_url = explode('.', $val['media_file']);
  21. unset($images_url[count($images_url) - 1]);
  22. $val['thumb_image'] = join('.', $images_url) . '_0.jpg';
  23. }else{
  24. $val['thumb_image'] = $val['media_file'] . '?imageView2/1/w/100/h/100/q/85';
  25. }
  26. }
  27. }
  28. $this->success(1,$list);
  29. }
  30. //上传
  31. public function addone(){
  32. $media_data = input('media_data','','htmlspecialchars_decode');
  33. $type = input('type','');
  34. if(!$media_data || !$type){
  35. $this->error();
  36. }
  37. $media_data = json_decode($media_data,true);
  38. if(!is_array($media_data)){
  39. $this->error();
  40. }
  41. $all_data = [];
  42. foreach($media_data as $key => $val){
  43. if(
  44. !isset($val['media_file']) ||
  45. !isset($val['media_name']) ||
  46. !isset($val['media_size']) ||
  47. empty($val['media_file']) ||
  48. empty($val['media_name']) ||
  49. empty($val['media_size'])
  50. ){continue;}
  51. $data = [
  52. 'user_id' => $this->auth->id,
  53. 'media_file' => $val['media_file'],
  54. 'media_name' => $val['media_name'],
  55. 'media_size' => format_bytes($val['media_size']),
  56. 'createtime' => time(),
  57. 'type' => $type,
  58. ];
  59. $all_data[] = $data;
  60. }
  61. Db::name('family')->insertAll($all_data);
  62. $this->success();
  63. }
  64. //删除
  65. public function delete(){
  66. $ids = input('ids','','trim');
  67. if(empty($ids)){
  68. $this->error();
  69. }
  70. $ids = explode(',',$ids);
  71. if(empty($ids)){
  72. $this->error();
  73. }
  74. Db::name('family')->where('id','IN',$ids)->delete();
  75. $this->success();
  76. }
  77. }