微调卡券列表

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

@@ -145,12 +145,12 @@ class IndexController extends AdminController
$export->column('redemptionCode', function ($value, $original) { $export->column('redemptionCode', function ($value, $original) {
return $value . "\t"; return $value . "\t";
}); });
// $export->column('price', function ($value, $original) { // $export->column('price', function ($value, $original) {
// return $value . "\t";
// });
// $export->column('total', function ($value, $original) {
// return $value . "\t"; // return $value . "\t";
// }); // });
$export->column('total', function ($value, $original) {
return $value . "\t";
});
$export->column('资金通道结算', function ($value, $original) { $export->column('资金通道结算', function ($value, $original) {
return strip_tags($value); return strip_tags($value);
}); });

View File

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