订单生成提成记录
parent
46a2b2cec0
commit
baeb2a026b
|
|
@ -15,3 +15,4 @@
|
|||
|
||||
- 自动取消未支付的订单: `php artisan order:close-expired`, 常驻内存执行(死循环)
|
||||
- 自动完成待收货的订单: `php artisan order:complete`, 常驻内存执行(死循环)
|
||||
- 生成订单的提成记录: `php artisan order:distribute`
|
||||
|
|
|
|||
|
|
@ -145,12 +145,12 @@ class ProductCategoryController extends AdminController
|
|||
|
||||
public function categories(Request $request)
|
||||
{
|
||||
$parent_id = (int) $request->input('q');
|
||||
$query = ProductCategoryModel::select('id', 'name as text');
|
||||
if ($parent_id) {
|
||||
$query->where('parent_id', $parent_id);
|
||||
} else {
|
||||
$query->whereNull('parent_id');
|
||||
if ($request->filled('pid')) {
|
||||
$query->where('parent_id', $request->input('pid'));
|
||||
}
|
||||
if ($request->filled('level')) {
|
||||
$query->withDepth()->having('depth', '=', $request->input('level'));
|
||||
}
|
||||
$data = $query->get();
|
||||
return response()->json($data);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use App\Exceptions\BizException;
|
|||
use App\Models\ProductBuynote;
|
||||
use App\Models\ProductFeature;
|
||||
use App\Models\ProductGroup;
|
||||
use App\Models\ProductCategory;
|
||||
use App\Models\ProductSpu as ProductSpuModel;
|
||||
use App\Models\ShippingTemplate;
|
||||
use Carbon\Carbon;
|
||||
|
|
@ -131,7 +132,7 @@ class ProductSpuController extends AdminController
|
|||
if ($form->isCreating()) {
|
||||
// $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('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('subtitle');
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Repositories\SalesValueLog;
|
||||
use App\Models\SalesValueLog;
|
||||
use Dcat\Admin\Form;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
|
|
@ -17,21 +17,20 @@ class SalesValueLogController extends AdminController
|
|||
*/
|
||||
protected function grid()
|
||||
{
|
||||
$builder = SalesValueLog::with(['user', 'user.userInfo']);
|
||||
return Grid::make($builder, function (Grid $grid) {
|
||||
// $grid->column('id')->sortable();
|
||||
$grid->column('user.phone');
|
||||
$grid->column('user.userInfo.nickname');
|
||||
// $grid->column('order_id');
|
||||
// $grid->column('order_user_id');
|
||||
$builder = SalesValueLog::with(['user', 'order']);
|
||||
return Grid::make($builder, function ($grid) {
|
||||
$grid->model()->latest('created_at');
|
||||
$grid->column('user.phone', '用户');
|
||||
$grid->column('order.sn', '订单号');
|
||||
$grid->column('change_sales_value');
|
||||
$grid->column('remarks');
|
||||
$grid->column('created_at');
|
||||
$grid->column('updated_at')->sortable();
|
||||
|
||||
$grid->disableActions();
|
||||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->panel(false);
|
||||
$filter->equal('user.phone')->width(3);
|
||||
$filter->equal('user.phone', '用户')->width(3);
|
||||
$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->resource('sales-value-logs', 'SalesValueLogController')->only(
|
||||
['index']
|
||||
)->names('sales_value_logs');
|
||||
$router->resource('sales-value-logs', 'SalesValueLogController')->only(['index'])->names('sales_value_logs');
|
||||
|
||||
//商城端-砍价活动
|
||||
$router->resource('bargain-activities', 'BargainActivityController')->names('bargain_activities');
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ use App\Models\Order;
|
|||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DistributeOrder extends Command
|
||||
class OrderDistribute extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'distribute:order {order}';
|
||||
protected $signature = 'order:distribute {order?}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
|
|
@ -41,11 +41,21 @@ class DistributeOrder extends Command
|
|||
public function handle()
|
||||
{
|
||||
$service = new \App\Services\DistributeService();
|
||||
$order = Order::find($this->argument('order'));
|
||||
try {
|
||||
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();
|
||||
$service->storeByOrder($order);
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
$this->line($th);
|
||||
|
|
@ -34,4 +34,9 @@ class SalesValueLog extends Model
|
|||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(Order::class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,16 +13,15 @@ use App\Exceptions\BizException;
|
|||
class DistributeService
|
||||
{
|
||||
/**
|
||||
* 用户下单后, 更新成长值, 添加返现记录
|
||||
* 根据订单, 更新成长值, 添加返现记录
|
||||
*
|
||||
* @param \App\Models\Order $order
|
||||
*
|
||||
* @return mixed
|
||||
* @return \App\Models\OrderProfit
|
||||
*/
|
||||
public function storeByOrder(Order $order)
|
||||
{
|
||||
// 订单已取消, 换货后生成的新订单
|
||||
if ($order->isCancelled() || $order->is_change) {
|
||||
if (!$this->canDistribute($order)) {
|
||||
return false;
|
||||
}
|
||||
// 订单成长值
|
||||
|
|
@ -94,7 +93,37 @@ class DistributeService
|
|||
$order->update([
|
||||
'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,
|
||||
'completed_at' => now(),
|
||||
]);
|
||||
|
||||
(new DistributeService())->storeByOrder($order);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ return [
|
|||
| login page.
|
||||
|
|
||||
*/
|
||||
'name' => '子春生-管理后台',
|
||||
'name' => '积趣-管理后台',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
@ -22,7 +22,7 @@ return [
|
|||
| `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 ([
|
||||
'app'=> [
|
||||
'value'=> [
|
||||
'app_name' => '子春生',
|
||||
'app_name' => '积趣',
|
||||
'ios_link' => '',
|
||||
'android_link' => '',
|
||||
'merchant_link' => '',
|
||||
|
|
|
|||
Loading…
Reference in New Issue