|
@@ -13,12 +13,14 @@ use App\Model\ProductCategory;
|
|
use App\Model\ProductInfo;
|
|
use App\Model\ProductInfo;
|
|
use App\Model\ProductIntroduction;
|
|
use App\Model\ProductIntroduction;
|
|
use App\Model\ProductInventoryOfTop;
|
|
use App\Model\ProductInventoryOfTop;
|
|
|
|
+use App\Model\ProductItemCodeMessage;
|
|
use App\Model\ProductPriceDetail;
|
|
use App\Model\ProductPriceDetail;
|
|
use App\Model\Role;
|
|
use App\Model\Role;
|
|
use App\Model\RoleMenuButton;
|
|
use App\Model\RoleMenuButton;
|
|
use App\Model\SeeRange;
|
|
use App\Model\SeeRange;
|
|
use App\Model\Storehouse;
|
|
use App\Model\Storehouse;
|
|
use App\Model\U8Job;
|
|
use App\Model\U8Job;
|
|
|
|
+use Illuminate\Support\Arr;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -630,6 +632,13 @@ class ProductService extends Service
|
|
|
|
|
|
// $model->where('title', 'LIKE', '%'.$data['title'].'%');
|
|
// $model->where('title', 'LIKE', '%'.$data['title'].'%');
|
|
}
|
|
}
|
|
|
|
+ if(! empty($data['product_item_code_title'])){
|
|
|
|
+ $item_code = ProductItemCodeMessage::where('del_time',0)
|
|
|
|
+ ->where('title', 'LIKE', '%'.$data['product_item_code_title'].'%')
|
|
|
|
+ ->select('item_code')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+ $model->whereIn('item_code', array_column($item_code,'item_code'));
|
|
|
|
+ }
|
|
if(isset($data['state'])) $model->where('state', $data['state']);
|
|
if(isset($data['state'])) $model->where('state', $data['state']);
|
|
if(isset($data['is_use'])) $model->where('is_use', $data['is_use']);
|
|
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(isset($data['product_attribute'])) $model->where('product_attribute', $data['product_attribute']);
|
|
@@ -773,6 +782,8 @@ class ProductService extends Service
|
|
public function productRule(&$data, $user, $is_add = true){
|
|
public function productRule(&$data, $user, $is_add = true){
|
|
if(empty($data['title'])) return [false,'产品名称不能为空'];
|
|
if(empty($data['title'])) return [false,'产品名称不能为空'];
|
|
if(empty($data['product_category_id'])) return [false,'产品分类不能为空'];
|
|
if(empty($data['product_category_id'])) return [false,'产品分类不能为空'];
|
|
|
|
+ if(empty($data['product_category'])) return [false,'产品分类树结构不能为空'];
|
|
|
|
+ $data['product_category'] = json_encode($data['product_category']);
|
|
if(empty($data['code'])) return [false,'产品编码不能为空'];
|
|
if(empty($data['code'])) return [false,'产品编码不能为空'];
|
|
if(! isset($data['cost'])) return [false, '请填写成本'];
|
|
if(! isset($data['cost'])) return [false, '请填写成本'];
|
|
if(! isset($data['retail_price'])) return [false, '请填写零售价'];
|
|
if(! isset($data['retail_price'])) return [false, '请填写零售价'];
|
|
@@ -792,7 +803,6 @@ class ProductService extends Service
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if(! empty($data['product_category'])) $data['product_category'] = json_encode($data['product_category']);
|
|
|
|
|
|
|
|
//所属部门 以及 顶级部门
|
|
//所属部门 以及 顶级部门
|
|
if(empty($data['depart_id'])) {
|
|
if(empty($data['depart_id'])) {
|
|
@@ -868,6 +878,11 @@ class ProductService extends Service
|
|
$product_fs = [];
|
|
$product_fs = [];
|
|
if(! empty($search['fs_price_get'])) $product_fs = $this->getProductPriceDetail(['id' => $product_id], $user);
|
|
if(! empty($search['fs_price_get'])) $product_fs = $this->getProductPriceDetail(['id' => $product_id], $user);
|
|
|
|
|
|
|
|
+ //商品编码关联信息
|
|
|
|
+ $item_code_map = ProductItemCodeMessage::where('del_time',0)
|
|
|
|
+ ->whereIn('item_code', array_column($data['data'],'item_code'))
|
|
|
|
+ ->pluck('title','item_code')
|
|
|
|
+ ->toArray();
|
|
foreach ($data['data'] as $key => $value){
|
|
foreach ($data['data'] as $key => $value){
|
|
$tmp = [];
|
|
$tmp = [];
|
|
if(isset($detail_map[$value['id']])){
|
|
if(isset($detail_map[$value['id']])){
|
|
@@ -907,6 +922,7 @@ class ProductService extends Service
|
|
$data['data'][$key]['stock'] = $stock_map[$value['id']] ?? (object)[];
|
|
$data['data'][$key]['stock'] = $stock_map[$value['id']] ?? (object)[];
|
|
//成本
|
|
//成本
|
|
$data['data'][$key]['cost_show'] = $value['cost'];
|
|
$data['data'][$key]['cost_show'] = $value['cost'];
|
|
|
|
+ $data['data'][$key]['product_item_code_title'] = $item_code_map[$value['item_code']] ?? "";
|
|
}
|
|
}
|
|
|
|
|
|
return $data;
|
|
return $data;
|
|
@@ -1277,10 +1293,17 @@ class ProductService extends Service
|
|
//当前门店
|
|
//当前门店
|
|
$top_depart = $user['depart_top'][0] ?? [];
|
|
$top_depart = $user['depart_top'][0] ?? [];
|
|
|
|
|
|
|
|
+ //库存
|
|
$stock = ProductInventoryOfTop::where('del_time',0)
|
|
$stock = ProductInventoryOfTop::where('del_time',0)
|
|
->whereIn('product_id',$product_id)
|
|
->whereIn('product_id',$product_id)
|
|
->pluck('number','product_id')
|
|
->pluck('number','product_id')
|
|
->toArray();
|
|
->toArray();
|
|
|
|
+
|
|
|
|
+ //商品编码关联信息
|
|
|
|
+ $item_code_map = ProductItemCodeMessage::where('del_time',0)
|
|
|
|
+ ->whereIn('item_code', array_column($data['data'],'item_code'))
|
|
|
|
+ ->pluck('title','item_code')
|
|
|
|
+ ->toArray();
|
|
foreach ($data['data'] as $key => $value){
|
|
foreach ($data['data'] as $key => $value){
|
|
$arr = json_decode($value['product_category'], true);
|
|
$arr = json_decode($value['product_category'], true);
|
|
$arr = array_flip($arr);
|
|
$arr = array_flip($arr);
|
|
@@ -1301,6 +1324,9 @@ class ProductService extends Service
|
|
$data['data'][$key]['product_attribute_title'] = Product::$product_attribute[$value['product_attribute']] ?? "";
|
|
$data['data'][$key]['product_attribute_title'] = Product::$product_attribute[$value['product_attribute']] ?? "";
|
|
$data['data'][$key]['stock'] = $this->returnStock($stock, $value);
|
|
$data['data'][$key]['stock'] = $this->returnStock($stock, $value);
|
|
$data['data'][$key]['unit_title'] = $basic_map[$value['unit']] ?? "";
|
|
$data['data'][$key]['unit_title'] = $basic_map[$value['unit']] ?? "";
|
|
|
|
+ $title = $value['title'];
|
|
|
|
+ if(! empty($item_code_map[$value['item_code']])) $title = $item_code_map[$value['item_code']];
|
|
|
|
+ $data['data'][$key]['title'] = $title;
|
|
}
|
|
}
|
|
|
|
|
|
return $data;
|
|
return $data;
|
|
@@ -1356,6 +1382,131 @@ class ProductService extends Service
|
|
return [true, $product];
|
|
return [true, $product];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function productUpdateProductBasicInfo($data){
|
|
|
|
+ $time = time();
|
|
|
|
+ list($status, $msg) = $this->productUpdateProductBasicInfoRule($data,$time);
|
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
|
+
|
|
|
|
+ //产品id 主表更新信息 子表插入信息 子表是否参与更新
|
|
|
|
+ list($product_id,$update,$insert_detail,$update_detail_bool) = $msg;
|
|
|
|
+// dd($product_id,$update,$insert_detail,$update_detail_bool);
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
+
|
|
|
|
+ if(! empty($update)){
|
|
|
|
+ foreach ($product_id as $p_id){
|
|
|
|
+ Product::where('id',$p_id)
|
|
|
|
+ ->update($update);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if($update_detail_bool){
|
|
|
|
+ ProductPriceDetail::where('del_time',0)
|
|
|
|
+ ->whereIn('product_id',$product_id)
|
|
|
|
+ ->update(['del_time' => $time]);
|
|
|
|
+
|
|
|
|
+ if(! empty($insert_detail)) ProductPriceDetail::insert($insert_detail);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DB::commit();
|
|
|
|
+ }catch (\Throwable $exception){
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ return [false, $exception->getMessage()];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return [true, ''];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function productUpdateProductBasicInfoRule($data,$time){
|
|
|
|
+ if(empty($data['product_id'])) return [false, '产品ID不能为空'];
|
|
|
|
+ $product = Product::where('del_time',0)
|
|
|
|
+ ->whereIn('id',$data['product_id'])
|
|
|
|
+ ->select('id')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+ if(empty($product)) return [false, '产品不存在或已被删除'];
|
|
|
|
+ $product = array_column($product,'id');
|
|
|
|
+
|
|
|
|
+ // 产品分类 单位 成本 各分社价 商品编码 产品属性
|
|
|
|
+ $update = $update_detail = [];
|
|
|
|
+ if(! empty($data['product_category_id'])){
|
|
|
|
+ $update['product_category_id'] = $data['product_category_id'];
|
|
|
|
+ if(empty($data['product_category'])) return [false,'产品分类树结构不能为空'];
|
|
|
|
+ $product_category = json_encode($data['product_category']);
|
|
|
|
+ $update['product_category'] = $product_category;
|
|
|
|
+ }
|
|
|
|
+ if(Arr::has($data,'unit')) $update['unit'] = $data['unit'] ?? 0;
|
|
|
|
+ if(Arr::has($data,'cost')){
|
|
|
|
+ $cost = $data['cost'] ?? 0;
|
|
|
|
+ $res = $this->checkNumber($cost);
|
|
|
|
+ if(! $res) return [false,'成本请输入不超过两位小数并且大于等于0的数值'];
|
|
|
|
+ $update['cost'] = $cost;
|
|
|
|
+ }
|
|
|
|
+ if(Arr::has($data,'item_code')) $update['item_code'] = $data['item_code'] ?? "";
|
|
|
|
+ if(Arr::has($data,'product_attribute')) $update['product_attribute'] = $data['product_attribute'] ?? 0;
|
|
|
|
+ if(! empty($data['product_price'])){
|
|
|
|
+ $map = BasicType::whereIn('id',array_column($data['product_price'],'basic_type_id'))
|
|
|
|
+ ->pluck('title','id')
|
|
|
|
+ ->toArray();
|
|
|
|
+ foreach ($data['product_price'] as $value){
|
|
|
|
+ $price = $value['price'] ?? 0;
|
|
|
|
+ $tmp = $map[$value['basic_type_id']] ?? '';
|
|
|
|
+ if(! $tmp) return [false, '分社价格错误'];
|
|
|
|
+ $res = $this->checkNumber($price);
|
|
|
|
+ if(! $res) return [false, $tmp . '请输入不超过两位小数并且大于0的数值'];
|
|
|
|
+ $update_detail[] = [
|
|
|
|
+ 'product_id' => 0,
|
|
|
|
+ 'basic_type_id' => $value['basic_type_id'],
|
|
|
|
+ 'price' => $price,
|
|
|
|
+ 'crt_time' => $time,
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(empty($update) && empty($update_detail)) return [false, '暂无更新'];
|
|
|
|
+ $update_detail_bool = false;
|
|
|
|
+
|
|
|
|
+ //详情信息
|
|
|
|
+ $insert_detail = [];
|
|
|
|
+ if(! empty($update_detail)){
|
|
|
|
+ $update_detail_bool = true;
|
|
|
|
+ foreach ($product as $p_id){
|
|
|
|
+ foreach ($update_detail as $detail){
|
|
|
|
+ $detail['product_id'] = $p_id;
|
|
|
|
+ $insert_detail[] = $detail;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return [true, [$product, $update, $insert_detail, $update_detail_bool]];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function productUpdateByItemCode($data){
|
|
|
|
+ if(empty($data['item_code'])) return [false, "商品编码不能为空"];
|
|
|
|
+
|
|
|
|
+ $title = $data['title'] ?? '';
|
|
|
|
+ try {
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
+
|
|
|
|
+ $time = time();
|
|
|
|
+
|
|
|
|
+ ProductItemCodeMessage::where('del_time',0)
|
|
|
|
+ ->where('item_code', $data['item_code'])
|
|
|
|
+ ->update(['del_time' => $time]);
|
|
|
|
+
|
|
|
|
+ ProductItemCodeMessage::insert([
|
|
|
|
+ 'item_code' => $data['item_code'],
|
|
|
|
+ 'title' => $title,
|
|
|
|
+ ]);
|
|
|
|
+
|
|
|
|
+ DB::commit();
|
|
|
|
+ }catch (\Throwable $exception){
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ return [false, $exception->getMessage()];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return [true, ''];
|
|
|
|
+ }
|
|
|
|
+
|
|
public function getProductByItemCode($item_code,$user){
|
|
public function getProductByItemCode($item_code,$user){
|
|
if(empty($item_code)) return [];
|
|
if(empty($item_code)) return [];
|
|
|
|
|