FormController.class.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Home\Controller;
  15. use Lib\Taobaoip;
  16. class FormController extends CommonController {
  17. function reply(){
  18. if(IS_GET){
  19. $id=get_url_id('id');
  20. $data['title']=I('name');
  21. $data['content']=I('comment');
  22. $data['email']=I('email');
  23. $data['blog_id']=$id;
  24. $data['ip']=get_client_ip();
  25. $tip=new Taobaoip();
  26. $ip_region=$tip->getLocation($data['ip']);
  27. $data['ip_region']=$ip_region['region'].'-'.$ip_region['city'];
  28. $data['create_time']=date('Y-m-d H:i:s',time());
  29. $data['status']=1;
  30. $r['blog_id']= $id;
  31. $r['reply'] = array('exp','reply+1');
  32. M('blog')->save($r);
  33. $data['device']=$_SERVER['HTTP_USER_AGENT'];
  34. if(M('blog_reply')->add($data)){
  35. die('true');
  36. }
  37. }
  38. }
  39. //写入留言
  40. public function comment(){
  41. if(IS_POST){
  42. //留言时间间隔 2分钟
  43. $time=120;
  44. $comment=I('comment');
  45. if(empty($comment)){
  46. $this->error='留言内容必填!!!';
  47. $this->author=I('author');
  48. $this->email=I('email');
  49. $this->phone=I('phone');
  50. $this->display('Html:contact');
  51. die;
  52. }
  53. $data['name']=I('author');
  54. $data['email']=I('email');
  55. $data['tel']=I('phone');
  56. $data['content']=I('comment');
  57. $data['ip']=get_client_ip();
  58. if($last_comment=M('comment')->where(array('ip'=>$data['ip']))->order('comment_id desc')->limit(1)->find()){
  59. if((time()-(int)$last_comment['create_time'])<$time){
  60. $this->error='请2分钟后再留言!!!';
  61. $this->author=I('author');
  62. $this->email=I('email');
  63. $this->phone=I('phone');
  64. $this->comment=$comment;
  65. $this->display('Html:contact');
  66. die;
  67. }
  68. }
  69. $tip=new Taobaoip();
  70. $ip_region=$tip->getLocation($data['ip']);
  71. $data['ip_region']=$ip_region['region'].'-'.$ip_region['city'];
  72. $data['create_time']=time();
  73. $data['create_time_date']=date('Y-m-d H:i:s',time());
  74. $data['device']=$_SERVER['HTTP_USER_AGENT'];
  75. $id=M('comment')->add($data);
  76. if($id){
  77. $this->success='留言成功!';
  78. $this->display('Html:contact');
  79. }else{
  80. $this->error='留言失败!';
  81. $this->display('Html:contact');
  82. }
  83. }
  84. }
  85. }