ShellController.php 3.3 KB

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