Snsmember.php 9.9 KB

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