|
@@ -3,11 +3,15 @@
|
|
|
namespace app\data\controller\api\business;
|
|
|
|
|
|
use app\data\model\ShopGoods;
|
|
|
+use app\data\model\ShopGoodsItem;
|
|
|
use think\admin\Controller;
|
|
|
use hg\apidoc\annotation\Title;
|
|
|
use hg\apidoc\annotation\Method;
|
|
|
use hg\apidoc\annotation\Param;
|
|
|
use hg\apidoc\annotation\Returned;
|
|
|
+use think\admin\extend\CodeExtend;
|
|
|
+use think\Db;
|
|
|
+
|
|
|
/**
|
|
|
* 商家商品数据接口
|
|
|
*/
|
|
@@ -50,7 +54,45 @@ class Goods extends Controller
|
|
|
* @Title ("添加商品")
|
|
|
*/
|
|
|
public function goods_add(){
|
|
|
+ $data = $this->_vali(
|
|
|
+ [
|
|
|
+ 'name.require'=>'商品名称不能为空',
|
|
|
+ 'cateids.require'=>'商品分类不能不选',
|
|
|
+ 'cover.require'=>'商品封面不能为空',
|
|
|
+ 'slider.require'=>'商品轮播图不能为空',
|
|
|
+ 'content.require'=>'商品详情不能为空',
|
|
|
+ 'stock_total.require'=>'商品库存不能为空',
|
|
|
+ 'price_selling.require'=>'商品销售价格不能为空',
|
|
|
+ 'price_market.require'=>'商品市场价格不能为空',
|
|
|
+ 'items.require'=>'商品规格不能为空'
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ $data['code']=CodeExtend::uniqidNumber(20, 'G');
|
|
|
+ $data['data_specs']=json($data['items']);
|
|
|
+ $data['create_at']=date('Y-m-d H:i:s');
|
|
|
+ $data['admin_id']=10000;
|
|
|
+
|
|
|
+ try {
|
|
|
+ ShopGoods::mk()->insertGetId($data);
|
|
|
+ foreach ($data['items']as &$v){
|
|
|
+ $item_data = [
|
|
|
+ 'goods_sku'=>CodeExtend::uniqidNumber(12, 'S'),
|
|
|
+ 'goods_code'=>$data['code'],
|
|
|
+ 'goods_spec'=>$v['name'],
|
|
|
+ 'stock_total'=>$v['total'],
|
|
|
+ 'price_selling'=>$v['price_selling'],
|
|
|
+ 'price_market'=>$v['price_market'],
|
|
|
+ 'create_at'=>date('Y-m-d H:i:s'),
|
|
|
+ 'admin_id'=>10000
|
|
|
+ ];
|
|
|
+ ShopGoodsItem::mk()->insertGetId($data);
|
|
|
+ }
|
|
|
+ $this->success('商品数据入库成功!');
|
|
|
|
|
|
+
|
|
|
+ }catch (\Exception $e){
|
|
|
+ $this->success('商品数据入库失败!');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|