Просмотр исходного кода

做到产品加上自定义的钱

cqpCow 1 год назад
Родитель
Сommit
0baeda0384

+ 0 - 13
app/Model/DepartPriceName.php

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

+ 1 - 2
app/Service/CheckService.php

@@ -186,7 +186,7 @@ class CheckService extends Service
         $model->save();
 
         $pro = Product::whereIn('id',array_column($product,'product_id'))
-            ->select('cost','depart_price','id','retail_price')
+            ->select('cost','id','retail_price')
             ->get()->toArray();
         $pro = array_column($pro,null,'id');
 
@@ -205,7 +205,6 @@ class CheckService extends Service
                 'bar_code' => $value['bar_code'],
                 'cost' => $tmp['cost'] ?? 0,
                 'retail_price' => $tmp['retail_price'] ?? 0,
-                'depart_price' => $tmp['depart_price'] ?? 0,
             ];
         }
 

+ 0 - 2
app/Service/ConstructionService.php

@@ -99,7 +99,6 @@ class ConstructionService extends Service
                         'unit' => $value['unit'] ?? 0,
                         'bar_code' => $value['bar_code'] ?? '',
                         'cost' => $value['cost'] ?? 0,
-                        'depart_price' => $value['depart_price'] ?? 0,
                         'retail_price' => $value['retail_price'] ?? 0,
                         'mark' => $value['mark'] ?? '',
                         'crt_time' => $time,
@@ -199,7 +198,6 @@ class ConstructionService extends Service
                         'unit' => $value['unit'] ?? 0,
                         'bar_code' => $value['bar_code'] ?? '',
                         'cost' => $value['cost'] ?? 0,
-                        'depart_price' => $value['depart_price'] ?? 0,
                         'retail_price' => $value['retail_price'] ?? 0,
                         'mark' => $value['mark'] ?? '',
                         'crt_time' => $time,

+ 16 - 14
app/Service/EmployeeService.php

@@ -1122,6 +1122,8 @@ class EmployeeService extends Service
             ->where('a.employee_id',$employee_id)
             ->where('b.is_use',Depart::IS_UES)
             ->select('a.depart_id','b.is_main','b.parent_id')
+            ->orderBy('b.parent_id','asc')
+            ->orderBy('b.is_main','desc')
             ->orderBy('a.depart_id','asc')
             ->get()->toArray();
 
