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
<?php
 
namespace app\operations\controller\plus\agent;
 
use app\common\library\helper;
use app\common\model\plus\agent\Setting as AgentSetting;
use app\common\model\plus\agent\Setting as AgentSettingModel;
use app\operations\controller\Controller;
use app\operations\model\plus\agent\Grade as AgentGradeModel;
use app\operations\model\product\Product as ProductModel;
use app\operations\service\ProductService;
use app\operations\model\plus\agent\Product as AgentProductModel;
use app\operations\model\product\Category as CategoryModel;
 
/**
 * 商品运营控制器
 */
class Product extends Controller
{
    /**
     * 商品列表
     */
    public function index()
    {
        $model = new ProductModel;
        $list = $model->getList(array_merge(['status' => -1], $this->postData()));
        // 商品分类
        $category = CategoryModel::getCacheTree();
        return $this->renderSuccess('', compact('list', 'category'));
    }
 
    /**
     * 编辑分销商
     */
    public function edit($product_id)
    {
        $model = new AgentProductModel();
        if ($this->request->isGet()) {
            // 平台分销规则
            $basicSetting = AgentSetting::getItem('basic');
            $agent_product = AgentProductModel::detail($product_id);
            return $this->renderSuccess('', compact('agent_product', 'basicSetting'));
        }
        if ($model->edit($this->postData())) {
            return $this->renderSuccess('操作成功');
        }
        return $this->renderError($model->getError() ?: '操作失败');
    }
 
    /**
     * 设置状态
     */
    public function setAgent($productIds, $is_agent)
    {
        $model = new AgentProductModel();
        if ($model->setAgent($productIds, $is_agent)) {
            return $this->renderSuccess('操作成功');
        }
        return $this->renderError($model->getError() ?: '操作失败');
    }
}