2025-09-10 13:39:06 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\crm\service;
|
|
|
|
|
|
2025-12-24 14:02:52 +08:00
|
|
|
use app\common\model\Role;
|
2025-12-08 13:19:16 +08:00
|
|
|
use app\common\model\User;
|
2025-12-08 15:01:02 +08:00
|
|
|
use app\common\model\UserGroupMembers;
|
2025-12-24 14:02:52 +08:00
|
|
|
use app\common\model\UserRoles;
|
2025-09-10 13:39:06 +08:00
|
|
|
use support\Request;
|
2025-09-15 15:01:19 +08:00
|
|
|
use support\exception\BusinessException;
|
2025-09-10 13:39:06 +08:00
|
|
|
|
2025-09-22 18:49:18 +08:00
|
|
|
class StockOrdersService extends \app\common\service\StockOrdersService
|
2025-09-10 13:39:06 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
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'];
|
2026-01-20 15:41:24 +08:00
|
|
|
} else {
|
|
|
|
|
$config['where']['salesperson_id'] = $request->user->uid;
|
2025-09-10 13:39:06 +08:00
|
|
|
}
|
|
|
|
|
// 初、终版
|
|
|
|
|
$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';
|
|
|
|
|
|
2025-12-24 14:02:52 +08:00
|
|
|
$user_role_id = UserRoles::where('user_id', $request->user->uid)->pluck('role_id')->toArray();
|
|
|
|
|
//$roles_id = array_intersect([1,6], $request->user->role_ids);
|
2026-01-20 15:30:24 +08:00
|
|
|
$roles_id = array_intersect([1,5,6], $user_role_id);
|
|
|
|
|
if (count($roles_id) != 0){
|
2025-12-24 13:41:14 +08:00
|
|
|
// if(in_array(4, $request->user->role_ids)){ //业务主管
|
|
|
|
|
// $report = User::where('report_to',$request->user->uid)->pluck('id')->toArray();
|
|
|
|
|
// $report = array_merge($report, [$request->user->uid]);
|
|
|
|
|
// $config['where']['salesperson_id'] = ['in',$report];
|
|
|
|
|
// } else
|
2026-01-20 15:30:24 +08:00
|
|
|
|
|
|
|
|
//内勤分组的人可以看到自己分组的备货单
|
|
|
|
|
if (in_array(5,$roles_id)){ //内勤
|
2025-12-08 15:01:02 +08:00
|
|
|
$userGroupMember = UserGroupMembers::where('user_id',$request->user->uid)
|
|
|
|
|
->where('is_leader',1)
|
|
|
|
|
->first();
|
|
|
|
|
if($userGroupMember){
|
2025-12-09 10:54:58 +08:00
|
|
|
$report = UserGroupMembers::where('group_id',$userGroupMember->group_id)
|
|
|
|
|
->pluck('user_id')
|
2025-12-08 15:01:02 +08:00
|
|
|
->toArray();
|
|
|
|
|
$config['where']['salesperson_id'] = ['in',$report];
|
|
|
|
|
}else{ //内勤没有负责的组时
|
|
|
|
|
$config['where']['salesperson_id'] = $request->user->uid;
|
|
|
|
|
}
|
2026-01-20 15:41:24 +08:00
|
|
|
} elseif (in_array(1,$roles_id)) { //超管可以看所有的
|
|
|
|
|
unset($config['where']['salesperson_id']);
|
|
|
|
|
}else{
|
2025-12-08 15:01:02 +08:00
|
|
|
$config['where']['salesperson_id'] = $request->user->uid;
|
|
|
|
|
}
|
2025-12-08 13:42:20 +08:00
|
|
|
}
|
2025-09-10 13:39:06 +08:00
|
|
|
break;
|
|
|
|
|
case 'print':
|
2025-09-10 18:34:20 +08:00
|
|
|
case 'approval':
|
2025-09-10 13:39:06 +08:00
|
|
|
$config['where']['id'] = $p['id'];
|
|
|
|
|
break;
|
2025-09-11 15:31:37 +08:00
|
|
|
case 'detail':
|
2025-09-10 13:39:06 +08:00
|
|
|
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';
|
2025-10-21 19:55:36 +08:00
|
|
|
$config['with'][] = 'files';
|
2025-09-10 13:39:06 +08:00
|
|
|
break;
|
|
|
|
|
case 'store':
|
|
|
|
|
break;
|
|
|
|
|
case 'update':
|
|
|
|
|
$config['where']['id'] = $p['id'];
|
|
|
|
|
break;
|
|
|
|
|
case 'destroy':
|
|
|
|
|
$config['where']['id'] = $p['id'];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $config;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-10 18:34:20 +08:00
|
|
|
|
2025-09-15 15:01:19 +08:00
|
|
|
/**
|
|
|
|
|
* 最终审批
|
|
|
|
|
*/
|
|
|
|
|
public function serviceUltimateApproval(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$config = $this->buildQueryConfig($request, 'detail');
|
|
|
|
|
$item = $this->logicShow($config);
|
2025-10-11 10:03:44 +00:00
|
|
|
|
|
|
|
|
// 检查是否至少有一个车辆填写了vin
|
|
|
|
|
$hasVin = false;
|
2025-09-15 15:01:19 +08:00
|
|
|
foreach ($item->items as $k => $v) {
|
2025-10-11 10:03:44 +00:00
|
|
|
if ($v->vin !== '') {
|
|
|
|
|
$hasVin = true;
|
|
|
|
|
break;
|
2025-09-15 15:01:19 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-10-11 10:03:44 +00:00
|
|
|
|
|
|
|
|
// 如果没有任何车辆填写vin,则抛出异常
|
|
|
|
|
if (!$hasVin) {
|
|
|
|
|
throw new BusinessException('至少需要为一辆车辆填写vin,才能提交审核');
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-15 15:01:19 +08:00
|
|
|
$this->logicUpdateBy($config, [
|
|
|
|
|
'approval_status' => 1
|
|
|
|
|
]);
|
|
|
|
|
$this->startApproval($item);
|
|
|
|
|
return $this->postProcess('UltimateApproval', $item);
|
|
|
|
|
}
|
2025-09-10 13:39:06 +08:00
|
|
|
}
|