194 lines
5.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\StoreProductReply; // 商品评论模型
use app\admin\model\StoreProductLabel; // 商品标签模型
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 Label extends BaseController
{
public function __construct()
{
$this->adminInfo = get_login_admin();
$this->category_id=354;
$this->url=[
'/admin/product.label/index?category_id='.$this->category_id,
'/admin/product.label/add',
'/admin/product.label/edit',
'/admin/product.label/del',
'/admin/product.label/index',
];
}
/**
*
* 商品评论列表
*
*/
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 = StoreProductLabel::where($where)->count();
$list = StoreProductLabel::with(['product'])->order('product_label_id desc')->select();
View::assign('url', $this->url);
View::assign('list', $list);
$result = ['total' => $total, 'data' => $list];
return table_assign(0, '', $result);
}else{
$list = StoreProductLabel::select();
View::assign('url', $this->url);
View::assign('list', $list);
return view();
}
}
/**
*
* 新增
*
*/
public function add()
{
if (request()->isAjax()) {
$params = get_params();
$data['label_name'] = $params['label_name']; // 标签名
$data['status'] = isset($params['status']) && $params['status'] == 'on'? 1:0; // 状态
$data['info'] = $params['info']; // 说明
$data['sort'] = $params['sort']; // 排序
$data['create_time'] = date('Y-m-d H:i:s');
// 数据入库
$res = StoreProductLabel::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['label_name'] = $params['label_name']; // 标签名
$data['status'] = isset($params['status']) && $params['status'] == 'on'? 1:0; // 状态
$data['info'] = $params['info']; // 说明
$data['sort'] = $params['sort']; // 排序
$data['create_time'] = date('Y-m-d H:i:s');
// 数据更新
$res = StoreProductLabel::where('product_label_id', $params['id'])->update($data);
if ($res){
return to_assign(0,'更新成功',['aid'=>$res]);
}
return to_assign(1, '更新失败,原因:'.$res);
}else{
$supplyChain = StoreProductLabel::find($id); // 取出当前供应链数据
View::assign('detail', $supplyChain);
View::assign('url', $this->url);
return view();
}
}
/**
*
* 删除
*
*/
public function del()
{
$id = get_params("id");
if(!$id) return to_assign(1, '非法操作!');
$res = StoreProductLabel::where('product_label_id', $id)->delete();
if ($res){
return to_assign(0,'操作成功',['aid'=>$res]);
}
return to_assign(1, '操作失败,原因:'.$res);
}
}