ShellController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. }
  23. /**
  24. * 每天邮件通知
  25. */
  26. public function actionWeekNotice($ip = '')
  27. {
  28. $open = [];
  29. if (empty($open)) {
  30. util::stop('取平台信息错误');
  31. }
  32. $name = $open['name'];
  33. $mail = Yii::$app->mailer->compose();
  34. $errFile = '/opt/shell/log/week_err_' . date("Ymd") . '.txt';
  35. $infoFile = '/opt/shell/log/week_info_' . date("Ymd") . '.txt';
  36. $mail->setTo('479439056@qq.com');
  37. $mail->setSubject("【{$name}】《每周》脚本执行 SUCCESS(" . $ip . ")");
  38. $mail->setTextBody('详细情况请查看附件哦');
  39. if (file_exists($errFile) && filesize($errFile) > 0) {
  40. $content = trim(file_get_contents($errFile));
  41. if ($content != "Warning: Using a password on the command line interface can be insecure.") {
  42. $mail->setSubject("【{$name}】《每周》脚本执行 出错了(" . $ip . ")");
  43. $mail->attach($errFile);
  44. }
  45. }
  46. if (file_exists($infoFile) && filesize($infoFile) > 0) {
  47. $mail->attach($infoFile);
  48. }
  49. $mail->send();
  50. }
  51. /**
  52. * 每天邮件通知
  53. */
  54. public function actionDayNotice($ip = '')
  55. {
  56. $openId = dict::getDict('openId');
  57. $open = [];
  58. if (empty($open)) {
  59. util::stop('取平台信息错误');
  60. }
  61. $name = $open['name'];
  62. $mail = Yii::$app->mailer->compose();
  63. $errFile = '/opt/shell/log/day_err_' . date("Ymd") . '.txt';
  64. $infoFile = '/opt/shell/log/day_info_' . date("Ymd") . '.txt';
  65. $mail->setTo('479439056@qq.com');
  66. $mail->setSubject("【{$name}】【每天】脚本执行 SUCCESS(" . $ip . ")");
  67. $mail->setTextBody('具体请看附件哦');
  68. if (file_exists($errFile) && filesize($errFile) > 0) {
  69. $mail->setSubject("【{$name}】【每天】脚本执行 出错了(" . $ip . ")");
  70. $mail->attach($errFile);
  71. }
  72. if (file_exists($infoFile) && filesize($infoFile) > 0) {
  73. $mail->attach($infoFile);
  74. }
  75. $mail->send();
  76. }
  77. //将缓存放入数据库 ssh
  78. public function actionPutCacheToSave()
  79. {
  80. //商家层面
  81. //guaguaka
  82. $arr = ['guaguacard-visit-12358-1170'];
  83. GuaGuaService::putGuaCacheToSave();
  84. //choujiang
  85. $arr = ['draw-visit-12358-1170'];
  86. //goods
  87. $arr = ['goods-visit-12358-5521'];
  88. GoodsService::putGoodsCacheToSave();
  89. //批发商层面
  90. //平台层面
  91. }
  92. }