| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- use think\Request;
- class GluingReport extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 设备角色菜单
- * @return void
- */
- public function getGluingcoleTab()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $sist = ['印后糊盒车间','精品自动化车间','数字化车间'];
- $list = db('设备_基本资料')
- ->where('使用部门','in',$sist)
- ->whereNotNull('sys_sbID')
- ->column('CONCAT(设备编号,"->",设备名称)');
- if (empty($list)){
- $this->error('未找到设备数据');
- }else{
- $this->success('成功',$list);
- }
- }
- /**
- * 设备角色列表
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getGluingcoleList()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $list = db('设备_糊盒班组角色')
- ->where('jtbh',$param['machine'])
- ->select();
- if (empty($list)){
- $this->error('未找到数据');
- }else{
- $this->success('成功',$list);
- }
- }
- /**
- * 设备角色资料详情
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getGluingcoleDetail()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $list = db('设备_糊盒班组角色')
- ->where('id',$param['id'])
- ->find();
- if (empty($list)){
- $this->error('未找到数据详情');
- }else{
- $this->success('成功',$list);
- }
- }
- /**
- * 新增机台班组角色
- * @return void
- */
- public function saveGluingcoleDetail(){
- if ($this->request->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)){
- $this->error('参数错误');
- }
- $param['sys_rq'] = date('Y-m-d H:i:s',time());
- $res = db('设备_糊盒班组角色')->insert($param);
- if (empty($res)){
- $this->error('新增失败');
- }else{
- $this->success('新增成功');
- }
- }
- /**
- * 修改设备角色资料
- * @return void
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function getGluingcoleDetaiEdit()
- {
- if ($this->request->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param['id'])){
- $this->error('参数错误');
- }
- $id = intval($param['id']);
- $param['mod_rq'] = date('Y-m-d H:i:s',time());
- unset($param['id']);
- $res = db('设备_糊盒班组角色')
- ->where('id',$id)
- ->update($param);
- if ($res === false){
- $this->error('修改失败');
- }else{
- $this->success('修改成功');
- }
- }
- /**
- * 设备当前班组角色
- * @return void
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function UpdateGluingcoleStatus()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param['id']) || empty($param['jtbh'])){
- $this->error('参数错误');
- }
- $updateRes = db('设备_糊盒班组角色')
- ->where('jtbh',$param['jtbh'])
- ->update(['status' => 0]);
- $res = db('设备_糊盒班组角色')
- ->where('id',$param['id'])
- ->update(['status' => 1]);
- if ($updateRes === false || $res === false){
- $this->error('更新失败');
- }else{
- $this->success('更新成功');
- }
- }
- /**
- * 设备班组资料列表
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getGluingClassLList()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $list = db('设备_糊盒班组资料')
- ->where('jtbh',$param['machine'])
- ->select();
- foreach ($list as $k=>$v){
- for ($i = 1; $i <= 15; $i++){
- $bh = $v['bh'.$i];
- $list[$k]['name'.$i] = '';
- if (!empty($bh) && $bh !== ''){
- $name = \db('人事_基本资料')
- ->where('员工编号',$bh)
- ->value('员工姓名');
- $list[$k]['name'.$i] = $name;
- }
- }
- }
- if (empty($list)){
- $this->error('未找到数据');
- }else{
- $this->success('成功',$list);
- }
- }
- /**
- * 获取设备角色数据
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getGluingcole()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $list = db('设备_糊盒班组角色')
- ->where('jtbh',$param['machine'])
- ->where('status',1)
- ->find();
- if (empty($list)){
- $this->error('未找到角色资料');
- }else{
- $this->success('成功',$list);
- }
- }
- /**
- * 新增糊盒机台班组资料
- * @return void
- */
- public function AddGluingClass()
- {
- if ($this->request->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)){
- $this->error('参数错误');
- }
- $param['sys_rq'] = date('Y-m-d H:i:s',time());
- $res = db('设备_糊盒班组资料')->insert($param);
- if ($res === false){
- $this->error('新增失败');
- }else{
- $this->success('新增成功');
- }
- }
- /**
- * 修改设备糊盒班组资料
- * @return void
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function UpdateGluingClass()
- {
- if ($this->request->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param['id'])){
- $this->error('参数错误');
- }
- $id = intval($param['id']);
- $param['mod_rq'] = date('Y-m-d H:i:s',time());
- unset($param['id']);
- $res = db('设备_糊盒班组资料')
- ->where('id',$id)
- ->update($param);
- if ($res === false){
- $this->error('修改失败');
- }else{
- $this->success('修改成功');
- }
- }
- /**
- * 糊盒机台报工
- * @return void
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- public function AddGluingReportData()
- {
- if ($this->request->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)){
- $this->error('参数错误');
- }
- $param['sys_rq'] = date('Y-m-d H:i:s',time());
- $Sql = db('设备_糊盒报工资料')->fetchSql(true)->insert($param);
- $res = db()->query($Sql);
- if ($res === false){
- $this->error('报工失败');
- }else{
- $this->success('报工成功');
- }
- }
- /**
- * 糊盒机台报工数据菜单
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getTab()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $data = [];
- $date = date('Y-m-d 00:00:00',time()-3888000);
- $sist = ['印后糊盒车间','精品自动化车间','数字化车间'];
- $department = \db('设备_基本资料')
- ->distinct(true)
- ->where('使用部门','in',$sist)
- ->where('设备编组','<>','')
- ->where('sys_sbID','<>','')
- ->order('设备编组')
- ->column('rtrim(使用部门) as 使用部门');
- if (empty($department)){
- $this->success('为获取到机台数据');
- }
- $list = \db('设备_糊盒报工资料')
- ->field([
- 'DISTINCT(sczl_rq)' => '时间',
- 'rtrim(sczl_jtbh)' => '机台编号'
- ])
- ->where('sczl_rq','>',$date)
- ->order('sczl_rq desc')
- ->select();
- if (empty($list)){
- $this->success('未找到机台生产记录');
- }
- foreach ($department as $value){
- $machine = \db('设备_基本资料')->where('使用部门',$value)->where('sys_sbID','<>','')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->order('设备编号')->select();
- foreach ($machine as $k=>$v){
- $data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']] = [];
- foreach ($list as $kk=>$vv){
- if ($v['设备编号'] === $vv['机台编号']){
- array_push($data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']],date('Y-m-d',strtotime($vv['时间'])));
- }
- }
- }
- }
- $this->success('成功',$data);
- }
- /**
- * 获取当前生产工单
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function GetProduction()
- {
- if (Request::instance()->isGet() == false) {
- $this->error('非法请求');
- }
- $params = Request::instance()->param();
- if (!isset($params['machine']) || empty($params['machine'])) {
- $this->error('参数错误');
- }
- $machine = $params['machine'];
- $machineCode = \db('dic_lzde')->where('适用机型',$machine)->value('sys_bh');
- $data = \db('设备_糊盒报工采集')->where('sczl_jtbh',$machine)->order('UID desc')->find();
- $list = [];
- $row = [];
- if (!empty($data['工单编号'])){
- $endTime = \db('工单_工艺资料')
- ->where('Gy0_gdbh',$data['工单编号'])
- ->where('Gy0_yjno',$data['印件号'])
- ->where('Gy0_gxh',$data['工序号'])
- ->find();
- $list['工单编号'] = $data['工单编号'];
- if (!empty($endTime)){
- $list['印件号'] = $data['印件号'];
- $name = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品名称');
- $code = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品代号');
- $list['产品名称'] = rtrim($name);
- $list['产品代号'] = rtrim($code);
- $list['工序名称'] = $data['工序名称'];
- }
- $list['状态'] = rtrim($data['当前状态']);
- $list['开工时间'] = $data['开工时间'];
- }else{
- $list['工单编号'] = '';
- $list['印件号'] = 0;
- $list['产品名称'] = '';
- $list['工序名称'] = '';
- $list['产品代号'] = '';
- $list['状态'] = '';
- $list['开工时间'] = '';
- }
- $list['班组编号'] = rtrim($data['sczl_bzbh']);
- $idList = explode(',',$data['班组ID']);
- foreach ($idList as $k=>$v){
- $class = \db('设备_糊盒班组资料')
- ->where('id',$v)
- ->field("role,rate,bh1,bh2,bh3,bh4,bh5,bh6,bh7,bh8,bh9,bh10,bh11,bh12,bh13,bh14,bh15")
- ->find();
- if (!empty($class)){
- for ($i=1;$i<16;$i++) {
- if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') {
- $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
- $row[$i] = [
- '编号' => $class['bh' . $i],
- '姓名' => $name['姓名'],
- '比例' => $class['rate'],
- '角色' => $class['role'],
- ];
- }
- }
- $row = array_values($row);
- }
- }
- $list['班组成员'] = $row;
- $list['定额代号'] = $machineCode;
- $this->success('成功',$list);
- }
- /**
- * 设置当前工单和当前班组
- * @return void
- */
- public function setMachineTeam()
- {
- if (Request::instance()->isPost() == false) {
- $this->error('非法请求');
- }
- $params = Request::instance()->post();
- if (!isset($params['machine']) || empty($params['machine'] )) {
- $this->error('参数不能为空');
- }
- if (empty($params['team_id']) || empty($params['sczl_bzdh'])){
- $this->error('请先选择班组成员');
- }
- $machine = $params['machine'] . '#';
- $data = [];
- $data['status'] = $params['status'];
- $data['sczl_sj'] = date('Y-m-d H:i:s');
- $data['sczl_jtbh'] = $machine;
- $data['sczl_gdbh'] = empty($params['order']) ? '':$params['order'];
- $data['sczl_yjno'] = empty($params['yjno']) ? '':$params['yjno'];
- $data['sczl_gxh'] = empty($params['gy_name']) ? '' : (int)substr($params['gy_name'], 0, 2);
- $data['sczl_gxmc'] = empty($params['gy_name']) ? '' : $params['gy_name'];
- $data['sczl_bzbh'] = $params['sczl_bzdh'];
- $data['班组ID'] = $params['team_id'];
- // 获取当前时间
- $current_time = time();
- // 设置时间范围
- $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
- $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
- $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
- $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
- $start_time4 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 00:00:00');
- // 判断当前时间属于哪个时间范围
- if ($current_time >= $start_time1 && $current_time <= $end_time1) {
- $data['sczl_kgsj'] = date('Y-m-d') . ' 08:30:00';
- } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
- $data['sczl_kgsj'] = date('Y-m-d') . ' 20:30:00';
- } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
- $data['sczl_kgsj'] = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
- }elseif ($current_time > $start_time4 && $current_time <= $start_time3){
- $data['sczl_kgsj'] = date('Y-m-d') . ' 20:30:00';
- }
- if (!empty($params['order']) && !empty($params['yjno'])){
- $option['Gy0_gdbh'] = $params['order'];
- $option['Gy0_yjno'] = $params['yjno'];
- $option['Gy0_gxh'] = $data['sczl_gxh'];
- $data['任务ID'] = \db('工单_工艺资料')->where($option)->value('UniqId');
- }else{
- $data['任务ID'] = '';
- }
- $sql = \db('设备_糊盒报工采集')->fetchSql(true)->insert($data);
- $res = Db::query($sql);
- if ($res === false) {
- $this->error('设置失败');
- } else {
- $this->success('设置成功');
- }
- }
- //
- }
|