chenqp 8 月之前
父節點
當前提交
894776a3cf

+ 21 - 0
app/Http/Controllers/Api/StatisticsController.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+use App\Service\StatisticsService;
+use Illuminate\Http\Request;
+
+class StatisticsController extends BaseController
+{
+    public function statisticsXs(Request $request){
+        $service = new StatisticsService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->statisticsXs($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+}

+ 81 - 0
app/Model/UseScopeBaseModel.php

@@ -568,6 +568,87 @@ class UseScopeBaseModel extends Model
         }
     }
 
+    //活动包 部门和顶级部门(公司)过滤
+    public function scopeSportsBagClear($query, $user, $search)
+    {
+        //是否所有部门
+        $is_all_depart = $user['is_all_depart'] ?? 0;
+        //权限范围内的部门
+        $depart_range = $user['depart_range'] ?? [];
+        //总社id
+        $top_depart_id = $user['head'] ?? [];
+        $top_depart = $top_depart_id['id'] ?? 0;
+
+        //可见范围方法
+        $model = $query->getModel(); // 获取模型的实例
+        $range_function = $model::range_function ?? ""; // 访问静态属性
+        $is_function_range = $this->hasMethod(new RangeService(),$range_function);
+
+        $model = $query->getModel(); // 获取模型的实例
+        $className = get_class($model); // 获取模型类名
+
+        //全部 待审 待我审核
+        if(isset($search['is_check'])){
+            if($search['is_check']){
+                $is_check = $search['is_check'];
+            }else{
+                $is_check = 0;
+            }
+        }else{
+            $is_check = 0;
+        }
+
+        //全部 待审 已审
+        $is_check_function = "";
+        if (defined($className . '::is_check_function')) $is_check_function = $className::is_check_function;
+        $is_check_function_bool = $this->hasMethod(new RangeService(),$is_check_function);
+
+        //全部0 待审1 已审2 (状态类 是全部时检索)
+        $check_search = "";
+        if($is_check_function_bool && $is_check) $check_search = RangeService::$is_check_function($user,$search);
+
+        //顶级部门
+        $search_depart_id = $search['top_depart_id'] ?? 0; //顶级公司
+        if(empty($search_depart_id)){
+            //默认进来 自身顶级公司
+            $top_depart_id = $user['depart_top'][0] ?? [];
+            $top_depart_id = $top_depart_id['depart_id'] ?? 0;
+        }else{
+            //查询 顶级公司
+            $top_depart_id = $search_depart_id;
+        }
+
+        $id = [];
+        //不可见范围
+        if($is_function_range) $id = RangeService::$range_function($user,$search);
+
+        if($is_all_depart){
+            //所有部门
+            if(empty($search_depart_id)){
+                //全部
+                $query->whereIn('depart_id', $depart_range)
+                    ->when(! empty($check_search), function ($query) use ($check_search) {
+                        return $query->whereRaw($check_search);
+                    });
+            }else{
+                //查看某个分社
+                $query->where('top_depart_id', $top_depart_id)
+                    ->when(! empty($check_search), function ($query) use ($check_search) {
+                        return $query->whereRaw($check_search);
+                    });
+            }
+        }else{
+            //某个分社全部 去掉不可见数
+            $query->where('top_depart_id', $top_depart_id)
+                ->when(! empty($check_search), function ($query) use ($check_search) {
+                    return $query->whereRaw($check_search);
+                })
+                ->whereIn('depart_id', $depart_range)
+                ->orWhere('top_depart_id',$top_depart)
+                ->whereNotIn('id', $id);
+        }
+    }
+
     public function getQx($data, $user){
         if(empty($data['menu_id'])) return 0;
         if($user['id'] == Employee::SPECIAL_ADMIN) return 0;

+ 15 - 8
app/Service/OaService.php

@@ -521,12 +521,19 @@ class OaService extends Service
 
     public function oaCommon($menu_id, $param, $sort = 1, $parent_id = 0,$user='')
     {
-        $request = request();
-        foreach ($param as $k => $v) {
-            $request->$k = $v;
-        }
-        $all = $request->all();
-        if (!isset($all['order_number'])) $request->merge($param);
+        //创建request副本对象 没有参数让检索出来的数据为空数组
+        $result_one['id'] = $param['id'] ?? -1;
+        $result_one['order_number'] = $param['order_number'] ?? "-1";
+        $currentRequest = request();
+        $request = $currentRequest->duplicate(
+            $result_one,
+            null,
+            [],
+            $currentRequest->cookies->all(),
+            $currentRequest->files->all(),
+            []
+        );
+
         $detail = $this->oaGetData($menu_id, $request,$user);
         //特殊的审批
         $oa_id = Oa::where('menu_id',$menu_id)->where('del_time', 0)->where('sub_type',2)->value('id');
@@ -833,9 +840,9 @@ class OaService extends Service
         $api = SysMenu::where('id', $menu_id)->value('api');
         $param =  SysMenu::where('id', $menu_id)->value('api_params');
         $param =  json_decode($param,true);
-        $param['state'] = null;
+//        $param['state'] = null;
         $param['menu_id'] = $menu_id;
-        $param['id'] = null;
+//        $param['id'] = null;
         $request->merge($param);
 
         $path = $this->getMenu();

+ 15 - 4
app/Service/SportsBagService.php

@@ -116,6 +116,16 @@ class SportsBagService extends Service
                 SportsBagProductInfo::insert($sub);
             }
 
+            if(! empty($data['check'])) {
+                list($status,$msg) = (new CheckService())->checkAll([
+                    "id" => $material_model->id,
+                    "order_number" => $data['order_number'],
+                    "opt_case" => CheckService::twl,
+                    "menu_id" => $data['menu_id']
+                ],$user);
+                if(! $status) return [true, '保存成功,活动包确认失败,异常信息:' . $msg];
+            }
+            dd(1);
             DB::commit();
         }catch (\Throwable $e){
             DB::rollBack();
@@ -148,15 +158,15 @@ class SportsBagService extends Service
             ->first();
         if(empty($order)) return [false, '活动包不存在或已被删除'];
         $order = $order->toArray();
-        $basic_type = BasicType::whereRaw("FIND_IN_SET(?, id)", [$order['purchase_attribute']])->pluck('title','id')->toArray();
+        $purchase_attribute = explode(',',$order['purchase_attribute']);
+        $basic_type = BasicType::whereIn('id',$purchase_attribute)->pluck('title','id')->toArray();
         $str = "";
         if(! empty($basic_type)){
-            $purchase_attribute = explode(',',$order['purchase_attribute']);
             foreach ($purchase_attribute as $value){
                 $str .= $basic_type[$value] . ',';
             }
         }
-        $order['purchase_attribute_title'] = $str;
+        $order['purchase_attribute_title'] = rtrim($str,',');
 
         $start_time = $order['start_time'] ? date("Y-m-d H:i",$order['start_time']) : '';
         $end_time = $order['end_time'] ? date("Y-m-d H:i",$order['end_time']) : '';
@@ -217,11 +227,12 @@ class SportsBagService extends Service
     }
 
     public function getList($data,$user){
-        $model = SportsBag::Clear($user,$data);
+        $model = SportsBag::SportsBagClear($user,$data);
         $model = $model->where('del_time',0)
             ->select('id','title','number','start_time','end_time','crt_time','crt_id','mark','total_amount','state','order_number','purchase_attribute')
             ->orderby('id', 'desc');
 
+        if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
         if(! empty($data['purchase_attribute'])) $model->whereRaw("FIND_IN_SET(?, purchase_attribute)", [$data['purchase_attribute']]);
         if(isset($data['state'])) $model->where('state', $data['state']);
         if(isset($data['valid'])) {

+ 10 - 0
app/Service/StatisticsService.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace App\Service;
+
+class StatisticsService extends Service
+{
+    public function statisticsXs($data,$user){
+
+    }
+}

+ 3 - 0
routes/api.php

@@ -275,6 +275,9 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('productInventorySetList', 'Api\ProductInventoryController@productInventorySetList');
     $route->any('getMySetting', 'Api\ProductInventoryController@getMySetting');
 
+    //统计
+    $route->any('statisticsXs', 'Api\StatisticsController@statisticsXs');
+
     //设置开关
     $route->any('productInventorySet', 'Api\ProductInventoryController@productInventorySet');
     //可见范围