userlogic.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 13:31:28
  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. ];
  31. return $list;
  32. }
  33. /**
  34. * 新建用户
  35. * wj
  36. * 20220118
  37. */
  38. public function newinfo($arr)
  39. {
  40. $result = $this->checkparam(__FUNCTION__, $arr);
  41. if (1 != $result['status']) {
  42. return $result;
  43. }
  44. $openid = $arr['openid'];
  45. $m_u = new usermodel();
  46. $uinfo = $m_u->getinfobyopenid($openid);
  47. if (!empty($uinfo)) {
  48. $id = $uinfo['id'];
  49. } else {
  50. $id = $m_u->insertData($arr);
  51. }
  52. if (empty($id)) {
  53. return backarr(0, "新增失败");
  54. }
  55. return backarr(1, "新增成功", ['id' => $id]);
  56. }
  57. /**
  58. * 实名认证
  59. * wj
  60. * 20220118
  61. */
  62. public function realauthbyopenid($arr)
  63. {
  64. $result = $this->checkparam(__FUNCTION__, $arr);
  65. if (1 != $result['status']) {
  66. return $result;
  67. }
  68. $openid = $arr['openid'];
  69. $m_u = new usermodel();
  70. $info = $m_u->getinfobyopenid($openid);
  71. if (empty($info)) {
  72. return backarr(0, '无用户');
  73. }
  74. $id = $info['id'];
  75. if (isset($arr['sfzid']) && !empty($arr['sfzid']) && is_string($arr['sfzid'])) {
  76. $sfzid = $arr['sfzid'];
  77. if ($info['sfzid'] != $sfzid) {
  78. $hassfzid = $this->hassfzid($sfzid);
  79. if ($hassfzid) {
  80. return backarr(0, '身份证已存在');
  81. }
  82. }
  83. }
  84. if (isset($arr['telno']) && !empty($arr['telno']) && is_string($arr['telno'])) {
  85. if (!isMoblid($arr['telno'])) {
  86. return backarr(0, '手机号格式错误');
  87. }
  88. $telno = $arr['telno'];
  89. if ($info['telno'] != $telno) {
  90. $hastelno = $this->hastelno($telno);
  91. if ($hastelno) {
  92. return backarr(0, '手机号已存在');
  93. }
  94. }
  95. }
  96. $updateField = ['user_name', 'telno', 'age', 'gender', 'sfzid', 'email'];
  97. $updateData = [];
  98. foreach ($updateField as $key => $value) {
  99. if (isset($arr[$value])) {
  100. if ($info[$value] != $arr[$value]) {
  101. $updateData[$value] = $arr[$value];
  102. }
  103. }
  104. }
  105. if (empty($updateData)) {
  106. return backarr(0, "无修改数据");
  107. }
  108. $row = $m_u->updatebyid($id, $updateData);
  109. if (empty($row)) {
  110. return backarr(0, "修改失败");
  111. }
  112. return backarr(1, "修改成功", ['id' => $id]);
  113. }
  114. /**
  115. * 验证身份证号
  116. */
  117. private function hassfzid($sfzid)
  118. {
  119. $m_u = new usermodel();
  120. $info = $m_u->getinfobysfzid($sfzid);
  121. return !empty($info);
  122. }
  123. /**
  124. * 验证手机号
  125. */
  126. private function hastelno($telno)
  127. {
  128. $m_u = new usermodel();
  129. $info = $m_u->getinfobytelno($telno);
  130. return !empty($info);
  131. }
  132. /**
  133. * 修改iscompany
  134. * wj
  135. * 20220118
  136. */
  137. public function updateiscompanybyopenid($arr)
  138. {
  139. $result = $this->checkparam(__FUNCTION__, $arr);
  140. if (1 != $result['status']) {
  141. return $result;
  142. }
  143. $openid = $arr['openid'];
  144. $m_u = new usermodel();
  145. $info = $m_u->getinfobyopenid($openid);
  146. if (empty($info)) {
  147. return backarr(0, '无用户');
  148. }
  149. $m_u->updateiscompanybyopenid($openid, 1);
  150. return backarr(1, '修改成功', ['id' => $info['id']]);
  151. }
  152. }