Snsmalbum.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class Snsmalbum extends AdminControl
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize(); // TODO: Change the autogenerated stub
  17. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/snsmalbum.lang.php');
  18. }
  19. /**
  20. * 相册设置
  21. */
  22. public function setting()
  23. {
  24. $config_model = model('config');
  25. if (request()->isPost()) {
  26. //构造更新数据数组
  27. $update_array = array();
  28. $update_array['malbum_max_sum'] = intval(input('post.malbum_max_sum'));
  29. $result = $config_model->editConfig($update_array);
  30. if ($result === true) {
  31. dsLayerOpenSuccess(lang('ds_common_save_succ'));
  32. } else {
  33. $this->error(lang('ds_common_save_fail'));
  34. }
  35. } else {
  36. $list_setting = rkcache('config', true);
  37. View::assign('list_setting', $list_setting);
  38. return View::fetch();
  39. }
  40. }
  41. /**
  42. * 相册列表
  43. */
  44. public function index()
  45. {
  46. $snsmalbum_model = model('snsalbum');
  47. // 相册总数量
  48. $where = array();
  49. if (input('param.class_name') != '') {
  50. $where[] = array('ac_name', 'like', '%' . trim(input('param.class_name')) . '%');
  51. }
  52. if (input('param.user_name') != '') {
  53. $where[] = array('member_name', 'like', '%' . trim(input('param.user_name')) . '%');
  54. }
  55. $ac_lists = $snsmalbum_model->getSnsalbumclassList($where, 10, 'a.*,m.member_name');
  56. if (!empty($ac_lists)) {
  57. $ac_list = $ac_lists;
  58. $acid_array = array();
  59. foreach ($ac_list as $val) {
  60. $acid_array[] = $val['ac_id'];
  61. }
  62. // 相册中商品数量
  63. $ap_count = $snsmalbum_model->getSnsalbumpicCountList(array(array('ac_id', 'in', $acid_array)), 'count(ap_id) as count,ac_id', 'ac_id');
  64. $ap_count = array_under_reset($ap_count, 'ac_id', 1);
  65. foreach ($ac_list as $key => $val) {
  66. if (isset($ap_count[$val['ac_id']])) {
  67. $ac_list[$key]['count'] = $ap_count[$val['ac_id']]['count'];
  68. } else {
  69. $ac_list[$key]['count'] = 0;
  70. }
  71. }
  72. View::assign('ac_list', $ac_list);
  73. }
  74. View::assign('showpage', $snsmalbum_model->page_info->render());
  75. $this->setAdminCurItem('index');
  76. return View::fetch('index');
  77. }
  78. /**
  79. * 图片列表
  80. */
  81. public function pic_list()
  82. {
  83. $snsmalbum_model = model('snsalbum');
  84. $id = intval(input('param.id'));
  85. if ($id <= 0) {
  86. $this->error(lang('param_error'));
  87. }
  88. $where = array();
  89. $where[] = array('ac_id', '=', $id);
  90. if (input('param.pic_name') != '') {
  91. $where[] = array('ap_name|ap_cover', 'like', '%' . input('param.pic_name') . '%');
  92. }
  93. $pic_list = $snsmalbum_model->getSnsalbumpicList($where, 10);
  94. View::assign('id', $id);
  95. View::assign('showpage', $snsmalbum_model->page_info->render());
  96. View::assign('pic_list', $pic_list);
  97. $this->setAdminCurItem('pic_list');
  98. return View::fetch();
  99. }
  100. /**
  101. * 删除图片
  102. */
  103. public function del_pic()
  104. {
  105. $id = input('param.ap_id');
  106. if ($id <= 0) {
  107. ds_json_encode(10001, lang('param_error'));
  108. }
  109. $id_array = ds_delete_param($id);
  110. if ($id_array === FALSE) {
  111. ds_json_encode(10001, lang('param_error'));
  112. }
  113. $condition = array(array('ap_id', 'in', $id_array));
  114. $snsmalbum_model = model('snsalbum');
  115. $ap_list = $snsmalbum_model->getSnsalbumpicList($condition);
  116. if (empty($ap_list)) {
  117. ds_json_encode(10001, lang('snsalbum_choose_need_del_img'));
  118. }
  119. foreach ($ap_list as $val) {
  120. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_MALBUM . DIRECTORY_SEPARATOR . $val['member_id'] . DIRECTORY_SEPARATOR . $val['ap_cover']);
  121. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_MALBUM . DIRECTORY_SEPARATOR . $val['member_id'] . DIRECTORY_SEPARATOR . str_ireplace('.', '_240.', $val['ap_cover']));
  122. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_MALBUM . DIRECTORY_SEPARATOR . $val['member_id'] . DIRECTORY_SEPARATOR . str_ireplace('.', '_1280.', $val['ap_cover']));
  123. }
  124. $result = $snsmalbum_model->delSnsalbumpic($condition);
  125. if ($result) {
  126. $this->log(lang('ds_del') . lang('ds_member_album_manage') . '[ID:' . $id . ']', 1);
  127. ds_json_encode(10000, lang('ds_common_del_succ'));
  128. } else {
  129. ds_json_encode(10001, lang('ds_common_del_fail'));
  130. }
  131. }
  132. protected function getAdminItemList($curitem = '')
  133. {
  134. $menu_array = array(
  135. array(
  136. 'name' => 'index',
  137. 'text' => lang('snsalbum_class_list'),
  138. 'url' => (string)url('Snsmalbum/index')
  139. ), array(
  140. 'name' => 'setting',
  141. 'text' => lang('snsalbum_album_setting'),
  142. 'url' => "javascript:dsLayerOpen('" . (string)url('Snsmalbum/setting') . "','" . lang('snsalbum_album_setting') . "')"
  143. ),
  144. );
  145. if (request()->action() == 'pic_list') {
  146. $menu_array[] = array(
  147. 'name' => 'pic_list',
  148. 'text' => lang('snsalbum_pic_list'),
  149. 'url' => (string)url('Snsmalbum/pic_list', ['id' => input('param.id')])
  150. );
  151. }
  152. return $menu_array;
  153. }
  154. }