appointmentmodel.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. namespace app\index\model;
  3. use think\Model;
  4. /**
  5. * 登记记录表
  6. *
  7. * @author wj
  8. * @date 2022-07-22
  9. */
  10. class appointmentmodel extends Model
  11. {
  12. public function insertData($data)
  13. {
  14. if (!isset($data['oprdate']) || empty($data['oprdate']) || !is_string($data['oprdate'])) {
  15. $data['oprdate'] = date("Y-m-d H:i:s");
  16. }
  17. if (isset($data['id'])) {
  18. unset($data['id']);
  19. }
  20. $data = $this->formatData($data);
  21. if (empty($data)) {
  22. return false;
  23. }
  24. $id = $this->insertGetId($data);
  25. return $id ? $id : false;
  26. }
  27. /**
  28. * 校验入库数据
  29. * 20220119
  30. */
  31. private function formatData($data)
  32. {
  33. $useData = [];
  34. $fields = $this->getTableFields();
  35. foreach ($data as $key => $value) {
  36. if (in_array($key, $fields)) {
  37. $useData[$key] = $value;
  38. }
  39. }
  40. return $useData;
  41. }
  42. public function getInfo($where, $field = "*", $row = true)
  43. {
  44. $info = $this->field($field)->where($where);
  45. if ($row) {
  46. $info = $info->find();
  47. } else {
  48. $info = $info->select();
  49. }
  50. return empty($info) ? false : $info;
  51. }
  52. public function updateinfo($where, $updateData)
  53. {
  54. $row = $this->where($where)->update($updateData);
  55. return empty($row) ? false : $row;
  56. }
  57. public function deleteinfo($where)
  58. {
  59. $row = $this->where($where)->delete();
  60. return empty($row) ? false : $row;
  61. }
  62. public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
  63. {
  64. $sqlObj = $this->where($where);
  65. if ("count" != $field) {
  66. $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
  67. if ($row) {
  68. $data = $sqlObj->find();
  69. } else {
  70. $data = $sqlObj->select();
  71. }
  72. } else {
  73. $data = $sqlObj = $sqlObj->count();
  74. }
  75. return $data;
  76. }
  77. /**
  78. * 根据id获取信息
  79. * wj
  80. * 20220118
  81. */
  82. public function getinfobyid($id)
  83. {
  84. $where = ['id' => $id];
  85. $info = $this->where($where)->find();
  86. return $info;
  87. }
  88. /**
  89. * 根据code获取信息
  90. * wj
  91. * 20220118
  92. */
  93. public function getinfobycode($code)
  94. {
  95. $where = ['code' => $code];
  96. $info = $this->where($where)->find();
  97. return $info ? $info : false;
  98. }
  99. /**
  100. * 根据id修改数据
  101. * wj
  102. * 20220118
  103. */
  104. public function updatebyid($id, $updateData)
  105. {
  106. $where = ['id' => $id];
  107. $updateData = $this->formatData($updateData);
  108. if (empty($updateData)) {
  109. return false;
  110. }
  111. $row = $this->where($where)->update($updateData);
  112. return $row;
  113. }
  114. /**
  115. * 获取最后一条可用数据
  116. *
  117. * @param [type] $wid
  118. * @return void
  119. * @author wj
  120. * @date 2022-07-22
  121. */
  122. public function getlastinfo($where)
  123. {
  124. $usewhere = ['isuse' => 0, 'ispay' => 1, 'oprdate' => ['>=', date("Y-m-d 00:00:00")]];
  125. if (isset($where['wid'])) {
  126. $usewhere['wid'] = $where['wid'];
  127. }
  128. if (isset($where['openid'])) {
  129. $usewhere['openid'] = $where['openid'];
  130. }
  131. if (isset($where['code'])) {
  132. $usewhere['code'] = $where['openid'];
  133. }
  134. if (isset($where['sfzid'])) {
  135. $usewhere['sfzid'] = $where['sfzid'];
  136. }
  137. $info = $this->where($usewhere)->find();
  138. return $info ? $info : false;
  139. }
  140. /**
  141. * 获取申请编码
  142. *
  143. * @return void
  144. * @author wj
  145. * @date 2022-07-22
  146. */
  147. public function createcode($str)
  148. {
  149. $code = substr($str, 0, 4) . date("YmdHis");
  150. return $code;
  151. }
  152. }