Files
fdesk/app/crm/service/StockOrdersService.php
T
2025-10-21 19:55:36 +08:00

97 lines
3.0 KiB
PHP

<?php
namespace app\crm\service;
use support\Request;
use support\exception\BusinessException;
class StockOrdersService extends \app\common\service\StockOrdersService
{
protected function buildQueryConfig(Request $request, string $scene = 'index'): array
{
$p = $request->all();
$config = [];
$config['model'] = $this->modelClass;
switch ($scene) {
case 'index':
// ====== ====== 筛选 ====== ======
// 业务id
if (isset($p['salesperson_id']) && $p['salesperson_id']) {
$config['where']['salesperson_id'] = $p['salesperson_id'];
}
// 初、终版
$config['where']['is_final'] = $p['is_final'] ?? 0;
// 关键字
if (isset($p['keyword']) && $p['keyword']) {
$k = '%' . $p['keyword'] . '%';
foreach (['pi_no', 'order_no', 'customer_snapshot'] as $col) {
$config['orWhere'][] = [$col, 'like', $k];
}
}
$config['order']['id'] = 'desc';
$config['where']['salesperson_id'] = $request->user->uid;
break;
case 'print':
case 'approval':
$config['where']['id'] = $p['id'];
break;
case 'detail':
case 'show':
$config['where']['id'] = $p['id'];
$config['with'][] = 'items';
$config['with'][] = 'items.options';
$config['with'][] = 'items.moneyValues';
$config['with'][] = 'accounts';
$config['with'][] = 'moneyValues';
$config['with'][] = 'salesperson';
$config['with'][] = 'files';
break;
case 'store':
break;
case 'update':
$config['where']['id'] = $p['id'];
break;
case 'destroy':
$config['where']['id'] = $p['id'];
break;
}
return $config;
}
/**
* 最终审批
*/
public function serviceUltimateApproval(Request $request)
{
$config = $this->buildQueryConfig($request, 'detail');
$item = $this->logicShow($config);
// 检查是否至少有一个车辆填写了vin
$hasVin = false;
foreach ($item->items as $k => $v) {
if ($v->vin !== '') {
$hasVin = true;
break;
}
}
// 如果没有任何车辆填写vin,则抛出异常
if (!$hasVin) {
throw new BusinessException('至少需要为一辆车辆填写vin,才能提交审核');
}
$this->logicUpdateBy($config, [
'approval_status' => 1
]);
$this->startApproval($item);
return $this->postProcess('UltimateApproval', $item);
}
}