|
@@ -3,6 +3,10 @@
|
|
|
|
|
|
|
|
namespace app\admin\controller\mall;
|
|
namespace app\admin\controller\mall;
|
|
|
|
|
|
|
|
|
|
+use app\admin\logic\ShopGoodsLogic;
|
|
|
|
|
+use app\admin\logic\ShopGoodsTypeLogic;
|
|
|
|
|
+use app\admin\logic\ShopHotKeywordsLogic;
|
|
|
|
|
+use app\admin\logic\ShopSupplierLogic;
|
|
|
use app\common\model\ShopGoods as ShopGoods;
|
|
use app\common\model\ShopGoods as ShopGoods;
|
|
|
use app\common\model\ShopGoodsSpec;
|
|
use app\common\model\ShopGoodsSpec;
|
|
|
use app\admin\traits\Curd;
|
|
use app\admin\traits\Curd;
|
|
@@ -27,7 +31,7 @@ class Goods extends AdminController
|
|
|
|
|
|
|
|
protected $relationSearch = true;
|
|
protected $relationSearch = true;
|
|
|
|
|
|
|
|
- public function __construct (App $app)
|
|
|
|
|
|
|
+ public function __construct(App $app)
|
|
|
{
|
|
{
|
|
|
parent::__construct($app);
|
|
parent::__construct($app);
|
|
|
$this->model = new ShopGoods();
|
|
$this->model = new ShopGoods();
|
|
@@ -36,7 +40,7 @@ class Goods extends AdminController
|
|
|
/**
|
|
/**
|
|
|
* @NodeAnotation(title="列表")
|
|
* @NodeAnotation(title="列表")
|
|
|
*/
|
|
*/
|
|
|
- public function index ()
|
|
|
|
|
|
|
+ public function index()
|
|
|
{
|
|
{
|
|
|
if ($this->request->isAjax()) {
|
|
if ($this->request->isAjax()) {
|
|
|
if (input('selectFields')) {
|
|
if (input('selectFields')) {
|
|
@@ -44,60 +48,26 @@ class Goods extends AdminController
|
|
|
}
|
|
}
|
|
|
list($page, $limit, $where) = $this->buildTableParames();
|
|
list($page, $limit, $where) = $this->buildTableParames();
|
|
|
|
|
|
|
|
-// foreach ($where as $key=>$val){
|
|
|
|
|
-// if ($val[0] == 'status'){
|
|
|
|
|
-// $where[$key][0] = 'o.status';
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// return $where;
|
|
|
|
|
|
|
|
|
|
- $count = $this->model
|
|
|
|
|
- ->withJoin(['supplier','cate'], 'LEFT')
|
|
|
|
|
- ->where($where)
|
|
|
|
|
- ->count();
|
|
|
|
|
|
|
+ list($count, $list) = ShopGoodsLogic::getList($page, $limit, $where);
|
|
|
|
|
|
|
|
- $list = $this->model
|
|
|
|
|
- ->withJoin(['supplier','cate'], 'LEFT')
|
|
|
|
|
- ->where($where)
|
|
|
|
|
- ->page($page, $limit)
|
|
|
|
|
- ->order('goods_id desc')
|
|
|
|
|
- ->select()->toArray();
|
|
|
|
|
- foreach ($list as $k => &$v) {
|
|
|
|
|
- $v['id'] = $v['goods_id'];
|
|
|
|
|
-// $v['supplier'] = Db::name('shop_supplier')->where(['id'=>$v['supplier']])->value('name');
|
|
|
|
|
- $v['goods_type'] = Db::name('shop_goods_type')->where(['id'=>$v['goods_type']])->value('name');
|
|
|
|
|
- }
|
|
|
|
|
$data = [
|
|
$data = [
|
|
|
- 'code' => 0,
|
|
|
|
|
- 'msg' => '',
|
|
|
|
|
|
|
+ 'code' => 0,
|
|
|
|
|
+ 'msg' => '',
|
|
|
'count' => $count,
|
|
'count' => $count,
|
|
|
- 'data' => $list,
|
|
|
|
|
|
|
+ 'data' => $list,
|
|
|
];
|
|
];
|
|
|
return json($data);
|
|
return json($data);
|
|
|
}
|
|
}
|
|
|
return $this->fetch();
|
|
return $this->fetch();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function goodsBase ($id)
|
|
|
|
|
|
|
+ public function goodsBase($id)
|
|
|
{
|
|
{
|
|
|
- $data = $this->model->where(['goods_id' => $id])->findOrEmpty()->toArray();
|
|
|
|
|
- if ($data['goods_img_banner']) {
|
|
|
|
|
- $data['goods_img_banner'] = implode('|', json_decode($data['goods_img_banner'], true));
|
|
|
|
|
- }
|
|
|
|
|
- $data['goods_remark'] = htmlspecialchars_decode($data['goods_remark']);
|
|
|
|
|
- $specRelation = Db::name('shop_goods_spec_relation')->where(['goods_id' => $id])->select()->toArray();
|
|
|
|
|
- $specAttrId = Db::name('shop_goods_spec_type')->where(['id' => $specRelation[0]['spec_id']])->value('pid');
|
|
|
|
|
- if ($data['is_exist_many_spec'] == 0) {
|
|
|
|
|
- $data['defaultSku'] = Db::name('shop_goods_spec')->where(['goods_id' => $id])->find();
|
|
|
|
|
- }
|
|
|
|
|
- $hot_keywords = Db::name('shop_hot_keywords')->select()->toArray();
|
|
|
|
|
- $shop_supplier = Db::name('shop_supplier')->select()->toArray();
|
|
|
|
|
- $shop_goods_type = Db::name('shop_goods_type')->field('id,name')->select()->toArray();
|
|
|
|
|
|
|
+ list($data, $hot_keywords, $shop_goods_type, $shop_supplier,$specAttrId) = ShopGoodsLogic::getGoodsBase($id);
|
|
|
|
|
|
|
|
$this->assign('shop_goods_type', $shop_goods_type);
|
|
$this->assign('shop_goods_type', $shop_goods_type);
|
|
|
-
|
|
|
|
|
$this->assign('box_type', system_box_typesetting());
|
|
$this->assign('box_type', system_box_typesetting());
|
|
|
-
|
|
|
|
|
$this->assign('hot_keywords', $hot_keywords);
|
|
$this->assign('hot_keywords', $hot_keywords);
|
|
|
$this->assign('shop_supplier', $shop_supplier);
|
|
$this->assign('shop_supplier', $shop_supplier);
|
|
|
$this->assign('specAttrId', $specAttrId);
|
|
$this->assign('specAttrId', $specAttrId);
|
|
@@ -114,14 +84,14 @@ class Goods extends AdminController
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
* 获取商品规格,商品sku
|
|
* 获取商品规格,商品sku
|
|
|
*/
|
|
*/
|
|
|
- public function getGoodsSpecData ($goodsId, $attriId)
|
|
|
|
|
|
|
+ public function getGoodsSpecData($goodsId, $attriId)
|
|
|
{
|
|
{
|
|
|
if ($this->request->isAjax()) {
|
|
if ($this->request->isAjax()) {
|
|
|
$specRelation = Db::name('shop_goods_spec_relation')->where(['goods_id' => $goodsId])->select()->toArray();
|
|
$specRelation = Db::name('shop_goods_spec_relation')->where(['goods_id' => $goodsId])->select()->toArray();
|
|
|
- $specAttrId = Db::name('shop_goods_spec_type')->where(['id' => $specRelation[0]['spec_id']])->value('pid');
|
|
|
|
|
- $specType = Db::name('shop_goods_spec_type')->select()->toArray();
|
|
|
|
|
- $specType = app()->make(Tree::class)->DeepTree($specType, 'child');
|
|
|
|
|
- $specTypeArr = [];
|
|
|
|
|
|
|
+ $specAttrId = Db::name('shop_goods_spec_type')->where(['id' => $specRelation[0]['spec_id']])->value('pid');
|
|
|
|
|
+ $specType = Db::name('shop_goods_spec_type')->select()->toArray();
|
|
|
|
|
+ $specType = app()->make(Tree::class)->DeepTree($specType, 'child');
|
|
|
|
|
+ $specTypeArr = [];
|
|
|
foreach ($specType as $k => $v) {
|
|
foreach ($specType as $k => $v) {
|
|
|
if ($v['id'] == $specAttrId) {
|
|
if ($v['id'] == $specAttrId) {
|
|
|
if (isset($v['child']))
|
|
if (isset($v['child']))
|
|
@@ -136,7 +106,7 @@ class Goods extends AdminController
|
|
|
|
|
|
|
|
$specRelationArr = array_column($specRelationArr, 'id');
|
|
$specRelationArr = array_column($specRelationArr, 'id');
|
|
|
foreach ($specTypeArr as $k => &$v) {
|
|
foreach ($specTypeArr as $k => &$v) {
|
|
|
- if(isset($v['child'])) {
|
|
|
|
|
|
|
+ if (isset($v['child'])) {
|
|
|
foreach ($v['child'] as $ck => &$cv) {
|
|
foreach ($v['child'] as $ck => &$cv) {
|
|
|
if (in_array($cv['id'], $specRelationArr)) {
|
|
if (in_array($cv['id'], $specRelationArr)) {
|
|
|
$cv['checked'] = true;
|
|
$cv['checked'] = true;
|
|
@@ -148,21 +118,21 @@ class Goods extends AdminController
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$goodsSkuArr = [];
|
|
$goodsSkuArr = [];
|
|
|
- $goodsSku = Db::name('shop_goods_spec')->where(['goods_id' => $goodsId])->select()->toArray();
|
|
|
|
|
|
|
+ $goodsSku = Db::name('shop_goods_spec')->where(['goods_id' => $goodsId])->select()->toArray();
|
|
|
foreach ($goodsSku as $sk => $sv) {
|
|
foreach ($goodsSku as $sk => $sv) {
|
|
|
- $goodsSkuArr['skus[' . $sv['spec_ids'] . '][picture]'] = $sv['picture'];
|
|
|
|
|
- $goodsSkuArr['skus[' . $sv['spec_ids'] . '][price]'] = $sv['price'];
|
|
|
|
|
- $goodsSkuArr['skus[' . $sv['spec_ids'] . '][cost_price]'] = $sv['cost_price'];
|
|
|
|
|
- $goodsSkuArr['skus[' . $sv['spec_ids'] . '][weight]'] = $sv['weight'];
|
|
|
|
|
- $goodsSkuArr['skus[' . $sv['spec_ids'] . '][stock]'] = $sv['stock'];
|
|
|
|
|
|
|
+ $goodsSkuArr['skus[' . $sv['spec_ids'] . '][picture]'] = $sv['picture'];
|
|
|
|
|
+ $goodsSkuArr['skus[' . $sv['spec_ids'] . '][price]'] = $sv['price'];
|
|
|
|
|
+ $goodsSkuArr['skus[' . $sv['spec_ids'] . '][cost_price]'] = $sv['cost_price'];
|
|
|
|
|
+ $goodsSkuArr['skus[' . $sv['spec_ids'] . '][weight]'] = $sv['weight'];
|
|
|
|
|
+ $goodsSkuArr['skus[' . $sv['spec_ids'] . '][stock]'] = $sv['stock'];
|
|
|
$goodsSkuArr['skus[' . $sv['spec_ids'] . '][rebate_score]'] = $sv['rebate_score'];
|
|
$goodsSkuArr['skus[' . $sv['spec_ids'] . '][rebate_score]'] = $sv['rebate_score'];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$data = [
|
|
$data = [
|
|
|
'code' => 0,
|
|
'code' => 0,
|
|
|
- 'msg' => '',
|
|
|
|
|
|
|
+ 'msg' => '',
|
|
|
'spec' => $specTypeArr,
|
|
'spec' => $specTypeArr,
|
|
|
- 'sku' => $goodsSkuArr
|
|
|
|
|
|
|
+ 'sku' => $goodsSkuArr
|
|
|
];
|
|
];
|
|
|
return json($data);
|
|
return json($data);
|
|
|
}
|
|
}
|
|
@@ -175,25 +145,25 @@ class Goods extends AdminController
|
|
|
{
|
|
{
|
|
|
if ($this->request->isAjax()) {
|
|
if ($this->request->isAjax()) {
|
|
|
$goods = $this->request->post();
|
|
$goods = $this->request->post();
|
|
|
- Db::startTrans();
|
|
|
|
|
- try {
|
|
|
|
|
- if (!isset($goods['is_exist_many_spec'])) {
|
|
|
|
|
- $flag = ShopGoods::singleSpecGoods($goods);
|
|
|
|
|
- } else {
|
|
|
|
|
- $flag = ShopGoods::manySpecGoods($goods);
|
|
|
|
|
- }
|
|
|
|
|
- Db::commit();
|
|
|
|
|
|
|
+ Db::startTrans();
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (!isset($goods['is_exist_many_spec'])) {
|
|
|
|
|
+ $flag = ShopGoods::singleSpecGoods($goods);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $flag = ShopGoods::manySpecGoods($goods);
|
|
|
|
|
+ }
|
|
|
|
|
+ Db::commit();
|
|
|
|
|
|
|
|
- }catch (\Exception $e){
|
|
|
|
|
- Db::rollback();
|
|
|
|
|
- $this->error($e->getMessage());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ Db::rollback();
|
|
|
|
|
+ $this->error($e->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
$this->success('成功');
|
|
$this->success('成功');
|
|
|
// return $flag ? json(['code' => 1, 'msg' => '发布成功']) :
|
|
// return $flag ? json(['code' => 1, 'msg' => '发布成功']) :
|
|
|
// json(['code' => 0, 'msg' => '发布失败']);
|
|
// json(['code' => 0, 'msg' => '发布失败']);
|
|
|
}
|
|
}
|
|
|
- $hot_keywords = Db::name('shop_hot_keywords')->select()->toArray();
|
|
|
|
|
|
|
+ $hot_keywords = Db::name('shop_hot_keywords')->select()->toArray();
|
|
|
$shop_supplier = Db::name('shop_supplier')->select()->toArray();
|
|
$shop_supplier = Db::name('shop_supplier')->select()->toArray();
|
|
|
$this->assign('hot_keywords', $hot_keywords);
|
|
$this->assign('hot_keywords', $hot_keywords);
|
|
|
$this->assign('shop_supplier', $shop_supplier);
|
|
$this->assign('shop_supplier', $shop_supplier);
|
|
@@ -203,7 +173,7 @@ class Goods extends AdminController
|
|
|
/**
|
|
/**
|
|
|
* @NodeAnotation(title="商品编辑")
|
|
* @NodeAnotation(title="商品编辑")
|
|
|
*/
|
|
*/
|
|
|
- public function edit ($id)
|
|
|
|
|
|
|
+ public function edit($id)
|
|
|
{
|
|
{
|
|
|
if ($this->request->isAjax()) {
|
|
if ($this->request->isAjax()) {
|
|
|
$goods = $this->request->post();
|
|
$goods = $this->request->post();
|
|
@@ -215,7 +185,7 @@ class Goods extends AdminController
|
|
|
ShopGoods::manySpecGoods($goods);
|
|
ShopGoods::manySpecGoods($goods);
|
|
|
}
|
|
}
|
|
|
Db::commit();
|
|
Db::commit();
|
|
|
- }catch (\Exception $e){
|
|
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
Db::rollback();
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
}
|
|
@@ -227,7 +197,7 @@ class Goods extends AdminController
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- public function copy ($id)
|
|
|
|
|
|
|
+ public function copy($id)
|
|
|
{
|
|
{
|
|
|
if ($this->request->isAjax()) {
|
|
if ($this->request->isAjax()) {
|
|
|
$goods = $this->request->post();
|
|
$goods = $this->request->post();
|
|
@@ -239,7 +209,7 @@ class Goods extends AdminController
|
|
|
$flag = ShopGoods::manySpecGoods($goods);
|
|
$flag = ShopGoods::manySpecGoods($goods);
|
|
|
}
|
|
}
|
|
|
Db::commit();
|
|
Db::commit();
|
|
|
- }catch (\Exception $e){
|
|
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
Db::rollback();
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
}
|
|
@@ -255,7 +225,7 @@ class Goods extends AdminController
|
|
|
/**
|
|
/**
|
|
|
* @NodeAnotation(title="入库")
|
|
* @NodeAnotation(title="入库")
|
|
|
*/
|
|
*/
|
|
|
- public function stock ($id)
|
|
|
|
|
|
|
+ public function stock($id)
|
|
|
{
|
|
{
|
|
|
$sku = Db::name('shop_goods_spec')->where(['goods_id' => $id])->select()->toArray();
|
|
$sku = Db::name('shop_goods_spec')->where(['goods_id' => $id])->select()->toArray();
|
|
|
$this->assign('sku', $sku);
|
|
$this->assign('sku', $sku);
|
|
@@ -270,11 +240,11 @@ class Goods extends AdminController
|
|
|
foreach ($data as $k => $v) {
|
|
foreach ($data as $k => $v) {
|
|
|
$stock[] = [
|
|
$stock[] = [
|
|
|
'goods_spec_id' => explode('_', $k)[1],
|
|
'goods_spec_id' => explode('_', $k)[1],
|
|
|
- 'stock' => $v
|
|
|
|
|
|
|
+ 'stock' => $v
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
$ShopGoodsSpec = new ShopGoodsSpec();
|
|
$ShopGoodsSpec = new ShopGoodsSpec();
|
|
|
- $flag = $ShopGoodsSpec->saveAll($stock);
|
|
|
|
|
|
|
+ $flag = $ShopGoodsSpec->saveAll($stock);
|
|
|
|
|
|
|
|
return $flag ? json(['code' => 1, 'msg' => '保存成功']) :
|
|
return $flag ? json(['code' => 1, 'msg' => '保存成功']) :
|
|
|
json(['code' => 0, 'msg' => '保存失败']);
|
|
json(['code' => 0, 'msg' => '保存失败']);
|