173 lines
6.0 KiB
PHP
173 lines
6.0 KiB
PHP
|
|
<?php
|
||
|
|
namespace app\api\logic;
|
||
|
|
|
||
|
|
use app\common\basics\Logic;
|
||
|
|
use app\common\model\goods\GoodsCategory;
|
||
|
|
use app\common\model\procurement\Procurementset;
|
||
|
|
use app\common\server\UrlServer;
|
||
|
|
|
||
|
|
class GoodsCategoryLogic extends Logic
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* 获取平台一级分类
|
||
|
|
*/
|
||
|
|
public static function getLevelOneList($p_id=0,$setid=0)
|
||
|
|
{
|
||
|
|
$where = [
|
||
|
|
'del' => 0, // 未删除
|
||
|
|
'is_show' => 1, // 显示
|
||
|
|
'pid' => 0
|
||
|
|
];
|
||
|
|
// 扫码分类
|
||
|
|
$w = "";
|
||
|
|
// if($p_id != 0&&$setid!=0){
|
||
|
|
// $set = Procurementset::where("set_id",$setid)->where("set_state",1)->find();
|
||
|
|
// if($set != null){
|
||
|
|
// if($set['goods_onetype']!=null){
|
||
|
|
// $w = " id in (".$set['goods_onetype'].")";
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// if($p_id != 0&&$setid==0){
|
||
|
|
// $set = Procurementset::where("u_id",$p_id)->where("set_state",1)->order("set_update desc")->limit(1)->find();
|
||
|
|
// if($set != null){
|
||
|
|
// if($set['goods_onetype']!=null){
|
||
|
|
// $w = " id in (".$set['goods_onetype'].")";
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
if($p_id != 0&&$setid!=0){
|
||
|
|
$set = Procurementset::where("set_id",$setid)->where("set_state",1)->find();
|
||
|
|
if($set != null){
|
||
|
|
if($set['goods_onetype']!=null){
|
||
|
|
$type_arr = "";
|
||
|
|
$set_array = json_decode($set['goods_onetype'], true);
|
||
|
|
foreach($set_array as $key=>$value){
|
||
|
|
if($key == 0){
|
||
|
|
$type_arr = $value['id'];
|
||
|
|
}else{
|
||
|
|
$type_arr.= ",".$value['id'];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$w = " id in (".$type_arr.")";
|
||
|
|
}
|
||
|
|
// if ($set['set_pro'] != 0) {
|
||
|
|
// $set_price_type = 1;
|
||
|
|
// }
|
||
|
|
// if ($set['set_issued'] != 0) {
|
||
|
|
// $set_price_type = 2;
|
||
|
|
// }
|
||
|
|
// if ($set['set_wholesale'] != 0) {
|
||
|
|
// $set_price_type = 3;
|
||
|
|
// }
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if($p_id != 0&&$setid==0){
|
||
|
|
$set = Procurementset::where("u_id",$p_id)->where("set_state",1)->order("set_update desc")->limit(1)->find();
|
||
|
|
if($set != null){
|
||
|
|
if($set['goods_onetype']!=null){
|
||
|
|
$type_arr = "";
|
||
|
|
$set_array = json_decode($set['goods_onetype'], true);
|
||
|
|
foreach($set_array as $key=>$value){
|
||
|
|
if($key == 0){
|
||
|
|
$type_arr = $value['id'];
|
||
|
|
}else{
|
||
|
|
$type_arr.= ",".$value['id'];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$w = " id in (".$type_arr.")";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
//
|
||
|
|
$list = GoodsCategory::field('id,name,image,bg_image')
|
||
|
|
->withAttr('bg_image', function ($value, $data) {
|
||
|
|
if (!empty($value)) {
|
||
|
|
return UrlServer::getFileUrl($value);
|
||
|
|
}
|
||
|
|
return $value;
|
||
|
|
})
|
||
|
|
->where($where)
|
||
|
|
->where($w)
|
||
|
|
->order('sort', 'asc')
|
||
|
|
->select()
|
||
|
|
->toArray();
|
||
|
|
|
||
|
|
return $list;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 获取一级分类下的后代分类
|
||
|
|
*/
|
||
|
|
public static function getListByLevelOne($id,$p_id,$setid)
|
||
|
|
{
|
||
|
|
$where = [
|
||
|
|
'del' => 0, // 未删除
|
||
|
|
'is_show' => 1, // 显示
|
||
|
|
'pid' => $id
|
||
|
|
];
|
||
|
|
$w = "";
|
||
|
|
// if($p_id != 0&&$setid!=0){
|
||
|
|
// $set = Procurementset::where("set_id",$setid)->where("set_state",1)->find();
|
||
|
|
// if($set != null){
|
||
|
|
// if($set['goods_twotype']!=null) {
|
||
|
|
// $w = " id in (" . $set['goods_twotype'] . ")";
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// if($p_id != 0&&$setid==0){
|
||
|
|
// $set = Procurementset::where("u_id",$p_id)->where("set_state",1)->order("set_update desc")->limit(1)->find();
|
||
|
|
// if($set != null){
|
||
|
|
// if($set['goods_twotype']!=null) {
|
||
|
|
// $w = " id in (" . $set['goods_twotype'] . ")";
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
if($p_id != 0&&$setid!=0){
|
||
|
|
$set = Procurementset::where("set_id",$setid)->where("set_state",1)->find();
|
||
|
|
if($set != null){
|
||
|
|
$second_t = "";
|
||
|
|
$set_array = json_decode($set['goods_onetype'], true);
|
||
|
|
foreach($set_array as $key=>$value){
|
||
|
|
if($value['id'] == $id){
|
||
|
|
$second_t = $value['child_id'];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$w = " id in (" . $second_t . ")";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if($p_id != 0&&$setid==0){
|
||
|
|
$set = Procurementset::where("u_id",$p_id)->where("set_state",1)->order("set_update desc")->limit(1)->find();
|
||
|
|
if($set != null){
|
||
|
|
$second_t = "";
|
||
|
|
$set_array = json_decode($set['goods_onetype'], true);
|
||
|
|
foreach($set_array as $key=>$value){
|
||
|
|
if($value['id'] == $id){
|
||
|
|
$second_t = $value['child_id'];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$w = " id in (" . $second_t . ")";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$list = GoodsCategory::field('id,name,image')
|
||
|
|
->where($where)
|
||
|
|
->where($w)
|
||
|
|
->order('sort', 'asc')
|
||
|
|
->select()
|
||
|
|
->toArray();
|
||
|
|
foreach($list as &$item) {
|
||
|
|
$where = [
|
||
|
|
'del' => 0, // 未删除
|
||
|
|
'is_show' => 1, // 显示
|
||
|
|
'pid' => $item['id']
|
||
|
|
];
|
||
|
|
$item['children'] = GoodsCategory::field('id,name,image')
|
||
|
|
->where($where)
|
||
|
|
->order('sort', 'asc')
|
||
|
|
->select()
|
||
|
|
->toArray();
|
||
|
|
}
|
||
|
|
|
||
|
|
return $list;
|
||
|
|
}
|
||
|
|
}
|