MemberAuth.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class MemberAuth extends BaseMember
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize(); // TODO: Change the autogenerated stub
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/member_auth.lang.php');
  18. }
  19. /**
  20. * 会员升级
  21. *
  22. * @param
  23. * @return
  24. */
  25. public function index()
  26. {
  27. $member_model = model('member');
  28. if (request()->isPost()) {
  29. $member_array = array();
  30. $member_array['member_auth_state'] = 1;
  31. $member_array['member_idcard'] = input('post.member_idcard');
  32. $member_array['member_truename'] = input('post.member_truename');
  33. $member_validate = ds_validate('member');
  34. if (!$member_validate->scene('auth')->check($member_array)) {
  35. ds_json_encode(10001, $member_validate->getError());
  36. }
  37. if (!$this->member_info['member_idcard_image1']) {
  38. ds_json_encode(10001, lang('member_idcard_image1_require'));
  39. }
  40. if (!$this->member_info['member_idcard_image2']) {
  41. ds_json_encode(10001, lang('member_idcard_image2_require'));
  42. }
  43. if (!$this->member_info['member_idcard_image3']) {
  44. ds_json_encode(10001, lang('member_idcard_image3_require'));
  45. }
  46. $res = $this->getIdCardInfo($this->member_info);
  47. if ($res['code'] == 200) {
  48. $info = $res['data'];
  49. if ($member_array['member_idcard'] != $info['idcard'] || $member_array['member_truename'] !== $info['name']) {
  50. ds_json_encode(10001,'您提交的身份信息或身份证照片未通过校验,请仔细核对后提交');
  51. }
  52. } else {
  53. ds_json_encode(10001,$res['msg']);
  54. }
  55. $update = $member_model->editMember(array(array('member_id', '=', $this->member_info['member_id']), array('member_auth_state', 'in', array(0, 2))), $member_array, $this->member_info['member_id']);
  56. $message = $update ? lang('ds_common_save_succ') : lang('ds_common_save_fail');
  57. if ($update) {
  58. ds_json_encode(10000, $message);
  59. } else {
  60. ds_json_encode(10001, $message);
  61. }
  62. }
  63. View::assign('member_info', $this->member_info);
  64. /* 设置买家当前菜单 */
  65. $this->setMemberCurMenu('member_auth');
  66. /* 设置买家当前栏目 */
  67. $this->setMemberCurItem('index');
  68. return View::fetch($this->template_dir . 'index');
  69. }
  70. public function image_upload()
  71. {
  72. $file_name = input('param.id');
  73. if (!empty($_FILES[$file_name]['name'])) {
  74. $res = ds_upload_pic(ATTACH_IDCARD_IMAGE, $file_name);
  75. if (!$res['code']) {
  76. ds_json_encode(10001, $res['msg']);
  77. }
  78. if (!in_array(substr($file_name, 0, 20), array('member_idcard_image1', 'member_idcard_image2', 'member_idcard_image3'))) {
  79. ds_json_encode(10001, lang('param_error'));
  80. }
  81. $member_array = array();
  82. $member_array[substr($file_name, 0, 20)] = $res['data']['file_name'];
  83. $member_model = model('member');
  84. if (!$member_model->editMember(array(array('member_id', '=', $this->member_info['member_id']), array('member_auth_state', 'in', array(0, 2))), $member_array, $this->member_info['member_id'])) {
  85. ds_json_encode(10001, lang('ds_common_save_fail'));
  86. }
  87. ds_json_encode(10000, '', array('file_name' => $res['data']['file_name'], 'file_path' => get_member_idcard_image($res['data']['file_name'])));
  88. }
  89. ds_json_encode(10001, lang('param_error'));
  90. }
  91. public function image_upload2()
  92. {
  93. $file_name = input('param.id');
  94. if (!empty($_FILES[$file_name]['name'])) {
  95. $res = ds_upload_pic(ATTACH_IDCARD_IMAGE, $file_name);
  96. if (!$res['code']) {
  97. ds_json_encode(10001, $res['msg']);
  98. }
  99. if (!in_array(substr($file_name, 0, 20), array('member_idcard_image1', 'member_idcard_image2', 'member_idcard_image3'))) {
  100. ds_json_encode(10001, lang('param_error'));
  101. }
  102. $member_array = array();
  103. $member_array[substr($file_name, 0, 20)] = $res['data']['file_name'];
  104. $member_model = model('member');
  105. // if (!$member_model->editMember(array(array('member_id', '=', $this->member_info['member_id']), array('member_auth_state', 'in', array(0, 2))), $member_array, $this->member_info['member_id'])) {
  106. // ds_json_encode(10001, lang('ds_common_save_fail'));
  107. // }
  108. ds_json_encode(10000, '', array('file_name' => $res['data']['file_name'], 'file_path' => get_member_idcard_image($res['data']['file_name'])));
  109. }
  110. ds_json_encode(10001, lang('param_error'));
  111. }
  112. public function image_drop()
  113. {
  114. $file_name = input('param.file_name');
  115. if (!in_array($file_name, array('member_idcard_image1', 'member_idcard_image2', 'member_idcard_image3'))) {
  116. ds_json_encode(10001, lang('param_error'));
  117. }
  118. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_IDCARD_IMAGE . DIRECTORY_SEPARATOR . $this->member_info[$file_name]);
  119. $member_array = array();
  120. $member_array[$file_name] = '';
  121. $member_model = model('member');
  122. if (!$member_model->editMember(array(array('member_id', '=', $this->member_info['member_id']), array('member_auth_state', 'in', array(0, 2))), $member_array, $this->member_info['member_id'])) {
  123. ds_json_encode(10001, lang('ds_common_save_fail'));
  124. }
  125. ds_json_encode(10000);
  126. }
  127. /**
  128. * 用户中心右边,小导航
  129. *
  130. * @param string $menu_type 导航类型
  131. * @param string $menu_key 当前导航的menu_key
  132. * @return
  133. */
  134. public function getMemberItemList()
  135. {
  136. $menu_array = array(
  137. array(
  138. 'name' => 'index',
  139. 'text' => lang('member_auth'),
  140. 'url' => (string)url('MemberAuth/index')
  141. ),
  142. );
  143. return $menu_array;
  144. }
  145. }