DashboardController.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: leo
  5. * Date: 2018/2/24
  6. * Time: 下午12:48
  7. */
  8. namespace frontendApi\modules\v1\controllers;
  9. use common\helpers\Cache;
  10. use common\helpers\ChartData;
  11. use common\helpers\Date;
  12. use common\helpers\user\Reconsume;
  13. use common\helpers\user\Info;
  14. use common\models\Ad;
  15. use common\models\Article;
  16. use common\models\ArticleCategory;
  17. use common\models\CalcBonus;
  18. use common\models\FlowBonus;
  19. use common\models\Period;
  20. use common\models\ReconsumePool;
  21. use common\models\RemainPv;
  22. use common\models\Order;
  23. class DashboardController extends BaseController
  24. {
  25. public $modelClass = FlowBonus::class;
  26. public function behaviors() {
  27. $behaviors = parent::behaviors();
  28. return $behaviors;
  29. }
  30. /**
  31. * 控制台首页
  32. * @return mixed
  33. * @throws \yii\base\Exception
  34. * @throws \yii\db\Exception
  35. * @throws \yii\web\HttpException
  36. */
  37. public function actionIndex(){
  38. $nowTime = Date::nowTime();
  39. $baseInfo=Info::baseInfoZh(\Yii::$app->user->id);
  40. $news=ArticleCategory::find()->select('ID,CATE_NAME')->orderBy('SORT ASC')->asArray()->all();
  41. $where = ' CID=:CID AND STATUS=1';
  42. $time = time();
  43. foreach ($news as &$value){
  44. $params = [
  45. ':CID'=>$value['ID'],
  46. ];
  47. $value['LISTS']=Article::find()->select('ID,TITLE,CID,CREATED_AT')->where($where,$params)->orderBy('CREATED_AT DESC')->limit(6)->asArray()->all();
  48. }
  49. $empLv = $baseInfo['EMP_LV'];
  50. $empLvName = $baseInfo['EMP_LV_NAME'];
  51. if($baseInfo['SHOW_EMP_LV']){
  52. $empLv = $baseInfo['SHOW_EMP_LV'];
  53. $empLvName = Cache::getEmpLevelConfig()[$baseInfo['SHOW_EMP_LV']]['LEVEL_NAME'];
  54. }
  55. //会员级别
  56. $decLv = $baseInfo['DEC_LV'];
  57. $decLvName = $baseInfo['DEC_LV_NAME'];
  58. //期数显示
  59. $period = Period::instance();
  60. $periodNum = $period->getNowPeriodNum();
  61. //
  62. $curYM = Period::find()->select("CALC_YEAR,CALC_MONTH")->where('PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM'=>$periodNum])->asArray()->one();
  63. $plist=Period::find()->select("PERIOD_NUM")->where('CALC_YEAR=:CALC_YEAR AND CALC_MONTH=:CALC_MONTH', [':CALC_YEAR'=>$curYM['CALC_YEAR'],':CALC_MONTH'=>$curYM['CALC_MONTH']])->orderBy('PERIOD_NUM ASC')->asArray()->all();
  64. $weeks = count($plist);
  65. $wkrd = '';
  66. foreach ($plist as $k=>$v){
  67. if($v['PERIOD_NUM']==$periodNum){
  68. $wkrd =$k+1;break;
  69. }
  70. }
  71. //剩余分期PV显示
  72. $myRemainPv = RemainPv::findOne(['USER_ID'=>$baseInfo['ID']])->REMAIN_PV ?? 0;
  73. // 找到当月的所有订单,计算总PV及总REMAIN_PV
  74. $myOrders = Order::fetchOrderCurrentMonth($periodNum, $baseInfo['ID']);
  75. $currentPv = $myOrders->SUM('PV');
  76. $currentRemainPv = $myOrders->SUM('REMAIN_PV');
  77. $totalRemainPv = $myRemainPv + $currentRemainPv;
  78. $sysConfig = Cache::getSystemConfig();
  79. $mesureUpCondition = $sysConfig['monthPcsPvFxCondition']['VALUE']; // 月达标条件 NC默认300
  80. $remainMonth = round($totalRemainPv / $mesureUpCondition);
  81. if($currentPv >= $mesureUpCondition){ // 如果当月合格,则活跃资格延后一个月
  82. $activeEndStr = date("Y-m", strtotime('next month'));
  83. }else{
  84. $activeEndStr = date("Y-m");
  85. }
  86. $activeEndStr = $activeEndStr. " + $remainMonth months";
  87. $activeEnd = date("Y-m-d H:i:s", strtotime($activeEndStr));
  88. return static::notice([
  89. 'nowTime' => $nowTime,
  90. 'empLv'=>$empLv,
  91. 'empLvName'=>$empLvName,
  92. 'decLv'=>$decLv,
  93. 'decLvName'=>$decLvName,
  94. 'slides'=>Ad::findUseSlaves()->select('ID,IMAGE,LID,TITLE,CONTENT,TYPE')->where('LID=:LID AND STATUS=1', [':LID'=>'7EFF6260A16C3CC7E053693418AC03E4'])->orderBy('SORT ASC')->asArray()->all(),
  95. 'news'=>$news,
  96. 'periodNum'=>$periodNum.'期,'.$curYM['CALC_MONTH'].'月第'.$wkrd.'周,共'.$weeks.'周',
  97. 'myRemainPv'=>$totalRemainPv,
  98. 'activeEnd'=>$activeEnd
  99. ]);
  100. }
  101. /**
  102. * 移动端我的页面首页
  103. * @return mixed
  104. * @throws \yii\base\Exception
  105. * @throws \yii\web\HttpException
  106. */
  107. public function actionMyIndex() {
  108. $nowTime = Date::nowTime();
  109. $baseInfo = Info::baseInfoZh(\Yii::$app->user->id);
  110. $empLv = $baseInfo['EMP_LV'];
  111. $empLvName = $baseInfo['EMP_LV_NAME'];
  112. if ($baseInfo['SHOW_EMP_LV']) {
  113. $empLv = $baseInfo['SHOW_EMP_LV'];
  114. $empLvName = Cache::getEmpLevelConfig()[$baseInfo['SHOW_EMP_LV']]['LEVEL_NAME'];
  115. }
  116. return static::notice([
  117. 'nowTime' => $nowTime,
  118. 'reConsumePool' => Reconsume::getUserReconsumePool(\Yii::$app->user->id),
  119. 'empLv' => $empLv,
  120. 'empLvName' => $empLvName,
  121. ]);
  122. }
  123. /**
  124. * 近7期奖金
  125. * @return mixed
  126. * @throws \yii\db\Exception
  127. * @throws \yii\web\HttpException
  128. */
  129. public function actionPeriodBonus(){
  130. return static::notice(CalcBonus::periodBonus(\Yii::$app->user->id));
  131. }
  132. /**
  133. * 奖金量
  134. * @return mixed
  135. * @throws \yii\web\HttpException
  136. */
  137. public function actionBonusNum(){
  138. $chartData = ChartData::instance();
  139. return static::notice($chartData->userBonusData(\Yii::$app->user->id));
  140. }
  141. }