| | |
| | | |
| | | use app\common\model\settings\Setting; |
| | | use app\supplier\model\product\Product as ProductModel; |
| | | use app\common\model\product\Category as CategoryModel; |
| | | use app\supplier\model\product\Category as CategoryModel; |
| | | use app\supplier\service\ProductService; |
| | | use app\supplier\model\supplier\Supplier as SupplierModel; |
| | | use app\supplier\controller\Controller; |
| | | use think\facade\Cache; |
| | | |
| | | /** |
| | | * 商品管理控制器 |
| | |
| | | $model = new ProductModel; |
| | | $list = $model->getList(array_merge(['status' => -1, 'shop_supplier_id' => $this->getSupplierId()], $this->postData())); |
| | | // 商品分类 |
| | | $category = CategoryModel::getCacheTree(); |
| | | $category = CategoryModel::getSupplierCacheTree($this->getSupplierId()); |
| | | |
| | | // 数量 |
| | | $product_count = [ |
| | | 'sell' => $model->getCount('sell', $this->getSupplierId()), |
| | |
| | | */ |
| | | public function add($scene = 'add') |
| | | { |
| | | $supplier = SupplierModel::detail($this->getSupplierId()); |
| | | // get请求 |
| | | if($this->request->isGet()){ |
| | | return $this->getBaseData(); |
| | | return $this->getBaseData($supplier); |
| | | } |
| | | //post请求 |
| | | $data = json_decode($this->postData()['params'], true); |
| | | $data['is_newcomer'] = $supplier['is_newcomer']; |
| | | $data['is_repurchase'] = $supplier['is_repurchase']; |
| | | $data['is_vip'] = $supplier['is_vip']; |
| | | // 添加商品 |
| | | if($scene == 'copy'){ |
| | | unset($data['create_time']); |
| | | unset($data['sku']['product_sku_id']); |
| | |
| | | /** |
| | | * 获取基础数据 |
| | | */ |
| | | public function getBaseData() |
| | | public function getBaseData($supplier) |
| | | { |
| | | return $this->renderSuccess('', array_merge(ProductService::getEditData(null, 'add', $this->getSupplierId()), [])); |
| | | return $this->renderSuccess('', array_merge(ProductService::getEditData(null, 'add', $this->getSupplierId()),['is_newcomer'=>$supplier['is_newcomer'],'is_repurchase'=>$supplier['is_repurchase'],'is_vip'=>$supplier['is_vip']])); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public function edit($product_id, $scene = 'edit') |
| | | { |
| | | $supplier = SupplierModel::detail($this->getSupplierId()); |
| | | if($this->request->isGet()){ |
| | | $model = ProductModel::detail($product_id); |
| | | return $this->renderSuccess('', array_merge(ProductService::getEditData($model, $scene, $this->getSupplierId()), compact('model'))); |
| | | $is_newcomer = $supplier['is_newcomer']; |
| | | $is_repurchase = $supplier['is_repurchase']; |
| | | $is_vip = $supplier['is_vip']; |
| | | $supplierName=''; |
| | | if($model['belonging_shop_supplier_id']){ |
| | | $belonging_shop_supplier= SupplierModel::detail($model['belonging_shop_supplier_id']); |
| | | $supplierName=$belonging_shop_supplier['name']; |
| | | } |
| | | return $this->renderSuccess('', array_merge(ProductService::getEditData($model, $scene, $this->getSupplierId()), compact('model','is_newcomer','is_repurchase','is_vip','supplierName'))); |
| | | } |
| | | if ($scene == 'copy') { |
| | | return $this->add($scene); |
| | | } |
| | | // 商品详情 |
| | | $model = ProductModel::detail($product_id); |
| | | $data = json_decode($this->postData()['params'], true); |
| | | $data['is_newcomer'] = $supplier['is_newcomer']; |
| | | $data['is_repurchase'] = $supplier['is_repurchase']; |
| | | $data['is_vip'] = $supplier['is_vip']; |
| | | // 更新记录 |
| | | if ($model->edit(json_decode($this->postData()['params'], true),$this->getSupplierId())) { |
| | | if ($model->edit($data,$this->getSupplierId())) { |
| | | return $this->renderSuccess('更新成功'); |
| | | } |
| | | return $this->renderError($model->getError() ?: '更新失败'); |