微调卡券列表

This commit is contained in:
2020-08-31 09:01:49 +08:00
parent e59ceefd16
commit 96a474493c
2 changed files with 83 additions and 71 deletions

View File

@@ -4,12 +4,14 @@ namespace App\Merchant\Controllers\Coupon;
use App\Merchant\Controllers\Controller;
use App\Merchant\Exporters\CouponExport;
use App\Models\ActivityRule;
use App\Models\Coupon;
use Auth;
use Illuminate\Http\Request;
class IndexController extends Controller
{
public function index(Request $request)
{
$user = Auth::guard('merchant')->user();
@@ -31,67 +33,66 @@ class IndexController extends Controller
}
$coupons = Coupon::where('user_id', $user->id)
->when($outlet, function ($q) use ($outlet) {
$q->whereHas('outlet', function ($q) use ($outlet) {
$q->whereHas('info', function ($q) use ($outlet) {
$q->where('nickname', 'like', "%{$outlet}%");
});
});
})
->when($redemptionCode, function ($q) use ($redemptionCode) {
$q->where('redemptionCode', $redemptionCode);
})
->when($thirdPartyGoodsId, function ($q) use ($thirdPartyGoodsId) {
$q->where('thirdPartyGoodsId', $thirdPartyGoodsId);
})
->when(is_numeric($status), function ($query) use ($status) {
if ($status == 4) {
$query->where('is_profit', 1);
->when($outlet, function ($q) use ($outlet) {
$q->whereHas('outlet', function ($q) use ($outlet) {
$q->whereHas('info', function ($q) use ($outlet) {
$q->where('nickname', 'like', "%{$outlet}%");
});
});
})
->when($redemptionCode, function ($q) use ($redemptionCode) {
$q->where('redemptionCode', $redemptionCode);
})
->when($thirdPartyGoodsId, function ($q) use ($thirdPartyGoodsId) {
$q->where('thirdPartyGoodsId', $thirdPartyGoodsId);
})
->when(is_numeric($status), function ($query) use ($status) {
if ($status == 4) {
$query->where('is_profit', 1);
} else {
$query->where('status', $status);
}
} else {
$query->where('status', $status);
}
})
->when($start && $end, function ($query) use ($start, $end) {
$query->whereBetween('created_at', [$start, $end]);
})
->when($start && !$end, function ($query) use ($start) {
$query->where('created_at', '>', $start);
})
->when(!$start && $end, function ($query) use ($end) {
$query->where('created_at', '<', $end);
})
->whereIn('status', [2, 3])
->orderBy('created_at', 'desc')->orderBy('id', 'desc')->paginate();
})
->when($start && $end, function ($query) use ($start, $end) {
$query->whereBetween('created_at', [$start, $end]);
})
->when($start && !$end, function ($query) use ($start) {
$query->where('created_at', '>', $start);
})
->when(!$start && $end, function ($query) use ($end) {
$query->where('created_at', '<', $end);
})
->whereIn('status', [2, 3])
->orderBy('created_at', 'desc')->orderBy('id', 'desc')->paginate();
$all = Coupon::query()
->where('user_id', $user->id)
->when($outlet, function ($q) use ($outlet) {
$q->whereHas('outlet', function ($q) use ($outlet) {
$q->whereHas('info', function ($q) use ($outlet) {
$q->where('nickname', 'like', "%{$outlet}%");
});
});
})
->when($redemptionCode, function ($q) use ($redemptionCode) {
$q->where('redemptionCode', $redemptionCode);
})
->when(is_numeric($status), function ($query) use ($status) {
$query->where('status', $status);
}, function ($query) {
$query->whereIn('status', [2, 3]);
})
->when($start && $end, function ($query) use ($start, $end) {
$query->whereBetween('created_at', [$start, $end]);
})
->when($start, function ($query) use ($start) {
$query->where('created_at', '>', $start);
})
->when($end, function ($query) use ($end) {
$query->where('created_at', '<', $end);
})
->orderBy('created_at', 'desc')->orderBy('id', 'desc')->get();
$all = Coupon::where('user_id', $user->id)
->when($outlet, function ($q) use ($outlet) {
$q->whereHas('outlet', function ($q) use ($outlet) {
$q->whereHas('info', function ($q) use ($outlet) {
$q->where('nickname', 'like', "%{$outlet}%");
});
});
})
->when($redemptionCode, function ($q) use ($redemptionCode) {
$q->where('redemptionCode', $redemptionCode);
})
->when(is_numeric($status), function ($query) use ($status) {
$query->where('status', $status);
}, function ($query) {
$query->whereIn('status', [2, 3]);
})
->when($start && $end, function ($query) use ($start, $end) {
$query->whereBetween('created_at', [$start, $end]);
})
->when($start, function ($query) use ($start) {
$query->where('created_at', '>', $start);
})
->when($end, function ($query) use ($end) {
$query->where('created_at', '<', $end);
})
->orderBy('created_at', 'desc')->orderBy('id', 'desc')->get();
$pass = $all->whereIn('status', [2, 4])->all();
$reject = $all->where('status', 3)->all();
@@ -99,14 +100,16 @@ class IndexController extends Controller
$reject = collect($reject);
$data = [
'all' => $all->count(),
'pass' => $pass->count(),
'reject' => $reject->count(),
'price' => $pass->sum('price'),
'profit' => $pass->sum('profit'),
'hasPrice' => $pass->where('is_profit', 1)->sum('profit'),
'all' => $all->count(),
'pass' => $pass->count(),
'reject' => $reject->count(),
// 'price' => $pass->sum('price'),
// 'profit' => $pass->sum('profit'),
// 'hasPrice' => $pass->where('is_profit', 1)->sum('profit'),
];
$rules = ActivityRule::get();
info(json_encode($rules));
if ($action == 'search') {
return view('Merchant::coupon.index', compact('coupons', 'data'));
@@ -115,11 +118,16 @@ class IndexController extends Controller
}
}
public function getData($request, $type)
{
}
/**
* 按照日期分润
* @author 玄尘 2020-03-11
* @param Request $request [description]
* @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @author 玄尘 2020-03-11
*/
public function profits(Request $request)
{
@@ -132,7 +140,10 @@ class IndexController extends Controller
if ($list->isEmpty()) {
return $this->error('分润失败!没有可处理的数据');
}
if (Coupon::where('user_id', $user->id)->whereDate('created_at', $date)->where('status', 2)->update(['status' => 4])) {
if (Coupon::where('user_id', $user->id)
->whereDate('created_at', $date)
->where('status', 2)
->update(['status' => 4])) {
return $this->success('分润成功!');
} else {
return $this->error('分润失败!');
@@ -146,7 +157,7 @@ class IndexController extends Controller
/**
* 分润
* @author 玄尘 2020-03-11
* @param Coupon $coupon [description]
* @param Coupon $coupon [description]
* @return [type] [description]
*/
public function profit(Coupon $coupon)
@@ -154,6 +165,7 @@ class IndexController extends Controller
if ($coupon->status == 2) {
$coupon->status = 4;
$coupon->save();
return $this->success('分润成功');
} else {
return $this->error('分润失败');