SettleVerifiedOut.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * SettleVerifiedOut.php UTF-8
  4. * 提现实名认证
  5. *
  6. * @date : 2018/10/13 16:07
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling <cbl@huosdk.com>
  10. * @version : Huomp 1.0
  11. */
  12. namespace huomp\controller\finance;
  13. use huo\controller\common\Base;
  14. use huo\controller\member\MemCache;
  15. use huo\controller\wap\Option;
  16. use huo\model\finance\SettleModel;
  17. use huo\model\member\MemberModel;
  18. use huolib\constant\CacheConst;
  19. use huolib\constant\CommonConst;
  20. use huolib\constant\OptionConst;
  21. use huolib\status\CommonStatus;
  22. use huolib\status\IdentifyStatus;
  23. use huolib\status\MemberStatus;
  24. use huolib\tool\StrUtils;
  25. use think\Cache;
  26. class SettleVerifiedOut extends Base {
  27. public function getVerifiedCfg() {
  28. /* 获取实名认证配置 */
  29. $_settle_set = OptionConst::SETTING_SETTLE_VERIFIED;
  30. $_settle_set_item = (new Option())->getOptionData($_settle_set);
  31. $_verified = [
  32. 'is_verified' => CommonConst::STATUS_NO, //是否需要实名 1 不需要 2需要
  33. 'first_verified' => CommonConst::STATUS_NO, //首单是否需要实名 1 不需要 2需要
  34. 'mobile_must' => CommonConst::STATUS_NO, //手机号是否必填 1 不需要 2需要
  35. ];
  36. if (!empty($_settle_set_item['option_value'])) {
  37. $_option_value = json_decode($_settle_set_item['option_value'], true);
  38. $_verified = array_merge($_verified, $_option_value);
  39. }
  40. return $_verified;
  41. }
  42. /**
  43. * 判断是否实名
  44. *
  45. * @param $mem_id
  46. * @param $agent_id
  47. * @param $real_name
  48. * @param $mobile
  49. *
  50. * @return array
  51. */
  52. public function isVerified($mem_id, $agent_id, $real_name, $mobile) {
  53. $_verified = $this->getVerifiedCfg();
  54. /* 不需要实名直接返回 */
  55. if (CommonConst::STATUS_NO == $_verified['is_verified']) {
  56. $_code = CommonStatus::NO_ERROR;
  57. return $this->huoError($_code, CommonStatus::getMsg($_code), []);
  58. }
  59. /* 首次不需要实名,判断是首次则直接返回 */
  60. if (CommonConst::STATUS_NO == $_verified['first_verified']) {
  61. $_withdraw_cnt = (new SettleModel())->getCnt($agent_id);
  62. if (empty($_withdraw_cnt)) {
  63. $_code = CommonStatus::NO_ERROR;
  64. return $this->huoError($_code, CommonStatus::getMsg($_code), []);
  65. }
  66. }
  67. /* 实名是否手机号必填 */
  68. if (CommonConst::STATUS_YES == $_verified['mobile_must']) {
  69. if (empty($mobile)) {
  70. $_code = MemberStatus::PHONE_EMPTY;
  71. return $this->huoError($_code, MemberStatus::getMsg($_code), []);
  72. }
  73. $_rs = StrUtils::checkPhone($mobile);
  74. if (false == $_rs) {
  75. $_code = MemberStatus::PHONE_ERROR;
  76. return $this->huoError($_code, MemberStatus::getMsg($_code), []);
  77. }
  78. $_mobile_mem_id = (new MemberModel())->where(['mobile' => $mobile])->value('id');
  79. if (!empty($_mobile_mem_id) && $mem_id != $_mobile_mem_id) {
  80. $_code = MemberStatus::PHONE_IS_BIND;
  81. return $this->huoError($_code, MemberStatus::getMsg($_code), []);
  82. }
  83. }
  84. if (empty($real_name)) {
  85. $_code = IdentifyStatus::REALNAME_EMPTY;
  86. return $this->huoError($_code, IdentifyStatus::getMsg($_code), []);
  87. }
  88. //将实名信息更新到玩家数据
  89. $_mem_cache = MemCache::ins();
  90. $_mem_data = $_mem_cache->getInfoById($mem_id);
  91. if ($_mem_data['real_name'] != $real_name) {
  92. $this->setRealNameCnt($real_name); //不相同表示新的名字,相同表示已统计过
  93. }
  94. $_mem_data['real_name'] = $real_name;
  95. $_mem_data['mobile'] = $mobile;
  96. $_rs = $_mem_cache->updateMem($mem_id, $_mem_data);
  97. if (false == $_rs) {
  98. $_code = CommonStatus::INNER_ERROR;
  99. return $this->huoError($_code, IdentifyStatus::getMsg($_code), []);
  100. }
  101. $_code = CommonStatus::NO_ERROR;
  102. return $this->huoSuccess($_code, IdentifyStatus::getMsg($_code), []);
  103. }
  104. /**
  105. * 获取某个名字的玩家数量
  106. *
  107. * @param $real_name
  108. *
  109. * @return array|mixed
  110. */
  111. public function getRealNameCnt($real_name) {
  112. if (empty($real_name)) {
  113. return 0;
  114. }
  115. $_cache_key = CacheConst::CACHE_REAL_NAME_PREFIX.md5($real_name);
  116. $_rdata = Cache::get($_cache_key);
  117. if (!empty($_rdata)) {
  118. return $_rdata;
  119. }
  120. $_cnt = (new MemberModel())->where(['real_name' => $real_name])->count();
  121. if (empty($_cnt)) {
  122. return 0;
  123. }
  124. Cache::set($_cache_key, $_cnt, CommonConst::CONST_DAY_SECONDS);
  125. return $_cnt;
  126. }
  127. /**
  128. * 设置某个名字的玩家数量
  129. *
  130. * @param $real_name
  131. */
  132. public function setRealNameCnt($real_name) {
  133. $_cache_key = CacheConst::CACHE_REAL_NAME_PREFIX.md5($real_name);
  134. $_rdata = $this->getRealNameCnt($real_name);
  135. $_rdata += 1;
  136. Cache::set($_cache_key, $_rdata, CommonConst::CONST_DAY_SECONDS);
  137. }
  138. /**
  139. * 判断玩家重名数是否达到限制
  140. *
  141. * @param $real_name
  142. *
  143. * @return bool true 表示达到限制 false 表示未达到限制
  144. */
  145. public function isLimit($real_name) {
  146. $_setting_name = OptionConst::SETTING_SAME_NAME_CNT;
  147. $_option_value = ['same_cnt' => 0];
  148. $_m = new Option();
  149. $_item = $_m->getOptionData($_setting_name, 1, true);
  150. if (!empty($_item['option_value'])) {
  151. $_item['option_value'] = json_decode($_item['option_value'], true);
  152. }
  153. $_option_value = array_merge($_option_value, $_item['option_value']);
  154. if (empty($_option_value['same_cnt'])) {
  155. return false;
  156. }
  157. $_cnt = $this->getRealNameCnt($real_name);
  158. if ($_cnt >= $_option_value['same_cnt']) {
  159. return true;
  160. }
  161. return false;
  162. }
  163. }