Snsmalbum.php 6.3 KB

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