diff --git a/app/Admin/Controllers/DistributionPreIncomeController.php b/app/Admin/Controllers/DistributionPreIncomeController.php index 856d772d..39141644 100644 --- a/app/Admin/Controllers/DistributionPreIncomeController.php +++ b/app/Admin/Controllers/DistributionPreIncomeController.php @@ -46,7 +46,7 @@ class DistributionPreIncomeController extends AdminController 1=>'danger', 2=>'success', ]); - $grid->column('remarks'); + // $grid->column('remarks'); $grid->column('completed_at'); $grid->column('created_at')->sortable(); diff --git a/app/Admin/Controllers/OrderController.php b/app/Admin/Controllers/OrderController.php index 6fcd198f..1c3e98b2 100644 --- a/app/Admin/Controllers/OrderController.php +++ b/app/Admin/Controllers/OrderController.php @@ -41,7 +41,14 @@ class OrderController extends AdminController $builder = Order::with(['user', 'tags']); return Grid::make($builder, function (Grid $grid) { - // $grid->column('id')->sortable(); + $grid->column('id')->sortable()->if(function () { + return Admin::user()->can('dcat.admin.orders.show'); + })->then(function (Column $column) { + $column->link(function ($value) { + return admin_route('orders.show', ['order' => $value]); + }); + }); + $grid->tools(function (Grid\Tools $tools) { //设置规格 if (Admin::user()->can('dcat.admin.orders.export_shipping_orders')) { diff --git a/app/Admin/Forms/Settings/Distribution.php b/app/Admin/Forms/Settings/Distribution.php index 6442e88e..a268cb0f 100644 --- a/app/Admin/Forms/Settings/Distribution.php +++ b/app/Admin/Forms/Settings/Distribution.php @@ -39,6 +39,10 @@ class Distribution extends Form // dd($appSettings, app_settings('distribution')); + $this->number('quota_v1_receive', '老配额分红领取时间(小时)') + ->min(0)->value($appSettings['quota_v1_receive'] ?? 0) + ->help('从发放配额分红开始后N小时内可以领取'); + $this->text('settle_days', '订单结算时间(天)') ->value($appSettings['settle_days'] ?? 0) ->rules('required|numeric|min:0') diff --git a/app/Endpoint/Api/Http/Controllers/Auth/LogoutController.php b/app/Endpoint/Api/Http/Controllers/Auth/LogoutController.php index 8971b53c..464970da 100644 --- a/app/Endpoint/Api/Http/Controllers/Auth/LogoutController.php +++ b/app/Endpoint/Api/Http/Controllers/Auth/LogoutController.php @@ -2,6 +2,7 @@ namespace App\Endpoint\Api\Http\Controllers\Auth; +use App\Constants\Device; use App\Endpoint\Api\Http\Controllers\Controller; use Illuminate\Http\Request; @@ -17,6 +18,24 @@ class LogoutController extends Controller { if ($user = $request->user()) { $user->currentAccessToken()->delete(); + + // 获取登录设备 + $device = $request->header('client-app', Device::UNIAPP); + + switch ($device) { + case Device::MERCHANT: + //解绑用户商家端cid + $user->cid->update([ + 'm_cid'=>null, + ]); + break; + default: + //解绑用户商城端cid + $user->cid->update([ + 'u_cid'=>null, + ]); + break; + } } return response()->noContent(); diff --git a/app/Endpoint/Api/Http/Controllers/Merchant/QuotaLogController.php b/app/Endpoint/Api/Http/Controllers/Merchant/QuotaLogController.php index 936c967a..763c8db9 100644 --- a/app/Endpoint/Api/Http/Controllers/Merchant/QuotaLogController.php +++ b/app/Endpoint/Api/Http/Controllers/Merchant/QuotaLogController.php @@ -4,8 +4,15 @@ namespace App\Endpoint\Api\Http\Controllers\Merchant; use App\Endpoint\Api\Http\Controllers\Controller; use App\Endpoint\Api\Http\Resources\QuotaLogResource; +use App\Endpoint\Api\Http\Resources\QuotaV1LogResource; +use App\Exceptions\BizException; use App\Helpers\Paginator as PaginatorHelper; +use App\Models\QuotaV1SendLog; +use App\Models\WalletLog; +use App\Services\WalletService; use Illuminate\Http\Request; +use Illuminate\Support\Facades\DB; +use Throwable; class QuotaLogController extends Controller { @@ -26,4 +33,38 @@ class QuotaLogController extends Controller return QuotaLogResource::collection($quotaLogs); } + + public function quotaV1Logs(Request $request) + { + $perPage = PaginatorHelper::resolvePerPage('per_page', 20, 50); + return QuotaV1LogResource::collection( + QuotaV1SendLog::where('user_id', $request->user()->id) + ->receive()->latest('id') + ->simplePaginate($perPage)); + } + + /** + * 领取老配额分红 + * + * @return void + */ + public function receiveQuotaV1(Request $request, WalletService $walletService) + { + $user = $request->user(); + + try { + DB::beginTransaction(); + foreach (QuotaV1SendLog::where('user_id', $user->id)->waitReceive()->cursor() as $log) { + $log->update(['status'=>1]); + $walletService->changeBalance($user, $log->amount, WalletLog::ACTION_QUOTA_V1, '老配额分红', $log); + } + DB::commit(); + } catch (Throwable $th) { + DB::rollBack(); + report($th); + + throw new BizException('领取失败,稍后再试'); + } + return response()->noContent(); + } } diff --git a/app/Endpoint/Api/Http/Controllers/Merchant/UserController.php b/app/Endpoint/Api/Http/Controllers/Merchant/UserController.php index cf7e87a9..604ac479 100644 --- a/app/Endpoint/Api/Http/Controllers/Merchant/UserController.php +++ b/app/Endpoint/Api/Http/Controllers/Merchant/UserController.php @@ -6,6 +6,7 @@ use App\Endpoint\Api\Http\Controllers\Controller; use App\Endpoint\Api\Http\Resources\Merchant\UserInfoResource; use App\Endpoint\Api\Http\Resources\UserBalanceResource; use App\Endpoint\Api\Http\Resources\UserWalletResource; +use App\Models\QuotaV1SendLog; use Illuminate\Http\Request; class UserController extends Controller @@ -46,6 +47,8 @@ class UserController extends Controller 'sales_value' => $user->userInfo->growth_value, // 总预收益 'total_pre_revenue' => $user->getTotalPreRevenue(), + // 待领取老配额分红 + 'wait_receive_quota_v1_amount' => bcdiv(QuotaV1SendLog::where('user_id', $user->id)->waitReceive()->sum('amount'), 100, 2), ]); } } diff --git a/app/Endpoint/Api/Http/Resources/AfterSaleResource.php b/app/Endpoint/Api/Http/Resources/AfterSaleResource.php index 551df281..7d1e47c8 100644 --- a/app/Endpoint/Api/Http/Resources/AfterSaleResource.php +++ b/app/Endpoint/Api/Http/Resources/AfterSaleResource.php @@ -31,6 +31,7 @@ class AfterSaleResource extends JsonResource 'description' => $this->description, 'remarks' => $this->remarks, 'created_at' => $this->created_at->toDateTimeString(), + 'amount'=> $this->amount_format, // 'logs' => AfterSaleLogResource::make($this->whenLoaded('logs')), ]; } diff --git a/app/Endpoint/Api/Http/Resources/QuotaV1LogResource.php b/app/Endpoint/Api/Http/Resources/QuotaV1LogResource.php new file mode 100644 index 00000000..354bb0c1 --- /dev/null +++ b/app/Endpoint/Api/Http/Resources/QuotaV1LogResource.php @@ -0,0 +1,23 @@ + (string) '老配额分红', + 'amount' => $this->amount_format, + 'created_at' => $this->created_at->toDateTimeString(), + ]; + } +} diff --git a/app/Endpoint/Api/routes.php b/app/Endpoint/Api/routes.php index 40577d74..a828b7a3 100644 --- a/app/Endpoint/Api/routes.php +++ b/app/Endpoint/Api/routes.php @@ -202,5 +202,9 @@ Route::group([ Route::get('agent-statistics', [Merchant\AgentController::class, 'statistics']); // 消息列表 Route::get('messages', [Merchant\MessageController::class, 'index']); + // 领取老配额分红 + Route::post('receive-quota-v1', [Merchant\QuotaLogController::class, 'receiveQuotaV1']); + // 老配额领取记录 + Route::get('quota-v1-logs', [Merchant\QuotaLogController::class, 'quotaV1Logs']); }); }); diff --git a/app/Models/AfterSale.php b/app/Models/AfterSale.php index 0c780875..e3443f14 100644 --- a/app/Models/AfterSale.php +++ b/app/Models/AfterSale.php @@ -77,6 +77,16 @@ class AfterSale extends Model return $afterSaleState; } + /** + * 获取格式化售后金额 + * + * @return void + */ + public function getAmountFormatAttribute() + { + return trim_trailing_zeros(bcdiv($this->attributes['amount'], 100, 2)); + } + /** * 仅查询处理中的售后订单 * diff --git a/app/Models/QuotaV1SendLog.php b/app/Models/QuotaV1SendLog.php index 1e3f5184..3c4f0044 100644 --- a/app/Models/QuotaV1SendLog.php +++ b/app/Models/QuotaV1SendLog.php @@ -31,4 +31,30 @@ class QuotaV1SendLog extends Model { return $this->belongsTo(User::class); } + + public function scopeReceive($query) + { + return $query->where('status', static::STATUS_SUCCESS); + } + + public function scopeWaitReceive($query) + { + $query->where('status', static::STATUS_FAILED); + + if ($hours = app_settings('quota_v1_receive', 0)) { + return $query->where('created_at', '>', now()->subHours($hours)); + } else { + return $query; + } + } + + /** + * 获取格式化售后金额 + * + * @return void + */ + public function getAmountFormatAttribute() + { + return trim_trailing_zeros(bcdiv($this->attributes['amount'], 100, 2)); + } } diff --git a/database/seeders/AppSettingSeeder.php b/database/seeders/AppSettingSeeder.php index 07503b03..d53abca0 100644 --- a/database/seeders/AppSettingSeeder.php +++ b/database/seeders/AppSettingSeeder.php @@ -109,6 +109,8 @@ class AppSettingSeeder extends Seeder 'lvl_same_bonus_fee_rate' => '0', // 级差奖励手续费 'lvl_diff_bonus_fee_rate' => '0.10', + // 老配额分红领取过期时间(小时) + 'quota_v1_receive' => 72, // 代理等级分润规则 'rules' => [