userlogic.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /*
  3. * @Author: wang jun
  4. * @Date: 2022-01-18 11:12:23
  5. * @Last Modified by: wang jun
  6. * @Last Modified time: 2022-01-19 15:48:53
  7. * 微信类
  8. */
  9. namespace app\index\logic;
  10. use app\index\model\usermodel;
  11. class userlogic extends baselogic
  12. {
  13. /**
  14. * 设置请求数据规则
  15. * 20220107
  16. * wj
  17. */
  18. protected function setrules()
  19. {
  20. $list = [
  21. 'newinfo' => [
  22. ['name' => 'openid', 'title' => 'openid', 'require' => true, 'type' => 'string'],
  23. ],
  24. 'realauthbyopenid' => [
  25. ['name' => 'openid', 'title' => 'openid', 'require' => true, 'type' => 'string'],
  26. ],
  27. 'updateiscompanybyopenid' => [
  28. ['name' => 'openid', 'title' => 'openid', 'require' => true, 'type' => 'string'],
  29. ],
  30. 'getfieldbyopenid' => [
  31. ['name' => 'openid', 'title' => 'openid', 'require' => true, 'type' => 'string'],
  32. ],
  33. ];
  34. return $list;
  35. }
  36. /**
  37. * 新建用户
  38. * wj
  39. * 20220118
  40. */
  41. public function newinfo($arr)
  42. {
  43. $result = $this->checkparam(__FUNCTION__, $arr);
  44. if (1 != $result['status']) {
  45. return $result;
  46. }
  47. $openid = $arr['openid'];
  48. $m_u = new usermodel();
  49. $uinfo = $m_u->getinfobyopenid($openid);
  50. if (!empty($uinfo)) {
  51. $id = $uinfo['id'];
  52. } else {
  53. $id = $m_u->insertData($arr);
  54. }
  55. if (empty($id)) {
  56. return backarr(0, "新增失败");
  57. }
  58. return backarr(1, "新增成功", ['id' => $id]);
  59. }
  60. /**
  61. * 实名认证
  62. * wj
  63. * 20220118
  64. */
  65. public function realauthbyopenid($arr)
  66. {
  67. $result = $this->checkparam(__FUNCTION__, $arr);
  68. if (1 != $result['status']) {
  69. return $result;
  70. }
  71. $openid = $arr['openid'];
  72. $m_u = new usermodel();
  73. $info = $m_u->getinfobyopenid($openid);
  74. if (empty($info)) {
  75. return backarr(0, '无用户');
  76. }
  77. $id = $info['id'];
  78. if (isset($arr['sfzid']) && !empty($arr['sfzid']) && is_string($arr['sfzid'])) {
  79. $sfzid = $arr['sfzid'];
  80. if ($info['sfzid'] != $sfzid) {
  81. $hassfzid = $this->hassfzid($sfzid);
  82. if ($hassfzid) {
  83. return backarr(0, '身份证已存在');
  84. }
  85. }
  86. }
  87. if (isset($arr['telno']) && !empty($arr['telno']) && is_string($arr['telno'])) {
  88. if (!isMoblid($arr['telno'])) {
  89. return backarr(0, '手机号格式错误');
  90. }
  91. $telno = $arr['telno'];
  92. if ($info['telno'] != $telno) {
  93. $hastelno = $this->hastelno($telno);
  94. if ($hastelno) {
  95. return backarr(0, '手机号已存在');
  96. }
  97. }
  98. }
  99. $updateField = ['user_name', 'telno', 'age', 'gender', 'sfzid', 'email'];
  100. $updateData = [];
  101. foreach ($updateField as $key => $value) {
  102. if (isset($arr[$value])) {
  103. if ($info[$value] != $arr[$value]) {
  104. $updateData[$value] = $arr[$value];
  105. }
  106. }
  107. }
  108. if (empty($updateData)) {
  109. return backarr(0, "无修改数据");
  110. }
  111. $row = $m_u->updatebyid($id, $updateData);
  112. if (empty($row)) {
  113. return backarr(0, "修改失败");
  114. }
  115. return backarr(1, "修改成功", ['id' => $id]);
  116. }
  117. /**
  118. * 验证身份证号
  119. */
  120. private function hassfzid($sfzid)
  121. {
  122. $m_u = new usermodel();
  123. $info = $m_u->getinfobysfzid($sfzid);
  124. return !empty($info);
  125. }
  126. /**
  127. * 验证手机号
  128. */
  129. private function hastelno($telno)
  130. {
  131. $m_u = new usermodel();
  132. $info = $m_u->getinfobytelno($telno);
  133. return !empty($info);
  134. }
  135. /**
  136. * 修改iscompany
  137. * wj
  138. * 20220118
  139. */
  140. public function updateiscompanybyopenid($arr)
  141. {
  142. $result = $this->checkparam(__FUNCTION__, $arr);
  143. if (1 != $result['status']) {
  144. return $result;
  145. }
  146. $openid = $arr['openid'];
  147. $m_u = new usermodel();
  148. $info = $m_u->getinfobyopenid($openid);
  149. if (empty($info)) {
  150. return backarr(0, '无用户');
  151. }
  152. $m_u->updateiscompanybyopenid($openid, 1);
  153. return backarr(1, '修改成功', ['id' => $info['id']]);
  154. }
  155. /**
  156. * 获取数据根据openid
  157. * wj
  158. * 20220118
  159. */
  160. public function getfieldbyopenid($arr)
  161. {
  162. $result = $this->checkparam(__FUNCTION__, $arr);
  163. if (1 != $result['status']) {
  164. return $result;
  165. }
  166. $openid = $arr['openid'];
  167. $m_u = new usermodel();
  168. $field = ["id", "user_name", "telno", "gender", "age", "email", "is_active", "is_company"];
  169. $info = $m_u->getfieldbyopenid($openid, $field);
  170. if (empty($info)) {
  171. return backarr(0, '无用户');
  172. }
  173. return backarr(1, '查询成功', $info);
  174. }
  175. }