userlogic.php 4.1 KB

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