order
parent
3ca83d3773
commit
71d287fbf4
|
|
@ -122,7 +122,7 @@ class OrderController extends AdminController
|
||||||
*/
|
*/
|
||||||
protected function grid()
|
protected function grid()
|
||||||
{
|
{
|
||||||
$grid = new Grid(Order::with(['user', 'tags']));
|
$grid = new Grid(Order::with(['user', 'userInfo', 'tags']));
|
||||||
|
|
||||||
$grid->setResource('orders');
|
$grid->setResource('orders');
|
||||||
$grid->model()->orderBy('id', 'desc');
|
$grid->model()->orderBy('id', 'desc');
|
||||||
|
|
@ -138,7 +138,16 @@ class OrderController extends AdminController
|
||||||
$grid->column('tags', '标签')->display(function ($tags) {
|
$grid->column('tags', '标签')->display(function ($tags) {
|
||||||
return $tags->implode('name');
|
return $tags->implode('name');
|
||||||
})->label();
|
})->label();
|
||||||
$grid->column('user.phone')->copyable();
|
$grid->column('user_id')->display(function () {
|
||||||
|
$nickname = $this->userInfo->nickname ?? '---';
|
||||||
|
$avatar = $this->userInfo->avatar ?? 'https://via.placeholder.com/45x45.png';
|
||||||
|
$phone = $this->user->phone;
|
||||||
|
return <<<HTML
|
||||||
|
<img src="{$avatar}" width="45" />
|
||||||
|
<span class="label bg-danger">{$nickname}</span>
|
||||||
|
<span class="label bg-success">{$phone}</span>
|
||||||
|
HTML;
|
||||||
|
});
|
||||||
$grid->column('total_amount')->display(function ($value) {
|
$grid->column('total_amount')->display(function ($value) {
|
||||||
return bcdiv($value, 100, 2);
|
return bcdiv($value, 100, 2);
|
||||||
})->prepend('¥');
|
})->prepend('¥');
|
||||||
|
|
@ -183,7 +192,12 @@ class OrderController extends AdminController
|
||||||
$grid->filter(function (Grid\Filter $filter) {
|
$grid->filter(function (Grid\Filter $filter) {
|
||||||
$filter->panel();
|
$filter->panel();
|
||||||
$filter->like('sn')->width(3);
|
$filter->like('sn')->width(3);
|
||||||
$filter->like('user.phone')->width(3);
|
$filter->where('user_id', function ($q) {
|
||||||
|
$q->where(function ($q) {
|
||||||
|
$q->whereHas('user', fn($q) => $q->where('phone', 'like', '%'.$this->input.'%'))
|
||||||
|
->orWhereHas('userInfo', fn($q) => $q->where('nickname', 'like', '%'.$this->input.'%'));
|
||||||
|
});
|
||||||
|
})->width(3)->placeholder('昵称/手机号');
|
||||||
$filter->where('tags', function ($query) {
|
$filter->where('tags', function ($query) {
|
||||||
$query->whereHas('tags', function ($q) {
|
$query->whereHas('tags', function ($q) {
|
||||||
$q->whereIn('tags.id', $this->input);
|
$q->whereIn('tags.id', $this->input);
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ class OrderController extends AdminController
|
||||||
|
|
||||||
protected function grid()
|
protected function grid()
|
||||||
{
|
{
|
||||||
$grid = new Grid(Order::with(['user', 'inviter', 'store']));
|
$grid = new Grid(Order::with(['user', 'userInfo', 'inviter', 'inviterInfo', 'store']));
|
||||||
|
|
||||||
$user = Admin::user();
|
$user = Admin::user();
|
||||||
$canAdmin = $this->canAdmin();
|
$canAdmin = $this->canAdmin();
|
||||||
|
|
@ -45,8 +45,26 @@ class OrderController extends AdminController
|
||||||
|
|
||||||
$grid->column('store.title', '门店');
|
$grid->column('store.title', '门店');
|
||||||
$grid->column('sn')->copyable();
|
$grid->column('sn')->copyable();
|
||||||
$grid->column('user.phone')->copyable();
|
$grid->column('user_id')->display(function () {
|
||||||
$grid->column('inviter.phone')->copyable();
|
$nickname = $this->userInfo->nickname ?? '---';
|
||||||
|
$avatar = $this->userInfo->avatar ?? 'https://via.placeholder.com/45x45.png';
|
||||||
|
$phone = $this->user->phone;
|
||||||
|
return <<<HTML
|
||||||
|
<img src="{$avatar}" width="45" />
|
||||||
|
<span class="label bg-danger">{$nickname}</span>
|
||||||
|
<span class="label bg-success">{$phone}</span>
|
||||||
|
HTML;
|
||||||
|
});
|
||||||
|
$grid->column('inviter_id')->display(function () {
|
||||||
|
$nickname = $this->inviterInfo->nickname ?? '---';
|
||||||
|
$avatar = $this->inviterInfo->avatar ?? 'https://via.placeholder.com/45x45.png';
|
||||||
|
$phone = $this->inviter->phone;
|
||||||
|
return <<<HTML
|
||||||
|
<img src="{$avatar}" width="45" />
|
||||||
|
<span class="label bg-danger">{$nickname}</span>
|
||||||
|
<span class="label bg-success">{$phone}</span>
|
||||||
|
HTML;
|
||||||
|
});
|
||||||
$grid->column('total_amount')->display(function ($value) {
|
$grid->column('total_amount')->display(function ($value) {
|
||||||
return bcdiv($value, 100, 2);
|
return bcdiv($value, 100, 2);
|
||||||
})->prepend('¥');
|
})->prepend('¥');
|
||||||
|
|
@ -70,8 +88,18 @@ class OrderController extends AdminController
|
||||||
$filter->panel();
|
$filter->panel();
|
||||||
$filter->equal('store_id', '门店')->select('api/store')->width(3);
|
$filter->equal('store_id', '门店')->select('api/store')->width(3);
|
||||||
$filter->like('sn')->width(3);
|
$filter->like('sn')->width(3);
|
||||||
$filter->like('user.phone')->width(3);
|
$filter->where('user_id', function ($q) {
|
||||||
$filter->like('inviter.phone')->width(3);
|
$q->where(function ($q) {
|
||||||
|
$q->whereHas('user', fn($q) => $q->where('phone', 'like', '%'.$this->input.'%'))
|
||||||
|
->orWhereHas('userInfo', fn($q) => $q->where('nickname', 'like', '%'.$this->input.'%'));
|
||||||
|
});
|
||||||
|
})->width(3)->placeholder('昵称/手机号');
|
||||||
|
$filter->where('inviter_id', function ($q) {
|
||||||
|
$q->where(function ($q) {
|
||||||
|
$q->whereHas('inviter', fn($q) => $q->where('phone', 'like', '%'.$this->input.'%'))
|
||||||
|
->orWhereHas('inviterInfo', fn($q) => $q->where('nickname', 'like', '%'.$this->input.'%'));
|
||||||
|
});
|
||||||
|
})->width(3)->placeholder('昵称/手机号');
|
||||||
$filter->equal('pay_way')->select([
|
$filter->equal('pay_way')->select([
|
||||||
PayWay::WxpayMiniProgram->value => PayWay::WxpayMiniProgram->text(),
|
PayWay::WxpayMiniProgram->value => PayWay::WxpayMiniProgram->text(),
|
||||||
PayWay::Offline->value => PayWay::Offline->text(),
|
PayWay::Offline->value => PayWay::Offline->text(),
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ class ProductController extends AdminController
|
||||||
|
|
||||||
protected function grid()
|
protected function grid()
|
||||||
{
|
{
|
||||||
$grid = new Grid(StoreProductSku::with(['store', 'productSku']));
|
$grid = new Grid(StoreProductSku::with(['store', 'productSku.category']));
|
||||||
$user = Admin::user();
|
$user = Admin::user();
|
||||||
$canAdmin = $this->canAdmin();
|
$canAdmin = $this->canAdmin();
|
||||||
if (!$canAdmin) {
|
if (!$canAdmin) {
|
||||||
|
|
@ -46,6 +46,7 @@ class ProductController extends AdminController
|
||||||
|
|
||||||
$grid->column('productSku.id', 'ID');
|
$grid->column('productSku.id', 'ID');
|
||||||
$grid->column('store.title', '店铺');
|
$grid->column('store.title', '店铺');
|
||||||
|
$grid->column('productSku.category.name', '分类');
|
||||||
$grid->column('productSku.name', '名称');
|
$grid->column('productSku.name', '名称');
|
||||||
$grid->column('productSku.specs', '规格')->label();
|
$grid->column('productSku.specs', '规格')->label();
|
||||||
$grid->column('productSku.cost_price', '成本价')->display(function ($value) {
|
$grid->column('productSku.cost_price', '成本价')->display(function ($value) {
|
||||||
|
|
@ -66,8 +67,40 @@ class ProductController extends AdminController
|
||||||
$grid->filter(function (Grid\Filter $filter) {
|
$grid->filter(function (Grid\Filter $filter) {
|
||||||
$filter->panel();
|
$filter->panel();
|
||||||
$filter->equal('store_id')->select('api/store')->width(3);
|
$filter->equal('store_id')->select('api/store')->width(3);
|
||||||
|
$filter->equal('productSku.category_id', '分类')->select(admin_route('api.product_categories', ['level' => 2]))->width(3);
|
||||||
$filter->like('productSku.name', '名称')->width(3);
|
$filter->like('productSku.name', '名称')->width(3);
|
||||||
});
|
});
|
||||||
|
$grid->footer(function ($collection) use ($grid) {
|
||||||
|
$query = StoreProductSku::join('product_skus', 'product_skus.id', '=', 'store_product_skus.product_sku_id');
|
||||||
|
$grid->model()->getQueries()->unique()->each(function ($value) use (&$query) {
|
||||||
|
if (in_array($value['method'], ['paginate', 'get', 'orderBy', 'orderByDesc'], true)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []);
|
||||||
|
});
|
||||||
|
$count = $query->count();
|
||||||
|
$market_price = 0;
|
||||||
|
$cost_price = 0;
|
||||||
|
$market_price = number_format($query->sum('product_skus.market_price') / 100);
|
||||||
|
$cost_price = number_format($query->sum('product_skus.cost_price') / 100);
|
||||||
|
$stock = number_format($query->sum('store_product_skus.amount'));
|
||||||
|
return <<<HTML
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>统计</td>
|
||||||
|
<td>总数: $count</td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
<td>成本价: $cost_price</td>
|
||||||
|
<td>销售价: $market_price</td>
|
||||||
|
<td>库存: $stock</td>
|
||||||
|
<tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
HTML;
|
||||||
|
});
|
||||||
return $grid;
|
return $grid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,21 +7,21 @@ use App\Models\Order;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class OrderDistribute extends Command
|
class OrderGrowthValue extends Command
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The name and signature of the console command.
|
* The name and signature of the console command.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'order:distribute {order?}';
|
protected $signature = 'order:growth-value {order?}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $description = '生成订单提成记录';
|
protected $description = '发放订单成长值';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command instance.
|
* Create a new command instance.
|
||||||
|
|
@ -52,7 +52,7 @@ class OrderDistribute extends Command
|
||||||
$this->line('总数: ' . $orders->count());
|
$this->line('总数: ' . $orders->count());
|
||||||
$count = 0;
|
$count = 0;
|
||||||
foreach($orders as $order) {
|
foreach($orders as $order) {
|
||||||
$profit = $service->storeByOrder($order);
|
$profit = $service->incrementGrowthValue($order);
|
||||||
if ($profit) {
|
if ($profit) {
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use App\Models\Order;
|
||||||
|
use App\Services\DistributeService;
|
||||||
|
use Exception;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class OrderDistribute
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create the event listener.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param object $event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle($event)
|
||||||
|
{
|
||||||
|
$order = Order::find($event->order->id);
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
$service = new DistributeService();
|
||||||
|
$service->storeByOrder($order);
|
||||||
|
DB::commit();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -136,11 +136,6 @@ class Order extends Model
|
||||||
return $this->belongsTo(User::class, 'user_id');
|
return $this->belongsTo(User::class, 'user_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function inviter()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(User::class, 'inviter_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下单人信息
|
* 下单人信息
|
||||||
*/
|
*/
|
||||||
|
|
@ -149,6 +144,17 @@ class Order extends Model
|
||||||
return $this->belongsTo(UserInfo::class, 'user_id', 'user_id');
|
return $this->belongsTo(UserInfo::class, 'user_id', 'user_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function inviter()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class, 'inviter_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function inviterInfo()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(UserInfo::class, 'inviter_id', 'user_id');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 门店
|
* 门店
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ class EventServiceProvider extends ServiceProvider
|
||||||
\App\Listeners\OrderPaidNotify::class,
|
\App\Listeners\OrderPaidNotify::class,
|
||||||
\App\Listeners\SendCoupons::class,
|
\App\Listeners\SendCoupons::class,
|
||||||
\App\Listeners\OrderPackage::class,
|
\App\Listeners\OrderPackage::class,
|
||||||
|
\App\Listeners\OrderDistribute::class
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,13 @@ use App\Exceptions\BizException;
|
||||||
class DistributeService
|
class DistributeService
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* 根据订单, 更新成长值, 添加返现记录
|
* 根据订单, 更新成长值
|
||||||
*
|
*
|
||||||
* @param \App\Models\Order $order
|
* @param \App\Models\Order $order
|
||||||
*
|
*
|
||||||
* @return \App\Models\OrderProfit
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function storeByOrder(Order $order)
|
public function incrementGrowthValue(Order $order)
|
||||||
{
|
{
|
||||||
if (!$this->canDistribute($order)) {
|
if (!$this->canDistribute($order)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -28,7 +28,7 @@ class DistributeService
|
||||||
$sales_value = $order->sales_value;
|
$sales_value = $order->sales_value;
|
||||||
$user = $order->user;
|
$user = $order->user;
|
||||||
$user_agent = $user->agent;
|
$user_agent = $user->agent;
|
||||||
// 已经添加过返现记录
|
// 已经处理过订单成长值
|
||||||
if ($user->salesValueLogs()->where('order_id', $order->id)->exists()) {
|
if ($user->salesValueLogs()->where('order_id', $order->id)->exists()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -60,6 +60,22 @@ class DistributeService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据订单, 添加返现记录
|
||||||
|
*
|
||||||
|
* @param \App\Models\Order $order
|
||||||
|
*
|
||||||
|
* @return \App\Models\OrderProfit
|
||||||
|
*/
|
||||||
|
public function storeByOrder(Order $order)
|
||||||
|
{
|
||||||
|
$sales_value = $order->sales_value;
|
||||||
|
$user = $order->user;
|
||||||
|
$user_agent = $user->agent;
|
||||||
|
|
||||||
// 上级返利
|
// 上级返利
|
||||||
$parent_ids = array_reverse($user->userInfo->parent_ids);
|
$parent_ids = array_reverse($user->userInfo->parent_ids);
|
||||||
$parents = User::with(['userInfo', 'agent'])->whereIn('id', $parent_ids)->get();
|
$parents = User::with(['userInfo', 'agent'])->whereIn('id', $parent_ids)->get();
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ return [
|
||||||
'user'=>[
|
'user'=>[
|
||||||
'phone' => '用户',
|
'phone' => '用户',
|
||||||
],
|
],
|
||||||
|
'inviter_id' => '员工',
|
||||||
'inviter'=>[
|
'inviter'=>[
|
||||||
'phone' => '员工',
|
'phone' => '员工',
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue