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