MemberAuth.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\model\member;
  11. use app\model\BaseModel;
  12. /**
  13. * 实名认证
  14. */
  15. class MemberAuth extends BaseModel
  16. {
  17. //申请状态
  18. private $status = [
  19. 1 => '审核通过',
  20. 0 => '待审核',
  21. -1 => '审核失败',
  22. ];
  23. /**
  24. * 获取实名认证分页列表
  25. *
  26. * @param array $condition
  27. * @param number $page
  28. * @param string $page_size
  29. * @param string $order
  30. * @param string $field
  31. */
  32. public function getMemberAuthPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
  33. {
  34. $list = model('member_auth')->pageList($condition, $field, $order, $page, $page_size, '', '', '');
  35. return $this->success($list);
  36. }
  37. /**
  38. * 获取实名认证列表
  39. *
  40. * @param array $condition
  41. * @param number $page
  42. * @param string $page_size
  43. * @param string $order
  44. * @param string $field
  45. */
  46. public function getMemberAuthList($where = [], $field = true, $order = '', $alias = 'a', $join = [], $group = '', $limit = null)
  47. {
  48. $res = model('member_auth')->getList($where, $field, $order, $alias, $join, $group, $limit);
  49. return $this->success($res);
  50. }
  51. /**
  52. * 获取实名认证信息
  53. * @param array $condition
  54. * @param string $field
  55. * @return unknown
  56. */
  57. public function getMemberAuthInfo($condition = [], $field = '*')
  58. {
  59. $member_info = model('member_auth')->getInfo($condition, $field);
  60. return $this->success($member_info);
  61. }
  62. /**
  63. * 添加实名认证
  64. * @param $data
  65. */
  66. public function add($data)
  67. {
  68. $member_id = isset($data['member_id']) ? $data['member_id'] : '';
  69. if ($member_id === '') {
  70. return $this->error('', 'REQUEST_SITE_ID');
  71. }
  72. $data["create_time"] = time();
  73. $result = model("member_auth")->add($data);
  74. if ($result === false) {
  75. return $this->error('', 'UNKNOW_ERROR');
  76. }
  77. return $this->success($result);
  78. }
  79. /**
  80. * 编辑实名认证
  81. * @param $data
  82. * @param $condition
  83. */
  84. public function edit($data, $condition)
  85. {
  86. $check_condition = array_column($condition, 2, 0);
  87. $member_id = isset($check_condition['member_id']) ? $check_condition['member_id'] : '';
  88. $auth_id = isset($check_condition['auth_id']) ? $check_condition['auth_id'] : '';
  89. if ($member_id === '') {
  90. return $this->error('', '会员ID不能为空');
  91. }
  92. if ($auth_id === '') {
  93. return $this->error('', '实名认证ID不能为空');
  94. }
  95. $res = model("member_auth")->update($data, $condition);
  96. if ($res === false) {
  97. return $this->error('', 'UNKNOW_ERROR');
  98. }
  99. return $this->success($res);
  100. }
  101. /**
  102. * 实名认证 审核通过 后台审核
  103. * @param unknown $auth_id
  104. */
  105. public function authPass($auth_id)
  106. {
  107. // 开启事务
  108. model('member_auth')->startTrans();
  109. try {
  110. //获取实名认证 信息
  111. $member_auth_info = model('member_auth')->getInfo([['auth_id', '=', $auth_id]]);
  112. //获取会员id
  113. $member_id = $member_auth_info['member_id'];
  114. // 会员用户实名修改
  115. model('member')->update(['is_auth' => 1], [['member_id', '=', $member_id]]);
  116. // 会员实名认证通过修改
  117. $res = model('member_auth')->update(['status' => 1, 'audit_time' => time()], [['auth_id', '=', $auth_id]]);
  118. // 事务提交
  119. model('member_auth')->commit();
  120. return $this->success($res);
  121. } catch (\Exception $e) {
  122. // 事务回滚
  123. model('member_auth')->rollback();
  124. return $this->error('', $e->getMessage());
  125. }
  126. }
  127. /**
  128. * 审核拒绝
  129. * @param unknown $auth_id
  130. * @param unknown $reason
  131. */
  132. public function authReject($auth_id, $reason)
  133. {
  134. $res = model('member_auth')->update(['status' => -1, 'remark' => $reason], [['auth_id', '=', $auth_id]]);
  135. return $this->success($res);
  136. }
  137. /**
  138. * 获取实名审核状态
  139. */
  140. public function getAuthStatus()
  141. {
  142. return $this->status;
  143. }
  144. }