Commit 7633b78a by 杨树贤

分类列表服务

parent 91a5b47d
...@@ -52,11 +52,12 @@ SKU_8_DB_DATABASE=liexin_sku_8 ...@@ -52,11 +52,12 @@ SKU_8_DB_DATABASE=liexin_sku_8
SKU_9_DB_DATABASE=liexin_sku_9 SKU_9_DB_DATABASE=liexin_sku_9
DB_CONNECTION=mysql DB_CONNECTION=mysql
DB_HOST=192.168.1.235 DB_HOST=192.168.2.239
DB_USERNAME=icDb29mLy2s DB_USERNAME=root
DB_PASSWORD=icDb29mLy2s DB_PASSWORD=root
DB_PORT=3306 DB_PORT=3306
DB_DATABASE=0 DB_DATABASE=lc_footstone
DB_PREFIX=lie_
REDIS_HOST=192.168.1.235 REDIS_HOST=192.168.1.235
......
<?php
namespace App\Http\Controllers;
use App\Model\SelfClassifyModel;
use Illuminate\Http\Request;
class ClassController extends Controller
{
public function classList(Request $request, SelfClassifyModel $model)
{
$classifications = $model->getClass();
return $this->Export(0, 'ok', ['data' => $classifications]);
}
}
\ No newline at end of file
...@@ -3,27 +3,71 @@ ...@@ -3,27 +3,71 @@
namespace App\Model; namespace App\Model;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
class SelfClassifyModel extends Model class SelfClassifyModel extends Model
{ {
protected $connection=false; protected $connection = false;
protected $table='self_classify'; protected $table = 'self_classify';
public $timestamps = false; public $timestamps = false;
//生成自营分类redis //生成自营分类redis
public function ProduceClassRedis($class_id='',$Redis=''){ public function ProduceClassRedis($class_id = '', $Redis = '')
if(empty($class_id)) return false; {
if(empty($Redis)) $Redis=new RedisModel(); if (empty($class_id)) {
$info=json_decode($Redis->hget('Self_SelfClassInfo',$class_id),true); return false;
if(!$info){
if(empty($this->connection)) $this->connection='self';
$info=$this->where('class_id','=',$class_id)->select('class_id','class_name','parent_id','sort','status','class_icon','ladder', 'is_dc')->first();
if($info){
$info=$info->toArray();
if(!empty($info['ladder'])) $info['ladder']=json_decode($info['ladder'],true);
$Redis->hset('Self_SelfClassInfo',$class_id,json_encode($info));
}else return false;
} }
if (empty($Redis)) {
$Redis = new RedisModel();
}
$info = json_decode($Redis->hget('Self_SelfClassInfo', $class_id), true);
if (!$info) {
if (empty($this->connection)) {
$this->connection = 'self';
}
$info = $this->where('class_id', '=', $class_id)->select('class_id', 'class_name', 'parent_id', 'sort',
'status', 'class_icon', 'ladder', 'is_dc')->first();
if ($info) {
$info = $info->toArray();
if (!empty($info['ladder'])) {
$info['ladder'] = json_decode($info['ladder'], true);
}
$Redis->hset('Self_SelfClassInfo', $class_id, json_encode($info));
} else {
return false;
}
}
return $info; return $info;
} }
//二级分类关联模型
public function sub_class()
{
return $this->hasMany(SelfClassifyModel::class, 'parent_id', 'class_id');
}
//获取一二级分类(有关联关系)
public function getClass()
{
$classificationsExpireMinute = 5;
return Cache::remember('class', $classificationsExpireMinute, function () {
$field = [
'class_id',
'class_name',
'status',
'class_icon',
];
return $this->select($field)->with([
'sub_class' => function ($query) use ($field) {
array_push($field, 'parent_id');
$query->select($field);
},
])->where('status', 1)->where('parent_id', 0)
->orderBy('sort', 'desc')->get()->toArray();
});
}
} }
...@@ -108,4 +108,12 @@ $app->router->group([ ...@@ -108,4 +108,12 @@ $app->router->group([
], function ($router) { ], function ($router) {
require __DIR__.'/../routes/web.php'; require __DIR__.'/../routes/web.php';
}); });
//lumen日志按日分割
$app->configureMonologUsing(function(Monolog\Logger $monoLog) use ($app){
return $monoLog->pushHandler(
new \Monolog\Handler\RotatingFileHandler($app->storagePath().'/logs/lumen.log',5)
);
});
return $app; return $app;
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
$router->get('/', function () use ($router) { $router->get('/', function () use ($router) {
return swoole_get_local_ip(); return swoole_get_local_ip();
return $router->app->version(); return $router->app->version();
}); });
...@@ -20,7 +21,10 @@ $router->get('/', function () use ($router) { ...@@ -20,7 +21,10 @@ $router->get('/', function () use ($router) {
$router->post('/synchronization', 'ServicesController@synchronization'); $router->post('/synchronization', 'ServicesController@synchronization');
$router->post('/ladderprice', 'ServicesController@ladderprice'); $router->post('/ladderprice', 'ServicesController@ladderprice');
$router->post('/uuid', 'ServicesController@uuid'); $router->post('/uuid', 'ServicesController@uuid');
$router->post('/self/sample/class/list', 'ServicesController@SelfSampleClassList'); $router->get('/self/sample/class/list', 'ServicesController@SelfSampleClassList');
$router->post('/self/sample/list', 'ServicesController@SelfSampleList'); $router->post('/self/sample/list', 'ServicesController@SelfSampleList');
$router->post('/get_new_customer_limit', 'ServicesController@getnewCustomerLimit'); $router->post('/get_new_customer_limit', 'ServicesController@getnewCustomerLimit');
//分类
$router->post('/class/list', 'ClassController@classList');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment