35 changed files with 594 additions and 41 deletions
-
10app/Constants/v3/ErrorCode.php
-
10app/Constants/v3/SsdbKeys.php
-
6app/Controller/v3/GoodsController.php
-
8app/Controller/v3/HomeController.php
-
90app/Controller/v3/HorsemanController.php
-
10app/Controller/v3/NotifyController.php
-
26app/Controller/v3/OrderOnlineController.php
-
2app/Controller/v3/SearchController.php
-
5app/Controller/v3/UserAddressController.php
-
22app/Model/v3/Employees.php
-
6app/Model/v3/Goods.php
-
17app/Model/v3/OrderMain.php
-
33app/Request/v3/EmployeesRequest.php
-
33app/Request/v3/HorsemanOrderRequest.php
-
28app/Service/v3/Implementations/DistributionPriceService.php
-
10app/Service/v3/Implementations/FeiePrintService.php
-
48app/Service/v3/Implementations/HelperService.php
-
95app/Service/v3/Implementations/HorsemanService.php
-
2app/Service/v3/Implementations/OrderListService.php
-
33app/Service/v3/Implementations/OrderOnlineService.php
-
18app/Service/v3/Implementations/OrderStatisticsService.php
-
13app/Service/v3/Implementations/SearchService.php
-
3app/Service/v3/Implementations/StoreService.php
-
11app/Service/v3/Implementations/TabsService.php
-
10app/Service/v3/Implementations/UserAddressService.php
-
36app/Service/v3/Implementations/UserCenterBlockService.php
-
9app/Service/v3/Implementations/UserInfoService.php
-
2app/Service/v3/Interfaces/DistributionPriceServiceInterface.php
-
16app/Service/v3/Interfaces/HorsemanServiceInterface.php
-
9app/Service/v3/Interfaces/OrderOnlineServiceInterface.php
-
2app/Service/v3/Interfaces/OrderStatisticsServiceInterface.php
-
2app/Service/v3/Interfaces/UserInfoServiceInterface.php
-
1config/autoload/dependencies.php
-
2config/config.php
-
7config/routes.php
@ -0,0 +1,90 @@ |
|||||
|
<?php |
||||
|
|
||||
|
|
||||
|
namespace App\Controller\v3; |
||||
|
|
||||
|
use App\Constants\v3\ErrorCode; |
||||
|
use App\Constants\v3\LogLabel; |
||||
|
use App\Controller\BaseController; |
||||
|
use App\Exception\ErrorCodeException; |
||||
|
use App\Model\v3\OrderMain; |
||||
|
use App\Service\v3\Interfaces\HorsemanServiceInterface; |
||||
|
use App\Service\v3\Interfaces\SeparateAccountsServiceInterface; |
||||
|
use Hyperf\DbConnection\Db; |
||||
|
use Hyperf\Di\Annotation\Inject; |
||||
|
use App\Service\v3\Interfaces\OrderOnlineServiceInterface; |
||||
|
use App\Request\v3\EmployeesRequest; |
||||
|
use App\Request\v3\HorsemanOrderRequest; |
||||
|
class HorsemanController extends BaseController |
||||
|
{ |
||||
|
/** |
||||
|
* @Inject |
||||
|
* @var HorsemanServiceInterface |
||||
|
*/ |
||||
|
protected $horsemanService; |
||||
|
|
||||
|
/** |
||||
|
* @Inject |
||||
|
* @var OrderOnlineServiceInterface |
||||
|
*/ |
||||
|
protected $orderOnlineService; |
||||
|
|
||||
|
/** |
||||
|
* @Inject |
||||
|
* @var SeparateAccountsServiceInterface |
||||
|
*/ |
||||
|
protected $separateAccountsService; |
||||
|
|
||||
|
public function getOrderList(EmployeesRequest $request) |
||||
|
{ |
||||
|
$employeesId = $this->request->input('employees_id', -1); |
||||
|
$page = $this->request->input('page',0); |
||||
|
$pagesize = $this->request->input('pagesize',0); |
||||
|
$orderMainList = $this->horsemanService->getOrderList($employeesId,$page, $pagesize); |
||||
|
return $this->success($orderMainList); |
||||
|
} |
||||
|
|
||||
|
public function getOrderInfo(HorsemanOrderRequest $request) |
||||
|
{ |
||||
|
$globalOrderId = $this->request->input('global_order_id', -1); |
||||
|
$orderMain = $this->orderOnlineService->getOrderInfo($globalOrderId); |
||||
|
return $this->success(['order' => $orderMain]); |
||||
|
} |
||||
|
|
||||
|
public function setHorsemanCoordinate(EmployeesRequest $request) |
||||
|
{ |
||||
|
$employeesId = $this->request->input('employees_id', -1); |
||||
|
$coordinate = $this->request->input('coordinate', -1); |
||||
|
return $this->success($this->horsemanService->setHorsemanCoordinate($employeesId,$coordinate)); |
||||
|
} |
||||
|
|
||||
|
public function getHorsemanCoordinate(EmployeesRequest $request) |
||||
|
{ |
||||
|
$employeesId = $this->request->input('employees_id', -1); |
||||
|
$coordinate = $this->horsemanService->getHorsemanCoordinate($employeesId); |
||||
|
return $this->success(['coordinate' => $coordinate]); |
||||
|
} |
||||
|
|
||||
|
public function getOrderCoordinate() |
||||
|
{ |
||||
|
$globalOrderId = $this->request->input('global_order_id', -1); |
||||
|
return $this->success($this->horsemanService->getOrderCoordinate($globalOrderId)); |
||||
|
} |
||||
|
|
||||
|
public function orderComplete(HorsemanOrderRequest $request) |
||||
|
{ |
||||
|
$globalOrderId = $this->request->input('global_order_id', -1); |
||||
|
$userId = OrderMain::query()->where('global_order_id',$globalOrderId)->value('user_id'); |
||||
|
Db::beginTransaction(); |
||||
|
try { |
||||
|
$this->orderOnlineService->doComplete($globalOrderId, $userId); |
||||
|
$this->separateAccountsService->orderOnlineCompleted($globalOrderId, $userId); |
||||
|
Db::commit(); |
||||
|
return $this->success(true); |
||||
|
} catch (\Exception $e) { |
||||
|
Db::rollBack(); |
||||
|
$this->log->event(LogLabel::ORDER_COMPLETE_LOG, ['exception' => $e->getMessage()]); |
||||
|
throw new ErrorCodeException(ErrorCode::ORDER_COMPLETE_FAIL); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
<?php |
||||
|
|
||||
|
|
||||
|
namespace App\Model\v3; |
||||
|
use App\Model\Model; |
||||
|
use Hyperf\Database\Model\Builder; |
||||
|
class Employees extends Model |
||||
|
{ |
||||
|
protected $table = 'lanzu_employees'; |
||||
|
|
||||
|
protected $casts = [ |
||||
|
'position' => 'array' |
||||
|
]; |
||||
|
|
||||
|
protected function boot(): void |
||||
|
{ |
||||
|
parent::boot(); |
||||
|
self::addGlobalScope('normal', function (Builder $builder) { |
||||
|
$builder->where([$this->getTable().'.status' => 1]); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
<?php |
||||
|
|
||||
|
|
||||
|
namespace App\Request\v3; |
||||
|
use App\Request\BaseFormRequest; |
||||
|
|
||||
|
class EmployeesRequest extends BaseFormRequest |
||||
|
{ |
||||
|
/** |
||||
|
* Get the validation rules that apply to the request. |
||||
|
*/ |
||||
|
public function rules(): array |
||||
|
{ |
||||
|
return [ |
||||
|
'employees_id' => 'required|nonempty|integer', |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function messages(): array |
||||
|
{ |
||||
|
return [ |
||||
|
'*.*' => ':attribute无效', |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
public function attributes(): array |
||||
|
{ |
||||
|
return parent::attributes(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
<?php |
||||
|
|
||||
|
|
||||
|
namespace App\Request\v3; |
||||
|
use App\Request\BaseFormRequest; |
||||
|
|
||||
|
class HorsemanOrderRequest extends BaseFormRequest |
||||
|
{ |
||||
|
/** |
||||
|
* Get the validation rules that apply to the request. |
||||
|
*/ |
||||
|
public function rules(): array |
||||
|
{ |
||||
|
return [ |
||||
|
'global_order_id' => 'required|nonempty|integer', |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function messages(): array |
||||
|
{ |
||||
|
return [ |
||||
|
'*.*' => ':attribute无效', |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
public function attributes(): array |
||||
|
{ |
||||
|
return parent::attributes(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,95 @@ |
|||||
|
<?php |
||||
|
|
||||
|
|
||||
|
namespace App\Service\v3\Implementations; |
||||
|
use App\Model\v3\Market; |
||||
|
use App\Model\v3\OrderMain; |
||||
|
use Hyperf\Di\Annotation\Inject; |
||||
|
use App\Service\v3\Interfaces\HorsemanServiceInterface; |
||||
|
use Hyperf\Utils\ApplicationContext; |
||||
|
use App\Constants\v3\SsdbKeys; |
||||
|
use App\TaskWorker\SSDBTask; |
||||
|
use App\Constants\v3\ErrorCode; |
||||
|
use App\Exception\ErrorCodeException; |
||||
|
class HorsemanService implements HorsemanServiceInterface |
||||
|
{ |
||||
|
public function do() |
||||
|
{ |
||||
|
// TODO: Implement do() method.
|
||||
|
} |
||||
|
|
||||
|
public function check() |
||||
|
{ |
||||
|
// TODO: Implement check() method.
|
||||
|
} |
||||
|
|
||||
|
public function undo() |
||||
|
{ |
||||
|
// TODO: Implement undo() method.
|
||||
|
} |
||||
|
public function getOrderList($employeesId,$page=1, $pagesize=10) |
||||
|
{ |
||||
|
$builder = OrderMain::query()->where(['state' => 3,'horseman_id' => $employeesId]); |
||||
|
$paginate = $builder->orderBy('created_at', 'desc')->paginate($pagesize); |
||||
|
$orders = $paginate->toArray(); |
||||
|
return [ |
||||
|
'has_more_pages' => $paginate->hasMorePages(), |
||||
|
'order_list' => $orders['data'] |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 记录骑手坐标 |
||||
|
*/ |
||||
|
public function setHorsemanCoordinate($employeesId,$coordinate){ |
||||
|
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); |
||||
|
if(false === $ssdb->exec('set', SsdbKeys::HORSEMAN_COORDINATE.$employeesId,$coordinate)) { |
||||
|
return false; |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取骑手坐标 |
||||
|
*/ |
||||
|
public function getHorsemanCoordinate($employeesId){ |
||||
|
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); |
||||
|
$params = $ssdb->exec('get', SsdbKeys::HORSEMAN_COORDINATE.$employeesId); |
||||
|
|
||||
|
if ((false === $params) || empty($params)) { |
||||
|
throw new ErrorCodeException(ErrorCode::HORSEMAN_COORDINATE_FAIL, '骑手正在配送中'); |
||||
|
} |
||||
|
return $params; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取订单起止坐标 |
||||
|
*/ |
||||
|
public function getOrderCoordinate($globalOrderId){ |
||||
|
//获取订单信息
|
||||
|
$order = OrderMain::where('global_order_id',$globalOrderId) |
||||
|
->select( |
||||
|
'lat', |
||||
|
'lng', |
||||
|
'state', |
||||
|
'market_id' |
||||
|
) |
||||
|
->first(); |
||||
|
if($order->state != 3) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
//获取市场信息
|
||||
|
$market = Market::where('id',$order->market_id) |
||||
|
->select( |
||||
|
'lat', |
||||
|
'lng' |
||||
|
) |
||||
|
->first(); |
||||
|
$res = [ |
||||
|
'order' => $order, |
||||
|
'market' => $market |
||||
|
]; |
||||
|
return $res; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
<?php |
||||
|
|
||||
|
|
||||
|
namespace App\Service\v3\Interfaces; |
||||
|
|
||||
|
|
||||
|
interface HorsemanServiceInterface |
||||
|
{ |
||||
|
public function do(); |
||||
|
public function check(); |
||||
|
public function undo(); |
||||
|
public function getOrderList($employeesId,$page=1, $pagesize=10); |
||||
|
public function setHorsemanCoordinate($horsemanId,$coordinate); |
||||
|
public function getHorsemanCoordinate($horsemanId); |
||||
|
public function getOrderCoordinate($globalOrderId); |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue