Memberinform.php 12 KB

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