| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace console\controllers;
- use bizHd\goods\services\GoodsService;
- use bizHd\stat\services\StatVisitService;
- use bizHd\promote\services\GuaGuaService;
- use common\components\util;
- use Yii;
- use yii\console\Controller;
- use common\models\xhMerchant;
- use common\components\dict;
- use common\services\xhWxOpenService;
- use common\components\stringUtil;
- /**
- * 执行脚本
- */
- class ShellController extends Controller
- {
-
- //每天要跑的东西放这里 ssh 2019.9.10
- // 10 0 * * * /usr/local/nginx/html/huahuibao/yii shell/per-day
- public function actionPerDay()
- {
- $query = xhMerchant::find();
- foreach ($query->batch(50) as $merchantList) {
- if (!empty($merchantList)) {
- foreach ($merchantList as $merchant) {
- $merchant = $merchant->toArray();
- $merchantId = $merchant['id'];
- $name = $merchant['name'];
- $visitData = StatVisitService::saveYesterdayNum($merchantId);//访问量
- if (!empty($visitData)) {
- $log = "商家:{$name}({$merchantId}):";
- $time = date("Y-m-d", $visitData['time']);
- $log .= "访问量:date:{$time} num:{$visitData['riseNum']}\r\n";
- stringUtil::log($log, '/opt/shell/log/merchant_visit_log_' . date("Ymd") . '.txt');
- }
- }
- }
- }
- }
-
- /**
- * 每天邮件通知
- */
- public function actionWeekNotice($ip = '')
- {
- $open = [];
- if (empty($open)) {
- util::stop('取平台信息错误');
- }
- $name = $open['name'];
- $mail = Yii::$app->mailer->compose();
- $errFile = '/opt/shell/log/week_err_' . date("Ymd") . '.txt';
- $infoFile = '/opt/shell/log/week_info_' . date("Ymd") . '.txt';
- $mail->setTo('479439056@qq.com');
- $mail->setSubject("【{$name}】《每周》脚本执行 SUCCESS(" . $ip . ")");
- $mail->setTextBody('详细情况请查看附件哦');
- if (file_exists($errFile) && filesize($errFile) > 0) {
- $content = trim(file_get_contents($errFile));
- if ($content != "Warning: Using a password on the command line interface can be insecure.") {
- $mail->setSubject("【{$name}】《每周》脚本执行 出错了(" . $ip . ")");
- $mail->attach($errFile);
- }
- }
- if (file_exists($infoFile) && filesize($infoFile) > 0) {
- $mail->attach($infoFile);
- }
- $mail->send();
- }
-
- /**
- * 每天邮件通知
- */
- public function actionDayNotice($ip = '')
- {
- $openId = dict::getConfig('openId');
- $open = [];
- if (empty($open)) {
- util::stop('取平台信息错误');
- }
- $name = $open['name'];
- $mail = Yii::$app->mailer->compose();
- $errFile = '/opt/shell/log/day_err_' . date("Ymd") . '.txt';
- $infoFile = '/opt/shell/log/day_info_' . date("Ymd") . '.txt';
- $mail->setTo('479439056@qq.com');
- $mail->setSubject("【{$name}】【每天】脚本执行 SUCCESS(" . $ip . ")");
- $mail->setTextBody('具体请看附件哦');
- if (file_exists($errFile) && filesize($errFile) > 0) {
- $mail->setSubject("【{$name}】【每天】脚本执行 出错了(" . $ip . ")");
- $mail->attach($errFile);
- }
- if (file_exists($infoFile) && filesize($infoFile) > 0) {
- $mail->attach($infoFile);
- }
- $mail->send();
- }
-
- //将缓存放入数据库 ssh
- public function actionPutCacheToSave()
- {
- //商家层面
- //guaguaka
- $arr = ['guaguacard-visit-12358-1170'];
- GuaGuaService::putGuaCacheToSave();
- //choujiang
- $arr = ['draw-visit-12358-1170'];
- //goods
- $arr = ['goods-visit-12358-5521'];
- GoodsService::putGoodsCacheToSave();
- //批发商层面
- //平台层面
- }
-
- }
|