admin store order 添加成本价/售价总额
parent
fcebed9a9d
commit
f70e9605b6
|
|
@ -8,6 +8,7 @@ use App\Models\{Order, OrderProduct, OrderPackage};
|
|||
use App\Enums\PayWay;
|
||||
use Dcat\Admin\Layout\Row;
|
||||
use Dcat\Admin\Widgets\{Box, Tab, Card};
|
||||
use App\Constants\OrderStatus;
|
||||
|
||||
class OrderController extends AdminController
|
||||
{
|
||||
|
|
@ -49,6 +50,12 @@ class OrderController extends AdminController
|
|||
$grid->column('total_amount')->display(function ($value) {
|
||||
return bcdiv($value, 100, 2);
|
||||
})->prepend('¥');
|
||||
$grid->column('market_price')->display(function ($value) {
|
||||
return bcdiv($value, 100, 2);
|
||||
})->prepend('¥');
|
||||
$grid->column('cost_price')->display(function ($value) {
|
||||
return bcdiv($value, 100, 2);
|
||||
})->prepend('¥');
|
||||
$grid->column('sales_value');
|
||||
$grid->column('order_status')->using($this->statusMap)->dot($this->statusColor);
|
||||
$grid->column('pay_way')->display(function ($v) {
|
||||
|
|
@ -65,7 +72,40 @@ class OrderController extends AdminController
|
|||
$filter->like('sn')->width(3);
|
||||
$filter->like('user.phone')->width(3);
|
||||
$filter->like('inviter.phone')->width(3);
|
||||
$filter->between('created_at')->dateTime()->width(7);
|
||||
$filter->equal('pay_way')->select([
|
||||
PayWay::WxpayMiniProgram->value => PayWay::WxpayMiniProgram->text(),
|
||||
PayWay::Offline->value => PayWay::Offline->text(),
|
||||
])->width(3);
|
||||
$filter->where('order_status', function ($q) {
|
||||
switch ($this->input) {
|
||||
case OrderStatus::PENDING:
|
||||
$q->where('status', Order::STATUS_PENDING);
|
||||
break;
|
||||
case OrderStatus::WAIT_SHIPPING:
|
||||
$q->where('status', Order::STATUS_PAID)->where('shipping_state', Order::SHIPPING_STATE_PENDING);
|
||||
break;
|
||||
case OrderStatus::SHIPPING:
|
||||
$q->where('status', Order::STATUS_PAID)->where('shipping_state', Order::SHIPPING_STATE_PROCESSING);
|
||||
break;
|
||||
case OrderStatus::SHIPPED:
|
||||
$q->where('status', Order::STATUS_PAID)->where('shipping_state', Order::SHIPPING_STATE_PROCESSED);
|
||||
break;
|
||||
case OrderStatus::COMPLETED:
|
||||
$q->where('status', Order::STATUS_COMPLETED);
|
||||
break;
|
||||
case OrderStatus::CANCELLED:
|
||||
$q->where('status', Order::STATUS_CANCELLED);
|
||||
break;
|
||||
}
|
||||
})->select([
|
||||
OrderStatus::PENDING => '待付款',
|
||||
OrderStatus::WAIT_SHIPPING => '待发货',
|
||||
OrderStatus::SHIPPING => '发货中',
|
||||
OrderStatus::SHIPPED => '已发货',
|
||||
OrderStatus::COMPLETED => '已完成',
|
||||
OrderStatus::CANCELLED => '已取消'
|
||||
])->width(3);
|
||||
$filter->between('created_at')->dateTime()->width(6);
|
||||
});
|
||||
return $grid;
|
||||
}
|
||||
|
|
@ -80,6 +120,12 @@ class OrderController extends AdminController
|
|||
$show->field('total_amount')->as(function ($value) {
|
||||
return bcdiv($value, 100, 2);
|
||||
});
|
||||
$show->field('market_price')->as(function ($value) {
|
||||
return bcdiv($value, 100, 2);
|
||||
});
|
||||
$show->field('cost_price')->as(function ($value) {
|
||||
return bcdiv($value, 100, 2);
|
||||
});
|
||||
$show->field('sales_value');
|
||||
$show->field('order_status')->as(function ($v) {
|
||||
return $this->order_status;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,9 @@ class TotalMoney extends Card
|
|||
$this->title('营业额');
|
||||
$this->subTitle('订单营业额');
|
||||
|
||||
$this->withContent(Order::whereNotNull('store_id')->where('status', Order::STATUS_COMPLETED)->sum('total_amount'));
|
||||
$money = floor(Order::whereNotNull('store_id')->where('status', Order::STATUS_COMPLETED)->sum('total_amount') / 100);
|
||||
|
||||
$this->withContent(number_format($money));
|
||||
}
|
||||
|
||||
public function withContent($content)
|
||||
|
|
|
|||
|
|
@ -94,6 +94,8 @@ class Order extends Model
|
|||
'source_id',
|
||||
'store_id',
|
||||
'inviter_id',
|
||||
'market_price',
|
||||
'cost_price',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ class OrderProduct extends Model
|
|||
'is_gift',
|
||||
'activity_id',
|
||||
'bargain_amount',
|
||||
'market_price',
|
||||
'cost_price',
|
||||
];
|
||||
|
||||
public function packageProducts()
|
||||
|
|
|
|||
|
|
@ -151,6 +151,7 @@ class OrderService
|
|||
$note,
|
||||
$coupon,
|
||||
$bargainOrder,//添加砍价订单逻辑
|
||||
$mapProducts
|
||||
);
|
||||
|
||||
$this->storeOrderProducts($order, $mapProducts);
|
||||
|
|
@ -209,7 +210,9 @@ class OrderService
|
|||
$salesValue,
|
||||
null,
|
||||
$note,
|
||||
$coupon
|
||||
$coupon,
|
||||
null,
|
||||
$mapProducts
|
||||
);
|
||||
$order->update([
|
||||
'store_id' => $order_pre->store_id,
|
||||
|
|
@ -234,15 +237,18 @@ class OrderService
|
|||
/**
|
||||
* 保存订单
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Models\ShippingAddress $shippingAddress
|
||||
* @param int $productsTotalAmount
|
||||
* @param int $couponDiscountAmount
|
||||
* @param int $vipDiscountAmount
|
||||
* @param int $shippingFee
|
||||
* @param float $salesValue
|
||||
* @param string|null $note
|
||||
* @param \App\Models\UserCoupon|null $coupon
|
||||
* @param \App\Models\User $user 下单用户
|
||||
* @param int $productsTotalAmount 商品售价总额
|
||||
* @param int $couponDiscountAmount 优惠券抵扣金额
|
||||
* @param int $vipDiscountAmount 会员抵扣金额
|
||||
* @param int $shippingFee 配送费
|
||||
* @param float $salesValue 成长值
|
||||
* @param \App\Models\ShippingAddress $shippingAddress 配送地址
|
||||
* @param string $note 用户订单备注
|
||||
* @param \App\Models\UserCoupon $coupon 使用的优惠券
|
||||
* @param \App\Models\BargainOrder 砍价订单
|
||||
* @param array 商品列表
|
||||
*
|
||||
* @return \App\Models\Order
|
||||
*/
|
||||
protected function storeOrder(
|
||||
|
|
@ -256,6 +262,7 @@ class OrderService
|
|||
?string $note = null,
|
||||
?UserCoupon $coupon = null,
|
||||
?BargainOrder $bargainOrder = null,
|
||||
?array $mapProducts = null
|
||||
): Order {
|
||||
// 订单支付金额=商品总额-券折扣金额-会员折扣金额+邮费-砍价金额
|
||||
$totalAmount = $productsTotalAmount - $couponDiscountAmount - $vipDiscountAmount;
|
||||
|
|
@ -271,35 +278,42 @@ class OrderService
|
|||
|
||||
$totalAmount += $shippingFee;
|
||||
|
||||
// 生成不重复的订单号
|
||||
do {
|
||||
// 如果订单号重复,则直接重试
|
||||
try {
|
||||
$attrs = [
|
||||
'sn' => serial_number(),
|
||||
'user_coupon_id' => $coupon?->id,
|
||||
'coupon_discount_amount' => $couponDiscountAmount,
|
||||
'vip_discount_amount' => $vipDiscountAmount,
|
||||
'shipping_fee' => $shippingFee,
|
||||
'products_total_amount' => $productsTotalAmount,
|
||||
'total_amount' => $totalAmount, // 商品总额-券折扣金额-会员折扣金额+邮费
|
||||
'sales_value' => $salesValue, // 订单总销售值
|
||||
'note' => $note,
|
||||
// 收货地址
|
||||
'consignee_name' => $shippingAddress->consignee??'',
|
||||
'consignee_telephone' => $shippingAddress->telephone??'',
|
||||
'consignee_zone' => $shippingAddress->zone??'',
|
||||
'consignee_address' => $shippingAddress->address??'',
|
||||
//砍价订单金额
|
||||
'bargain_amount'=>$bargainOrder?->bargain_price ?? 0,
|
||||
];
|
||||
$sn = serial_number();
|
||||
} while(Order::where('sn', $sn)->exists());
|
||||
|
||||
return $user->orders()->create($attrs);
|
||||
} catch (QueryException $e) {
|
||||
if (strpos($e->getMessage(), 'Duplicate entry') === false) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
} while (true);
|
||||
// 计算商品市场价和成本价之和
|
||||
$market_price = 0;
|
||||
$cost_price = 0;
|
||||
foreach($mapProducts as $item) {
|
||||
$sku = $item['sku'];
|
||||
$market_price += $sku->market_price;
|
||||
$cost_price += $sku->cost_price;
|
||||
}
|
||||
|
||||
$attrs = [
|
||||
'sn' => $sn,
|
||||
'user_coupon_id' => $coupon?->id,
|
||||
'coupon_discount_amount' => $couponDiscountAmount,
|
||||
'vip_discount_amount' => $vipDiscountAmount,
|
||||
'shipping_fee' => $shippingFee,
|
||||
'products_total_amount' => $productsTotalAmount,
|
||||
'total_amount' => $totalAmount, // 商品总额-券折扣金额-会员折扣金额+邮费
|
||||
'sales_value' => $salesValue, // 订单总销售值
|
||||
'note' => $note,
|
||||
// 收货地址
|
||||
'consignee_name' => $shippingAddress->consignee??'',
|
||||
'consignee_telephone' => $shippingAddress->telephone??'',
|
||||
'consignee_zone' => $shippingAddress->zone??'',
|
||||
'consignee_address' => $shippingAddress->address??'',
|
||||
//砍价订单金额
|
||||
'bargain_amount'=>$bargainOrder?->bargain_price ?? 0,
|
||||
'market_price' => $market_price,
|
||||
'cost_price' => $cost_price,
|
||||
];
|
||||
|
||||
return $user->orders()->create($attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -336,6 +350,8 @@ class OrderService
|
|||
'sell_price' => $sku->sell_price,
|
||||
'vip_price' => $sku->vip_price,
|
||||
'sales_value' => $sku->sales_value,
|
||||
'market_price' => $sku->cost_price,
|
||||
'cost_price' => $sku->cost_price,
|
||||
'quantity' => $qty,
|
||||
'remain_quantity' => $qty, // 剩余发货数量
|
||||
'coupon_discount_amount' => $product['coupon_discount_amount'],
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCostPriceToOrders extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('orders', function (Blueprint $table) {
|
||||
$table->bigInteger('market_price')->unsigned()->default(0)->comment('市场价格:分');
|
||||
$table->bigInteger('cost_price')->unsigned()->default(0)->comment('成本价格:分');
|
||||
});
|
||||
|
||||
Schema::table('order_products', function (Blueprint $table) {
|
||||
$table->bigInteger('market_price')->unsigned()->default(0)->comment('市场价格:分');
|
||||
$table->bigInteger('cost_price')->unsigned()->default(0)->comment('成本价格:分');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('orders', function (Blueprint $table) {
|
||||
$table->dropColumn(['market_price', 'cost_price']);
|
||||
});
|
||||
Schema::table('order_products', function (Blueprint $table) {
|
||||
$table->dropColumn(['market_price', 'cost_price']);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -57,6 +57,8 @@ return [
|
|||
'tags'=>'标签',
|
||||
'profit' => '累计返利',
|
||||
'sales_value' => '成长值',
|
||||
'market_price' => '市场价',
|
||||
'cost_price' => '成本价',
|
||||
],
|
||||
'options' => [
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in New Issue