Browse Source

一些功能

Kirin 3 years ago
parent
commit
5bd909f075

+ 125 - 0
app/admin/controller/system/SystemStore.php

@@ -9,6 +9,7 @@ use app\admin\model\system\SystemStoreBill;
 use app\admin\model\system\SystemStorePoint;
 use app\admin\model\system\SystemStoreProductStock;
 use app\admin\model\system\SystemStoreProductStockLog;
+use app\admin\model\system\SystemStoreSender;
 use crmeb\services\FormBuilder;
 use crmeb\services\JsonService;
 use crmeb\services\JsonService as Json;
@@ -467,4 +468,128 @@ class SystemStore extends AuthController
                 return Json::successful('删除门店成功!');
         }
     }
+
+
+    /**
+     * @param $id
+     * @return string
+     * @throws Exception
+     */
+    public function store_sender($id)
+    {
+
+        $type = $this->request->param('type');
+        $show = SystemStoreSender::where('store_id', $id)->where('is_show', 1)->where('is_del', 0)->count();//显示中的门店
+        $hide = SystemStoreSender::where('store_id', $id)->where('is_show', 0)->count();//隐藏的门店
+        $recycle = SystemStoreSender::where('store_id', $id)->where('is_del', 1)->count();//删除的门店
+        if ($type == null) $type = 1;
+        $this->assign(compact('type', 'show', 'hide', 'recycle', 'id'));
+        return $this->fetch();
+    }
+
+    public function store_sender_list($id)
+    {
+        $where = UtilService::getMore([
+            ['page', 1],
+            ['limit', 20],
+            ['name', ''],
+            ['excel', 0],
+            ['type', $this->request->param('type')]
+        ]);
+        $where['store_id'] = $id;
+        JsonService::successlayui(SystemStoreSender::getStoreList($where));
+    }
+
+    /**
+     * 门店添加
+     * @param int $id
+     * @return string
+     */
+    public function add_sender($id = 0, $store_id = 0)
+    {
+        $store = SystemStoreSender::getStoreDispose($id);
+        $this->assign(compact('store', 'store_id'));
+        return $this->fetch();
+    }
+
+
+    /**
+     * 保存修改门店信息
+     * @param int $id
+     */
+    public function save_sender($id = 0)
+    {
+        $data = UtilService::postMore([
+            ['name', ''],
+            ['phone', ''],
+            ['store_id', 0],
+        ]);
+//        var_dump($data['store_id']);
+        if (!$data['store_id'] || !SystemStoreModel::getStoreDispose($data['store_id'])) JsonService::fail('无效门店');
+        SystemStoreSender::beginTrans();
+        try {
+            if ($id) {
+                if (SystemStoreSender::where('id', $id)->update($data)) {
+                    SystemStoreSender::commitTrans();
+                    JsonService::success('修改成功');
+                } else {
+                    SystemStoreSender::rollbackTrans();
+                    JsonService::fail('修改失败或者您没有修改什么!');
+                }
+            } else {
+                $data['add_time'] = time();
+                $data['is_show'] = 1;
+                if ($res = SystemStoreSender::create($data)) {
+                    SystemStoreSender::commitTrans();
+                    JsonService::success('保存成功', ['id' => $res->id]);
+                } else {
+                    SystemStoreSender::rollbackTrans();
+                    JsonService::fail('保存失败!');
+                }
+            }
+        } catch (\Exception $e) {
+            SystemStoreSender::rollbackTrans();
+            JsonService::fail($e->getMessage());
+        }
+    }
+
+    /**
+     * 设置单个门店是否显示
+     * @param string $is_show
+     * @param string $id
+     * @return json
+     */
+    public function set_sender_show($is_show = '', $id = '')
+    {
+        ($is_show == '' || $id == '') && JsonService::fail('缺少参数');
+        $res = SystemStoreSender::where(['id' => $id])->update(['is_show' => (int)$is_show]);
+        if ($res) {
+            return JsonService::successful($is_show == 1 ? '设置显示成功' : '设置隐藏成功');
+        } else {
+            return JsonService::fail($is_show == 1 ? '设置显示失败' : '设置隐藏失败');
+        }
+    }
+
+    /**
+     * 删除恢复门店
+     * @param $id
+     */
+    public function sender_delete($id)
+    {
+        if (!$id) return $this->failed('数据不存在');
+        if (!SystemStoreSender::be(['id' => $id])) return $this->failed('数据不存在');
+        if (SystemStoreSender::be(['id' => $id, 'is_del' => 1])) {
+            $data['is_del'] = 0;
+            if (!SystemStoreSender::edit($data, $id))
+                return Json::fail(SystemStoreSender::getErrorInfo('恢复失败,请稍候再试!'));
+            else
+                return Json::successful('恢复门店成功!');
+        } else {
+            $data['is_del'] = 1;
+            if (!SystemStoreSender::edit($data, $id))
+                return Json::fail(SystemStoreSender::getErrorInfo('删除失败,请稍候再试!'));
+            else
+                return Json::successful('删除门店成功!');
+        }
+    }
 }

