cqp před 1 měsícem
rodič
revize
a4c6a96da9

+ 13 - 0
app/Http/Controllers/Api/CustomerSupplyController.php

@@ -61,6 +61,19 @@ class CustomerSupplyController extends BaseController
         }
     }
 
+    public function customerSupplyList2(Request $request)
+    {
+        $service = new CustomerSupplyService();
+        $user = $request->userData;
+        list($status,$data) = $service->customerSupplyList2($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
     public function customerSupplyDetail(Request $request)
     {
         $service = new CustomerSupplyService();

+ 13 - 0
app/Http/Controllers/Api/OrderController.php

@@ -221,6 +221,19 @@ class OrderController extends BaseController
         }
     }
 
+    public function toDoList2(Request $request)
+    {
+        $service = new OrderService();
+        $user = $request->userData;
+        list($status,$data) = $service->toDoList2($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
     public function toDoDetail(Request $request)
     {
         $service = new OrderService();

+ 61 - 2
app/Service/CustomerSupplyService.php

@@ -19,7 +19,6 @@ class CustomerSupplyService extends Service
             DB::beginTransaction();
 
             $model = CustomerSupply::where('id',$data['id'])->first();
-            $model->code = $data['code'] ?? '';
             $model->title = $data['title'] ?? '';
             $model->type = $data['type'] ?? 0;
             $model->status = $data['status'] ?? 0;
@@ -64,7 +63,7 @@ class CustomerSupplyService extends Service
             DB::beginTransaction();
 
             $model = new CustomerSupply();
-            $model->code = $data['code'] ?? '';
+            $model->code = $this->generateCode($user['id']);
             $model->title = $data['title'] ?? '';
             $model->type = $data['type'] ?? 0;
             $model->status = $data['status'] ?? 0;
@@ -96,6 +95,9 @@ class CustomerSupplyService extends Service
             DB::commit();
         }catch (\Exception $exception){
             DB::rollBack();
+            if (str_contains($exception->getMessage(), '1062') || str_contains($exception->getMessage(), 'Duplicate entry')) {
+                return [false, '网络波动,请重新操作!'];
+            }
             return [false,$exception->getMessage()];
         }
 
@@ -234,6 +236,37 @@ class CustomerSupplyService extends Service
         return [true, $list];
     }
 
+    public function customerSupplyList2($data,$user){
+        $model = $this->customerSupplyCommon($data, $user);
+        $list = $this->limit($model,'',$data);
+        $list = $this->fillData($list,$user,$data);
+
+        // 加上统计
+        $list['sum_array'] = $this->countStatus($data, $user);
+
+        return [true, $list];
+    }
+
+    public function countStatus($data, $user)
+    {
+        $model = $this->customerSupplyCommon($data, $user);
+
+        // 统计各状态
+        $status1 = (clone $model)->where('status', 1)->count();
+        $status2 = (clone $model)->where('status', 2)->count();
+        $status3 = (clone $model)->where('status', 3)->count();
+        $status4 = (clone $model)->where('status', 4)->count();
+        $status5 = (clone $model)->where('status', 5)->count();
+
+        return [
+            'status_1' => $status1,
+            'status_2' => $status2,
+            'status_3' => $status3,
+            'status_4' => $status4,
+            'status_5' => $status5,
+        ];
+    }
+
     public function customerSupplyListForSearch($data,$user){
         $model = $this->customerSupplyCommon($data, $user,['id']);
         $id = $model->get()->toArray();
@@ -321,4 +354,30 @@ class CustomerSupplyService extends Service
 
         return array_column($result,null,'id');
     }
+
+    public function generateCode($crt_id)
+    {
+        return DB::transaction(function () use ($crt_id) {
+
+            // 加行级锁 FOR UPDATE,避免并发重复
+            $maxCode = CustomerSupply::where('crt_id', $crt_id)
+                ->lockForUpdate()
+                ->max('code');
+
+            // 转数字
+            $num = intval($maxCode);
+
+            // +1
+            $num++;
+
+            // 小于 10000 → 保留 4 位前导零
+            if ($num < 10000) {
+                $code = str_pad($num, 4, '0', STR_PAD_LEFT);
+            } else {
+                $code = (string)$num; // 大于等于10000则直接用数字
+            }
+
+            return $code;
+        });
+    }
 }

+ 28 - 0
app/Service/OrderService.php

@@ -800,10 +800,38 @@ class OrderService extends Service
         $model = $this->toDoCommon($data, $user);
         $list = $this->limit($model,'',$data);
         $list = $this->fillToDoData($list,$user,$data);
+        $list['sum_array'] = $this->countStatus($data, $user);
 
         return [true, $list];
     }
 
