quanwei
2025-11-21 2d9362ae6f528f57e6133d5d80f0b633c24e8eb6
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
<?php
 
namespace app\supplier\controller\activity;
 
use app\common\model\product\Product as ProductModel;
use app\supplier\controller\Controller;
use app\supplier\model\plus\point\Product as PointProductModel;
use app\common\model\user\Grade as GradeModel;
 
/**
 * 积分活动控制器
 */
class Point extends Controller
{
    /**
     * 添加
     */
    public function add($product_id)
    {
        $grade_list = GradeModel::getUsableList();
        if($this->request->isGet()){
            $model = ProductModel::detail($product_id);
            //会员等级列表 by yj 2024.1.8
            $model["grade_list"] = $grade_list;
            return $this->renderSuccess('', compact('model'));
        }
        $model = new PointProductModel();
        if ($model->checkProduct($product_id)) {
             return $this->renderError('商品已经参加活动了,请勿重复提交');
        }
        if ($model->saveProduct($this->getSupplierId(), $this->postData(),$grade_list)) {
            return $this->renderSuccess('添加成功');
        }
        return $this->renderError($model->getError() ?: '添加失败');
    }
 
    /**
     * 列表
     */
    public function my()
    {
        $supplier = $this->supplier['user'];
        $list = (new PointProductModel())->getList($supplier['shop_supplier_id'], $this->postData());
        //排除id
        $exclude_ids = (new PointProductModel())->getExcludeIds($this->getSupplierId());
        return $this->renderSuccess('', compact('list', 'exclude_ids'));
    }
 
    /**
     * 编辑
     */
    public function edit($point_product_id)
    {
        $grade_list = GradeModel::getUsableList();
        if($this->request->isGet()){
            //商品详情
            $model = PointProductModel::detail($point_product_id, ['product' => ['image.file'],'sku']);
            //会员等级列表 by yj 2024.1.8
            $model["grade_list"] = $grade_list;
            if(!empty($grade_list) && !empty($model["sku"][0]["grade_point"])){
                foreach ($model["sku"] as &$item){
                    $grade_point = [];
                    foreach ($grade_list as $val){
                        foreach ($item["grade_point"] as $vv){
                            if($val["grade_id"] == $vv["grade_id"]){
                                $grade_point[] = $vv["point_num"];
                                continue;
                            }
                        }
                    }
                    $item["grade_point"] = $grade_point;
                }
            }
            return $this->renderSuccess('', compact('model'));
        }
        $data = $this->postData();
        $model = PointProductModel::detail($point_product_id);
        if ($model->edit($data,$grade_list)) {
            return $this->renderSuccess('添加成功');
        }
        return $this->renderError($model->getError() ?:'添加失败');
    }
 
    /**
     * 删除
     */
    public function del($point_product_id)
    {
        $model = PointProductModel::detail($point_product_id);
        if ($model->remove($point_product_id, $this->getSupplierId())) {
            return $this->renderSuccess('删除成功');
        }
        return $this->renderError($model->getError() ?: '删除失败');
    }
}