cqp 1 ヶ月 前
コミット
cb9f247099

+ 76 - 0
app/Http/Controllers/Api/FreightController.php

@@ -0,0 +1,76 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+use App\Service\FreightService;
+use Illuminate\Http\Request;
+
+class FreightController extends BaseController
+{
+    public function freightEdit(Request $request)
+    {
+        $service = new FreightService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->freightEdit($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function freightAdd(Request $request)
+    {
+        $service = new FreightService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->freightAdd($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+
+    }
+
+    public function freightDel(Request $request)
+    {
+        $service = new FreightService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->freightDel($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+
+    }
+
+    public function freightList(Request $request)
+    {
+        $service = new FreightService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->freightList($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function freightDetail(Request $request)
+    {
+        $service = new FreightService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->freightDetail($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+}

+ 13 - 0
app/Model/Freight.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Model;
+
+class Freight extends UseScopeBaseModel
+{
+    protected $table = "freight"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+
+    public static $field = ['area','id','region','kilometer','min_freight_fee','one_and_five','greater_than_five','crt_id','crt_time','company'];
+}

+ 169 - 0
app/Service/FreightService.php

@@ -0,0 +1,169 @@
+<?php
+
+namespace App\Service;
+
+use App\Model\Employee;
+use App\Model\Freight;
+use Illuminate\Support\Facades\DB;
+
+/**
+ * 运费设置
+ */
+class FreightService extends Service
+{
+    public function freightEdit($data,$user){
+        list($status,$msg) = $this->freightRule($data, $user, false);
+        if(!$status) return [$status,$msg];
+
+        try {
+            DB::beginTransaction();
+
+            $model = Freight::where('id',$data['id'])->first();
+            $model->area = $data['area'] ?? '';
+            $model->region = $data['region'] ?? '';
+            $model->kilometer = $data['kilometer'] ?? 0;
+            $model->min_freight_fee = $data['min_freight_fee'] ?? 0;
+            $model->one_and_five = $data['one_and_five'] ?? 0;
+            $model->greater_than_five = $data['greater_than_five'] ?? 0;
+            $model->company = $data['company'] ?? "";
+            $model->save();
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true, ''];
+    }
+
+    public function freightAdd($data,$user){
+        list($status,$msg) = $this->freightRule($data, $user);
+        if(!$status) return [$status,$msg];
+
+        try {
+            DB::beginTransaction();
+
+            $model = new Freight();
+            $model->area = $data['area'] ?? '';
+            $model->region = $data['region'] ?? '';
+            $model->kilometer = $data['kilometer'] ?? 0;
+            $model->min_freight_fee = $data['min_freight_fee'] ?? 0;
+            $model->one_and_five = $data['one_and_five'] ?? 0;
+            $model->greater_than_five = $data['greater_than_five'] ?? 0;
+            $model->company = $data['company'] ?? "";
+            $model->crt_id = $user['id'];
+            $model->save();
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true, ''];
+    }
+
+    public function freightDel($data){
+        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
+
+        try {
+            DB::beginTransaction();
+            $time = time();
+
+            Freight::where('del_time',0)
+                ->whereIn('id',$data['id'])
+                ->update(['del_time' => $time]);
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true, ''];
+    }
+
+    public function freightDetail($data,$user){
+        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
+        $customer = Freight::where('del_time',0)
+            ->where('id',$data['id'])
+            ->first();
+        if(empty($customer)) return [false,'运费设置不存在或已被删除'];
+        $customer = $customer->toArray();
+
+        $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('emp_name');
+        $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
+
+        return [true, $customer];
+    }
+
+    public function freightCommon($data,$user, $field = []){
+        if(empty($field)) $field = Freight::$field;
+
+        $model = Freight::where('del_time',0)
+            ->select($field)
+            ->orderby('id', 'desc');
+
+        if(! empty($data['area'])) $model->where('area', 'LIKE', '%'.$data['area'].'%');
+        if(! empty($data['region'])) $model->where('region', 'LIKE', '%'.$data['region'].'%');
+        if(! empty($data['company'])) $model->where('company', 'LIKE', '%'.$data['company'].'%');
+        if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
+            $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
+            $model->where('crt_time','>=',$return[0]);
+            $model->where('crt_time','<=',$return[1]);
+        }
+
+        return $model;
+    }
+
+    public function freightList($data,$user){
+        $model = $this->freightCommon($data, $user);
+        $list = $this->limit($model,'',$data);
+        $list = $this->fillData($list,$user,$data);
+
+        return [true, $list];
+    }
+
+    public function freightRule(&$data, $user, $is_add = true){
+        if(! empty($data['kilometer'])){
+            $res = $this->checkNumber($data['kilometer'],2,'positive');
+            if(! $res['valid']) return [false,'公里数:' . $res['error']];
+        }
+        if(! empty($data['min_freight_fee'])){
+            $res = $this->checkNumber($data['min_freight_fee'],2,'positive');
+            if(! $res['valid']) return [false,'最低运费:' . $res['error']];
+        }
+        if(! empty($data['one_and_five'])){
+            $res = $this->checkNumber($data['one_and_five'],2,'positive');
+            if(! $res['valid']) return [false,'1-5吨:' . $res['error']];
+        }
+        if(! empty($data['greater_than_five'])){
+            $res = $this->checkNumber($data['greater_than_five'],2,'positive');
+            if(! $res['valid']) return [false,'5吨以上:' . $res['error']];
+        }
+
+        if($is_add){
+
+        }else{
+            if(empty($data['id'])) return [false,'ID不能为空'];
+            $bool = Freight::where('id',$data['id'])
+                ->where('del_time',0)
+                ->exists();
+            if(! $bool) return [false,'运费设置不存在或已被删除'];
+        }
+
+        return [true, $data];
+    }
+
+    public function fillData($data, $user, $search){
+        if(empty($data['data'])) return $data;
+
+        foreach ($data['data'] as $key => $value){
+            $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
+            $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
+        }
+
+        return $data;
+    }
+}

+ 37 - 0
config/header/66.php

@@ -0,0 +1,37 @@
+<?php
+/**
+ * '菜单ID' => [
+ *     '字段英文名' =》 '字段中文名'
+ * ]
+ */
+
+return [
+    [
+        'key' =>'area',
+        'value' => '所属区域',
+    ],
+    [
+        'key' =>'region',
+        'value' => '地区',
+    ],
+    [
+        'key' =>'kilometer',
+        'value' => '公里数',
+    ],
+    [
+        'key' =>'min_freight_fee',
+        'value' => '最低运费',
+    ],
+    [
+        'key' =>'one_and_five',
+        'value' => '1-5吨',
+    ],
+    [
+        'key' =>'greater_than_five',
+        'value' => '5吨以上',
+    ],
+    [
+        'key' =>'company',
+        'value' => '物流公司',
+    ],
+];

+ 8 - 1
routes/api.php

@@ -89,12 +89,19 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('getEmployeeImg', 'Api\EmployeeController@getEmployeeImg');
 
     //产品名称
-    $route->any('productList', 'Api\ProductController@productList');//选择列表页
+    $route->any('productList', 'Api\ProductController@productList');
     $route->any('productEdit', 'Api\ProductController@productEdit');
     $route->any('productAdd', 'Api\ProductController@productAdd');
     $route->any('productDel', 'Api\ProductController@productDel');
     $route->any('productDetail', 'Api\ProductController@productDetail');
 
+    //运费设置
+    $route->any('freightList', 'Api\FreightController@freightList');
+    $route->any('freightEdit', 'Api\FreightController@freightEdit');
+    $route->any('freightAdd', 'Api\FreightController@freightAdd');
+    $route->any('freightDel', 'Api\FreightController@freightDel');
+    $route->any('freightDetail', 'Api\FreightController@freightDetail');
+
     //获取默认表头
     $route->any('getTableHead','Api\TableHeadController@tableHeadGet');
     //设置表头