feat : spu
This commit is contained in:
56
app/Service/Api/Driver/BaseDriverService.php
Normal file
56
app/Service/Api/Driver/BaseDriverService.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\Driver;
|
||||
|
||||
use App\Constants\Common\RoleCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\AdminUser;
|
||||
use App\Service\Api\BaseService;
|
||||
use App\Service\ServiceTrait\Common\CycleTrait;
|
||||
use Hyperf\Database\Model\Builder;
|
||||
use Hyperf\Database\Model\Model;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
abstract class BaseDriverService extends BaseService
|
||||
{
|
||||
use CycleTrait;
|
||||
|
||||
/**
|
||||
* @var AdminUser
|
||||
*/
|
||||
#[Inject]
|
||||
protected AdminUser $adminUserModel;
|
||||
|
||||
/**
|
||||
* @var Builder|Model|AdminUser|null
|
||||
*/
|
||||
protected AdminUser|null|Builder|Model $adminInfo;
|
||||
|
||||
protected int $cycleId;
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->cycleId = $this->initTodayCycleId();
|
||||
|
||||
$this->adminInfo = $this->adminUserModel->getAdminInfoByBindUserId($this->userId);
|
||||
if ($this->adminInfo->role_id != RoleCode::DRIVER) throw new ErrException('暂无权限,请联系客服并提供相关信息绑定账号');
|
||||
}
|
||||
|
||||
abstract public function handle();
|
||||
}
|
||||
166
app/Service/Api/Driver/GetSiteListService.php
Normal file
166
app/Service/Api/Driver/GetSiteListService.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\Driver;
|
||||
|
||||
use App\Constants\Admin\CateringCode;
|
||||
use App\Constants\Common\GoodCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\OrderMealCateringLog;
|
||||
use App\Model\OrderOptionCateringLog;
|
||||
use App\Model\Site;
|
||||
use App\Model\Sku;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class GetSiteListService extends BaseDriverService
|
||||
{
|
||||
/**
|
||||
* @var Site
|
||||
*/
|
||||
#[Inject]
|
||||
protected Site $siteModel;
|
||||
|
||||
/**
|
||||
* @var OrderMealCateringLog
|
||||
*/
|
||||
#[Inject]
|
||||
protected OrderMealCateringLog $orderMealCateringLogModel;
|
||||
|
||||
/**
|
||||
* @var OrderOptionCateringLog
|
||||
*/
|
||||
#[Inject]
|
||||
protected OrderOptionCateringLog $orderOptionCateringLogModel;
|
||||
|
||||
/**
|
||||
* @var Sku
|
||||
*/
|
||||
#[Inject]
|
||||
protected Sku $skuModel;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected array $siteIds;
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private function setCache()
|
||||
{
|
||||
$siteArr = $this->siteModel
|
||||
->where('delivered_id',$this->adminInfo->id)
|
||||
->orderBy('sequence')
|
||||
->get();
|
||||
if ($siteArr->isEmpty()) throw new ErrException('该司机并未绑定站点');
|
||||
$siteArr = array_column($siteArr->toArray(),null,'id');
|
||||
$this->siteIds = array_keys($siteArr);
|
||||
|
||||
$optionArr = $this->getOptionData();
|
||||
|
||||
$mealArr = $this->getMealData();
|
||||
|
||||
$res = [];
|
||||
foreach ($siteArr as $site) {
|
||||
if (empty($res[$site['id']])) {
|
||||
$res[$site['id']] = [
|
||||
'site_id' => $site['id'],
|
||||
'site_name' => $site['name'],
|
||||
'name' => '',
|
||||
'meal_order_quantity' => 0,
|
||||
'meal_add_staple_food_num' => 0,
|
||||
'option_order_quantity' => 0,
|
||||
'option_add_staple_food_num' => 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getMealData(): array
|
||||
{
|
||||
$mealArr = $this->orderMealCateringLogModel
|
||||
->where('cycle_id',$this->cycleId)
|
||||
->where('status',CateringCode::CATERING_STATUS_FINISH)
|
||||
->whereIn('site_id', $this->siteIds)
|
||||
->select(['quantity','site_id','sku_id'])
|
||||
->get();
|
||||
if ($mealArr->isEmpty()) $mealArr = [];
|
||||
$mealArr = $mealArr->toArray();
|
||||
|
||||
$skuIds = array_column($mealArr, 'sku_id');
|
||||
$skuArr = $this->skuModel->getDataArrByIds($skuIds);
|
||||
$skuArr = array_column($skuArr,null,'id');
|
||||
|
||||
|
||||
$res = [];
|
||||
foreach ($mealArr as $oneLog) {
|
||||
if (empty($res[$oneLog['site_id']])) {
|
||||
$res[$oneLog['site_id']] = [
|
||||
'total_copies' => 0,
|
||||
'add_staple_food_num' => 0,
|
||||
'sku' => []
|
||||
];
|
||||
}
|
||||
|
||||
if (empty($res[$oneLog['site_id']]['sku'][$oneLog['sku_id']])) {
|
||||
$res[$oneLog['site_id']]['sku'][$oneLog['sku_id']] = [
|
||||
'sku_id' => $oneLog['sku_id'],
|
||||
'sku_name' => $skuArr[$oneLog['sku_id']]['title'] ?? '',
|
||||
'quantity' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
if ($skuArr[$oneLog['sku_id']]['is_add_staple_food'] == GoodCode::IS_ADD_STAPLE_FOOD) {
|
||||
$res[$oneLog['site_id']]['add_staple_food_num'] += $oneLog['quantity'];
|
||||
} else {
|
||||
$res[$oneLog['site_id']]['total_copies'] += $oneLog['quantity'];
|
||||
}
|
||||
|
||||
$res[$oneLog['site_id']]['sku'][$oneLog['sku_id']]['quantity'] += $oneLog['quantity'];
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getOptionData(): array
|
||||
{
|
||||
$optionArr = $this->orderOptionCateringLogModel
|
||||
->where('cycle_id',$this->cycleId)
|
||||
->where('status',CateringCode::CATERING_STATUS_FINISH)
|
||||
->whereIn('site_id', $this->siteIds)
|
||||
->select(['quantity','site_id','add_staple_food_num'])
|
||||
->get();
|
||||
if ($optionArr->isEmpty()) $optionArr = [];
|
||||
$optionArr = $optionArr->toArray();
|
||||
|
||||
$res = [];
|
||||
foreach ($optionArr as $oneSite) {
|
||||
if (empty($res[$oneSite['site_id']])) {
|
||||
$res[$oneSite['site_id']] = [
|
||||
'copies' => 0,
|
||||
'add_staple_food_num' => 0
|
||||
];
|
||||
}
|
||||
|
||||
$res[$oneSite['site_id']]['copies'] = $oneSite['quantity'] + $res[$oneSite['site_id']]['copies'];
|
||||
$res[$oneSite['site_id']]['add_staple_food_num'] = $oneSite['add_staple_food_num'] + $res[$oneSite['site_id']]['add_staple_food_num'];
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user