1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Bear
- * Date: 2019/9/12
- * Time: 下午1:44
- */
- namespace app\admin\command;
- use app\admin\service\LogService;
- use app\main\constants\OrderContents;
- use app\main\service\OrdersCollectUpdateService;
- use think\console\Command;
- use think\console\Input;
- use think\console\input\Option;
- use think\console\Output;
- use think\Request;
- class OrdersCollectUpdate extends BaseCommand
- {
- protected function configure()
- {
- $this->setName('OrdersCollectUpdate')
- ->addOption('current_time', 'c', Option::VALUE_OPTIONAL, '时间节点:2019-08-11', null)
- ->addOption('type', 't', Option::VALUE_OPTIONAL, '执行类型', 0)
- ->setDescription('订单按月和汇总统计');
- }
- protected function execute(Input $input, Output $output)
- {
- Request::instance()->module('admin');
- //初始化,统计到昨天
- if ($input->getOption('type')) {
- $end_time = time() - 86400;
- $current_time = strtotime($input->getOption('current_time'));
- if (!$current_time) {
- LogService::error('初始化未提供开始参数');
- echo '初始化未提供开始参数';
- exit;
- }
- while ($current_time < $end_time) {
- $this->start($current_time);
- $current_time += 86400;
- }
- } else {
- $current_time = strtotime($input->getOption('current_time'));
- if (!$current_time) {
- //默认取昨天
- $current_time = time() - 86400;
- }
- $this->start($current_time);
- }
- }
- /**
- * 执行
- * @param $end_time
- */
- public function start($end_time)
- {
- $msg = 'processing:' . date('Y-m-d H:i:s', $end_time) . "\n";
- echo $msg;
- LogService::debug($msg);
- OrdersCollectUpdateService::instance()->setCurrentTime($end_time);
- $flags = [
- OrderContents::ORDER_COLLECT_FLAG_SELF,
- OrderContents::ORDER_COLLECT_FLAG_CHILD,
- OrderContents::ORDER_COLLECT_FLAG_ALL,
- ];
- $types = [
- OrderContents::ORDER_COLLECT_TYPE_MONTH,
- OrderContents::ORDER_COLLECT_TYPE_TOTAL,
- ];
- foreach ($flags as $flag) {
- $admin_list = OrdersCollectUpdateService::instance()->getAdminIdsToUpdate($flag)->data;
- foreach ($types as $type) {
- if ($admin_list) {
- array_push($admin_list, 0);
- foreach (array_chunk($admin_list, 100) as $admin_ids) {
- try {
- $list = OrdersCollectUpdateService::instance()->getOrderCollectData($type, $flag, $admin_ids)->data;
- OrdersCollectUpdateService::instance()->insertOrUpdateCollect($list);
- } catch (\Exception $e) {
- LogService::exception($e);
- }
- }
- }
- }
- }
- }
- }
|