@@ -1132,17 +1134,22 @@ class EmployeeService extends Service
             $depart_map = array_column($list,null,'id');
             foreach ($depart as $value){
                 if($value['parent_id'] == 0){//顶级
-                    $tmp['depart_id'] = $value['depart_id'];
-                    $tmp['is_main'] = $value['is_main'];
-                    $top[] = $tmp;
+                    $top[$value['depart_id']] = [
+                        'depart_id' => $value['depart_id'],
+                        'is_main' => $value['is_main'],
+                        'basic_type_id' => $value['basic_type_id'],
+                    ];
                     $map[$value['depart_id']] = $value['depart_id'];
                     if(! empty($tmp['is_main']) && ! $is_all_depart) $is_all_depart = 1;
                 }else{
                     $t = self::getTopParentId($value['depart_id'],$list);
                     if($t && isset($depart_map[$t])) {
-                        $tmp['depart_id'] = $depart_map[$t]['id'];
-                        $tmp['is_main'] = $depart_map[$t]['is_main'];
-                        $top[] = $tmp;
+                        $t_tmp = $depart_map[$t] ?? [];
+                        $top[$t_tmp['id']] = [
+                            'depart_id' => $t_tmp['id'],
+                            'is_main' => $t_tmp['is_main'],
+                            'basic_type_id' => $t_tmp['basic_type_id'],
+                        ];
                         $map[$value['depart_id']] = $t;
                         if(! empty($tmp['is_main']) && $value['is_main'] &&! $is_all_depart) $is_all_depart = 1;
                     }
@@ -1207,17 +1214,12 @@ class EmployeeService extends Service
             $depart_map = array_column($list,null,'id');
             foreach ($depart as $value){
                 if($value['parent_id'] == 0){//顶级
-                    $tmp['depart_id'] = $value['depart_id'];
-                    $tmp['is_main'] = $value['is_main'];
-                    if(! empty($tmp['is_main']) && ! $is_main) $is_main = 1;
+                    if(! empty($value['is_main']) && ! $is_main) $is_main = 1;
                 }else{
                     $t = self::getTopParentId($value['depart_id'],$list);
                     if($t && isset($depart_map[$t])) {
-                        $tmp['depart_id'] = $depart_map[$t]['id'];
-                        $tmp['is_main'] = $depart_map[$t]['is_main'];
-                        $top[] = $tmp;
-                        $map[$value['depart_id']] = $t;
-                        if(! empty($tmp['is_main']) && ! $is_main) $is_main = 1;
+                        $tmp_is_main = $depart_map[$t]['is_main'] ?? 0;
+                        if(! empty($tmp_is_main) && ! $is_main) $is_main = 1;
                     }
                 }
             }

+ 1 - 1
app/Service/InvoiceOrderService.php

@@ -160,7 +160,7 @@ class InvoiceOrderService extends Service
             ->toArray();
         $info = InvoiceOrderInfo::where('del_time',0)
             ->where('order_number',$data['order_number'])
-            ->select('id','order_number','depart_id','product_id','number','mark','title','code','size','unit','bar_code','invoice_id')
+            ->select('id','order_number','storehouse_id','product_id','number','mark','title','code','size','unit','bar_code','invoice_id')
             ->get()->toArray();
         $order['product'] = $info;
         $order['send_name'] = $emp_map[$order['send']] ?? '';

+ 40 - 14
app/Service/ProductService.php

@@ -174,7 +174,6 @@ class ProductService extends Service
             $model->unit = $data['unit'] ?? 0;
             $model->bar_code = $data['bar_code'] ?? '';
             $model->cost = $data['cost'] ?? 0;
-            $model->depart_price = $data['depart_price'] ?? 0;
             $model->retail_price = $data['retail_price'] ?? 0;
             $model->mark = $data['mark'] ?? '';
             $model->state = $data['state'] ?? 0;
@@ -264,7 +263,7 @@ class ProductService extends Service
                     $insert[] = [
                         'product_id' => $model->id,
                         'basic_type_id' => $value['basic_type_id'],
-                        'grade' => $value['grade'],
+                        'price' => $value['price'],
                         'crt_time' => $time,
                     ];
                 }
@@ -301,7 +300,6 @@ class ProductService extends Service
             $model->unit = $data['unit'] ?? 0;
             $model->bar_code = $data['bar_code'] ?? '';
             $model->cost = $data['cost'] ?? 0;
-            $model->depart_price = $data['depart_price'] ?? 0;
             $model->retail_price = $data['retail_price'] ?? 0;
             $model->mark = $data['mark'] ?? '';
             $model->state = $data['state'] ?? 0;
@@ -379,7 +377,7 @@ class ProductService extends Service
                     $insert[] = [
                         'product_id' => $model->id,
                         'basic_type_id' => $value['basic_type_id'],
-                        'grade' => $value['grade'],
+                        'price' => $value['price'],
                         'crt_time' => $time,
                     ];
                 }
