|
|
@@ -0,0 +1,235 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Http\Controllers\Admin;
|
|
|
+
|
|
|
+use App\Http\Requests\BalanceCreateRequest;
|
|
|
+use App\Http\Requests\BalanceUpdateRequest;
|
|
|
+use App\Models\Balance;
|
|
|
+use Illuminate\Http\Request;
|
|
|
+use App\Http\Controllers\Controller;
|
|
|
+use App\Models\Role;
|
|
|
+
|
|
|
+class BalanceController extends Controller
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * Display a listing of the resource.
|
|
|
+ *
|
|
|
+ * @return \Illuminate\Http\Response
|
|
|
+ */
|
|
|
+ public function party()
|
|
|
+{
|
|
|
+ return view('admin.balance.index');
|
|
|
+}
|
|
|
+
|
|
|
+ public function partyData(Request $request)
|
|
|
+ {
|
|
|
+ $balanceModel = new Balance();
|
|
|
+ $res = $balanceModel
|
|
|
+ ->select(['ag_balance_log.*','ag_app.appname','ag_party.name'])
|
|
|
+ ->leftJoin('ag_app', 'ag_balance_log.app_id', '=', 'ag_app.id')
|
|
|
+ ->leftJoin('ag_party', 'ag_balance_log.party_id', '=', 'ag_party.id')
|
|
|
+ ->orderBy('ag_balance_log.id','asc')
|
|
|
+ ->paginate($request->get('limit', 30))
|
|
|
+ ->toArray();
|
|
|
+ ;
|
|
|
+
|
|
|
+ foreach ($res['data'] as $key=>$val){
|
|
|
+ $res['data'][$key]['typename'] = $val['type'] == 1 ? '充值' : '扣除';
|
|
|
+ }
|
|
|
+ $data = [
|
|
|
+ 'code' => 0,
|
|
|
+ 'msg' => '正在请求中...',
|
|
|
+ 'count' => $res['total'],
|
|
|
+ 'data' => $res['data']
|
|
|
+ ];
|
|
|
+ return response()->json($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function app()
|
|
|
+ {
|
|
|
+ return view('admin.balance.appIndex');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function appData(Request $request)
|
|
|
+ {
|
|
|
+ $balanceModel = new Balance();
|
|
|
+ $res = $balanceModel
|
|
|
+ ->select(['ag_balance_log.*','ag_app.appname','ag_party.name'])
|
|
|
+ ->leftJoin('ag_app', 'ag_balance_log.app_id', '=', 'ag_app.id')
|
|
|
+ ->leftJoin('ag_party', 'ag_balance_log.party_id', '=', 'ag_party.id')
|
|
|
+ ->orderBy('ag_balance_log.id','asc')
|
|
|
+ ->paginate($request->get('limit', 30))
|
|
|
+ ->toArray();
|
|
|
+ ;
|
|
|
+
|
|
|
+ foreach ($res['data'] as $key=>$val){
|
|
|
+ $res['data'][$key]['typename'] = $val['type'] == 2 ? '充值' : '扣除';
|
|
|
+ }
|
|
|
+ $data = [
|
|
|
+ 'code' => 0,
|
|
|
+ 'msg' => '正在请求中...',
|
|
|
+ 'count' => $res['total'],
|
|
|
+ 'data' => $res['data']
|
|
|
+ ];
|
|
|
+ return response()->json($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Show the form for creating a new resource.
|
|
|
+ *
|
|
|
+ * @return \Illuminate\Http\Response
|
|
|
+ */
|
|
|
+ public function create()
|
|
|
+ {
|
|
|
+ return view('admin.party.create')->with(['party'=>array()]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Store a newly created resource in storage.
|
|
|
+ *
|
|
|
+ * @param \Illuminate\Http\Request $request
|
|
|
+ * @return \Illuminate\Http\Response
|
|
|
+ */
|
|
|
+ public function store(BalanceCreateRequest $request)
|
|
|
+ {
|
|
|
+ $data = $request->all();
|
|
|
+ if (Balance::create($data)){
|
|
|
+ return redirect()->to(route('admin.party'))->with(['status'=>'添加成功']);
|
|
|
+ }
|
|
|
+ return redirect()->to(route('admin.party'))->withErrors('系统错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Display the specified resource.
|
|
|
+ *
|
|
|
+ * @param int $id
|
|
|
+ * @return \Illuminate\Http\Response
|
|
|
+ */
|
|
|
+ public function show($id)
|
|
|
+ {
|
|
|
+ //
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Show the form for editing the specified resource.
|
|
|
+ *
|
|
|
+ * @param int $id
|
|
|
+ * @return \Illuminate\Http\Response
|
|
|
+ */
|
|
|
+ public function edit($id)
|
|
|
+ {
|
|
|
+ $party = Balance::where('id', $id)->first();
|
|
|
+ return view('admin.party.edit',compact('party'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Update the specified resource in storage.
|
|
|
+ *
|
|
|
+ * @param \Illuminate\Http\Request $request
|
|
|
+ * @param int $id
|
|
|
+ * @return \Illuminate\Http\Response
|
|
|
+ */
|
|
|
+ public function update(BalanceUpdateRequest $request, $id)
|
|
|
+ {
|
|
|
+ // $party = Balance::findOrFail($id);
|
|
|
+
|
|
|
+ $data = $request->all();
|
|
|
+ if(empty($data['key'])){
|
|
|
+ unset($data['key']);
|
|
|
+ }
|
|
|
+ if(empty($data['secret'])){
|
|
|
+ unset($data['secret']);
|
|
|
+ }
|
|
|
+ $party = Balance::findOrFail($id);
|
|
|
+
|
|
|
+ if ($party->update($data)){
|
|
|
+ return redirect()->to(route('admin.party'))->with(['status'=>'更新成功']);
|
|
|
+ }
|
|
|
+ return redirect()->to(route('admin.party'))->withErrors('系统错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Remove the specified resource from storage.
|
|
|
+ *
|
|
|
+ * @param int $id
|
|
|
+ * @return \Illuminate\Http\Response
|
|
|
+ */
|
|
|
+ public function destroy(Request $request)
|
|
|
+ {
|
|
|
+ $ids = $request->get('ids');
|
|
|
+ if (empty($ids)){
|
|
|
+ return response()->json(['code'=>1,'msg'=>'请选择删除项']);
|
|
|
+ }
|
|
|
+ if (Balance::destroy($ids)){
|
|
|
+ return response()->json(['code'=>0,'msg'=>'删除成功']);
|
|
|
+ }
|
|
|
+ return response()->json(['code'=>1,'msg'=>'删除失败']);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分配角色
|
|
|
+ */
|
|
|
+ public function role(Request $request,$id)
|
|
|
+ {
|
|
|
+ $party = Balance::findOrFail($id);
|
|
|
+ $roles = Role::get();
|
|
|
+ $hasRoles = $party->roles();
|
|
|
+ foreach ($roles as $role){
|
|
|
+ $role->own = $party->hasRole($role) ? true : false;
|
|
|
+ }
|
|
|
+ return view('admin.party.role',compact('roles','party'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新分配角色
|
|
|
+ */
|
|
|
+ public function assignRole(Request $request,$id)
|
|
|
+ {
|
|
|
+ $party = Balance::findOrFail($id);
|
|
|
+ $roles = $request->get('roles',[]);
|
|
|
+ if ($party->syncRoles($roles)){
|
|
|
+ return redirect()->to(route('admin.party'))->with(['status'=>'更新用户角色成功']);
|
|
|
+ }
|
|
|
+ return redirect()->to(route('admin.party'))->withErrors('系统错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分配权限
|
|
|
+ */
|
|
|
+ public function permission(Request $request,$id)
|
|
|
+ {
|
|
|
+ $party = Balance::findOrFail($id);
|
|
|
+ $permissions = $this->tree();
|
|
|
+ foreach ($permissions as $key1 => $item1){
|
|
|
+ $permissions[$key1]['own'] = $party->hasDirectPermission($item1['id']) ? 'checked' : false ;
|
|
|
+ if (isset($item1['_child'])){
|
|
|
+ foreach ($item1['_child'] as $key2 => $item2){
|
|
|
+ $permissions[$key1]['_child'][$key2]['own'] = $party->hasDirectPermission($item2['id']) ? 'checked' : false ;
|
|
|
+ if (isset($item2['_child'])){
|
|
|
+ foreach ($item2['_child'] as $key3 => $item3){
|
|
|
+ $permissions[$key1]['_child'][$key2]['_child'][$key3]['own'] = $party->hasDirectPermission($item3['id']) ? 'checked' : false ;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return view('admin.party.permission',compact('party','permissions'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 存储权限
|
|
|
+ */
|
|
|
+ public function assignPermission(Request $request,$id)
|
|
|
+ {
|
|
|
+ $party = Balance::findOrFail($id);
|
|
|
+ $permissions = $request->get('permissions');
|
|
|
+
|
|
|
+ if (empty($permissions)){
|
|
|
+ $party->permissions()->detach();
|
|
|
+ return redirect()->to(route('admin.party'))->with(['status'=>'已更新用户直接权限']);
|
|
|
+ }
|
|
|
+ $party->syncPermissions($permissions);
|
|
|
+ return redirect()->to(route('admin.party'))->with(['status'=>'已更新用户直接权限']);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|