+ 137 - 0
app/admin/model/system/SystemStoreSender.php

@@ -0,0 +1,137 @@
+<?php
+
+
+namespace app\admin\model\system;
+
+use app\admin\model\order\StoreOrder;
+use crmeb\traits\ModelTrait;
+use crmeb\basic\BaseModel;
+use crmeb\services\PHPExcelService;
+
+/**
+ * 门店自提 model
+ * Class SystemStore
+ * @package app\admin\model\system
+ */
+class SystemStoreSender extends BaseModel
+{
+    use ModelTrait;
+
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 模型名称
+     * @var string
+     */
+    protected $name = 'system_store_sender';
+
+
+    public static function verificWhere()
+    {
+        return self::where('is_show', 1)->where('is_del', 0);
+    }
+
+    /**
+     * 获取门店信息
+     * @param int $id
+     * @return array|\think\Model|null
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function getStoreDispose($id = 0, $store_id = 0)
+    {
+        if ($id)
+            $storeInfo = self::verificWhere()->where('id', $id)->find();
+        else
+//            $storeInfo = self::verificWhere()->find();
+            $storeInfo = [];
+
+        if ($storeInfo) {
+            if ($store_id && $store_id != $storeInfo) {
+                goto end;
+            }
+            $storeInfo['store'] = SystemStore::get($storeInfo['store_id'])->toArray();
+        } else {
+            end:
+            $storeInfo['id'] = 0;
+            $storeInfo['store'] = [];
+        }
+        return $storeInfo;
+    }
+
+    /**
+     * 获取门店列表
+     * @param $where
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function getStoreList($where)
+    {
+        $model = new self();
+        if (isset($where['store_id']) && $where['store_id'] != '') {
+            $model = $model->where('store_id', $where['store_id']);
+        }
+        if (isset($where['name']) && $where['name'] != '') {
+            $model = $model->where('id|name', 'like', '%' . $where['name'] . '%');
+        }
+        if (isset($where['type']) && $where['type'] != '' && ($data = self::setData($where['type']))) {
+            $model = $model->where($data);
+        }
+        $count = $model->count();
+        $data = $model->page((int)$where['page'], (int)$where['limit'])->select()->each(function ($item) {
+            $item['store'] = SystemStore::get($item['store_id'])->value('name');
+        });
+        if ($where['excel'] == 1) {
+            $export = [];
+            foreach ($data as $index => $item) {
+                $export[] = [
+                    $item['name'],
+                    $item['store'],
+                    $item['phone'],
+                ];
+            }
+            PHPExcelService::setExcelHeader(['配送员姓名', '所属门店', '配送员电话'])
+                ->setExcelTile('配送员导出', '配送员信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time()))
+                ->setExcelContent($export)
+                ->ExcelSave();
+        }
+        return compact('count', 'data');
+    }
+
+    /**
+     * 获取连表查询条件
+     * @param $type
+     * @return array
+     */
+    public static function setData($type)
+    {
+        switch ((int)$type) {
+            case 1:
+                $data = ['is_show' => 1, 'is_del' => 0];
+                break;
+            case 2:
+                $data = ['is_show' => 0, 'is_del' => 0];
+                break;
+            case 3:
+                $data = ['is_del' => 1];
+                break;
+        };
+        return isset($data) ? $data : [];
+    }
+
+    public static function dropList()
+    {
+        $model = new self();
+        $model = $model->where('is_del', 0);
+        $list = $model->select()
+            ->toArray();
+        return $list;
+    }
+}

+ 97 - 0
app/admin/view/system/system_store/add_sender.php

