|
|
<?php
namespace App\Service\v3\Implementations;use App\Constants\v3\OrderState;use App\Constants\v3\OrderType;use App\Constants\v3\SsdbKeys;use App\Model\v3\Order;use App\Model\v3\OrderGoods;use App\Model\v3\OrderMain;use \App\Service\v3\Interfaces\OrderStatisticsServiceInterface;use App\TaskWorker\SSDBTask;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');
if ($type == OrderType::ONLINE) { $builder = $builder->join($goodsTable, ''.$goodsTable.'.order_id', '=', ''.$childTable.'.id'); }
$builder = $builder->where([''.$childTable.'.store_id' => $storeId, ''.$mainTable.'.type' => $type]) ->where(function ($query) use ($mainTable, $goodsTable, $type) { $query->where(function ($q) use ($mainTable, $goodsTable, $type) { $q->whereIn(''.$mainTable.'.state', array_merge(OrderState::FINISH, [OrderState::REFUNDED_DIRECT,OrderState::REFUND_REFUSE])); if ($type == OrderType::ONLINE) { $q->whereIn(''.$goodsTable.'.status', [1,2]); }
})->orWhere(''.$mainTable.'.coupon_money', '>', 0); });
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;
}
public function setForMarket($marketId) { $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); $incr = $ssdb->exec('incr', SsdbKeys::TODAY_SALES_FOR_MARKET.$marketId); $expire = strtotime('23:59:59') - time(); $expire = $ssdb->exec('expire', SsdbKeys::TODAY_SALES_FOR_MARKET.$marketId,$expire); return $incr && $expire; }
public function getForMarket($marketId) { $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); $count = $ssdb->exec('get', SsdbKeys::TODAY_SALES_FOR_MARKET.$marketId); return $count; }}
|