ShellController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace console\controllers;
  3. use biz\goods\services\GoodsService;
  4. use biz\stat\services\VisitByDayService;
  5. use biz\tool\services\GuaGuaService;
  6. use Yii;
  7. use yii\console\Controller;
  8. use common\models\xhMerchant;
  9. use common\components\configDict;
  10. use common\services\xhWxOpenService;
  11. use common\components\stringUtil;
  12. /**
  13. * 执行脚本
  14. */
  15. class ShellController extends Controller
  16. {
  17. public $enableCsrfValidation = false;
  18. //每天要跑的东西放这里 shish 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. $merchantName = $merchant['merchantName'];
  29. $visitData = VisitByDayService::saveYesterdayNum($merchantId);//访问量
  30. if (!empty($visitData)) {
  31. $log = "商家:{$merchantName}({$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_info_' . date("Ymd") . '.txt');
  35. }
  36. }
  37. }
  38. }
  39. }
  40. /**
  41. * 每天邮件通知
  42. */
  43. public function actionWeekNotice($ip = '')
  44. {
  45. $openId = configDict::getConfig('openId');
  46. $open = xhWxOpenService::getById($openId);
  47. $openName = $open['openName'];
  48. $mail = Yii::$app->mailer->compose();
  49. $errFile = '/opt/shell/log/week_err_' . date("Ymd") . '.txt';
  50. $infoFile = '/opt/shell/log/week_info_' . date("Ymd") . '.txt';
  51. $mail->setTo('479439056@qq.com');
  52. $mail->setSubject("【{$openName}】《每周》脚本执行 SUCCESS(" . $ip . ")");
  53. $mail->setTextBody('详细情况请查看附件哦');
  54. if (file_exists($errFile) && filesize($errFile) > 0) {
  55. $content = trim(file_get_contents($errFile));
  56. if ($content != "Warning: Using a password on the command line interface can be insecure.") {
  57. $mail->setSubject("【{$openName}】《每周》脚本执行 出错了(" . $ip . ")");
  58. $mail->attach($errFile);
  59. }
  60. }
  61. if (file_exists($infoFile) && filesize($infoFile) > 0) {
  62. $mail->attach($infoFile);
  63. }
  64. $mail->send();
  65. }
  66. /**
  67. * 每天邮件通知
  68. */
  69. public function actionDayNotice($ip = '')
  70. {
  71. $openId = configDict::getConfig('openId');
  72. $open = xhWxOpenService::getById($openId);
  73. $openName = $open['openName'];
  74. $mail = Yii::$app->mailer->compose();
  75. $errFile = '/opt/shell/log/day_err_' . date("Ymd") . '.txt';
  76. $infoFile = '/opt/shell/log/day_info_' . date("Ymd") . '.txt';
  77. $mail->setTo('479439056@qq.com');
  78. $mail->setSubject("【{$openName}】【每天】脚本执行 SUCCESS(" . $ip . ")");
  79. $mail->setTextBody('具体请看附件哦');
  80. if (file_exists($errFile) && filesize($errFile) > 0) {
  81. $mail->setSubject("【{$openName}】【每天】脚本执行 出错了(" . $ip . ")");
  82. $mail->attach($errFile);
  83. }
  84. if (file_exists($infoFile) && filesize($infoFile) > 0) {
  85. $mail->attach($infoFile);
  86. }
  87. $mail->send();
  88. }
  89. //将缓存放入数据库 shish
  90. public function actionPutCacheToSave()
  91. {
  92. //商家层面
  93. //guaguaka
  94. $arr = ['guaguacard-visit-12358-1170'];
  95. GuaGuaService::putGuaCacheToSave();
  96. //choujiang
  97. $arr = ['draw-visit-12358-1170'];
  98. //goods
  99. $arr = ['goods-visit-12358-5521'];
  100. GoodsService::putGoodsCacheToSave();
  101. //批发商层面
  102. //平台层面
  103. }
  104. }