Snsalbum.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * 买家相册
  4. */
  5. namespace app\home\controller;
  6. use think\facade\Lang;
  7. use think\facade\Db;
  8. /**
  9. * ============================================================================
  10. *
  11. * ============================================================================
  12. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  13. * 网站地址: https://www.valimart.net/
  14. * ----------------------------------------------------------------------------
  15. *
  16. * ============================================================================
  17. * 控制器
  18. */
  19. class Snsalbum extends BaseMember {
  20. public function initialize() {
  21. parent::initialize();
  22. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/snsalbum.lang.php');
  23. }
  24. /**
  25. * 图片删除
  26. */
  27. public function album_pic_del() {
  28. $ids = input('param.id');
  29. if (empty($ids)) {
  30. ds_json_encode(10001, lang('album_parameter_error'));
  31. };
  32. if (!empty($ids) && is_array($ids)) {
  33. $id = $ids;
  34. } else {
  35. $id[] = intval($ids);
  36. }
  37. foreach ($id as $v) {
  38. $v = intval($v);
  39. if ($v <= 0)
  40. continue;
  41. $ap_info = Db::name('snsalbumpic')->where(array('ap_id' => $v, 'member_id' => session('member_id')))->find();
  42. if (empty($ap_info))
  43. continue;
  44. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_MALBUM . DIRECTORY_SEPARATOR . session('member_id') . DIRECTORY_SEPARATOR . $ap_info['ap_cover']);
  45. $res = Db::name('snsalbumpic')->delete($ap_info['ap_id']);
  46. }
  47. if ($res) {
  48. ds_json_encode(10000, lang('album_class_pic_del_succeed'));
  49. }
  50. }
  51. /**
  52. * 上传图片
  53. *
  54. * @param
  55. * @return
  56. */
  57. public function swfupload() {
  58. $member_id = session('member_id');
  59. $class_id = intval(input('param.category_id'));
  60. if ($member_id <= 0 && $class_id <= 0) {
  61. echo json_encode(array('state' => 'false', 'message' => lang('sns_upload_pic_fail'), 'origin_file_name' => $_FILES["file"]["name"]));
  62. exit;
  63. }
  64. /**
  65. * 上传图片
  66. */
  67. //上传文件保存路径
  68. if (!empty($_FILES['file']['name'])) {
  69. //设置特殊图片名称
  70. $file_name = $member_id . '_' . date('YmdHis') . rand(10000, 99999).'.png';
  71. $res = ds_upload_pic(ATTACH_MALBUM . DIRECTORY_SEPARATOR . $member_id, 'file', $file_name);
  72. if ($res['code']) {
  73. $img_path = $res['data']['file_name'];
  74. } else {
  75. $error = $res['msg'];
  76. $data['state'] = 'false';
  77. $data['message'] = $error;
  78. $data['origin_file_name'] = $_FILES['file']['name'];
  79. echo json_encode($data);
  80. exit;
  81. }
  82. } else {
  83. //未上传图片不做后面处理
  84. exit;
  85. }
  86. list($width, $height, $type, $attr) = getimagesize(ds_get_pic(ATTACH_MALBUM . DIRECTORY_SEPARATOR . $member_id, $img_path));
  87. $insert = array();
  88. $insert['ap_name'] = $img_path;
  89. $insert['ac_id'] = $class_id;
  90. $insert['ap_cover'] = $img_path;
  91. $insert['ap_size'] = intval($_FILES['file']['size']);
  92. $insert['ap_spec'] = $width . 'x' . $height;
  93. $insert['ap_uploadtime'] = TIMESTAMP;
  94. $insert['member_id'] = $member_id;
  95. $result = Db::name('snsalbumpic')->insertGetId($insert);
  96. $data = array();
  97. $data['file_id'] = $result;
  98. $data['file_name'] = $img_path;
  99. $data['origin_file_name'] = $_FILES["file"]["name"];
  100. $data['file_path'] = $img_path;
  101. $data['file_url'] = sns_thumb($img_path, 240);
  102. $data['state'] = 'true';
  103. /**
  104. * 整理为json格式
  105. */
  106. $output = json_encode($data);
  107. echo $output;
  108. }
  109. }
  110. ?>