Institution.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace app\admin\model;
  3. use think\model;
  4. class Institution extends Model
  5. {
  6. /**
  7. * 获取分页列表
  8. * @param $where
  9. * @param $param
  10. */
  11. public function getFinancialList($where, $param)
  12. {
  13. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  14. $order = empty($param['order']) ? 'id desc' : $param['order'];
  15. // halt($order,$rows);
  16. $list = self::where($where)->field('id,financial,name,principal,phone,landline,address')->order($order)->paginate($rows, false, ['query' => $param]);
  17. return $list;
  18. }
  19. /**
  20. * 添加数据
  21. * @param $param
  22. */
  23. public function addFinancial($param)
  24. {
  25. $insertId = 0;
  26. try {
  27. $param['create_time'] = time();
  28. $insertId = self::strict(false)->field(true)->insertGetId($param);
  29. add_log('add', $insertId, $param);
  30. } catch(\Exception $e) {
  31. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  32. }
  33. return to_assign(0,'操作成功',['aid'=>$insertId]);
  34. }
  35. /**
  36. * 编辑信息
  37. * @param $param
  38. */
  39. public function editFinancial($param)
  40. {
  41. try {
  42. $param['update_time'] = time();
  43. self::where('id', $param['id'])->strict(false)->field(true)->update($param);
  44. add_log('edit', $param['id'], $param);
  45. } catch(\Exception $e) {
  46. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  47. }
  48. return to_assign();
  49. }
  50. /**
  51. * 根据id获取信息
  52. * @param $id
  53. */
  54. public function getFinancialById($id)
  55. {
  56. $info = self::where('id', $id)->find();
  57. return $info;
  58. }
  59. /**
  60. * 删除信息
  61. * @param $id
  62. * @return array
  63. */
  64. public function delFinancialById($id,$type=0)
  65. {
  66. if($type==0){
  67. //逻辑删除
  68. try {
  69. $param['delete_time'] = time();
  70. self::where('id', $id)->update(['delete_time'=>time()]);
  71. add_log('delete', $id);
  72. } catch(\Exception $e) {
  73. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  74. }
  75. }
  76. else{
  77. //物理删除
  78. try {
  79. self::where('id', $id)->delete();
  80. add_log('delete', $id);
  81. } catch(\Exception $e) {
  82. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  83. }
  84. }
  85. return to_assign();
  86. }
  87. }