wxuserlogic.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace app\index\logic;
  3. use app\common\model\wxusermodel;
  4. /**
  5. * 微信用户类
  6. *
  7. * @author wj
  8. * @date 2022-07-22
  9. */
  10. class wxuserlogic extends baselogic
  11. {
  12. /**
  13. * 设置请求数据规则
  14. * 20220107
  15. * wj
  16. */
  17. protected function setrules()
  18. {
  19. $list = [
  20. /*'getinfobyopenid' => [
  21. ['name' => 'openid', 'title' => 'openid', 'require' => true, 'type' => 'string'],
  22. ],*/
  23. 'saveinfo' => [
  24. ['name' => 'openid', 'title' => 'openid', 'require' => true, 'type' => 'string'],
  25. ['name' => 'sfzid', 'title' => '身份证号', 'require' => true, 'type' => 'string'],
  26. ['name' => 'real_name', 'title' => '真实姓名', 'require' => true, 'type' => 'string'],
  27. ['name' => 'union_id', 'title' => 'union_id', 'require' => false, 'type' => 'string'],
  28. ['name' => 'nick_name', 'title' => '昵称', 'require' => false, 'type' => 'string'],
  29. ['name' => 'avatar_url', 'title' => '头像', 'require' => false, 'type' => 'string'],
  30. ['name' => 'gender', 'title' => '性别', 'require' => false, 'type' => 'string'],
  31. ['name' => 'province', 'title' => '省', 'require' => false, 'type' => 'string'],
  32. ['name' => 'city', 'title' => '市', 'require' => false, 'type' => 'string'],
  33. ['name' => 'country', 'title' => '县', 'require' => false, 'type' => 'string'],
  34. ['name' => 'telno', 'title' => '手机号', 'require' => false, 'type' => 'string'],
  35. ['name' => 'address', 'title' => '地址', 'require' => false, 'type' => 'string'],
  36. ],
  37. ];
  38. return $list;
  39. }
  40. /**
  41. * 根据openid获取信息
  42. *
  43. * @param [type] $arr
  44. * @return void
  45. * @author wj
  46. * @date 2022-07-22
  47. */
  48. /*public function getinfobyopenid($arr)
  49. {
  50. $result = $this->checkparam(__FUNCTION__, $arr);
  51. if (1 != $result['status']) {
  52. return $result;
  53. }
  54. $data = $result['data'];
  55. $openid = $data['openid'];
  56. $m_wu = new wxusermodel();
  57. $info = $m_wu->getinfobyopenid($openid);
  58. if (empty($info)) {
  59. return backarr(0, "无用户信息");
  60. }
  61. return backarr(1, "success", $info);
  62. }*/
  63. /**
  64. * 保存用户信息
  65. *
  66. * @param [type] $arr
  67. * @return void
  68. * @author wj
  69. * @date 2022-07-22
  70. */
  71. public function saveinfo($arr)
  72. {
  73. $result = $this->checkparam(__FUNCTION__, $arr);
  74. if (1 != $result['status']) {
  75. return $result;
  76. }
  77. $data = $result['data'];
  78. $m_wu = new wxusermodel();
  79. $id = $m_wu->insertData($data);
  80. if (empty($id)) {
  81. return backarr(0, "添加失败");
  82. }
  83. return backarr(1, "添加成功", ['id' => $id]);
  84. }
  85. }