@@ -0,0 +1,97 @@
+<!DOCTYPE html>
+<html lang="zh-CN">
+<head>
+    {include file="public/head"}
+
+    <link href="/system/frame/css/bootstrap.min.css?v=3.4.0" rel="stylesheet">
+    <link href="/system/frame/css/style.min.css?v=3.0.0" rel="stylesheet">
+    <title>{$title|default=''}</title>
+    <style></style>
+</head>
+<body>
+<div class="wrapper wrapper-content">
+    <div class="row">
+        <div class="col-sm-12">
+            <div class="ibox float-e-margins">
+                <div class="ibox-title">
+                    <h5>配送员设置</h5>
+                </div>
+                <div id="store-attr" class="mp-form" v-cloak="">
+                    <i-Form :label-width="80" style="width: 100%">
+                        <template>
+                            <Form-Item>
+                                <Row>
+                                    <i-Col span="13">
+                                        <span>配送员姓名:</span>
+                                        <i-Input placeholder="配送员姓名" v-model="form.name" style="width: 80%"
+                                                 type="text"></i-Input>
+                                    </i-Col>
+                                </Row>
+                            </Form-Item>
+                            <Form-Item>
+                                <Row>
+                                    <i-Col span="13">
+                                        <span>配送员手机号:</span>
+                                        <i-Input placeholder="配送员手机号" v-model="form.phone" style="width: 80%"
+                                                 type="text"></i-Input>
+                                    </i-Col>
+                                </Row>
+                            </Form-Item>
+                        </template>
+                        <Form-Item>
+                            <Row>
+                                <i-Col span="8" offset="6">
+                                    <i-Button type="primary" @click="submit">提交</i-Button>
+                                </i-Col>
+                            </Row>
+                        </Form-Item>
+                    </i-Form>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+<script src="{__PLUG_PATH}city.js"></script>
+<script>
+    var storeData = {:json_encode($store)};
+    var store_id = {$store_id};
+    mpFrame.start(function (Vue) {
+        new Vue({
+            data: function () {
+                return {
+                    id: storeData.id || 0,
+                    form: {
+                        name: storeData.name || '',
+                        phone: storeData.phone || '',
+                        store_id: store_id,
+                    },
+                    visible: false,
+                }
+            },
+            methods: {
+                isPhone: function (test) {
+                    var reg = /^1[3456789]\d{9}$/;
+                    return reg.test(test);
+                },
+                submit: function () {
+                    var that = this;
+                    if (!that.form.name) return $eb.message('error', '请填写名称');
+                    if (!that.form.phone) return $eb.message('error', '请输入手机号码');
+                    if (!that.isPhone(that.form.phone)) return $eb.message('error', '请输入正确的手机号码');
+                    if (!that.form.store_id) return $eb.message('error', '请选择所属门店!');
+                    var index = layer.load(1, {
+                        shade: [0.5, '#fff']
+                    });
+                    $eb.axios.post('{:Url("save_sender")}' + (that.id ? '?id=' + that.id : ''), that.form).then(function (res) {
+                        layer.close(index);
+                        layer.msg(res.data.msg);
+                        if (res.data.data.id) that.id = res.data.data.id;
+                    }).catch(function (err) {
+                        console.log(err);
+                        layer.close(index);
+                    })
+                },
+            },
+        }).$mount(document.getElementById('store-attr'))
+    })
+</script>

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

@@ -83,6 +83,9 @@
                         <button type="button" class="layui-btn layui-btn-xs layui-btn-normal" lay-event='pick_point'>
                             自提点列表
                         </button>
+                        <button type="button" class="layui-btn layui-btn-xs layui-btn-normal" lay-event='sender'>
+                            配送员列表
+                        </button>
                         <!--                        <button type="button" class="layui-btn layui-btn-xs layui-btn-normal" lay-event='bill'>-->
                         <!--                            门店佣金-->
                         <!--                        </button>-->
@@ -191,6 +194,12 @@
                     w: 1100
                 });
                 break;
