订单生成提成记录
parent
46a2b2cec0
commit
baeb2a026b
|
|
@ -15,3 +15,4 @@
|
||||||
|
|
||||||
- 自动取消未支付的订单: `php artisan order:close-expired`, 常驻内存执行(死循环)
|
- 自动取消未支付的订单: `php artisan order:close-expired`, 常驻内存执行(死循环)
|
||||||
- 自动完成待收货的订单: `php artisan order:complete`, 常驻内存执行(死循环)
|
- 自动完成待收货的订单: `php artisan order:complete`, 常驻内存执行(死循环)
|
||||||
|
- 生成订单的提成记录: `php artisan order:distribute`
|
||||||
|
|
|
||||||
|
|
@ -145,12 +145,12 @@ class ProductCategoryController extends AdminController
|
||||||
|
|
||||||
public function categories(Request $request)
|
public function categories(Request $request)
|
||||||
{
|
{
|
||||||
$parent_id = (int) $request->input('q');
|
|
||||||
$query = ProductCategoryModel::select('id', 'name as text');
|
$query = ProductCategoryModel::select('id', 'name as text');
|
||||||
if ($parent_id) {
|
if ($request->filled('pid')) {
|
||||||
$query->where('parent_id', $parent_id);
|
$query->where('parent_id', $request->input('pid'));
|
||||||
} else {
|
}
|
||||||
$query->whereNull('parent_id');
|
if ($request->filled('level')) {
|
||||||
|
$query->withDepth()->having('depth', '=', $request->input('level'));
|
||||||
}
|
}
|
||||||
$data = $query->get();
|
$data = $query->get();
|
||||||
return response()->json($data);
|
return response()->json($data);
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ use App\Exceptions\BizException;
|
||||||
use App\Models\ProductBuynote;
|
use App\Models\ProductBuynote;
|
||||||
use App\Models\ProductFeature;
|
use App\Models\ProductFeature;
|
||||||
use App\Models\ProductGroup;
|
use App\Models\ProductGroup;
|
||||||
|
use App\Models\ProductCategory;
|
||||||
use App\Models\ProductSpu as ProductSpuModel;
|
use App\Models\ProductSpu as ProductSpuModel;
|
||||||
use App\Models\ShippingTemplate;
|
use App\Models\ShippingTemplate;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
|
@ -131,7 +132,7 @@ class ProductSpuController extends AdminController
|
||||||
if ($form->isCreating()) {
|
if ($form->isCreating()) {
|
||||||
// $form->select('one_category')->options(admin_route('api.product_categories'))->load('two_category', admin_route('api.product_categories'));
|
// $form->select('one_category')->options(admin_route('api.product_categories'))->load('two_category', admin_route('api.product_categories'));
|
||||||
// $form->select('two_category')->load('category_id', admin_route('api.product_categories'));
|
// $form->select('two_category')->load('category_id', admin_route('api.product_categories'));
|
||||||
$form->select('category_id')->options(admin_route('api.product_categories', ['q'=>2]))->required();
|
$form->select('category_id')->options(admin_route('api.product_categories', ['level' => 2]))->required();
|
||||||
}
|
}
|
||||||
$form->text('name')->required();
|
$form->text('name')->required();
|
||||||
$form->text('subtitle');
|
$form->text('subtitle');
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace App\Admin\Controllers;
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
use App\Admin\Repositories\SalesValueLog;
|
use App\Models\SalesValueLog;
|
||||||
use Dcat\Admin\Form;
|
use Dcat\Admin\Form;
|
||||||
use Dcat\Admin\Grid;
|
use Dcat\Admin\Grid;
|
||||||
use Dcat\Admin\Http\Controllers\AdminController;
|
use Dcat\Admin\Http\Controllers\AdminController;
|
||||||
|
|
@ -17,21 +17,20 @@ class SalesValueLogController extends AdminController
|
||||||
*/
|
*/
|
||||||
protected function grid()
|
protected function grid()
|
||||||
{
|
{
|
||||||
$builder = SalesValueLog::with(['user', 'user.userInfo']);
|
$builder = SalesValueLog::with(['user', 'order']);
|
||||||
return Grid::make($builder, function (Grid $grid) {
|
return Grid::make($builder, function ($grid) {
|
||||||
// $grid->column('id')->sortable();
|
$grid->model()->latest('created_at');
|
||||||
$grid->column('user.phone');
|
$grid->column('user.phone', '用户');
|
||||||
$grid->column('user.userInfo.nickname');
|
$grid->column('order.sn', '订单号');
|
||||||
// $grid->column('order_id');
|
|
||||||
// $grid->column('order_user_id');
|
|
||||||
$grid->column('change_sales_value');
|
$grid->column('change_sales_value');
|
||||||
$grid->column('remarks');
|
$grid->column('remarks');
|
||||||
$grid->column('created_at');
|
$grid->column('created_at');
|
||||||
$grid->column('updated_at')->sortable();
|
|
||||||
|
$grid->disableActions();
|
||||||
|
|
||||||
$grid->filter(function (Grid\Filter $filter) {
|
$grid->filter(function (Grid\Filter $filter) {
|
||||||
$filter->panel(false);
|
$filter->panel(false);
|
||||||
$filter->equal('user.phone')->width(3);
|
$filter->equal('user.phone', '用户')->width(3);
|
||||||
$filter->between('created_at')->dateTime()->width(7);
|
$filter->between('created_at')->dateTime()->width(7);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Admin\Repositories;
|
|
||||||
|
|
||||||
use App\Models\SalesValueLog as Model;
|
|
||||||
use Dcat\Admin\Repositories\EloquentRepository;
|
|
||||||
|
|
||||||
class SalesValueLog extends EloquentRepository
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Model.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $eloquentClass = Model::class;
|
|
||||||
}
|
|
||||||
|
|
@ -150,9 +150,7 @@ Route::group([
|
||||||
|
|
||||||
$router->get('import-job-logs', 'ImportJobLogController@index')->name('import_job_logs.index');
|
$router->get('import-job-logs', 'ImportJobLogController@index')->name('import_job_logs.index');
|
||||||
|
|
||||||
$router->resource('sales-value-logs', 'SalesValueLogController')->only(
|
$router->resource('sales-value-logs', 'SalesValueLogController')->only(['index'])->names('sales_value_logs');
|
||||||
['index']
|
|
||||||
)->names('sales_value_logs');
|
|
||||||
|
|
||||||
//商城端-砍价活动
|
//商城端-砍价活动
|
||||||
$router->resource('bargain-activities', 'BargainActivityController')->names('bargain_activities');
|
$router->resource('bargain-activities', 'BargainActivityController')->names('bargain_activities');
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,14 @@ use App\Models\Order;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class DistributeOrder extends Command
|
class OrderDistribute extends Command
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The name and signature of the console command.
|
* The name and signature of the console command.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'distribute:order {order}';
|
protected $signature = 'order:distribute {order?}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
|
|
@ -41,11 +41,21 @@ class DistributeOrder extends Command
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$service = new \App\Services\DistributeService();
|
$service = new \App\Services\DistributeService();
|
||||||
$order = Order::find($this->argument('order'));
|
|
||||||
try {
|
try {
|
||||||
DB::beginTransaction();
|
DB::beginTransaction();
|
||||||
|
$query = Order::completable();
|
||||||
|
if ($id = $this->argument('order')) {
|
||||||
|
$query->whereIn('id', explode(',', $id));
|
||||||
|
}
|
||||||
|
$orders = $query->get();
|
||||||
|
$this->line('总数: ' . $orders->count());
|
||||||
|
$count = 0;
|
||||||
|
foreach($orders as $order) {
|
||||||
|
$profit = $service->storeByOrder($order);
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
$this->info('符合要求: ' . $count);
|
||||||
DB::commit();
|
DB::commit();
|
||||||
$service->storeByOrder($order);
|
|
||||||
} catch (Throwable $th) {
|
} catch (Throwable $th) {
|
||||||
DB::rollBack();
|
DB::rollBack();
|
||||||
$this->line($th);
|
$this->line($th);
|
||||||
|
|
@ -34,4 +34,9 @@ class SalesValueLog extends Model
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class);
|
return $this->belongsTo(User::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function order()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Order::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,16 +13,15 @@ use App\Exceptions\BizException;
|
||||||
class DistributeService
|
class DistributeService
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* 用户下单后, 更新成长值, 添加返现记录
|
* 根据订单, 更新成长值, 添加返现记录
|
||||||
*
|
*
|
||||||
* @param \App\Models\Order $order
|
* @param \App\Models\Order $order
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return \App\Models\OrderProfit
|
||||||
*/
|
*/
|
||||||
public function storeByOrder(Order $order)
|
public function storeByOrder(Order $order)
|
||||||
{
|
{
|
||||||
// 订单已取消, 换货后生成的新订单
|
if (!$this->canDistribute($order)) {
|
||||||
if ($order->isCancelled() || $order->is_change) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// 订单成长值
|
// 订单成长值
|
||||||
|
|
@ -94,7 +93,37 @@ class DistributeService
|
||||||
$order->update([
|
$order->update([
|
||||||
'profit' => $money_sum
|
'profit' => $money_sum
|
||||||
]);
|
]);
|
||||||
$order->profits()->createMany($profit_list);
|
return $order->profits()->createMany($profit_list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断订单是否可以生成返利
|
||||||
|
*
|
||||||
|
* @param \App\Models\Order $order
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function canDistribute(Order $order)
|
||||||
|
{
|
||||||
|
// 订单已取消, 换货后生成的新订单
|
||||||
|
if ($order->isCancelled() || $order->is_change) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 订单确认收货
|
||||||
|
if (!$order->isCompleted()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 已经生成过返利记录
|
||||||
|
if ($order->profits()->exists()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 订单超过售后期限
|
||||||
|
$value = app_setting('sale_after_expire_days');
|
||||||
|
if ($value && $order->completed_at) {
|
||||||
|
$diff_day = $order->completed_at->diffInDays();
|
||||||
|
return $diff_day > $value;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1146,8 +1146,6 @@ class OrderService
|
||||||
'status' => Order::STATUS_COMPLETED,
|
'status' => Order::STATUS_COMPLETED,
|
||||||
'completed_at' => now(),
|
'completed_at' => now(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
(new DistributeService())->storeByOrder($order);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ return [
|
||||||
| login page.
|
| login page.
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
'name' => '子春生-管理后台',
|
'name' => '积趣-管理后台',
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
@ -22,7 +22,7 @@ return [
|
||||||
| `img` tag, eg '<img src="http://logo-url" alt="Admin logo">'.
|
| `img` tag, eg '<img src="http://logo-url" alt="Admin logo">'.
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
'logo' => '<img src="/images/logo.png" width="35"> 子春生-管理后台',
|
'logo' => '<img src="/images/logo.png" width="35"> 积趣-管理后台',
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class AppSettingSeeder extends Seeder
|
||||||
foreach ([
|
foreach ([
|
||||||
'app'=> [
|
'app'=> [
|
||||||
'value'=> [
|
'value'=> [
|
||||||
'app_name' => '子春生',
|
'app_name' => '积趣',
|
||||||
'ios_link' => '',
|
'ios_link' => '',
|
||||||
'android_link' => '',
|
'android_link' => '',
|
||||||
'merchant_link' => '',
|
'merchant_link' => '',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue