feat : driver
This commit is contained in:
@@ -12,9 +12,13 @@ namespace App\Service\Admin\System;
|
||||
|
||||
use App\Constants\Admin\UserCode;
|
||||
use App\Constants\Common\RoleCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\AdminSection;
|
||||
use App\Model\AdminUser;
|
||||
use App\Model\DriverSequence;
|
||||
use App\Model\Site;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class DriverService extends BaseService
|
||||
@@ -32,6 +36,18 @@ class DriverService extends BaseService
|
||||
#[Inject]
|
||||
protected readonly AdminUser $adminUserModel;
|
||||
|
||||
/**
|
||||
* @var DriverSequence
|
||||
*/
|
||||
#[Inject]
|
||||
protected readonly DriverSequence $driverSequenceModel;
|
||||
|
||||
/**
|
||||
* @var Site
|
||||
*/
|
||||
#[Inject]
|
||||
protected readonly Site $siteModel;
|
||||
|
||||
|
||||
public function handle()
|
||||
{
|
||||
@@ -74,4 +90,123 @@ class DriverService extends BaseService
|
||||
|
||||
return $this->return->success('success',$list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 司机配送顺序列表
|
||||
* @return array
|
||||
*/
|
||||
public function driverSequenceList(): array
|
||||
{
|
||||
if (empty($this->cityId)) return $this->return->success('success',['list' => []]);
|
||||
|
||||
$list = $this
|
||||
->adminUserModel
|
||||
->leftJoin('driver_sequence', 'admin_user.id', '=', 'driver_sequence.driver_id')
|
||||
->where('admin_user.is_del',UserCode::IS_NO_DEL)
|
||||
->where('admin_user.status',UserCode::ENABLE)
|
||||
->where('admin_user.role_id',RoleCode::DRIVER)
|
||||
->where('admin_user.city_id', $this->cityId)
|
||||
->get(['admin_user.id','admin_user.chinese_name','driver_order.driver_num','driver_order.sequence']);
|
||||
|
||||
if (empty($list)) return $this->return->success('success',['list' => []]);
|
||||
|
||||
return $this->return->success('success',['list' => $list->toArray()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置司机排序
|
||||
* @return array
|
||||
*/
|
||||
public function settingDriverSequence(): array
|
||||
{
|
||||
$driverArr = explode(',',$this->request->input('driver_ids'));
|
||||
|
||||
$list = $this->driverSequenceModel->whereIn('driver_id',$driverArr)->pluck('driver_num','driver_id')->toArray();
|
||||
|
||||
$updateArr = [];
|
||||
|
||||
foreach ($driverArr as $key => $one) {
|
||||
$oneSequence = $key + 1;
|
||||
$updateArr[] = [
|
||||
'driver_id' => $one,
|
||||
'sequence' => $oneSequence,
|
||||
'driver_num' => $list[$one] ?? 0,
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($updateArr)) {
|
||||
Db::table('driver_sequence')->upsert($updateArr,['driver_id']);
|
||||
}
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置司机号码
|
||||
* @return array
|
||||
*/
|
||||
public function settingDriverNum(): array
|
||||
{
|
||||
$driverId = (int)$this->request->input('driver_id');
|
||||
$driverNum = $this->request->input('driver_num');
|
||||
|
||||
$info = $this->driverSequenceModel->getInfoByDriverId($driverId);
|
||||
|
||||
if (empty($info)) {
|
||||
$info = new DriverSequence();
|
||||
|
||||
$info->driver_id = $driverId;
|
||||
$info->driver_num = $driverNum;
|
||||
$info->sequence = 999;
|
||||
} else {
|
||||
$info->driver_num = $driverNum;
|
||||
}
|
||||
|
||||
if (!$info->save()) throw new ErrException('设置司机号码失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 站点顺序列表
|
||||
* @return array
|
||||
*/
|
||||
public function siteSequenceListByDriver(): array
|
||||
{
|
||||
$driverId = (int)$this->request->input('driver_id');
|
||||
|
||||
$list = $this->siteModel->getSiteSequenceListByDriver($driverId);
|
||||
|
||||
if (empty($list)) return $this->return->success('success',['list' => []]);
|
||||
|
||||
return $this->return->success('success',['list' => $list->toArray()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 站点设置顺序
|
||||
* @return array
|
||||
*/
|
||||
public function settingSiteSequence(): array
|
||||
{
|
||||
$siteArr = explode(',',$this->request->input('site_ids'));
|
||||
$driverId = (int)$this->request->input('driver_id');
|
||||
|
||||
$list = $this->siteModel->getSiteSequenceListByDriver($driverId);
|
||||
if (empty($list)) throw new ErrException('站点列表为空');
|
||||
|
||||
if (count($list->toArray()) != count($siteArr)) throw new ErrException('站点数据不对,刷新后重新设置');
|
||||
|
||||
$updateArr = [];
|
||||
foreach ($siteArr as $key => $one) {
|
||||
$updateArr[] = [
|
||||
'id' => $one,
|
||||
'sequence' => $key + 1,
|
||||
];
|
||||
}
|
||||
|
||||
$updateHandle = (new Site)->update($updateArr);
|
||||
if (!$updateHandle) throw new ErrException('设置失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user