usermodel.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. * 根据id获取信息
  77. * wj
  78. * 20220118
  79. */
  80. public function getinfobyid($id)
  81. {
  82. $where = ['id' => $id];
  83. $info = $this->where($where)->find();
  84. return $info;
  85. }
  86. /**
  87. * 根据openid获取信息
  88. * wj
  89. * 20220118
  90. */
  91. public function getinfobyopenid($openid)
  92. {
  93. $where = ['openid' => $openid];
  94. $info = $this->where($where)->find();
  95. return $info;
  96. }
  97. /**
  98. * 根据openid获取信息
  99. * wj
  100. * 20220118
  101. */
  102. public function getfieldbyopenid($openid, $field = "")
  103. {
  104. if (empty($field)) {
  105. $field = ["id", "user_name", "telno", "gender", "age", "email", "is_active", "is_company", "nation", "origin", "address"];
  106. }
  107. $where = ['openid' => $openid];
  108. $info = $this->field($field)->where($where)->find();
  109. return $info;
  110. }
  111. /**
  112. * 根据id获取信息
  113. * wj
  114. * 20220118
  115. */
  116. public function getfieldbyid($id, $field = "")
  117. {
  118. if (empty($field)) {
  119. $field = ["id", "user_name", "telno", "gender", "age", "email", "is_active", "is_company", "nation", "origin", "address"];
  120. }
  121. $where = ['id' => $id];
  122. $info = $this->field($field)->where($where)->find();
  123. return $info;
  124. }
  125. /**
  126. * 根据openid获取信息
  127. * wj
  128. * 20220118
  129. */
  130. public function getinfobysfzid($sfzid)
  131. {
  132. $where = ['sfzid' => $sfzid];
  133. $info = $this->where($where)->find();
  134. return $info;
  135. }
  136. /**
  137. * 根据telno获取信息
  138. * wj
  139. * 20220118
  140. */
  141. public function getinfobytelno($telno)
  142. {
  143. $where = ['telno' => $telno];
  144. $info = $this->where($where)->find();
  145. return $info;
  146. }
  147. /**
  148. * 根据openid获取修改unionid
  149. * wj
  150. * 20220118
  151. */
  152. public function updateunionidbyopenid($openid, $unionid)
  153. {
  154. $where = ['openid' => $openid];
  155. $updateData = ['unionid' => $unionid];
  156. $row = $this->where($where)->update($updateData);
  157. return $row;
  158. }
  159. /**
  160. * 根据openid获取修改iscompany
  161. * wj
  162. * 20220118
  163. */
  164. public function updateiscompanybyopenid($openid, $iscompany = 1)
  165. {
  166. $where = ['openid' => $openid];
  167. $updateData = ['is_company' => $iscompany];
  168. $row = $this->where($where)->update($updateData);
  169. return $row;
  170. }
  171. /**
  172. * 根据id修改数据
  173. * wj
  174. * 20220118
  175. */
  176. public function updatebyid($id, $updateData)
  177. {
  178. $where = ['id' => $id];
  179. $updateData = $this->formatData($updateData);
  180. if (empty($updateData)) {
  181. return false;
  182. }
  183. $row = $this->where($where)->update($updateData);
  184. return $row;
  185. }
  186. }