Contact.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\admin\model;
  3. use think\model;
  4. use think\facade\Db;
  5. class Contact extends Model
  6. {
  7. protected $table = 'cp_contact';
  8. // protected $autoWriteTimestamp = true;
  9. // public function getAuditStatusAttr($value){
  10. // $status = [
  11. // 0 => '未审核',
  12. // 1 => '未通过',
  13. // 2 => '已通过',
  14. // ];
  15. // return $status[$value];
  16. // }
  17. /**
  18. * 添加数据
  19. * @param $param
  20. */
  21. public function addContact($param)
  22. {
  23. $insertId = 0;
  24. try {
  25. $param['create_time'] = time();
  26. $insertId = $this->strict(false)->field(true)->insertGetId($param);
  27. add_log('add', $insertId, $param);
  28. } catch (\Exception $e) {
  29. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  30. }
  31. return to_assign(0, '操作成功', ['aid' => $insertId]);
  32. }
  33. /**
  34. * 编辑信息
  35. * @param $param
  36. */
  37. public function editReport($param)
  38. {
  39. try {
  40. $param['update_time'] = time();
  41. $this->where('id', $param['id'])->strict(false)->field(true)->update($param);
  42. add_log('edit', $param['id'], $param);
  43. } catch (\Exception $e) {
  44. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  45. }
  46. return to_assign();
  47. }
  48. /**
  49. * 根据id获取信息
  50. * @param $id
  51. */
  52. public function getContactById($id)
  53. {
  54. $info = $this->where('id', $id)->find();
  55. return $info;
  56. }
  57. /**
  58. * 删除信息
  59. * @param $id
  60. * @return array
  61. */
  62. public function delContactById($id, $type = 0)
  63. {
  64. if ($type == 0) {
  65. //逻辑删除
  66. try {
  67. $param['delete_time'] = time();
  68. $this->where('id', $id)->update(['delete_time' => time()]);
  69. add_log('delete', $id);
  70. } catch (\Exception $e) {
  71. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  72. }
  73. } else {
  74. //物理删除
  75. try {
  76. $this->where('id', $id)->delete();
  77. add_log('delete', $id);
  78. } catch (\Exception $e) {
  79. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  80. }
  81. }
  82. return to_assign();
  83. }
  84. public function detail($id)
  85. {
  86. $detail = Db::name('Contact')->where(['id' => $id])->find();
  87. $detail["maker_name"] = get_admin($detail["maker_id"])["nickname"];
  88. return $detail;
  89. }
  90. }