cqpCow 1 anno fa
parent
commit
c8de234ad2

+ 26 - 0
app/Http/Controllers/Api/ProductController.php

@@ -8,6 +8,19 @@ use Illuminate\Http\Request;
 
 class ProductController extends BaseController
 {
+    public function setIsEditUnitPrice(Request $request)
+    {
+        $service = new ProductService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->setIsEditUnitPrice($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
     public function productCategoryEdit(Request $request)
     {
         $service = new ProductService();
@@ -114,6 +127,19 @@ class ProductController extends BaseController
 
     }
 
+    public function productListIndex(Request $request)
+    {
+        $service = new ProductService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->productListIndex($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
     public function productList(Request $request)
     {
         $service = new ProductService();

+ 7 - 0
app/Model/Product.php

@@ -47,4 +47,11 @@ class Product extends UseScopeBaseModel
             'font_color' => 'white',
         ],
     ];
+
+    const is_use_zero = 0;
+    const is_use_one = 1;
+    public static $is_use = [
+        self::is_use_zero => '停用',
+        self::is_use_one => '启用',
+    ];
 }

+ 4 - 0
app/Model/ProductCategory.php

@@ -8,4 +8,8 @@ class ProductCategory extends UseScopeBaseModel
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
     protected $dateFormat = 'U';
+    public static $is_edit_unit_price = [
+        0 => "否",
+        1 => "是",
+    ];
 }

+ 70 - 4
app/Service/ProductService.php

@@ -22,6 +22,19 @@ use Illuminate\Support\Facades\DB;
  */
 class ProductService extends Service
 {
+    public function setIsEditUnitPrice($data,$user){
+        if($this->isEmpty($data,'id')) return [false,'请选择分类!'];
+        if(! isset($data['is_edit_unit_price'])) return [false,'请选择受否允许修改采购单价!'];
+        $is_edit_unit_price = $data['is_edit_unit_price'] > 0 ? 1 : 0;
+        $all_id = $this->getProductCateGory($data['id']);
+
+        ProductCategory::whereIn('id',$all_id)->update([
+            'is_edit_unit_price' => $is_edit_unit_price
+        ]);
+
+        return [true, ''];
+    }
+
     /**
      * 产品分类编辑
      * @param $data
@@ -93,11 +106,16 @@ class ProductService extends Service
     public function productCategoryList($data,$user){
         $model = ProductCategory::TopClear($user,$data);
         $model = $model->where('del_time',0)
-            ->select('title','id','parent_id')
+            ->select('title','id','parent_id','is_edit_unit_price')
             ->orderby('id','asc');
         if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
+        if(isset($data['is_edit_unit_price'])) $model->where('is_edit_unit_price', $data['is_edit_unit_price']);
 
         $list = $model->get()->toArray();
+        foreach ($list as $key => $value){
+            $list[$key]['is_edit_unit_price_title'] = ProductCategory::$is_edit_unit_price[$value['is_edit_unit_price']] ?? "";
+        }
+
         $list_tree = $list;
         if(! empty($list_tree)) {
             $list_tree = $this->makeTree(0,$list_tree);
@@ -231,6 +249,7 @@ class ProductService extends Service
             $model->mark = $data['mark'] ?? '';
             $model->state = $data['state'] ?? 0;
             $model->product_attribute = $data['product_attribute'] ?? 0;
+            $model->is_use = $data['is_use'] ?? Product::is_use_one;
             $model->save();
 
             $time = time();
@@ -353,6 +372,7 @@ class ProductService extends Service
             $model->crt_id = $user['id'];
             $model->depart_id = $data['depart_id'] ?? 0;
             $model->top_depart_id = $data['top_depart_id'] ?? 0;
+            $model->is_use = $data['is_use'] ?? Product::is_use_one;
             $model->save();
 
             $time = time();
@@ -474,6 +494,7 @@ class ProductService extends Service
         if(empty($customer)) return [false,'产品不存在或已被删除'];
         $customer = $customer->toArray();
         $customer['product_attribute_title'] = Product::$product_attribute[$customer['product_attribute']] ?? "";
+        $customer['is_use_title'] = Product::$is_use[$customer['is_use']] ?? "";
         $customer['product_category'] = ! empty($customer['product_category']) ? json_decode($customer['product_category'],true): [];
         $category = ProductCategory::where('id',$customer['product_category_id'])
             ->value('title');
@@ -567,6 +588,45 @@ class ProductService extends Service
         return [true, $customer];
     }
 
+    public function productListIndex($data,$user){
+        $model = Product::ProductClear($user,$data);
+        $model = $model->where('del_time',0)
+            ->select('title','id','product_category_id','code','size','unit','bar_code','retail_price','cost','state','crt_id','crt_time','mark','depart_id','top_depart_id','install_time','product_attribute','is_use')
+            ->orderby('product_attribute', 'desc')
+            ->orderby('id', 'desc');
+
+        if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
+        if(isset($data['state'])) $model->where('state', $data['state']);
+        if(isset($data['is_use'])) $model->where('is_use', $data['is_use']);
+        if(isset($data['product_attribute'])) $model->where('product_attribute', $data['product_attribute']);
+        if(! empty($data['product_category_id'])) $model->where('product_category_id', $data['product_category_id']);
+        if(! empty($data['category'])){
+            $id = $this->getProductCateGory($data['category']);
+            $model->whereIn('product_category_id', $id);
+        }
+        if(! empty($data['product_category'])) {
+            $product_category = ProductCategory::where('del_time',0)
+                ->where('title', 'LIKE', '%'.$data['product_category'].'%')
+                ->select('id')
+                ->get()->toArray();
+            $model->whereIn('product_category_id',array_unique(array_column($product_category,'id')));
+        }
+        if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
+        if(! empty($data['bar_code'])) $model->where('bar_code', 'LIKE', '%'.$data['bar_code'].'%');
+        if(! empty($data['size'])) $model->where('size', 'LIKE', '%'.$data['size'].'%');
+        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]);
+        }
+        if(! empty($data['product_id'])) $model->whereIn('id',$data['product_id']);
+
+        $list = $this->limit($model,'',$data);
+        $list = $this->fillData($list,$user,$data);
+
+        return [true, $list];
+    }
+
     /**
      * 产品列表
      * @param $data
@@ -576,7 +636,8 @@ class ProductService extends Service
     public function productList($data,$user){
         $model = Product::ProductClear($user,$data);
         $model = $model->where('del_time',0)
-            ->select('title','id','product_category_id','code','size','unit','bar_code','retail_price','cost','state','crt_id','crt_time','mark','depart_id','top_depart_id','install_time','product_attribute')
+            ->select('title','id','product_category_id','code','size','unit','bar_code','retail_price','cost','state','crt_id','crt_time','mark','depart_id','top_depart_id','install_time','product_attribute','is_use')
+            ->where('is_use', Product::is_use_one)
             ->orderby('product_attribute', 'desc')
             ->orderby('id', 'desc');
 
@@ -707,8 +768,10 @@ class ProductService extends Service
             ->pluck('emp_name','id')
             ->toArray();
         $category = ProductCategory::whereIn('id',array_unique(array_column($data['data'],'product_category_id')))
-            ->pluck('title','id')
+            ->select('title','id','is_edit_unit_price')
+            ->get()
             ->toArray();
+        $category = array_column($category,null,'id');
         $basic_map = BasicType::whereIn('id',array_unique(array_column($data['data'],'unit')))
             ->orWhere('type',BasicType::type_22)
             ->pluck('title','id')
@@ -747,8 +810,11 @@ class ProductService extends Service
             }
             $data['data'][$key]['product_price'] = $tmp;
             $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
+            $data['data'][$key]['is_use_title'] = Product::$is_use[$value['is_use']] ?? "";
             $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
-            $data['data'][$key]['product_category_name'] = $category[$value['product_category_id']] ?? '';
+            $category_tmp = $category[$value['product_category_id']] ?? [];
+            $data['data'][$key]['product_category_name'] = $category_tmp['title'] ?? '';
+            $data['data'][$key]['is_edit_unit_price'] = $category_tmp['is_edit_unit_price'] ?? 0;
             $data['data'][$key]['state_name'] = Product::$state[$value['state']] ?? '';
             $data['data'][$key]['unit_name'] = $basic_map[$value['unit']] ?? '';
             $data['data'][$key]['belong_to'] = $depart_map[$value['top_depart_id']] ?? '';

+ 3 - 1
routes/api.php

@@ -141,6 +141,7 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('contactsDetail', 'Api\ContactsController@contactsDetail');
 
     //产品分类
+    $route->any('setIsEditUnitPrice', 'Api\ProductController@setIsEditUnitPrice');
     $route->any('productCategoryList', 'Api\ProductController@productCategoryList');
     $route->any('productCategoryEdit', 'Api\ProductController@productCategoryEdit');
     $route->any('productCategoryAdd', 'Api\ProductController@productCategoryAdd');
@@ -148,7 +149,8 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('productCategoryList2', 'Api\ProductController@productCategoryList2');
 
     //产品名称
-    $route->any('productList', 'Api\ProductController@productList');
+    $route->any('productListIndex', 'Api\ProductController@productListIndex');//列表页
+    $route->any('productList', 'Api\ProductController@productList');//选择列表页
     $route->any('productEdit', 'Api\ProductController@productEdit')->middleware('OssFileDeal');
     $route->any('productAdd', 'Api\ProductController@productAdd')->middleware('OssFileDeal');
     $route->any('productDel', 'Api\ProductController@productDel')->middleware('OssFileDeal');