@@ -442,7 +440,6 @@ class ProductService extends Service
      */
     public function productDetail($data,$user){
         if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
-
         $customer = Product::where('del_time',0)
             ->where('id',$data['id'])
             ->first();
@@ -459,17 +456,24 @@ class ProductService extends Service
 
         $detail = ProductPriceDetail::where('del_time',0)
             ->where('product_id',$data['id'])
-            ->select('product_id','basic_type_id','grade')
+            ->select('product_id','basic_type_id','price')
             ->get()->toArray();
         $title_map = BasicType::whereIn('id',array_column($detail,'basic_type_id'))
             ->pluck('title','id')
             ->toArray();
+        //是否总公司
+        $is_main = EmployeeService::isMain($user['id']);
         $customer['product_price'] = [];
+        //展示金额
         foreach ($detail as $value){
+            if(! $is_main){
+                $top_depart = $user['depart_top'][0] ?? [];
+                if($top_depart['basic_type_id'] != $value['basic_type_id']) continue;
+            }
             $customer['product_price'][] = [
                 'basic_type_id' => $value['basic_type_id'],
                 'basic_type_title' => $title_map[$value['basic_type_id']] ?? '',
-                'grade' => $value['grade'],
+                'price' => $value['price'],
             ];
         }
 
@@ -534,7 +538,7 @@ class ProductService extends Service
     public function productList($data,$user){
         $model = new Product(['userData' => $user]);
         $model = $model->where('del_time',0)
-            ->select('title','id','product_category_id','code','size','unit','bar_code','retail_price','cost','depart_price','state','crt_id','crt_time','mark','depart_id','top_depart_id')
+            ->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')
             ->orderby('id', 'desc');
 
         //getALL传入后无视设置范围
@@ -553,7 +557,7 @@ class ProductService extends Service
         if(isset($data['state'])) $model->where('state', $data['state']);
 
         $list = $this->limit($model,'',$data);
-        $list = $this->fillData($list);
+        $list = $this->fillData($list,$user);
 
         return [true, $list];
     }
@@ -571,9 +575,6 @@ class ProductService extends Service
         if(empty($data['cost'])) return [false,'成本不能为空'];
         $res = $this->checkNumber($data['cost']);
         if(! $res) return [false,'成本请输入不超过两位小数并且大于0的数值'];
-        if(empty($data['depart_price'])) return [false,'分社价格不能为空'];
-        $res = $this->checkNumber($data['depart_price']);
-        if(! $res) return [false,'分社价格请输入不超过两位小数并且大于0的数值'];
         if(empty($data['retail_price'])) return [false,'零售价不能为空'];
         $res = $this->checkNumber($data['retail_price']);
         if(! $res) return [false,'零售价格请输入不超过两位小数并且大于0的数值'];
@@ -603,7 +604,7 @@ class ProductService extends Service
      * @param $data
      * @return array
      */
-    public function fillData($data){
+    public function fillData($data, $user){
         if(empty($data['data'])) return $data;
 
         $emp = Employee::whereIn('id',array_unique(array_column($data['data'],'crt_id')))
@@ -612,11 +613,36 @@ class ProductService extends Service
         $category = ProductCategory::whereIn('id',array_unique(array_column($data['data'],'product_category_id')))
             ->pluck('title','id')
             ->toArray();
-        $basic_map = BasicType::whereIn('id',array_unique(array_column($data['data'],'unit')))
+        $detail = ProductPriceDetail::where('del_time',0)
+            ->where('product_id',array_unique(array_column($data['data'],'id')))
+            ->select('product_id','basic_type_id','price')
+            ->get()->toArray();
+        $basic_map = BasicType::whereIn('id',array_unique(array_merge_recursive(array_column($data['data'],'unit'),array_column($detail,'basic_type_id'))))
             ->pluck('title','id')
             ->toArray();
+        $detail_map = [];
+        foreach ($detail as $value){
+            $detail_map[$value['product_id']] = $value;
+        }
 
+        //是否总公司
+        $is_main = EmployeeService::isMain($user['id']);
+        $top_depart = $user['depart_top'][0] ?? [];
         foreach ($data['data'] as $key => $value){
+            $tmp = [];
+            if(isset($detail_map[$value['id']])){
+                $d = $detail_map[$value['id']];
+                foreach ($d as $v){
+                    //不是总公司 不是公司设置的金额 就不展示
+                    if(! $is_main && ($top_depart['basic_type_id'] != $v['basic_type_id'])) continue;
+                    $tmp[] = [
+                        'basic_type_id' => $value['basic_type_id'],
+                        'basic_type_title' => $basic_map[$value['basic_type_id']] ?? '',
+                        'price' => $value['price'],
+                    ];
+                }
+            }
+            $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]['crt_name'] = $emp[$value['crt_id']] ?? '';
             $data['data'][$key]['product_category_name'] = $category[$value['product_category_id']] ?? '';

+ 1 - 1
app/Service/PurchaseOrderService.php

@@ -165,7 +165,7 @@ class PurchaseOrderService extends Service
 
         $info = PurchaseOrderInfo::where('del_time',0)
             ->where('order_number',$data['order_number'])
-            ->select('id','order_number','depart_id','product_id','number','mark','price','title','size','code','bar_code','purchase_order_id')
+            ->select('id','order_number','storehouse_id','product_id','number','mark','price','title','size','code','bar_code','purchase_order_id')
             ->get()->toArray();
         $order['product'] = $info;
         $order['crt_name'] = $emp_map[$order['crt_id']] ?? '';

+ 1 - 5
app/Service/ReturnExchangeOrderService.php

@@ -45,7 +45,6 @@ class ReturnExchangeOrderService extends Service
                         'unit' => $value['unit'] ?? 0,
                         'bar_code' => $value['bar_code'] ?? '',
                         'cost' => $value['cost'] ?? 0,
-                        'depart_price' => $value['depart_price'] ?? 0,
                         'retail_price' => $value['retail_price'] ?? 0,
                         'return_or_exchange' => ReturnExchangeOrderProductInfo::type_one,
                         'crt_time' => $time,
@@ -69,7 +68,6 @@ class ReturnExchangeOrderService extends Service
                         'unit' => $value['unit'] ?? 0,
                         'bar_code' => $value['bar_code'] ?? '',
                         'cost' => $value['cost'] ?? 0,
-                        'depart_price' => $value['depart_price'] ?? 0,
                         'retail_price' => $value['retail_price'] ?? 0,
                         'return_or_exchange' => ReturnExchangeOrderProductInfo::type_two,
                         'crt_time' => $time,
@@ -154,7 +152,6 @@ class ReturnExchangeOrderService extends Service
                         'unit' => $value['unit'] ?? 0,
                         'bar_code' => $value['bar_code'] ?? '',
                         'cost' => $value['cost'] ?? 0,
-                        'depart_price' => $value['depart_price'] ?? 0,
                         'retail_price' => $value['retail_price'] ?? 0,
                         'return_or_exchange' => ReturnExchangeOrderProductInfo::type_one,
                         'crt_time' => $time,
@@ -178,7 +175,6 @@ class ReturnExchangeOrderService extends Service
                         'unit' => $value['unit'] ?? 0,
                         'bar_code' => $value['bar_code'] ?? '',
                         'cost' => $value['cost'] ?? 0,
-                        'depart_price' => $value['depart_price'] ?? 0,
                         'retail_price' => $value['retail_price'] ?? 0,
                         'return_or_exchange' => ReturnExchangeOrderProductInfo::type_two,
                         'crt_time' => $time,
@@ -244,7 +240,7 @@ class ReturnExchangeOrderService extends Service
         $order['product_one'] = $order['product_two'] = $order['depart'] = $order['employee'] = [];
         $info = ReturnExchangeOrderProductInfo::where('del_time',0)
             ->where('return_exchange_id',$data['id'])
-            ->select('id','return_exchange_id','product_id','product_id','number','mark','title','code','size','unit','bar_code','cost','depart_price','retail_price','return_or_exchange')
+            ->select('id','return_exchange_id','product_id','product_id','number','mark','title','code','size','unit','bar_code','cost','retail_price','return_or_exchange')
             ->get()->toArray();
         foreach ($info as $value){
             if($value['return_or_exchange'] == ReturnExchangeOrderProductInfo::type_one){

+ 2 - 4
app/Service/SalesOrderService.php

@@ -118,7 +118,7 @@ class SalesOrderService extends Service
 
             if(! empty($data['product'])){
                 $pro = Product::whereIn('id',array_column($data['product'],'product_id'))
-                    ->select('bar_code','code','cost','depart_price','size','title','id','retail_price','unit','top_depart_id')
+                    ->select('bar_code','code','cost','size','title','id','retail_price','unit','top_depart_id')
                     ->get()->toArray();
                 $pro = array_column($pro,null,'id');
                 $insert = [];
@@ -134,7 +134,6 @@ class SalesOrderService extends Service
                         'unit' => $tmp['unit'] ?? 0,
                         'bar_code' => $tmp['bar_code'] ?? '',
                         'cost' => $tmp['cost'] ?? 0,
-                        'depart_price' => $tmp['depart_price'] ?? 0,
                         'retail_price' => $tmp['retail_price'] ?? 0,
                         'mark' => $value['mark'] ?? '',
                         'crt_time' => $time,
@@ -244,7 +243,7 @@ class SalesOrderService extends Service
 
             if(! empty($data['product'])){
                 $pro = Product::whereIn('id',array_column($data['product'],'product_id'))
-                    ->select('bar_code','code','cost','depart_price','size','title','id','retail_price','unit','top_depart_id')
+                    ->select('bar_code','code','cost','size','title','id','retail_price','unit','top_depart_id')
                     ->get()->toArray();
                 $pro = array_column($pro,null,'id');
                 $insert = [];
@@ -260,7 +259,6 @@ class SalesOrderService extends Service
                         'unit' => $tmp['unit'] ?? 0,
                         'bar_code' => $tmp['bar_code'] ?? '',
                         'cost' => $tmp['cost'] ?? 0,
-                        'depart_price' => $tmp['depart_price'] ?? 0,
                         'retail_price' => $tmp['retail_price'] ?? 0,
                         'mark' => $value['mark'] ?? '',
                         'crt_time' => $time,