Spec.php
2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace app\admin\controller;
use app\common\controller\Backend;
use fast\Tree;
/**
* 规格管理
*
* @icon fa fa-circle-o
*/
class Spec extends Backend
{
/* @var SpecModel $SpecModel */
private $SpecModel;
/* @var SpecValueModel $SpecModel */
private $SpecValueModel;
public function _initialize()
{
parent::_initialize();
$this->SpecModel = new \app\admin\model\Spec;
$this->SpecValueModel = new \app\admin\model\SpecValue;
}
/**
* 添加规则组
*/
public function addSpec($spec_name, $spec_value_name)
{
// 判断规格组是否存在
if (!$specId = $this->SpecModel->getSpecIdByName($spec_name)) {
// 新增规格组and规则值
if ($this->SpecModel->add($spec_name)
&& $this->SpecValueModel->add($this->SpecModel['id'], $spec_value_name))
$this->success('', null, [
'spec_id' => (int)$this->SpecModel['id'],
'spec_value_id' => (int)$this->SpecValueModel['id'],
]);
$this->error();
}
// 判断规格值是否存在
if ($specValueId = $this->SpecValueModel->getSpecValueIdByName($specId, $spec_value_name)) {
$this->success('', null, [
'spec_id' => (int)$specId,
'spec_value_id' => (int)$specValueId,
]);
}
// 添加规则值
if ($this->SpecValueModel->add($specId, $spec_value_name))
$this->success('', null, [
'spec_id' => (int)$specId,
'spec_value_id' => (int)$this->SpecValueModel['id'],
]);
$this->error();
}
/**
* 添加规格值
*/
public function addSpecValue($spec_id, $spec_value_name)
{
// 判断规格值是否存在
if ($specValueId = $this->SpecValueModel->getSpecValueIdByName($spec_id, $spec_value_name)) {
$this->success('', null, [
'spec_value_id' => (int)$specValueId,
]);
}
// 添加规则值
if ($this->SpecValueModel->add($spec_id, $spec_value_name))
$this->success('', null, [
'spec_value_id' => (int)$this->SpecValueModel['id'],
]);
$this->error();
}
}