|
@@ -11,9 +11,9 @@ use hg\apidoc\annotation\Method;
|
|
|
use hg\apidoc\annotation\Param;
|
|
|
use hg\apidoc\annotation\Returned;
|
|
|
use think\admin\extend\CodeExtend;
|
|
|
-use think\Db;
|
|
|
use think\db\Where;
|
|
|
use think\exception\ErrorException;
|
|
|
+use \think\facade\Db;
|
|
|
|
|
|
/**
|
|
|
* 商家商品数据接口
|
|
@@ -81,7 +81,7 @@ class Goods extends Controller
|
|
|
* @Param ("items",desc="商品规格信息 [ goods_spec 规格名 颜色::红色;;大小::1','stock_total 库存','price_selling 售价','sku_image 图片''status 1在售 2 下架']")
|
|
|
*/
|
|
|
public function goods_add(){
|
|
|
- $admin_id = $this->uuid();
|
|
|
+// $admin_id = $this->uuid();
|
|
|
$data = $this->_vali(
|
|
|
[
|
|
|
'name.require'=>'商品名称不能为空',
|
|
@@ -96,7 +96,6 @@ class Goods extends Controller
|
|
|
'status.require'=>'商品状态不能为空',
|
|
|
]
|
|
|
);
|
|
|
- $items = json_decode($data['items'],true);
|
|
|
$goods_data= [
|
|
|
'name'=>$data['name'],
|
|
|
'cateids'=>$data['cateids'],
|
|
@@ -108,15 +107,17 @@ class Goods extends Controller
|
|
|
'price_market'=>$data['price_selling'],
|
|
|
'code'=>CodeExtend::uniqidNumber(20, 'G'),
|
|
|
'data_specs'=>$data['spec'],
|
|
|
- 'data_items'=>json_encode($data['items'],true),
|
|
|
+ 'data_items'=>$data['items'],
|
|
|
'status'=>$data['status'],
|
|
|
'create_at'=>date('Y-m-d H:i:s'),
|
|
|
- 'admin_id'=>$admin_id->id,
|
|
|
+ 'admin_id'=>2
|
|
|
];
|
|
|
- \think\facade\Db::startTrans();
|
|
|
+ $data['items'] = '[{"goods_spec":"白色","stock_total":"1","price_selling":"1","sku_image":"https://ship-expert.zhousi.hdlkeji.com/upload/49/af58e8d3b1f0ab1afaf92a69e0d33d.jpg","status":1},{"goods_spec":"棕色","stock_total":"1","price_selling":"2","sku_image":"https://ship-expert.zhousi.hdlkeji.com/upload/cb/dd06ba71472d29c4d1a0827f1935d4.png","status":1}]';
|
|
|
+ Db::startTrans();
|
|
|
try {
|
|
|
ShopGoods::mk()->insertGetId($goods_data);
|
|
|
- foreach ($items['list']as &$v){
|
|
|
+ $data['items']=json_decode($data['items'],true);
|
|
|
+ foreach ($data['items'] as &$v){
|
|
|
$item_data = [
|
|
|
'goods_sku'=>CodeExtend::uniqidNumber(12, 'S'),
|
|
|
'goods_code'=>$goods_data['code'],
|
|
@@ -124,17 +125,17 @@ class Goods extends Controller
|
|
|
'stock_total'=>$v['stock_total'],
|
|
|
'price_selling'=>$v['price_selling'],
|
|
|
'price_market'=>$v['price_selling'],
|
|
|
- 'show_image'=>$v['sku_iamge'],
|
|
|
+ 'show_image'=>$v['sku_image'],
|
|
|
'create_at'=>date('Y-m-d H:i:s'),
|
|
|
'status'=>$v['status'],
|
|
|
- 'admin_id'=>$admin_id->id
|
|
|
+ 'admin_id'=>2
|
|
|
];
|
|
|
ShopGoodsItem::mk()->insertGetId($item_data);
|
|
|
}
|
|
|
+ Db::commit();
|
|
|
$this->success('商品数据入库成功!');
|
|
|
-
|
|
|
-
|
|
|
}catch (\ErrorException $e){
|
|
|
+ Db::rollback();
|
|
|
$this->error('商品数据入库失败!');
|
|
|
}
|
|
|
}
|
|
@@ -156,6 +157,7 @@ class Goods extends Controller
|
|
|
*/
|
|
|
public function goods_edit(){
|
|
|
$goods_id = input('goods_id');
|
|
|
+
|
|
|
$data = $this->_vali(
|
|
|
[
|
|
|
'name.require'=>'商品名称不能为空',
|
|
@@ -179,12 +181,12 @@ class Goods extends Controller
|
|
|
'stock_total'=>$data['stock_total'],
|
|
|
'price_selling'=>$data['price_selling'],
|
|
|
'data_specs'=>$data['spec'],
|
|
|
- 'data_items'=>$data['items'],true,
|
|
|
+ 'data_items'=>$data['items'],
|
|
|
'status'=>$data['status'],
|
|
|
'create_at'=>date('Y-m-d H:i:s'),
|
|
|
];
|
|
|
- $data['items']=json_decode($data['items'],'true');
|
|
|
- \think\facade\Db::startTrans();
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
try {
|
|
|
ShopGoods::mk()->where('id',$goods_id)->save($goods_data);
|
|
|
foreach ($data['items']as &$v){
|
|
@@ -198,10 +200,12 @@ class Goods extends Controller
|
|
|
];
|
|
|
ShopGoodsItem::mk()->where('id',$v['id'])->save($item_data);
|
|
|
}
|
|
|
+ Db::commit();
|
|
|
$this->success('商品数据入库成功!');
|
|
|
|
|
|
|
|
|
}catch (\ErrorException $e){
|
|
|
+ Db::rollback();
|
|
|
$this->success('商品数据入库失败!');
|
|
|
}
|
|
|
|