ShellController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace console\controllers;
  3. use bizHd\goods\services\GoodsService;
  4. use bizHd\stat\services\StatVisitService;
  5. use bizHd\promote\services\GuaGuaService;
  6. use common\components\util;
  7. use Yii;
  8. use yii\console\Controller;
  9. use common\models\xhMerchant;
  10. use common\components\dict;
  11. use common\services\xhWxOpenService;
  12. use common\components\stringUtil;
  13. /**
  14. * 执行脚本
  15. */
  16. class ShellController extends Controller
  17. {
  18. //每天要跑的东西放这里 ssh 2019.9.10
  19. // 10 0 * * * /usr/local/nginx/html/huahuibao/yii shell/per-day
  20. public function actionPerDay()
  21. {
  22. $query = xhMerchant::find();
  23. foreach ($query->batch(50) as $merchantList) {
  24. if (!empty($merchantList)) {
  25. foreach ($merchantList as $merchant) {
  26. $merchant = $merchant->toArray();
  27. $merchantId = $merchant['id'];
  28. $name = $merchant['name'];
  29. $visitData = StatVisitService::saveYesterdayNum($merchantId);//访问量
  30. if (!empty($visitData)) {
  31. $log = "商家:{$name}({$merchantId}):";
  32. $time = date("Y-m-d", $visitData['time']);
  33. $log .= "访问量:date:{$time} num:{$visitData['riseNum']}\r\n";
  34. stringUtil::log($log, '/opt/shell/log/merchant_visit_log_' . date("Ymd") . '.txt');
  35. }
  36. }
  37. }
  38. }
  39. }
  40. /**
  41. * 每天邮件通知
  42. */
  43. public function actionWeekNotice($ip = '')
  44. {
  45. $open = [];
  46. if (empty($open)) {
  47. util::stop('取平台信息错误');
  48. }
  49. $name = $open['name'];
  50. $mail = Yii::$app->mailer->compose();
  51. $errFile = '/opt/shell/log/week_err_' . date("Ymd") . '.txt';
  52. $infoFile = '/opt/shell/log/week_info_' . date("Ymd") . '.txt';
  53. $mail->setTo('479439056@qq.com');
  54. $mail->setSubject("【{$name}】《每周》脚本执行 SUCCESS(" . $ip . ")");
  55. $mail->setTextBody('详细情况请查看附件哦');
  56. if (file_exists($errFile) && filesize($errFile) > 0) {
  57. $content = trim(file_get_contents($errFile));
  58. if ($content != "Warning: Using a password on the command line interface can be insecure.") {
  59. $mail->setSubject("【{$name}】《每周》脚本执行 出错了(" . $ip . ")");
  60. $mail->attach($errFile);
  61. }
  62. }
  63. if (file_exists($infoFile) && filesize($infoFile) > 0) {
  64. $mail->attach($infoFile);
  65. }
  66. $mail->send();
  67. }
  68. /**
  69. * 每天邮件通知
  70. */
  71. public function actionDayNotice($ip = '')
  72. {
  73. $openId = dict::getConfig('openId');
  74. $open = [];
  75. if (empty($open)) {
  76. util::stop('取平台信息错误');
  77. }
  78. $name = $open['name'];
  79. $mail = Yii::$app->mailer->compose();
  80. $errFile = '/opt/shell/log/day_err_' . date("Ymd") . '.txt';
  81. $infoFile = '/opt/shell/log/day_info_' . date("Ymd") . '.txt';
  82. $mail->setTo('479439056@qq.com');
  83. $mail->setSubject("【{$name}】【每天】脚本执行 SUCCESS(" . $ip . ")");
  84. $mail->setTextBody('具体请看附件哦');
  85. if (file_exists($errFile) && filesize($errFile) > 0) {
  86. $mail->setSubject("【{$name}】【每天】脚本执行 出错了(" . $ip . ")");
  87. $mail->attach($errFile);
  88. }
  89. if (file_exists($infoFile) && filesize($infoFile) > 0) {
  90. $mail->attach($infoFile);
  91. }
  92. $mail->send();
  93. }
  94. //将缓存放入数据库 ssh
  95. public function actionPutCacheToSave()
  96. {
  97. //商家层面
  98. //guaguaka
  99. $arr = ['guaguacard-visit-12358-1170'];
  100. GuaGuaService::putGuaCacheToSave();
  101. //choujiang
  102. $arr = ['draw-visit-12358-1170'];
  103. //goods
  104. $arr = ['goods-visit-12358-5521'];
  105. GoodsService::putGoodsCacheToSave();
  106. //批发商层面
  107. //平台层面
  108. }
  109. }