Snsmember.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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 Snsmember 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') . '/snsmember.lang.php');
  18. }
  19. /**
  20. * 标签列表
  21. */
  22. public function index()
  23. {
  24. // 实例化模型
  25. $snsmember_model = model('snsmember');
  26. $tag_list = $snsmember_model->getSnsmembertagList('mtag_sort asc', 10);
  27. View::assign('showpage', $snsmember_model->page_info->render());
  28. View::assign('tag_list', $tag_list);
  29. $this->setAdminCurItem('index');
  30. return View::fetch();
  31. }
  32. /**
  33. * 添加标签
  34. */
  35. public function tag_add()
  36. {
  37. if (request()->isPost()) {
  38. /**
  39. * 验证
  40. */
  41. $data = [
  42. 'membertag_name' => input('post.membertag_name'), 'membertag_sort' => input('post.membertag_sort'),
  43. ];
  44. $snsmember_validate = ds_validate('snsmember');
  45. if (!$snsmember_validate->scene('tag_add')->check($data)) {
  46. $this->error($snsmember_validate->getError());
  47. } else {
  48. /**
  49. * 上传图片
  50. */
  51. $img = '';
  52. if (!empty($_FILES['membertag_img']['name'])) {
  53. $res = ds_upload_pic(ATTACH_PATH . '/membertag', 'membertag_img');
  54. if ($res['code']) {
  55. $img = $res['data']['file_name'];
  56. } else {
  57. $this->error($res['msg']);
  58. }
  59. }
  60. $insert = array(
  61. 'mtag_name' => input('post.membertag_name'),
  62. 'mtag_sort' => intval(input('post.membertag_sort')),
  63. 'mtag_recommend' => intval(input('post.membertag_recommend')),
  64. 'mtag_desc' => trim(input('post.membertag_desc')),
  65. 'mtag_img' => $img
  66. );
  67. $snsmember_model = model('snsmember');
  68. $result = $snsmember_model->addSnsmembertag($insert);
  69. if ($result) {
  70. $this->log(lang('ds_add') . lang('sns_member_tag') . '[' . input('post.membertag_name') . ']', 1);
  71. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  72. } else {
  73. $this->error(lang('ds_common_op_fail'));
  74. }
  75. }
  76. } else {
  77. return View::fetch();
  78. }
  79. }
  80. /**
  81. * 编辑标签
  82. */
  83. public function tag_edit()
  84. {
  85. // 实例化模型
  86. if (request()->isPost()) {
  87. /**
  88. * 验证
  89. */
  90. $data = [
  91. 'membertag_name' => input('post.membertag_name'), 'membertag_sort' => input('post.membertag_sort'),
  92. ];
  93. $snsmember_validate = ds_validate('snsmember');
  94. if (!$snsmember_validate->scene('tag_edit')->check($data)) {
  95. $this->error($snsmember_validate->getError());
  96. } else {
  97. /**
  98. * 上传图片
  99. */
  100. $input = '';
  101. if (!empty($_FILES['membertag_img']['name'])) {
  102. $res = ds_upload_pic(ATTACH_PATH . '/membertag', 'membertag_img');
  103. if ($res['code']) {
  104. $input = $res['data']['file_name'];
  105. } else {
  106. $this->error($res['msg']);
  107. }
  108. }
  109. $update = array();
  110. $update['mtag_id'] = intval(input('post.id'));
  111. $update['mtag_name'] = trim(input('post.membertag_name'));
  112. $update['mtag_sort'] = intval(input('post.membertag_sort'));
  113. $update['mtag_recommend'] = intval(input('post.membertag_recommend'));
  114. $update['mtag_desc'] = trim(input('post.membertag_desc'));
  115. $update['mtag_img'] = $input;
  116. $snsmember_model = model('snsmember');
  117. $result = $snsmember_model->editSnsmembertag($update);
  118. if ($result >= 0) {
  119. $this->log(lang('ds_edit') . lang('sns_member_tag') . '[' . input('post.membertag_name') . ']', 1);
  120. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  121. } else {
  122. $this->error(lang('ds_common_op_fail'));
  123. }
  124. }
  125. } else {
  126. // 验证
  127. $mtag_id = intval(input('param.id'));
  128. if ($mtag_id <= 0) {
  129. $this->error(lang('param_error'));
  130. }
  131. $snsmember_model = model('snsmember');
  132. $mtag_info = $snsmember_model->getOneSnsmembertag($mtag_id);
  133. if (empty($mtag_info)) {
  134. $this->error(lang('param_error'));
  135. }
  136. $this->setAdminCurItem('tag_edit');
  137. //halt($mtag_info);
  138. View::assign('mtag_info', $mtag_info);
  139. return View::fetch();
  140. }
  141. }
  142. /**
  143. * 删除标签
  144. */
  145. public function tag_del()
  146. {
  147. $mtag_id = input('param.id');
  148. $mtag_id_array = ds_delete_param($mtag_id);
  149. if ($mtag_id_array == FALSE) {
  150. ds_json_encode('10001', lang('param_error'));
  151. }
  152. $condition = array();
  153. $condition[] = array('mtag_id', 'in', $mtag_id_array);
  154. $snsmember_model = model('snsmember');
  155. $result = $snsmember_model->delSnsmembertag($condition);
  156. if ($result) {
  157. $this->log(lang('ds_del') . lang('sns_member_tag') . '[ID:' . $mtag_id . ']', 1);
  158. ds_json_encode('10000', lang('ds_common_del_succ'));
  159. } else {
  160. ds_json_encode('10001', lang('ds_common_del_fail'));
  161. }
  162. }
  163. /**
  164. * 标签所属会员列表
  165. */
  166. public function tag_member()
  167. {
  168. // 验证
  169. $mtag_id = intval(input('param.id'));
  170. if ($mtag_id <= 0) {
  171. $this->error(lang('param_error'));
  172. }
  173. $snsmember_model = model('snsmember');
  174. $count = $snsmember_model->getSnstagmemberCount(array('mtag_id' => $mtag_id));
  175. $tagmember_list = $snsmember_model->getSnsmtagmemberList(array('s.mtag_id' => $mtag_id), 's.*,m.member_avatar,m.member_name', 10, 's.recommend desc, s.member_id asc', $count);
  176. View::assign('tagmember_list', $tagmember_list);
  177. View::assign('showpage', $snsmember_model->page_info->render());
  178. $this->setAdminCurItem('tag_member');
  179. return View::fetch();
  180. }
  181. /**
  182. * 删除添加标签会员
  183. */
  184. public function mtag_del()
  185. {
  186. $snsmember_model = model('snsmember');
  187. $mtag_id = intval(input('param.id'));
  188. $member_id = intval(input('param.mid'));
  189. if ($mtag_id <= 0 || $member_id <= 0) {
  190. $this->error(lang('miss_argument'));
  191. }
  192. // 条件
  193. $condition = array();
  194. $condition[] = array('mtag_id', '=', $mtag_id);
  195. $condition[] = array('member_id', '=', $member_id);
  196. $result = $snsmember_model->delSnsmtagmember($condition);
  197. if ($result) {
  198. $this->log(lang('ds_del') . lang('sns_member_tag') . '[ID:' . $mtag_id . ']', 1);
  199. $this->success(lang('ds_common_del_succ'));
  200. } else {
  201. $this->error(lang('ds_common_del_fail'));
  202. }
  203. }
  204. /**
  205. * ajax修改
  206. */
  207. public function ajax()
  208. {
  209. // 实例化模型
  210. $snsmember_model = model('snsmember');
  211. switch (input('param.branch')) {
  212. /**
  213. * 更新名称、排序、推荐
  214. */
  215. case 'membertag_name':
  216. case 'membertag_sort':
  217. case 'membertag_recommend':
  218. $update = array(
  219. 'mtag_id' => intval(input('param.id')), input('param.column') => input('param.value')
  220. );
  221. $snsmember_model->editSnsmembertag($update);
  222. echo 'true';
  223. break;
  224. /**
  225. * sns_mtagmember表推荐
  226. */
  227. case 'mtagmember_recommend':
  228. list($where['mtag_id'], $where['member_id']) = explode(',', input('param.id'));
  229. $update = array(
  230. input('param.column') => input('param.value')
  231. );
  232. $snsmember_model->editSnsmtagmember($where, $update);
  233. echo 'true';
  234. break;
  235. }
  236. }
  237. protected function getAdminItemList()
  238. {
  239. $menu_array = array(
  240. array(
  241. 'name' => 'index', 'text' => lang('sns_member_tag_manage'), 'url' => (string) url('Snsmember/index')
  242. ), array(
  243. 'name' => 'tag_add',
  244. 'text' => lang('ds_new'),
  245. 'url' => "javascript:dsLayerOpen('" . (string) url('Snsmember/tag_add') . "','" . lang('ds_new') . "')"
  246. ),
  247. );
  248. if (request()->action() == 'tag_member') {
  249. $menu_array[] = array(
  250. 'name' => 'tag_member', 'text' => lang('sns_member_member_list'), 'url' => ('#')
  251. );
  252. }
  253. return $menu_array;
  254. }
  255. }