HomeCityModel.class.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace Admin\Model;
  3. use Common\Model\HomeCityModel as HomeCity;
  4. /**
  5. * 官网新闻
  6. * @author: linch
  7. * Class HomeCityModel
  8. * @package Common\Model
  9. */
  10. class HomeCityModel extends HomeCity
  11. {
  12. /**
  13. * 获取列表
  14. * @author: linch
  15. * @param array $search 筛选条件
  16. * @param int $page_num 页码
  17. * @param int $page_size 页行数
  18. * @return array
  19. */
  20. public function get_list($search, $page_num, $page_size) {
  21. $where = array(
  22. 'status' => array('neq', self::status_del),
  23. );
  24. if (!empty($search['name'])) {
  25. $where['name'] = array('like', '%' . trim($search['name']) . '%');
  26. }
  27. $order = 'id desc';
  28. $limit = ($page_num - 1) * $page_size . ' ,' . $page_size;
  29. $field = '*';
  30. $list = $this->where($where)->order($order)->field($field)->limit($limit)->select();
  31. $count = $this->mod->where($where)->count();
  32. $page = $this->x_show($count, $page_size, array());
  33. $data = array(
  34. 'list' => $list,
  35. 'pager' => $page,
  36. );
  37. return $data;
  38. }
  39. /**
  40. * 验证保存数据
  41. * @author: linch
  42. * @param $data
  43. * @return array
  44. */
  45. protected function check_edit_data($data) {
  46. if (empty($data['name'])) {
  47. return array('code' => false, 'msg' => '城市不能为空');
  48. }
  49. return array('code' => true, 'msg' => '数据符合');
  50. }
  51. /**
  52. * 新增数据
  53. * @author: linch
  54. * @param $data
  55. * @return mixed
  56. */
  57. public function data_add($data) {
  58. $time = date('Y-m-d H:i:s');
  59. $save_data = array(
  60. 'name' => trim($data['name']),
  61. 'c_time' => $time,
  62. );
  63. $result = $this->check_edit_data($save_data);
  64. $id = $this->data($save_data)->add();
  65. if ($result == false) { //录入数据库失败
  66. return array('code' => false, 'msg' => '系统出错,请重试');
  67. }
  68. return array('code' => true, 'msg' => '操作成功', 'id' => $id);
  69. }
  70. /**
  71. * 编辑数据
  72. * @author: linch
  73. * @param $data
  74. * @return bool
  75. */
  76. public function data_edit($data) {
  77. $id = intval($data['id']);
  78. $save_data = array(
  79. 'name' => trim($data['name']),
  80. );
  81. $result = $this->check_edit_data($save_data);
  82. if ($result['code'] == false) { //验证的数据不合格
  83. return array('code' => false, 'msg' => $result['msg']);
  84. }
  85. $result = $this->where(array('id' => $id))->data($save_data)->save();
  86. if ($result === false) { //录入数据库失败
  87. return array('code' => false, 'msg' => '系统出错,请重试');
  88. }
  89. return array('code' => true, 'msg' => '操作成功');
  90. }
  91. /**
  92. * 设置删除状态
  93. * @author: linch
  94. * @param $id
  95. * @return bool
  96. */
  97. public function data_del($id) {
  98. $result = $this->where(array('id' => $id))->setField(array('status' => self::status_del));
  99. return $result;
  100. }
  101. }