Status.php 7.1 KB

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