|
|
@@ -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('删除失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|