+    public function toDoList2($data,$user){
+        $model = $this->toDoCommon($data, $user);
+        $list = $this->limit($model,'',$data);
+        $list = $this->fillToDoData($list,$user,$data);
+
+        // 加上统计
+        $list['sum_array'] = $this->countStatus($data, $user);
+
+        return [true, $list];
+    }
+
+    public function countStatus($data, $user)
+    {
+        $model = $this->toDoCommon($data, $user);
+
+        // 统计各状态
+        $status0 = (clone $model)->where('status', 0)->count();
+        $status1 = (clone $model)->where('status', 1)->count();
+        $status2 = (clone $model)->where('status', 2)->count();
+
+        return [
+            'status_0' => $status0,
+            'status_1' => $status1,
+            'status_2' => $status2,
+        ];
+    }
+
     public function toDoRule(&$data, $user, $is_add = true){
         if(empty($data['title'])) return [false, '待办标题不能为空'];
         if(empty($data['type'])) return [false, '间隔时长不能为空'];

+ 40 - 21
app/Service/OrganizationService.php

@@ -17,7 +17,6 @@ class OrganizationService extends Service
             DB::beginTransaction();
 
             $model = Organization::where('id',$data['id'])->first();
-            $model->code = $data['code'] ?? '';
             $model->title = $data['title'] ?? '';
             $model->industry_name = $data['industry_name'] ?? "";
             $model->industry_ranking = $data['industry_ranking'] ?? "";
@@ -53,7 +52,7 @@ class OrganizationService extends Service
             DB::beginTransaction();
 
             $model = new Organization();
-            $model->code = $data['code'] ?? '';
+            $model->code = $this->generateCode($user['id']);
             $model->title = $data['title'] ?? '';
             $model->industry_name = $data['industry_name'] ?? "";
             $model->industry_ranking = $data['industry_ranking'] ?? "";
@@ -72,6 +71,9 @@ class OrganizationService extends Service
             DB::commit();
         }catch (\Exception $exception){
             DB::rollBack();
+            if (str_contains($exception->getMessage(), '1062') || str_contains($exception->getMessage(), 'Duplicate entry')) {
+                return [false, '网络波动,请重新操作!'];
+            }
             return [false,$exception->getMessage()];
         }
 
@@ -95,14 +97,11 @@ class OrganizationService extends Service
         if(! empty($data['receipt_list'])){
             $receipt = [];
             foreach ($data['receipt_list'] as $value){
-                $start_time = strtotime($value['start_time'] . "-01");
-                $end_time = strtotime($value['end_time'] . "-01");
                 if(empty($value['receipt'])) continue;
                 $receipt[] = [
                     'organization_id' => $id,
                     'type' => $value['type'],
-                    'start_time' => $start_time,
-                    'end_time' => $end_time,
+                    'year' => $value['year'],
                     'receipt' => $value['receipt'],
                     'crt_time' => $time,
                 ];
@@ -141,8 +140,7 @@ class OrganizationService extends Service
             }elseif(in_array($value['type'], [OrganizationDetails::type_three])){
                 $receipt[] = [
                     'type' => $value['type'],
-                    'start_time' => date("Y-m", $value['start_time']),
-                    'end_time' => date("Y-m", $value['end_time']),
+                    'year' => $value['year'],
                     'receipt' => $value['receipt'],
                 ];
             }else{
@@ -241,7 +239,6 @@ class OrganizationService extends Service
     }
 
     public function organizationRule(&$data, $user, $is_add = true){
-        if(empty($data['code'])) return [false, '编码不能为空'];
         if(empty($data['title'])) return [false, '名称不能为空'];
         if(empty($data['type']) || ! isset(Organization::$type_name[$data['type']])) return [false, '组织类型错误'];
         if(! empty($data['founding_time'])) $data['founding_time'] = $this->changeDateToDate($data['founding_time']);
@@ -256,10 +253,10 @@ class OrganizationService extends Service
         if(! empty($data['receipt_list'])){
             foreach ($data['receipt_list'] as $value){
                 if(empty($value['type'])) return [false, '营收信息类型不能为空'];
-                if(empty($value['start_time']) || empty($value['end_time'])) return [false, '营收日期范围不能为空'];
-                $start_time = strtotime($value['start_time'] . "-01");
-                $end_time = strtotime($value['end_time'] . "-01");
-                if(! $start_time || ! $end_time) return [false, '营收日期范围错误'];
+                if(empty($value['year'])) return [false, '营收年份不能为空'];
+//                $start_time = strtotime($value['start_time'] . "-01");
+//                $end_time = strtotime($value['end_time'] . "-01");
+//                if(! $start_time) return [false, '营收日期范围错误'];
                 if(empty($value['receipt'])) return [false, '营收数据不能为空'];
             }
         }
@@ -274,19 +271,14 @@ class OrganizationService extends Service
         }
 
         if($is_add){
-            $bool = Organization::where('code',$data['code'])
-                ->where('crt_id', $user['id'])
-                ->where('del_time',0)
-                ->exists();
+
         }else{
             if(empty($data['id'])) return [false,'ID不能为空'];
-            $bool = Organization::where('code',$data['code'])
-                ->where('crt_id', $user['id'])
-                ->where('id','<>',$data['id'])
+            $bool = Organization::where('id', $data['id'])
                 ->where('del_time',0)
                 ->exists();
+            if(! $bool) return [false, '组织不存在或已被删除'];
         }
-        if($bool) return [false, '编码已存在'];
 
         return [true, $data];
     }
