226 lines
6.5 KiB
PHP
226 lines
6.5 KiB
PHP
<?php
|
|
/**
|
|
* @copyright Copyright (c) 2021 勾股工作室
|
|
* @license https://opensource.org/licenses/Apache-2.0
|
|
* @link https://www.gougucms.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\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; // 区域负责人模型
|
|
|
|
/**
|
|
*
|
|
* 商品分类控制器
|
|
*
|
|
*/
|
|
class Classify extends BaseController
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->adminInfo = get_login_admin();
|
|
$this->category_id=354;
|
|
$this->url=[
|
|
'/admin/product.classify/index?category_id='.$this->category_id,
|
|
'/admin/product.classify/add',
|
|
'/admin/product.classify/edit',
|
|
'/admin/product.classify/delete'
|
|
];
|
|
}
|
|
|
|
/**
|
|
*
|
|
* 商城分类列表
|
|
*
|
|
*/
|
|
public function index()
|
|
{
|
|
if (request()->isAjax()) {
|
|
|
|
$params= get_params();
|
|
|
|
$where = [];
|
|
|
|
if (isset($params['keywords']) && !empty($params['keywords'])){
|
|
$where[]= ['name','like','%'.$params['keywords'].'%'];
|
|
}
|
|
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','=',''];
|
|
}
|
|
}
|
|
|
|
$total = StoreCategory::where($where)->count();
|
|
|
|
// $list = StoreCategory::with(['merchant', 'street', 'area'])->order('id desc')->select();
|
|
$list = StoreCategory::order('store_category_id desc')->select();
|
|
|
|
View::assign('url', $this->url);
|
|
View::assign('list', $list);
|
|
|
|
$result = ['total' => $total, 'data' => $list];
|
|
|
|
return table_assign(0, '', $result);
|
|
|
|
}else{
|
|
|
|
$list = StoreCategory::select();
|
|
|
|
View::assign('url', $this->url);
|
|
View::assign('list', $list);
|
|
return view();
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
* 新增
|
|
*
|
|
*/
|
|
public function add()
|
|
{
|
|
$param = get_params();
|
|
|
|
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['pic'] = $params['pic']; // 图标
|
|
$data['pid'] = $params['pid']; // 上级分类
|
|
$data['sort'] = $params['sort']; // 排序
|
|
$data['create_time'] = date('Y-m-d H:i:s');
|
|
|
|
// 数据入库
|
|
$res = StoreCategory::create($data);
|
|
|
|
if ($res){
|
|
return to_assign(0,'操作成功',['aid'=>$res]);
|
|
}
|
|
|
|
return to_assign(1, '操作失败,原因:'.$res);
|
|
|
|
} else {
|
|
|
|
$id = isset($param['id']) ? $param['id'] : 0;
|
|
$pid = isset($param['pid']) ? $param['pid'] : 0;
|
|
|
|
if($id > 0){
|
|
$detail = StoreCategory::find($id); // 分类模型
|
|
View::assign('detail', $detail);
|
|
}
|
|
|
|
$storeCategoryList = StoreCategory::order('store_category_id desc')->where('pid', 0)->select();
|
|
|
|
View::assign('storeCategoryList', $storeCategoryList);
|
|
View::assign('url', $this->url);
|
|
|
|
View::assign('id', $id);
|
|
View::assign('pid', $pid);
|
|
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['pic'] = $params['pic']; // 图标
|
|
$data['pid'] = $params['pid']; // 上级分类
|
|
$data['sort'] = $params['sort']; // 排序
|
|
|
|
// 数据更新
|
|
$res = StoreCategory::where('store_category_id', $params['id'])->update($data);
|
|
|
|
if ($res){
|
|
return to_assign(0,'操作成功',['aid'=>$res]);
|
|
}
|
|
|
|
return to_assign(1, '操作失败,原因:'.$res);
|
|
|
|
}else{
|
|
|
|
$category = StoreCategory::with(['storeCategory'])->find($id); // 取出当前供应链数据
|
|
$storeCategoryList = StoreCategory::order('store_category_id desc')->where('pid', 0)->select();
|
|
|
|
View::assign('storeCategoryList', $storeCategoryList);
|
|
View::assign('detail', $category);
|
|
|
|
View::assign('url', $this->url);
|
|
return view();
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
*
|
|
* 删除
|
|
*
|
|
*/
|
|
public function delete()
|
|
{
|
|
$id = get_params("id");
|
|
if(!$id) return to_assign(1, '非法操作!');
|
|
|
|
$supplyChain = SupplyChain::with(['linkMerchant'])->find($id);
|
|
// 删除关联模型
|
|
$res = $supplyChain->together(['linkMerchant'])->delete();
|
|
|
|
if ($res){
|
|
return to_assign(0,'操作成功',['aid'=>$res]);
|
|
}
|
|
|
|
return to_assign(1, '操作失败,原因:'.$res);
|
|
|
|
}
|
|
|
|
/**
|
|
*
|
|
* 获取子分类
|
|
*
|
|
*/
|
|
public function street($pcode)
|
|
{
|
|
$storeCategory = StoreCategory::order('sort desc')
|
|
->where('is_show', 1)
|
|
->where('pid', $pcode)
|
|
->select();
|
|
|
|
return json($storeCategory);
|
|
}
|
|
} |