sunhao 5 years ago
parent
commit
7450fd84cd

+ 52 - 15
app/Http/Controllers/Admin/CustReportController.php

@@ -73,11 +73,12 @@ class custReportController extends Controller
73 73
         $this->validate($request, [
74 74
             'total_cost'           => 'required', 
75 75
             'total_fan_add'           => 'required',   
76
-            'dtime'           => 'required',   
76
+            'dtime'           => 'required|unique:cust_day_total,dtime,1,is_del',   
77 77
         ], [                  
78 78
             'total_cost.required'           => '总成本不能为空',                   
79 79
             'total_fan_add.required'           => '总加粉数不能为空',                                    
80
-            'dtime.required'           => '日期不能为空',                                    
80
+            'dtime.required'           => '日期不能为空',
81
+            'dtime.unique'           => '指定日期已经添加过',                                    
81 82
         ]);
82 83
         //数据库-新增数据
83 84
         $custreport = array();
@@ -112,17 +113,19 @@ class custReportController extends Controller
112 113
      * @return \Illuminate\Http\RedirectResponse
113 114
      */
114 115
     public function totalupdate(Request $request)
115
-    {            
116
+    {    
117
+        $id = (int)$request->input('id');        
116 118
         $this->validate($request, [
117 119
             'id'                  => 'required',
118 120
             'total_cost'          => 'required', 
119 121
             'total_fan_add'       => 'required',   
120
-            'dtime'               => 'required',   
122
+            'dtime'               => 'required|unique:cust_day_total,dtime,'.$id.',id,is_del,0',   
121 123
         ], [                  
122 124
             'id.required'              => 'id不能为空',                   
123 125
             'total_cost.required'      => '总成本不能为空',                   
124 126
             'total_fan_add.required'   => '总加粉数不能为空',                                    
125
-            'dtime.required'           => '日期不能为空',                                    
127
+            'dtime.required'           => '日期不能为空',
128
+            'dtime.unique'           => '指定日期已存在',                                    
126 129
         ]);
127 130
        
128 131
         $custreport = array();
@@ -130,7 +133,6 @@ class custReportController extends Controller
130 133
         $custreport['total_fan_add'] = $request->input('total_fan_add'); 
131 134
         $custreport['dtime'] = $request->input('dtime'); 
132 135
 
133
-        $id = (int)$request->input('id');
134 136
         $res = DB::table('cust_day_total')->where('id', $id)->update($custreport);        
135 137
         return redirect('/admin/custreport/totalindex')->with('info', '更新成功');         
136 138
     }
@@ -316,7 +318,11 @@ class custReportController extends Controller
316 318
      */
317 319
     public function detailcreate(Request $request)
318 320
     {
319
-        return view('custreport/detailcreate');
321
+        $adminList = DB::table('admin')->select('id', 'realname', 'username')->where('id','>', 1)->get();
322
+        $adminList = json_decode(json_encode($adminList), true);
323
+        $teamList = DB::table('teams')->select('id', 'name')->get();
324
+        $teamList = json_decode(json_encode($teamList), true);
325
+        return view('custreport/detailcreate',['adminlist'=>$adminList, 'teamlist'=>$teamList]);
320 326
     }
321 327
     /**
322 328
      * 分组管理-进行添加操作
@@ -325,16 +331,21 @@ class custReportController extends Controller
325 331
      */
326 332
     public function detailstore(Request $request)
327 333
     {       
334
+        $admin_id = (int)$request->input('admin_id');
335
+        if(!$admin_id){
336
+            $admin_id = session('admin_id');
337
+        }
328 338
         $this->validate($request, [
329 339
             'old_consult'           => 'required', 
330 340
             'new_consult'           => 'required', 
331 341
             'fan_add'           => 'required',   
332
-            'dtime'           => 'required',   
342
+            'dtime'           => 'required|unique:cust_day_detail,dtime,1,is_del,admin_id,'.$admin_id,   
333 343
         ], [                  
334 344
             'old_consult.required'           => '老粉咨询不能为空',                   
335 345
             'new_consult.required'           => '新粉咨询数不能为空',                                    
336 346
             'fan_add.required'           => '加粉数不能为空',                                    
337 347
             'dtime.required'           => '日期不能为空',                                    
348
+            'dtime.unique'           => '指定日期已经添加过',                                    
338 349
         ]);
339 350
         //数据库-新增数据
340 351
         $custreport = array();
@@ -342,10 +353,17 @@ class custReportController extends Controller
342 353
         $custreport['old_consult'] = $request->input('old_consult'); 
343 354
         $custreport['new_consult'] = $request->input('new_consult'); 
344 355
         $custreport['fan_add'] = $request->input('fan_add'); 
356
+        $custreport['new_reply'] = $request->input('new_reply'); 
345 357
         $custreport['dtime'] = $request->input('dtime'); 
346
-        $custreport['admin_id'] = session('admin_id'); 
347
-        $custreport['admin_name'] = session('real_name'); 
348
-                
358
+   
359
+        if($admin_id>0){
360
+            $admin_info = DB::table('admin')->select('realname', 'team_id')->where('id', $admin_id)->first();
361
+            $custreport['admin_id'] = $admin_id;
362
+            $custreport['admin_name'] = $admin_info->realname;
363
+        }else{
364
+            $custreport['admin_id'] = session('admin_id'); 
365
+            $custreport['admin_name'] = session('real_name'); 
366
+        }    
349 367
         $res = DB::table('cust_day_detail')->insert($custreport);            
350 368
         return redirect('/admin/custreport/detailindex')->with('info', '添加成功'); 
351 369
        
@@ -360,8 +378,14 @@ class custReportController extends Controller
360 378
     {
361 379
         
362 380
         $data = CustDetail::where('id', $id)->first();
381
+        $adminList = DB::table('admin')->select('id', 'realname', 'username')->where('id','>', 1)->get();
382
+        $adminList = json_decode(json_encode($adminList), true);
383
+        $teamList = DB::table('teams')->select('id', 'name')->get();
384
+        $teamList = json_decode(json_encode($teamList), true);
363 385
         return view('custreport/detailedit', [       
364 386
             'custreport' => $data,
387
+            'adminlist'  => $adminList,
388
+            'teamlist'  => $teamList,
365 389
         ]);
366 390
 
367 391
     }
@@ -373,27 +397,40 @@ class custReportController extends Controller
373 397
      */
374 398
     public function detailupdate(Request $request)
375 399
     {            
400
+        $id = (int)$request->input('id');
401
+        $admin_id = (int)$request->input('admin_id');
402
+        if(!$admin_id){
403
+            $admin_id = session('admin_id');
404
+        }
376 405
         $this->validate($request, [
377 406
             'id'           => 'required', 
378 407
             'old_consult'           => 'required', 
379 408
             'new_consult'           => 'required', 
380 409
             'fan_add'           => 'required',   
381
-            'dtime'           => 'required',   
410
+            'dtime'           => 'required|unique:cust_day_detail,dtime,'.$id.',id,admin_id,'.$admin_id,   
382 411
         ], [                  
383 412
             'id.required'           => 'id不能为空',                   
384 413
             'old_consult.required'           => '老粉咨询不能为空',                   
385 414
             'new_consult.required'           => '新粉咨询数不能为空',                                    
386 415
             'fan_add.required'           => '加粉数不能为空',                                    
387
-            'dtime.required'           => '日期不能为空',                                    
416
+            'dtime.required'           => '日期不能为空', 
417
+            'dtime.unique'           => '指定日期已经存在',                                   
388 418
         ]);
389 419
         //数据库-新增数据
390 420
         $custreport = array();       
391 421
         $custreport['old_consult'] = $request->input('old_consult'); 
392 422
         $custreport['new_consult'] = $request->input('new_consult'); 
393 423
         $custreport['fan_add'] = $request->input('fan_add'); 
394
-        $custreport['dtime'] = $request->input('dtime');  
424
+        $custreport['new_reply'] = $request->input('new_reply'); 
425
+        $custreport['dtime'] = $request->input('dtime'); 
426
+
427
+        $admin_id = (int)$request->input('admin_id');   
428
+        if($admin_id>0){
429
+            $admin_info = DB::table('admin')->select('realname', 'team_id')->where('id', $admin_id)->first();
430
+            $custreport['admin_id'] = $admin_id;
431
+            $custreport['admin_name'] = $admin_info->realname;
432
+        } 
395 433
 
396
-        $id = (int)$request->input('id');
397 434
         $res = DB::table('cust_day_detail')->where('id', $id)->update($custreport);        
398 435
         return redirect('/admin/custreport/detailindex')->with('info', '更新成功');         
399 436
     }

+ 54 - 4
resources/views/custreport/detailcreate.blade.php

@@ -19,11 +19,18 @@
19 19
                     <input type="text" class="input-text" value="{{old('fan_add')}}" placeholder="请输入加粉数" name="fan_add">
20 20
                 </div>
21 21
             </div>
22
-            
22
+
23
+            <div class="row cl">
24
+                <label class="form-label col-xs-4 col-sm-2">
25
+                    新粉回复数:</label>
26
+                <div class="formControls col-xs-6 col-sm-6">
27
+                    <input type="text" class="input-text" value="{{old('new_reply')}}" placeholder="" name="new_reply">
28
+                </div>
29
+            </div>            
23 30
             
24 31
             <div class="row cl">
25 32
                 <label class="form-label col-xs-4 col-sm-2">
26
-                    老粉咨询数:</label>
33
+                    老粉询数:</label>
27 34
                 <div class="formControls col-xs-6 col-sm-6">
28 35
                     <input type="text" class="input-text" value="{{old('old_consult')}}" placeholder="" name="old_consult">
29 36
                 </div>
@@ -31,7 +38,7 @@
31 38
 
32 39
             <div class="row cl">
33 40
                 <label class="form-label col-xs-4 col-sm-2">
34
-                    新粉询数:</label>
41
+                    新粉询数:</label>
35 42
                 <div class="formControls col-xs-6 col-sm-6">
36 43
                     <input type="text" class="input-text" value="{{old('new_consult')}}" placeholder="" name="new_consult">
37 44
                 </div>
@@ -44,6 +51,29 @@
44 51
                     <input id="dtime" type="text" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd' })" class="input-text Wdate" style="width:22%;text-align:center;" name="dtime" value="">                    
45 52
                 </div>
46 53
             </div>
54
+
55
+            <div class="row cl">
56
+                <label class="form-label col-xs-4 col-sm-2">
57
+                    选择销售员(不选默认当前用户):</label>
58
+                <div class="formControls col-xs-6 col-sm-6">
59
+                    <span class="select-box">
60
+                        <select  size="1" name="team" id='team'>
61
+                            <option value="0" @if(old('team')=='') selected @endif>选择团队</option>
62
+                            @foreach($teamlist as $v)
63
+                                <option value="{{$v['id']}}" @if(old('team')==$v['id']) selected @endif>{{$v['name']}}</option>
64
+                            @endforeach
65
+                        </select>
66
+
67
+                        <select id='admins' size="1" name="admin_id">
68
+                            <option value="0" @if(old('admin_id')=='') selected @endif>-- 选择销售 --</option>
69
+                            @foreach($adminlist as $v)
70
+                                <option value="{{$v['id']}}" @if(old('admin_id')==$v['id']) selected @endif>{{$v['realname']}}</option>
71
+                            @endforeach
72
+                        </select>
73
+                        &nbsp;&nbsp;
74
+                    </span>
75
+                </div>
76
+            </div>
47 77
         
48 78
             <div class="row cl">
49 79
                 <div class="col-9 col-offset-2">
@@ -64,7 +94,27 @@
64 94
     <script type="text/javascript" src="/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
65 95
     <script type="text/javascript">
66 96
         $(function(){
67
-            setTimeout("$('#error').hide()",3000);            
97
+            setTimeout("$('#error').hide()",3000); 
98
+
99
+            $('#team').change(function(){
100
+                team = $('#team').val();
101
+                if(team==''){
102
+                    return false;
103
+                }
104
+                $.ajax({
105
+                    'url':'/admin/order/teamAdmins/'+team,
106
+                    'type': 'get',
107
+                    'dataType':'json',
108
+                    'success' : function(data){
109
+                        str = '<option value=\'0\'>-- 选择销售 --<\/option>';
110
+                        $.each(data, function(i, va){
111
+                            str += '<option value="'+va.id+'">' + va.realname +'<\/option>';
112
+                        })
113
+                        
114
+                        $('#admins').html(str);
115
+                    }
116
+                });
117
+            })           
68 118
         });
69 119
         /*返回*/
70 120
         function return_index(){

+ 52 - 2
resources/views/custreport/detailedit.blade.php

@@ -22,10 +22,17 @@
22 22
                 </div>
23 23
             </div>
24 24
             
25
+            <div class="row cl">
26
+                <label class="form-label col-xs-4 col-sm-2">
27
+                    新粉回复数:</label>
28
+                <div class="formControls col-xs-6 col-sm-6">
29
+                    <input type="text" class="input-text" value="{{$custreport['new_reply']}}" placeholder="" name="new_reply">
30
+                </div>
31
+            </div>
25 32
             
26 33
             <div class="row cl">
27 34
                 <label class="form-label col-xs-4 col-sm-2">
28
-                    老粉咨询数:</label>
35
+                    老粉询数:</label>
29 36
                 <div class="formControls col-xs-6 col-sm-6">
30 37
                     <input type="text" class="input-text" value="{{$custreport['old_consult']}}" placeholder="" name="old_consult">
31 38
                 </div>
@@ -33,7 +40,7 @@
33 40
 
34 41
             <div class="row cl">
35 42
                 <label class="form-label col-xs-4 col-sm-2">
36
-                    新粉询数:</label>
43
+                    新粉询数:</label>
37 44
                 <div class="formControls col-xs-6 col-sm-6">
38 45
                     <input type="text" class="input-text" value="{{$custreport['new_consult']}}" placeholder="" name="new_consult">
39 46
                 </div>
@@ -46,6 +53,29 @@
46 53
                     <input id="dtime" type="text" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd' })" class="input-text Wdate" style="width:22%;text-align:center;" name="dtime" value="{{$custreport['dtime']}}">                    
47 54
                 </div>
48 55
             </div>
56
+
57
+            <div class="row cl">
58
+                <label class="form-label col-xs-4 col-sm-2">
59
+                    选择销售员(不选默认当前用户):</label>
60
+                <div class="formControls col-xs-6 col-sm-6">
61
+                    <span class="select-box">
62
+                        <select  size="1" name="team" id='team'>
63
+                            <option value="0" @if($custreport['team_id']=='') selected @endif>选择团队</option>
64
+                            @foreach($teamlist as $v)
65
+                                <option value="{{$v['id']}}" @if($custreport['team_id']==$v['id']) selected @endif>{{$v['name']}}</option>
66
+                            @endforeach
67
+                        </select>
68
+
69
+                        <select id='admins' size="1" name="admin_id">
70
+                            <option value="0" @if($custreport['admin_id']=='') selected @endif>-- 选择销售 --</option>
71
+                            @foreach($adminlist as $v)
72
+                                <option value="{{$v['id']}}" @if($custreport['admin_id']==$v['id']) selected @endif>{{$v['realname']}}</option>
73
+                            @endforeach
74
+                        </select>
75
+                        &nbsp;&nbsp;
76
+                    </span>
77
+                </div>
78
+            </div>
49 79
                
50 80
             @endif
51 81
 
@@ -69,6 +99,26 @@
69 99
     <script type="text/javascript">
70 100
         $(function(){
71 101
             setTimeout("$('#error').hide()",3000);
102
+
103
+            $('#team').change(function(){
104
+                team = $('#team').val();
105
+                if(team==''){
106
+                    return false;
107
+                }
108
+                $.ajax({
109
+                    'url':'/admin/order/teamAdmins/'+team,
110
+                    'type': 'get',
111
+                    'dataType':'json',
112
+                    'success' : function(data){
113
+                        str = '<option value=\'0\'>-- 选择销售 --<\/option>';
114
+                        $.each(data, function(i, va){
115
+                            str += '<option value="'+va.id+'">' + va.realname +'<\/option>';
116
+                        })
117
+                        
118
+                        $('#admins').html(str);
119
+                    }
120
+                });
121
+            })
72 122
         });
73 123
         /*返回*/
74 124
         function return_index(){

+ 4 - 2
resources/views/custreport/detaillist.blade.php

@@ -32,8 +32,9 @@
32 32
                 <tr class="text-c">
33 33
                     <th width="8%">日期</th>
34 34
                     <th width="8%">加粉数</th>
35
-                    <th width="8%">老粉咨询数</th>
36
-                    <th width="8%">新粉咨询数</th>
35
+                    <th width="8%">新粉回复数</th>
36
+                    <th width="8%">老粉询价数</th>
37
+                    <th width="8%">新粉询价数</th>
37 38
                     <th width="8%">所属销售</th>                                  
38 39
                     <th width="6%">操作</th>                  
39 40
                 </tr>
@@ -44,6 +45,7 @@
44 45
                         <tr class="text-c" style=" text-align:center;">                           
45 46
                             <td>{{$a['dtime']}}</td>                            
46 47
                             <td>{{$a['fan_add']}}</td>                            
48
+                            <td>{{$a['new_reply']}}</td>                            
47 49
                             <td>{{$a['old_consult']}}</td>                            
48 50
                             <td>{{$a['new_consult']}}</td>                            
49 51
                             <td>{{$a['admin_name']}}</td>