回筐、账单完成
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Mini;
|
||||
|
||||
use App\Exceptions\RepositoryException;
|
||||
use App\Models\BillModel;
|
||||
use App\Services\BillDetailService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\AnnoRoute\Attribute\GetRoute;
|
||||
use Modules\AnnoRoute\Attribute\PostRoute;
|
||||
use Modules\AnnoRoute\Attribute\RequestAttribute;
|
||||
|
||||
/**
|
||||
* 小程序门店账单(采购单完成后由后台生成,门店端只读)
|
||||
*/
|
||||
#[RequestAttribute('/mini', 'mini', authGuard: 'users')]
|
||||
class BillController extends BaseMiniController
|
||||
{
|
||||
/** 账单列表:当前门店强制过滤,?page=&pageSize= */
|
||||
#[GetRoute('/bill', authorize: true)]
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$user = $this->currentUser($request);
|
||||
$store = $this->ensureStoreBound($user);
|
||||
|
||||
$data = BillModel::query()
|
||||
->where('store_id', $store->id)
|
||||
->with('purchase:id,purchase_no,purchase_date')
|
||||
->orderBy('bill_date', 'desc')
|
||||
->orderBy('id', 'desc')
|
||||
->paginate((int) $request->input('pageSize', 10))
|
||||
->toArray();
|
||||
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/** 账单详情(校验归属:仅能查看本店账单;含合并后的商品明细与关联订单) */
|
||||
#[GetRoute('/bill/{id}', authorize: true, where: ['id' => '[0-9]+'])]
|
||||
public function detail(int $id, Request $request): JsonResponse
|
||||
{
|
||||
$user = $this->currentUser($request);
|
||||
$store = $this->ensureStoreBound($user);
|
||||
|
||||
$bill = BillModel::with('purchase:id,purchase_no,purchase_date')
|
||||
->where('store_id', $store->id)
|
||||
->find($id);
|
||||
if ($bill === null) {
|
||||
throw new RepositoryException('账单不存在');
|
||||
}
|
||||
|
||||
$orders = $bill->orders()
|
||||
->orderBy('id')
|
||||
->get(['id', 'order_no', 'order_date', 'total_quantity', 'total_weight', 'total_amount', 'status'])
|
||||
->toArray();
|
||||
|
||||
return $this->success([
|
||||
'bill' => $bill->toArray(),
|
||||
'items' => app(BillDetailService::class)->mergedItems($bill),
|
||||
'orders' => $orders,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在线支付(预留接口,本次不实现;当前为线下收款,由后台手动登记)
|
||||
*/
|
||||
#[PostRoute('/bill/{id}/pay', authorize: true, where: ['id' => '[0-9]+'])]
|
||||
public function pay(int $id, Request $request): JsonResponse
|
||||
{
|
||||
throw new RepositoryException('在线支付暂未开通,请线下付款后由商家登记收款');
|
||||
}
|
||||
}
|
||||
@@ -108,7 +108,6 @@ class OrderController extends BaseMiniController
|
||||
'order_date' => $now->toDateString(),
|
||||
'total_quantity' => $totalQuantity,
|
||||
'total_weight' => 0,
|
||||
'product_amount' => $totalAmount,
|
||||
'total_amount' => $totalAmount,
|
||||
'status' => StoreOrderModel::STATUS_PENDING,
|
||||
'remark' => $remark,
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Mini;
|
||||
|
||||
use App\Exceptions\RepositoryException;
|
||||
use App\Models\StatementModel;
|
||||
use App\Services\ExportService;
|
||||
use App\Services\StatementGenerateService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\AnnoRoute\Attribute\GetRoute;
|
||||
use Modules\AnnoRoute\Attribute\PostRoute;
|
||||
use Modules\AnnoRoute\Attribute\RequestAttribute;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* 小程序门店对账单(自助生成 / 查看 / 导出)
|
||||
*/
|
||||
#[RequestAttribute('/mini', 'mini', authGuard: 'users')]
|
||||
class StatementController extends BaseMiniController
|
||||
{
|
||||
/** 对账单列表(当前门店) */
|
||||
#[GetRoute('/statement', authorize: true)]
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$user = $this->currentUser($request);
|
||||
$store = $this->ensureStoreBound($user);
|
||||
|
||||
$data = StatementModel::query()
|
||||
->where('store_id', $store->id)
|
||||
->orderBy('id', 'desc')
|
||||
->paginate((int) $request->input('pageSize', 10))
|
||||
->toArray();
|
||||
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/** 生成对账单:快照当前回款周期,settlement_date = period_end + cycle 天 */
|
||||
#[PostRoute('/statement/generate', authorize: true)]
|
||||
public function generate(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'period_start' => 'required|date_format:Y-m-d',
|
||||
'period_end' => 'required|date_format:Y-m-d|after_or_equal:period_start',
|
||||
], [
|
||||
'period_start.required' => '请选择对账周期开始日期',
|
||||
'period_start.date_format' => '开始日期格式为 Y-m-d',
|
||||
'period_end.required' => '请选择对账周期结束日期',
|
||||
'period_end.date_format' => '结束日期格式为 Y-m-d',
|
||||
'period_end.after_or_equal' => '结束日期不能早于开始日期',
|
||||
]);
|
||||
|
||||
$user = $this->currentUser($request);
|
||||
$store = $this->ensureStoreBound($user);
|
||||
|
||||
$statement = app(StatementGenerateService::class)->generate(
|
||||
$store,
|
||||
$data['period_start'],
|
||||
$data['period_end'],
|
||||
);
|
||||
|
||||
return $this->success([
|
||||
'id' => $statement->id,
|
||||
'statement_no' => $statement->statement_no,
|
||||
'total_amount' => $statement->total_amount,
|
||||
'settlement_date' => $statement->settlement_date?->toDateString(),
|
||||
], '对账单已生成');
|
||||
}
|
||||
|
||||
/** 对账单详情(校验归属,含单品对账状态标识) */
|
||||
#[GetRoute('/statement/{id}', authorize: true, where: ['id' => '[0-9]+'])]
|
||||
public function detail(int $id, Request $request): JsonResponse
|
||||
{
|
||||
$user = $this->currentUser($request);
|
||||
$store = $this->ensureStoreBound($user);
|
||||
|
||||
$statement = StatementModel::with('items')
|
||||
->where('store_id', $store->id)
|
||||
->find($id);
|
||||
if ($statement === null) {
|
||||
throw new RepositoryException('对账单不存在');
|
||||
}
|
||||
|
||||
return $this->success($statement->toArray());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user