15 changed files with 272 additions and 56 deletions
-
8app/Controller/v3/HomeController.php
-
66app/Controller/v3/OrderOfflineController.php
-
17app/Model/v3/Order.php
-
21app/Model/v3/OrderGoods.php
-
5app/Model/v3/Store.php
-
45app/Request/v3/OrderOfflineRequest.php
-
95app/Service/v3/Implementations/OrderOfflineService.php
-
15app/Service/v3/Implementations/OrderOnlineService.php
-
6app/Service/v3/Implementations/PaymentService.php
-
30app/Service/v3/Implementations/StoreInfoService.php
-
5app/Service/v3/Implementations/StoreService.php
-
10app/Service/v3/Interfaces/OrderOfflineServiceInterface.php
-
2app/Service/v3/Interfaces/PaymentServiceInterface.php
-
1config/autoload/dependencies.php
-
2config/routes.php
@ -0,0 +1,66 @@ |
|||
<?php |
|||
|
|||
namespace App\Controller\v3; |
|||
|
|||
use App\Controller\BaseController; |
|||
use App\Request\v3\OrderOfflineRequest; |
|||
use App\Request\v3\OrderOnlineRequest; |
|||
use App\Service\v3\Interfaces\OrderOfflineServiceInterface; |
|||
use App\Service\v3\Interfaces\StoreServiceInterface; |
|||
use Hyperf\Validation\ValidationException; |
|||
use Hyperf\Di\Annotation\Inject; |
|||
|
|||
class OrderOfflineController extends BaseController |
|||
{ |
|||
/** |
|||
* @Inject |
|||
* @var StoreServiceInterface |
|||
*/ |
|||
protected $storeService; |
|||
|
|||
/** |
|||
* @Inject |
|||
* @var OrderOfflineServiceInterface |
|||
*/ |
|||
protected $orderOfflineService; |
|||
|
|||
/** |
|||
* 当面付的页面详情 |
|||
* 1、上传store_id,获取商户相关信息 |
|||
* 2、返回商户相关信息即可 |
|||
*/ |
|||
public function review() |
|||
{ |
|||
$validator = $this->validationFactory->make( |
|||
$this->request->all(), |
|||
['store_id' => 'required|nonempty'], |
|||
['*.*' => '商户ID参数异常'] |
|||
); |
|||
|
|||
if ($validator->fails()) { |
|||
throw new ValidationException($validator); |
|||
} |
|||
|
|||
$params = $validator->validated(); |
|||
$store = $this->storeService->detail($params['store_id']); |
|||
return $this->success(['store' => $store]); |
|||
} |
|||
|
|||
/** |
|||
* 当面付下单支付 |
|||
* 1、用户id、去商户id下支付、支付的金额 |
|||
* 2、下单同时支付,下发支付参数 |
|||
* @param OrderOfflineRequest $request |
|||
*/ |
|||
public function add(OrderOfflineRequest $request) |
|||
{ |
|||
$params = $request->validated(); |
|||
$data = $this->orderOfflineService->do( |
|||
$params['store_id'], |
|||
$params['user_id'], |
|||
$params['money'], |
|||
$params['plat'] |
|||
); |
|||
return $this->success(['data' => $data]); |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Request\v3; |
|||
|
|||
use App\Request\BaseFormRequest; |
|||
|
|||
class OrderOfflineRequest extends BaseFormRequest |
|||
{ |
|||
/** |
|||
* Determine if the user is authorized to make this request. |
|||
*/ |
|||
public function authorize(): bool |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
/** |
|||
* Get the validation rules that apply to the request. |
|||
*/ |
|||
public function rules(): array |
|||
{ |
|||
return [ |
|||
'store_id' => 'required|nonempty|integer', |
|||
'user_id' => 'required|nonempty|integer', |
|||
'money' => 'required|nonempty', |
|||
'plat' => 'nonempty', |
|||
]; |
|||
} |
|||
|
|||
public function messages(): array |
|||
{ |
|||
return [ |
|||
'*.*' => ':attribute 参数异常' |
|||
]; |
|||
} |
|||
|
|||
public function attributes(): array |
|||
{ |
|||
return [ |
|||
|
|||
]; |
|||
} |
|||
} |
|||
@ -0,0 +1,95 @@ |
|||
<?php |
|||
|
|||
namespace App\Service\v3\Implementations; |
|||
|
|||
use App\Constants\v3\ErrorCode; |
|||
use App\Constants\v3\LogLabel; |
|||
use App\Constants\v3\OrderState; |
|||
use App\Constants\v3\OrderType; |
|||
use App\Exception\ErrorCodeException; |
|||
use App\Model\v3\Order; |
|||
use App\Model\v3\OrderMain; |
|||
use App\Model\v3\Store; |
|||
use App\Service\v3\Interfaces\OrderOfflineServiceInterface; |
|||
use App\Service\v3\Interfaces\PaymentServiceInterface; |
|||
use Hyperf\DbConnection\Db; |
|||
use Hyperf\Snowflake\IdGeneratorInterface; |
|||
use Hyperf\Utils\ApplicationContext; |
|||
use Hyperf\Di\Annotation\Inject; |
|||
|
|||
class OrderOfflineService implements OrderOfflineServiceInterface |
|||
{ |
|||
|
|||
/** |
|||
* @Inject |
|||
* @var PaymentServiceInterface |
|||
*/ |
|||
protected $paymentService; |
|||
|
|||
public function do($storeId, $userId, $money, $plat ='') |
|||
{ |
|||
try { |
|||
|
|||
$store = Store::find($storeId); |
|||
|
|||
// 获取分布式全局ID
|
|||
$generator = ApplicationContext::getContainer()->get(IdGeneratorInterface::class); |
|||
$globalOrderId = $generator->generate(); |
|||
|
|||
$dataMain = [ |
|||
'market_id' => $store->market_id, |
|||
'order_num' => $globalOrderId, |
|||
'global_order_id' => $globalOrderId, |
|||
'user_id' => $userId, |
|||
'type' => OrderType::OFFLINE, |
|||
'money' => $money, |
|||
'total_money' => $money, |
|||
'services_money' => 0, |
|||
'coupon_money' => 0, |
|||
'delivery_money' => 0, |
|||
'state' => OrderState::UNPAID, |
|||
'tel' => '', |
|||
'address' => '', |
|||
'lat' => '', |
|||
'lng' => '', |
|||
'name' => '', |
|||
'plat' => $plat, |
|||
'delivery_time_note' => '' |
|||
]; |
|||
|
|||
$orderMain = OrderMain::create($dataMain); |
|||
$orderMainId = $orderMain->id; |
|||
|
|||
// 子订单数据
|
|||
$dataChildren = [ |
|||
'order_main_id' => $orderMainId, |
|||
'user_id' => $userId, |
|||
'store_id' => $storeId, |
|||
'money' => $money, |
|||
'order_num' => date('YmdHis').mt_rand(1000, 9999), |
|||
'note' => '' |
|||
]; |
|||
|
|||
$orderChild = Order::create($dataChildren); |
|||
$orderChildId = $orderChild->id; |
|||
|
|||
Db::commit(); |
|||
// 支付
|
|||
return $this->paymentService->do($globalOrderId, $money, $userId, config('site_host') . '/wechat/notify/wxminioffline'); |
|||
} catch (\Exception $e) { |
|||
Db::rollBack(); |
|||
$this->log->event(LogLabel::ORDER_ONLINE_LOG, ['exception_msg' => $e->getMessage()]); |
|||
throw new ErrorCodeException(ErrorCode::ORDER_ONLINE_FAIL); |
|||
} |
|||
} |
|||
|
|||
public function check() |
|||
{ |
|||
// TODO: Implement check() method.
|
|||
} |
|||
|
|||
public function undo() |
|||
{ |
|||
// TODO: Implement undo() method.
|
|||
} |
|||
} |
|||
@ -1,30 +0,0 @@ |
|||
<?php |
|||
|
|||
|
|||
namespace App\Service\v3\Implementations; |
|||
|
|||
use App\Service\v3\Interfaces\StoreInfoServiceInterface; |
|||
use App\Model\v3\Store; |
|||
class StoreInfoService implements StoreInfoServiceInterface |
|||
{ |
|||
|
|||
public function do() |
|||
{ |
|||
// TODO: Implement do() method.
|
|||
} |
|||
|
|||
public function check() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public function undo() |
|||
{ |
|||
// TODO: Implement undo() method.
|
|||
} |
|||
|
|||
public function detail() |
|||
{ |
|||
return Store::query()->where('id',1)->first()->toArray(); |
|||
} |
|||
} |
|||
@ -1,16 +1,10 @@ |
|||
<?php |
|||
|
|||
|
|||
namespace App\Service\v3\Interfaces; |
|||
|
|||
|
|||
interface StoreInfoServiceInterface |
|||
interface OrderOfflineServiceInterface |
|||
{ |
|||
public function do(); |
|||
|
|||
public function do($storeId, $userId, $money, $plat=''); |
|||
public function check(); |
|||
|
|||
public function undo(); |
|||
|
|||
public function detail(); |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue