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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
 
namespace app\operations\controller\plus\points;
 
use app\operations\controller\Controller;
use app\operations\model\plus\point\Product as PointProductModel;
use app\operations\model\settings\Setting as SettingModel;
use app\operations\model\order\Order as OrderModel;
use app\common\model\product\Product as ProductModel;
 
/**
 * 积分兑换控制器
 */
class Product extends Controller
{
    /**
     *积分商品
     */
    public function index()
    {
        $model = new PointProductModel();
        $list = $model->getList($this->postData());
        return $this->renderSuccess('', compact('list'));
    }
 
    /**
     *添加积分商品
     */
    public function add($product_id)
    {
        if($this->request->isGet()){
            $model = ProductModel::detail($product_id);
            return $this->renderSuccess('', compact('model'));
        }
        $model = new PointProductModel();
        if ($model->checkProduct($product_id)) {
            return $this->renderError('商品已经存在');
        }
        if ($model->saveProduct($this->postData(), false)) {
            return $this->renderSuccess('添加成功');
        }
        return $this->renderError($model->getError() ?: '添加失败');
    }
 
    /**
     *修改商品
     */
    public function edit($point_product_id)
    {
        $model = PointProductModel::detail($point_product_id, ['product.image.file','sku']);
        if($this->request->isGet()){
            return $this->renderSuccess('', compact('model'));
        }
 
        if ($model->saveProduct($this->postData(), true)) {
            return $this->renderSuccess('修改成功');
        }
        return $this->renderError($model->getError() ?: '修改失败');
    }
 
    /**
     *删除商品
     */
    public function delete($id)
    {
        $model = new PointProductModel();
        if ($model->del($id)) {
            return $this->renderSuccess('删除成功');
        }
        return $this->renderError('删除失败');
    }
 
 
    /**
     *配置
     */
    public function settings()
    {
        if($this->request->isGet()){
            $vars['values'] = SettingModel::getItem('pointsmall');
            return $this->renderSuccess('', compact('vars'));
        }
 
        $model = new SettingModel;
        $data = $this->request->param();
        if ($model->edit('pointsmall', $data)) {
            return $this->renderSuccess('操作成功');
        }
    }
 
    /**
     *获取兑换记录
     */
    public function record()
    {
        $model = new OrderModel;
        $list = $model->getExchange($this->postData());
        return $this->renderSuccess('', compact('list'));
 
    }
 
    /**
     * 设置状态
     */
    public function state($point_product_id)
    {
        // 详情
        $model = PointProductModel::detail($point_product_id);
        // 更新记录
        if ($model->setState($this->request->post())) {
            return $this->renderSuccess('操作成功');
        }
        return $this->renderError($model->getError() ?: '操作失败');
    }
}