+            case 'sender':
+                $eb.createModalFrame(data.name + '-配送员', layList.U({a: 'store_sender', q: {id: data.id}}), {
+                    h: 700,
+                    w: 1100
+                });
+                break;
             case 'bill':
                 $eb.createModalFrame(data.name + '-佣金', layList.U({a: 'store_bill_log', q: {id: data.id}}), {
                     h: 700,

+ 179 - 0
app/admin/view/system/system_store/store_sender.php

@@ -0,0 +1,179 @@
+{extend name="public/container"}
+{block name="head_top"}
+
+{/block}
+{block name="content"}
+<div class="layui-fluid" style="background: #fff;margin-top: -10px;">
+    <div class="layui-tab layui-tab-brief" lay-filter="tab">
+        <ul class="layui-tab-title">
+            <li lay-id="list" {eq name='type' value='1' }class="layui-this" {
+            /eq}>
+            <a href="{eq name='type' value='1'}javascript:;{else}{:Url('store_sender',['id'=>$id,'type'=>1])}{/eq}">显示中的配送员({$show})</a>
+            </li>
+            <li lay-id="list" {eq name='type' value='2' }class="layui-this" {
+            /eq}>
+            <a href="{eq name='type' value='2'}javascript:;{else}{:Url('store_sender',['id'=>$id,'type'=>2])}{/eq}">隐藏中的配送员({$hide})</a>
+            </li>
+            <li lay-id="list" {eq name='type' value='3' }class="layui-this" {
+            /eq}>
+            <a href="{eq name='type' value='3'}javascript:;{else}{:Url('store_sender',['id'=>$id,'type'=>3])}{/eq}">回收站的配送员({$recycle})</a>
+            </li>
+        </ul>
+    </div>
+    <div class="layui-row layui-col-space15">
+        <div class="layui-col-md12">
+            <div class="layui-card">
+                <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">
+                                    <input type="text" name="name" class="layui-input" placeholder="请输入配送员名称,编号">
+                                    <input type="hidden" name="type" value="{$type}">
+                                </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>
+                                    <button class="layui-btn layui-btn-primary layui-btn-sm export" lay-submit="export"
+                                            lay-filter="export">
+                                        <i class="fa fa-floppy-o" style="margin-right: 3px;"></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="layui-btn-container">
+                        <button class="layui-btn layui-btn-sm"
+                                onclick="$eb.createModalFrame(this.innerText,'{:Url('add_sender',['store_id'=>$id])}',{h:700,w:1100})">
+                            添加配送员
+                        </button>
+                    </div>
+                    <table class="layui-hide" id="List" lay-filter="List"></table>
+                    <script type="text/html" id="headimgurl">
+                        <img style="cursor: pointer" lay-event='open_image' src="{{d.image}}">
+                    </script>
+                    <script type="text/html" id="checkboxstatus">
+                        <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="act">
+                        <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='bill'>-->
+                        <!--                            门店佣金-->
+                        <!--                        </button>-->
+                        <button type="button" class="layui-btn layui-btn-xs layui-btn-normal" lay-event='del'>
+                            {{# if(d.is_del){ }}
+                            恢复配送员
+                            {{# }else{ }}
+                            删除配送员
+                            {{# } }}
+                        </button>
+                    </script>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+<script src="{__ADMIN_PATH}js/layuiList.js"></script>
+{/block}
+{block name="script"}
+<script>
+    var type = <?=$type?>;
+    var store_id = <?=$id?>;
+    layList.tableList('List', "{:Url('store_sender_list',['id'=>$id,'type'=>$type])}", function () {
+        return [
+            {field: 'id', title: 'ID', sort: true, event: 'id', width: '4%'},
+            {field: 'name', title: '配送员姓名', width: '10%'},
+            {field: 'phone', title: '配送员电话', width: '8%'},
+            {field: 'status', title: '是否显示', templet: "#checkboxstatus", width: '8%'},
+            {field: 'right', title: '操作', align: 'center', toolbar: '#act', width: '14%'},
+        ];
+    });
+    //查询条件
+    layList.search('search', function (where) {
+        where.store_id = store_id;
+        layList.reload(where);
+    });
+    //excel下载
+    layList.search('export', function (where) {
+        where.excel = 1;
+        where.store_id = store_id;
+        location.href = layList.U({c: 'system.system_store', a: 'store_sender_list', q: where});
+    })
+    //门店是否显示
+    layList.switch('is_show', function (odj, value) {
+        if (odj.elem.checked == true) {
+            layList.baseGet(layList.Url({
+                c: 'system.system_store',
+                a: 'set_sender_show',
+                p: {is_show: 1, id: value}
+            }), function (res) {
+                layList.msg(res.msg, function () {
+                    layList.reload();
+                });
+            });
+        } else {
+            layList.baseGet(layList.Url({
+                c: 'system.system_store',
+                a: 'set_sender_show',
+                p: {is_show: 0, id: value}
+            }), function (res) {
+                layList.msg(res.msg, function () {
+                    layList.reload();
+                });
+            });
+        }
+    });
+    //点击事件绑定
+    layList.tool(function (event, data, obj) {
+        switch (event) {
+            case 'del':
+                var url = layList.U({c: 'system.system_store', a: 'sender_delete', q: {id: data.id}});
+                if (data.is_del) var code = {title: "操作提示", text: "确定恢复配送员吗?", type: 'info', confirm: '是的,恢复该配送员'};
+                else var code = {title: "操作提示", text: "确定将该配送员删除吗?", type: 'info', confirm: '是的,删除该配送员'};
+                $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();
+                            location.reload();
+                        } else
+                            return Promise.reject(res.data.msg || '删除失败')
+                    }).catch(function (err) {
+                        $eb.$swal('error', err);
+                    });
+                }, code)
+                break;
+            case 'open_image':
+                $eb.openImage(data.image);
+                break;
+            case 'edit':
+                $eb.createModalFrame(data.name + '-编辑', layList.U({
+                    a: 'add_sender',
+                    q: {id: data.id, store_id: store_id}
+                }), {h: 700, w: 1100});
+                break;
+            // case 'bill':
+            //     $eb.createModalFrame(data.name + '-佣金', layList.U({a: 'store_bill_log', q: {id: data.id}}), {
+            //         h: 700,
+            //         w: 1100
+            //     });
+            //     break;
+        }
+    })
+</script>
+{/block}