Status.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: leo
  5. * Date: 2018/10/30
  6. * Time: 下午3:19
  7. */
  8. namespace common\helpers\user;
  9. use common\helpers\Cache;
  10. use common\helpers\Date;
  11. use common\helpers\Tool;
  12. use common\models\forms\UserStatusForm;
  13. use common\models\PerfMonth;
  14. use common\models\Period;
  15. use common\models\UserWallet;
  16. use common\models\User;
  17. use common\models\UserClose;
  18. use common\models\UserInfo;
  19. use common\models\UserStatusAudit;
  20. use Yii;
  21. class Status
  22. {
  23. /**
  24. * 根据所传期数获取当前期数是否可以因为复销得到奖金
  25. * @param $userId
  26. * @param $periodNum
  27. * @return bool
  28. */
  29. public static function fxGetBonusStatusByPeriodNum($userId, $periodNum){
  30. $period = Period::instance();
  31. $lastYearMonth = $period->getLastMonth($periodNum);
  32. return PerfMonth::find()->yearMonth($lastYearMonth['yearMonth'])->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH AND FX_STATUS=1', [':USER_ID'=>$userId, ':CALC_MONTH'=>$lastYearMonth['yearMonth']])->exists();
  33. }
  34. // public static function fxGetBonusStatusByYearMonth($userId, $yearMonth){
  35. // $period = Period::instance();
  36. // $lastYearMonth = Date::lastNumMonth($yearMonth);
  37. // return PerfMonth::find()->yearMonth($lastYearMonth)->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH AND FX_STATUS=1', [':USER_ID'=>$userId, ':CALC_MONTH'=>$lastYearMonth])->exists();
  38. // }
  39. /**
  40. * 是否所传的结算月加入
  41. * @param $userId
  42. * @param $calcMonth
  43. * @return bool
  44. * @throws \yii\db\Exception
  45. */
  46. public static function isMonthJoin($userId, $calcMonth){
  47. $oneUser = User::find()->select('PERIOD_AT')->where('ID=:USER_ID', [':USER_ID'=>$userId])->asArray()->one();
  48. $period = Period::instance();
  49. $addYearMonth = $period->getYearMonth($oneUser['PERIOD_AT']);
  50. return $addYearMonth == $calcMonth;
  51. }
  52. /**
  53. * 所传结算月之后加入
  54. * @param $userId
  55. * @param $calcMonth
  56. * @return bool
  57. * @throws \yii\db\Exception
  58. */
  59. public static function afterMonthJoin($userId, $calcMonth){
  60. $oneUser = User::find()->select('PERIOD_AT')->where('ID=:USER_ID', [':USER_ID'=>$userId])->asArray()->one();
  61. $period = Period::instance();
  62. $addYearMonth = $period->getYearMonth($oneUser['PERIOD_AT']);
  63. return $addYearMonth > $calcMonth;
  64. }
  65. /**
  66. * 是否完善了身份证照片
  67. * @param $userId
  68. * @return bool
  69. */
  70. public static function isFinishIdCard($userId){
  71. return User::find()->where('ID=:ID AND ID_IMAGE IS NOT NULL',[':ID'=>$userId])->exists();
  72. }
  73. /**
  74. * 是否存在点位合作情况
  75. * @param $userId
  76. * @return bool
  77. */
  78. public static function isTeamwork($userId){
  79. return UserInfo::find()->where('IS_TEAM=1 AND USER_ID=:USER_ID', [':USER_ID' => $userId])->exists();
  80. }
  81. /**
  82. * 点位绑定情况
  83. * @param $userId
  84. * @return array|null|\yii\db\ActiveRecord
  85. */
  86. public static function chkBind($userId){
  87. $userBind=UserInfo::find()->select('IS_BIND,IS_BIND_MAIN')->where('USER_ID=:USER_ID',[':USER_ID'=>$userId])->asArray()->one();
  88. return $userBind;
  89. }
  90. /**
  91. * 会员状态
  92. * @param $userId
  93. * @param null $periodNum
  94. * @return string
  95. */
  96. public static function getStatus($userId, $periodNum = null){
  97. $period = Period::instance();
  98. $nowPeriod = $period->getNowPeriodNum();
  99. if($periodNum === null || $periodNum = $nowPeriod){
  100. $user = User::findOneAsArray('ID=:ID', ['ID'=>$userId], 'STATUS');
  101. return $user['STATUS'];
  102. } else {
  103. // 获取会员所传期数之前的最后一次修改状态的记录
  104. $data = UserStatusAudit::findUseSlaves()->where('USER_ID=:USER_ID AND AUDIT_STATUS=:AUDIT_STATUS AND PERIOD_NUM<=:PERIOD_NUM', [':USER_ID' => $userId, ':AUDIT_STATUS' => \Yii::$app->params['auditStatus']['true']['value'], ':PERIOD_NUM' => $periodNum])->orderBy('AUDITED_AT DESC')->asArray()->one();
  105. if($data) {
  106. return $data['STATUS_VALUE'];
  107. } else {
  108. return self::getStatus($userId, null);
  109. }
  110. }
  111. }
  112. /**
  113. * 获取超过关停时间的会员
  114. * @param bool $hasClear 清除过钱包
  115. * @return array|null|\yii\db\ActiveRecord[]
  116. */
  117. public static function getCloseUser($hasClear = false){
  118. $days = Cache::getSystemConfig()['closeInspectClearDays']['VALUE'];
  119. if($hasClear){
  120. $users = User::findAllAsArray('STATUS=:STATUS AND STATUS_AT<:STATUS_AT',[':STATUS'=>UserStatusForm::STATUS_CLOSE,'STATUS_AT'=>Date::lastNumDay($days)],'ID,STATUS,REAL_NAME,STATUS_AT');
  121. }else{
  122. $users = User::find()->from(User::tableName() . ' AS U')->select('U.ID,U.STATUS,U.REAL_NAME,U.STATUS_AT')->where('U.STATUS=:STATUS AND U.STATUS_AT<:STATUS_AT AND UW.CLEAR_BY_CLOSED_AT=0',[':STATUS'=>UserStatusForm::STATUS_CLOSE,'STATUS_AT'=>Date::lastNumDay($days)])->join('LEFT JOIN',UserWallet::tableName().' AS UW','U.ID=UW.USER_ID')->asArray()->all();
  123. }
  124. foreach ($users as $k=>$u){
  125. $users[$k]['STATUS_NAME'] = Tool::paramConvert(Yii::$app->params['userStatus'])[$u['STATUS']]['label'];
  126. }
  127. return $users;
  128. }
  129. public static function getLoginStatus() {
  130. }
  131. // /**
  132. // * 是否关停状态
  133. // * @param $userId
  134. // * @param null $periodNum
  135. // * @return bool
  136. // */
  137. // public static function isCloseAccount($userId, $periodNum=null){
  138. // if($periodNum === null){
  139. // $data = UserInfo::findOneAsArray('USER_ID=:USER_ID', [':USER_ID'=>$userId], 'CLOSE_ACCOUNT');
  140. // return boolval($data['CLOSE_ACCOUNT']);
  141. // } else {
  142. // // 获取会员所传期数之前的最后一次关停并审核的记录
  143. // $data = UserClose::find()->where('USER_ID=:USER_ID AND TYPE=:TYPE AND AUDIT_STATUS=:AUDIT_STATUS AND PERIOD_NUM<=:PERIOD_NUM', [':USER_ID'=>$userId, ':TYPE' => UserClose::TYPE_GT, ':AUDIT_STATUS'=>\Yii::$app->params['auditStatus']['true']['value'], ':PERIOD_NUM'=>$periodNum])->orderBy('AUDITED_AT DESC')->asArray()->one();
  144. // if($data) return boolval($data['IS_CLOSE']);
  145. // return false;
  146. // }
  147. // }
  148. //
  149. // /**
  150. // * 是否停发状态
  151. // * @param $userId
  152. // * @param null $periodNum
  153. // * @return bool
  154. // */
  155. // public static function isCloseBonus($userId, $periodNum=null){
  156. // if($periodNum === null){
  157. // $data = UserInfo::findOneAsArray('USER_ID=:USER_ID', [':USER_ID'=>$userId], 'CLOSE_BONUS');
  158. // return boolval($data['CLOSE_BONUS']);
  159. // } else {
  160. // // 获取会员所传期数之前的最后一次关停并审核的记录
  161. // $data = UserClose::find()->where('USER_ID=:USER_ID AND TYPE=:TYPE AND AUDIT_STATUS=:AUDIT_STATUS AND PERIOD_NUM<=:PERIOD_NUM', [':USER_ID'=>$userId, ':TYPE' => UserClose::TYPE_TF, ':AUDIT_STATUS'=>\Yii::$app->params['auditStatus']['true']['value'], ':PERIOD_NUM'=>$periodNum])->orderBy('AUDITED_AT DESC')->asArray()->one();
  162. // if($data) return boolval($data['IS_CLOSE']);
  163. // return false;
  164. // }
  165. // }
  166. }