Inform.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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 Inform 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') . '/inform.lang.php');
  18. }
  19. /*
  20. * 未处理的举报列表
  21. */
  22. public function inform_list()
  23. {
  24. $this->get_inform_list(1, 'inform_list');
  25. return View::fetch();
  26. }
  27. /*
  28. * 已处理的举报列表
  29. */
  30. public function inform_handled_list()
  31. {
  32. $this->get_inform_list(2, 'inform_handled_list');
  33. return View::fetch();
  34. }
  35. /*
  36. * 获取举报列表
  37. */
  38. private function get_inform_list($type, $action)
  39. {
  40. //获得举报列表
  41. $inform_model = model('inform');
  42. //搜索条件
  43. $condition = array();
  44. if ((input('param.input_inform_goods_name'))) {
  45. $condition[] = array('inform.inform_goods_name', 'like', "%" . input('param.input_inform_goods_name') . "%");
  46. }
  47. if ((input('param.input_inform_member_name'))) {
  48. $condition[] = array('inform.inform_member_name', 'like', "%" . input('param.input_inform_member_name') . "%");
  49. }
  50. if ((input('param.input_inform_type'))) {
  51. $condition[] = array('inform_subject.informsubject_type_name', 'like', "%" . input('param.input_inform_type') . "%");
  52. }
  53. if ((input('param.input_inform_subject'))) {
  54. $condition[] = array('inform_subject.informsubject_content', 'like', "%" . input('param.input_inform_subject') . "%");
  55. }
  56. $stime = input('param.input_inform_datetime_start') ? strtotime(input('param.input_inform_datetime_start')) : 0;
  57. $etime = input('param.input_inform_datetime_end') ? strtotime(input('param.input_inform_datetime_end')) : 0;
  58. if ($stime > 0) {
  59. $condition[] = array('inform.inform_datetime', '>=', $stime);
  60. }
  61. if ($etime > 0) {
  62. $etime = $etime + 86399;
  63. $condition[] = array('inform.inform_datetime', '<=', $etime);
  64. }
  65. if ($type === 1) {
  66. $order = 'inform_id asc';
  67. } else {
  68. $order = 'inform_id desc';
  69. }
  70. $condition[] = array('inform.inform_state', '=', $type);
  71. $inform_list = $inform_model->getInformList($condition, 10, $order);
  72. $this->setAdminCurItem($action);
  73. View::assign('inform_list', $inform_list);
  74. View::assign('show_page', $inform_model->page_info->render());
  75. }
  76. /*
  77. * 举报类型列表
  78. */
  79. public function inform_subject_type_list()
  80. {
  81. //获得有效举报类型列表
  82. $informsubjecttype_model = model('informsubjecttype');
  83. $informsubjecttype_list = $informsubjecttype_model->getActiveInformsubjecttypeList(10);
  84. $this->setAdminCurItem('inform_subject_type_list');
  85. View::assign('informsubjecttype_list', $informsubjecttype_list);
  86. View::assign('show_page', $informsubjecttype_model->page_info->render());
  87. return View::fetch();
  88. }
  89. /*
  90. * 举报主题列表
  91. */
  92. public function inform_subject_list()
  93. {
  94. //获得举报主题列表
  95. $informsubject_model = model('informsubject');
  96. //搜索条件
  97. $condition = array();
  98. $informsubject_type_id = intval(input('param.informsubject_type_id'));
  99. if ($informsubject_type_id > 0) {
  100. $condition[] = array('informsubject_type_id', '=', $informsubject_type_id);
  101. }
  102. $condition[] = array('informsubject_state', '=', 1);
  103. $informsubject_list = $informsubject_model->getInformsubjectList($condition, 10);
  104. //获取有效举报类型
  105. $informsubjecttype_model = model('informsubjecttype');
  106. $type_list = $informsubjecttype_model->getActiveInformsubjecttypeList();
  107. $this->setAdminCurItem('inform_subject_list');
  108. View::assign('informsubject_list', $informsubject_list);
  109. View::assign('type_list', $type_list);
  110. View::assign('show_page', $informsubject_model->page_info->render());
  111. return View::fetch();
  112. }
  113. /*
  114. * 添加举报类型页面
  115. */
  116. public function inform_subject_type_add()
  117. {
  118. if (!request()->isPost()) {
  119. return View::fetch();
  120. } else {
  121. //获取提交的内容
  122. $input['informtype_name'] = trim(input('post.informtype_name'));
  123. $input['informtype_desc'] = trim(input('post.informtype_desc'));
  124. //验证提交的内容
  125. $data = [
  126. 'informtype_name' => $input['informtype_name'],
  127. 'informtype_desc' => $input['informtype_desc'],
  128. ];
  129. $inform_validate = ds_validate('inform');
  130. if (!$inform_validate->scene('inform_subject_type_save')->check($data)) {
  131. $this->error($inform_validate->getError());
  132. } else {
  133. //验证成功保存
  134. $input['informtype_state'] = 1;
  135. $informsubjecttype_model = model('informsubjecttype');
  136. $informsubjecttype_model->addInformsubjecttype($input);
  137. $this->log(lang('ds_add') . lang('inform_type') . '[' . input('post.informtype_name') . ']', 1);
  138. dsLayerOpenSuccess(lang('ds_common_save_succ'));
  139. }
  140. }
  141. }
  142. /*
  143. * 添加举报类型页面
  144. */
  145. public function inform_subject_type_edit()
  146. {
  147. $informtype_id = input('param.informtype_id');
  148. if (!request()->isPost()) {
  149. $informsubjecttype_model = model('informsubjecttype');
  150. $condition = array();
  151. $condition[] = ['informtype_id', '=', $informtype_id];
  152. $informsubjecttype_info = $informsubjecttype_model->getInformsubjecttypeInfo($condition);
  153. View::assign('informsubjecttype_info', $informsubjecttype_info);
  154. return View::fetch();
  155. } else {
  156. //获取提交的内容
  157. $condition = array();
  158. $condition[] = ['informtype_id', '=', $informtype_id];
  159. $input['informtype_name'] = trim(input('post.informtype_name'));
  160. $input['informtype_desc'] = trim(input('post.informtype_desc'));
  161. //验证提交的内容
  162. $data = [
  163. 'informtype_name' => $input['informtype_name'],
  164. 'informtype_desc' => $input['informtype_desc'],
  165. ];
  166. $inform_validate = ds_validate('inform');
  167. if (!$inform_validate->scene('inform_subject_type_save')->check($data)) {
  168. $this->error($inform_validate->getError());
  169. } else {
  170. //验证成功保存
  171. $input['informtype_state'] = 1;
  172. $informsubjecttype_model = model('informsubjecttype');
  173. $informsubjecttype_model->editInformsubjecttype($input, $condition);
  174. dsLayerOpenSuccess(lang('ds_common_save_succ'));
  175. }
  176. }
  177. }
  178. /*
  179. * 删除举报类型,伪删除只是修改标记
  180. */
  181. public function inform_subject_type_drop()
  182. {
  183. $informtype_id = trim(input('param.informtype_id'));
  184. $informrtype_id_array = ds_delete_param($informtype_id);
  185. if ($informrtype_id_array == FALSE) {
  186. ds_json_encode(10001, lang('param_error'));
  187. }
  188. //删除分类
  189. $informsubjecttype_model = model('informsubjecttype');
  190. $update_array = array();
  191. $update_array['informtype_state'] = 2;
  192. $where_array = array();
  193. $where_array[] = array('informtype_id', 'in', $informrtype_id_array);
  194. $informsubjecttype_model->editInformsubjecttype($update_array, $where_array);
  195. //删除分类下边的主题
  196. $informsubject_model = model('informsubject');
  197. $update_subject_array = array();
  198. $update_subject_array['informsubject_state'] = 2;
  199. $where_subject_array = array();
  200. $where_subject_array[] = array('informsubject_type_id', 'in', $informrtype_id_array);
  201. $informsubject_model->editInformsubject($update_subject_array, $where_subject_array);
  202. $this->log(lang('ds_del') . lang('inform_type') . '[ID:' . input('post.informtype_id') . ']', 1);
  203. ds_json_encode(10000, lang('ds_common_del_succ'));
  204. }
  205. /*
  206. * 添加举报主题页面
  207. */
  208. public function inform_subject_add()
  209. {
  210. if (!request()->isPost()) {
  211. //获得可用举报类型列表
  212. $informsubjecttype_model = model('informsubjecttype');
  213. $informsubjecttype_list = $informsubjecttype_model->getActiveInformsubjecttypeList();
  214. if (empty($informsubjecttype_list)) {
  215. $this->error(lang('inform_type_error'));
  216. }
  217. View::assign('informsubjecttype_list', $informsubjecttype_list);
  218. return View::fetch();
  219. } else {
  220. //获取提交的内容
  221. list($input['informsubject_type_id'], $input['informsubject_type_name']) = explode(',', trim(input('post.inform_subject_type')));
  222. $input['informsubject_content'] = trim(input('post.informsubject_content'));
  223. //验证提交的内容
  224. $data = [
  225. 'informsubject_type_name' => $input['informsubject_type_name'],
  226. 'informsubject_content' => $input['informsubject_content'],
  227. 'informsubject_type_id' => $input['informsubject_type_id']
  228. ];
  229. $inform_validate = ds_validate('inform');
  230. if (!$inform_validate->scene('inform_subject_save')->check($data)) {
  231. $this->error($inform_validate->getError());
  232. } else {
  233. //验证成功保存
  234. $input['informsubject_state'] = 1;
  235. $informsubject_model = model('informsubject');
  236. $informsubject_model->addInformsubject($input);
  237. $this->log('添加' . lang('inform_subject') . '[' . $input['informsubject_type_name'] . ']', 1);
  238. dsLayerOpenSuccess(lang('ds_common_save_succ'));
  239. }
  240. }
  241. }
  242. /*
  243. * 删除举报主题,伪删除只是修改标记
  244. */
  245. public function inform_subject_drop()
  246. {
  247. $informsubject_id = trim(input('param.informsubject_id'));
  248. $informsubject_id_array = ds_delete_param($informsubject_id);
  249. if ($informsubject_id_array == FALSE) {
  250. ds_json_encode('10001', lang('param_error'));
  251. }
  252. $informsubject_model = model('informsubject');
  253. $update_array = array();
  254. $update_array['informsubject_state'] = 2;
  255. $where_array = array();
  256. $where_array[] = array('informsubject_id', 'in', $informsubject_id_array);
  257. $informsubject_model->editInformsubject($update_array, $where_array);
  258. $this->log(lang('ds_del') . lang('inform_subject') . '[' . input('post.informsubject_id') . ']', 1);
  259. ds_json_encode(10000, lang('ds_common_del_succ'));
  260. }
  261. /*
  262. * 显示处理举报
  263. */
  264. public function show_handle_page()
  265. {
  266. $inform_id = intval(input('param.inform_id'));
  267. $inform_goods_name = urldecode(input('param.inform_goods_name'));
  268. View::assign('inform_id', $inform_id);
  269. View::assign('inform_goods_name', $inform_goods_name);
  270. return View::fetch('inform_handle');
  271. }
  272. /*
  273. * 处理举报
  274. */
  275. public function inform_handle()
  276. {
  277. $inform_id = intval(input('post.inform_id'));
  278. $inform_handle_type = intval(input('post.inform_handle_type'));
  279. $inform_handle_message = trim(input('post.inform_handle_message'));
  280. if (empty($inform_id) || empty($inform_handle_type)) {
  281. $this->error(lang('param_error'));
  282. }
  283. //验证输入的数据
  284. $data = [
  285. "inform_handle_message" => $inform_handle_message,
  286. ];
  287. $inform_validate = ds_validate('inform');
  288. if (!$inform_validate->scene('inform_handle')->check($data)) {
  289. $this->error($inform_validate->getError());
  290. }
  291. $inform_model = model('inform');
  292. $inform_info = $inform_model->getOneInform(array('inform_id' => $inform_id));
  293. if (empty($inform_info) || intval($inform_info['inform_state']) === 2) {
  294. $this->error(lang('param_error'));
  295. }
  296. $update_array = array();
  297. $where_array = array();
  298. //根据选择处理
  299. switch ($inform_handle_type) {
  300. case 1:
  301. $where_array[] = array('inform_id', '=', $inform_id);
  302. break;
  303. case 2:
  304. //恶意举报,清理所有该用户的举报,设置该用户禁止举报
  305. $where_array[] = array('inform_member_id', '=', $inform_info['inform_member_id']);
  306. $this->denyMemberInform($inform_info['inform_member_id']);
  307. break;
  308. case 3:
  309. //有效举报,商品禁售
  310. $where_array[] = array('inform_id', '=', $inform_id);
  311. $this->denyGoods($inform_info['inform_goods_id']);
  312. break;
  313. default:
  314. $this->error(lang('param_error'));
  315. }
  316. $update_array['inform_state'] = 2;
  317. $update_array['inform_handle_type'] = $inform_handle_type;
  318. $update_array['inform_handle_message'] = $inform_handle_message;
  319. $update_array['inform_handle_datetime'] = TIMESTAMP;
  320. $admin_info = $this->getAdminInfo();
  321. $update_array['inform_handle_member_id'] = $admin_info['admin_id'];
  322. $where_array[] = array('inform_state', '=', 1);
  323. if ($inform_model->editInform($update_array, $where_array)) {
  324. $this->log(lang('inform_text_handle') . lang('inform') . '[ID:' . $inform_id . ']', 1);
  325. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  326. } else {
  327. $this->error(lang('ds_common_op_fail'));
  328. }
  329. }
  330. /*
  331. * 禁止该用户举报
  332. */
  333. private function denyMemberInform($member_id)
  334. {
  335. $member_model = model('member');
  336. $param = array();
  337. $param['inform_allow'] = 2;
  338. return $member_model->editMember(array('member_id' => $member_id), $param, $member_id);
  339. }
  340. /*
  341. * 禁止商品销售
  342. */
  343. private function denyGoods($goods_id)
  344. {
  345. //修改商品状态
  346. $goods_model = model('goods');
  347. $goods_info = $goods_model->getGoodsInfoByID($goods_id);
  348. if (empty($goods_info)) {
  349. return true;
  350. }
  351. return $goods_model->editProducesLockUp(array('goods_stateremark' => lang('goods_be_informed')), array('goods_commonid' => $goods_info['goods_commonid']));
  352. }
  353. /**
  354. * 获取卖家栏目列表,针对控制器下的栏目
  355. */
  356. protected function getAdminItemList()
  357. {
  358. $menu_array = array(
  359. array(
  360. 'name' => 'inform_list',
  361. 'text' => lang('inform_state_unhandle'),
  362. 'url' => (string) url('Inform/inform_list')
  363. ),
  364. array(
  365. 'name' => 'inform_handled_list',
  366. 'text' => lang('inform_state_handled'),
  367. 'url' => (string) url('Inform/inform_handled_list')
  368. ),
  369. array(
  370. 'name' => 'inform_subject_type_list',
  371. 'text' => lang('inform_type'),
  372. 'url' => (string) url('Inform/inform_subject_type_list')
  373. ),
  374. array(
  375. 'name' => 'inform_subject_type_add',
  376. 'text' => lang('inform_type_add'),
  377. 'url' => "javascript:dsLayerOpen('" . (string) url('Inform/inform_subject_type_add') . "','" . lang('inform_type_add') . "')"
  378. ),
  379. array(
  380. 'name' => 'inform_subject_list',
  381. 'text' => lang('inform_subject'),
  382. 'url' => (string) url('Inform/inform_subject_list')
  383. ),
  384. array(
  385. 'name' => 'inform_subject_add',
  386. 'text' => lang('inform_subject_add'),
  387. 'url' => "javascript:dsLayerOpen('" . (string) url('Inform/inform_subject_add') . "','" . lang('inform_subject_add') . "')"
  388. ),
  389. );
  390. return $menu_array;
  391. }
  392. }