CommentsModel.class.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * 洛阳赤炎鹰网络科技有限公司
  4. * https://www.cyyvip.com
  5. * Copyright (c) 2022 赤店商城 All rights reserved.
  6. */
  7. namespace Common\Model;
  8. use Common\Model\CommonModel;
  9. class CommentsModel extends CommonModel{
  10. //自动验证
  11. protected $_validate = array(
  12. //array(验证字段,验证规则,错误提示,验证条件,附加规则,验证时间)
  13. array('full_name', 'check_full_name', '姓名不能为空!', 1, 'callback', CommonModel:: MODEL_INSERT ),
  14. //array('email', 'check_full_email', '邮箱不能为空!', 1, 'callback', CommonModel:: MODEL_INSERT ),
  15. array('content', 'require', '评论不能为空!', 1, 'regex', CommonModel:: MODEL_BOTH ),
  16. //array('email','email','邮箱格式不正确!',0,'',CommonModel:: MODEL_BOTH ),
  17. array('post_table','table_exists','您评论的内容不存在!',0,'callback',CommonModel:: MODEL_BOTH ),
  18. );
  19. protected $_auto = array(
  20. array('createtime','mDate',1,'callback'), // 对msg字段在新增的时候回调htmlspecialchars方法
  21. );
  22. function mDate(){
  23. return date("Y-m-d H:i:s");
  24. }
  25. function check_full_name($data){
  26. if(empty($data)){
  27. if(isset($_SESSION["user"])){
  28. return true;
  29. }
  30. return false;
  31. }
  32. return true;
  33. }
  34. function check_full_email($data){
  35. if(empty($data)){
  36. if(isset($_SESSION["user"])){
  37. return true;
  38. }
  39. return false;
  40. }
  41. return true;
  42. }
  43. protected function _before_write(&$data) {
  44. parent::_before_write($data);
  45. }
  46. protected function _after_insert($data,$options){
  47. parent::_after_insert($data,$options);
  48. $id=$data['id'];
  49. $parent_id=$data['parentid'];
  50. if($parent_id==0){
  51. $d['path']="0-$id";
  52. }else{
  53. $parent=$this->where("id=$parent_id")->find();
  54. $d['path']=$parent['path'].'-'.$id;
  55. }
  56. $this->where("id=$id")->save($d);
  57. }
  58. protected function _after_update($data,$options){
  59. parent::_after_update($data,$options);
  60. if(isset($data['parentid'])){
  61. $id=$data['id'];
  62. $parent_id=$data['parentid'];
  63. if($parent_id==0){
  64. $d['path']="0-$id";
  65. }else{
  66. $parent=$this->where("id=$parent_id")->find();
  67. $d['path']=$parent['path'].'-'.$id;
  68. }
  69. $this->where("id=$id")->save($d);
  70. }
  71. }
  72. }