@@ -304,4 +296,31 @@ class OrganizationService extends Service
 
         return $data;
     }
+
+    public function generateCode($crt_id)
+    {
+        return DB::transaction(function () use ($crt_id) {
+
+            // 加行级锁 FOR UPDATE,避免并发重复
+            $maxCode = Organization::where('crt_id', $crt_id)
+                ->lockForUpdate()
+                ->max('code');
+
+            // 转数字
+            $num = intval($maxCode);
+
+            // +1
+            $num++;
+
+            // 小于 10000 → 保留 4 位前导零
+            if ($num < 10000) {
+                $code = str_pad($num, 4, '0', STR_PAD_LEFT);
+            } else {
+                $code = (string)$num; // 大于等于10000则直接用数字
+            }
+
+            return $code;
+        });
+    }
+
 }

+ 0 - 2
app/Service/QuantizationService.php

@@ -285,7 +285,6 @@ class QuantizationService extends Service
             $model->quantization_id = $data['quantization_id'];
             $model->start_time = $data['start_time'] ?? 0;
             $model->end_time = $data['end_time'] ?? 0;
-            $model->products = $data['products'] ?? '';
             $model->score = $data['score'] ?? 0;
             $model->save();
 
@@ -317,7 +316,6 @@ class QuantizationService extends Service
             $model->quantization_id = $data['quantization_id'];
             $model->start_time = $data['start_time'] ?? 0;
             $model->end_time = $data['end_time'] ?? 0;
-            $model->products = $data['products'] ?? '';
             $model->score = $data['score'] ?? 0;
             $model->type = $data['type'] ?? 0;
             $model->crt_id = $user['id'];

+ 0 - 4
config/header/69.php

@@ -18,10 +18,6 @@ return [
         'key' =>'organization_title',
         'value' => '组织名称',
     ],
-    [
-        'key' =>'products',
-        'value' => '拟合作产品',
-    ],
     [
         'key' =>'score',
         'value' => '得分',

+ 2 - 2
routes/wx.php

@@ -59,7 +59,7 @@ Route::group(['middleware'=> ['checkWx']],function ($route){
     $route->any('organizationDetail', 'Api\OrganizationController@organizationDetail');
 
     //客户供应商
-    $route->any('customerSupplyList', 'Api\CustomerSupplyController@customerSupplyList');
+    $route->any('customerSupplyList', 'Api\CustomerSupplyController@customerSupplyList2');
     $route->any('customerSupplyEdit', 'Api\CustomerSupplyController@customerSupplyEdit');
     $route->any('customerSupplyAdd', 'Api\CustomerSupplyController@customerSupplyAdd');
     $route->any('customerSupplyDel', 'Api\CustomerSupplyController@customerSupplyDel');
@@ -103,7 +103,7 @@ Route::group(['middleware'=> ['checkWx']],function ($route){
     $route->any('reminderSendWx', 'Api\OrderController@reminderSendWx');
 
     //待办
-    $route->any('toDoList', 'Api\OrderController@toDoList');
+    $route->any('toDoList', 'Api\OrderController@toDoList2');
     $route->any('toDoEdit', 'Api\OrderController@toDoEdit');
     $route->any('toDoAdd', 'Api\OrderController@toDoAdd');
     $route->any('toDoDel', 'Api\OrderController@toDoDel');