quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
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
<?php
 
namespace app\operations\controller\plus\assemble;
 
use app\operations\controller\Controller;
use app\operations\model\plus\assemble\Product as AssembleProductModel;
 
/**
 * 产品控制器
 */
class Product extends Controller
{
    /**
     * 产品列表
     */
    public function index()
    {   
        $data = $this->postData();
        $model = new AssembleProductModel;
        $list = $model->getAllList($data);
        return $this->renderSuccess('', compact('list'));
    }
 
    //审核产品
    public function edit($assemble_product_id)
    {
        if ($this->request->isGet()) {
            $detail = AssembleProductModel::detail($assemble_product_id, ['product.sku', 'assembleSku', 'active', 'product.image.file']);
            return $this->renderSuccess('', compact('detail'));
        }
        $data = $this->postData();
        // 修改
        $model = AssembleProductModel::detail($assemble_product_id);
        if ($model->editProduct($data)) {
            return $this->renderSuccess('修改成功');
        }
        return $this->renderError($model->getError() ?: '修改失败');
 
    }
 
    /**
     * 删除商品
     */
    public function delete($assemble_product_id)
    {
        // 详情
        $model = AssembleProductModel::detail($assemble_product_id);
        if ($model->setDelete()) {
            return $this->renderSuccess('删除成功');
        }
        return $this->renderError($model->getError() ?: '删除失败');
    }
 
    /**
     * 设置状态
     */
    public function state($assemble_product_id)
    {
        // 详情
        $model = AssembleProductModel::detail($assemble_product_id);
        // 更新记录
        if ($model->setState($this->request->post())) {
            return $this->renderSuccess('操作成功');
        }
        return $this->renderError($model->getError() ?: '操作失败');
    }
}