/
home
/
henzagold
/
server
/
app
/
Http
/
Controllers
/
Adm
/
File Upload :
llllll
Current File: /home/henzagold/server/app/Http/Controllers/Adm/NotifyController.php
<?php namespace App\Http\Controllers\Adm; use App\DB\Te\TableEngine; use App\Http\Controllers\Controller; use App\Models\Customer; use App\Models\CustomerTest; use App\Models\Major\Cash; use App\Models\Notify; use App\Models\Product; use App\Models\User; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; class NotifyController extends Controller { protected function createNotify($person,$data){ if (!is_null($person->token_mobile)){ Notify::store($person->token_mobile,$data['title'],$data['note']); $data['sender_id'] = auth()->id(); $data['read'] = 0; Notify::create($data); $person->increment('notify_count'); } } public function store(Request $request){ $data = $request->all(); switch ($data['type_send']){ case 1: case 2: $customers = Customer::where('type',$data['type_send'])->get(); foreach ($customers as $customer){ $data['customer_id'] = $customer->id; $this->createNotify($customer,$data); } break; case 3: $customer = Customer::findOrFail($data['customer_id']); $data['customer_id'] = $customer->id; $this->createNotify($customer,$data); break; case 4: $customers = Customer::all(); foreach ($customers as $customer){ $data['customer_id'] = $customer->id; $this->createNotify($customer,$data); } break; case 5: $user = User::findOrFail($data['customer_id']); $data['user_id'] = $data['customer_id']; unset($data['customer_id']); $this->createNotify($user,$data); break; case 6: $users = User::all(); foreach ($users as $user){ $data['user_id'] = $user->id; $this->createNotify($user,$data); } break; } return response()->json(true); } public function customer(Request $request){ $records = Customer::query(); TableEngine::create($records, $request->all()) ->initSearch([]) ->select([ '*', ])->export($records); return response()->json($records); } public function index(Request $request) { $records = Notify::where('user_id',auth()->id()); TableEngine::create($records, $request->all()) ->initSearch([]) ->select([ '*', ])->export($records); return response()->json($records); } public function getUnreadNotify() { $count = Notify::where('user_id',auth()->id()) ->where('read',false)->get(); return response()->json($count); } public function show($id){ return response()->json(Notify::findOrFail($id)); } public function read($id){ Notify::find($id)->update(['read'=>1]); return response()->json(true); } }
Copyright ©2k19 -
Hexid
|
Tex7ure