diff --git a/app/Constants/LogLabel.php b/app/Constants/LogLabel.php index b3cadb4..aafacd8 100644 --- a/app/Constants/LogLabel.php +++ b/app/Constants/LogLabel.php @@ -21,4 +21,9 @@ class LogLabel extends AbstractConstants * @Message("Device Speaker Log Label") */ const DEVICE_LOG = 'device_log'; + + /** + * @Message("Pay Notice Log Label") + */ + const PAY_NOTIFY_WXMINI = 'notify_wxmini'; } diff --git a/app/Controller/NotifyController.php b/app/Controller/NotifyController.php index 8aa0ba0..02aa0a3 100644 --- a/app/Controller/NotifyController.php +++ b/app/Controller/NotifyController.php @@ -1,10 +1,16 @@ log->event( + LogLabel::PAY_NOTIFY_WXMINI, + json_encode($this->request->input()) + ); + } } \ No newline at end of file diff --git a/app/Controller/OrderController.php b/app/Controller/OrderController.php index 8d93c54..89a1cad 100644 --- a/app/Controller/OrderController.php +++ b/app/Controller/OrderController.php @@ -20,8 +20,8 @@ class OrderController extends BaseController { $orderMainId = $this->orderService->addOnlineOrder($request->validated()); if (!is_int($orderMainId)) { - return $this->w7result(500, $orderMainId); + return $this->w7result(500, (string)$orderMainId); } - return $this->w7result(200, $orderMainId); + return $this->w7result(200, (string)$orderMainId); } } \ No newline at end of file diff --git a/app/Controller/PaymentController.php b/app/Controller/PaymentController.php index 14fbc48..29b88e3 100644 --- a/app/Controller/PaymentController.php +++ b/app/Controller/PaymentController.php @@ -1,14 +1,45 @@ validated(); + + $config = config('wxpay'); + $app = Factory::payment($config); + $app['guzzle_handler'] = CoroutineHandler::class; + + // 待支付的,类型一致的,未超时(15min,900sec)的订单 + $orderMain = OrderMain::query() + ->where(['state' => OrderMain::ORDER_STATE_UNPAY, 'type' => $data['type'], 'id' => $data['order_id']]) + ->where('time', '<=', date('Y-m-d H:i:s', (time()-900))) + ->first(); + + if (empty($orderMain)) { + return $this->result(200, ['order_id' => $data['order_id']],'订单不存在或已失效'); + } + + $result = $app->order->unify([ + 'body' => '懒族生活 - 外卖下单', + 'out_trade_no' => $orderMain->global_order_id, + 'total_fee' => bcmul(floatval($orderMain->money), 100), + 'notify_url' => config('site_host') . '/v1/notify/wxmini', + 'trade_type' => 'JSAPI', + 'openid' => $data['openid'], + ]); + + return $this->success($result); } } \ No newline at end of file diff --git a/app/Exception/Handler/ValidationExceptionHandler.php b/app/Exception/Handler/ValidationExceptionHandler.php index cc2384c..cee5579 100644 --- a/app/Exception/Handler/ValidationExceptionHandler.php +++ b/app/Exception/Handler/ValidationExceptionHandler.php @@ -24,7 +24,7 @@ class ValidationExceptionHandler extends ExceptionHandler ]); return $response->withHeader('Content-Type', 'application/json') - ->withStatus($throwable->status) + ->withStatus(200) ->withBody(new SwooleStream($content)); } diff --git a/app/Request/OrderOnlineRequest.php b/app/Request/OrderOnlineRequest.php index dfe0ae6..019cc99 100644 --- a/app/Request/OrderOnlineRequest.php +++ b/app/Request/OrderOnlineRequest.php @@ -4,9 +4,7 @@ declare(strict_types=1); namespace App\Request; -use Hyperf\Validation\Request\FormRequest; - -class OrderOnlineRequest extends FormRequest +class OrderOnlineRequest extends BaseFormRequest { /** * Determine if the user is authorized to make this request. diff --git a/app/Request/WxminiPayRequest.php b/app/Request/WxminiPayRequest.php index 0a7f6dd..2307691 100644 --- a/app/Request/WxminiPayRequest.php +++ b/app/Request/WxminiPayRequest.php @@ -14,45 +14,25 @@ class WxminiPayRequest extends BaseFormRequest public function rules(): array { return [ - 'c_attitude' => 'required|nonempty|integer', - 'c_service' => 'required|nonempty|integer', - 'c_quality' => 'required|nonempty|integer', - 'content' => 'required|nonempty|strlen:15,150', - 'user_id' => 'required|nonempty|integer|exists:ims_cjdc_user,id', - 'service_personnel_id' => 'required|nonempty|integer|exists_enable:lanzu_service_personnel,id,status=1|not_equal:user_id,lanzu_service_personnel,id,user_id', - 'market_id' => 'required|nonempty|integer|exists:ims_cjdc_market,id', + 'order_id' => 'required|nonempty|integer', + 'type' => 'required|nonempty|integer', + 'openid' => 'required|nonempty', ]; } public function messages(): array { return [ - 'user_id.exists' => ':attribute不存在', - 'service_personnel_id.exists' => ':attribute不存在', - 'market_id.exists' => ':attribute不存在', - 'user_id.*' => ':attribute信息不正确', - 'service_personnel_id.exists_enable' => ':attribute不存在或被禁用', - 'service_personnel_id.not_equal' => ':attribute不能是自己', - 'service_personnel_id.*' => ':attribute信息不正确', - 'market_id.*' => ':attribute信息不正确', - 'c_attitude.*' => ':attribute信息不正确', - 'c_service.*' => ':attribute信息不正确', - 'c_quality.*' => ':attribute信息不正确', - 'content.strlen' => ':attribute字数限制在:min~:max字', - 'content.*' => ':attribute信息不正确', + '*.*' => ':attribute 参数异常', ]; } public function attributes(): array { return [ - 'user_id' => '用户', - 'service_personnel_id' => '服务专员', - 'market_id' => '服务专员市场', - 'c_attitude' => '服务态度评分', - 'c_service' => '服务值评分', - 'c_quality' => '服务质量评分', - 'content' => '服务评价内容', + 'order_id' => '订单', + 'type' => '订单类型', + 'openid' => '用户标识', ]; } } \ No newline at end of file diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 374631e..321c1f7 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -72,7 +72,7 @@ class OrderService implements OrderServiceInterface $currentTime = time(); $dataMain['time'] = date('Y-m-d H:i:s', $currentTime); $dataMain['time_add'] = $currentTime; - $dataMain['pay_time'] = date('Y-m-d H:i:s', $currentTime); + $dataMain['pay_time'] = ''; $dataMain['state'] = OrderMain::ORDER_STATE_UNPAY; $dataMain['code'] = $dataMain['global_order_id']; $dataMain['jj_note'] = ''; diff --git a/composer.json b/composer.json index dfc0c2b..0e16cf6 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,8 @@ "alibabacloud/iot": "^1.8", "hyperf/amqp": "^2.0", "hyperf/snowflake": "^2.0", - "ext-bcmath": "*" + "ext-bcmath": "*", + "overtrue/wechat": "~4.0" }, "require-dev": { "swoole/ide-helper": "^4.5", diff --git a/config/config.php b/config/config.php index c5ce284..c67f910 100644 --- a/config/config.php +++ b/config/config.php @@ -28,7 +28,14 @@ return [ LogLevel::WARNING, ], ], - - 'site_host'=>'http://store.api.lanzulive.com/' + 'site_host'=> env('SITE_HOST', ''), + 'wxpay' => [ + 'app_id' => env('APP_ID',''), + 'mch_id' => env('MCH_ID',''), + 'key' => env('APP_SECRET',''), + 'cert_path' => env('CERT_PATH',''), + 'key_path' => env('KEY_PATH',''), + 'notify_url' => env('NOTIFY_URL',''), + ] ]; diff --git a/config/routes.php b/config/routes.php index dfdf5ab..2393433 100644 --- a/config/routes.php +++ b/config/routes.php @@ -42,5 +42,6 @@ Router::addGroup('/v1/',function (){ //小程序支付相关 Router::post('wxmini/pay', 'App\Controller\PaymentController@wxminiPay'); + Router::post('notify/wxmini', 'App\Controller\NotifyController@wxmini'); }); \ No newline at end of file