Commit 7633b78a by 杨树贤

分类列表服务

parent 91a5b47d
......@@ -52,11 +52,12 @@ SKU_8_DB_DATABASE=liexin_sku_8
SKU_9_DB_DATABASE=liexin_sku_9
DB_CONNECTION=mysql
DB_HOST=192.168.1.235
DB_USERNAME=icDb29mLy2s
DB_PASSWORD=icDb29mLy2s
DB_HOST=192.168.2.239
DB_USERNAME=root
DB_PASSWORD=root
DB_PORT=3306
DB_DATABASE=0
DB_DATABASE=lc_footstone
DB_PREFIX=lie_
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 @@
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
class SelfClassifyModel extends Model
{
protected $connection=false;
protected $table='self_classify';
protected $connection = false;
protected $table = 'self_classify';
public $timestamps = false;
//生成自营分类redis
public function ProduceClassRedis($class_id='',$Redis=''){
if(empty($class_id)) 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;
public function ProduceClassRedis($class_id = '', $Redis = '')
{
if (empty($class_id)) {
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;
}
//二级分类关联模型
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([
], function ($router) {
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;
......@@ -13,6 +13,7 @@
$router->get('/', function () use ($router) {
return swoole_get_local_ip();
return $router->app->version();
});
......@@ -20,7 +21,10 @@ $router->get('/', function () use ($router) {
$router->post('/synchronization', 'ServicesController@synchronization');
$router->post('/ladderprice', 'ServicesController@ladderprice');
$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('/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