|
@@ -10,6 +10,7 @@ use App\Model\ProductCategory;
|
|
use App\Model\ProductInfo;
|
|
use App\Model\ProductInfo;
|
|
use App\Model\ProductIntroduction;
|
|
use App\Model\ProductIntroduction;
|
|
use App\Model\ProductInventory;
|
|
use App\Model\ProductInventory;
|
|
|
|
+use App\Model\ProductPriceDetail;
|
|
use App\Model\ProductRange;
|
|
use App\Model\ProductRange;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
@@ -159,7 +160,7 @@ class ProductService extends Service
|
|
* @return array
|
|
* @return array
|
|
*/
|
|
*/
|
|
public function productEdit($data,$user){
|
|
public function productEdit($data,$user){
|
|
- list($status,$msg) = $this->productRule($data,false);
|
|
|
|
|
|
+ list($status,$msg) = $this->productRule($data, $user, false);
|
|
if(!$status) return [$status,$msg];
|
|
if(!$status) return [$status,$msg];
|
|
|
|
|
|
try {
|
|
try {
|
|
@@ -253,6 +254,23 @@ class ProductService extends Service
|
|
ProductRange::insert($insert);
|
|
ProductRange::insert($insert);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ ProductPriceDetail::where('del_time',0)
|
|
|
|
+ ->where('product_id',$data['id'])
|
|
|
|
+ ->update(['del_time' => $time]);
|
|
|
|
+
|
|
|
|
+ if(! empty($data['product_price'])){
|
|
|
|
+ $insert = [];
|
|
|
|
+ foreach ($data['product_price'] as $value){
|
|
|
|
+ $insert[] = [
|
|
|
|
+ 'product_id' => $model->id,
|
|
|
|
+ 'basic_type_id' => $value['basic_type_id'],
|
|
|
|
+ 'grade' => $value['grade'],
|
|
|
|
+ 'crt_time' => $time,
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ ProductPriceDetail::insert($insert);
|
|
|
|
+ }
|
|
|
|
+
|
|
DB::commit();
|
|
DB::commit();
|
|
}catch (\Exception $exception){
|
|
}catch (\Exception $exception){
|
|
DB::rollBack();
|
|
DB::rollBack();
|
|
@@ -269,7 +287,7 @@ class ProductService extends Service
|
|
* @return array
|
|
* @return array
|
|
*/
|
|
*/
|
|
public function productAdd($data,$user){
|
|
public function productAdd($data,$user){
|
|
- list($status,$msg) = $this->productRule($data);
|
|
|
|
|
|
+ list($status,$msg) = $this->productRule($data, $user);
|
|
if(!$status) return [$status,$msg];
|
|
if(!$status) return [$status,$msg];
|
|
|
|
|
|
try {
|
|
try {
|
|
@@ -288,6 +306,8 @@ class ProductService extends Service
|
|
$model->mark = $data['mark'] ?? '';
|
|
$model->mark = $data['mark'] ?? '';
|
|
$model->state = $data['state'] ?? 0;
|
|
$model->state = $data['state'] ?? 0;
|
|
$model->crt_id = $user['id'];
|
|
$model->crt_id = $user['id'];
|
|
|
|
+ $model->depart_id = $data['depart_id'] ?? 0;
|
|
|
|
+ $model->top_depart_id = $data['top_depart_id'] ?? 0;
|
|
$model->save();
|
|
$model->save();
|
|
|
|
|
|
$time = time();
|
|
$time = time();
|
|
@@ -353,6 +373,19 @@ class ProductService extends Service
|
|
ProductRange::insert($insert);
|
|
ProductRange::insert($insert);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if(! empty($data['product_price'])){
|
|
|
|
+ $insert = [];
|
|
|
|
+ foreach ($data['product_price'] as $value){
|
|
|
|
+ $insert[] = [
|
|
|
|
+ 'product_id' => $model->id,
|
|
|
|
+ 'basic_type_id' => $value['basic_type_id'],
|
|
|
|
+ 'grade' => $value['grade'],
|
|
|
|
+ 'crt_time' => $time,
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ ProductPriceDetail::insert($insert);
|
|
|
|
+ }
|
|
|
|
+
|
|
DB::commit();
|
|
DB::commit();
|
|
}catch (\Exception $exception){
|
|
}catch (\Exception $exception){
|
|
DB::rollBack();
|
|
DB::rollBack();
|
|
@@ -388,6 +421,10 @@ class ProductService extends Service
|
|
->where('product_id',$data['id'])
|
|
->where('product_id',$data['id'])
|
|
->update(['del_time' => $time]);
|
|
->update(['del_time' => $time]);
|
|
|
|
|
|
|
|
+ ProductPriceDetail::where('del_time',0)
|
|
|
|
+ ->where('product_id',$data['id'])
|
|
|
|
+ ->update(['del_time' => $time]);
|
|
|
|
+
|
|
DB::commit();
|
|
DB::commit();
|
|
}catch (\Exception $exception){
|
|
}catch (\Exception $exception){
|
|
DB::rollBack();
|
|
DB::rollBack();
|
|
@@ -418,13 +455,27 @@ class ProductService extends Service
|
|
$in = ProductIntroduction::where('del_time',0)
|
|
$in = ProductIntroduction::where('del_time',0)
|
|
->where('product_id',$data['id'])
|
|
->where('product_id',$data['id'])
|
|
->first();
|
|
->first();
|
|
- if($in) $customer['introduction'] = $in->introduction;
|
|
|
|
|
|
+ if(! empty($in)) $customer['introduction'] = $in->introduction;
|
|
|
|
+
|
|
|
|
+ $detail = ProductPriceDetail::where('del_time',0)
|
|
|
|
+ ->where('product_id',$data['id'])
|
|
|
|
+ ->select('product_id','basic_type_id','grade')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+ $title_map = BasicType::whereIn('id',array_column($detail,'basic_type_id'))
|
|
|
|
+ ->pluck('title','id')
|
|
|
|
+ ->toArray();
|
|
|
|
+ $customer['product_price'] = [];
|
|
|
|
+ foreach ($detail as $value){
|
|
|
|
+ $customer['product_price'][] = [
|
|
|
|
+ 'basic_type_id' => $value['basic_type_id'],
|
|
|
|
+ 'basic_type_title' => $title_map[$value['basic_type_id']] ?? '',
|
|
|
|
+ 'grade' => $value['grade'],
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
|
|
//单位
|
|
//单位
|
|
$title = BasicType::where('id',$customer['unit'])->value('title');
|
|
$title = BasicType::where('id',$customer['unit'])->value('title');
|
|
$customer['unit_name'] = $title;
|
|
$customer['unit_name'] = $title;
|
|
- //库存
|
|
|
|
- $customer['product_inventory'] = (new ProductInventoryService())->getRealStock([$data['id']]);
|
|
|
|
|
|
|
|
$customer['img'] = $customer['file'] = $customer['depart'] = $customer['employee'] = [];
|
|
$customer['img'] = $customer['file'] = $customer['depart'] = $customer['employee'] = [];
|
|
$customer_info = ProductInfo::where('del_time',0)
|
|
$customer_info = ProductInfo::where('del_time',0)
|
|
@@ -481,7 +532,8 @@ class ProductService extends Service
|
|
* @return array
|
|
* @return array
|
|
*/
|
|
*/
|
|
public function productList($data,$user){
|
|
public function productList($data,$user){
|
|
- $model = Product::where('del_time',0)
|
|
|
|
|
|
+ $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')
|
|
->select('title','id','product_category_id','code','size','unit','bar_code','retail_price','cost','depart_price','state','crt_id','crt_time','mark')
|
|
->orderby('id', 'desc');
|
|
->orderby('id', 'desc');
|
|
|
|
|
|
@@ -512,7 +564,7 @@ class ProductService extends Service
|
|
* @param $is_add
|
|
* @param $is_add
|
|
* @return array
|
|
* @return array
|
|
*/
|
|
*/
|
|
- public function productRule($data, $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['code'])) return [false,'产品编码不能为空'];
|
|
if(empty($data['code'])) return [false,'产品编码不能为空'];
|
|
@@ -526,6 +578,10 @@ class ProductService extends Service
|
|
$res = $this->checkNumber($data['retail_price']);
|
|
$res = $this->checkNumber($data['retail_price']);
|
|
if(! $res) return [false,'零售价格请输入不超过两位小数并且大于0的数值'];
|
|
if(! $res) return [false,'零售价格请输入不超过两位小数并且大于0的数值'];
|
|
|
|
|
|
|
|
+ //所属部门 以及 顶级部门
|
|
|
|
+ if(empty($data['depart_id'])) $data['depart_id'] = $this->getDepart($user);
|
|
|
|
+ $data['top_depart_id'] = $user['depart_map'][$data['depart_id']] ?? 0;
|
|
|
|
+
|
|
if($is_add){
|
|
if($is_add){
|
|
$bool = Product::whereRaw("(binary code = '{$data['code']}' OR title = '{$data['title']}')")
|
|
$bool = Product::whereRaw("(binary code = '{$data['code']}' OR title = '{$data['title']}')")
|
|
->where('del_time',0)
|
|
->where('del_time',0)
|