216 lines
5.9 KiB
PHP
216 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace app\openapi\controller;
|
|
set_time_limit(0);
|
|
ini_set('memory_limit','512M');
|
|
ini_set('default_socket_timeout', -1); //不超时
|
|
use app\channel\service\ProductService;
|
|
use app\gateway\service\RedisService;
|
|
use app\merchant\service\MerchantLogHistoryService;
|
|
use app\merchant\service\MerchantService;
|
|
use app\merchant\service\OrderHistoryService;
|
|
use app\merchant\service\OrderLastHistoryService;
|
|
use app\merchant\service\OrderLastweekHistoryService;
|
|
use app\merchant\service\OrderService;
|
|
use app\merchant\service\OrderTwoHistoryService;
|
|
use app\merchant\service\RebateService;
|
|
use app\order\service\AfterSalesOrderService;
|
|
use app\setting\service\ChannelAccountService;
|
|
use app\setting\service\StatService;
|
|
use dever\Log;
|
|
use think\facade\Db;
|
|
|
|
//use app\gateway\controller\api\Coreks;
|
|
|
|
/**
|
|
* 任务
|
|
* Class Test
|
|
* @package app\gateway\api
|
|
*/
|
|
class Task extends Core
|
|
{
|
|
# 是否检测数据
|
|
protected $check = false;
|
|
# redis连接
|
|
protected $redis = false;
|
|
|
|
|
|
|
|
# 对submit提交的数据进行处理
|
|
|
|
|
|
protected function redis()
|
|
{
|
|
if (!$this->redis) {
|
|
$this->redis = RedisService::getInstance();
|
|
}
|
|
}
|
|
|
|
|
|
public function finishafter()
|
|
{
|
|
$day = input('day');
|
|
|
|
$page = 1;
|
|
while($this->finishOne_after($day, $page)) {
|
|
$page++;
|
|
}
|
|
|
|
}
|
|
|
|
public function finishOne_after($day, $page)
|
|
{
|
|
$afterSalesOrderService= AfterSalesOrderService::instance();
|
|
|
|
$data = $afterSalesOrderService->getFinishData($day, $page);
|
|
|
|
if ($data) {
|
|
foreach ($data as $k => $v) {
|
|
# 先插入一条历史数据
|
|
$id = $v['id'];
|
|
unset($v['id']);
|
|
$state = Db::name('merchant_order_history_aftersales')->insert($v);
|
|
if ($state) {
|
|
$afterSalesOrderService->del($id);
|
|
}
|
|
}
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
#完成订单迁移
|
|
public function finish()
|
|
{
|
|
$day = input('day');
|
|
MerchantService::instance()->init($day);
|
|
/*
|
|
if (!$day) {
|
|
$day = date('Y-m-d', strtotime('-1 day'));
|
|
}
|
|
*/
|
|
$page = 1;
|
|
while($this->finishOne($day, $page)) {
|
|
$page++;
|
|
}
|
|
}
|
|
|
|
public function finishOne($day, $page)
|
|
{
|
|
$orderService = OrderService::instance();
|
|
$orderHistoryService = OrderHistoryService::instance();
|
|
$orderLastHistoryService = OrderLastHistoryService::instance();
|
|
$data = $this->getFinishData($day, $page, $orderService,2);
|
|
// $data = $orderService->getFinishData($day, $page);
|
|
|
|
if ($data) {
|
|
|
|
foreach ($data as $k => $v) {
|
|
# 先插入一条历史数据
|
|
$id = $v['id'];
|
|
unset($v['id']);
|
|
$state = $orderLastHistoryService->up($v);
|
|
if ($state) {
|
|
$orderService->del($id);
|
|
}
|
|
}
|
|
}
|
|
|
|
$orderTwoHistoryService = OrderTwoHistoryService::instance();
|
|
|
|
$last_data = $this->getFinishData($day, $page, $orderLastHistoryService,3);
|
|
// $data = $orderService->getFinishData($day, $page);
|
|
|
|
if ($last_data) {
|
|
|
|
foreach ($last_data as $k => $v) {
|
|
# 先插入一条历史数据
|
|
$id = $v['id'];
|
|
unset($v['id']);
|
|
$state = $orderTwoHistoryService->up($v);
|
|
if ($state) {
|
|
$orderLastHistoryService->del($id);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
$two_data = $this->getFinishData($day, $page, $orderTwoHistoryService,4);
|
|
// $data = $orderService->getFinishData($day, $page);
|
|
if ($two_data) {
|
|
|
|
foreach ($two_data as $k => $v) {
|
|
# 先插入一条历史数据
|
|
$id = $v['id'];
|
|
unset($v['id']);
|
|
$state = $orderHistoryService->up($v);
|
|
if ($state) {
|
|
$orderTwoHistoryService->del($id);
|
|
}
|
|
}
|
|
}
|
|
|
|
if($data || $last_data || $two_data){
|
|
return true;
|
|
}else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function getFinishData($day, $page, $orderService ,$type = 1)
|
|
{
|
|
if (!$day) {
|
|
$start = date('Y-m-d', strtotime('-360 day'));
|
|
$day = date('Y-m-d', strtotime('-1 day'));
|
|
if($type == 2){
|
|
$start = date('Y-m-d', strtotime('-30 day'));
|
|
$day = date('Y-m-d', strtotime('-1 day'));
|
|
}
|
|
if($type == 3){
|
|
$start = date('Y-m-d', strtotime('-90 day'));
|
|
$day = date('Y-m-d', strtotime('-31 day'));
|
|
}
|
|
if($type == 4){
|
|
$start = date('Y-m-d', strtotime('-365 day'));
|
|
$day = date('Y-m-d', strtotime('-91 day'));
|
|
}
|
|
} else {
|
|
$start = $day;
|
|
}
|
|
$begin = $start . ' 00:00:00';
|
|
$after = $day . ' 23:59:59';
|
|
$time = [$begin, $after];
|
|
|
|
$db = $orderService->db()->whereRaw('status in(2,3) ');
|
|
$db = $db->whereBetween('create_at', $time)->order('id asc');
|
|
if ($page) {
|
|
$limit = 10000;
|
|
$page = $page - 1;
|
|
$page = $page * $limit;
|
|
$db->limit($page, $limit);
|
|
}
|
|
return $db;
|
|
|
|
}
|
|
|
|
# 回调时间计算利润
|
|
public function notify_profit()
|
|
{
|
|
$day = input('day');
|
|
if (!$day) {
|
|
$day = date('Y-m-d', strtotime('-1 day'));
|
|
}
|
|
// $orderHistoryService = OrderHistoryService::instance();
|
|
$orderLastweekHistoryService = OrderLastweekHistoryService::instance();
|
|
$data = $orderLastweekHistoryService->getTotalData($day,false,false,2);
|
|
// var_dump($data);
|
|
if ($data) {
|
|
StatService::instance()->handle($day, $data);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
} |