feat : driver
This commit is contained in:
@@ -6,7 +6,6 @@ namespace App\Controller\Admin;
|
||||
|
||||
use App\Middleware\Admin\JwtAuthMiddleware;
|
||||
use App\Request\Admin\DriverRequest;
|
||||
use App\Request\Admin\SiteRequest;
|
||||
use App\Service\Admin\System\DriverService;
|
||||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\Middlewares;
|
||||
@@ -28,6 +27,66 @@ class DriverController
|
||||
#[Scene(scene: "driver_list")]
|
||||
public function driverList(DriverRequest $request)
|
||||
{
|
||||
return (new DriverService())->driverList();
|
||||
return (new DriverService)->driverList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 司机配送顺序列表
|
||||
* @param DriverRequest $request
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "driver_sequence_list", methods: "GET")]
|
||||
#[Scene(scene: "driver_sequence_list")]
|
||||
public function driverSequenceList(DriverRequest $request)
|
||||
{
|
||||
return (new DriverService)->driverSequenceList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置司机排序
|
||||
* @param DriverRequest $request
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "setting_driver_sequence", methods: "POST")]
|
||||
#[Scene(scene: "setting_driver_sequence")]
|
||||
public function settingDriverSequence(DriverRequest $request)
|
||||
{
|
||||
return (new DriverService)->settingDriverSequence();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置司机号码
|
||||
* @param DriverRequest $request
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "setting_driver_num", methods: "POST")]
|
||||
#[Scene(scene: "setting_driver_num")]
|
||||
public function settingDriverNum(DriverRequest $request)
|
||||
{
|
||||
return (new DriverService)->settingDriverNum();
|
||||
}
|
||||
|
||||
/**
|
||||
* 站点顺序列表
|
||||
* @param DriverRequest $request
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "site_sequence_list_by_driver", methods: "GET")]
|
||||
#[Scene(scene: "site_sequence_list_by_driver")]
|
||||
public function siteSequenceListByDriver(DriverRequest $request)
|
||||
{
|
||||
return (new DriverService)->siteSequenceListByDriver();
|
||||
}
|
||||
|
||||
/**
|
||||
* 站点设置顺序
|
||||
* @param DriverRequest $request
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "setting_site_sequence", methods: "POST")]
|
||||
#[Scene(scene: "setting_site_sequence")]
|
||||
public function settingSiteSequence(DriverRequest $request)
|
||||
{
|
||||
return (new DriverService)->settingSiteSequence();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ use Hyperf\DbConnection\Model\Model;
|
||||
* @property int $is_del
|
||||
* @property int $role_id
|
||||
* @property int $section_id
|
||||
* @property int $city_id
|
||||
* @property string $create_time
|
||||
* @property string $update_time
|
||||
*/
|
||||
|
||||
49
app/Model/DriverSequence.php
Normal file
49
app/Model/DriverSequence.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use Hyperf\Database\Model\Builder;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $driver_id
|
||||
* @property int $driver_num
|
||||
* @property int $sequence
|
||||
* @property string $create_time
|
||||
* @property string $update_time
|
||||
*/
|
||||
class DriverSequence extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'driver_sequence';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = [];
|
||||
|
||||
protected array $guarded = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*/
|
||||
protected array $casts = ['id' => 'integer', 'driver_id' => 'integer', 'driver_num' => 'integer', 'sequence' => 'integer'];
|
||||
|
||||
const string CREATED_AT = 'create_time';
|
||||
|
||||
const string UPDATED_AT = 'update_time';
|
||||
|
||||
/**
|
||||
* @param int $driverId
|
||||
* @return Builder|\Hyperf\Database\Model\Model|null
|
||||
*/
|
||||
public function getInfoByDriverId(int $driverId): \Hyperf\Database\Model\Model|Builder|null
|
||||
{
|
||||
return $this->where('driver_id', $driverId)->first();
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ namespace App\Model;
|
||||
|
||||
use App\Constants\Common\SiteCode;
|
||||
use Hyperf\Database\Model\Builder;
|
||||
use Hyperf\Database\Model\Collection;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
/**
|
||||
@@ -23,7 +24,8 @@ use Hyperf\DbConnection\Model\Model;
|
||||
* @property string $expected_spend_time
|
||||
* @property int $status
|
||||
* @property int $image_id
|
||||
* @property int $delivered_id
|
||||
* @property int $delivered_id
|
||||
* @property int $sequence
|
||||
* @property string $create_time
|
||||
* @property string $update_time
|
||||
* @property int $is_del
|
||||
@@ -81,4 +83,17 @@ class Site extends Model
|
||||
{
|
||||
return $this->where('id',$id)->where('is_del',SiteCode::SITE_NO_DEL)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $driverId
|
||||
* @return Collection|array
|
||||
*/
|
||||
public function getSiteSequenceListByDriver(int $driverId): Collection|array
|
||||
{
|
||||
return $this
|
||||
->where('is_del',SiteCode::SITE_NO_DEL)
|
||||
->where('status',SiteCode::SITE_ENABLE)
|
||||
->where('delivered_id',$driverId)
|
||||
->get(['id','name', 'sequence']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -96,7 +96,8 @@ class EmployeeService extends BaseService
|
||||
$model->status = $this->request->input('status', 1);
|
||||
$model->avatar = $this->request->input('avatar',0);
|
||||
$model->role_id = $this->request->input('role_id', 0);
|
||||
$model->section_id = $this->request->input('section_id', 0);
|
||||
$model->city_id = $this->request->input('city_id', 0);
|
||||
// $model->section_id = $this->request->input('section_id', 0);
|
||||
|
||||
if (!$model->save()) throw new ErrException('账号添加失败');
|
||||
|
||||
@@ -128,6 +129,7 @@ class EmployeeService extends BaseService
|
||||
$info->status = $this->request->input('status', 1);
|
||||
$info->avatar = $this->request->input('avatar',0);
|
||||
$info->role_id = $this->request->input('role_id', 0);
|
||||
$info->city_id = $this->request->input('city_id', 0);
|
||||
$info->section_id = $this->request->input('section_id', 0);
|
||||
|
||||
if (!$info->save()) throw new ErrException('账号修改失败');
|
||||
|
||||
@@ -205,7 +205,39 @@ GET {{host}}/admin/site/del?id=1
|
||||
content-type: application/json
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
|
||||
### 司机列表
|
||||
GET {{host}}/admin/site/driver_list?limit=1
|
||||
content-type: application/json
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
### 司机配送顺序列表
|
||||
GET {{host}}/admin/site/driver_sequence_list?city_id=1
|
||||
content-type: application/json
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
### 设置司机排序
|
||||
POST {{host}}/admin/site/setting_driver_sequence
|
||||
content-type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
driver_ids=1,2,3
|
||||
|
||||
### 设置司机号码
|
||||
POST {{host}}/admin/site/setting_driver_num
|
||||
content-type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
driver_id=1&driver_num=50
|
||||
|
||||
### 司机配送顺序列表
|
||||
GET {{host}}/admin/site/site_sequence_list_by_driver?driver_id=1
|
||||
content-type: application/json
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
### 设置司机排序
|
||||
POST {{host}}/admin/site/setting_driver_sequence
|
||||
content-type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
driver_id=1&site_ids=1,2,3
|
||||
Reference in New Issue
Block a user