|
|
@@ -57,31 +57,39 @@ class OrderIssueService
|
|
|
private function getOrderQuery(array $arr, $query)
|
|
|
{
|
|
|
$query->whereHas('order', function ($query) use ($arr) {
|
|
|
- $params = [
|
|
|
- 'consignee_name' => $arr['consignee_name'] ?? '',
|
|
|
- 'consignee_phone' => $arr['consignee_phone'] ?? '',
|
|
|
- 'client_code' => $arr['client_code'] ?? '',
|
|
|
- ];
|
|
|
-
|
|
|
- $columnQueryRules = ['consignee_phone' => ['like' => ''], 'consignee_name' => ['like' => ''],];
|
|
|
- $query = app(QueryService::class)->query($params, $query, $columnQueryRules);
|
|
|
-
|
|
|
+ if ($arr['client_code'] ?? false) {
|
|
|
+ return $this->searchWay($query,$arr['client_code'],'client_code');
|
|
|
+ }
|
|
|
+ if ($arr['consignee_name'] ?? false) {
|
|
|
+ return $this->searchWay($query,$arr['consignee_name'],'consignee_name');
|
|
|
+ }
|
|
|
+ if ($arr['consignee_phone'] ?? false) {
|
|
|
+ return $this->searchWay($query,$arr['consignee_phone'],'consignee_phone');
|
|
|
+ }
|
|
|
if ($arr['logistic_number'] ?? false) {
|
|
|
- $query->whereHas('packages', function ($query) use ($arr) {
|
|
|
- $query->where('logistic_number', $arr['logistic_number']);
|
|
|
+ $logistic_number = $arr['logistic_number'];
|
|
|
+ $query->whereHas('packages', function ($query) use ($logistic_number) {
|
|
|
+ return $this->searchWay($query,$logistic_number,'logistic_number');
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
if (($arr['good_barcode'] ?? false) || ($arr['good_name'] ?? false)) {
|
|
|
- $query->whereHas('packages.commodities.commodity', function ($query) use ($arr) {
|
|
|
- $params = ['sku' => $arr['good_barcode'] ?? '', 'name' => $arr['good_name'] ?? '',];
|
|
|
- $query = app(QueryService::class)->query($params, $query, []);
|
|
|
+ $query->whereHas('packages', function ($query) use ($arr) {
|
|
|
+ $query->whereHas('commodities', function ($query) use ($arr) {
|
|
|
+ $query->whereHas('commodity', function ($query) use ($arr) {
|
|
|
+ if ($arr['good_barcode'] ?? false) {
|
|
|
+ return $this->searchWay($query,$arr['good_barcode'],'sku');
|
|
|
+ }
|
|
|
+ if ($arr['good_name'] ?? false) {
|
|
|
+ $query->where('name', $arr['good_name']);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
if ($arr['send_client_code'] ?? false) {
|
|
|
$query->whereHas('secondOrder', function ($query) use ($arr) {
|
|
|
- $query->where('client_code', $arr['send_client_code']);
|
|
|
+ return $this->searchWay($query,$arr['send_client_code'], 'client_code');
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -90,14 +98,16 @@ class OrderIssueService
|
|
|
|
|
|
public function getRejectedBillQuery(array $arr, $query)
|
|
|
{
|
|
|
- if ($arr['logistic_number_return'] ?? false) {
|
|
|
+ if( ($arr['logistic_number_return'] ?? false) || ($arr['id_quality_label'] ?? false)){
|
|
|
$query->whereHas('rejectedBill', function ($query) use (&$arr) {
|
|
|
- $query->where('logistic_number_return', 'like', $arr['logistic_number_return']);
|
|
|
- });
|
|
|
- }
|
|
|
- if ($arr['id_quality_label'] ?? false) {
|
|
|
- $query->whereHas('rejectedBill.items', function ($query) use (&$arr) {
|
|
|
- $query->where('id_quality_label', $arr['id_quality_label']);
|
|
|
+ if ($arr['logistic_number_return'] ?? false) {
|
|
|
+ return $this->searchWay($query,$arr['logistic_number_return'], 'logistic_number_return');
|
|
|
+ }
|
|
|
+ if ($arr['id_quality_label'] ?? false) {
|
|
|
+ $query->whereHas('items', function ($query) use ($arr) {
|
|
|
+ $query->where('id_quality_label', $arr['id_quality_label']);
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
return $query;
|
|
|
@@ -108,32 +118,55 @@ class OrderIssueService
|
|
|
$query = $this->getQuery($arr, $condition);
|
|
|
$query = $this->getOrderQuery($condition ?? $arr, $query);
|
|
|
$query = $this->getRejectedBillQuery($condition ?? $arr, $query);
|
|
|
+
|
|
|
if (!isset($condition)) {
|
|
|
$condition = $arr;
|
|
|
}
|
|
|
- $params = [
|
|
|
- 'created_at_start' => $condition['created_at_start'] ?? '',
|
|
|
- 'final_status' => $condition['final_status'] ?? '',
|
|
|
- 'order_issue_type_id' => $condition['order_issue_type_id'] ?? '',
|
|
|
- 'logistic_indemnity_money' => $condition['logistic_indemnity_money'] ?? '',
|
|
|
- 'baoshi_indemnity_money' => $condition['baoshi_indemnity_money'] ?? '',
|
|
|
- 'order_issues.id' => $condition['order_issue_ids'] ?? '',
|
|
|
- ];
|
|
|
- $columnQueryRules = [
|
|
|
- 'order_issues.id' => ['alias' => 'order_issues.id', 'multi' => ','],
|
|
|
- 'created_at_start' => ['alias' => 'order_issues.created_at', 'startDate' => ' 00:00:00'],
|
|
|
- ];
|
|
|
- $query = app(QueryService::class)->query($params, $query, $columnQueryRules);
|
|
|
-
|
|
|
+ if (isset($condition['created_at_start'])) {
|
|
|
+ $query->where('order_issues.created_at', '>=', $condition['created_at_start'] . " 00:00:00");
|
|
|
+ }
|
|
|
+ if (isset($condition['created_at_end'])) {
|
|
|
+ $query->where('order_issues.created_at', '<=', $condition['created_at_end'] . " 23:59:59");
|
|
|
+ }
|
|
|
+ if (isset($condition['final_status'])) {
|
|
|
+ $query->where('final_status', $condition['final_status']);
|
|
|
+ }
|
|
|
+ if (isset($condition['order_issue_type_id'])) {
|
|
|
+ $query->where('order_issue_type_id', $condition['order_issue_type_id']);
|
|
|
+ }
|
|
|
if (!($condition['is_handle'] ?? false) && !($condition['final_status'] ?? false)) {
|
|
|
$query->where(function ($query) {
|
|
|
$query->where('final_status', '<>', '已解决')->orWhereNull('final_status');
|
|
|
});
|
|
|
}
|
|
|
- if ($condition['created_at_end'] ?? false) {
|
|
|
- $query->whereHas('logs', function ($query) use ($condition) {
|
|
|
- $query->where('created_at', $condition['created_at_end'])->where('type', '结束');
|
|
|
- });
|
|
|
+ if (isset($condition['logistic_indemnity_money'])) {
|
|
|
+ $query->where('logistic_indemnity_money', $condition['logistic_indemnity_money']);
|
|
|
+ }
|
|
|
+ if (isset($condition['baoshi_indemnity_money'])) {
|
|
|
+ $query->where('baoshi_indemnity_money', $condition['baoshi_indemnity_money']);
|
|
|
+ }
|
|
|
+ if (isset($condition['order_issue_ids'])) {
|
|
|
+ $orderIssuesId = $condition['order_issue_ids'];
|
|
|
+ if (is_string($orderIssuesId)) {
|
|
|
+ $orderIssuesId = explode(',', $orderIssuesId);
|
|
|
+ }
|
|
|
+ $query->whereIn('order_issues.id', $orderIssuesId);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $query;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function isSearchLike($str){
|
|
|
+ if (substr($str,0,1) == "%" || substr($str,strlen($str)-1,1) == "%"){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ private function searchWay($query, $param, $column){
|
|
|
+ if ($this->isSearchLike($param)){
|
|
|
+ $query->where($column,'like', $param);
|
|
|
+ }else{
|
|
|
+ $query->whereIn($column,array_filter(preg_split('/[,, ]+/is', $param)));
|
|
|
}
|
|
|
return $query;
|
|
|
}
|