CommonApiController.php
3.15 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
104
105
106
107
108
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Services\AdminUserService;
use App\Model\BrandModel;
use App\Model\SelfClassifyModel;
use App\Model\StandardBrandModel;
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 getSelfClassList($request)
{
$model = new SelfClassifyModel();
$result = $model->getClassList();
return $this->response(0, 'ok', $result);
}
//获取所有品牌
public function getBrandList($request)
{
$type = $request->get('type');
//如果传的type=0,默认给自营
$type = $type ?: 1;
$model = new BrandModel();
$brandList = $model->getBrandListByType($type);
return $this->response(0, 'ok', $brandList);
}
//获取标准品牌
public function getStandardBrandList($request)
{
$model = new BrandModel();
$brandList = $model->getStandardBrandList();
return $this->response(0, 'ok', $brandList);
}
//搜索标准品牌
public function SearchStandardBrand($request)
{
$brandName = $request->input('brand_name');
$standardBrandModel = new StandardBrandModel();
$query = $standardBrandModel->where('status', 1);
if ($brandName) {
$query = $query->where('brand_name', 'like', $brandName . '%');
}
$count = $query->count();
$list = $query->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
]);
}
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 test($request)
{
$as = new AdminUserService();
$as->getPurchaseUsers();
}
}