📖 File Reader
<?php
namespace app\admin\controller;
use adminCreate\form\Form;
use app\admin\common\Common_config;
use app\admin\model\ModGoodsAct;
use think\facade\Db;
use think\facade\View;
class Shop extends Base
{
/*店铺设置*/
public function shop_config()
{
if ($this->admin_info["role_type"] != 2){
return $this->error("您不是店铺管理员,不可操作!");
}
$shop_id = $this->admin_info["shop_id"];
$shop_info = db::name("shop")->where("id = $shop_id")->find();
if (input("post.")){
$info = [
'name'=>input("param.name"),
'describe'=>input("param.describe"),
'name_person'=>input("param.name_person"),
'mobile_person'=>input("param.mobile_person"),
];
if (!empty($_FILES["logo"]['name'])) {
$info["logo"] = '/public/uploads/' . $this->upload("logo");
}
db::name("shop")->where("id = $shop_id")->update($info);
return $this->succeed_json("操作成功");
}else{
View::assign([
'shop_info'=>$shop_info
]);
return View::fetch();
}
}
/*店铺列表*/
public function shop_list()
{
return View::fetch();
}
/*店铺审核列表*/
public function shop_list_check()
{
return View::fetch();
}
/*店铺列表数据*/
public function shop_list_ajax()
{
$keyword = input("param.keyword");
$is_check = input("param.is_check");//审核:1是 0否
$state = input("param.state");
$where = 1;
if (!empty($keyword)){
$where .= " and (name like '%".$keyword."%' or name_person like '%".$keyword."%' or mobile_person like '%".$keyword."%')";
}
if ($is_check == 1) {
$where .= " and state in (0,2)";
}else{
$where .= " and state = 1";
}
if ($state != ''){
$where .= " and state = $state";
}
$list = db::name("shop")->where($where)->order("time_add desc")->page($this->page,$this->limit)->select()->toArray();
foreach ($list as $k => $v){
$list[$k]["time_add"] = date("Y-m-d H:i",$v["time_add"]);
}
$count = db::name("shop")->where($where)->count();
return $this->layui_json($count,$list);
}
/*店铺创建*/
public function shop_update()
{
$id = input("param.id");
if ($_POST){
/*验证*/
$name = input("param.name");
$where = 1;
$where .= " and name = '$name'";
if (!empty($id)){
$where .= " and id != $id";
}
$shop_num = db::name("shop")->where($where)->order("id desc")->find();
if (!empty($shop_num)){
return $this->error_json("该店铺已存在");
}
$info = [
'name'=>input("param.name"),
'describe'=>input("param.describe"),
'logo'=>input("param.logo") != ''?implode(",", input("param.logo")):'',
'name_person'=>input("param.name_person"),
'mobile_person'=>input("param.mobile_person"),
'is_seal'=>input("param.is_seal")!=''?input("param.is_seal"):0,
'region_id_str'=>input("param.region_id_str") != ''?implode(",", input("param.region_id_str")):'',
'province_id'=>0,
'city_id'=>0,
'district_id'=>0,
'address'=>input("param.address"),
];
if (!empty(input("param.region_id_str"))){
if (count(input("param.region_id_str")) != 3){
return $this->error_json("店铺地区选择完整!");
}
$info["province_id"] = input("param.region_id_str")[0];
$info["city_id"] = input("param.region_id_str")[1];
$info["district_id"] = input("param.region_id_str")[2];
}
if (!empty($id)){
/*店铺封闭处理*/
if (input("param.is_seal") == 1){
$shop_info = db::name("shop")->where("id = $id")->find();
if ($shop_info["is_seal"] == 0){
$goods_list = db::name("goods")->where("shop_id = $id and is_sold = 1")->field("goods_id,shop_id")->order("goods_id asc")->select()->toArray();
$goods_id_arr = [];
foreach ($goods_list as $v){
$goods_id_arr[] = $v["goods_id"];
}
$goods_id_str = implode(",", $goods_id_arr);
if (!empty($goods_id_str)){
db::name("goods")->where("goods_id in ($goods_id_str)")->update(['is_sold'=>0]);
}
$info["seal_describe"] = input("param.seal_describe");
$info["time_deblocking"] = strtotime(input("param.time_deblocking"));
$info["goods_id_str"] = $goods_id_str;
$info_variation = [
'admin_id'=>$this->admin_id,
'shop_id'=>$id,
'type'=>1,
'describe'=>input("param.seal_describe"),
'goods_id_str'=>$goods_id_str,
'time_add'=>time(),
];
db::name("shop_variation")->insert($info_variation);
}
}else{
$shop_info = db::name("shop")->where("id = $id")->find();
if ($shop_info["is_seal"] == 1){
$info["seal_describe"] = '';
$info["time_deblocking"] = 0;
$info["goods_id_str"] = '';
if (!empty($shop_info["goods_id_str"])){
db::name("goods")->where("goods_id in ($shop_info[goods_id_str])")->update(['is_sold'=>1]);
}
$info_variation = [
'admin_id'=>$this->admin_id,
'shop_id'=>$id,
'type'=>2,
'describe'=>"店铺解封!",
'goods_id_str'=>$shop_info["goods_id_str"],
'time_add'=>time(),
];
db::name("shop_variation")->insert($info_variation);
}
}
}
if (empty($id)){
$info["state"] = 1;
$info["time_add"] = time();
db::name("shop")->insertGetId($info);
}else{
db::name("shop")->where("id = $id")->data($info)->update();
}
return $this->succeed_json("操作成功");
}else{
$info = ['name'=>'','describe'=>'','logo'=>[],'name_person'=>'','mobile_person'=>'','is_seal'=>'0','seal_describe'=>'','time_deblocking'=>'','region_id_str'=>[],'address'=>''];
if (!empty($id)){
$info = db::name("shop")->where("id = $id")->find();
$info["logo"] = $info["logo"] != ''?explode(',',$info['logo']):[];
$info["time_deblocking"] = $info["time_deblocking"] != 0?date("Y-m-d H:i",$info["time_deblocking"]):'';
$info["region_id_str"] = $info["region_id_str"] != ''?explode(',',$info['region_id_str']):[];
}
$form = new Form();
$form->tabs('tabs1', '基本信息');
$form->input('name', '店铺名称',$info["name"])->required()->tabs('tabs1');
$form->input('describe', '店铺描述',$info["describe"])->type('textarea')->tabs('tabs1')->required();
$form->upload('logo', '店铺logo', '/admin/ad/uploads', $info['logo'])->nultiple(false)->required('',"array")->tabs('tabs1');
$form->cascader('region_id_str', '店铺地区', $info["region_id_str"])->setOptions(function () {
$menus = Common_config::region_dw();
return $menus;
})->tabs('tabs1')->required('','array');
$form->input('address', '店铺详细地址',$info["address"])->required()->tabs('tabs1');
$form->input('name_person', '法人姓名',$info["name_person"])->required()->tabs('tabs1')->col(7);
$form->input('mobile_person', '法人手机号',$info["mobile_person"])->required()->tabs('tabs1')->col(7);
if (!empty($id)){
$form->radio('is_seal', '店铺状态', $info["is_seal"])->setOptions(function () {
$menus[] = ['label' => '正常', 'value' => '0'];
$menus[] = ['label' => '封闭', 'value' => '1'];
return $menus;
})->tabs('tabs1')->tips('小提示:选择封闭状态,该店铺下所有的商品都自动下架。需谨慎操作!');
$form->input('seal_describe', '封闭原因',$info["seal_describe"])->type('textarea')->tabs('tabs1')->show(['is_seal1'])->required();
$form->datetime('time_deblocking', '解封时间',$info["time_deblocking"])->tabs('tabs1')->type('datetime')->show(['is_seal1'])->required();
}
$form->hidden('id',$id);
$form->button('/admin/Shop/shop_update');
return $form;
}
}
/*店铺审核*/
public function shop_update_check()
{
$id = input("param.id");
if ($_POST){
$info = [
'admin_id_check'=>$this->admin_id,
'state'=>input("param.state"),
'describe_reject'=>input("param.describe_reject"),
'time_check'=>time(),
];
if (input("param.state") != 2){
$info["describe_reject"] = '';
}
db::name("shop")->where("id = $id")->data($info)->update();
return $this->succeed_json("操作成功");
}else{
$info = ['name'=>'','describe'=>'','name_person'=>'','mobile_person'=>'','state'=>'','describe_reject'=>''];
if (!empty($id)){
$info = db::name("shop")->where("id = $id")->find();
$info["state"] = $info["state"] == 0?'':$info["state"];
}
$form = new Form();
$form->tabs('tabs1', '基本信息');
$form->input('name', '店铺名称',$info["name"])->required()->tabs('tabs1')->disabled(true);
$form->input('describe', '店铺描述',$info["describe"])->type('textarea')->tabs('tabs1')->required()->disabled(true);
$form->input('name_person', '法人姓名',$info["name_person"])->required()->tabs('tabs1')->col(7)->disabled(true);
$form->input('mobile_person', '法人手机号',$info["mobile_person"])->required()->tabs('tabs1')->col(7)->disabled(true);
$form->hr()->tabs('tabs1');
$form->selectone('state', '审核状态', $info["state"])->setOptions(function () {
$menus[] = ['label' => '审核通过', 'value' => 1];
$menus[] = ['label' => '审核驳回', 'value' => 2];
return $menus;
})->tabs('tabs1')->multiple(false)->filterable(false)->required('请选择审核状态');
$form->input('describe_reject', '驳回描述',$info["describe_reject"])->type('textarea')->tabs('tabs1')->required()->show(['state2']);
$form->hidden('id',$id);
$form->button('/admin/Shop/shop_update_check');
return $form;
}
}
/*店铺删除*/
public function shop_del()
{
$id = input("param.id");
$goods_num = db::name("goods")->where("shop_id = $id and is_delete = 0")->count();
if (!empty($goods_num)){
return $this->error_json("该店铺存在商品,不可删除!");
}
$order_num = db::name("order")->where("shop_id = $id")->count();
if (!empty($order_num)){
return $this->error_json("该店铺存在订单,不可删除!");
}
db::name("shop")->where("id = $id")->delete();
return $this->succeed_json("删除成功");
}
/*商品审核列表*/
public function goods_list_check()
{
return View::fetch();
}
/*商品审核列表数据*/
public function goods_list_check_ajax()
{
$name = input("param.name");
$act_id = input("param.act_id");
$state = input("param.state");
$where = 1;
$where .= " and a.shop_id != 0 and a.state in (0,2)";
if (!empty($name)){
$where .= " and a.name like '%".$name."%'";
}
if (!empty($act_id)){
$sublevel_act_id = ModGoodsAct::sublevel_act_id($act_id,1);
$where .= " and a.act_id in ($sublevel_act_id)";
}
if ($state != ''){
$where .= " and a.state = $state";
}
$list = db::name("goods")->alias("a")
->join("goods_act b","a.act_id = b.id","LEFT")
->join("shop c","a.shop_id = c.id","LEFT")
->field("a.*, b.name as name_act,c.name as shop_name")
->where("a.is_delete = 0 and ".$where)
->order("a.sort desc,a.add_time desc")
->page($this->page,$this->limit)
->select()
->toArray();
foreach ($list as $k => $v){
$guige_count = db::name("goods_guige_value")->where("goods_id = $v[goods_id]")->count();
$is_guige = $guige_count > 0?1:0;
if ($is_guige == 1){
$stocks = db::name("goods_guige_value")->where("goods_id = $v[goods_id]")->sum("stocks");
}else{
$stocks = $v["stocks"];
}
$list[$k]["stocks"] = $stocks;
$list[$k]["shop_name"] = $v["shop_name"] != ''?$v["shop_name"]:'';
$list[$k]["add_time"] = date("Y-m-d H:i",$v["add_time"]);
}
$count = db::name("goods")->alias("a")
->join("goods_act b","a.act_id = b.id","LEFT")
->join("shop c","a.shop_id = c.id","LEFT")
->where("a.is_delete = 0 and ".$where)
->count();
return $this->layui_json($count,$list);
}
/*商品审核提交*/
public function shop_goods_check()
{
$goods_id = input("param.goods_id");
if (input("post.")){
$info = [
'admin_id_check'=>$this->admin_id,
'state'=>input("param.state"),
'describe_reject'=>input("param.describe_reject"),
'act_id'=>0,
'act_id_str'=>input("param.act_id_str") != ''?implode(",",input("param.act_id_str")):'',
'time_check'=>time(),
];
if (!empty(input("param.act_id_str"))){
$arr_k = count(input("param.act_id_str"))-1;//最后一位k值
$act_id = input("param.act_id_str")[$arr_k];
$info["act_id"] = $act_id;
/*分类检测*/
$act_count = db::name("goods_act")->where("parent_id = $act_id")->count();
if (!empty($act_count)){
return $this->error_json("所属分类请填写完全");
}
}
if (input("param.state") != 2){
$info["describe_reject"] = '';
}
db::name("goods")->where("goods_id = $goods_id")->data($info)->update();
return $this->succeed_json("操作成功");
}else{
$info = db::name("goods")->alias("a")
->join("shop b","a.shop_id = b.id","left")
->field("a.*,b.name as shop_name")
->where("a.goods_id = $goods_id")
->find();
$info["act_id_str"] = $info["act_id_str"] != ''?explode(',',$info['act_id_str']):[];
$info["add_time"] = date("Y-m-d H:i",$info["add_time"]);
$info["state"] = $info["state"] == 0?'':$info["state"];
$form = new Form();
$form->tabs('tabs1', '基本信息');
$form->tabs('tabs2', '详细描述');
$form->input('shop_name', '店铺名称',$info["shop_name"])->tabs('tabs1')->required()->readonly(true);
$form->input('name', '商品名称',$info["name"])->required()->tabs('tabs1')->readonly(true);
$form->input('describe', '简单描述',$info["describe"])->type('textarea')->tabs('tabs1')->readonly(true);
$form->upload('img', '缩略图', '/admin/ad/uploads', [$info['img']])->nultiple(false)->required('',"array")->tabs('tabs1')->disabled(true);
//产品图册
$goods_photo = db::name("goods_photo")->where("goods_id = $goods_id")->order("sort desc,add_time desc")->field("id,photo_img")->select()->toArray();
$arr_photo = [];
foreach ($goods_photo as $v){
$arr_photo[] = $v["photo_img"];
}
$form->upload('photo_img', '产品图册', '/admin/ad/uploads', $arr_photo)->nultiple(false)->tabs('tabs1')->disabled(true);
$form->number('price', '售价', $info["price"])->required()->tabs('tabs1')->col(6)->readonly(true);
$form->number('price_market', '市场价', $info["price_market"])->tabs('tabs1')->col(6)->readonly(true);
$form->number('stocks', '库存', $info["stocks"])->tabs('tabs1')->col(6)->readonly(true);
$form->editor('content', '详细信息',$info["content"])->action('/admin/ad/uploads')->tabs('tabs2');
/*产品规格*/
$Table = [
$form->Tableimges('img', '缩略图','/admin/ad/uploads',true),
$form->Tabletext('guige_name', '规格名称',true,'300',"left"),
$form->Tabletext('price', '售价',true),
$form->Tabletext('stocks', '库存',true),
];
$guige_value = db::name("goods_guige_value")->where("goods_id = $goods_id")->order("id asc")->select()->toArray();
$table_data = [];
foreach ($guige_value as $k => $v){
$table_data[$k] = [
'img'=>$v["img"] != ''?explode(',',$v['img']):[],
'guige_name'=>$v["guige_name"],
'price'=>$v["price"],
'stocks'=>$v["stocks"],
];
}
$form->Table('guige_list', '产品规格',$Table,$table_data)->is_type(0)->col(24)->tabs('tabs1');
$form->hr()->tabs('tabs1');
$form->cascader('act_id_str', '所属分类',$info["act_id_str"])->setOptions(function(){
$list = db::name("goods_act")->field("id,id as value,parent_id as pid,name as label,name")->order("sort desc")->select()->toArray();
$menus = Common_config::array_reinstallation($list);
return $menus;
})->required()->tabs('tabs1');
$form->selectone('state', '审核状态', $info["state"])->setOptions(function () {
$menus[] = ['label' => '审核通过', 'value' => 1];
$menus[] = ['label' => '审核驳回', 'value' => 2];
return $menus;
})->tabs('tabs1')->multiple(false)->filterable(false)->required('请选择审核状态');
$form->input('describe_reject', '驳回描述',$info["describe_reject"])->type('textarea')->tabs('tabs1')->required()->show(['state2']);
$form->hidden('goods_id',$goods_id);
$form->button("/admin/Shop/shop_goods_check");
return $form;
}
}
/*店铺变动记录*/
public function shop_variation()
{
return View::fetch();
}
/*店铺变动记录数据*/
public function shop_variation_ajax()
{
$keyword = input("param.keyword");
$where = 1;
if (!empty($keyword)){
$where .= " and (a.describe like '%".$keyword."%' or b.name like '%".$keyword."%' or c.nickname like '%".$keyword."%')";
}
$list = db::name("shop_variation")->alias("a")
->join("shop b","a.shop_id = b.id","LEFT")
->join("admin c","a.admin_id = c.admin_id","LEFT")
->field("a.*, b.name as shop_name,c.nickname")
->where($where)
->order("a.id desc")
->page($this->page,$this->limit)
->select()
->toArray();
foreach ($list as $k => $v){
$list[$k]["time_add"] = date("Y-m-d H:i",$v["time_add"]);
}
$count = db::name("shop_variation")->alias("a")
->join("shop b","a.shop_id = b.id","LEFT")
->join("admin c","a.admin_id = c.admin_id","LEFT")
->where($where)
->count();
return $this->layui_json($count,$list);
}
}