userlogic.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. 'getfieldbyid'=>[
  34. ['name' => 'userid', 'title' => 'userid', 'require' => true, 'type' => 'string'],
  35. ]
  36. ];
  37. return $list;
  38. }
  39. /**
  40. * 新建用户
  41. * wj
  42. * 20220118
  43. */
  44. public function newinfo($arr)
  45. {
  46. $result = $this->checkparam(__FUNCTION__, $arr);
  47. if (1 != $result['status']) {
  48. return $result;
  49. }
  50. $openid = $arr['openid'];
  51. $m_u = new usermodel();
  52. $uinfo = $m_u->getinfobyopenid($openid);
  53. if (!empty($uinfo)) {
  54. $id = $uinfo['id'];
  55. } else {
  56. $id = $m_u->insertData($arr);
  57. }
  58. if (empty($id)) {
  59. return backarr(0, "新增失败");
  60. }
  61. return backarr(1, "新增成功", ['id' => $id]);
  62. }
  63. /**
  64. * 实名认证
  65. * wj
  66. * 20220118
  67. */
  68. public function realauthbyopenid($arr)
  69. {
  70. $result = $this->checkparam(__FUNCTION__, $arr);
  71. if (1 != $result['status']) {
  72. return $result;
  73. }
  74. $openid = $arr['openid'];
  75. $m_u = new usermodel();
  76. $info = $m_u->getinfobyopenid($openid);
  77. if (empty($info)) {
  78. return backarr(0, '无用户');
  79. }
  80. $id = $info['id'];
  81. if (isset($arr['sfzid']) && !empty($arr['sfzid']) && is_string($arr['sfzid'])) {
  82. $sfzid = $arr['sfzid'];
  83. if ($info['sfzid'] != $sfzid) {
  84. $hassfzid = $this->hassfzid($sfzid);
  85. if ($hassfzid) {
  86. return backarr(0, '身份证已存在');
  87. }
  88. }
  89. }
  90. if (isset($arr['telno']) && !empty($arr['telno']) && is_string($arr['telno'])) {
  91. if (!isMoblid($arr['telno'])) {
  92. return backarr(0, '手机号格式错误');
  93. }
  94. $telno = $arr['telno'];
  95. if ($info['telno'] != $telno) {
  96. $hastelno = $this->hastelno($telno);
  97. if ($hastelno) {
  98. return backarr(0, '手机号已存在');
  99. }
  100. }
  101. }
  102. $updateField = ['user_name', 'telno', 'age', 'gender', 'sfzid', 'email'];
  103. $updateData = [];
  104. foreach ($updateField as $key => $value) {
  105. if (isset($arr[$value])) {
  106. if ($info[$value] != $arr[$value]) {
  107. $updateData[$value] = $arr[$value];
  108. }
  109. }
  110. }
  111. if (empty($updateData)) {
  112. return backarr(0, "无修改数据");
  113. }
  114. $row = $m_u->updatebyid($id, $updateData);
  115. if (empty($row)) {
  116. return backarr(0, "修改失败");
  117. }
  118. return backarr(1, "修改成功", ['id' => $id]);
  119. }
  120. /**
  121. * 验证身份证号
  122. */
  123. private function hassfzid($sfzid)
  124. {
  125. $m_u = new usermodel();
  126. $info = $m_u->getinfobysfzid($sfzid);
  127. return !empty($info);
  128. }
  129. /**
  130. * 验证手机号
  131. */
  132. private function hastelno($telno)
  133. {
  134. $m_u = new usermodel();
  135. $info = $m_u->getinfobytelno($telno);
  136. return !empty($info);
  137. }
  138. /**
  139. * 修改iscompany
  140. * wj
  141. * 20220118
  142. */
  143. public function updateiscompanybyopenid($arr)
  144. {
  145. $result = $this->checkparam(__FUNCTION__, $arr);
  146. if (1 != $result['status']) {
  147. return $result;
  148. }
  149. $openid = $arr['openid'];
  150. $m_u = new usermodel();
  151. $info = $m_u->getinfobyopenid($openid);
  152. if (empty($info)) {
  153. return backarr(0, '无用户');
  154. }
  155. $m_u->updateiscompanybyopenid($openid, 1);
  156. return backarr(1, '修改成功', ['id' => $info['id']]);
  157. }
  158. /**
  159. * 获取数据根据openid
  160. * wj
  161. * 20220118
  162. */
  163. public function getfieldbyopenid($arr)
  164. {
  165. $result = $this->checkparam(__FUNCTION__, $arr);
  166. if (1 != $result['status']) {
  167. return $result;
  168. }
  169. $openid = $arr['openid'];
  170. $m_u = new usermodel();
  171. $field = ["id", "user_name", "telno", "gender", "age", "email", "is_active", "is_company"];
  172. $info = $m_u->getfieldbyopenid($openid, $field);
  173. if (empty($info)) {
  174. return backarr(0, '无用户');
  175. }
  176. return backarr(1, '查询成功', $info);
  177. }
  178. /**
  179. * 获取数据根据openid
  180. * wj
  181. * 20220118
  182. */
  183. public function getfieldbyid($arr)
  184. {
  185. $result = $this->checkparam(__FUNCTION__, $arr);
  186. if (1 != $result['status']) {
  187. return $result;
  188. }
  189. $userid = $arr['userid'];
  190. $m_u = new usermodel();
  191. $field = ["id", "user_name", "telno", "gender", "age", "email", "is_active", "is_company"];
  192. $info = $m_u->getfieldbyid($userid, $field);
  193. if (empty($info)) {
  194. return backarr(0, '无用户');
  195. }
  196. return backarr(1, '查询成功', $info);
  197. }
  198. }