model = new \app\admin\model\Task; } /** * 编辑 * * @param $ids * @return string * @throws DbException * @throws \think\Exception */ public function edit($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } if (false === $this->request->isPost()) { $ids = input('ids'); $order = Db::name('task')->field('drawer_name,examine_name')->where('id',"=",$ids)->find(); $personnel_sckp = Db::name('personnel')->where('name','=',$order['drawer_name'])->find(); $personnel_scsh = Db::name('personnel')->where('name','=',$order['examine_name'])->find(); //查询生产部 开票人 审核人 $sckp = Db::name('personnel')->where('bid',"=",3)->where('position','=',"sckp")->order('name desc')->select(); $scsh = Db::name('personnel')->where('bid',"=",3)->where('position','=',"scsh")->order('name desc')->select(); $this->assign('sckp',$sckp); $this->assign('scsh',$scsh); $this->assign('personnel_sckp',$personnel_sckp); $this->assign('personnel_scsh',$personnel_scsh); //新增关联订单 $order = Db::name('order')->where('status','neq',3)->field('id,customer,product,number,completed')->select(); $uncompleted_order = array(); if (!empty($order)){ foreach($order as $k=>$v){ $uncompleted_order[$k]['id'] = $v['id']; if (empty($v['completed'])){ $completed = 0; }else{ $completed = $v['completed']; } $uncompleted_order[$k]['str'] = $v['id'].'、'.$v['customer'].'-'.$v['product'].'-'.'总数量('.$v['number'].'kg)'.'-' .'已完成('.$completed.'kg)'; } } $formula_detail['data'] = Db::name('task')->where('id',$ids)->find(); $formula_detail['detail'] = Db::name('formula_detail')->where('pid',$formula_detail['data']['fid'])->select(); foreach ($formula_detail['detail'] as $key=>$value){ $formula_detail['detail'][$key]['percentage'] = decode($value['percentage']); } $this->view->assign("formula_detail", $formula_detail); $this->view->assign('row', $row); $this->view->assign('order',$uncompleted_order); $this->view->assign('machineList',\app\admin\model\Machine::select()); return $this->view->fetch(); } /** * 如果修改关联订单,1、将之前oid的已完成订单数量减掉 2、加上新选择的oid的已完成订单数量 * 3、修改作业票信息 */ $params = $this->request->post('row/a'); // echo "
"; // print_r($params); // echo ""; // die; if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } $params = $this->preExcludeFields($params); $result = false; Db::startTrans(); try { if ($row['oid'] != $params['oid']){ //第一步 $res = Db::name('order')->where('id',$row['oid'])->find(); $num = $res['completed'] - $row['number']; Db::name('order')->where('id',$row['oid'])->setField('completed',$num); //第二步 $order = Db::name('order')->where('id',$params['oid'])->find(); $o_num = $order['completed'] + $row['number']; Db::name('order')->where('id',$params['oid'])->setField('completed',$o_num); } //第三步 $result = Db::name('task')->where('id',$ids)->update($params); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if (false === $result) { $this->error(__('No rows were updated')); } $this->success(); } /** * 生产管理 作业票列表查看 */ public function show($ids) { $row = $this->model->get($ids); $this->view->assign("row", $row); $this->view->assign("ids", $ids); $formula_detail['data'] = Db::name('task')->where('id',$ids)->find(); $formula_detail['detail'] = Db::name('formula_detail')->where('pid',$formula_detail['data']['fid'])->select(); foreach ($formula_detail['detail'] as $key=>$value){ $formula_detail['detail'][$key]['percentage'] = decode($value['percentage']); } $this->view->assign("formula_detail", $formula_detail); $task= Db::name('task')->where('id',$ids)->find(); $gyinfo= Db::name('formula_detail')->where('pid',$row['fid'])->select(); if (empty($gyinfo)){return array('status'=>0,'msg'=>'数据错误');} $total = Db::name('formula_detail')->where('pid',$row['fid'])->column('percentage'); if (empty($total)){return array('status'=>0,'msg'=>'数据错误');} foreach ($total as $k=>$v){ $total[$k] = decode($v); } $num = array_sum($total); foreach ($gyinfo as $key=>$value){ if($gyinfo[$key]['gy_name'] == null){// $gyinfo[$key]['gy_name'] = '';// }// $gyinfo[$key]['num'] = ''; $gyinfo[$key]['percentage'] = decode($value['percentage']); if (!empty($value['percentage'])){ // $gyinfo[$key]['num'] = number_format($gyinfo[$key]['percentage'] / $num * $params['number'],3); $number = ceil($gyinfo[$key]['percentage'] / $num * $task['number'] *1000); $gyinfo[$key]['num'] = number_format($number/1000,3); } } $date = date('Y/m/d'); $this->view->assign("task", $task); $this->view->assign("gyinfo", $gyinfo); $this->view->assign("date", $date); return $this->view->fetch(); } /** * 生成作业票 查看 打印页面 */ // public function task_print(){ // $params = input(''); // if ($params['ids'] == '' || $params['number'] == '' || !is_numeric($params['number'])){ // return array('status'=>0,'msg'=>'请求参数错误'); // } // $task = Db::name('task')->where('id',$params['ids'])->find(); // $formula = Db::name('formula')->where('name',$task['name'])->find(); // $formula_detail= Db::name('formula_detail')->where('pid',$formula['id'])->where('version',$formula['version'])->field('id,material,percentage,gy_name,gy_num')->select(); // if (empty($formula_detail)){return array('status'=>0,'msg'=>'数据错误');}else{return $formula_detail;} // $this->view->assign("formula_detail", $formula_detail); // } /** * 生成领料单 * @return string * @throws \think\Exception */ public function taskadd(){ $ids = input('ids');//获取作业票id if(empty($ids)){$this->error('异常');} $ids = substr($ids,0,strlen($ids)-1); $id = explode(',',$ids);//逗号分割开 $list = []; foreach ($id as $k=>$v){ $task[$k]= Db::name('task')->where('id',$v)->find(); $list[$k] = Db::name('formula_detail')->where('pid',$task[$k]['fid'])->field('material,percentage')->select(); } /* * 根据查到的配方fid去查配方详情表 fid = pid * 解密百分比字段 * 根据task['number'] 算出应该领出的数量 应领重量 = 材料百分比/(所有材料百分比相加)*task['number'] * 值相加去重 */ $res = array(); foreach ($list as $key=>$value){ //查出百分比 相加得出总计百分比 $total = Db::name('formula_detail')->where('pid',$task[$key]['fid'])->column('percentage'); foreach ($total as $k=>$v){ $total[$k] = decode($v); } $num = array_sum($total);//算出所有百分比总数 for ($i=0;$i
"; // print_r($task);//一维 // echo ""; // // echo "
"; // print_r($sum_list);//原材料信息 // echo ""; // echo "
"; // print_r($result);//汇总领料单 // echo ""; $this->view->assign("task", $task);//生成领料单配方信息 $this->view->assign("list", $list);//生成领料单 $this->view->assign("result", $result);//汇总领料单 return $this->view->fetch('taskadd'); } /** * 计算数量,值去重&相加 * $arr 数组 * $str1 要合并的值 * $str2 要计算的值 */ function sumWeight($arr,$str1,$str2) { $item = array(); foreach ($arr as $k => $v) { if (!isset($item[$v[$str1]])) { $item[$v[$str1]] = $v; } else { $item[$v[$str1]][$str2] += $v[$str2]; } // if ($k == 13) { // echo "
"; // print_r($item);die; // echo ""; // } } return array_values($item); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ }