appointmentmodel.php 4.1 KB

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