...
|
...
|
@@ -6,23 +6,23 @@ use app\common\controller\Backend; |
|
|
use fast\Tree;
|
|
|
|
|
|
/**
|
|
|
* 规格管理
|
|
|
* 定制风格值管理
|
|
|
*
|
|
|
* @icon fa fa-circle-o
|
|
|
*/
|
|
|
class SpecValue extends Backend
|
|
|
class StyleValue extends Backend
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
* SpecValue模型对象
|
|
|
* @var \app\admin\model\SpecValue
|
|
|
* StyleValue模型对象
|
|
|
* @var \app\admin\model\StyleValue
|
|
|
*/
|
|
|
protected $model = null;
|
|
|
|
|
|
public function _initialize()
|
|
|
{
|
|
|
parent::_initialize();
|
|
|
$this->model = new \app\admin\model\SpecValue;
|
|
|
$this->model = new \app\admin\model\StyleValue;
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
@@ -54,20 +54,15 @@ class SpecValue extends Backend |
|
|
{
|
|
|
return $this->selectpage();
|
|
|
}
|
|
|
$where['spec_id'] = $this->request->request('spec_id',0);
|
|
|
$style_id = $this->request->request("style_id");
|
|
|
$total = $this->model
|
|
|
->where($where)
|
|
|
->order('weigh desc')
|
|
|
->where('style_id',$style_id)
|
|
|
->count();
|
|
|
|
|
|
$list = $this->model
|
|
|
->where($where)
|
|
|
->order('weigh desc')
|
|
|
->where('style_id',$style_id)
|
|
|
->select();
|
|
|
|
|
|
foreach ($list as $row) {
|
|
|
$row->visible(['id','spec_value','spec_value_image','spec_value_price','updatetime','weigh']);
|
|
|
|
|
|
$row->visible(['id','style_id','style_value_name','style_value_image','style_value_price','updatetime','weigh']);
|
|
|
}
|
|
|
$list = collection($list)->toArray();
|
|
|
$result = array("total" => $total, "rows" => $list);
|
...
|
...
|
@@ -82,7 +77,7 @@ class SpecValue extends Backend |
|
|
*/
|
|
|
public function add()
|
|
|
{
|
|
|
$spec_id = $this->request->request('spec_id');
|
|
|
$style_id = $this->request->request('style_id');
|
|
|
if ($this->request->isPost()) {
|
|
|
$params = $this->request->post("row/a");
|
|
|
if ($params) {
|
...
|
...
|
@@ -92,29 +87,29 @@ class SpecValue extends Backend |
|
|
$params[$this->dataLimitField] = $this->auth->id;
|
|
|
}
|
|
|
|
|
|
if(!empty($params['spec_ids'])){
|
|
|
$spec = new \app\common\model\Spec;
|
|
|
$display_mode = $spec->where('id',$params['spec_id'])->value('display_mode');
|
|
|
if(!empty($params['style_ids'])){
|
|
|
$style = new \app\common\model\Style;
|
|
|
$display_mode = $style->where('id',$params['style_id'])->value('display_mode');
|
|
|
if($display_mode == '2'){
|
|
|
$this->error(__('该规格值,不能选择规格值下规格'));
|
|
|
$this->error(__('该风格值为【风格值下显示风格】的值,不能选择【风格值下显示风格】'));
|
|
|
}
|
|
|
$spec_id_arr = explode(',',$params['spec_ids']);
|
|
|
$parentsIds = Tree::instance()->init(collection($spec->select())->toArray())->getParentsIds($params['spec_id'], true);
|
|
|
foreach($spec_id_arr as $v){
|
|
|
// 规格值下规格,不能是所属规格的父规格或所属规格
|
|
|
$style_id_arr = explode(',',$params['style_ids']);
|
|
|
$parentsIds = Tree::instance()->init(collection($style->select())->toArray())->getParentsIds($params['style_id'], true);
|
|
|
foreach($style_id_arr as $v){
|
|
|
// 选项下风格,不能是所属风格的父风格或所属风格
|
|
|
if (in_array($v, $parentsIds)) {
|
|
|
$this->error(__('规格值下规格,不能是所属规格的父规格或所属规格'));
|
|
|
$this->error(__('风格值下风格,不能是所属风格的父风格或所属风格'));
|
|
|
}
|
|
|
// 规格值下的规格,只能出现在一个地方
|
|
|
// 选项下的风格,只能出现在一个地方
|
|
|
$has = $this->model
|
|
|
->alias('v')
|
|
|
->join('spec s','s.id = v.spec_id')
|
|
|
->where("FIND_IN_SET('{$v}', v.spec_ids)")
|
|
|
->field('v.spec_id,s.spec_name')
|
|
|
->join('style s','s.id = v.style_id')
|
|
|
->where("FIND_IN_SET('{$v}', v.style_ids)")
|
|
|
->field('v.style_id,s.style_name')
|
|
|
->find();
|
|
|
if($params['spec_id'] != $has['spec_id']){
|
|
|
$spec_name = $spec->where('id',$v)->value('spec_name');
|
|
|
$this->error(__($spec_name.' 已被 '.$has['spec_name'].' 下规格值使用'));
|
|
|
if($params['style_id'] != $has['style_id']){
|
|
|
$style_name = $style->where('id',$v)->value('style_name');
|
|
|
$this->error(__($style_name.' 已被 '.$has['style_name'].' 下风格值使用'));
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -140,8 +135,8 @@ class SpecValue extends Backend |
|
|
}
|
|
|
$this->error(__('Parameter %s can not be empty', ''));
|
|
|
}
|
|
|
$this->view->assign("spec_id", $spec_id);
|
|
|
$this->view->assign("spec_template_id", \app\common\model\Spec::where('id',$spec_id)->value('spec_template_id'));
|
|
|
$this->view->assign("style_id", $style_id);
|
|
|
$this->view->assign("style_template_id", \app\common\model\Style::where('id',$style_id)->value('style_template_id'));
|
|
|
return parent::add();
|
|
|
}
|
|
|
|
...
|
...
|
@@ -165,29 +160,29 @@ class SpecValue extends Backend |
|
|
if ($params) {
|
|
|
$params = $this->preExcludeFields($params);
|
|
|
|
|
|
if(!empty($params['spec_ids'])){
|
|
|
$spec = new \app\common\model\Spec;
|
|
|
$display_mode = $spec->where('id',$params['spec_id'])->value('display_mode');
|
|
|
if(!empty($params['style_ids'])){
|
|
|
$style = new \app\common\model\Style;
|
|
|
$display_mode = $style->where('id',$params['style_id'])->value('display_mode');
|
|
|
if($display_mode == '2'){
|
|
|
$this->error(__('该规格值,不能选择规格值下规格'));
|
|
|
$this->error(__('该风格值为【风格值下显示风格】的值,不能选择【风格值下显示风格】'));
|
|
|
}
|
|
|
$spec_id_arr = explode(',',$params['spec_ids']);
|
|
|
$parentsIds = Tree::instance()->init(collection($spec->select())->toArray())->getParentsIds($params['spec_id'], true);
|
|
|
foreach($spec_id_arr as $v){
|
|
|
// 规格值下规格,不能是所属规格的父规格或所属规格
|
|
|
$style_id_arr = explode(',',$params['style_ids']);
|
|
|
$parentsIds = Tree::instance()->init(collection($style->select())->toArray())->getParentsIds($params['style_id'], true);
|
|
|
foreach($style_id_arr as $v){
|
|
|
// 选项下风格,不能是所属风格的父风格或所属风格
|
|
|
if (in_array($v, $parentsIds)) {
|
|
|
$this->error(__('规格值下规格,不能是所属规格的父规格或所属规格'));
|
|
|
$this->error(__('风格值下风格,不能是所属风格的父风格或所属风格'));
|
|
|
}
|
|
|
// 规格值下的规格,只能出现在一个地方
|
|
|
// 选项下的风格,只能出现在一个地方
|
|
|
$has = $this->model
|
|
|
->alias('v')
|
|
|
->join('spec s','s.id = v.spec_id')
|
|
|
->where("FIND_IN_SET('{$v}', v.spec_ids) and v.spec_id != {$params['spec_id']}")
|
|
|
->field('v.spec_id,s.spec_name')
|
|
|
->join('style s','s.id = v.style_id')
|
|
|
->where("FIND_IN_SET('{$v}', v.style_ids) and v.style_id != {$params['style_id']}")
|
|
|
->field('v.style_id,s.style_name')
|
|
|
->find();
|
|
|
if($has){
|
|
|
$spec_name = $spec->where('id',$v)->value('spec_name');
|
|
|
$this->error(__($spec_name.' 已被 '.$has['spec_name'].' 下规格值使用'));
|
|
|
$style_name = $style->where('id',$v)->value('style_name');
|
|
|
$this->error(__($style_name.' 已被 '.$has['style_name'].' 下风格值使用'));
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -214,7 +209,7 @@ class SpecValue extends Backend |
|
|
$this->error(__('Parameter %s can not be empty', ''));
|
|
|
}
|
|
|
$this->view->assign("row", $row);
|
|
|
$this->view->assign("spec_template_id", \app\common\model\Spec::where('id',$row['spec_id'])->value('spec_template_id'));
|
|
|
$this->view->assign("style_template_id", \app\common\model\Style::where('id',$row['style_id'])->value('style_template_id'));
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
} |
...
|
...
|
|