cqpCow 1 ano atrás
pai
commit
9bb03e90f3

+ 35 - 0
app/Http/Controllers/Api/TableHeadController.php

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

+ 14 - 0
app/Model/TableSetting.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+
+class TableSetting extends Model
+{
+    protected $table = "table_setting"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+}

+ 62 - 0
app/Service/TableHeadService.php

@@ -0,0 +1,62 @@
+<?php
+
+namespace App\Service;
+
+use App\Model\TableSetting;
+use Illuminate\Support\Facades\DB;
+
+class TableHeadService extends Service
+{
+    public function tableheadAdd($data, $user){
+        if(empty($data['table_head'])) return [false,'自定义表头不能为空'];
+        if(empty($data['menu_id'])) return [false, 'menu_id不能为空'];
+
+        $time = time();
+        $insert = [];
+        foreach ($data['table_head'] as $value){
+            if(empty($value['key'])) return [false, 'key不能为空'];
+            if(empty($value['value'])) return [false, 'value不能为空'];
+            if(empty($value['sort'])) return [false, 'sort不能为空'];
+            if(empty($value['is_show'])) return [false, 'is_show不能为空'];
+
+            $insert[] = [
+                'key' => $value['key'],
+                'value' => $value['value'],
+                'sort' => $value['sort'],
+                'is_show' => $value['is_show'],
+                'menu_id' => $data['menu_id'],
+                'crt_time' => $time,
+                'crt_id' => $user['id'],
+            ];
+        }
+
+        DB::beginTransaction();
+        try{
+            TableSetting::where('del_time',0)
+                ->where('crt_id',$user['id'])
+                ->where('menu_id',$data['menu_id'])
+                ->update(['del_time' => $time]);
+            TableSetting::insert($insert);
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false, $exception->getMessage()];
+        }
+
+        return [true,''];
+    }
+
+    public function tableheadGet($data, $user){
+        if(empty($data['menu_id'])) return [false,'menu_id不能为空!'];
+
+        $header = config("header.{$data['menu_id']}") ?? [];
+
+        foreach ($header as $key => $value){
+            $header[$key]['sort'] = $key + 1;
+            $header[$key]['is_show'] = 1;
+        }
+
+        return [true, $header];
+    }
+}

+ 105 - 0
config/header/37.php

@@ -0,0 +1,105 @@
+<?php
+/**
+ * '菜单ID' => [
+ *     '字段英文名' =》 '字段中文名'
+ * ]
+ */
+
+return [
+    [
+        'key' => 'order_number',
+        'value' => '合同编号',
+    ],
+    [
+        'key' => 'model_type_title',
+        'value' => '合同模板',
+    ],
+    [
+        'key' => 'sales_order_type_title',
+        'value' => '类型',
+    ],
+    [
+        'key' => 'customer_title',
+        'value' => '客户',
+    ],
+    [
+        'key' => 'sign_time',
+        'value' => '签订时间',
+    ],
+    [
+        'key' => 'contract_state_title',
+        'value' => '合同状态',
+    ],
+    [
+        'key' => 'product_total',
+        'value' => '产品合计',
+    ],
+    [
+        'key' => 'rate',
+        'value' => '整单折扣率',
+    ],
+    [
+        'key' => 'other_fee',
+        'value' => '其它费用',
+    ],
+    [
+        'key' => 'discount_fee',
+        'value' => '优惠金额',
+    ],
+    [
+        'key' => 'contract_fee',
+        'value' => '合同金额',
+    ],
+    [
+        'key' => 'fee',
+        'value' => '指派金额',
+    ],
+    [
+        'key' => 'fee1',
+        'value' => '已收金额',
+    ],
+    [
+        'key' => 'fee2',
+        'value' => '未收金额',
+    ],
+    [
+        'key' => 'fee3',
+        'value' => '坏账金额',
+    ],
+    [
+        'key' => 'fee4',
+        'value' => '最终金额',
+    ],
+    [
+        'key' => 'order_type_title',
+        'value' => '订单类型',
+    ],
+    [
+        'key' => 'crt_time',
+        'value' => '创建时间',
+    ],
+    [
+        'key' => 'state_name',
+        'value' => '订单状态',
+    ],
+    [
+        'key' => 'invoice_state_name',
+        'value' => '发货状态',
+    ],
+    [
+        'key' => 'invoice_arr',
+        'value' => '发货单号',
+    ],
+    [
+        'key' => 'dispatch_company',
+        'value' => '派遣公司',
+    ],
+    [
+        'key' => 'contract_type_title',
+        'value' => '合同类型',
+    ],
+    [
+        'key' => 'pay_way_title',
+        'value' => '付款方式',
+    ],
+];

+ 5 - 0
routes/api.php

@@ -238,4 +238,9 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('yjMan','Api\DeleteController@yj');
     //导入
     $route->any('import','Api\ImportController@import');
+
+    //获取默认表头
+    $route->any('getTableHead','Api\TableHeadController@tableHeadGet');
+    //设置表头
+    $route->any('setTableHead','Api\TableHeadController@tableHeadAdd');
 });