ToolController.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /**
  3. * 测试专用控制器
  4. * Created by PhpStorm.
  5. * User: leo
  6. * Date: 2018/3/9
  7. * Time: 上午11:56
  8. */
  9. namespace console\controllers;
  10. use common\helpers\Cache;
  11. use common\helpers\DataBak;
  12. use common\helpers\Date;
  13. use common\helpers\Form;
  14. use common\helpers\ocr\OcrApi;
  15. use common\helpers\Tool;
  16. use common\libs\api\sms\SmsApi;
  17. use common\libs\swoole\RPCApi;
  18. use common\models\CalcBonus;
  19. use common\models\CalcBonusFX;
  20. use common\models\CalcBonusQY;
  21. use common\models\CalcBonusYC;
  22. use common\models\FlowBonus;
  23. use common\models\forms\ClearDataForm;
  24. use common\models\forms\DeclarationLoopForm;
  25. use common\models\forms\UserForm;
  26. use common\models\PerfMonth;
  27. use common\models\PerfOrder;
  28. use common\models\PerfPeriod;
  29. use common\models\ReconsumePool;
  30. use common\models\ReconsumePoolFlow;
  31. use common\models\DecOrder;
  32. use common\models\User;
  33. use common\models\UserInfo;
  34. use common\models\UserNetwork;
  35. use common\models\UserRelation;
  36. use yii\base\Exception;
  37. use yii\db\Expression;
  38. use yii\db\Query;
  39. class ToolController extends BaseController
  40. {
  41. /**
  42. * 显示系统的当前时间
  43. */
  44. public function actionTime(){
  45. echo(Date::nowTime().PHP_EOL);
  46. }
  47. /**
  48. * 显示系统的当前时间
  49. * @param null $time
  50. */
  51. public function actionDateTime($time = null){
  52. if($time === null){
  53. $time = Date::nowTime();
  54. }
  55. echo(date('Y-m-d H:i:s', $time).PHP_EOL);
  56. }
  57. /**
  58. * 格式化传入的时间
  59. * @param $dateTime
  60. */
  61. public function actionDateToTime($dateTime){
  62. echo(strtotime($dateTime).PHP_EOL);
  63. }
  64. /**
  65. * 重新生成表缓存
  66. * @throws Exception
  67. * @throws \yii\base\InvalidConfigException
  68. */
  69. public function actionTable(){
  70. $percent = 0;
  71. $dir = \Yii::getAlias('@common/runtime/tableSchema');
  72. Tool::clearDir($dir);
  73. $percent += 10;
  74. $this->_percentHandle($percent);
  75. $dbArr = ['db'];
  76. foreach($dbArr as $key=>$dbName){
  77. $db = \Yii::$app->get($dbName, false);
  78. $dbTables = $db->getSchema()->getTableNames();
  79. $tableCount = count($dbTables);
  80. foreach($dbTables as $tableName){
  81. $db->getSchema()->generateTableSchema($tableName);
  82. $percent += 1/$tableCount * 100;
  83. $this->_percentHandle($percent);
  84. }
  85. }
  86. $this->_percentHandle($percent, true);
  87. echo ' 生成表缓存完成'.PHP_EOL;
  88. }
  89. /**
  90. * 生成百分比箭头文字
  91. * @param $percent
  92. * @param bool $isDone
  93. */
  94. private function _percentHandle($percent, $isDone = false){
  95. $percent = intval($percent);
  96. if($percent >= 100) $percent = 100;
  97. $beforeStr = str_repeat('=', intval($percent/2));
  98. $afterStr = str_repeat(' ', 50 - intval($percent/2));
  99. if($percent >= 100){
  100. $echoString = "\r[=".$beforeStr.$afterStr.'] '.$percent.'% ';
  101. } else {
  102. $echoString = "\r[".$beforeStr.'>'.$afterStr.'] '.$percent.'% ';
  103. }
  104. echo $echoString;
  105. flush();
  106. if($percent >= 100 && $isDone){
  107. echo PHP_EOL;
  108. }
  109. }
  110. /**
  111. * 清空缓存
  112. */
  113. public function actionClearCache() {
  114. \Yii::$app->tokenRedis->flushdb();
  115. \Yii::$app->redis->flushdb();
  116. \Yii::$app->cache->flush();
  117. echo '清空成功'.PHP_EOL;
  118. }
  119. /**
  120. * 重置接点和推荐数量
  121. */
  122. public function actionResetConNum(){
  123. // 先清空会员表内的所有con_num数据
  124. UserInfo::updateAll(['CON_NUM'=>0, 'REC_NUM'=>0], '1=1');
  125. // 循环所有会员,给他的上级数量增加1
  126. $this->_loopUserAddConNum();
  127. echo ' 重置接点推荐数量完成'.PHP_EOL;
  128. }
  129. /**
  130. * 循环为上级增加数量
  131. * @param int $offset
  132. */
  133. public function _loopUserAddConNum($offset = 0){
  134. $userData = UserInfo::find()->select('USER_ID,CON_UID,REC_UID')->where('1=1')->orderBy('CREATED_AT ASC')->offset($offset)->limit(100)->asArray()->all();
  135. $totalNum = UserInfo::find()->count();
  136. $startNum = $offset;
  137. if($userData){
  138. foreach($userData as $user){
  139. if($user['CON_UID']){
  140. UserInfo::updateAll(['CON_NUM'=>new Expression('CON_NUM+1')], 'USER_ID=:USER_ID', [':USER_ID'=>$user['CON_UID']]);
  141. }
  142. if($user['REC_UID']){
  143. UserInfo::updateAll(['REC_NUM'=>new Expression('REC_NUM+1')], 'USER_ID=:USER_ID', [':USER_ID'=>$user['REC_UID']]);
  144. }
  145. $this->_percentHandle($startNum + 1/$totalNum*100);
  146. }
  147. $this->_loopUserAddConNum($offset + 100);
  148. }
  149. }
  150. /**
  151. * 清网络缓存
  152. */
  153. public function actionClearNet(){
  154. \Yii::$app->redis->del(Cache::USER_NETWORK_PARENTS);
  155. \Yii::$app->redis->del(Cache::USER_RELATION_PARENTS);
  156. }
  157. }