chengkun
2025-08-29 a370f8c298c691b18f713d4db19919162fbd3299
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
 
namespace app\admin\controller;
 
use app\supplier\model\GoodsAnnex;
use think\facade\Config;
use think\facade\Db;
use think\facade\Request;
use think\facade\View;
use think\Exception;
 
class GoodsBrand extends Common {
    /*
     * 品牌管理
     */
    public function index(): string {
        View::assign('menuitem', strtolower('goodsBrand-index'));
        $other['title'] = '品牌管理';
        $guide['one']['text'] = '数据审核';
        $guide['two']['text'] = '品牌审核';
        $guide['two']['url'] = url('/admin/supplier/index')->build();
        View::assign('guide', $guide);
        View::assign('other', $other);
        return View::fetch('index');
    }
    
    /*
     * 获取商品品牌列表
     */
    public function getGoodsBrandList() {
        try {
            if (!Request::isPost()) {
                throw new Exception(lang('request_method_incorrect'));
            }
            $kw = input('kw');
            $condition['istemp'] = 1;
            $condition['finish_status'] = 1;
            $condition['status'] = 0;
            if (!empty($kw)) {
                $condition[] = array('brand_name', 'like', "%$kw%");
            }
            $p = input('page', 1);
            $_GET['p'] = $p;
            $other['page_size'] = input('page_size', 20);
            $order = 'id desc';
            $count = Db::name('goods_brand')->where($condition)->count();
            $list = Db::name('goods_brand')->field("*")->where($condition)->order($order)->page($p, $other['page_size'])->select()->toArray();
            $other['count'] = $count;
            if (!$list) {
                $list = [];
            }
            $result['code'] = 200;
            $result['list'] = $list;
            $result['other'] = $other;
            return $this->successResponse($result);
            
        } catch (\Exception $exc) {
            return $this->errorResponse($exc->getMessage());
        }
    }
    
    
    /*
     * 获取品牌证书列表
     */
    public function getBrandCertList() {
        try {
            if (!Request::isPost()) {
                throw new Exception(lang('request_method_incorrect'));
            }
            $brand_id = input('brand_id');
            $where['brand_id'] = $brand_id;
            $list = Db::name('goods_brand_cert')->field('id,title,filename,filesize,ext')->where($where)->withAttr('filesize', function ($value) {
                return getsizebytype($value);
            })->order('id asc')->select()->toArray();///
            if ($list) {
                $result['list'] = $list;
                return $this->successResponse($result);
            } else {
                throw new Exception(lang('no_data_found'));
            }
        } catch (\Exception $exc) {
            return $this->errorResponse($exc->getMessage());
        }
    }
    
    
    /*
     * 获取品牌协议列表
     */
    public function getBrandAgreementList() {
        try {
            if (!Request::isPost()) {
                throw new Exception(lang('request_method_incorrect'));
            }
            $brand_id = input('brand_id');
            $where['brand_id'] = $brand_id;
            $list = Db::name('goods_brand_agreement')->field('id,title,filename,filesize,ext')->where($where)->withAttr('filesize', function ($value) {
                return getsizebytype($value);
            })->order('id asc')->select()->toArray();///
            if ($list) {
                $result['list'] = $list;
                return $this->successResponse($result);
            } else {
                throw new Exception(lang('no_data_found'));
            }
        } catch (\Exception $exc) {
            return $this->errorResponse($exc->getMessage());
        }
    }
    
    
    /*
     * 获取品牌备案范围列表
     */
    public function getGoodsBrandFilingsList() {
        try {
            if (!Request::isPost()) {
                throw new Exception(lang('request_method_incorrect'));
            }
            $brand_id = input('brand_id');
            $where['GBF.brand_id'] = $brand_id;
            $list = Db::name('goods_brand_filings')
                ->alias('GBF')
                ->join('stock_country SC', 'GBF.stock_country_id=SC.id')
                ->join('dis_platform DP', 'GBF.dis_platform_id=DP.id')
                ->field('GBF.*,SC.country,DP.platform_name')->where($where)->order('GBF.id asc')->select()->toArray();///
            if ($list) {
                $result['list'] = $list;
                return $this->successResponse($result);
            } else {
                throw new Exception(lang('no_data_found'));
            }
        } catch (\Exception $exc) {
            return $this->errorResponse($exc->getMessage());
        }
    }
    
    /**
     * 品牌审核
     * @return array|int[]
     */
    public function reviewGoodsBrand() {
        // 开始数据库事务
        Db::startTrans();
        try {
            if (!Request::isPost()) {
                throw new Exception(lang('request_method_incorrect'));
            }
            $brand_id = input('post.brand_id');
            if (is_numeric($brand_id)) {
                $status = input('post.status');
                //更新数据
                $info = Db::name('goods_brand')->field('id,status')->where('id', $brand_id)->find();
                if (!$info) {
                    throw new Exception(lang('no_data_found'));
                }
                if ($info['status'] == 1) {
                    throw new Exception('该申请已审核通过,不能重复审核');
                }
                if ($status == 1) {
                    Db::name('goods_brand')->where('id', $brand_id)->update(['status' => 1]);
                    $message = '操作成功,审核通过';
                } else {
                    Db::name('goods_brand')->where('id', $brand_id)->update(['status' => 2]);
                    $message = '操作成功,审核不通过';
                }
                // 提交事务
                Db::commit();
                return $this->successResponse($message);
            } else {
                return $this->errorResponse(lang('request_method_incorrect'));
            }
        } catch (Exception $exc) {
            // 回滚事务
            Db::rollback();
            return $this->errorResponse($exc->getMessage());
        }
    }
    
}