|
|
@@ -3,7 +3,6 @@
|
|
|
namespace app\admin\controller\store;
|
|
|
|
|
|
use app\admin\controller\AuthController;
|
|
|
-use app\models\store\StoreProductLevel;
|
|
|
use app\models\system\Tree;
|
|
|
use app\admin\model\store\{
|
|
|
StoreDescription,
|
|
|
@@ -111,10 +110,10 @@ class StoreProduct extends AuthController
|
|
|
['type', $this->request->param('type')]
|
|
|
]);
|
|
|
$admin_id=$this->adminId;
|
|
|
- $mer_id = SystemAdmin::where('id',$admin_id)->value('mer_id');
|
|
|
- if ($mer_id>0){
|
|
|
- $where['mer_id'] = $mer_id;
|
|
|
- }
|
|
|
+ $mer_id = SystemAdmin::where('id',$admin_id)->value('mer_id');
|
|
|
+ if ($mer_id>0){
|
|
|
+ $where['mer_id'] = $mer_id;
|
|
|
+ }
|
|
|
|
|
|
return Json::successlayui(ProductModel::ProductList($where));
|
|
|
}
|
|
|
@@ -195,7 +194,7 @@ class StoreProduct extends AuthController
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取商品详细信息
|
|
|
+ * 获取产品详细信息
|
|
|
* @param int $id
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
|
* @throws \think\db\exception\DbException
|
|
|
@@ -220,22 +219,6 @@ class StoreProduct extends AuthController
|
|
|
$productInfo['cate_id'] = explode(',', $productInfo['cate_id']);
|
|
|
$productInfo['description'] = htmlspecialchars_decode(StoreDescription::getDescription($id));
|
|
|
$productInfo['slider_image'] = is_string($productInfo['slider_image']) ? json_decode($productInfo['slider_image'], true) : [];
|
|
|
-
|
|
|
- // 获取等级返利数据
|
|
|
- $levelRebates = StoreProductLevel::where('product_id', $id)->select();
|
|
|
- if ($levelRebates) {
|
|
|
- $productInfo['level_rebates'] = $levelRebates->toArray();
|
|
|
- } else {
|
|
|
- // 默认等级数据
|
|
|
- $productInfo['level_rebates'] = [
|
|
|
- ['id' => 1, 'name' => '青源客', 'rebate_ratio' => 0],
|
|
|
- ['id' => 2, 'name' => '青润使', 'rebate_ratio' => 0],
|
|
|
- ['id' => 3, 'name' => '青金团', 'rebate_ratio' => 0],
|
|
|
- ['id' => 4, 'name' => '青玉团', 'rebate_ratio' => 0],
|
|
|
- ['id' => 5, 'name' => '青谷团', 'rebate_ratio' => 0]
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
if ($productInfo['spec_type'] == 1) {
|
|
|
$result = StoreProductAttrResult::getResult($id);
|
|
|
foreach ($result['value'] as $k => $v) {
|
|
|
@@ -319,8 +302,7 @@ class StoreProduct extends AuthController
|
|
|
['mer_use', 0],
|
|
|
['is_postage', 0],
|
|
|
['is_good', 0],
|
|
|
- ['is_level_rebate', 0],
|
|
|
- ['level_rebates', []],
|
|
|
+// ['description', ''],
|
|
|
['spec_type', 0],
|
|
|
['video_link', ''],
|
|
|
['items', []],
|
|
|
@@ -329,34 +311,13 @@ class StoreProduct extends AuthController
|
|
|
['store_type', 1],
|
|
|
['mer_id',0]
|
|
|
], $this->request, false, true);
|
|
|
-
|
|
|
- // 验证等级返利数据
|
|
|
- if ($data['is_level_rebate'] == 1) {
|
|
|
- if (empty($data['level_rebates']) || !is_array($data['level_rebates'])) {
|
|
|
- return Json::fail('请设置等级返利数据');
|
|
|
- }
|
|
|
-
|
|
|
- // 验证返利比例是否合理
|
|
|
- foreach ($data['level_rebates'] as $k => $level) {
|
|
|
- if (!isset($level['rebate_ratio']) || $level['rebate_ratio'] === '') {
|
|
|
- return Json::fail('请设置等级返利比例');
|
|
|
- }
|
|
|
-
|
|
|
- if ($level['rebate_ratio'] < 0 || $level['rebate_ratio'] > 100) {
|
|
|
- return Json::fail('返利比例必须在0-100之间');
|
|
|
- }
|
|
|
-
|
|
|
- // 验证等级间返利比例是否递增
|
|
|
- if ($k > 0) {
|
|
|
- if ($level['rebate_ratio'] <= $data['level_rebates'][$k-1]['rebate_ratio']) {
|
|
|
- return Json::fail('等级返利比例应随等级提高而递增');
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $data['is_pick'] = SystemStore::where('id', $data['mer_id'])->value('is_pick');
|
|
|
-
|
|
|
+// $admin_id=$this->adminId;
|
|
|
+// $mer_id = SystemAdmin::where('id',$admin_id)->value('mer_id');
|
|
|
+// if ($data['mer_id']>0){
|
|
|
+// $data['mer_id'] = $mer_id;
|
|
|
+ $data['is_pick']=SystemStore::where('id',$data['mer_id'])->value('is_pick');
|
|
|
+// var_dump($data);die();
|
|
|
+// }
|
|
|
foreach ($data['activity'] as $k => $v) {
|
|
|
if ($v == '秒杀') {
|
|
|
$data['activity'][$k] = 1;
|
|
|
@@ -375,11 +336,7 @@ class StoreProduct extends AuthController
|
|
|
$data['ot_price'] = min(array_column($detail, 'ot_price'));
|
|
|
$data['cost'] = min(array_column($detail, 'cost'));
|
|
|
$attr = $data['items'];
|
|
|
-
|
|
|
- // 保存等级返利数据
|
|
|
- $levelRebates = $data['level_rebates'];
|
|
|
- unset($data['items'], $data['video'], $data['attrs'], $data['level_rebates']);
|
|
|
-
|
|
|
+ unset($data['items'], $data['video'], $data['attrs']);
|
|
|
if (count($data['cate_id']) < 1) return Json::fail('请选择产品分类');
|
|
|
if (!in_array($data['store_type'], [1, 2])) return Json::fail('请选择正确的商品类型');
|
|
|
$cate_id = $data['cate_id'];
|
|
|
@@ -391,110 +348,76 @@ class StoreProduct extends AuthController
|
|
|
$data['image'] = $data['image'][0];
|
|
|
$data['slider_image'] = json_encode($data['slider_image']);
|
|
|
$data['stock'] = array_sum(array_column($detail, 'stock'));
|
|
|
-
|
|
|
ProductModel::beginTrans();
|
|
|
- try {
|
|
|
- foreach ($detail as &$item) {
|
|
|
- if (($item['brokerage'] + $item['brokerage_two']) > $item['price']) {
|
|
|
- throw new \Exception('一二级返佣相加不能大于商品售价');
|
|
|
- }
|
|
|
+ foreach ($detail as &$item) {
|
|
|
+ if (($item['brokerage'] + $item['brokerage_two']) > $item['price']) {
|
|
|
+ return Json::fail('一二级返佣相加不能大于商品售价');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($id) {
|
|
|
+ unset($data['sales']);
|
|
|
+ ProductModel::edit($data, $id);
|
|
|
+ $description = $data['description'];
|
|
|
+ unset($data['description']);
|
|
|
+ StoreDescription::saveDescription($description, $id);
|
|
|
+ StoreProductCate::where('product_id', $id)->delete();
|
|
|
+ $cateData = [];
|
|
|
+ foreach ($cate_id as $cid) {
|
|
|
+ $cateData[] = ['product_id' => $id, 'cate_id' => $cid, 'add_time' => time()];
|
|
|
+ }
|
|
|
+ StoreProductCate::insertAll($cateData);
|
|
|
+ if ($data['spec_type'] == 0) {
|
|
|
+ $attr = [
|
|
|
+ [
|
|
|
+ 'value' => '规格',
|
|
|
+ 'detailValue' => '',
|
|
|
+ 'attrHidden' => '',
|
|
|
+ 'detail' => ['默认']
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ $detail[0]['value1'] = '规格';
|
|
|
+ $detail[0]['detail'] = ['规格' => '默认'];
|
|
|
}
|
|
|
|
|
|
- if ($id) {
|
|
|
- unset($data['sales']);
|
|
|
- ProductModel::edit($data, $id);
|
|
|
- $description = $data['description'];
|
|
|
- unset($data['description']);
|
|
|
- StoreDescription::saveDescription($description, $id);
|
|
|
- StoreProductCate::where('product_id', $id)->delete();
|
|
|
- $cateData = [];
|
|
|
- foreach ($cate_id as $cid) {
|
|
|
- $cateData[] = ['product_id' => $id, 'cate_id' => $cid, 'add_time' => time()];
|
|
|
- }
|
|
|
- StoreProductCate::insertAll($cateData);
|
|
|
-
|
|
|
- // 更新等级返利数据
|
|
|
- if ($data['is_level_rebate'] == 1) {
|
|
|
- // 删除原有数据
|
|
|
- StoreProductLevel::where('product_id', $id)->delete();
|
|
|
-
|
|
|
- // 插入新数据
|
|
|
- foreach ($levelRebates as $level) {
|
|
|
- StoreProductLevel::create([
|
|
|
- 'product_id' => $id,
|
|
|
- 'level_id' => $level['id'],
|
|
|
- 'rebate_ratio' => $level['rebate_ratio'],
|
|
|
- 'add_time' => time(),
|
|
|
- 'update_time' => time()
|
|
|
- ]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if ($data['spec_type'] == 0) {
|
|
|
- $attr = [
|
|
|
- [
|
|
|
- 'value' => '规格',
|
|
|
- 'detailValue' => '',
|
|
|
- 'attrHidden' => '',
|
|
|
- 'detail' => ['默认']
|
|
|
- ]
|
|
|
- ];
|
|
|
- $detail[0]['value1'] = '规格';
|
|
|
- $detail[0]['detail'] = ['规格' => '默认'];
|
|
|
- }
|
|
|
-
|
|
|
- $attr_res = StoreProductAttr::createProductAttr($attr, $detail, $id);
|
|
|
- if (!$attr_res) {
|
|
|
- throw new \Exception(StoreProductAttr::getErrorInfo());
|
|
|
- }
|
|
|
+ $attr_res = StoreProductAttr::createProductAttr($attr, $detail, $id);
|
|
|
+ if ($attr_res) {
|
|
|
+ ProductModel::commitTrans();
|
|
|
+ return Json::success('修改成功!');
|
|
|
} else {
|
|
|
- $data['add_time'] = time();
|
|
|
- $data['code_path'] = '';
|
|
|
- $res = ProductModel::create($data);
|
|
|
- $description = $data['description'];
|
|
|
- StoreDescription::saveDescription($description, $res['id']);
|
|
|
- $cateData = [];
|
|
|
- foreach ($cate_id as $cid) {
|
|
|
- $cateData[] = ['product_id' => $res['id'], 'cate_id' => $cid, 'add_time' => time()];
|
|
|
- }
|
|
|
- StoreProductCate::insertAll($cateData);
|
|
|
-
|
|
|
- // 保存等级返利数据
|
|
|
- if ($data['is_level_rebate'] == 1) {
|
|
|
- foreach ($levelRebates as $level) {
|
|
|
- StoreProductLevel::create([
|
|
|
- 'product_id' => $res['id'],
|
|
|
- 'level_id' => $level['id'],
|
|
|
- 'rebate_ratio' => $level['rebate_ratio'],
|
|
|
- 'add_time' => time(),
|
|
|
- 'update_time' => time()
|
|
|
- ]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if ($data['spec_type'] == 0) {
|
|
|
- $attr = [
|
|
|
- [
|
|
|
- 'value' => '规格',
|
|
|
- 'detailValue' => '',
|
|
|
- 'attrHidden' => '',
|
|
|
- 'detail' => ['默认']
|
|
|
- ]
|
|
|
- ];
|
|
|
- $detail[0]['value1'] = '规格';
|
|
|
- $detail[0]['detail'] = ['规格' => '默认'];
|
|
|
- }
|
|
|
- $attr_res = StoreProductAttr::createProductAttr($attr, $detail, $res['id']);
|
|
|
- if (!$attr_res) {
|
|
|
- throw new \Exception(StoreProductAttr::getErrorInfo());
|
|
|
- }
|
|
|
+ ProductModel::rollbackTrans();
|
|
|
+ return Json::fail(StoreProductAttr::getErrorInfo());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $data['add_time'] = time();
|
|
|
+ $data['code_path'] = '';
|
|
|
+ $res = ProductModel::create($data);
|
|
|
+ $description = $data['description'];
|
|
|
+ StoreDescription::saveDescription($description, $res['id']);
|
|
|
+ $cateData = [];
|
|
|
+ foreach ($cate_id as $cid) {
|
|
|
+ $cateData[] = ['product_id' => $res['id'], 'cate_id' => $cid, 'add_time' => time()];
|
|
|
+ }
|
|
|
+ StoreProductCate::insertAll($cateData);
|
|
|
+ if ($data['spec_type'] == 0) {
|
|
|
+ $attr = [
|
|
|
+ [
|
|
|
+ 'value' => '规格',
|
|
|
+ 'detailValue' => '',
|
|
|
+ 'attrHidden' => '',
|
|
|
+ 'detail' => ['默认']
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ $detail[0]['value1'] = '规格';
|
|
|
+ $detail[0]['detail'] = ['规格' => '默认'];
|
|
|
+ }
|
|
|
+ $attr_res = StoreProductAttr::createProductAttr($attr, $detail, $res['id']);
|
|
|
+ if ($attr_res) {
|
|
|
+ ProductModel::commitTrans();
|
|
|
+ return Json::success('添加产品成功!');
|
|
|
+ } else {
|
|
|
+ ProductModel::rollbackTrans();
|
|
|
+ return Json::fail(StoreProductAttr::getErrorInfo());
|
|
|
}
|
|
|
-
|
|
|
- ProductModel::commitTrans();
|
|
|
- return Json::success($id ? '修改成功!' : '添加产品成功!');
|
|
|
- } catch (\Exception $e) {
|
|
|
- ProductModel::rollbackTrans();
|
|
|
- return Json::fail($e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -557,7 +480,6 @@ class StoreProduct extends AuthController
|
|
|
Form::radio('is_postage', '是否包邮', $product->getData('is_postage'))->options([['label' => '是', 'value' => 1], ['label' => '否', 'value' => 0]])->col(8),
|
|
|
Form::radio('is_good', '是否优品推荐', $product->getData('is_good'))->options([['label' => '是', 'value' => 1], ['label' => '否', 'value' => 0]])->col(8),
|
|
|
Form::radio('is_wholesale', '是否批发商品', $product->getData('is_wholesale'))->options([['label' => '是', 'value' => 1], ['label' => '否', 'value' => 0]])->col(8),
|
|
|
- Form::radio('is_level_rebate', '是否开启等级返利', $product->getData('is_level_rebate'))->options([['label' => '是', 'value' => 1], ['label' => '否', 'value' => 0]])->col(8),
|
|
|
];
|
|
|
$form = Form::make_post_form('编辑产品', $field, Url::buildUrl('update', array('id' => $id)), 2);
|
|
|
$this->assign(compact('form'));
|
|
|
@@ -600,7 +522,6 @@ class StoreProduct extends AuthController
|
|
|
['is_postage', 0],
|
|
|
['is_good', 0],
|
|
|
['is_wholesale',0],
|
|
|
- ['is_level_rebate',0],
|
|
|
['mer_id',0]
|
|
|
]);
|
|
|
if (count($data['cate_id']) < 1) return Json::fail('请选择产品分类');
|
|
|
@@ -609,6 +530,7 @@ class StoreProduct extends AuthController
|
|
|
if (!$data['store_name']) return Json::fail('请输入产品名称');
|
|
|
if (count($data['image']) < 1) return Json::fail('请上传产品图片');
|
|
|
if (count($data['slider_image']) < 1) return Json::fail('请上传产品轮播图');
|
|
|
+ // if(count($data['slider_image'])>8) return Json::fail('轮播图最多5张图');
|
|
|
if ($data['price'] == '' || $data['price'] < 0) return Json::fail('请输入产品售价');
|
|
|
if ($data['ot_price'] == '' || $data['ot_price'] < 0) return Json::fail('请输入产品市场价');
|
|
|
if ($data['stock'] == '' || $data['stock'] < 0) return Json::fail('请输入库存');
|
|
|
@@ -856,4 +778,4 @@ class StoreProduct extends AuthController
|
|
|
return Json::fail();
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|