252 lines
7.4 KiB
PHP
252 lines
7.4 KiB
PHP
<?php
|
||
/**
|
||
* @date :2023年03月9日
|
||
* @author:刘孝全
|
||
* @email:q8197264@126.com
|
||
*
|
||
* @ 商品参数列表与模板添加
|
||
*/
|
||
namespace app\admin\controller\product;
|
||
|
||
use app\admin\BaseController;
|
||
use think\facade\Db;
|
||
use think\facade\View;
|
||
use app\admin\model\Merchant; // 商户模型
|
||
use app\admin\model\StoreCategory; // 商品分类模型
|
||
use app\admin\model\StoreProductReply; // 商品评论模型
|
||
use app\admin\model\Guarantee as GuaranteeModel; // 商品保障服务模型
|
||
use app\admin\model\GeoCity; // 省市模型
|
||
use app\admin\model\GeoArea; // 区域模型
|
||
use app\admin\model\GeoStreet; // 街道模型
|
||
use app\admin\model\SupplyChain; // 供应链模型
|
||
use app\api\model\Area as AreaModel; // 市场区域模型
|
||
use app\api\model\AreaManager as AreaManagerModel; // 区域负责人模型
|
||
|
||
use app\admin\model\store\paramter\ParameterTemplate as ParameterTemplateModel;//商品参数model
|
||
use app\common\controller\FormatList;
|
||
|
||
/**
|
||
*
|
||
* 平台商品参数控制器
|
||
*
|
||
*
|
||
*/
|
||
class Parameter extends BaseController
|
||
{
|
||
protected $url;
|
||
protected $adminInfo;
|
||
protected $temp;
|
||
|
||
public function __construct(ParameterTemplateModel $temp)
|
||
{
|
||
$this->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);
|
||
}
|
||
|
||
} |