wesley 6 年之前
父節點
當前提交
7f3aac7676

+ 65 - 42
app/Http/Controllers/Admin/Call/RecordsController.php

xqd xqd xqd xqd
@@ -1,13 +1,16 @@
 <?php
 /**
  *  通话纪录
- *  @author  system
- *  @version    1.0
- *  @date 2018-11-27 03:15:47
+ * @author  system
+ * @version    1.0
+ * @date 2018-11-27 03:15:47
  *
  */
+
 namespace App\Http\Controllers\Admin\Call;
+
 use App\Http\Controllers\Admin\Controller;
+use App\Models\CallListModel;
 use Illuminate\Http\Request;
 use App\Repositories\Base\Criteria\OrderBy;
 use App\Repositories\Call\Records\Criteria\MultiWhere;
@@ -17,24 +20,26 @@ class RecordsController extends Controller
 {
     private $repository;
 
-    public function __construct(RecordsRepository $repository) {
-        if(!$this->repository) $this->repository = $repository;
+    public function __construct(RecordsRepository $repository)
+    {
+        if (!$this->repository) $this->repository = $repository;
     }
 
     /**
      * 列表页
      */
-    function index(Request $request) {
+    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('updated_at','DESC'));
+        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('updated_at', 'DESC'));
         }
         $list = $query->paginate(16);
-        return view('admin.call.records.index',compact('list'));
+        return view('admin.call.records.index', compact('list'));
     }
 
 
