hrjy 2 lat temu
rodzic
commit
23d7cca1c9

+ 198 - 0
app/admin/controller/store/StoreCate.php

@@ -0,0 +1,198 @@
+<?php
+
+namespace app\admin\controller\store;
+
+use app\admin\controller\AuthController;
+use think\Request;
+use think\facade\Route as Url;
+use app\admin\model\system\SystemAttachment;
+use app\admin\model\store\StoreCate as CategoryModel;
+use crmeb\services\{FormBuilder as Form, JsonService as Json, UtilService as Util};
+
+/**
+ * 产品分类控制器
+ * Class StoreCategory
+ * @package app\admin\controller\system
+ */
+class StoreCate extends AuthController
+{
+    /**
+     * 显示资源列表
+     *
+     * @return \think\Response
+     */
+    public function index()
+    {
+        $this->assign('pid', $this->request->get('pid', 0));
+        $this->assign('cate', CategoryModel::getTierList(null, 0));
+        return $this->fetch();
+    }
+
+    /*
+     *  异步获取分类列表
+     *  @return json
+     */
+    public function category_list()
+    {
+        $where = Util::getMore([
+            ['is_show', ''],
+            ['pid', $this->request->param('pid', '')],
+            ['cate_name', ''],
+            ['page', 1],
+            ['limit', 20],
+            ['order', '']
+        ]);
+        return Json::successlayui(CategoryModel::CategoryList($where));
+    }
+
+    /**
+     * 设置产品分类上架|下架
+     * @param string $is_show
+     * @param string $id
+     */
+    public function set_show($is_show = '', $id = '')
+    {
+        ($is_show == '' || $id == '') && Json::fail('缺少参数');
+        if (CategoryModel::setCategoryShow($id, (int)$is_show)) {
+            return Json::successful($is_show == 1 ? '显示成功' : '隐藏成功');
+        } else {
+            return Json::fail(CategoryModel::getErrorInfo($is_show == 1 ? '显示失败' : '隐藏失败'));
+        }
+    }
+
+    /**
+     * 快速编辑
+     * @param string $field
+     * @param string $id
+     * @param string $value
+     */
+    public function set_category($field = '', $id = '', $value = '')
+    {
+        $field == '' || $id == '' || $value == '' && Json::fail('缺少参数');
+        if (CategoryModel::where('id', $id)->update([$field => $value]))
+            return Json::successful('保存成功');
+        else
+            return Json::fail('保存失败');
+    }
+
+    /**
+     * 显示创建资源表单页.
+     *
+     * @return \think\Response
+     */
+    public function create()
+    {
+        $field = [
+            Form::select('pid', '父级')->setOptions(function () {
+                $list = CategoryModel::getTierList(null, 0);
+                $menus = [['value' => 0, 'label' => '顶级菜单']];
+                foreach ($list as $menu) {
+                    $menus[] = ['value' => $menu['id'], 'label' => $menu['html'] . $menu['cate_name']];
+                }
+                return $menus;
+            })->filterable(1),
+            Form::input('cate_name', '分类名称'),
+            Form::frameImageOne('pic', '分类图标(180*180)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'pic')))->icon('image')->width('100%')->height('500px'),
+            Form::number('sort', '排序'),
+            Form::radio('is_show', '状态', 1)->options([['label' => '显示', 'value' => 1], ['label' => '隐藏', 'value' => 0]])
+        ];
+        $form = Form::make_post_form('添加分类', $field, Url::buildUrl('save'), 2);
+        $this->assign(compact('form'));
+        return $this->fetch('public/form-builder');
+    }
+
+    /**
+     * 保存新建的资源
+     *
+     * @param \think\Request $request
+     * @return \think\Response
+     */
+    public function save(Request $request)
+    {
+        $data = Util::postMore([
+            'pid',
+            'cate_name',
+            ['pic', []],
+            'sort',
+            ['is_show', 0]
+        ], $request);
+        if ($data['pid'] == '') return Json::fail('请选择父类');
+        if (!$data['cate_name']) return Json::fail('请输入分类名称');
+        if (count($data['pic']) < 1) return Json::fail('请上传分类图标');
+        if ($data['sort'] < 0) $data['sort'] = 0;
+        $data['pic'] = $data['pic'][0];
+        $data['add_time'] = time();
+        CategoryModel::create($data);
+        return Json::successful('添加分类成功!');
+    }
+
+    /**
+     * 显示编辑资源表单页.
+     *
+     * @param int $id
+     * @return \think\Response
+     */
+    public function edit($id)
+    {
+        $c = CategoryModel::get($id);
+        if (!$c) return Json::fail('数据不存在!');
+        $field = [
+            Form::select('pid', '父级', (string)$c->getData('pid'))->setOptions(function () use ($id) {
+                $list = CategoryModel::getTierList(CategoryModel::where('id', '<>', $id), 0);
+//                $list = (sort_list_tier((CategoryModel::where('id','<>',$id)->select()->toArray(),'顶级','pid','cate_name'));
+                $menus = [['value' => 0, 'label' => '顶级菜单']];
+                foreach ($list as $menu) {
+                    $menus[] = ['value' => $menu['id'], 'label' => $menu['html'] . $menu['cate_name']];
+                }
+                return $menus;
+            })->filterable(1),
+            Form::input('cate_name', '分类名称', $c->getData('cate_name')),
+            Form::frameImageOne('pic', '分类图标', Url::buildUrl('admin/widget.images/index', array('fodder' => 'pic')), $c->getData('pic'))->icon('image')->width('100%')->height('500px'),
+            Form::number('sort', '排序', $c->getData('sort')),
+            Form::radio('is_show', '状态', $c->getData('is_show'))->options([['label' => '显示', 'value' => 1], ['label' => '隐藏', 'value' => 0]])
+        ];
+        $form = Form::make_post_form('编辑分类', $field, Url::buildUrl('update', array('id' => $id)), 2);
+
+        $this->assign(compact('form'));
+        return $this->fetch('public/form-builder');
+    }
+
+    /**
+     * 保存更新的资源
+     *
+     * @param \think\Request $request
+     * @param int $id
+     * @return \think\Response
+     */
+    public function update(Request $request, $id)
+    {
+        $data = Util::postMore([
+            'pid',
+            'cate_name',
+            ['pic', []],
+            'sort',
+            ['is_show', 0]
+        ], $request);
+        if ($data['pid'] == '') return Json::fail('请选择父类');
+        if (!$data['cate_name']) return Json::fail('请输入分类名称');
+        if (count($data['pic']) < 1) return Json::fail('请上传分类图标');
+        if ($data['sort'] < 0) $data['sort'] = 0;
+        $data['pic'] = $data['pic'][0];
+        CategoryModel::edit($data, $id);
+        return Json::successful('修改成功!');
+    }
+
+    /**
+     * 删除指定资源
+     *
+     * @param int $id
+     * @return \think\Response
+     */
+    public function delete($id)
+    {
+        if (!CategoryModel::delCategory($id))
+            return Json::fail(CategoryModel::getErrorInfo('删除失败,请稍候再试!'));
+        else
+            return Json::successful('删除成功!');
+    }
+}

+ 59 - 1
app/admin/controller/system/SystemStore.php

@@ -3,10 +3,13 @@
 namespace app\admin\controller\system;
 
 use app\admin\controller\AuthController;
+use app\admin\model\store\StoreCate;
 use crmeb\services\JsonService;
 use crmeb\services\JsonService as Json;
 use app\admin\model\system\SystemStore as SystemStoreModel;
 use crmeb\services\UtilService;
+use crmeb\services\FormBuilder as Form;
+use think\facade\Route as Url;
 
 /**
  * 门店管理控制器
@@ -55,7 +58,8 @@ class SystemStore extends AuthController
     public function add($id = 0)
     {
         $store = SystemStoreModel::getStoreDispose($id);
-        $this->assign(compact('store'));
+        $cate = StoreCate::select();
+        $this->assign(compact('store', 'cate'));
         return $this->fetch();
     }
 
@@ -127,6 +131,7 @@ class SystemStore extends AuthController
             ['latlng', ''],
             ['valid_time', []],
             ['day_time', []],
+            ['cate_id', '']
         ]);
         SystemStoreModel::beginTrans();
         try {
@@ -166,4 +171,57 @@ class SystemStore extends AuthController
             return JsonService::fail($e->getMessage());
         }
     }
+
+    /**
+     * 上传店内图片
+     * @param $id
+     * @return string
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function up($id)
+    {
+        if (!$id) Json::fail('数据不存在');
+        $data = SystemStoreModel::where('id', $id)->find();
+        $f = [];
+        if ($data['slider_image'] and $data['gatehead']){
+            $f[] = Form::frameImages('gatehead', '门头图(640*640px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'gatehead')), json_decode($data->getData('slider_image'), 1))->maxLength(5)->icon('images')->width('100%')->height('500px');
+            $f[] = Form::frameImages('slider_image', '店内图片(640*640px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'slider_image')), json_decode($data->getData('slider_image'), 1))->maxLength(5)->icon('images')->width('100%')->height('500px');
+        }else{
+            $f[] = Form::frameImages('gatehead', '门头图(640*640px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'gatehead')))->maxLength(5)->icon('images')->width('100%')->height('500px');
+            $f[] = Form::frameImages('slider_image', '店内图片(640*640px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'slider_image')))->maxLength(5)->icon('images')->width('100%')->height('500px');
+        }
+        $f[] = Form::hidden('id', $id);
+        $form = Form::make_post_form('修改', $f, Url::buildUrl('image_save', compact('id')));
+        $this->assign(compact('form'));
+        return $this->fetch('public/form-builder');
+
+    }
+
+    /**
+     * 添加接口
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function image_save()
+    {
+
+        $data = UtilService::postMore([
+            ['gatehead', ''],
+            ['slider_image', ''],
+            ['id']
+        ]);
+        if (empty($data['gatehead']) or empty($data['slider_image']))   return JsonService::fail('门头图或店内图不能为空');
+        $store = SystemStoreModel::find($data['id']);
+        $store['gatehead'] = json_encode($data['gatehead']);
+        $store['slider_image'] = json_encode($data['slider_image']);
+
+        $res = $store->save();
+        if ($res)  return JsonService::success('上传成功');
+        return JsonService::fail('上传失败');
+    }
+
 }

+ 145 - 0
app/admin/model/store/StoreCate.php

@@ -0,0 +1,145 @@
+<?php
+/**
+ * @author: xaboy<365615158@qq.com>
+ * @day: 2017/11/11
+ */
+
+namespace app\admin\model\store;
+
+use crmeb\traits\ModelTrait;
+use crmeb\basic\BaseModel;
+
+/**
+ * Class StoreCategory
+ * @package app\admin\model\store
+ */
+class StoreCate extends BaseModel
+{
+
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 模型名称
+     * @var string
+     */
+    protected $name = 'store_cate';
+
+    use ModelTrait;
+
+    /**
+     * 异步获取分类列表
+     * @param $where
+     * @return array
+     */
+    public static function CategoryList($where)
+    {
+        $data = ($data = self::systemPage($where, true)->page((int)$where['page'], (int)$where['limit'])->select()) && count($data) ? $data->toArray() : [];
+        foreach ($data as &$item) {
+            if ($item['pid']) {
+                $item['pid_name'] = self::where('id', $item['pid'])->value('cate_name');
+            } else {
+                $item['pid_name'] = '顶级';
+            }
+        }
+        $count = self::systemPage($where, true)->count();
+        return compact('count', 'data');
+    }
+
+    /**
+     * @param $where
+     * @return array
+     */
+    public static function systemPage($where, $isAjax = false)
+    {
+        $model = new self;
+        if ($where['pid'] != '') $model = $model->where('pid', $where['pid']);
+        else if ($where['pid'] == '' && $where['cate_name'] == '') $model = $model->where('pid', 0);
+        if ($where['is_show'] != '') $model = $model->where('is_show', $where['is_show']);
+        if ($where['cate_name'] != '') $model = $model->where('cate_name', 'LIKE', "%$where[cate_name]%");
+        if ($isAjax === true) {
+            if (isset($where['order']) && $where['order'] != '') {
+                $model = $model->order(self::setOrder($where['order']));
+            } else {
+                $model = $model->order('sort desc,id desc');
+            }
+            return $model;
+        }
+        return self::page($model, function ($item) {
+            if ($item['pid']) {
+                $item['pid_name'] = self::where('id', $item['pid'])->value('cate_name');
+            } else {
+                $item['pid_name'] = '顶级';
+            }
+        }, $where);
+    }
+
+    /**
+     * 获取顶级分类
+     * @return array
+     */
+    public static function getCategory()
+    {
+        return self::where('is_show', 1)->column('cate_name', 'id');
+    }
+
+    /**
+     * 分级排序列表
+     * @param null $model
+     * @param int $type
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public static function getTierList($model = null, $type = 0)
+    {
+        if ($model === null) $model = new self();
+        if (!$type) return sort_list_tier($model->order('sort desc,id desc')->where('pid', 0)->select()->toArray());
+        return sort_list_tier($model->order('sort desc,id desc')->select()->toArray());
+    }
+
+    public static function delCategory($id)
+    {
+        $count = self::where('pid', $id)->count();
+        if ($count)
+            return self::setErrorInfo('请先删除下级子分类');
+        else {
+            return self::del($id);
+        }
+    }
+
+    /**
+     * 产品分类隐藏显示
+     * @param $id
+     * @param $show
+     * @return bool
+     */
+    public static function setCategoryShow($id, $show)
+    {
+        $count = self::where('id', $id)->count();
+        if (!$count) return self::setErrorInfo('参数错误');
+        $count = self::where('id', $id)->where('is_show', $show)->count();
+        if ($count) return true;
+        $pid = self::where('id', $id)->value('pid');
+        self::beginTrans();
+        $res1 = true;
+        $res2 = self::where('id', $id)->update(['is_show' => $show]);
+        if (!$pid) {//一级分类隐藏
+            $count = self::where('pid', $id)->count();
+            if ($count) {
+                $count      = self::where('pid', $id)->where('is_show', $show)->count();
+                $countWhole = self::where('pid', $id)->count();
+                if (!$count || $countWhole > $count) {
+                    $res1 = self::where('pid', $id)->update(['is_show' => $show]);
+                }
+            }
+        }
+        $res = $res1 && $res2;
+        self::checkTrans($res);
+        return $res;
+    }
+}

+ 7 - 4
app/admin/model/system/SystemStore.php

@@ -81,8 +81,11 @@ class SystemStore extends BaseModel
     public static function getStoreList($where)
     {
         $model = new self();
+        $model = $model->alias('a')
+            ->field('a.*, b.cate_name')
+            ->leftJoin('store_cate b', 'a.cate_id = b.id');
         if (isset($where['name']) && $where['name'] != '') {
-            $model = $model->where('id|name|introduction', 'like', '%' . $where['name'] . '%');
+            $model = $model->where('a.id|a.name|a.introduction', 'like', '%' . $where['name'] . '%');
         }
         if (isset($where['type']) && $where['type'] != '' && ($data = self::setData($where['type']))) {
             $model = $model->where($data);
@@ -118,13 +121,13 @@ class SystemStore extends BaseModel
     {
         switch ((int)$type) {
             case 1:
-                $data = ['is_show' => 1, 'is_del' => 0];
+                $data = ['a.is_show' => 1, 'a.is_del' => 0];
                 break;
             case 2:
-                $data = ['is_show' => 0, 'is_del' => 0];
+                $data = ['a.is_show' => 0, 'a.is_del' => 0];
                 break;
             case 3:
-                $data = ['is_del' => 1];
+                $data = ['a.is_del' => 1];
                 break;
         };
         return isset($data) ? $data : [];

+ 2 - 2
app/admin/view/login/index.php

@@ -17,11 +17,11 @@
     </script>
 </head>
 <body class="gray-bg login-bg">
-<canvas id="canvas" width="900" height="300" style="position: fixed;top: -50px;width: 60%;left: 20%"></canvas>
+<!--<canvas id="canvas" width="900" height="300" style="position: fixed;top: -50px;width: 60%;left: 20%"></canvas>-->
 <div class="middle-box text-center loginscreen  animated fadeInDown">
     <div class="login-group">
         <h3 class="login-logo">
-            <img src="{__ADMIN_PATH}images/logo.png">
+<!--            <img src="{__ADMIN_PATH}images/logo.png">-->
         </h3>
         <form role="form" action="{:url('verify')}" method="post" id="form" onsubmit="return false">
             <div class="form-group">

+ 176 - 0
app/admin/view/store/store_cate/index.php

@@ -0,0 +1,176 @@
+{extend name="public/container"}
+{block name="content"}
+
+<div class="layui-fluid">
+    <div class="layui-row layui-col-space15"  id="app">
+        <div class="layui-col-md12">
+            <div class="layui-card">
+                <div class="layui-card-header">搜索条件</div>
+                <div class="layui-card-body">
+                    <form class="layui-form layui-form-pane" action="">
+                        <div class="layui-form-item">
+                            <div class="layui-inline">
+                                <label class="layui-form-label">所有分类</label>
+                                <div class="layui-input-block">
+                                    <select name="is_show">
+                                        <option value="">是否显示</option>
+                                        <option value="1">显示</option>
+                                        <option value="0">不显示</option>
+                                    </select>
+                                </div>
+                            </div>
+                            <div class="layui-inline">
+                                <label class="layui-form-label">所有分类</label>
+                                <div class="layui-input-block">
+                                    <select name="pid">
+                                        <option value="">所有菜单</option>
+                                        {volist name="cate" id="vo"}
+                                        <option value="{$vo.id}">{$vo.html}{$vo.cate_name}</option>
+                                        {/volist}
+                                    </select>
+                                </div>
+                            </div>
+                            <div class="layui-inline">
+                                <label class="layui-form-label">产品名称</label>
+                                <div class="layui-input-block">
+                                    <input type="text" name="cate_name" class="layui-input" placeholder="请输入分类名称">
+                                </div>
+                            </div>
+                            <div class="layui-inline">
+                                <div class="layui-input-inline">
+                                    <button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit="search" lay-filter="search">
+                                        <i class="layui-icon layui-icon-search"></i>搜索</button>
+                                </div>
+                            </div>
+                        </div>
+                    </form>
+                </div>
+            </div>
+        </div>
+        <!--产品列表-->
+        <div class="layui-col-md12">
+            <div class="layui-card">
+                <div class="layui-card-header">分类列表</div>
+                <div class="layui-card-body">
+                    <div class="alert alert-info" role="alert">
+                        注:点击父级名称可查看子集分类,点击分页首页可返回顶级分类;分类名称和排序可进行快速编辑;
+                        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
+                    </div>
+                    <div class="layui-btn-container">
+                        <a class="layui-btn layui-btn-sm" href="{:Url('index')}">分类首页</a>
+                        <button type="button" class="layui-btn layui-btn-sm" onclick="$eb.createModalFrame(this.innerText,'{:Url('create')}')">添加分类</button>
+                    </div>
+                    <table class="layui-hide" id="List" lay-filter="List"></table>
+                    <script type="text/html" id="pic">
+                        {{# if(d.pic){ }}
+                        <img style="cursor: pointer" lay-event='open_image' src="{{d.pic}}">
+                        {{# }else{ }}
+                        暂无图片
+                        {{# } }}
+                    </script>
+                    <script type="text/html" id="is_show">
+                        <input type='checkbox' name='id' lay-skin='switch' value="{{d.id}}" lay-filter='is_show' lay-text='显|隐'  {{ d.is_show == 1 ? 'checked' : '' }}>
+                    </script>
+                    <script type="text/html" id="pid">
+                        <a href="{:Url('index')}?pid={{d.id}}">查看</a>
+                    </script>
+                    <script type="text/html" id="act">
+                        <button class="layui-btn layui-btn-xs" onclick="$eb.createModalFrame('编辑','{:Url('edit')}?id={{d.id}}')">
+                            <i class="fa fa-edit"></i> 编辑
+                        </button>
+                        <button class="layui-btn btn-danger layui-btn-xs" lay-event='delstor'>
+                            <i class="fa fa-times"></i> 删除
+                        </button>
+                    </script>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+<script src="{__ADMIN_PATH}js/layuiList.js"></script>
+{/block}
+{block name="script"}
+<script>
+    setTimeout(function () {
+        $('.alert-info').hide();
+    },3000);
+    //实例化form
+    layList.form.render();
+    //加载列表
+    layList.tableList('List',"{:Url('category_list',['pid'=>$pid])}",function (){
+        return [
+            {field: 'id', title: 'ID', sort: true,event:'id',width:'4%',align:'center'},
+            {field: 'pid_name', title: '父级',align:'center'},
+            {field: 'cate_name', title: '分类名称',edit:'cate_name',align:'center'},
+            {field: 'pid', title: '查看子分类',templet:'#pid',align:'center',width:'8%'},
+            {field: 'pic', title: '分类图标',templet:'#pic',align:'center'},
+            {field: 'sort', title: '排序',sort: true,event:'sort',edit:'sort',width:'8%',align:'center'},
+            {field: 'is_show', title: '状态',templet:'#is_show',width:'10%',align:'center'},
+            {field: 'right', title: '操作',align:'center',toolbar:'#act',width:'10%',align:'center'},
+        ];
+    });
+    //自定义方法
+    var action= {
+        set_category: function (field, id, value) {
+            layList.baseGet(layList.Url({
+                c: 'store.store_category',
+                a: 'set_category',
+                q: {field: field, id: id, value: value}
+            }), function (res) {
+                layList.msg(res.msg);
+            });
+        },
+    }
+    //查询
+    layList.search('search',function(where){
+        layList.reload(where,true);
+    });
+    layList.switch('is_show',function (odj,value) {
+        if(odj.elem.checked==true){
+            layList.baseGet(layList.Url({c:'store.store_category',a:'set_show',p:{is_show:1,id:value}}),function (res) {
+                layList.msg(res.msg);
+            });
+        }else{
+            layList.baseGet(layList.Url({c:'store.store_category',a:'set_show',p:{is_show:0,id:value}}),function (res) {
+                layList.msg(res.msg);
+            });
+        }
+    });
+    //快速编辑
+    layList.edit(function (obj) {
+        var id=obj.data.id,value=obj.value;
+        switch (obj.field) {
+            case 'cate_name':
+                action.set_category('cate_name',id,value);
+                break;
+            case 'sort':
+                action.set_category('sort',id,value);
+                break;
+        }
+    });
+    //监听并执行排序
+    layList.sort(['id','sort'],true);
+    //点击事件绑定
+    layList.tool(function (event,data,obj) {
+        switch (event) {
+            case 'delstor':
+                var url=layList.U({c:'store.store_category',a:'delete',q:{id:data.id}});
+                $eb.$swal('delete',function(){
+                    $eb.axios.get(url).then(function(res){
+                        if(res.status == 200 && res.data.code == 200) {
+                            $eb.$swal('success',res.data.msg);
+                            obj.del();
+                        }else
+                            return Promise.reject(res.data.msg || '删除失败')
+                    }).catch(function(err){
+                        $eb.$swal('error',err);
+                    });
+                })
+                break;
+            case 'open_image':
+                $eb.openImage(data.pic);
+                break;
+        }
+    })
+</script>
+{/block}

+ 14 - 0
app/admin/view/system/system_store/add.php

@@ -36,6 +36,18 @@
                                     </i-Col>
                                 </Row>
                             </Form-Item>
+                            <Form-Item>
+                                <Row>
+                                    <i-Col span="13">
+                                        <span>门店分类:</span>
+                                        <i-Select placeholder="门店分类" v-model="form.cate_id" style="width: 80%" type="text">
+                                            {volist name="cate" id="vo"}
+                                            <i-option  :value="{$vo.id}">{$vo.cate_name}</i-option>
+                                            {/volist}
+                                        </i-Select>
+                                    </i-Col>
+                                </Row>
+                            </Form-Item>
                             <Form-Item>
                                 <Row>
                                     <i-Col span="13">
@@ -160,6 +172,7 @@
                         latlng:storeData.latlng || '',
                         valid_time:storeData.valid_time || [],
                         day_time:storeData.day_time || [],
+                        cate_id:storeData.cate_id || '',
                     },
                     visible:false,
                 }
@@ -218,6 +231,7 @@
                     if(!that.form.valid_time) return  $eb.message('error','请选择核销时效');
                     if(!that.form.day_time) return  $eb.message('error','请选择门店营业时间');
                     if(!that.form.latlng) return  $eb.message('error','请选择门店经纬度!');
+                    if(!that.form.cate_id) return  $eb.message('error','请选择门店分类');
                     var index = layer.load(1, {
                         shade: [0.5,'#fff']
                     });

+ 7 - 0
app/admin/view/system/system_store/index.php

@@ -67,6 +67,9 @@
                         <button type="button" class="layui-btn layui-btn-xs layui-btn-normal" lay-event='edit'>
                             编辑门店
                         </button>
+                        <button type="button" class="layui-btn layui-btn-xs layui-btn-normal" lay-event='image'>
+                            店内图片
+                        </button>
                         <button type="button" class="layui-btn layui-btn-xs layui-btn-normal" lay-event='del'>
                             {{# if(d.is_del){ }}
                             恢复门店
@@ -90,6 +93,7 @@
             {field: 'id', title: 'ID', sort: true, event: 'id', width: '4%'},
             {field: 'image', title: '门店图片', templet: '#headimgurl', width: '6%'},
             {field: 'name', title: '门店名称', width: '10%'},
+            {field: 'cate_name', title: '分类', width: '10%'},
             {field: 'phone', title: '门店电话', width: '10%'},
             {field: 'address', title: '地址', templet: '#address'},
             {field: 'day_time', title: '营业时间', width: '15%'},
@@ -157,6 +161,9 @@
             case 'edit':
                 $eb.createModalFrame(data.name + '-编辑', layList.U({a: 'add', q: {id: data.id}}), {h: 700, w: 1100});
                 break;
+            case 'image':
+                $eb.createModalFrame(data.name + '-上传图片', layList.U({a: 'up', q: {id: data.id}}), {h: 700, w: 1100});
+                break;
         }
     })
 </script>

+ 21 - 3
app/api/controller/PublicController.php

@@ -286,13 +286,14 @@ class PublicController
      */
     public function store_list(Request $request)
     {
-        list($latitude, $longitude, $page, $limit) = UtilService::getMore([
+        list($latitude, $longitude, $page, $limit, $cate_id) = UtilService::getMore([
             ['latitude', ''],
             ['longitude', ''],
             ['page', 1],
-            ['limit', 10]
+            ['limit', 10],
+            ['cate_id']
         ], $request, true);
-        $list = SystemStore::lst($latitude, $longitude, $page, $limit);
+        $list = SystemStore::lst($latitude, $longitude, $page, $limit, $cate_id);
         if (!$list) $list = [];
         $data['list'] = $list;
         $data['tengxun_map_key'] = sys_config('tengxun_map_key');
@@ -330,4 +331,21 @@ class PublicController
         return app('json')->successful($list);
     }
 
+    /**
+     * 门店详情
+     * @param $id
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function store_details($id)
+    {
+        $data = SystemStore::find($id);
+        $data = empty($data) ? [] : $data->toArray();
+        $data['slider_image'] = json_decode($data['slider_image']);
+        $data['images'] = json_decode($data['gatehead']);
+        return app('json')->successful($data);
+    }
+
 }

+ 38 - 3
app/api/controller/admin/StoreOrderController.php

@@ -11,9 +11,7 @@ use crmeb\repositories\ShortLetterRepositories;
 use crmeb\services\{
     MiniProgramService, UtilService, WechatService
 };
-use app\models\store\{
-    StoreCart, StoreOrder, StoreOrderStatus, StorePink, StoreService
-};
+use app\models\store\{StoreCart, StoreCoupon, StoreCouponUser, StoreOrder, StoreOrderStatus, StorePink, StoreService};
 use app\models\system\SystemStoreStaff;
 
 /**
@@ -479,5 +477,42 @@ class StoreOrderController
         }
     }
 
+    /**
+     * 优惠券核销
+     * @param Request $request
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function coupon_verific(Request $request)
+    {
+        list($verify_code,) = UtilService::postMore([
+            ['verify_code', ''],
+        ], $request, true);
+        if (!$verify_code) return app('json')->fail('缺少核销码');
+        $coupon = StoreCouponUser::where('code', $verify_code)->where('status', 0)->find();
+        $coupons = StoreCoupon::where('id', $coupon['cid'])->find();
+        if (!$coupon) return app('json')->fail('核销的优惠券不存在或已使用');
+        $user = SystemStoreStaff::where('uid', $request->uid())->find();
+        if (!$user) return app('json')->fail('你不是店员');
+        if ($coupons['store_id'] != $user['store_id']) return app('json')->fail('你不是门店优惠券指定店员,没有权限核销');
+        StoreCouponUser::beginTrans();
+        try {
+            $coupon['status'] = 1;
+            $coupon['use_time'] = time();
+            $res = $coupon->save();
+            $pon = StoreCouponUser::where('order_id', $coupon['order_id'])->where('code', '<>', $verify_code)->where('status', 0)->select();
+            if (count($pon) == 0){
+                StoreOrder::where('order_id', $coupon['order_id'])->update(['use' => 1]);
+            }
+            StoreCouponUser::commitTrans();
+            if ($res) return app('json')->success('核销成功');
+        } catch (\PDOException $e) {
+            StoreCouponUser::rollbackTrans();
+            return app('json')->fail($e->getMessage());
+        }
+    }
+
 
 }

+ 26 - 4
app/api/controller/order/StoreOrderController.php

@@ -8,8 +8,7 @@ use app\admin\model\system\{
 use app\admin\model\user\User;
 use app\models\routine\RoutineFormId;
 use crmeb\repositories\OrderRepository;
-use app\models\store\{
-    StoreBargainUser,
+use app\models\store\{StoreBargainUser,
     StoreCart,
     StoreCoupon,
     StoreCouponIssue,
@@ -18,8 +17,8 @@ use app\models\store\{
     StoreOrderCartInfo,
     StoreOrderStatus,
     StorePink,
-    StoreProductReply
-};
+    StoreProduct,
+    StoreProductReply};
 use app\models\system\SystemStore;
 use app\models\user\UserAddress;
 use app\models\user\UserLevel;
@@ -666,4 +665,27 @@ class StoreOrderController
     {
         return app('json')->successful(StoreOrder::getUserOrderSearchList($request->uid(), 0, 0, 0, ''));
     }
+
+    /**
+     * 查看订单优惠券信息
+     * @param Request $request
+     * @return void
+     */
+    public function view_order(Request  $request)
+    {
+        $data = UtilService::postMore(['order_id']);
+        $order = StoreOrder::where('order_id', $data['order_id'])->find();
+        if (!$order) return app('json')->fail('订单不查找');
+        $coupon = StoreCouponUser::alias('a')
+            ->field('a.id,a.title,a.coupon_price,a.add_time,a.end_time,a.code,c.id as store_id ,c.name,c.phone,c.address,c.detailed_address,c.image,c.day_time,c.latitude,c.longitude')
+            ->leftJoin('store_coupon b', 'b.id = a.cid')
+            ->leftJoin('system_store c', 'b.store_id = c.id')
+            ->where('a.order_id', $data['order_id'])
+            ->select();
+        $order['coupon'] = $coupon;
+        $order['produc'] = StoreProduct::where('id', $order['product_id'])->find();
+        $order = $order->toArray();
+        return app('json')->successful($order);
+    }
+
 }

+ 8 - 0
app/api/controller/store/CategoryController.php

@@ -2,6 +2,7 @@
 
 namespace app\api\controller\store;
 
+use app\admin\model\store\StoreCate;
 use app\models\store\StoreCategory;
 use app\Request;
 
@@ -12,4 +13,11 @@ class CategoryController
         $cateogry = StoreCategory::with('children')->where('is_show', 1)->order('sort desc,id desc')->where('pid', 0)->select();
         return app('json')->success($cateogry->hidden(['add_time', 'is_show', 'sort', 'children.sort', 'children.add_time', 'children.pid', 'children.is_show'])->toArray());
     }
+
+    public function store_cate(Request $request)
+    {
+        $cate = StoreCate::where('is_show', 1)->order('sort desc,id desc')->where('pid', 0)->select()->toArray();
+
+        return app('json')->success($cate);
+    }
 }

+ 22 - 4
app/api/controller/user/UserBillController.php

@@ -292,12 +292,12 @@ class UserBillController
                             array(
                                 'url' => $urlCode,     //二维码资源
                                 'stream' => 0,
-                                'left' => 114,
-                                'top' => 790,
+                                'left' => 225,
+                                'top' => 913,
                                 'right' => 0,
                                 'bottom' => 0,
-                                'width' => 120,
-                                'height' => 120,
+                                'width' => 300,
+                                'height' => 300,
                                 'opacity' => 100
                             )
                         ),
@@ -358,4 +358,22 @@ class UserBillController
         return app('json')->successful(UserBill::userBillList($request->uid(), $page, $limit, 'integral', ['pm' => $status]));
 
     }
+
+
+    /**
+     * 抵扣券记录
+     * @param Request $request
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function voucher_list(Request $request)
+    {
+        list($page, $limit, $status) = UtilService::getMore([
+            ['page', 0], ['limit', 0], ['pm', 0]
+        ], $request, true);
+        return app('json')->successful(UserBill::userBillList($request->uid(), $page, $limit, 'voucher', ['pm' => $status]));
+
+    }
 }

+ 4 - 3
app/models/store/StoreOrder.php

@@ -807,6 +807,7 @@ class StoreOrder extends BaseModel
                         $data = [
                             'cid' => $value['id'],
                             'uid' => $uid,
+                            'order_id'=> $orderId,
                             'coupon_title' => $value['title'],
                             'coupon_price' => $value['coupon_price'],
                             'use_min_price' => $value['use_min_price'],
@@ -1143,7 +1144,7 @@ class StoreOrder extends BaseModel
             $status['_title'] = '待评价';
             $status['_msg'] = '已收货,快去评价一下吧';
             $status['_class'] = 'state-ypj';
-        } else if ($order['status'] == 3) {
+        } else if ($order['use'] == 1) {
             $status['_type'] = 4;
             $status['_title'] = '交易完成';
             $status['_msg'] = '交易完成,感谢您的支持';
@@ -1191,9 +1192,9 @@ class StoreOrder extends BaseModel
         else if ($status == 2)//待收货
             return $model->where('paid', 1)->where('status', 1)->where('refund_status', 0);
         else if ($status == 3)//待评价
-            return $model->where('paid', 1)->where('status', 2)->where('refund_status', 0);
+            return $model->where('paid', 1)->where('status', 2)->where('use', 0)->where('refund_status', 0);
         else if ($status == 4)//已完成
-            return $model->where('paid', 1)->where('status', 3)->where('refund_status', 0);
+            return $model->where('paid', 1)->where('use', 1)->where('refund_status', 0);
         else if ($status == -1)//退款中
             return $model->where('paid', 1)->where('refund_status', 1);
         else if ($status == -2)//已退款

+ 2 - 1
app/models/system/SystemStore.php

@@ -144,11 +144,12 @@ class SystemStore extends BaseModel
      * 门店列表
      * @return mixed
      */
-    public static function lst($latitude, $longitude, $page, $limit)
+    public static function lst($latitude, $longitude, $page, $limit,$cate_id)
     {
         $model = new self();
         $model = $model->where('is_del', 0);
         $model = $model->where('is_show',1);
+        $model = $model->where('cate_id', $cate_id);
         if ($latitude && $longitude) {
             $model = $model->field(['*', self::distanceSql($latitude, $longitude)])->order('distance asc');
         }

+ 12 - 0
app/models/user/User.php

@@ -736,4 +736,16 @@ class User extends BaseModel
         }
         return $model->where('brokerage_price', '>', $brokerage_price)->count('uid');
     }
+
+    /**
+     * 获取ID
+     * @param string $key 键名
+     * @return mixed
+     */
+    public static function getkeytoid(string $key)
+    {
+
+        $rs = self::order('uid DESC')->find();
+        return $rs['uid']+1;
+    }
 }

+ 6 - 1
route/api/route.php

@@ -161,6 +161,9 @@ Route::group(function () {
     Route::get('user/level/task/:id', 'user.UserLevelController/task')->name('userLevelTask');//获取等级任务
     //首页获取未支付订单
     Route::get('order/nopay', 'order.StoreOrderController/get_noPay')->name('getNoPay');//获取未支付订单
+
+    Route::get('order/view_order', 'order.StoreOrderController/view_order')->name('view_order');//查看订单优惠信息
+    Route::post('coupon_verific', 'admin.StoreOrderController/coupon_verific')->name('coupon_verific');//优惠券核销
 })->middleware(\app\http\middleware\AllowOriginMiddleware::class)->middleware(\app\http\middleware\AuthTokenMiddleware::class, true);
 //未授权接口
 Route::group(function () {
@@ -226,9 +229,11 @@ Route::group(function () {
 
     //门店列表
     Route::get('store_list', 'PublicController/store_list')->name('storeList');
+    Route::get('store_details/:id', 'PublicController/store_details')->name('store_details');
     //获取城市列表
     Route::get('city_list', 'PublicController/city_list')->name('cityList');
-
+    //门店分类类
+    Route::get('store_cate', 'store.CategoryController/store_cate')->name('store_cate'); // 门店分类
 
 })->middleware(\app\http\middleware\AllowOriginMiddleware::class)->middleware(\app\http\middleware\AuthTokenMiddleware::class, false);