|
@@ -7,6 +7,7 @@ use App\Model\ConstructionProductInfo;
|
|
|
use App\Model\InvoiceOrder;
|
|
|
use App\Model\InvoiceOrderInfo;
|
|
|
use App\Model\Product;
|
|
|
+use App\Model\ProductCategory;
|
|
|
use App\Model\ProductInventory;
|
|
|
use App\Model\Setting;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
@@ -182,4 +183,39 @@ class ProductInventoryService extends Service
|
|
|
|
|
|
return [true,''];
|
|
|
}
|
|
|
+
|
|
|
+ //现存量
|
|
|
+ public function productInventoryList($data,$user){
|
|
|
+ $model = ProductInventory::from('product_inventory as a')
|
|
|
+ ->join('product as b','b.id','a.product_id')
|
|
|
+ ->select('a.product_id','a.id','a.number','b.title','b.code','b.product_category_id','b.unit','b.bar_code','a.crt_time')
|
|
|
+ ->orderby('a.crt_time', 'desc');
|
|
|
+ if(! empty($data['product_category_id'])) $model->where("b.product_category_id", $data['product_category_id']);
|
|
|
+ if(!empty($data['code'])) $model->where('b.code', 'LIKE', '%'.$data['code'].'%');
|
|
|
+ if(! empty($data['product_id'])) $model->where('a.product_id', $data['product_id']);
|
|
|
+ if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
|
|
|
+ $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
|
|
|
+ $model->whereBetween('a.crt_time',[$return[0],$return[1]]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $list = $this->limit($model,'',$data);
|
|
|
+ $list = $this->fillListData($list);
|
|
|
+
|
|
|
+ return [true, $list];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function fillListData($data){
|
|
|
+ if(empty($data['data'])) return $data;
|
|
|
+
|
|
|
+ $category = ProductCategory::whereIn('id',array_column($data['data'],'product_category_id'))
|
|
|
+ ->pluck('title','id')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ foreach ($data['data'] as $key => $value){
|
|
|
+ $data['data'][$key]['product_category_title'] = $category[$value['product_category_id']] ?? '';
|
|
|
+ $data['data'][$key]['crt_time'] = $value['crt_time'] ? date("Y-m-d H:i:s",$value['crt_time']):'';
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
}
|