usermodel.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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-19 15:42:39
  7. */
  8. namespace app\index\model;
  9. use think\Model;
  10. class usermodel extends Model
  11. {
  12. protected $table = 't_users';
  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. $data = $this->formatData($data);
  19. if (empty($data)) {
  20. return false;
  21. }
  22. $id = $this->insertGetId($data);
  23. return empty($id) ? false : $id;
  24. }
  25. /**
  26. * 校验入库数据
  27. * 20220119
  28. */
  29. private function formatData($data)
  30. {
  31. $useData = [];
  32. $fields = $this->getTableFields();
  33. foreach ($data as $key => $value) {
  34. if (in_array($key, $fields)) {
  35. $useData[$key] = $value;
  36. }
  37. }
  38. return $useData;
  39. }
  40. public function getInfo($where, $field = "*", $row = true)
  41. {
  42. $info = $this->field($field)->where($where);
  43. if ($row) {
  44. $info = $info->find();
  45. } else {
  46. $info = $info->select();
  47. }
  48. return empty($info) ? false : $info;
  49. }
  50. public function updateinfo($where, $updateData)
  51. {
  52. $row = $this->where($where)->update($updateData);
  53. return empty($row) ? false : $row;
  54. }
  55. public function deleteinfo($where)
  56. {
  57. $row = $this->where($where)->delete();
  58. return empty($row) ? false : $row;
  59. }
  60. public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
  61. {
  62. $sqlObj = $this->where($where);
  63. if ("count" != $field) {
  64. $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
  65. if ($row) {
  66. $data = $sqlObj->find();
  67. } else {
  68. $data = $sqlObj->select();
  69. }
  70. } else {
  71. $data = $sqlObj = $sqlObj->count();
  72. }
  73. return $data;
  74. }
  75. /**
  76. * 根据openid获取信息
  77. * wj
  78. * 20220118
  79. */
  80. public function getinfobyopenid($openid)
  81. {
  82. $where = ['openid' => $openid];
  83. $info = $this->where($where)->find();
  84. return $info;
  85. }
  86. /**
  87. * 根据openid获取信息
  88. * wj
  89. * 20220118
  90. */
  91. public function getfieldbyopenid($openid, $field = "")
  92. {
  93. $where = ['openid' => $openid];
  94. $info = $this->field($field)->where($where)->find();
  95. return $info;
  96. }
  97. /**
  98. * 根据openid获取信息
  99. * wj
  100. * 20220118
  101. */
  102. public function getinfobysfzid($sfzid)
  103. {
  104. $where = ['sfzid' => $sfzid];
  105. $info = $this->where($where)->find();
  106. return $info;
  107. }
  108. /**
  109. * 根据telno获取信息
  110. * wj
  111. * 20220118
  112. */
  113. public function getinfobytelno($telno)
  114. {
  115. $where = ['telno' => $telno];
  116. $info = $this->where($where)->find();
  117. return $info;
  118. }
  119. /**
  120. * 根据openid获取修改unionid
  121. * wj
  122. * 20220118
  123. */
  124. public function updateunionidbyopenid($openid, $unionid)
  125. {
  126. $where = ['openid' => $openid];
  127. $updateData = ['unionid' => $unionid];
  128. $row = $this->where($where)->update($updateData);
  129. return $row;
  130. }
  131. /**
  132. * 根据openid获取修改iscompany
  133. * wj
  134. * 20220118
  135. */
  136. public function updateiscompanybyopenid($openid, $iscompany = 1)
  137. {
  138. $where = ['openid' => $openid];
  139. $updateData = ['is_company' => $iscompany];
  140. $row = $this->where($where)->update($updateData);
  141. return $row;
  142. }
  143. /**
  144. * 根据id修改数据
  145. * wj
  146. * 20220118
  147. */
  148. public function updatebyid($id, $updateData)
  149. {
  150. $where = ['id' => $id];
  151. $updateData = $this->formatData($updateData);
  152. if (empty($updateData)) {
  153. return false;
  154. }
  155. $row = $this->where($where)->update($updateData);
  156. return $row;
  157. }
  158. }