mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-11-30 22:20:45 +00:00
82 lines
2.8 KiB
PHP
82 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Business;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\BusinessOrder;
|
|
use App\Utils\DateTimeUtils;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Resources\BusinessOrderResource;
|
|
|
|
class BusinessOrderController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$businessOrders = BusinessOrder::query()
|
|
->where('shop_id', '<>', 8)
|
|
->with([
|
|
'shop:id,name',
|
|
'items:id,business_order_id,goods_name,goods_number'
|
|
])
|
|
->orderByDesc('confirm_at')
|
|
->filter()
|
|
->paginate($request->get('per_page'));
|
|
|
|
return BusinessOrderResource::collection($businessOrders);
|
|
}
|
|
|
|
public function exportOrderBlank(Request $request)
|
|
{
|
|
$shopId = $request->get('shop_id');
|
|
$startNo = $request->get('start_no');
|
|
$endNo = $request->get('end_no');
|
|
$startTime = BusinessOrder::query()->where('participate_no', $startNo)->value('confirm_at');
|
|
$endTime = BusinessOrder::query()->where('participate_no', $endNo)->value('confirm_at');
|
|
$orders = BusinessOrder::query()
|
|
->with([
|
|
'items:id,business_order_id,external_sku_id,goods_number,goods_name',
|
|
'items.goodsSkuLocation:id,external_sku_id,location'
|
|
])
|
|
->where('shop_id', $shopId)
|
|
->where('confirm_at', '>=', $startTime)
|
|
->where('confirm_at', '<=', $endTime)
|
|
->where('after_sales_status', 0)
|
|
->where('cancel_status', 0)
|
|
->where('is_supplier', 1)
|
|
->orderByDesc('confirm_at')
|
|
->get(['id', 'participate_no']);
|
|
$distribution = [];
|
|
$no = [];
|
|
foreach ($orders as $key => $order) {
|
|
$no[] = $order->participate_no;
|
|
foreach ($order->items as $item) {
|
|
if (isset($distribution[$item['external_sku_id']])) {
|
|
$distribution[$item['external_sku_id']]['p'][] = $key;
|
|
$distribution[$item['external_sku_id']]['num'] += $item['goods_number'];
|
|
} else {
|
|
$distribution[$item['external_sku_id']] = [
|
|
'p' => [$key],
|
|
'local' => 0,
|
|
'num' => $item['goods_number']
|
|
];
|
|
}
|
|
}
|
|
}
|
|
var_dump($distribution, $no);
|
|
}
|
|
|
|
public function groupActivity(Request $request, $shopId)
|
|
{
|
|
$todayTime = Carbon::today()->timestamp;
|
|
$todayTime = DateTimeUtils::getMicroTime($todayTime);
|
|
|
|
return BusinessOrder::query()
|
|
->where('shop_id', $shopId)
|
|
->where('confirm_at', '>=', $todayTime)
|
|
->groupBy('activity_no')
|
|
->pluck('activity_title', 'activity_no')
|
|
->toArray();
|
|
}
|
|
}
|