Snsmalbum.php 6.5 KB

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