Browse Source

产品配置,打码列表

曹鹤洋 2 years ago
parent
commit
a75ca4ac6c

+ 399 - 0
application/admin/controller/QcodeBach.php

@@ -0,0 +1,399 @@
+<?php
+
+namespace app\admin\controller;
+
+use app\admin\model\QcodeCompany;
+use app\common\controller\Backend;
+use \think\Session;
+
+/**
+ * 
+ *
+ * @icon fa fa-circle-o
+ */
+class QcodeBach extends Backend
+{
+
+    /**
+     * Product模型对象
+     * @var \app\admin\model\QcodeBach
+     */
+    protected $model = null;
+
+    public function _initialize()
+    {
+        parent::_initialize();
+        $this->model = new \app\admin\model\QcodeBach();
+    }
+
+
+
+    /**
+     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
+     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
+     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
+     */
+
+
+    /**
+     * 查看
+     */
+    public function index()
+    {
+        //当前是否为关联查询
+        $this->relationSearch = false;
+        //设置过滤方法
+        $this->request->filter(['strip_tags', 'trim']);
+        if ($this->request->isAjax()) {
+            //如果发送的来源是Selectpage,则转发到Selectpage
+            if ($this->request->request('keyField')) {
+                return $this->selectpage();
+            }
+            $where = [
+                'delete_time'=> ''
+            ];
+
+            $req = input();
+            $req['sort'] == 'id' ? $sort = '_id' : $sort = $req['sort'];
+            $order = $req['order'];
+            $offset = $req['offset'];
+            $limit = $req['limit'];
+
+            // 构造模糊查询条件
+//            $regex = new MongoDB\BSON\Regex('.*abc.*', 'i');
+//            $filter = ['field' => $regex];
+
+            $filter = json_decode($req['filter'], true);
+            foreach ($filter as $k => $v){
+                $where[$k] = new \MongoDB\BSON\Regex($v);
+            }
+
+            $list = $this->model->where($where)
+                ->order($sort,$order)
+                ->limit($limit)
+                ->skip($offset)
+                ->select();
+            foreach ($list as $k=>$v) {
+                $oid = $v['_id']->jsonSerialize();
+                $list[$k]['id'] = $oid['$oid'];
+            }
+
+            $result = array("total" => count($list), "rows" => $list);
+
+            return json($result);
+        }
+        return $this->view->fetch();
+    }
+
+    /**
+     * 查看
+     */
+    public function table1()
+    {
+        //当前是否为关联查询
+        $this->relationSearch = false;
+        //设置过滤方法
+        $this->request->filter(['strip_tags', 'trim']);
+        if ($this->request->isAjax()) {
+            //如果发送的来源是Selectpage,则转发到Selectpage
+            if ($this->request->request('keyField')) {
+                return $this->selectpage();
+            }
+            $where = [
+                'delete_time'=> ''
+            ];
+
+            $req = input();
+            $req['sort'] == 'id' ? $sort = '_id' : $sort = $req['sort'];
+            $order = $req['order'];
+            $offset = $req['offset'];
+            $limit = $req['limit'];
+
+            // 构造模糊查询条件
+//            $regex = new MongoDB\BSON\Regex('.*abc.*', 'i');
+//            $filter = ['field' => $regex];
+
+            $filter = json_decode($req['filter'], true);
+            foreach ($filter as $k => $v){
+                $where[$k] = new \MongoDB\BSON\Regex($v);
+            }
+            $total = $this->model->where($where)
+                ->order($sort,$order)
+                ->skip($offset)
+                ->select();
+            $list = $this->model->where($where)
+                ->order($sort,$order)
+                ->limit($limit)
+                ->skip($offset)
+                ->select();
+            foreach ($list as $k=>$v) {
+                $oid = $v['_id']->jsonSerialize();
+                $list[$k]['id'] = $oid['$oid'];
+            }
+
+            $result = array("total" => count($total), "rows" => $list);
+
+            return json($result);
+        }
+        return $this->view->fetch();
+    }
+
+    /**
+     * 查看
+     */
+    public function table2()
+    {
+        //当前是否为关联查询
+        $this->relationSearch = false;
+        //设置过滤方法
+        $this->request->filter(['strip_tags', 'trim']);
+        if ($this->request->isAjax()) {
+            //如果发送的来源是Selectpage,则转发到Selectpage
+            if ($this->request->request('keyField')) {
+                return $this->selectpage();
+            }
+            $userInfo = Session::get('admin');
+            $company_id = (int)$userInfo['company'];
+            $where = [
+//                'company_id'=>(int)$userInfo['company'],
+                'delete_time'=> ''
+            ];
+
+            $req = input();
+            $req['sort'] == 'id' ? $sort = '_id' : $sort = $req['sort'];
+            $order = $req['order'];
+            $offset = $req['offset'];
+            $limit = $req['limit'];
+
+            // 构造模糊查询条件
+//            $regex = new MongoDB\BSON\Regex('.*abc.*', 'i');
+//            $filter = ['field' => $regex];
+
+            $filter = json_decode($req['filter'], true);
+            foreach ($filter as $k => $v){
+                $where[$k] = new \MongoDB\BSON\Regex($v);
+            }
+
+            $db = new QcodeCompany();
+            $rows = $db->name($company_id.'_'."qcode_company")
+                ->where('delete_time','')
+                ->column('product_id');
+            $rows = array_values($rows);
+
+            $total = $this->model->where($where)
+                ->where('_id','in',$rows)
+                ->order($sort,$order)
+                ->skip($offset)
+                ->select();
+
+            $list = $this->model->where($where)
+                ->where('_id','in',$rows)
+                ->order($sort,$order)
+                ->limit($limit)
+                ->skip($offset)
+                ->select();
+            foreach ($list as $k=>$v) {
+                $oid = $v['_id']->jsonSerialize();
+                $list[$k]['id'] = $oid['$oid'];
+            }
+
+            $result = array("total" => count($total), "rows" => $list);
+
+            return json($result);
+        }
+        return $this->view->fetch();
+    }
+    /**
+     * 新增
+     */
+    public function add()
+    {
+        if ($this->request->isAjax()){
+            $req = $this->request->post();
+            if(!isset($req['row']['product_code']) || empty($req['row']['product_code'])){
+                $this->error('请填写编号');
+            }else{
+                $data = [
+                    'product_code'=>$req['row']['product_code'],
+                    'delete_time'=>'',
+                ];
+                if ($this->model->where($data)->find()){
+                    $this->error('编号已存在');
+                }
+            }
+            if(!isset($req['row']['product_name']) || empty($req['row']['product_name'])){
+                $this->error('请填写名称');
+            }else{
+                $data = [
+                    'product_name'=>$req['row']['product_name'],
+                    'delete_time'=>'',
+                ];
+                if ($this->model->where($data)->find()){
+                    $this->error('名称已存在');
+                }
+            }
+            if(!isset($req['row']['temple']) || empty($req['row']['temple'])){
+                $this->error('请填写辅料代号');
+            }
+            if(!isset($req['row']['main_unit'])){
+                $this->error('请填写主计量单位');
+            }
+            if(!isset($req['row']['sec_unit'])){
+                $this->error('请填写辅计量单位');
+            }
+            if(!isset($req['row']['proportion'])){
+                $this->error('请填写换算关系');
+            }
+            $data = [
+                'product_code'      =>$req['row']['product_code'],
+                'product_name'      =>$req['row']['product_name'],
+                'temple'            =>$req['row']['temple'],
+                'main_unit'         =>$req['row']['main_unit'],
+                'sec_unit'          =>$req['row']['sec_unit'],
+                'proportion'        =>$req['row']['proportion'],
+                'create_time'        =>date('Y-m-d H:i:s'),
+            ];
+            //插入数据
+            $re = $this->model->save($data);
+            if($re){
+                $this->success('成功');
+            }else{
+                $this->error('失败');
+            }
+        }
+        return $this->view->fetch();
+
+    }
+
+    /**
+     * 编辑
+     */
+    public function edit($ids = NULL)
+    {
+        if ($this->request->isAjax()){
+
+            $req = $this->request->post();
+            if(!isset($req['row']['product_code']) || empty($req['row']['product_code'])){
+                $this->error('请填写编号');
+            }else{
+                $data = [
+                    'product_code'=>$req['row']['product_code'],
+                    'delete_time'=>'',
+                ];
+                if ($this->model->where($data)->where('_id','neq',$ids)->find()){
+                    $this->error('编号已存在');
+                }
+            }
+            if(!isset($req['row']['product_name']) || empty($req['row']['product_name'])){
+                $this->error('请填写名称');
+            }else{
+                $data = [
+                    'product_name'=>$req['row']['product_name'],
+                    'delete_time'=>'',
+                ];
+                if ($this->model->where($data)->where('_id','neq',$ids)->find()){
+                    $this->error('名称已存在');
+                }
+            }
+            if(!isset($req['row']['temple']) || empty($req['row']['temple'])){
+                $this->error('请填写辅料代号');
+            }
+            if(!isset($req['row']['main_unit'])){
+                $this->error('请填写主计量单位');
+            }
+            if(!isset($req['row']['sec_unit'])){
+                $this->error('请填写辅计量单位');
+            }
+            if(!isset($req['row']['proportion'])){
+                $this->error('请填写换算关系');
+            }
+            $data = [
+                'product_code'      =>$req['row']['product_code'],
+                'product_name'      =>$req['row']['product_name'],
+                'temple'            =>$req['row']['temple'],
+                'main_unit'         =>$req['row']['main_unit'],
+                'sec_unit'          =>$req['row']['sec_unit'],
+                'proportion'        =>$req['row']['proportion'],
+                'update_time'       =>date('Y-m-d H:i:s'),
+            ];
+
+            //修改数据
+            $department = \app\admin\model\QcodeProduct::get(['_id' => new \MongoDB\BSON\ObjectID($ids)]);
+            $re = $department->save($data);
+            if($re){
+                $this->success('修改成功');
+            }else{
+                $this->error('修改失败');
+            }
+        }
+        $row = $this->model->where('_id',$ids)->find();
+
+        $this->view->assign('row',$row);
+        return $this->view->fetch();
+
+    }
+
+    /**
+     * 删除
+     */
+    public function del($ids = NULL)
+    {
+        $department = \app\admin\model\QcodeProduct::get(['_id' => new \MongoDB\BSON\ObjectID($ids)]);
+
+        $department->delete_time = date('Y-m-d H:i:s');
+        $re = $department->save();
+        if($re){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 绑定
+     */
+    public function bind($ids = NULL)
+    {
+        $userInfo = Session::get('admin');
+        $company_id = (int)$userInfo['company'];
+        $db = new QcodeCompany();
+        //查询是否已经添加
+        $row = $db->name($company_id.'_'."qcode_company")
+            ->where(['delete_time'=>'','product_id'=>$ids])
+            ->find();
+        if($row) $this->success('已添加');
+
+        $data = [
+            'product_id'=>$ids,
+            'create_time'=>date('Y-m-d H:i:s'),
+        ];
+
+        //插入qcode_company数据
+        $bool = $db->save($data);
+        if($bool){
+            $this->success('添加成功');
+        }else{
+            $this->error('添加失败');
+        }
+    }
+
+    /**
+     * 解绑
+     */
+    public function unbind($ids = NULL)
+    {
+        $userInfo = Session::get('admin');
+        $company_id = (int)$userInfo['company'];
+        $db = new QcodeCompany();
+        //查询是否已经添加
+        $bool = $db->name($company_id.'_'."qcode_company")
+            ->where(['delete_time'=>'','product_id'=>$ids])
+            ->update(['delete_time'=>date('Y-m-d H:i:s')]);
+
+        if($bool){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+}

+ 399 - 0
application/admin/controller/QcodeProduct.php

@@ -0,0 +1,399 @@
+<?php
+
+namespace app\admin\controller;
+
+use app\admin\model\QcodeCompany;
+use app\common\controller\Backend;
+use \think\Session;
+
+/**
+ * 
+ *
+ * @icon fa fa-circle-o
+ */
+class QcodeProduct extends Backend
+{
+
+    /**
+     * Product模型对象
+     * @var \app\admin\model\QcodeProduct
+     */
+    protected $model = null;
+
+    public function _initialize()
+    {
+        parent::_initialize();
+        $this->model = new \app\admin\model\QcodeProduct();
+    }
+
+
+
+    /**
+     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
+     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
+     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
+     */
+
+
+    /**
+     * 查看
+     */
+    public function index()
+    {
+        //当前是否为关联查询
+        $this->relationSearch = false;
+        //设置过滤方法
+        $this->request->filter(['strip_tags', 'trim']);
+        if ($this->request->isAjax()) {
+            //如果发送的来源是Selectpage,则转发到Selectpage
+            if ($this->request->request('keyField')) {
+                return $this->selectpage();
+            }
+            $where = [
+                'delete_time'=> ''
+            ];
+
+            $req = input();
+            $req['sort'] == 'id' ? $sort = '_id' : $sort = $req['sort'];
+            $order = $req['order'];
+            $offset = $req['offset'];
+            $limit = $req['limit'];
+
+            // 构造模糊查询条件
+//            $regex = new MongoDB\BSON\Regex('.*abc.*', 'i');
+//            $filter = ['field' => $regex];
+
+            $filter = json_decode($req['filter'], true);
+            foreach ($filter as $k => $v){
+                $where[$k] = new \MongoDB\BSON\Regex($v);
+            }
+
+            $list = $this->model->where($where)
+                ->order($sort,$order)
+                ->limit($limit)
+                ->skip($offset)
+                ->select();
+            foreach ($list as $k=>$v) {
+                $oid = $v['_id']->jsonSerialize();
+                $list[$k]['id'] = $oid['$oid'];
+            }
+
+            $result = array("total" => count($list), "rows" => $list);
+
+            return json($result);
+        }
+        return $this->view->fetch();
+    }
+
+    /**
+     * 查看
+     */
+    public function table1()
+    {
+        //当前是否为关联查询
+        $this->relationSearch = false;
+        //设置过滤方法
+        $this->request->filter(['strip_tags', 'trim']);
+        if ($this->request->isAjax()) {
+            //如果发送的来源是Selectpage,则转发到Selectpage
+            if ($this->request->request('keyField')) {
+                return $this->selectpage();
+            }
+            $where = [
+                'delete_time'=> ''
+            ];
+
+            $req = input();
+            $req['sort'] == 'id' ? $sort = '_id' : $sort = $req['sort'];
+            $order = $req['order'];
+            $offset = $req['offset'];
+            $limit = $req['limit'];
+
+            // 构造模糊查询条件
+//            $regex = new MongoDB\BSON\Regex('.*abc.*', 'i');
+//            $filter = ['field' => $regex];
+
+            $filter = json_decode($req['filter'], true);
+            foreach ($filter as $k => $v){
+                $where[$k] = new \MongoDB\BSON\Regex($v);
+            }
+            $total = $this->model->where($where)
+                ->order($sort,$order)
+                ->skip($offset)
+                ->select();
+            $list = $this->model->where($where)
+                ->order($sort,$order)
+                ->limit($limit)
+                ->skip($offset)
+                ->select();
+            foreach ($list as $k=>$v) {
+                $oid = $v['_id']->jsonSerialize();
+                $list[$k]['id'] = $oid['$oid'];
+            }
+
+            $result = array("total" => count($total), "rows" => $list);
+
+            return json($result);
+        }
+        return $this->view->fetch();
+    }
+
+    /**
+     * 查看
+     */
+    public function table2()
+    {
+        //当前是否为关联查询
+        $this->relationSearch = false;
+        //设置过滤方法
+        $this->request->filter(['strip_tags', 'trim']);
+        if ($this->request->isAjax()) {
+            //如果发送的来源是Selectpage,则转发到Selectpage
+            if ($this->request->request('keyField')) {
+                return $this->selectpage();
+            }
+            $userInfo = Session::get('admin');
+            $company_id = (int)$userInfo['company'];
+            $where = [
+//                'company_id'=>(int)$userInfo['company'],
+                'delete_time'=> ''
+            ];
+
+            $req = input();
+            $req['sort'] == 'id' ? $sort = '_id' : $sort = $req['sort'];
+            $order = $req['order'];
+            $offset = $req['offset'];
+            $limit = $req['limit'];
+
+            // 构造模糊查询条件
+//            $regex = new MongoDB\BSON\Regex('.*abc.*', 'i');
+//            $filter = ['field' => $regex];
+
+            $filter = json_decode($req['filter'], true);
+            foreach ($filter as $k => $v){
+                $where[$k] = new \MongoDB\BSON\Regex($v);
+            }
+
+            $db = new QcodeCompany();
+            $rows = $db->name($company_id.'_'."qcode_company")
+                ->where('delete_time','')
+                ->column('product_id');
+            $rows = array_values($rows);
+
+            $total = $this->model->where($where)
+                ->where('_id','in',$rows)
+                ->order($sort,$order)
+                ->skip($offset)
+                ->select();
+
+            $list = $this->model->where($where)
+                ->where('_id','in',$rows)
+                ->order($sort,$order)
+                ->limit($limit)
+                ->skip($offset)
+                ->select();
+            foreach ($list as $k=>$v) {
+                $oid = $v['_id']->jsonSerialize();
+                $list[$k]['id'] = $oid['$oid'];
+            }
+
+            $result = array("total" => count($total), "rows" => $list);
+
+            return json($result);
+        }
+        return $this->view->fetch();
+    }
+    /**
+     * 新增
+     */
+    public function add()
+    {
+        if ($this->request->isAjax()){
+            $req = $this->request->post();
+            if(!isset($req['row']['product_code']) || empty($req['row']['product_code'])){
+                $this->error('请填写编号');
+            }else{
+                $data = [
+                    'product_code'=>$req['row']['product_code'],
+                    'delete_time'=>'',
+                ];
+                if ($this->model->where($data)->find()){
+                    $this->error('编号已存在');
+                }
+            }
+            if(!isset($req['row']['product_name']) || empty($req['row']['product_name'])){
+                $this->error('请填写名称');
+            }else{
+                $data = [
+                    'product_name'=>$req['row']['product_name'],
+                    'delete_time'=>'',
+                ];
+                if ($this->model->where($data)->find()){
+                    $this->error('名称已存在');
+                }
+            }
+            if(!isset($req['row']['temple']) || empty($req['row']['temple'])){
+                $this->error('请填写辅料代号');
+            }
+            if(!isset($req['row']['main_unit'])){
+                $this->error('请填写主计量单位');
+            }
+            if(!isset($req['row']['sec_unit'])){
+                $this->error('请填写辅计量单位');
+            }
+            if(!isset($req['row']['proportion'])){
+                $this->error('请填写换算关系');
+            }
+            $data = [
+                'product_code'      =>$req['row']['product_code'],
+                'product_name'      =>$req['row']['product_name'],
+                'temple'            =>$req['row']['temple'],
+                'main_unit'         =>$req['row']['main_unit'],
+                'sec_unit'          =>$req['row']['sec_unit'],
+                'proportion'        =>$req['row']['proportion'],
+                'create_time'        =>date('Y-m-d H:i:s'),
+            ];
+            //插入数据
+            $re = $this->model->save($data);
+            if($re){
+                $this->success('成功');
+            }else{
+                $this->error('失败');
+            }
+        }
+        return $this->view->fetch();
+
+    }
+
+    /**
+     * 编辑
+     */
+    public function edit($ids = NULL)
+    {
+        if ($this->request->isAjax()){
+
+            $req = $this->request->post();
+            if(!isset($req['row']['product_code']) || empty($req['row']['product_code'])){
+                $this->error('请填写编号');
+            }else{
+                $data = [
+                    'product_code'=>$req['row']['product_code'],
+                    'delete_time'=>'',
+                ];
+                if ($this->model->where($data)->where('_id','neq',$ids)->find()){
+                    $this->error('编号已存在');
+                }
+            }
+            if(!isset($req['row']['product_name']) || empty($req['row']['product_name'])){
+                $this->error('请填写名称');
+            }else{
+                $data = [
+                    'product_name'=>$req['row']['product_name'],
+                    'delete_time'=>'',
+                ];
+                if ($this->model->where($data)->where('_id','neq',$ids)->find()){
+                    $this->error('名称已存在');
+                }
+            }
+            if(!isset($req['row']['temple']) || empty($req['row']['temple'])){
+                $this->error('请填写辅料代号');
+            }
+            if(!isset($req['row']['main_unit'])){
+                $this->error('请填写主计量单位');
+            }
+            if(!isset($req['row']['sec_unit'])){
+                $this->error('请填写辅计量单位');
+            }
+            if(!isset($req['row']['proportion'])){
+                $this->error('请填写换算关系');
+            }
+            $data = [
+                'product_code'      =>$req['row']['product_code'],
+                'product_name'      =>$req['row']['product_name'],
+                'temple'            =>$req['row']['temple'],
+                'main_unit'         =>$req['row']['main_unit'],
+                'sec_unit'          =>$req['row']['sec_unit'],
+                'proportion'        =>$req['row']['proportion'],
+                'update_time'       =>date('Y-m-d H:i:s'),
+            ];
+
+            //修改数据
+            $department = \app\admin\model\QcodeProduct::get(['_id' => new \MongoDB\BSON\ObjectID($ids)]);
+            $re = $department->save($data);
+            if($re){
+                $this->success('修改成功');
+            }else{
+                $this->error('修改失败');
+            }
+        }
+        $row = $this->model->where('_id',$ids)->find();
+
+        $this->view->assign('row',$row);
+        return $this->view->fetch();
+
+    }
+
+    /**
+     * 删除
+     */
+    public function del($ids = NULL)
+    {
+        $department = \app\admin\model\QcodeProduct::get(['_id' => new \MongoDB\BSON\ObjectID($ids)]);
+
+        $department->delete_time = date('Y-m-d H:i:s');
+        $re = $department->save();
+        if($re){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 绑定
+     */
+    public function bind($ids = NULL)
+    {
+        $userInfo = Session::get('admin');
+        $company_id = (int)$userInfo['company'];
+        $db = new QcodeCompany();
+        //查询是否已经添加
+        $row = $db->name($company_id.'_'."qcode_company")
+            ->where(['delete_time'=>'','product_id'=>$ids])
+            ->find();
+        if($row) $this->success('已添加');
+
+        $data = [
+            'product_id'=>$ids,
+            'create_time'=>date('Y-m-d H:i:s'),
+        ];
+
+        //插入qcode_company数据
+        $bool = $db->save($data);
+        if($bool){
+            $this->success('添加成功');
+        }else{
+            $this->error('添加失败');
+        }
+    }
+
+    /**
+     * 解绑
+     */
+    public function unbind($ids = NULL)
+    {
+        $userInfo = Session::get('admin');
+        $company_id = (int)$userInfo['company'];
+        $db = new QcodeCompany();
+        //查询是否已经添加
+        $bool = $db->name($company_id.'_'."qcode_company")
+            ->where(['delete_time'=>'','product_id'=>$ids])
+            ->update(['delete_time'=>date('Y-m-d H:i:s')]);
+
+        if($bool){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+}

+ 10 - 0
application/admin/lang/zh-cn/qcode_bach.php

@@ -0,0 +1,10 @@
+<?php
+
+return [
+    'Matter_no'          => '辅料编号',
+    'Matter_name'          => '辅料名称',
+    'Bach_num'              => '批次号',
+    'Larger_num'             => '大件数量',
+    'Small_num'              => '小件数量',
+    'Proportion'            => '换算关系',
+];

+ 10 - 0
application/admin/lang/zh-cn/qcode_product.php

@@ -0,0 +1,10 @@
+<?php
+
+return [
+    'Product_code'          => '编号',
+    'Product_name'          => '名称',
+    'Temple'                => '辅料代号',
+    'Main_unit'             => '主计量单位',
+    'Sec_unit'              => '辅计量单位',
+    'Proportion'            => '换算关系',
+];

+ 70 - 0
application/admin/model/QcodeBach.php

@@ -0,0 +1,70 @@
+<?php
+namespace app\admin\model;
+
+use think\Model;
+use think\Log;
+use \think\Session;
+
+use traits\model\SoftDelete;
+class QcodeBach extends Model
+{
+    protected $connection = 'mongodb';
+    protected $table = '';
+    protected $deleteTime = 'delete_time';
+
+    use SoftDelete;
+
+    public function createIndex()
+    {
+        //获取公司编码
+        $userInfo = Session::get('admin');
+        $company_id = (int)$userInfo['company'];
+
+        $this->connection->command([
+            'createIndexes' => $company_id.'_'."qcode_bach",
+            'indexes' => [
+                [
+                    'key' => ['pid' => 1],
+                    'name' => 'pid_index'
+                ]
+            ]
+        ]);
+    }
+
+    protected static function init()
+    {
+        self::event('before_insert', function ($model) {
+            //获取公司编码
+            $userInfo = Session::get('admin');
+            $company_id = (int)$userInfo['company'];
+
+            // 设置表名
+            $model->table($company_id.'_'."qcode_bach");
+        });
+
+        //获取公司编码
+        $userInfo = Session::get('admin');
+        $company_id = (int)$userInfo['company'];
+
+        //把当前表加入到监听队列
+        Redis_sAdd('watch_tables', $company_id.'_'."qcode_bach");
+        self::beforeWrite(function ($model) {
+            if (!isset($model->create_time)){
+                $model->create_time="";
+            }
+            if (!isset($model->update_time)){
+                $model->update_time="";
+            }
+            if (!isset($model->delete_time)){
+                $model->delete_time="";
+            }
+
+            $model->sync_flag=0;
+        });
+
+//        $model->sync_flag=1;
+
+
+    }
+
+}

+ 70 - 0
application/admin/model/QcodeCompany.php

@@ -0,0 +1,70 @@
+<?php
+namespace app\admin\model;
+
+use think\Model;
+use think\Log;
+use \think\Session;
+
+use traits\model\SoftDelete;
+class QcodeCompany extends Model
+{
+    protected $connection = 'mongodb';
+    protected $table = '';
+    protected $deleteTime = 'delete_time';
+
+    use SoftDelete;
+
+    public function createIndex()
+    {
+        //获取公司编码
+        $userInfo = Session::get('admin');
+        $company_id = (int)$userInfo['company'];
+
+        $this->connection->command([
+            'createIndexes' => $company_id.'_'."qcode_company",
+            'indexes' => [
+                [
+                    'key' => ['pid' => 1],
+                    'name' => 'pid_index'
+                ]
+            ]
+        ]);
+    }
+
+    protected static function init()
+    {
+        self::event('before_insert', function ($model) {
+            //获取公司编码
+            $userInfo = Session::get('admin');
+            $company_id = (int)$userInfo['company'];
+
+            // 设置表名
+            $model->table($company_id.'_'."qcode_company");
+        });
+
+        //获取公司编码
+        $userInfo = Session::get('admin');
+        $company_id = (int)$userInfo['company'];
+
+        //把当前表加入到监听队列
+        Redis_sAdd('watch_tables', $company_id.'_'."qcode_company");
+        self::beforeWrite(function ($model) {
+            if (!isset($model->create_time)){
+                $model->create_time="";
+            }
+            if (!isset($model->update_time)){
+                $model->update_time="";
+            }
+            if (!isset($model->delete_time)){
+                $model->delete_time="";
+            }
+
+            $model->sync_flag=0;
+        });
+
+//        $model->sync_flag=1;
+
+
+    }
+
+}

+ 70 - 0
application/admin/model/QcodeLarge.php

@@ -0,0 +1,70 @@
+<?php
+namespace app\admin\model;
+
+use think\Model;
+use think\Log;
+use \think\Session;
+
+use traits\model\SoftDelete;
+class QcodeLarge extends Model
+{
+    protected $connection = 'mongodb';
+    protected $table = '';
+    protected $deleteTime = 'delete_time';
+
+    use SoftDelete;
+
+    public function createIndex()
+    {
+        //获取公司编码
+        $userInfo = Session::get('admin');
+        $company_id = (int)$userInfo['company'];
+
+        $this->connection->command([
+            'createIndexes' => $company_id.'_'."qcode_large",
+            'indexes' => [
+                [
+                    'key' => ['pid' => 1],
+                    'name' => 'pid_index'
+                ]
+            ]
+        ]);
+    }
+
+    protected static function init()
+    {
+        self::event('before_insert', function ($model) {
+            //获取公司编码
+            $userInfo = Session::get('admin');
+            $company_id = (int)$userInfo['company'];
+
+            // 设置表名
+            $model->table($company_id.'_'."qcode_large");
+        });
+
+        //获取公司编码
+        $userInfo = Session::get('admin');
+        $company_id = (int)$userInfo['company'];
+
+        //把当前表加入到监听队列
+        Redis_sAdd('watch_tables', $company_id.'_'."qcode_large");
+        self::beforeWrite(function ($model) {
+            if (!isset($model->create_time)){
+                $model->create_time="";
+            }
+            if (!isset($model->update_time)){
+                $model->update_time="";
+            }
+            if (!isset($model->delete_time)){
+                $model->delete_time="";
+            }
+
+            $model->sync_flag=0;
+        });
+
+//        $model->sync_flag=1;
+
+
+    }
+
+}

+ 51 - 0
application/admin/model/QcodeProduct.php

@@ -0,0 +1,51 @@
+<?php
+namespace app\admin\model;
+
+use think\Model;
+use think\Log;
+use traits\model\SoftDelete;
+class QcodeProduct extends Model
+{
+    protected $connection = 'mongodb';
+    protected $table = 'qcode_product';
+    protected $deleteTime = 'delete_time';
+
+    use SoftDelete;
+
+    public function createIndex()
+    {
+        $this->connection->command([
+            'createIndexes' => $this->table,
+            'indexes' => [
+                [
+                    'key' => ['pid' => 1],
+                    'name' => 'pid_index'
+                ]
+            ]
+        ]);
+    }
+    protected static function init()
+    {
+
+        //把当前表加入到监听队列
+        Redis_sAdd('watch_tables', "qcode_product");
+        self::beforeWrite(function ($model) {
+            if (!isset($model->create_time)){
+                $model->create_time="";
+            }
+            if (!isset($model->update_time)){
+                $model->update_time="";
+            }
+            if (!isset($model->delete_time)){
+                $model->delete_time="";
+            }
+
+            $model->sync_flag=0;
+        });
+
+//        $model->sync_flag=1;
+
+
+    }
+
+}

+ 70 - 0
application/admin/model/QcodeSmall.php

@@ -0,0 +1,70 @@
+<?php
+namespace app\admin\model;
+
+use think\Model;
+use think\Log;
+use \think\Session;
+
+use traits\model\SoftDelete;
+class QcodeSmall extends Model
+{
+    protected $connection = 'mongodb';
+    protected $table = '';
+    protected $deleteTime = 'delete_time';
+
+    use SoftDelete;
+
+    public function createIndex()
+    {
+        //获取公司编码
+        $userInfo = Session::get('admin');
+        $company_id = (int)$userInfo['company'];
+
+        $this->connection->command([
+            'createIndexes' => $company_id.'_'."qcode_small",
+            'indexes' => [
+                [
+                    'key' => ['pid' => 1],
+                    'name' => 'pid_index'
+                ]
+            ]
+        ]);
+    }
+
+    protected static function init()
+    {
+        self::event('before_insert', function ($model) {
+            //获取公司编码
+            $userInfo = Session::get('admin');
+            $company_id = (int)$userInfo['company'];
+
+            // 设置表名
+            $model->table($company_id.'_'."qcode_small");
+        });
+
+        //获取公司编码
+        $userInfo = Session::get('admin');
+        $company_id = (int)$userInfo['company'];
+
+        //把当前表加入到监听队列
+        Redis_sAdd('watch_tables', $company_id.'_'."qcode_small");
+        self::beforeWrite(function ($model) {
+            if (!isset($model->create_time)){
+                $model->create_time="";
+            }
+            if (!isset($model->update_time)){
+                $model->update_time="";
+            }
+            if (!isset($model->delete_time)){
+                $model->delete_time="";
+            }
+
+            $model->sync_flag=0;
+        });
+
+//        $model->sync_flag=1;
+
+
+    }
+
+}

+ 45 - 0
application/admin/view/qcode_bach/add.html

@@ -0,0 +1,45 @@
+<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Product_code')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-product_code" data-rule="required" class="form-control" name="row[product_code]" type="number">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Product_name')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-product_name" data-rule="required" class="form-control" name="row[product_name]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Temple')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-temple" data-rule="required" class="form-control" name="row[temple]" type="number">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Main_unit')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-main_unit" class="form-control" name="row[main_unit]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Sec_unit')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-sec_unit" class="form-control" name="row[sec_unit]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Proportion')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-proportion" class="form-control" name="row[proportion]" type="number">
+        </div>
+    </div>
+    <div class="form-group layer-footer" >
+        <div style="text-align: center">
+            <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+</form>

+ 48 - 0
application/admin/view/qcode_bach/edit.html

@@ -0,0 +1,48 @@
+<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Product_code')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-product_code" data-rule="required" class="form-control" name="row[product_code]" type="number" value="{$row.product_code|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Product_name')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-product_name" data-rule="required" class="form-control" name="row[product_name]" type="text" value="{$row.product_name|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Temple')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-temple" data-rule="required" class="form-control" name="row[temple]" type="number" value="{$row.temple|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Main_unit')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-main_unit" class="form-control" name="row[main_unit]" type="text" value="{$row.main_unit|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Sec_unit')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-sec_unit" class="form-control" name="row[sec_unit]" type="text" value="{$row.sec_unit|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Proportion')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-proportion" class="form-control" name="row[proportion]" type="number" value="{$row.proportion|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+</form>
+
+

+ 49 - 0
application/admin/view/qcode_bach/index.html

@@ -0,0 +1,49 @@
+<div class="row">
+    <div class="panel panel-default panel-intro">
+        <div class="panel-body">
+            <div id="1" class="tab-content">
+                <div class="tab-pane fade active in" id="one">
+                    <div class="widget-body no-padding">
+                        <div id="toolbar1" class="toolbar">
+                            {:build_toolbar('refresh')}
+                            <a href="javascript:;" id="bind" class="btn btn-success btn-disabled disabled {:$auth->check('qcode_product/bind')?'':'hide'}" title="增加产品" ><i class="fa fa-plus"></i> 增加产品</a>
+                            <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('qcode_product/add')?'':'hide'}" data-area='["800px","500px"]' title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
+                            <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('qcode_product/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
+                            <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('qcode_product/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
+
+                        </div>
+                        <table id="table1" class="table table-striped table-bordered table-hover" width="100%">
+
+                        </table>
+
+
+                    </div>
+                </div>
+
+            </div>
+        </div>
+    </div>
+    <div class="panel panel-default panel-intro">
+        <div class="panel-body">
+            <div id="myTabContent2" class="tab-content">
+                <div class="tab-pane fade active in" id="two">
+                    <div class="widget-body no-padding">
+                        <div id="toolbar2" class="toolbar">
+                            {:build_toolbar('refresh')}
+<!--                            <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('qcode_product/add')?'':'hide'}" data-area='["800px","500px"]' title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>-->
+                            <!--                        <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('qcode_product/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>-->
+                            <a href="javascript:;" id="unbind" class="btn btn-danger btn-disabled disabled {:$auth->check('qcode_product/unbind')?'':'hide'}" title="删除产品" ><i class="fa fa-trash"></i> 删除产品</a>
+
+                        </div>
+                        <table id="table2" class="table table-striped table-bordered table-hover" width="100%">
+
+                        </table>
+
+
+                    </div>
+                </div>
+
+            </div>
+        </div>
+    </div>
+</div>

+ 45 - 0
application/admin/view/qcode_product/add.html

@@ -0,0 +1,45 @@
+<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Product_code')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-product_code" data-rule="required" class="form-control" name="row[product_code]" type="number">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Product_name')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-product_name" data-rule="required" class="form-control" name="row[product_name]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Temple')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-temple" data-rule="required" class="form-control" name="row[temple]" type="number">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Main_unit')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-main_unit" class="form-control" name="row[main_unit]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Sec_unit')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-sec_unit" class="form-control" name="row[sec_unit]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Proportion')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-proportion" class="form-control" name="row[proportion]" type="number">
+        </div>
+    </div>
+    <div class="form-group layer-footer" >
+        <div style="text-align: center">
+            <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+</form>

+ 48 - 0
application/admin/view/qcode_product/edit.html

@@ -0,0 +1,48 @@
+<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Product_code')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-product_code" data-rule="required" class="form-control" name="row[product_code]" type="number" value="{$row.product_code|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Product_name')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-product_name" data-rule="required" class="form-control" name="row[product_name]" type="text" value="{$row.product_name|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Temple')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-temple" data-rule="required" class="form-control" name="row[temple]" type="number" value="{$row.temple|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Main_unit')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-main_unit" class="form-control" name="row[main_unit]" type="text" value="{$row.main_unit|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Sec_unit')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-sec_unit" class="form-control" name="row[sec_unit]" type="text" value="{$row.sec_unit|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Proportion')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-proportion" class="form-control" name="row[proportion]" type="number" value="{$row.proportion|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+</form>
+
+

+ 49 - 0
application/admin/view/qcode_product/index.html

@@ -0,0 +1,49 @@
+<div class="row">
+    <div class="panel panel-default panel-intro">
+        <div class="panel-body">
+            <div id="1" class="tab-content">
+                <div class="tab-pane fade active in" id="one">
+                    <div class="widget-body no-padding">
+                        <div id="toolbar1" class="toolbar">
+                            {:build_toolbar('refresh')}
+                            <a href="javascript:;" id="bind" class="btn btn-success btn-disabled disabled {:$auth->check('qcode_product/bind')?'':'hide'}" title="增加产品" ><i class="fa fa-plus"></i> 增加产品</a>
+                            <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('qcode_product/add')?'':'hide'}" data-area='["800px","500px"]' title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
+                            <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('qcode_product/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
+                            <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('qcode_product/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
+
+                        </div>
+                        <table id="table1" class="table table-striped table-bordered table-hover" width="100%">
+
+                        </table>
+
+
+                    </div>
+                </div>
+
+            </div>
+        </div>
+    </div>
+    <div class="panel panel-default panel-intro">
+        <div class="panel-body">
+            <div id="myTabContent2" class="tab-content">
+                <div class="tab-pane fade active in" id="two">
+                    <div class="widget-body no-padding">
+                        <div id="toolbar2" class="toolbar">
+                            {:build_toolbar('refresh')}
+<!--                            <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('qcode_product/add')?'':'hide'}" data-area='["800px","500px"]' title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>-->
+                            <!--                        <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('qcode_product/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>-->
+                            <a href="javascript:;" id="unbind" class="btn btn-danger btn-disabled disabled {:$auth->check('qcode_product/unbind')?'':'hide'}" title="删除产品" ><i class="fa fa-trash"></i> 删除产品</a>
+
+                        </div>
+                        <table id="table2" class="table table-striped table-bordered table-hover" width="100%">
+
+                        </table>
+
+
+                    </div>
+                </div>
+
+            </div>
+        </div>
+    </div>
+</div>

+ 131 - 0
application/api/controller/Index.php

@@ -2,8 +2,14 @@
 
 namespace app\api\controller;
 
+use app\admin\model\QcodeProduct;
+use app\admin\model\QcodeUnit;
 use app\common\controller\Api;
 
+use app\admin\controller\Sample;
+use think\Log;
+use think\Db;
+
 /**
  * 首页接口
  */
@@ -20,4 +26,129 @@ class Index extends Api
     {
         $this->success('请求成功');
     }
+
+    /**
+     * 产品表qr_code_product同步
+     */
+    public function vo1()
+    {
+        $num1 = $this->request->param('num1');
+        $num2 = $this->request->param('num2');
+        if($num2<=$num1){
+            $this->error('同步num1到num2之间的数据, 要求num2大于num1');
+        }
+        $qcodeProduct = new QcodeProduct();
+
+        // 连接到其他数据库
+        $config = [
+            'type'     => 'mysql',
+            'hostname' => '127.0.0.1',
+            'database' => 'dm_7in6_com',
+            'username' => 'root',
+            'password' => 'root',
+            'charset'  => 'utf8mb4',
+            'prefix'   => 'qr_',
+        ];
+        $db = Db::connect($config);
+
+        //查询主表记录
+        $rows1 = $db->name('qcode_product')
+            ->limit($num1,$num2-$num1)
+            ->select();
+
+        foreach($rows1 as $v){
+            //1. 查询mongodb中是否存在该条记录
+            $bool = $qcodeProduct->where('oid_id',$v['id'])->find();
+            if ($bool) continue;
+
+            //2. 获取设置主表数据
+            $row['oid_id'] = $v['id'];
+            $row['product_name'] = $v['product_name'];
+            $row['product_code'] = $v['product_code'];
+            $row['temple'] = $v['temple'];
+//            unset($row['id']);
+//            $row = array_merge(['oid_id'=>$v['id']],$row);
+
+            //查询unit表数据
+            $rows2 = $db->name('qcode_unit')
+                ->where('code',$v['product_code'])
+                ->find();
+            if($rows2){
+                if($rows2['main_unit']!=null){
+                    $row['main_unit'] = $rows2['main_unit'];
+                }else{
+                    $row['main_unit'] = '';
+                }
+                if($rows2['sec_unit']!=null){
+                    $row['sec_unit'] = $rows2['sec_unit'];
+                }else{
+                    $row['sec_unit'] = '';
+                }
+                if($rows2['proportion']!=null){
+                    $row['proportion'] = $rows2['proportion'];
+                }else{
+                    $row['proportion'] = '';
+                }
+            }else{
+                $row['main_unit'] = '';
+                $row['sec_unit'] = '';
+                $row['proportion'] = '';
+            }
+
+            //3. 插入主表记录到mongodb中
+            $qcodeProduct = new QcodeProduct();
+            $qcodeProduct->save($row);
+        }
+
+        $this->success('成功');
+
+    }
+
+    /**
+     * 产品表qr_code_unit同步
+     */
+    public function vo2()
+    {
+        $num1 = $this->request->param('num1');
+        $num2 = $this->request->param('num2');
+        if($num2<=$num1){
+            $this->error('同步num1到num2之间的数据, 要求num2大于num1');
+        }
+        $qcodeUnit = new QcodeUnit();
+
+        // 连接到其他数据库
+        $config = [
+            'type'     => 'mysql',
+            'hostname' => '127.0.0.1',
+            'database' => 'dm_7in6_com',
+            'username' => 'root',
+            'password' => 'root',
+            'charset'  => 'utf8mb4',
+            'prefix'   => 'qr_',
+        ];
+        $db = Db::connect($config);
+
+        //查询主表记录
+        $rows1 = $db->name('qcode_unit')
+            ->limit($num1,$num2-$num1)
+            ->select();
+
+        foreach($rows1 as $v){
+            //1. 查询mongodb中是否存在该条记录
+            $bool = $qcodeUnit->where('oid_id',$v['id'])->find();
+            if ($bool) continue;
+
+            //2. 获取设置主表数据
+            $row = $v;
+            unset($row['id']);
+            $row = array_merge(['oid_id'=>$v['id']],$row);
+
+            //3. 插入主表记录到mongodb中
+            $qcodeUnit = new QcodeUnit();
+            $qcodeUnit->save($row);
+        }
+
+        $this->success('成功');
+
+    }
 }

+ 19 - 0
application/common.php

@@ -560,3 +560,22 @@ EOT;
         return $icon;
     }
 }
+
+
+
+if (!function_exists('Redis_sAdd')){
+    function Redis_sAdd($name,$value){
+
+        // 获取Redis连接实例
+        $redis = \think\Cache::store('redis')->handler();;
+        if(is_array($value)){
+            // 设置Set
+            // 使用call_user_func_array方法将数组拆分为参数,并设置Set
+            call_user_func_array([$redis, 'sAdd'], array_merge([$name], $value));
+        }else{
+            $redis->sAdd($name,$value);
+        }
+        // 关闭Redis连接
+
+    }
+}

+ 218 - 0
public/assets/js/backend/qcode_bach.js

@@ -0,0 +1,218 @@
+define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
+
+    var Controller = {
+        index: function () {
+            // 初始化表格参数配置
+            Table.api.init();
+            this.table.first();
+            this.table.second();
+
+            //绑定
+            $('#bind').click(function (e) {
+                var ids = $('#table1').bootstrapTable('getSelections')[0]['id'];
+
+                $.get('qcode_product/bind',{'ids':ids},function (data) {
+                    if(data.code==1){
+                        Toastr.success(data.msg)
+                        $('#table2').bootstrapTable('refresh');
+                    }else{
+                        Toastr.error(data.msg)
+                    }
+                },'json');
+
+                // layer.confirm('确定提交选中的 1 项?!', {
+                //     btn: ['确定', '取消'],
+                //     cancel: function(index, layero) {
+                //     }
+                // },function (index) {
+                //     $.get('qcode_product/bind',{'ids':ids},function (data) {
+                //         if(data.code==1){
+                //             Toastr.success(data.msg)
+                //             table2.bootstrapTable('refresh');
+                //         }else{
+                //             Toastr.error(data.msg)
+                //         }
+                //     },'json');
+                //     Layer.close(index);
+                //
+                // },function (){})
+
+            })
+
+            //绑定
+            $('#unbind').click(function (e) {
+                layer.confirm('确定提交选中的 1 项?!', {
+                    btn: ['确定', '取消'],
+                    cancel: function(index, layero) {
+                    }
+                },function (index) {
+                    var ids = $('#table2').bootstrapTable('getSelections')[0]['id'];
+
+                    $.get('qcode_product/unbind',{'ids':ids},function (data) {
+                        if(data.code==1){
+                            Toastr.success(data.msg)
+                            $('#table2').bootstrapTable('refresh');
+                        }else{
+                            Toastr.error(data.msg)
+                        }
+                    },'json');
+                    Layer.close(index);
+
+                },function (){})
+
+            })
+
+        },
+        table: {
+            first: function () {
+                // 表格1
+                var table1 = $("#table1");
+                table1.bootstrapTable({
+                    url: 'qcode_product/table1',
+                    extend: {
+                        index_url: 'qcode_product/table1' + location.search,
+                        add_url: 'qcode_product/add',
+                        edit_url: 'qcode_product/edit',
+                        del_url: 'qcode_product/del',
+                        table: 'qcode_product',
+                    },
+                    toolbar: '#toolbar1',
+                    pk: 'id',
+                    sortName: 'id',
+                    pageSize: 8,
+                    pageList: [8, 20, 50, 'All'],
+                    search: false,
+                    singleSelect: true,
+                    columns: [
+                        [
+                            {checkbox: true},
+                            {field: 'product_code', title: __('Product_code'), operate: 'LIKE'},
+                            {field: 'product_name', title: __('Product_name'), operate: 'LIKE'},
+                            {field: 'temple', title: __('Temple'), operate: 'LIKE'},
+                            {field: 'main_unit', title: __('Main_unit'), operate: 'LIKE'},
+                            {field: 'sec_unit', title: __('Sec_unit'), operate: 'LIKE'},
+                            {field: 'proportion', title: __('Proportion'), operate: 'LIKE'},
+                            // {field: 'notes', title: __('Notes')},
+                            // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+                        ]
+                    ]
+                });
+
+                // 为表格1绑定事件
+                Table.api.bindevent(table1);
+            },
+            second: function () {
+                // 表格2
+                var table2 = $("#table2");
+                table2.bootstrapTable({
+                    url: 'qcode_product/table2',
+                    extend: {
+                        index_url: '',
+                        add_url: '',
+                        edit_url: '',
+                        del_url: '',
+                        multi_url: '',
+                        table: '',
+                    },
+                    toolbar: '#toolbar2',
+                    pk: 'id',
+                    sortName: 'id',
+                    pageSize: 8,
+                    pageList: [8, 20, 50, 'All'],
+                    search: false,
+                    singleSelect: true,
+                    columns: [
+                        [
+                            {checkbox: true},
+                            {field: 'product_code', title: __('Product_code'), operate: 'LIKE'},
+                            {field: 'product_name', title: __('Product_name'), operate: 'LIKE'},
+                            {field: 'temple', title: __('Temple'), operate: 'LIKE'},
+                            {field: 'main_unit', title: __('Main_unit'), operate: 'LIKE'},
+                            {field: 'sec_unit', title: __('Sec_unit'), operate: 'LIKE'},
+                            {field: 'proportion', title: __('Proportion'), operate: 'LIKE'},
+                            // {field: 'notes', title: __('Notes')},
+                            // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+                        ]
+                    ]
+                });
+
+                // 为表格2绑定事件
+                Table.api.bindevent(table2);
+            }
+        },
+
+        /*recyclebin: function () {
+            // 初始化表格参数配置
+            Table.api.init({
+                extend: {
+                    'dragsort_url': ''
+                }
+            });
+
+            var table = $("#table");
+
+            // 初始化表格
+            table.bootstrapTable({
+                url: 'qcode_product/recyclebin' + location.search,
+                pk: 'id',
+                sortName: 'id',
+                columns: [
+                    [
+                        {checkbox: true},
+                        {field: 'id', title: __('Id')},
+                        {field: 'name', title: __('Name'), align: 'left'},
+                        {
+                            field: 'deletetime',
+                            title: __('Deletetime'),
+                            operate: 'RANGE',
+                            addclass: 'datetimerange',
+                            formatter: Table.api.formatter.datetime
+                        },
+                        {
+                            field: 'operate',
+                            width: '140px',
+                            title: __('Operate'),
+                            table: table,
+                            events: Table.api.events.operate,
+                            buttons: [
+                                {
+                                    name: 'Restore',
+                                    text: __('Restore'),
+                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
+                                    icon: 'fa fa-rotate-left',
+                                    url: 'qcode_product/restore',
+                                    refresh: true
+                                },
+                                {
+                                    name: 'Destroy',
+                                    text: __('Destroy'),
+                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
+                                    icon: 'fa fa-times',
+                                    url: 'qcode_product/destroy',
+                                    refresh: true
+                                }
+                            ],
+                            formatter: Table.api.formatter.operate
+                        }
+                    ]
+                ]
+            });
+
+            // 为表格绑定事件
+            Table.api.bindevent(table);
+        },*/
+
+        add: function () {
+            Controller.api.bindevent();
+        },
+        edit: function () {
+            Controller.api.bindevent();
+        },
+        api: {
+            bindevent: function () {
+                Form.api.bindevent($("form[role=form]"));
+            }
+        }
+    };
+    return Controller;
+});

+ 218 - 0
public/assets/js/backend/qcode_product.js

@@ -0,0 +1,218 @@
+define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
+
+    var Controller = {
+        index: function () {
+            // 初始化表格参数配置
+            Table.api.init();
+            this.table.first();
+            this.table.second();
+
+            //绑定
+            $('#bind').click(function (e) {
+                var ids = $('#table1').bootstrapTable('getSelections')[0]['id'];
+
+                $.get('qcode_product/bind',{'ids':ids},function (data) {
+                    if(data.code==1){
+                        Toastr.success(data.msg)
+                        $('#table2').bootstrapTable('refresh');
+                    }else{
+                        Toastr.error(data.msg)
+                    }
+                },'json');
+
+                // layer.confirm('确定提交选中的 1 项?!', {
+                //     btn: ['确定', '取消'],
+                //     cancel: function(index, layero) {
+                //     }
+                // },function (index) {
+                //     $.get('qcode_product/bind',{'ids':ids},function (data) {
+                //         if(data.code==1){
+                //             Toastr.success(data.msg)
+                //             table2.bootstrapTable('refresh');
+                //         }else{
+                //             Toastr.error(data.msg)
+                //         }
+                //     },'json');
+                //     Layer.close(index);
+                //
+                // },function (){})
+
+            })
+
+            //绑定
+            $('#unbind').click(function (e) {
+                layer.confirm('确定提交选中的 1 项?!', {
+                    btn: ['确定', '取消'],
+                    cancel: function(index, layero) {
+                    }
+                },function (index) {
+                    var ids = $('#table2').bootstrapTable('getSelections')[0]['id'];
+
+                    $.get('qcode_product/unbind',{'ids':ids},function (data) {
+                        if(data.code==1){
+                            Toastr.success(data.msg)
+                            $('#table2').bootstrapTable('refresh');
+                        }else{
+                            Toastr.error(data.msg)
+                        }
+                    },'json');
+                    Layer.close(index);
+
+                },function (){})
+
+            })
+
+        },
+        table: {
+            first: function () {
+                // 表格1
+                var table1 = $("#table1");
+                table1.bootstrapTable({
+                    url: 'qcode_product/table1',
+                    extend: {
+                        index_url: 'qcode_product/table1' + location.search,
+                        add_url: 'qcode_product/add',
+                        edit_url: 'qcode_product/edit',
+                        del_url: 'qcode_product/del',
+                        table: 'qcode_product',
+                    },
+                    toolbar: '#toolbar1',
+                    pk: 'id',
+                    sortName: 'id',
+                    pageSize: 8,
+                    pageList: [8, 20, 50, 'All'],
+                    search: false,
+                    singleSelect: true,
+                    columns: [
+                        [
+                            {checkbox: true},
+                            {field: 'product_code', title: __('Product_code'), operate: 'LIKE'},
+                            {field: 'product_name', title: __('Product_name'), operate: 'LIKE'},
+                            {field: 'temple', title: __('Temple'), operate: 'LIKE'},
+                            {field: 'main_unit', title: __('Main_unit'), operate: 'LIKE'},
+                            {field: 'sec_unit', title: __('Sec_unit'), operate: 'LIKE'},
+                            {field: 'proportion', title: __('Proportion'), operate: 'LIKE'},
+                            // {field: 'notes', title: __('Notes')},
+                            // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+                        ]
+                    ]
+                });
+
+                // 为表格1绑定事件
+                Table.api.bindevent(table1);
+            },
+            second: function () {
+                // 表格2
+                var table2 = $("#table2");
+                table2.bootstrapTable({
+                    url: 'qcode_product/table2',
+                    extend: {
+                        index_url: '',
+                        add_url: '',
+                        edit_url: '',
+                        del_url: '',
+                        multi_url: '',
+                        table: '',
+                    },
+                    toolbar: '#toolbar2',
+                    pk: 'id',
+                    sortName: 'id',
+                    pageSize: 8,
+                    pageList: [8, 20, 50, 'All'],
+                    search: false,
+                    singleSelect: true,
+                    columns: [
+                        [
+                            {checkbox: true},
+                            {field: 'product_code', title: __('Product_code'), operate: 'LIKE'},
+                            {field: 'product_name', title: __('Product_name'), operate: 'LIKE'},
+                            {field: 'temple', title: __('Temple'), operate: 'LIKE'},
+                            {field: 'main_unit', title: __('Main_unit'), operate: 'LIKE'},
+                            {field: 'sec_unit', title: __('Sec_unit'), operate: 'LIKE'},
+                            {field: 'proportion', title: __('Proportion'), operate: 'LIKE'},
+                            // {field: 'notes', title: __('Notes')},
+                            // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+                        ]
+                    ]
+                });
+
+                // 为表格2绑定事件
+                Table.api.bindevent(table2);
+            }
+        },
+
+        /*recyclebin: function () {
+            // 初始化表格参数配置
+            Table.api.init({
+                extend: {
+                    'dragsort_url': ''
+                }
+            });
+
+            var table = $("#table");
+
+            // 初始化表格
+            table.bootstrapTable({
+                url: 'qcode_product/recyclebin' + location.search,
+                pk: 'id',
+                sortName: 'id',
+                columns: [
+                    [
+                        {checkbox: true},
+                        {field: 'id', title: __('Id')},
+                        {field: 'name', title: __('Name'), align: 'left'},
+                        {
+                            field: 'deletetime',
+                            title: __('Deletetime'),
+                            operate: 'RANGE',
+                            addclass: 'datetimerange',
+                            formatter: Table.api.formatter.datetime
+                        },
+                        {
+                            field: 'operate',
+                            width: '140px',
+                            title: __('Operate'),
+                            table: table,
+                            events: Table.api.events.operate,
+                            buttons: [
+                                {
+                                    name: 'Restore',
+                                    text: __('Restore'),
+                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
+                                    icon: 'fa fa-rotate-left',
+                                    url: 'qcode_product/restore',
+                                    refresh: true
+                                },
+                                {
+                                    name: 'Destroy',
+                                    text: __('Destroy'),
+                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
+                                    icon: 'fa fa-times',
+                                    url: 'qcode_product/destroy',
+                                    refresh: true
+                                }
+                            ],
+                            formatter: Table.api.formatter.operate
+                        }
+                    ]
+                ]
+            });
+
+            // 为表格绑定事件
+            Table.api.bindevent(table);
+        },*/
+
+        add: function () {
+            Controller.api.bindevent();
+        },
+        edit: function () {
+            Controller.api.bindevent();
+        },
+        api: {
+            bindevent: function () {
+                Form.api.bindevent($("form[role=form]"));
+            }
+        }
+    };
+    return Controller;
+});