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