|
|
@@ -3,6 +3,7 @@
|
|
|
namespace App;
|
|
|
|
|
|
use App\Traits\ModelTimeFormat;
|
|
|
+use Illuminate\Database\Eloquent\Collection;
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
@@ -20,7 +21,7 @@ class RejectedAnalyzeOwner extends Model
|
|
|
* created_at:创建时间
|
|
|
*
|
|
|
*/
|
|
|
- protected $appends = ['id_owner', 'owner_name', 'bounce_amount', 'check_amount', 'in_storage_count'];
|
|
|
+// protected $appends = ['id_owner', 'owner_name', 'bounce_amount', 'check_amount', 'in_storage_count', 'not_in_storage_count'];
|
|
|
|
|
|
// 按条件查询 zengjun
|
|
|
public static function findBy($array = null)
|
|
|
@@ -36,9 +37,10 @@ class RejectedAnalyzeOwner extends Model
|
|
|
$rao->bounce_amount = $result->bounce_amount;
|
|
|
$rao->check_amount = $result->check_amount;
|
|
|
$rao->in_storage_count = $result->in_storage_count;
|
|
|
+ $rao->not_in_storage_count = $result->not_in_storage_count;
|
|
|
$collection[] = $rao;
|
|
|
}
|
|
|
- return $collection;
|
|
|
+ return (new Collection($collection));
|
|
|
}
|
|
|
|
|
|
// 按条件查询 zengjun
|
|
|
@@ -54,7 +56,7 @@ class RejectedAnalyzeOwner extends Model
|
|
|
'check_amount'=>$result->check_amount,
|
|
|
'uncheck_amount'=>$result->bounce_amount-$result->check_amount,
|
|
|
'in_storage_count'=>$result->in_storage_count,
|
|
|
- 'not_in_storage_count'=>$result->bounce_amount-$result->in_storage_count,
|
|
|
+ 'not_in_storage_count'=>$result->not_in_storage_count,
|
|
|
];
|
|
|
$list[] = $rao;
|
|
|
}
|
|
|
@@ -119,23 +121,27 @@ class RejectedAnalyzeOwner extends Model
|
|
|
// 返回sql zengjun
|
|
|
public static function getQuerySQL($array= null){
|
|
|
$condition = RejectedAnalyzeOwner::getCondition($array);// 条件
|
|
|
- $sql = 'select distinct rao.id_owner,owners.name,sum(bounce_amount) bounce_amount,sum(check_amount) check_amount,sum(in_storage_count) in_storage_count from';
|
|
|
+ $sql = 'select distinct rao.id_owner,owners.name,sum(bounce_amount) bounce_amount,sum(check_amount) check_amount,sum(in_storage_count) in_storage_count,sum(not_in_storage_count) not_in_storage_count from';
|
|
|
$sql .= '(';
|
|
|
// 退件单数
|
|
|
- $sql .= ' select distinct id_owner,count(1) bounce_amount,0 check_amount,0 in_storage_count from rejected_bills where 1=1 ';
|
|
|
+ $sql .= ' select distinct id_owner,count(1) bounce_amount,0 check_amount,0 in_storage_count,0 not_in_storage_count from rejected_bills where deleted_at is null ';
|
|
|
$sql .= $condition;
|
|
|
$sql .= ' UNION ';
|
|
|
// 审核单数
|
|
|
- $sql .= ' select distinct id_owner,0 bounce_amount,count(1) check_amount,0 in_storage_count from rejected_bills where is_checked = 1 ';
|
|
|
+ $sql .= ' select distinct id_owner,0 bounce_amount,count(1) check_amount,0 in_storage_count,0 not_in_storage_count from rejected_bills where is_checked = 1 and deleted_at is null ';
|
|
|
+ $sql .= $condition;
|
|
|
+ $sql .= ' UNION ';
|
|
|
+ // 未入库数
|
|
|
+ $sql .= ' select distinct id_owner,0 bounce_amount,0 check_amount,0 in_storage_count,count(1) not_in_storage_count from rejected_bills where is_loaded <> 1 and is_loaded is not null and deleted_at is null ';
|
|
|
$sql .= $condition;
|
|
|
$sql .= ' UNION ';
|
|
|
// 入库单数
|
|
|
- $sql .= ' select distinct id_owner,0 bounce_amount,0 check_amount,count(1) in_storage_count from rejected_bills where is_loaded = 1 ';
|
|
|
+ $sql .= ' select distinct id_owner,0 bounce_amount,0 check_amount,count(1) in_storage_count,0 not_in_storage_count from rejected_bills where is_loaded = 1 and deleted_at is null ';
|
|
|
$sql .= $condition;
|
|
|
$sql .= ') rao ';
|
|
|
|
|
|
- $sql .= ' left join owners on owners.id = rao.id_owner ';
|
|
|
- $sql .= ' group by rao.id_owner ';
|
|
|
+ $sql .= ' left join owners on owners.id = rao.id_owner and owners.deleted_at is null';
|
|
|
+ $sql .= ' group by rao.id_owner having owners.name is not null order by bounce_amount desc';
|
|
|
return $sql;
|
|
|
}
|
|
|
|