ProjectComment.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace app\admin\model;
  3. use think\model;
  4. use app\admin\model\Keywords;
  5. use think\facade\Db;
  6. class ProjectComment extends Model
  7. {
  8. /**
  9. * 添加数据
  10. * @param $param
  11. */
  12. public function addComment($param)
  13. {
  14. $insertId = 0;
  15. try {
  16. $param['create_time'] = time();
  17. $insertId = self::strict(false)->field(true)->insertGetId($param);
  18. add_log('add', $insertId, $param);
  19. } catch(\Exception $e) {
  20. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  21. }
  22. return to_assign(0,'操作成功',['aid'=>$insertId]);
  23. }
  24. /**
  25. * 编辑信息
  26. * @param $param
  27. */
  28. public function editComment($param)
  29. {
  30. try {
  31. $param['update_time'] = time();
  32. self::where('id', $param['id'])->strict(false)->field(true)->update($param);
  33. add_log('edit', $param['id'], $param);
  34. } catch(\Exception $e) {
  35. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  36. }
  37. return to_assign();
  38. }
  39. /**
  40. * 根据id获取信息
  41. * @param $id
  42. */
  43. public function getCommentById($id)
  44. {
  45. $info = self::where('id', $id)->find();
  46. return $info;
  47. }
  48. /**
  49. * 删除信息
  50. * @param $id
  51. * @return array
  52. */
  53. public function delCommentById($id,$type=0)
  54. {
  55. if($type==0){
  56. //逻辑删除
  57. try {
  58. $param['delete_time'] = time();
  59. self::where('id', $id)->update(['delete_time'=>time()]);
  60. add_log('delete', $id);
  61. } catch(\Exception $e) {
  62. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  63. }
  64. }
  65. else{
  66. //物理删除
  67. try {
  68. self::where('id', $id)->delete();
  69. add_log('delete', $id);
  70. } catch(\Exception $e) {
  71. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  72. }
  73. }
  74. return to_assign();
  75. }
  76. }