wesley.chen пре 7 година
родитељ
комит
450344785c

+ 13 - 11
app/Http/Controllers/Admin/Paid/SettingController.php

xqd xqd xqd
@@ -22,16 +22,12 @@ class SettingController extends Controller
     }
 
     function index(Request $request) {
-        $search['keyword'] = $request->input('keyword');
-        $query = $this->repository->pushCriteria(new MultiWhere($search));
-
-        if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
-        $query = $query->pushCriteria(new OrderBy($request['sort_field'],$request['sort_field_by']));
-        }else{
-            $query = $query->pushCriteria(new OrderBy('id','DESC'));
+        if($request->method() == 'POST') {
+            return $this->_createSave();
         }
-        $list = $query->paginate(10);
-        return view('admin.paid.setting.index',compact('list'));
+        $data = $this->repository->paginate(1)[0];
+
+        return view('admin.paid.setting.index',compact('data'));
     }
 
 
@@ -64,7 +60,13 @@ class SettingController extends Controller
      */
     private function _createSave(){
         $data = (array) request('data');
-        $id = $this->repository->create($data);
+        $hasSet = $this->repository->paginate(1);
+        if(count($hasSet)){
+            $id = $this->repository->update($hasSet[0]->id,$data);
+        }else{
+            $id = $this->repository->create($data);
+        }
+
         if($id) {
             $url[] = array('url'=>U( 'Paid/Setting/index'),'title'=>'返回列表');
             $url[] = array('url'=>U( 'Paid/Setting/create'),'title'=>'继续添加');
@@ -94,7 +96,7 @@ class SettingController extends Controller
      */
     private function _updateSave() {
         $data = (array) request('data');
-        $ok = $this->repository->update(request('id'),$data);
+        $ok = $this->repository->update(1,$data);
         if($ok) {
             $url[] = array('url'=>U( 'Paid/Setting/index'),'title'=>'返回列表');
             return $this->showMessage('操作成功',urldecode(request('_referer')));

+ 11 - 8
app/Models/PaidSettingModel.php

xqd xqd xqd
@@ -1,13 +1,15 @@
 <?php
+
 namespace App\Models;
+
 use App\Models\BaseModel;
 use Illuminate\Database\Eloquent\SoftDeletes;
 
 /**
- *  @description 付费设置
- *  @author  system;
- *  @version    1.0
- *  @date 2018-06-06 01:47:00
+ * @description 付费设置
+ * @author  system;
+ * @version    1.0
+ * @date 2018-06-06 01:47:00
  *
  */
 class PaidSettingModel extends BaseModel
@@ -21,7 +23,7 @@ class PaidSettingModel extends BaseModel
      */
     protected $table = 'paid_setting';
     /**
-    主键
+     * 主键
      */
     protected $primaryKey = 'id';
 
@@ -34,8 +36,9 @@ class PaidSettingModel extends BaseModel
      * @var string
      */
     protected $fillable = [
-                           'year',
-                           'price'
-                          ];
+        'id',
+        'year',
+        'price'
+    ];
 
 }

+ 32 - 82
resources/views/admin/paid/setting/index.blade.php

xqd xqd
@@ -1,6 +1,16 @@
 @extends('admin.layout')
 
 @section('content')
+
+    <?php
+    if(!isset($data)) $data = array();
+    if(!$data && session("data")){
+        $data = session("data");
+    }
+    if(!$data && session('_old_input')){
+        $data = session("_old_input");
+    }
+    ?>
     <div class="row">
         <div class="col-sm-12">
             <div class="ibox float-e-margins">
@@ -12,98 +22,38 @@
                     </div>
                 </div>
                 <div class="ibox-content">
-                    <div class="row">
-                        <form method="GET" action="" accept-charset="UTF-8">
-
-                            <div class="col-sm-4">
-                                <div class="input-group">
-                                    <input type="text" value="{{Request::get('keyword')}}" placeholder="请输入关键词"
-                                           name="keyword" class="input-sm form-control">
-                                    <span class="input-group-btn">
-									<button type="submit" class="btn btn-sm btn-primary">搜索</button>
-								</span>
-                                </div>
-                            </div>
-                        </form>
-                        @if(role('Paid/Setting/create'))
-                            <div class="col-sm-3 pull-right">
-                                <a href="{{ U('Paid/Setting/create')}}" class="btn btn-sm btn-primary pull-right">添加</a>
-                            </div>
-                        @endif
-                    </div>
-
-                    <table class="table table-striped table-bordered table-hover dataTables-example dataTable">
-                        <thead>
-                        <tr>
-
-                            <th class="sorting" data-sort="id"> ID</th>
-                            <th class="sorting" data-sort="year"> 需要付费的年份</th>
-                            <th class="sorting" data-sort="price"> 付费金额/年</th>
-                            <th class="sorting" data-sort="created_at">创建时间</th>
-                            <th class="sorting" data-sort="updated_at">更新时间</th>
-                            <th width="22%">相关操作</th>
-                        </tr>
-                        </thead>
-                        <tbody>
-                        @if(isset($list))
-                            @foreach($list as $key => $item)
-                                <tr>
 
-                                    <td>{{ $item->id }}</td>
-                                    <td>{{ $item->year }}</td>
-                                    <td>{{ $item->price }}</td>
-                                    <td>{{ $item->created_at }}</td>
-                                    <td>{{ $item->updated_at }}</td>
-                                    <td>
-                                        <div class="btn-group">
-                                            <button data-toggle="dropdown"
-                                                    class="btn btn-warning btn-sm dropdown-toggle"
-                                                    aria-expanded="false">
-                                                操作 <span class="caret"></span>
-                                            </button>
-                                            <ul class="dropdown-menu">
+                    <div class="row">
+                        <div class="col-lg-10">
+                            <form name="form_product" id="form-validation" action="" class="form-horizontal form-validation" accept-charset="UTF-8" method="post">
+                                <div class="form-group">
 
+                                    <label class="control-label col-sm-3">付费金额/年</label>
 
-                                                @if(role('Paid/Setting/update'))
-                                                    <li><a href="{{ U('Paid/Setting/update',['id'=>$item->id])}}"
-                                                           class="font-bold">修改</a></li>
-                                                @endif
+                                    <div class="col-sm-9">
+                                        <input id="data_price" name="data[price]" class="form-control" value="{{ $data['price'] or ''}}" required="" aria-required="true"  placeholder="">
+                                    </div>
 
-                                                @if(role('Paid/Setting/destroy'))
-                                                    <li class="divider"></li>
-                                                    <li><a href="{{ U('Paid/Setting/destroy',['id'=>$item->id])}}"
-                                                           onclick="return confirm('你确定执行删除操作?');">删除</a></li>
-                                                @endif
+                                </div>
 
-                                            </ul>
-                                        </div>
-                                        @if(role('Paid/Setting/view'))
-                                            <button onclick="layer.open({type: 2,area: ['80%', '90%'],content: '{{ U('Paid/Setting/view',['id'=>$item->id])}}'});"
-                                                    class="btn btn-primary ">查看
-                                            </button>
-                                        @endif
-                                    </td>
-                                </tr>
-                            @endforeach
-                        @endif
+                                <div class="form-group">
+                                    <label class="control-label col-sm-3">&nbsp;</label>
+                                    <div class="col-sm-9">
+                                        <input type="hidden" name="_referer" value="<?php echo urlencode(request()->server('HTTP_REFERER'));?>"/>
+                                        <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>"/>
+                                        <input type="submit" class="btn btn-success" style="margin-right:20px;">
+                                        <input type="reset" class="btn btn-default" >
+                                    </div>
+                                </div>
 
-                        </tbody>
-                    </table>
-                    <div class="row">
-                        <div class="col-sm-6">
-                            <div class="dataTables_info" id="DataTables_Table_0_info"
-                                 role="alert" aria-live="polite" aria-relevant="all">每页{{ $list->count() }}
-                                条,共{{ $list->lastPage() }}页,总{{ $list->total() }}条。
-                            </div>
-                        </div>
-                        <div class="col-sm-6">
-                            <div class="dataTables_paginate paging_simple_numbers" id="DataTables_Table_0_paginate">
-                                {!! $list->setPath('')->appends(Request::all())->render() !!}
-                            </div>
+                            </form>
                         </div>
+                        <!-- /.col-lg-10 -->
                     </div>
+                    <!-- /.row -->
                 </div>
             </div>
         </div>
     </div>
+
 @endsection

+ 45 - 45
routes/api.php

xqd
@@ -19,48 +19,48 @@ use Illuminate\Http\Request;
 
 
 
-//
-//$api = app('Dingo\Api\Routing\Router');
-//
-//$api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($api) {
-//    // test
-//    $api->get('test', [
-//        'as' => 'test',
-//        'uses' => 'AuthController@test',
-//    ]);
-//    // Auth
-//    // signin
-//    $api->post('auth/login', [
-//        'as' => 'auth.login',
-//        'uses' => 'AuthController@login',
-//    ]);
-//    $api->post('auth/logout', [
-//        'as' => 'auth.logout',
-//        'uses' => 'AuthController@logout',
-//    ]);
-//    $api->post('auth/code', [
-//        'as' => 'auth.code',
-//        'uses' => 'AuthController@getCode',
-//    ]);
-//    // signup
-//    $api->post('auth/register', [
-//        'as' => 'auth.register',
-//        'uses' => 'AuthController@register',
-//    ]);
-//    $api->post('auth/password', [
-//        'as' => 'auth.reset',
-//        'uses' => 'AuthController@setPassword',
-//    ]);
-//    $api->post('auth/check_password', [
-//        'as' => 'auth.check_password',
-//        'uses' => 'AuthController@check_password',
-//    ]);
-//    $api->post('auth/reset', [
-//        'as' => 'auth.reset',
-//        'uses' => 'AuthController@reset',
-//    ]);
-//    $api->get('auth/is_login', [
-//        'as' => 'auth.is_login',
-//        'uses' => 'AuthController@isLogin',
-//    ]);
-//});
+
+$api = app('Dingo\Api\Routing\Router');
+
+$api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($api) {
+    // test
+    $api->get('test', [
+        'as' => 'test',
+        'uses' => 'AuthController@test',
+    ]);
+    // Auth
+    // signin
+    $api->post('auth/login', [
+        'as' => 'auth.login',
+        'uses' => 'AuthController@login',
+    ]);
+    $api->post('auth/logout', [
+        'as' => 'auth.logout',
+        'uses' => 'AuthController@logout',
+    ]);
+    $api->post('auth/code', [
+        'as' => 'auth.code',
+        'uses' => 'AuthController@getCode',
+    ]);
+    // signup
+    $api->post('auth/register', [
+        'as' => 'auth.register',
+        'uses' => 'AuthController@register',
+    ]);
+    $api->post('auth/password', [
+        'as' => 'auth.reset',
+        'uses' => 'AuthController@setPassword',
+    ]);
+    $api->post('auth/check_password', [
+        'as' => 'auth.check_password',
+        'uses' => 'AuthController@check_password',
+    ]);
+    $api->post('auth/reset', [
+        'as' => 'auth.reset',
+        'uses' => 'AuthController@reset',
+    ]);
+    $api->get('auth/is_login', [
+        'as' => 'auth.is_login',
+        'uses' => 'AuthController@isLogin',
+    ]);
+});