You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

68 lines
2.4 KiB

<?php
namespace App\Service\v3\Implementations;
use App\Constants\v3\OrderState;
use App\Constants\v3\OrderType;
use App\Model\v3\Order;
use App\Model\v3\OrderGoods;
use App\Model\v3\OrderMain;
use \App\Service\v3\Interfaces\OrderStatisticsServiceInterface;
use Hyperf\Utils\ApplicationContext;
class OrderStatisticsService implements OrderStatisticsServiceInterface
{
public function do()
{
// TODO: Implement do() method.
}
public function check()
{
// TODO: Implement check() method.
}
public function undo()
{
// TODO: Implement undo() method.
}
public function countOrder($storeId,$type,$startTime = '',$endTime = '')
{
$childTable = ApplicationContext::getContainer()->get(Order::class)->getTable();
$mainTable = ApplicationContext::getContainer()->get(OrderMain::class)->getTable();
$goodsTable = ApplicationContext::getContainer()->get(OrderGoods::class)->getTable();
$builder = OrderMain::query()
->selectRaw('COUNT(DISTINCT '.$mainTable.'.id) AS count')
->join($childTable, ''.$childTable.'.order_main_id', '=', ''.$mainTable.'.global_order_id')
->where([''.$childTable.'.store_id' => $storeId, ''.$mainTable.'.type' => $type])
->whereIn(''.$mainTable.'.state', array_merge(OrderState::FINISH, [OrderState::REFUNDED_DIRECT,OrderState::REFUND_REFUSE]));
if ($type == OrderType::ONLINE) {
$builder = $builder->join($goodsTable, ''.$goodsTable.'.order_id', '=', ''.$childTable.'.id')
->whereIn(''.$goodsTable.'.status', [1,2]);
}
if ($startTime) {
$builder = $builder->where(''.$mainTable.'.created_at', '>=', $startTime);
}
if ($endTime) {
$builder = $builder->where(''.$mainTable.'.created_at', '<=', $endTime);
}
return $builder->first()->count;
// $builder = Order::join('lanzu_order_main','lanzu_order_main.global_order_id','lanzu_order.order_main_id')
// ->where('lanzu_order.store_id',$storeId);
// if(!empty($startTime) && !empty($endTime)){
// $builder->whereBetween('lanzu_order_main.created_at',[$startTime,$endTime]);
// }
// $count = $builder->whereIn('lanzu_order_main.state', OrderState::FINISH)
// ->where('type',$type)
// ->count();
// return $count;
}
}