adminInfo = get_login_admin(); $this->temp = $temp; $this->url=[ '/admin/product/params/index', '/admin/product/params/add', '/admin/product/params/edit', '/admin/product/params/del', ]; } /** * 非超级管理员登入 需更新当前用户所属地区 * @param array $where 地区id数组 * @return array $where 更改后的地区id数组 */ protected function auth(array $where):array { if($this->adminInfo['position_id'] != 1){ //不是超级管理员 $www['admin_id'] = $this->adminInfo['id']; $user_address = Db::table('fa_szxc_information_useraddress')->where($www)->find(); if ($user_address){ if($user_address['auth_range'] == 1){ $where[] = ['village_id','=',$user_address['village_id']]; }elseif ($user_address['auth_range'] == 2){ $where[] = ['street_id','=',$user_address['street_id']]; }elseif ($user_address['auth_range'] == 3){ $where[] = ['area_id','=',$user_address['area_id']]; }else{ $where[] = ['village_id','=',$user_address['village_id']]; } }else{ $where[] = ['village_id','=','']; } } return $where; } /** * 商品参数列表 * @ */ public function index(StoreCategory $category) { if (request()->isAjax()) { // Ajax 获取列表数据 $params= get_params(); // 构建查询条件 $where = []; if (isset($params['keywords']) && !empty($params['keywords'])){ $where[]= ['name','like','%'.$params['keywords'].'%']; } $where = $this->auth($where); // 获取列表数据 $page = empty($params['page'])? 1 : (int)$params['page']; $limit = empty($params['limit'])? (int)get_config('app . page_size') : (int)$params['limit']; $where['template_name'] = empty($params['template_name'])?'':$params['template_name']; $where['cate_id'] = empty($params['cate_id'])?'':$params['cate_id']; $where['mer_name'] = empty($params['mer_name'])?'':$params['mer_name']; $where['mer_id'] = empty($params['mer_id'])?'':$params['mer_id']; if (isset($params['is_mer'])) { $merId = $params['mer_id']; $where['mer_id'] = $merId; unset($where['is_mer']); } $data = $this->temp->getList($where,$page, $limit); $data['list'] = [[ 'template_id'=>1, 'template_name'=>'测试', 'cateid'=>'', 'sort'=>'1', 'create_time'=> '2023-03-09 17:13:22', ]]; return to_assign(0, '', $data); }else{ // 初始空页面展示 $where['mer_id'] = 0; $where['is_show'] = 0; $cate_list = $category->getList($where); $cate_list = FormatList::DropDownMenu($cate_list); View::assign('url', $this->url); View::assign('cate_list', $cate_list); return view(); } } /** * * 新增 * */ public function add() { if (request()->isAjax()) { $params = get_params(); $data['cate_name'] = $params['cate_name']; // 分类名称 $data['is_show'] = isset($params['is_show']) && $params['is_show'] == 'on'? 1:0; // 是否显示 $data['pid'] = $params['pid']; // 上级分类 $data['sort'] = $params['sort']; // 排序 $data['create_time'] = date('Y-m-d H:i:s'); // 数据入库 // $res = StoreBrandCategory::create($data); // if ($res){ // return to_assign(0,'操作成功',['aid'=>$res]); // } // return to_assign(1, '操作失败,原因:'.$res); }else{ View::assign('editor', get_system_config('other','editor')); View::assign('url', $this->url); return view(); } } /** * * 编辑 * */ public function edit() { $id = get_params("id"); if(!$id) return to_assign(1, '非法操作!'); if (request()->isAjax()) { $params = get_params(); $data['cate_name'] = $params['cate_name']; // 分类名称 $data['is_show'] = isset($params['is_show']) && $params['is_show'] == 'on'? 1:0; // 是否显示 $data['pid'] = $params['pid']; // 上级分类 $data['sort'] = $params['sort']; // 排序 $data['create_time'] = date('Y-m-d H:i:s'); // 数据更新 $res = StoreBrandCategory::where('store_brand_category_id', $params['id'])->update($data); if ($res){ return to_assign(0,'更新成功',['aid'=>$res]); } return to_assign(1, '更新失败,原因:'.$res); }else{ $storeBrandCtegory = StoreBrandCategory::find($id); // 取出当前品牌分类信息 View::assign('detail', $storeBrandCtegory); View::assign('url', $this->url); return view(); } } /** * * 删除 * */ public function del() { $id = get_params("id"); if(!$id) return to_assign(1, '非法操作!'); // 验证下面是否有子分类 if(StoreBrandCategory::where('pid', $id)->count()) { return to_assign(1, '请先删除子分类!'); } $res = StoreBrandCategory::where('store_brand_category_id', $id)->delete(); if ($res){ return to_assign(0,'操作成功',['aid'=>$res]); } return to_assign(1, '操作失败,原因:'.$res); } /** * * 子分类 * */ public function street($pcode) { $storeBrandCategory = StoreBrandCategory::order('sort desc') ->where('is_show', 1) ->where('pid', $pcode) ->select(); return json($storeBrandCategory); } }