Browse Source

查询限制个人,异常去掉售后还货数

Sunny Feng 3 years ago
parent
commit
7d8c050a66

+ 1 - 1
app/Admin/Controllers/AlarmController.php

xqd
@@ -43,7 +43,7 @@ class AlarmController extends AdminController
             $grid->column('outbound_num')->link(function () {
                 return admin_url('GoodsOutbound?user_id=' . $this->user_id . '&out_at=' . $this->out_at .'&goods_id='.$this->goods_id);
             });
-            $grid->column('back_num')->link(function () {
+            $grid->column('back_num', '还货数(不含售后)')->link(function () {
                 return admin_url('GoodsBack?seller_user_id=' . $this->user_id . '&out_at=' . $this->out_at .'&goods_id='.$this->goods_id);
             });
             $grid->column('deliver_num')->link(function () {

+ 21 - 0
app/Admin/Controllers/TestController.php

xqd
@@ -0,0 +1,21 @@
+<?php
+
+namespace App\Admin\Controllers;
+
+use App\Models\Alarm;
+use App\Http\Controllers\Controller;
+use Illuminate\Http\Request;
+
+class TestController extends Controller
+{
+    // 地址 /admin/test?date=2021-07-21
+    public function index(Request $req, Alarm $alarm)
+    {
+        if($req->date){
+            $alarm->syncAlarm($req->date);
+        } else {
+            return 'date not null';
+        }
+        return 'ok';
+    }
+}

+ 1 - 0
app/Admin/routes.php

xqd
@@ -25,6 +25,7 @@ Route::group([
     $router->resource('users', 'UserController');
 
     $router->get('/', 'HomeController@index');
+    $router->get('test', 'TestController@index');
     $router->any('Inventory', 'InventoryController@index');
     $router->any('InventoryRole', 'InventoryRoleController@index');
 

+ 12 - 0
app/Helpers/functions.php

xqd
@@ -4,6 +4,18 @@ use GuzzleHttp\Client;
 use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Storage;
 
+
+if (!function_exists('get_req')) {
+    // 查询限制本人
+    function get_req($req, $user){ // $this->user()
+        if (empty($req['user_id']) && in_array($user->role, [1,3,4])) {
+             // 销售 物流 售后 才限制
+            $req['user_id'] = $user->id;
+        }
+        return $req;
+    }
+}
+
 if (!function_exists('plus_minus_conversion')) {
     //正负数相互转换--支持小数
     function plus_minus_conversion($value){

+ 2 - 0
app/Http/Controllers/Api/GoodsBackController.php

xqd
@@ -18,6 +18,8 @@ class GoodsBackController extends Controller
     public function list()
     {
         $req = request()->post();
+        // 销售、物流、售后 只能看到自己的记录
+        $req = get_req($req, $this->user());
         $builder = GoodsBack::ofCommon($req)
         ->with(['user','sourceUser','sellerUser','goods','goods.category'])
         ->orderBy('id','desc');

+ 2 - 0
app/Http/Controllers/Api/GoodsDeliverController.php

xqd
@@ -19,6 +19,8 @@ class GoodsDeliverController extends Controller
     public function list()
     {
         $req = request()->post();
+        // 物流 只能看到自己的记录
+        $req = get_req($req, $this->user());
         $builder = GoodsDeliver::ofCommon($req)
         ->with(['user','sellerUser','goods','goods.category'])
         ->orderBy('id','desc');

+ 2 - 0
app/Http/Controllers/Api/GoodsInspectController.php

xqd
@@ -16,6 +16,8 @@ class GoodsInspectController extends Controller
     public function list()
     {
         $req = request()->post();
+        // 售后 只能看到自己的记录
+        $req = get_req($req, $this->user());
         $builder = GoodsInspect::ofCommon($req)
         ->with(['user','sellerUser','goods','goods.category'])
         ->orderBy('id','desc');

+ 3 - 1
app/Http/Controllers/Api/GoodsOutboundController.php

xqd
@@ -15,11 +15,13 @@ class GoodsOutboundController extends Controller
     public function list()
     {
         $req = request()->post();
-        // 兼容
+        // 兼容搜索
         if (isset($req['seller_user_id']) && $req['seller_user_id'] !== '') {
             $req['user_id'] = $req['seller_user_id'];
             unset($req['seller_user_id']);
         }
+        // 销售 只能看到自己的记录
+        $req = get_req($req, $this->user());
         $builder = GoodsOutbound::ofCommon($req)
         ->with(['user','goods','goods.category'])
         ->orderBy('id','desc');

+ 2 - 0
app/Http/Controllers/Api/IndexController.php

xqd
@@ -31,6 +31,8 @@ class IndexController extends Controller
             $category = new Category();
             $req['category_id'] = $category->getChildIds([$req['category_id']], [$req['category_id']]);
         }
+        // 销售、物流、售后 只能看到自己的记录
+        $req = get_req($req, $user);
 
         $result = call_user_func_array(array($this, 'getRole' . $user->role), [$req]);
 

+ 7 - 2
app/Models/Traits/GenerateAlarmHelper.php

xqd xqd
@@ -11,10 +11,12 @@ use Carbon\Carbon;
 // 定时任务生成警报
 trait GenerateAlarmHelper
 {
-    public function syncAlarm()
+    public function syncAlarm($out_at = '')
     {
         // 获取前天的日期,格式如:2021-06-30
-        $out_at = Carbon::now()->subDays(2)->toDateString();
+        if(!$out_at){
+            $out_at = Carbon::now()->subDays(2)->toDateString();
+        }
 
         // 获取所有销售
         $users = User::where('role', 1)->get()->toArray();
@@ -31,6 +33,9 @@ trait GenerateAlarmHelper
             // 还货
             $back = GoodsBack::where('out_at', $out_at)
             ->where('seller_user_id', $user['id'])
+            ->whereHas('sourceUser', function($query) {
+                $query->where('role', '<>', 3); // 不包括售后
+            })
             ->selectRaw('sum(number) as number, goods_id as id')
             ->groupBy('goods_id')
             ->pluck('number','id')