From 96a474493c3490ca5ba21d7150d01e7d6f24a97c Mon Sep 17 00:00:00 2001 From: xuanchen <122383162@qq.com> Date: Mon, 31 Aug 2020 09:01:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E8=B0=83=E5=8D=A1=E5=88=B8=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Coupon/IndexController.php | 8 +- .../Controllers/Coupon/IndexController.php | 146 ++++++++++-------- 2 files changed, 83 insertions(+), 71 deletions(-) diff --git a/app/Admin/Controllers/Coupon/IndexController.php b/app/Admin/Controllers/Coupon/IndexController.php index 1222162..215a131 100644 --- a/app/Admin/Controllers/Coupon/IndexController.php +++ b/app/Admin/Controllers/Coupon/IndexController.php @@ -145,12 +145,12 @@ class IndexController extends AdminController $export->column('redemptionCode', function ($value, $original) { 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"; // }); - $export->column('total', function ($value, $original) { - return $value . "\t"; - }); $export->column('资金通道结算', function ($value, $original) { return strip_tags($value); }); diff --git a/app/Merchant/Controllers/Coupon/IndexController.php b/app/Merchant/Controllers/Coupon/IndexController.php index 55180ec..6b496ea 100644 --- a/app/Merchant/Controllers/Coupon/IndexController.php +++ b/app/Merchant/Controllers/Coupon/IndexController.php @@ -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('分润失败');