@@ -43,7 +48,7 @@ class RecordsController extends Controller
      */
     public function create(Request $request)
     {
-        if($request->method() == 'POST') {
+        if ($request->method() == 'POST') {
             return $this->_createSave();
         }
         return view('admin.call.records.edit');
@@ -52,61 +57,79 @@ class RecordsController extends Controller
     /**
      * 保存修改
      */
-    private function _createSave(){
-        $data = (array) request('data');
+    private function _createSave()
+    {
+        $data = (array)request('data');
         $id = $this->repository->create($data);
-        if($id) {
-            $url[] = array('url'=>U( 'Call/Records/index'),'title'=>'返回列表');
-            $url[] = array('url'=>U( 'Call/Records/create'),'title'=>'继续添加');
-            $this->showMessage('添加成功',$url);
-        }else{
-            $url[] = array('url'=>U( 'Call/Records/index'),'title'=>'返回列表');
-            return $this->showWarning('添加失败',$url);
+        if ($id) {
+            $url[] = array('url' => U('Call/Records/index'), 'title' => '返回列表');
+            $url[] = array('url' => U('Call/Records/create'), 'title' => '继续添加');
+            $this->showMessage('添加成功', $url);
+        } else {
+            $url[] = array('url' => U('Call/Records/index'), 'title' => '返回列表');
+            return $this->showWarning('添加失败', $url);
         }
     }
-    
+
     /**
      * 修改
      */
-    public function update(Request $request) {
-        if($request->method() == 'POST') {
+    public function update(Request $request)
+    {
+        if ($request->method() == 'POST') {
             return $this->_updateSave();
         }
         $data = $this->repository->find($request->get('id'));
-        return view('admin.call.records.edit',compact('data'));
+        return view('admin.call.records.edit', compact('data'));
     }
 
     /**
      * 保存修改
      */
-    private function _updateSave() {
-        $data = (array) request('data');
-        $ok = $this->repository->update(request('id'),$data);
-        if($ok) {
-            $url[] = array('url'=>U( 'Call/Records/index'),'title'=>'返回列表');
-            return $this->showMessage('操作成功',urldecode(request('_referer')));
-        }else{
-            $url[] = array('url'=>U( 'Call/Records/index'),'title'=>'返回列表');
-            return $this->showWarning('操作失败',$url);
+    private function _updateSave()
+    {
+        $data = (array)request('data');
+        $ok = $this->repository->update(request('id'), $data);
+        if ($ok) {
+            $url[] = array('url' => U('Call/Records/index'), 'title' => '返回列表');
+            return $this->showMessage('操作成功', urldecode(request('_referer')));
+        } else {
+            $url[] = array('url' => U('Call/Records/index'), 'title' => '返回列表');
+            return $this->showWarning('操作失败', $url);
         }
     }
 
-    public function view(Request $request) {
+    public function view(Request $request)
+    {
         $data = $this->repository->find(request('id'));
-        return view('admin.call.records.view',compact('data'));
+        return view('admin.call.records.view', compact('data'));
     }
 
 
-    
     /**
      * 删除
      */
-    public function destroy(Request $request) {
+    public function destroy(Request $request)
+    {
         $bool = $this->repository->destroy($request->get('id'));
-        if($bool) {
-            return  $this->showMessage('操作成功');
-        }else{
-            return  $this->showWarning("操作失败");
+        if ($bool) {
+            return $this->showMessage('操作成功');
+        } else {
+            return $this->showWarning("操作失败");
+        }
+    }
+
+    public function addCallList(Request $request)
+    {
+        $phones = $request->get('contact_phones');
+        foreach ($phones as $phone) {
+            $hasAdd = CallListModel::where('phone', $phone)->where('sync', 0)->count();
+            if (!$hasAdd) {
+                CallListModel::create(['phone' => $phone, 'sync' => 0]);
+            }
+
+
         }
+        return 200;
     }
 }

+ 1 - 1
database/migrations/2018_11_29_071236_add_term_status_to_call_records.php

xqd
@@ -14,7 +14,7 @@ class AddTermStatusToCallRecords extends Migration
     public function up()
     {
         Schema::table('call_records', function (Blueprint $table) {
-            $table->integer('term_status')->after('cdr_id')->comment('接通状态');
+            $table->string('term_status',11)->after('cdr_id')->nullable()->comment('接通状态');
             $table->integer('intention')->after('term_status')->comment('客户意向');
         });
     }

+ 83 - 14
resources/views/admin/call/records/index.blade.php

xqd xqd xqd xqd
@@ -27,11 +27,16 @@
                                     </div>
                                 </form>
                             </div>
-
+                            @if(role('Call/Records/addCallList'))
+                                <div class="col-sm-8 pull-right">
+                                    <span id="addCallList" class="btn btn-primary pull-right fa fa-phone"
+                                          style="display: none">添加到电话列表</span>
+                                </div>
+                            @endif
                             {{--@if(role('Call/Records/create'))--}}
-                                {{--<div class="col-sm-8 pull-right">--}}
-                                    {{--<a href="{{ U('Call/Records/create')}}" class="btn btn-primary pull-right">添加</a>--}}
-                                {{--</div>--}}
+                            {{--<div class="col-sm-8 pull-right">--}}
+                            {{--<a href="{{ U('Call/Records/create')}}" class="btn btn-primary pull-right">添加</a>--}}
+                            {{--</div>--}}
                             {{--@endif--}}
                         </div>
                     </div>
@@ -39,7 +44,8 @@
                     <table class="table table-striped table-bordered table-hover dataTables-example dataTable">
                         <thead>
                         <tr>
-
+                            <th><label><input type="checkbox" id="checkAll"> 全选</label>
+                            </th>
                             <th class="sorting" data-sort="id"> ID</th>
                             <th class="sorting" data-sort="phone"> 电话号码</th>
                             <th class="sorting" data-sort="start_time"> 拨打时间</th>
@@ -56,29 +62,35 @@
                         @if(isset($list))
                             @foreach($list as $key => $item)
                                 <tr>
-
+                                    <td>
+                                        <label><input class="contacts" name='contact_phone[]' type="checkbox"
+                                                      value="{{ $item->phone }}"></label>
+                                    </td>
                                     <td>{{ $item->id }}</td>
                                     <td>{{ $item->phone }}</td>
                                     <td>{{ $item->start_time }}</td>
                                     <td>{{ $item->end_time }}</td>
-                                    <td>{{ $item->record_path }}</td>
+                                    <td>
+                                        <audio src="http://{{ $item->record_path }}" controls="controls">
+                                        </audio>
+                                    </td>
                                     <td>{{ $item->intention }}</td>
                                     <td>{{ $item->term_status }}</td>
                                     <td>{{ $item->hangup_dispostion }}</td>
                                     <td>{{ $item->ip }}</td>
                                     <td>
                                         {{--@if(role('Call/Records/update'))--}}
-                                            {{--<button class="btn btn-sm btn-success"--}}
-                                                    {{--onclick="window.location.href='{{ U('Call/Records/update',['id'=>$item->id])}}' ">--}}
-                                                {{--修改--}}
-                                            {{--</button>--}}
+                                        {{--<button class="btn btn-sm btn-success"--}}
+                                        {{--onclick="window.location.href='{{ U('Call/Records/update',['id'=>$item->id])}}' ">--}}
+                                        {{--修改--}}
+                                        {{--</button>--}}
 
                                         {{--@endif--}}
 
                                         {{--@if(role('Call/Records/destroy'))--}}
-                                            {{--<a class="btn btn-sm btn-danger"--}}
-                                               {{--href="{{ U('Call/Records/destroy',['id'=>$item->id])}}"--}}
-                                               {{--onclick="return confirm('你确定执行删除操作?');">删除</a>--}}
+                                        {{--<a class="btn btn-sm btn-danger"--}}
+                                        {{--href="{{ U('Call/Records/destroy',['id'=>$item->id])}}"--}}
+                                        {{--onclick="return confirm('你确定执行删除操作?');">删除</a>--}}
                                         {{--@endif--}}
 
                                         @if(role('Call/Records/view'))
@@ -110,4 +122,61 @@
             </div>
         </div>
     </div>
+@endsection
+
+@section('js')
+    <script type="text/javascript">
+        /*电话全选功能*/
+        var items = $('.contacts')
+        $('#checkAll').click(function () {
+            isChecked = $(this).prop('checked')
+            items.prop('checked', isChecked)
+            if (isChecked == true) {
+                $('#addCallList').show()
+            } else {
+                $('#addCallList').hide()
+            }
+        })
+
+        items.click(function () {
+            checkedLength = $('.contacts:checked').length
+            if (checkedLength) {
+                $('#addCallList').show()
+            } else {
+                $('#addCallList').hide()
+            }
+            if (items.length == checkedLength) {
+                $('#addCallList').show()
+            } else {
+                $('#checkAll').prop('checked', false)
+            }
+        })
+
+        /*添加选择的电话到拨打列表*/
+        $('#addCallList').click(function () {
+            contact_phones = []
+            csrf_token = "{{ csrf_token() }}"
+            $('.contacts:checked').each(function () {
+                contact_phones.push($(this).val())
+            })
+            $.ajax({
+                type: 'post',
+                url: '{{ U('Call/Records/addCallList') }}',
+                data: {contact_phones: contact_phones, _token: csrf_token},
+                success: function (data) {
+                    if (data == 200) {
+                        layer.msg('导入成功1', {
+                            time: 2000 //2秒关闭(如果不配置,默认是3秒)
+                        }, function(){
+                            window.location.href = window.location.href
+                        });
+
+                    }
+                }
+
+            })
+
+            console.log(contact_phones)
+        })
+    </script>
 @endsection

+ 10 - 6
resources/views/admin/user/threads/index.blade.php

xqd
@@ -152,12 +152,16 @@
                 contact_ids.push($(this).val())
             })
             $.ajax({
-                type:'post',
-                url:'{{ U('User/Threads/addCallList') }}',
-                data:{contact_ids:contact_ids,_token:csrf_token},
-                success:function (data) {
-                    if(data == 200){
-                        window.location.href =window.location.href
+                type: 'post',
+                url: '{{ U('User/Threads/addCallList') }}',
+                data: {contact_ids: contact_ids, _token: csrf_token},
+                success: function (data) {
+                    if (data == 200) {
+                        layer.msg('导入成功1', {
+                            time: 2000 //2秒关闭(如果不配置,默认是3秒)
+                        }, function () {
+                            window.location.href = window.location.href
+                        });
                     }
                 }