|
@@ -6,6 +6,7 @@ use App\Models\DistProductCategory as Model;
|
|
|
|
|
|
use App\Models\DistProductParameter;
|
|
|
use Dcat\Admin\Repositories\EloquentRepository;
|
|
|
+use Illuminate\Support\Facades\Session;
|
|
|
|
|
|
class DistProductCategory extends EloquentRepository
|
|
|
{
|
|
@@ -68,24 +69,26 @@ class DistProductCategory extends EloquentRepository
|
|
|
*/
|
|
|
public function get(Grid\Model|\Dcat\Admin\Grid\Model $model)
|
|
|
{
|
|
|
+ // 获取当前登录的分销商/经销商
|
|
|
+ $distributor=Session::get('distributor');
|
|
|
|
|
|
+ // 获取模型对象
|
|
|
$obj = $this->model();
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- $obj->where('dist_user_id',0);
|
|
|
-
|
|
|
- // 将树结构转换为数组
|
|
|
+ // 过滤分销商
|
|
|
+ if ($distributor) {
|
|
|
+ $obj = $obj->where('dist_id', $distributor->id);
|
|
|
+ }
|
|
|
+ // 获取数据
|
|
|
$tree = $obj->get();
|
|
|
|
|
|
- // var_dump($tree->toArray());
|
|
|
-
|
|
|
+ // 构建树形结构
|
|
|
$data=buildTree($tree->toArray());
|
|
|
-
|
|
|
+ // 转换成一维数组
|
|
|
$data=flattenTree($data);
|
|
|
|
|
|
return $model->makePaginator(
|
|
|
- 1, // 传入总记录数
|
|
|
+ count($data), // 传入总记录数
|
|
|
$data // 传入数据二维数组
|
|
|
);
|
|
|
}
|