companymodel.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /*
  3. * @Author: wang jun
  4. * @Date: 2022-01-18 09:43:33
  5. * @Last Modified by: wang jun
  6. * @Last Modified time: 2022-01-18 16:58:11
  7. */
  8. namespace app\index\model;
  9. use think\Model;
  10. class companymodel extends Model
  11. {
  12. protected $table = 't_company';
  13. public function insertData($data)
  14. {
  15. if (!isset($data['create_time']) || empty($data['create_time']) || !is_string($data['create_time'])) {
  16. $data['create_time'] = date("Y-m-d H:i:s");
  17. }
  18. $id = $this->insertGetId($data);
  19. return empty($id) ? false : $id;
  20. }
  21. public function getInfo($where, $field = "*", $row = true)
  22. {
  23. $info = $this->field($field)->where($where);
  24. if ($row) {
  25. $info = $info->find();
  26. } else {
  27. $info = $info->select();
  28. }
  29. return empty($info) ? false : $info;
  30. }
  31. public function updateinfo($where, $updateData)
  32. {
  33. $row = $this->where($where)->update($updateData);
  34. return empty($row) ? false : $row;
  35. }
  36. public function deleteinfo($where)
  37. {
  38. $row = $this->where($where)->delete();
  39. return empty($row) ? false : $row;
  40. }
  41. public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
  42. {
  43. $sqlObj = $this->where($where);
  44. if ("count" != $field) {
  45. $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
  46. if ($row) {
  47. $data = $sqlObj->find();
  48. } else {
  49. $data = $sqlObj->select();
  50. }
  51. } else {
  52. $data = $sqlObj = $sqlObj->count();
  53. }
  54. return $data;
  55. }
  56. /**
  57. * 根据id获取信息
  58. * wj
  59. * 20220118
  60. */
  61. public function getinfobyid($id)
  62. {
  63. $where = ['id' => $id];
  64. $info = $this->where($where)->find();
  65. return $info;
  66. }
  67. /**
  68. * 根据id修改数据
  69. * wj
  70. * 20220118
  71. */
  72. public function updatebyid($id, $updateData)
  73. {
  74. $where = ['id' => $id];
  75. $row = $this->where($where)->update($updateData);
  76. return $row;
  77. }
  78. }