Memberinform.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. *
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 控制器
  14. */
  15. class Memberinform extends BaseMember
  16. {
  17. public function initialize()
  18. {
  19. parent::initialize(); // TODO: Change the autogenerated stub
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberinfom.lang.php');
  21. }
  22. /*
  23. * 获取当前用户的举报列表
  24. */
  25. public function index()
  26. {
  27. /*
  28. * 得到当前用户的举报列表
  29. */
  30. $inform_model = model('inform');
  31. $condition = array();
  32. $inform_state = intval(input('param.select_inform_state'));
  33. if ($inform_state > 0) {
  34. $condition[] = array('inform.inform_state', '=', $inform_state);
  35. }
  36. $condition[] = array('inform.inform_member_id', '=', session('member_id'));
  37. $inform_list = $inform_model->getInformList($condition, 10);
  38. /* 设置买家当前菜单 */
  39. $this->setMemberCurMenu('member_inform');
  40. /* 设置买家当前栏目 */
  41. $this->setMemberCurItem('inform_list');
  42. View::assign('inform_list', $inform_list);
  43. View::assign('show_page', $inform_model->page_info->render());
  44. return View::fetch($this->template_dir . 'index');
  45. }
  46. /*
  47. * 提交举报商品
  48. */
  49. public function inform_submit()
  50. {
  51. //检查当前用户是否允许举报
  52. $this->check_member_allow_inform();
  53. $goods_id = intval(input('param.goods_id'));
  54. //获取商品详细信息
  55. $goods_info = $this->get_goods_info_byid($goods_id);
  56. //检查是否是本店商品
  57. if (!empty(session('store_id'))) {
  58. if ($goods_info['store_id'] == session('store_id')) {
  59. $this->error(lang('param_error'));
  60. }
  61. }
  62. $inform_model = model('inform');
  63. //检查是否当前正在举报
  64. if ($inform_model->isProcessOfInform($goods_id)) {
  65. $this->error(lang('inform_handling'));
  66. }
  67. //获取举报类型
  68. $informsubjecttype_model = model('informsubjecttype');
  69. $inform_subject_type_list = $informsubjecttype_model->getActiveInformsubjecttypeList();
  70. if (empty($inform_subject_type_list)) {
  71. $this->error(lang('inform_type_null'));
  72. }
  73. /* 设置买家当前菜单 */
  74. $this->setMemberCurMenu('member_inform');
  75. /* 设置买家当前栏目 */
  76. $this->setMemberCurItem('inform_list');
  77. View::assign('goods_info', $goods_info);
  78. View::assign('type_list', $inform_subject_type_list);
  79. return View::fetch($this->template_dir . 'inform_submit');
  80. }
  81. /*
  82. * 保存用户提交的商品举报
  83. */
  84. public function inform_save()
  85. {
  86. //检查当前用户是否允许举报
  87. $this->check_member_allow_inform();
  88. $goods_id = intval(input('post.inform_goods_id'));
  89. //获取商品详细信息
  90. $goods_info = $this->get_goods_info_byid($goods_id);
  91. //检查是否是本店商品
  92. if (!empty(session('store_id'))) {
  93. if ($goods_info['store_id'] == session('store_id')) {
  94. $this->error(lang('param_error'));
  95. }
  96. }
  97. //实例化举报模型
  98. $inform_model = model('inform');
  99. //检查是否当前正在举报
  100. if ($inform_model->isProcessOfInform($goods_id)) {
  101. $this->error(lang('inform_handling'));
  102. }
  103. //处理用户输入的数据
  104. $input = array();
  105. $input['inform_member_id'] = session('member_id');
  106. $input['inform_member_name'] = session('member_name');
  107. $input['inform_goods_id'] = $goods_id;
  108. $input['inform_goods_name'] = $goods_info['goods_name'];
  109. $input['inform_goods_image'] = $goods_info['goods_image'];
  110. list($input['informsubject_id'], $input['informsubject_content']) = explode(",", trim(input('post.inform_subject')));
  111. $input['inform_content'] = trim(input('post.inform_content'));
  112. //上传图片
  113. $inform_pic = array();
  114. $inform_pic[1] = 'inform_pic1';
  115. $inform_pic[2] = 'inform_pic2';
  116. $inform_pic[3] = 'inform_pic3';
  117. $pic_name = $this->inform_upload_pic($inform_pic);
  118. $input['inform_pic1'] = $pic_name[1];
  119. $input['inform_pic2'] = $pic_name[2];
  120. $input['inform_pic3'] = $pic_name[3];
  121. $input['inform_datetime'] = TIMESTAMP;
  122. $input['inform_store_id'] = $goods_info['store_id'];
  123. $input['inform_store_name'] = $goods_info['store_name'];
  124. $input['inform_state'] = 1;
  125. $input['inform_handle_message'] = '';
  126. $input['inform_handle_member_id'] = 0;
  127. $input['inform_handle_datetime'] = 1;
  128. //验证输入的数据
  129. $data = [
  130. 'inform_content' => $input["inform_content"],
  131. 'informsubject_content' => $input["informsubject_content"]
  132. ];
  133. $res = word_filter($input['inform_content']);
  134. if (!$res['code']) {
  135. $this->error($res['msg']);
  136. }
  137. $input['inform_content'] = $res['data']['text'];
  138. $inform_validate = ds_validate('inform');
  139. if (!$inform_validate->scene('inform_save')->check($data)) {
  140. $this->error($inform_validate->getError());
  141. }
  142. //保存
  143. if ($inform_model->addInform($input)) {
  144. $this->success(lang('inform_success'), (string)url('Memberinform/index'));
  145. } else {
  146. $this->error(lang('inform_fail'), (string)url('Memberinform/index'));
  147. }
  148. }
  149. /*
  150. * 取消用户提交的商品举报
  151. */
  152. public function inform_cancel()
  153. {
  154. $inform_id = intval(input('param.inform_id'));
  155. $inform_info = $this->get_inform_info($inform_id);
  156. if (intval($inform_info['inform_state']) === 1) {
  157. $pics = array();
  158. if (!empty($inform_info['inform_pic1'])) {
  159. $pics[] = $inform_info['inform_pic1'];
  160. }
  161. if (!empty($inform_info['inform_pic2'])) {
  162. $pics[] = $inform_info['inform_pic2'];
  163. }
  164. if (!empty($inform_info['inform_pic3'])) {
  165. $pics[] = $inform_info['inform_pic3'];
  166. }
  167. $this->drop_inform($inform_id, $pics);
  168. ds_json_encode(10000, lang('inform_cancel_success'));
  169. } else {
  170. ds_json_encode(10001, lang('inform_cancel_fail'));
  171. }
  172. }
  173. /**
  174. * 商品举报详细
  175. */
  176. public function inform_info()
  177. {
  178. $inform_id = intval(input('param.inform_id'));
  179. $inform_info = $this->get_inform_info($inform_id);
  180. View::assign('inform_info', $inform_info);
  181. // 商品信息
  182. $goods_info = model('goods')->getGoodsInfoByID($inform_info['inform_goods_id']);
  183. View::assign('goods_info', $goods_info);
  184. // 投诉类型
  185. $subject_info = model('informsubject')->getOneInformsubject(array('informsubject_id' => $inform_info['informsubject_id']));
  186. /* 设置买家当前菜单 */
  187. $this->setMemberCurMenu('member_inform');
  188. /* 设置买家当前栏目 */
  189. $this->setMemberCurItem('inform_list');
  190. View::assign('subject_info', $subject_info);
  191. return View::fetch($this->template_dir . 'inform_info');
  192. }
  193. /*
  194. * 根据id获取投诉详细信息
  195. */
  196. private function get_inform_info($inform_id)
  197. {
  198. if (empty($inform_id)) {
  199. $this->error(lang('param_error'));
  200. }
  201. $inform_model = model('inform');
  202. $inform_info = $inform_model->getOneInform(array('inform_id' => $inform_id));
  203. if (empty($inform_info)) {
  204. $this->error(lang('param_error'));
  205. }
  206. if (intval($inform_info['inform_member_id']) !== intval(session('member_id'))) {
  207. $this->error(lang('param_error'));
  208. }
  209. return $inform_info;
  210. }
  211. /*
  212. * 根据id获取投诉详细信息
  213. */
  214. private function drop_inform($inform_id, $inform_pics)
  215. {
  216. $inform_model = model('inform');
  217. //删除图片
  218. if (!empty($inform_pics)) {
  219. foreach ($inform_pics as $pic) {
  220. $this->inform_delete_pic($pic);
  221. }
  222. }
  223. $inform_model->delInform(array('inform_id' => $inform_id));
  224. }
  225. /*
  226. * 根据id获取商品详细信息
  227. */
  228. private function get_goods_info_byid($goods_id)
  229. {
  230. if (empty($goods_id)) {
  231. $this->error(lang('param_error'));
  232. }
  233. $goods_model = model('goods');
  234. $goods_info = $goods_model->getGoodsOnlineInfoByID($goods_id);
  235. //检查该商品是否存在
  236. if (empty($goods_info)) {
  237. $this->error(lang('goods_null'));
  238. }
  239. return $goods_info;
  240. }
  241. /*
  242. * 检查当前用户是否允许举报
  243. */
  244. private function check_member_allow_inform()
  245. {
  246. //检查是否允许举报
  247. $member_model = model('member');
  248. if (!$member_model->isMemberAllowInform(session('member_id'))) {
  249. $this->error(lang('deny_inform'));
  250. }
  251. }
  252. /*
  253. * 上传用户提供的举报图片
  254. */
  255. private function inform_upload_pic($inform_pic)
  256. {
  257. $pic_name = array();
  258. $count = 1;
  259. foreach ($inform_pic as $pic) {
  260. if (!empty($_FILES[$pic]['name'])) {
  261. $file_name = session('member_id') . '_' . date('YmdHis') . rand(10000, 99999) . '.png';
  262. $res = ds_upload_pic('home' . DIRECTORY_SEPARATOR . 'inform', $pic, $file_name);
  263. if ($res['code']) {
  264. $pic_name[$count] = $res['data']['file_name'];
  265. } else {
  266. $pic_name[$count] = '';
  267. }
  268. } else {
  269. $pic_name[$count] = '';
  270. }
  271. $count++;
  272. }
  273. return $pic_name;
  274. }
  275. /*
  276. * 上传用户提供的举报图片
  277. */
  278. private function inform_delete_pic($pic_name)
  279. {
  280. //上传路径
  281. $pic = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_PATH . DIRECTORY_SEPARATOR . 'inform' . DIRECTORY_SEPARATOR . $pic_name;
  282. if (file_exists($pic)) {
  283. @unlink($pic);
  284. }
  285. }
  286. /*
  287. * 根据举报类型id获取,举报具体列表
  288. */
  289. public function get_subject_by_typeid()
  290. {
  291. $informsubject_type_id = intval(input('param.type_id'));
  292. if (empty($informsubject_type_id)) {
  293. echo '';
  294. } else {
  295. /*
  296. * 获得举报主题列表
  297. */
  298. $informsubject_model = model('informsubject');
  299. //搜索条件
  300. $condition = array();
  301. $condition[] = array('informsubject_type_id', '=', $informsubject_type_id);
  302. $condition[] = array('informsubject_state', '=', 1);
  303. $inform_subject_list = $informsubject_model->getInformsubjectList($condition, 10, 'informsubject_id,informsubject_content');
  304. echo json_encode($inform_subject_list);
  305. }
  306. }
  307. /**
  308. * 用户中心右边,小导航
  309. *
  310. * @param string $menu_type 导航类型
  311. * @param string $menu_key 当前导航的menu_key
  312. * @param array $array 附加菜单
  313. *
  314. * @return
  315. */
  316. public function getMemberItemList()
  317. {
  318. $menu_array = array(
  319. array(
  320. 'name' => 'inform_list',
  321. 'text' => lang('violation_report'),
  322. 'url' => (string)url('Memberinform/index')
  323. ),
  324. );
  325. return $menu_array;
  326. }
  327. }