|
@@ -6,6 +6,7 @@ namespace app\admin\controller;
|
|
|
use app\BaseController;
|
|
use app\BaseController;
|
|
|
use app\common\model\ProductCategoryModel;
|
|
use app\common\model\ProductCategoryModel;
|
|
|
use app\common\model\ProductModel;
|
|
use app\common\model\ProductModel;
|
|
|
|
|
+use app\common\model\SupplierModel;
|
|
|
use think\App;
|
|
use think\App;
|
|
|
use think\facade\View;
|
|
use think\facade\View;
|
|
|
use think\Request;
|
|
use think\Request;
|
|
@@ -15,12 +16,14 @@ class Product extends BaseController
|
|
|
|
|
|
|
|
private $productModel;
|
|
private $productModel;
|
|
|
private $categoryModel;
|
|
private $categoryModel;
|
|
|
|
|
+ private $supplierModel;
|
|
|
|
|
|
|
|
public function __construct(App $app)
|
|
public function __construct(App $app)
|
|
|
{
|
|
{
|
|
|
parent::__construct($app);
|
|
parent::__construct($app);
|
|
|
$this->productModel = new ProductModel();
|
|
$this->productModel = new ProductModel();
|
|
|
$this->categoryModel = new ProductCategoryModel();
|
|
$this->categoryModel = new ProductCategoryModel();
|
|
|
|
|
+ $this->supplierModel = new SupplierModel();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -52,20 +55,28 @@ class Product extends BaseController
|
|
|
$category = $this->categoryModel->findById($params['category_id']);
|
|
$category = $this->categoryModel->findById($params['category_id']);
|
|
|
if(!$category)
|
|
if(!$category)
|
|
|
return $this->fail(lang('Category does not exist'));
|
|
return $this->fail(lang('Category does not exist'));
|
|
|
|
|
+ $supplier = $this->supplierModel->findById($params['supplier_id']);
|
|
|
|
|
+ if(!$supplier)
|
|
|
|
|
+ return $this->fail(lang('Company does not exist'));
|
|
|
$res = $this->productModel->save([
|
|
$res = $this->productModel->save([
|
|
|
'bar_code' => $params['bar_code'],
|
|
'bar_code' => $params['bar_code'],
|
|
|
'name' => $params['name'] ?? null,
|
|
'name' => $params['name'] ?? null,
|
|
|
'image' => $params['image'] ?? null,
|
|
'image' => $params['image'] ?? null,
|
|
|
'category_id' => $params['category_id'] ?? null,
|
|
'category_id' => $params['category_id'] ?? null,
|
|
|
- 'category_name' => $category->name,
|
|
|
|
|
|
|
+ 'supplier_id' => $supplier->id,
|
|
|
'is_serve' => $params['is_serve'],
|
|
'is_serve' => $params['is_serve'],
|
|
|
'purchase_price'=> $params['purchase_price'],
|
|
'purchase_price'=> $params['purchase_price'],
|
|
|
- 'selling_price' => $params['selling_price']
|
|
|
|
|
|
|
+ 'real_price' => $params['real_price'],
|
|
|
|
|
+ 'lineate_price' => $params['lineate_price'],
|
|
|
|
|
+ 'is_upload_numerology' => $params['is_upload_numerology'],
|
|
|
|
|
+ 'is_gather_annuity' => $params["is_gather_annuity"],
|
|
|
|
|
+ 'annuity' => $params["annuity"]
|
|
|
]);
|
|
]);
|
|
|
return $this->ok($res);
|
|
return $this->ok($res);
|
|
|
}
|
|
}
|
|
|
View::assign([
|
|
View::assign([
|
|
|
'all_category' => recursion($this->categoryModel->findAll(),0),
|
|
'all_category' => recursion($this->categoryModel->findAll(),0),
|
|
|
|
|
+ "all_supplier" => $this->supplierModel->findAll()
|
|
|
]);
|
|
]);
|
|
|
return view();
|
|
return view();
|
|
|
}
|
|
}
|
|
@@ -79,15 +90,22 @@ class Product extends BaseController
|
|
|
$category = $this->categoryModel->findById($params['category_id']);
|
|
$category = $this->categoryModel->findById($params['category_id']);
|
|
|
if(!$category)
|
|
if(!$category)
|
|
|
return $this->fail(lang('Category does not exist'));
|
|
return $this->fail(lang('Category does not exist'));
|
|
|
|
|
+ $supplier = $this->supplierModel->findById($params['supplier_id'] ?? 0);
|
|
|
|
|
+ if(!$supplier)
|
|
|
|
|
+ return $this->fail(lang('Company does not exist'));
|
|
|
$res = $this->productModel->where('id',$params['id'])->update([
|
|
$res = $this->productModel->where('id',$params['id'])->update([
|
|
|
'bar_code' => $params['bar_code'],
|
|
'bar_code' => $params['bar_code'],
|
|
|
- 'name' => $params['name'] ?? null,
|
|
|
|
|
- 'image' => $params['image'] ?? null,
|
|
|
|
|
- 'category_id' => $params['category_id'] ?? null,
|
|
|
|
|
- 'category_name' => $category->name,
|
|
|
|
|
|
|
+ 'name' => isset($params['name']) ? $params['name'] : $product->name,
|
|
|
|
|
+ 'image' => isset($params['image']) ? $params['image'] : $product->image,
|
|
|
|
|
+ 'category_id' => $category->id,
|
|
|
|
|
+ 'supplier_id' => $supplier->id,
|
|
|
'is_serve' => (int)$params['is_serve'],
|
|
'is_serve' => (int)$params['is_serve'],
|
|
|
- 'purchase_price'=> $params['purchase_price'],
|
|
|
|
|
- 'selling_price' => $params['selling_price'],
|
|
|
|
|
|
|
+ 'purchase_price'=> isset($params['purchase_price']) ? $params['purchase_price'] : $product->purchase_price,
|
|
|
|
|
+ 'real_price' => isset($params['real_price']) && $params['real_price'] > 0 ? $params['real_price'] : $product->real_price,
|
|
|
|
|
+ 'lineate_price' => isset($params['lineate_price']) && $params['lineate_price'] > 0 ? $params['lineate_price'] : $product->lineate_price,
|
|
|
|
|
+ 'is_upload_numerology' => $params['is_upload_numerology'],
|
|
|
|
|
+ 'is_gather_annuity' => $params["is_gather_annuity"],
|
|
|
|
|
+ 'annuity' => $params["annuity"],
|
|
|
'update_time' => time()
|
|
'update_time' => time()
|
|
|
]);
|
|
]);
|
|
|
return $this->ok($res);
|
|
return $this->ok($res);
|
|
@@ -95,6 +113,7 @@ class Product extends BaseController
|
|
|
View::assign([
|
|
View::assign([
|
|
|
'product' => $product,
|
|
'product' => $product,
|
|
|
'all_category' => recursion($this->categoryModel->findAll(),0),
|
|
'all_category' => recursion($this->categoryModel->findAll(),0),
|
|
|
|
|
+ 'all_supplier' => $this->supplierModel->findAll()
|
|
|
]);
|
|
]);
|
|
|
return view();
|
|
return view();
|
|
|
}
|
|
}
|