diff --git a/app/Constants/v3/ErrorCode.php b/app/Constants/v3/ErrorCode.php index ceff6d3..7ed6387 100644 --- a/app/Constants/v3/ErrorCode.php +++ b/app/Constants/v3/ErrorCode.php @@ -131,6 +131,13 @@ class ErrorCode extends AbstractConstants * @Message("账号密码错误") */ const STORE_LOGIN_ERROR = 706; + + /** + * 商户异常,当前商户可能不存在或失效了 + * @Message("当前商户异常") + */ + const STORE_NOT_AVAILABLE = 707; + /************************************/ /* 定位相关 751-800 */ /************************************/ diff --git a/app/Controller/v3/WithdrawController.php b/app/Controller/v3/WithdrawController.php new file mode 100644 index 0000000..f185438 --- /dev/null +++ b/app/Controller/v3/WithdrawController.php @@ -0,0 +1,89 @@ +validationFactory->make( + $this->request->all(), + [ + 'user_id' => 'required|nonempty|integer', + 'store_id' => 'required|nonempty|integer', + ], + ['*.*' => ':attribute 参数不正确'] + ); + + if ($validator->fails()) { + throw new ValidationException($validator); + } + + $userId = $this->request->input('user_id', 0); + $storeId = $this->request->input('store_id', 0); + $store = Store::query()->where(['user_id' => $userId, 'id' => $storeId])->first(); + if (empty($store)) { + throw new ErrorCodeException(ErrorCode::STORE_NOT_AVAILABLE); + } + + $data['balance'] = UserBalance::query() + ->where(['source_id' => $store->user_id, 'user_type' => UserType::STORE]) + ->value('balance'); + + $data['award'] = $this->financialService->sumAmount( + $store->user_id, + UserType::STORE, + [FinancialRecord::MONEY_TYPE_STORE_PLAT_NEW_USER, FinancialRecord::MONEY_TYPE_STORE_FIRST_ORDER] + ); + + $data['notice'] = [ + [ + 'title' => '用户须知', + 'content' => '
请仔细填写相关信息,如果由于您填写的信息有误导致资金流失,平台概不负责。
注意:因微信限制当前用户账户余额满1元后才可提现
' + ], + [ + 'title' => '提现须知', + 'content' => '一次提现金额最低为1元
' + .'一次提现金额最高为5000元
' + .'每天可提现10次
' + ], + ]; + + return $this->success($data); + } + + public function applyByStore() + { + $validator = $this->validationFactory->make( + $this->request->all(), + [ + 'user_id' => 'required|nonempty' + ] + ); + } +} \ No newline at end of file diff --git a/app/Service/v3/Implementations/FinancialRecordService.php b/app/Service/v3/Implementations/FinancialRecordService.php index c4a6925..97fc31c 100644 --- a/app/Service/v3/Implementations/FinancialRecordService.php +++ b/app/Service/v3/Implementations/FinancialRecordService.php @@ -312,4 +312,25 @@ class FinancialRecordService implements FinancialRecordServiceInterface { $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); } + + /** + * @inheritDoc + */ + public function sumAmount($user_id, $user_type, $money_type = []) + { + $financialRecord = new FinancialRecord(); + + if ($user_id != FinancialRecord::ACCOUNT_LEDGER) { + $mod = bcmod((string)$user_id, '5', 0); + $financialRecord->suffix($mod); + } + + $sumAmount = $financialRecord->where([ + 'source_id' => $user_id, + 'user_type' => $user_type + ])->whereIn('money_type', $money_type) + ->sum('money'); + + return bcadd($sumAmount, '0', 2); + } } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/FinancialRecordServiceInterface.php b/app/Service/v3/Interfaces/FinancialRecordServiceInterface.php index a5f90cf..6958fb2 100644 --- a/app/Service/v3/Interfaces/FinancialRecordServiceInterface.php +++ b/app/Service/v3/Interfaces/FinancialRecordServiceInterface.php @@ -250,4 +250,17 @@ interface FinancialRecordServiceInterface $comment='' ); + /** + * 统计用户某些金额 + * @param $user_id + * @param $user_type + * @param array $money_type + * @return mixed + */ + public function sumAmount( + $user_id, + $user_type, + $money_type = [] + ); + } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index 79aeeae..94e9764 100644 --- a/config/routes.php +++ b/config/routes.php @@ -137,6 +137,7 @@ Router::addGroup('/v3/', function () { Router::post('orderOnline/complete', 'App\Controller\v3\OrderOnlineController@complete'); Router::post('user/oflOrders', 'App\Controller\v3\OrderListController@offlineForUser'); Router::post('shopCart/delete', 'App\Controller\v3\ShopCartUpdateController@delete'); + Router::post('withdraw/pageByStore', 'App\Controller\v3\WithdrawController@pageByStore'); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class, \App\Middleware\Auth\UserMiddleware::class]]); // 微信支付回调