<?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());
|
}
|
}
|
|
}
|