model = new \app\admin\model\WarehousingDetail(); $this->view->assign("isScrapList", $this->model->getIsScrapList()); $this->view->assign("statusList", $this->model->getStatusList()); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $search = input('search'); $map=array(); if (!empty($search)){ $map['formula'] = array('like',"%$search%"); } $total = Db::name('warehousing') ->order('update desc') ->where($map) ->count(); $list = Db::name('warehousing') ->order('update desc') ->where($map) ->limit($offset, $limit) ->select(); $list = collection($list)->toArray(); $result = array("total" => $total, "rows" => $list); return json($result); } return $this->view->fetch(); } //增加库存 public function add() { if ($this->request->isPost()) { $params = $this->request->post("row/a"); //过滤前台传的字段 $params = $this->preExcludeFields($params); // print_r($params);die; if (empty($params['cid'])){ return array('status'=>0,'msg'=>'请请选择颜色'); } //专色墨批次 由产品编码+时间+色号+人员编号+'-'+当日本产品第几次调墨 //产品编码 $product_number = $params['product_number']; //时间取6位 $time = date('Ymd'); $time = substr($time,-6); $user = Session::get('admin'); $name = $user['nickname']; //人员编号,根据缓存的nickname确认人员编号 $people_number = Db::name('people')->where('name',$name)->value('number'); //色号,根据产品编码和颜色 确定它的色号 $color_number = Db::name('formula')->where('id',$params['cid'])->value('color_number'); $params['color'] = Db::name('formula')->where('id',$params['cid'])->value('color'); //查这个色号当日第几次调配 $num = Db::name('warehousing_detail')->where('product_number',$product_number)->where('cid',$params['cid'])->whereTime('create','today')->count(); if (empty($num)){ $color = 1; }else{ $color = $num + 1; } //专色墨批次号 $params['bach_number'] = $product_number.$time.$color_number.$people_number.'-'.$color; $params['weight'] = $params['weight'] * 1000; $params['create'] = date('Y-m-d H:i:s'); Db::startTrans(); try{ $id = Db::name('warehousing_detail')->insertGetId($params); if (empty($id)){ throw new Exception('插入数据失败,请联系开发人员'); } $totalWeight = Db::name('warehousing')->where('product_name',$params['product_name'])->where('cid',$params['cid'])->find(); if (!empty($totalWeight)){ $totalWeight['weight'] = $totalWeight['weight'] + $params['weight']; Db::name('warehousing')->where('product_name',$params['product_name'])->where('cid',$params['cid'])->setField('weight',$totalWeight['weight']); Db::name('warehousing')->where('product_name',$params['product_name'])->where('cid',$params['cid'])->setField('update',date('Y-m-d H:i:s')); }else{ $data = array(); $data['weight'] = $params['weight']; $data['product_name'] = $params['product_name']; $data['product_number'] = $params['product_number']; $data['formula'] = $params['formula']; $data['cid'] = $params['cid']; $data['color'] = $params['color']; $data['update'] = date('Y-m-d H:i:s'); Db::name('warehousing')->insert($data); } Db::commit(); $this->success(); }catch (\think\Exception\DbException $exception){ Db::rollback(); $this->error(__('No rows were inserted')); } } //检索数据 $data = Db::connect('db2')->query("select 产品名称 from 产品_基本资料 where 状态 = '' "); $backData = array(); foreach ($data as $key=>$value){ $backData[$key] = trim($value['产品名称']); } return $this->view->fetch('',compact('backData')); } //查看油墨详情 public function read(){ $params = input(''); $warehousing = Db::name('warehousing')->where('id', $params['ids'])->find(); $result = Db::name('warehousing_detail')->where('cid', $warehousing['cid'])->where('status',0)->order('id desc')->select(); return $this->view->fetch('',compact('result')); } //获取某个产品色号 public function getColor(){ $params = input('data'); if (is_numeric($params)){//传递来的是产品编号 $product_number = trim($params); $where[] = ['exp',Db::raw("FIND_IN_SET($product_number,product_number)")]; $result = Db::name('formula') ->where($where) ->select(); }else{//传递来的是产品名称 $product = Db::connect('db2')->query("select * from 工单_基本资料 where 成品名称 = '{$params}' limit 1"); if (empty($product)){ return array('status'=>0,'msg'=>'MES库不存在,请重新选择产品名称'); } $product_number = rtrim($product[0]['Gd_cpdh']); $where[] = ['exp',Db::raw("FIND_IN_SET($product_number,product_number)")]; $result = Db::name('formula') ->where($where) ->select(); } $fomulaData = array(); foreach ($result as $key=>$value){ $result[$key]['product_number'] = $product_number; $fomulaData[$key] = $value['product_name']; if ($key > 0){ if ($value['product_name'] != $result[$key-1]['product_name']){ $fomulaData[$key] = $value['product_name']; }else{ unset($fomulaData[$key]); } } } if (!empty($result)){ return array('status'=>1,'msg'=>'请求成功','data'=>$result,'formula'=>$fomulaData); }else{ return array('status'=>0,'msg'=>'未查询到数据'); } } }