CommonApiController.php
3.12 KB
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
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Services\AdminUserService;
use App\Http\Services\CompanyService;
use App\Http\Services\StandardBrandService;
use App\Model\BrandModel;
use App\Model\StandardBrandModel;
use App\Model\SupplierChannelModel;
use Illuminate\Http\Request;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\DB;
//通用API,比如获取品牌列表,分类列表等
class CommonApiController extends Controller
{
public function Entrance(Request $request, $id)
{
$this->$id($request, $id);
}
//获取所有品牌
public function getBrandList($request)
{
$type = $request->get('type');
//如果传的type=0,默认给自营
$type = $type ?: 1;
$model = new BrandModel();
$brandList = $model->getBrandListByType($type);
$this->response(0, 'ok', $brandList);
}
//获取标准品牌
public function getStandardBrandList($request)
{
$list = (new StandardBrandService())->getStandardBrandList($request->all());
$data = array_get($list, 'data');
$lastPage = array_get($list, 'last_page');
$total = array_get($list, 'total');
echo json_encode([
'err_code' => 0,
'err_msg' => 'ok',
'total' => $total,
'count' => $total,
'data' => $data,
'last_page' => $lastPage
]);
exit();
}
private function SearchBrand($request)
{
$brandName = $request->input('brand_name');
$type = $request->input('type');
if (empty($type)) {
$type = 1;
}
$connection = $type == 1 ? 'spu' : 'self';
$table = $type == 1 ? 'brand' : 'brand';
$db = DB::connection($connection)->table($table)->where('status', '1');
if ($brandName) {
$db = $db->where('brand_name', 'like', $brandName . '%');
}
$count = $db->count();
$list = $db->select('brand_name', 'brand_id')->paginate(17);
$list = $list ? $list->toArray() : [];
$data = array_get($list, 'data');
$lastPage = array_get($list, 'last_page');
echo json_encode([
'errcode' => 0,
'errmsg' => 'ok',
'total' => $count,
'count' => $count,
'data' => $data,
'last_page' => $lastPage
]);
}
public function checkCompanyInfo($request)
{
//请求天眼查校验接口
$supplierName = $request->get('supplier_name');
$taxNumber = $request->get('tax_number');
$region = $request->get('region');
$company = [];
if (in_array($region, config('field.NeedCheckCompanyRegion'))) {
$regionType = $region == SupplierChannelModel::REGION_CN ? 1 : 2;
$company = (new CompanyService())->getCompanyInfo($supplierName, $taxNumber, $regionType);
if (!$company) {
$this->response(-1, '获取不到公司');
}
}else{
$this->response(-2, '供应商跳过天眼查校验');
}
$this->response(0, 'ok', $company);
}
}