|
@@ -91,7 +91,49 @@ class Goods extends Controller
|
|
|
public function add()
|
|
|
{
|
|
|
$this->title = '添加';
|
|
|
- $this->_form($this->table, 'form');
|
|
|
+// $this->_form($this->table, 'form');
|
|
|
+ if ($this->request->isGet()) {
|
|
|
+ $this->category_list = GoodsCategoryService::get_list([],1);
|
|
|
+ return $this->fetch('form',['vo' => []]);
|
|
|
+ }
|
|
|
+ if ($this->request->isPost()) {
|
|
|
+ list($data) = [$this->request->post()];
|
|
|
+ if($data){
|
|
|
+ // 添加编辑提交数据时
|
|
|
+ $data['goods_category_first'] = $data['first_classify'];
|
|
|
+ $data['goods_category_id'] = $data['second_classify'];
|
|
|
+ $goods_info = model::field('id')
|
|
|
+ ->where('goods_category_first', $data['goods_category_first'])
|
|
|
+ ->where('goods_category_id', $data['goods_category_id'])
|
|
|
+ ->where('goods_name', $data['goods_name'])
|
|
|
+ ->where('is_deleted', CommonConstant::IS_DELETED_0)
|
|
|
+ ->find();
|
|
|
+ if($goods_info){
|
|
|
+ $this->error('该商品已存在不能重复添加');
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = model::create($data);
|
|
|
+ $goods_stock = $data['goods_stock'];
|
|
|
+ $goods_stock_data = [];
|
|
|
+ if(isset($data['id']) && $data['id']){
|
|
|
+
|
|
|
+ } else{
|
|
|
+ // 添加商品 添加规格
|
|
|
+ foreach ($goods_stock as $key=>$val){
|
|
|
+ $goods_stock_data[] = [
|
|
|
+ 'goods_id'=>$result,
|
|
|
+ 'name'=>$val['name'],
|
|
|
+ 'stock'=>$val['stock'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ if($goods_stock_data){
|
|
|
+ GoodsStock::insertAll($goods_stock_data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->success('商品编辑成功!', 'javascript:history.back()');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -129,9 +171,21 @@ class Goods extends Controller
|
|
|
}
|
|
|
if ($this->request->isPost()) {
|
|
|
if($data){
|
|
|
- // 编辑提交数据时
|
|
|
+ // 添加编辑提交数据时
|
|
|
$data['goods_category_first'] = $data['first_classify'];
|
|
|
$data['goods_category_id'] = $data['second_classify'];
|
|
|
+ if(isset($data['id']) && $data['id'] > 0){
|
|
|
+ } else{
|
|
|
+ $goods_info = model::field('id')
|
|
|
+ ->where('goods_category_first', $data['goods_category_first'])
|
|
|
+ ->where('goods_category_id', $data['goods_category_id'])
|
|
|
+ ->where('goods_name', $data['goods_name'])
|
|
|
+ ->where('is_deleted', CommonConstant::IS_DELETED_0)
|
|
|
+ ->find();
|
|
|
+ if($goods_info){
|
|
|
+ $this->error('该商品已存在不能重复添加');
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -144,28 +198,23 @@ class Goods extends Controller
|
|
|
{
|
|
|
if ($result && $this->request->isPost()) {
|
|
|
list($data) = [$this->request->post()];
|
|
|
- p($result);
|
|
|
- p($data);
|
|
|
- exit;
|
|
|
-// $data['id'] = $result;
|
|
|
-// $low_price = 0;
|
|
|
-// foreach (json_decode($data['lists'], true) as $ko=>$vo){
|
|
|
-// if($low_price == 0 || $vo[0]['sell_price'] < $low_price )$low_price = $vo[0]['sell_price'];
|
|
|
-// Data::save('StoreGoodsItem', [
|
|
|
-// 'goods_id' => $data['id'],
|
|
|
-// 'spec_cover' => $data['spec_cover'][$ko] ? $data['spec_cover'][$ko] : $vo[0]['spec_cover'],
|
|
|
-// 'goods_spec' => $vo[0]['key'],
|
|
|
-// 'goods_no' => $vo[0]['sku'],
|
|
|
-// 'original_price' => $vo[0]['original_price'],
|
|
|
-// 'sell_price' => $vo[0]['sell_price'],
|
|
|
-// 'virtual' => $vo[0]['virtual'],
|
|
|
-// 'status' => $vo[0]['status'] ? 1 : 0,
|
|
|
-// 'weight' => $vo[0]['weight'] ? $vo[0]['weight'] : 0,
|
|
|
-// ], 'goods_spec', ['goods_id' => $data['id']]);
|
|
|
-// }
|
|
|
-// Db::name('StoreGoods')->where(['id'=>$data['id']])->update(['low_price'=>$low_price]);
|
|
|
-// \app\common\model\StoreGoods::esAdd($result);
|
|
|
-// \app\common\model\TopSearch::saveData($result,'goods');
|
|
|
+ $goods_stock = $data['goods_stock'];
|
|
|
+ $goods_stock_data = [];
|
|
|
+ if(isset($data['id']) && $data['id']){
|
|
|
+
|
|
|
+ } else{
|
|
|
+ // 添加商品 添加规格
|
|
|
+ foreach ($goods_stock as $key=>$val){
|
|
|
+ $goods_stock_data[] = [
|
|
|
+ 'goods_id'=>$result,
|
|
|
+ 'name'=>$val['name'],
|
|
|
+ 'stock'=>$val['stock'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ if($goods_stock_data){
|
|
|
+ GoodsStock::insertAll($goods_stock_data);
|
|
|
+ }
|
|
|
+ }
|
|
|
$this->success('商品编辑成功!', 'javascript:history.back()');
|
|
|
}
|
|
|
}
|