优化渠道导出
This commit is contained in:
@@ -10,14 +10,21 @@ use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
|
||||
class CouponExport implements FromQuery, WithMapping, WithHeadings
|
||||
{
|
||||
|
||||
use Exportable;
|
||||
|
||||
public $outlet = '';
|
||||
|
||||
public $status = '';
|
||||
|
||||
public $redemptionCode = '';
|
||||
|
||||
public $start = '';
|
||||
|
||||
public $end = '';
|
||||
|
||||
public $user = '';
|
||||
|
||||
public $thirdPartyGoodsId = '';
|
||||
|
||||
public function __construct($serchDatas, $user)
|
||||
@@ -27,9 +34,16 @@ class CouponExport implements FromQuery, WithMapping, WithHeadings
|
||||
|
||||
if (!empty($serchDatas)) {
|
||||
foreach ($serchDatas as $key => $data) {
|
||||
if ($key == 'start') {
|
||||
$data = $data . ' 00:00:01';
|
||||
}
|
||||
if ($key == 'end') {
|
||||
$data = $data . ' 23:59:59';
|
||||
}
|
||||
if ($data) {
|
||||
$this->$key = $data;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,37 +59,37 @@ class CouponExport implements FromQuery, WithMapping, WithHeadings
|
||||
public function query()
|
||||
{
|
||||
return Coupon::where('user_id', $this->user->id)
|
||||
->when($this->outlet, function ($q) {
|
||||
$q->whereHas('outlet', function ($q) {
|
||||
$q->whereHas('info', function ($q) {
|
||||
$q->where('nickname', 'like', "%{$this->outlet}%");
|
||||
});
|
||||
});
|
||||
})
|
||||
->when($this->redemptionCode, function ($q) {
|
||||
$q->where('redemptionCode', $this->redemptionCode);
|
||||
})
|
||||
->when($this->thirdPartyGoodsId, function ($q) {
|
||||
$q->where('thirdPartyGoodsId', $this->thirdPartyGoodsId);
|
||||
})
|
||||
->when(is_numeric($this->status), function ($query) {
|
||||
if ($this->status == 4) {
|
||||
$query->where('is_profit', 1);
|
||||
} else {
|
||||
$query->where('status', $this->status);
|
||||
}
|
||||
})
|
||||
->when($this->start && $this->end, function ($query) {
|
||||
$query->whereBetween('created_at', [$this->start, $this->end]);
|
||||
})
|
||||
->when($this->start, function ($query) {
|
||||
$query->where('created_at', '>', $this->start);
|
||||
})
|
||||
->when($this->end, function ($query) {
|
||||
$query->where('created_at', '<', $this->end);
|
||||
})
|
||||
->whereIn('status', [2, 3])
|
||||
->orderBy('created_at', 'desc');
|
||||
->when($this->outlet, function ($q) {
|
||||
$q->whereHas('outlet', function ($q) {
|
||||
$q->whereHas('info', function ($q) {
|
||||
$q->where('nickname', 'like', "%{$this->outlet}%");
|
||||
});
|
||||
});
|
||||
})
|
||||
->when($this->redemptionCode, function ($q) {
|
||||
$q->where('redemptionCode', $this->redemptionCode);
|
||||
})
|
||||
->when($this->thirdPartyGoodsId, function ($q) {
|
||||
$q->where('thirdPartyGoodsId', $this->thirdPartyGoodsId);
|
||||
})
|
||||
->when(is_numeric($this->status), function ($query) {
|
||||
if ($this->status == 4) {
|
||||
$query->where('is_profit', 1);
|
||||
} else {
|
||||
$query->where('status', $this->status);
|
||||
}
|
||||
})
|
||||
->when($this->start && $this->end, function ($query) {
|
||||
$query->whereBetween('created_at', [$this->start, $this->end]);
|
||||
})
|
||||
->when($this->start, function ($query) {
|
||||
$query->where('created_at', '>', $this->start);
|
||||
})
|
||||
->when($this->end, function ($query) {
|
||||
$query->where('created_at', '<', $this->end);
|
||||
})
|
||||
->whereIn('status', [2, 3])
|
||||
->orderBy('created_at', 'desc');
|
||||
}
|
||||
|
||||
public function map($info): array
|
||||
|
||||
Reference in New Issue
Block a user