| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- /**
- * 成品入仓维护接口
- */
- class FinishedProductWarehousing extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 首页
- *
- */
- public function index()
- {
- $this->success('请求成功');
- }
- /**
- * 侧边栏
- * @ApiMethod (GET)
- */
- public function getTab()
- {
- //get请求
- if(!$this->request->isGet()){
- $this->error('请求方式错误');
- }
- $rows = db()->table('成品入仓')
- ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
- ->group('date')
- ->order('UniqId desc')
- ->limit(50)
- ->select();
- $arr = db()->table('成品入仓')
- ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(sys_id) as count')
- ->where('sys_rq','>=',$rows[49]['date'])
- ->group('date, sys_id')
- ->select();
- foreach($rows as $key=>$value){
- $rows[$key]['sys'] = [];
- foreach($arr as $k=>$v){
- if($value['date'] == $v['date']){
- unset($v['date']);
- array_push($rows[$key]['sys'],$v);
- unset($arr[$k]);
- }
- }
- $rows[$key]['date'] = str_replace('-', '.', $rows[$key]['date']);
- }
- $this->success('成功',$rows);
- }
- /**
- * 侧边栏
- * @ApiMethod (GET)
- */
- public function getTabByGdbh()
- {
- //get请求
- if(!$this->request->isGet()){
- $this->error('请求方式错误');
- }
- $rows = db()->table('成品入仓')
- ->field('jjcp_gdbh, rtrim(jjcp_cpdh) as jjcp_cpdh, LEFT(Sys_rq, 10) as Sys_rq')
- ->order('Sys_rq desc')
- ->select();
- $arr = db()->table('工单_基本资料')
- ->column('CONCAT(Gd_gdbh, "-", rtrim(Gd_cpdh)) AS gdcp, CONCAT(rtrim(Gd_khdh), " 【", rtrim(Gd_khmc)) AS kh');
- $data = [];
- foreach ($rows as $value) {
- $key = $value['jjcp_gdbh'].'-'.$value['jjcp_cpdh'];
- if (isset($arr[$key]) && !isset($data[$arr[$key]])) {
- $data[$arr[$key]] = $value['Sys_rq'];
- }
- }
- // 对键进行升序排序
- uksort($data, function($a, $b) use ($data) {
- if ($data[$a] == $data[$b]) {
- return ($a > $b) ? 1 : -1; // 在值相同的情况下,根据键进行升序排列
- }
- return ($data[$a] < $data[$b]) ? 1 : -1;
- });
- $this->success('成功',$data);
- }
- /**
- * 列表
- * @ApiMethod (GET)
- * @param string $date 时间
- * @param string $sys_id 用户
- */
- public function getList()
- {
- //get请求
- if(!$this->request->isGet()){
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- if (!isset($req['date'])) $this->error('参数缺失');
- $page = 1;
- $limit = 15;
- if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
- if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
- if(strpos($req['date'],'-')){
- $where = ['c.Sys_rq'=>['like','%'.$req['date'].'%']];
- $option = ['Sys_rq'=>['like','%'.$req['date'].'%']];
- }else{
- $where = [];
- $option = [];
- }
- if (isset($req['sys_id']) && !empty($req['sys_id'])){
- $where['c.Sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
- $option['Sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
- }
- //客户编号
- $rows = db()->table('成品入仓')->alias('c')
- ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
- rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh,
- c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj,
- rtrim(c.jjcp_smb) as jjcp_smb, rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
- rtrim(c.成品编码) as 成品编码, rtrim(c.成品名称) as 成品名称,
- rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, LEFT(c.成品编码,4) as 客户编号, rtrim(g.Gd_客户名称) as Gd_客户名称,
- rtrim(c.机型备注) as 机型备注, rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
- ->where($where)
- ->where('g.Gd_cpdh=c.jjcp_cpdh')
- ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
- ->order('c.UniqId desc')
- ->page($page,$limit)
- ->select();
- $total = db()->table('成品入仓')->where($option)->count();
- foreach ($rows as $key=>$value) {
- $row = db()->table('成品入仓')
- ->field('LEFT(Sys_rq, 10) as Sys_rq,jjcp_sl')
- ->where(['jjcp_gdbh'=>$value['jjcp_gdbh'], 'jjcp_cpdh'=>$value['jjcp_cpdh']])
- ->order('Sys_rq desc')
- ->select();
- $rows[$key]['jjcp_sls'] = 0;
- foreach ($row as $k=>$v) {
- $rows[$key]['jjcp_sls'] += $v['jjcp_sl'];
- }
- if ($value['订单数量']!=0){
- $rows[$key]['完成率'] = number_format($rows[$key]['jjcp_sls']/$value['订单数量']/100,2);
- }else{
- $rows[$key]['完成率'] = '';
- }
- $rows[$key]['订单数量'] = floatval($value['订单数量']*10000);
- $rows[$key]['最近入仓日期'] = $row[0]['Sys_rq'];
- $rows[$key]['Mod_rq'] = $value['Mod_rq']=='1900-01-01 00:00:00' ? '' :$value['Mod_rq'];
- }
- $data = [
- 'total' => $total,
- 'rows' => $rows,
- ];
- $this->success('成功',$data);
- }
- /**
- * 定位
- * @ApiMethod (GET)
- * @param string $gdbh 工单编号
- * @param string $cpmc 产品名称
- * @param string $page 页码
- * @param string $limit 数量
- */
- public function locate()
- {
- //get请求
- if(!$this->request->isGet()){
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- $page = 1;
- $limit = 15;
- if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
- if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
- if (isset($req['gdbh']) && !empty($req['gdbh'])){
- $where = ['c.jjcp_gdbh'=>[ 'like', '%' . $req['gdbh'] . '%']];
- $option = ['jjcp_gdbh'=>[ 'like', '%' . $req['gdbh'] . '%']];
- //客户编号
- $rows = db()->table('成品入仓')->alias('c')
- ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
- rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh,
- c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj,
- rtrim(c.jjcp_smb) as jjcp_smb, rtrim(y.yj_Yjdh) as yj_Yjdh, rtrim(y.yj_yjmc) as yj_yjmc,
- rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
- rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, LEFT(c.成品编码,4) as 客户编号, rtrim(g.Gd_客户名称) as Gd_客户名称,
- rtrim(c.机型备注) as 机型备注, rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
- ->where($where)
- ->where('y.yj_Yjno=c.jjcp_yjno')
- ->where('g.Gd_cpdh=c.jjcp_cpdh')
- ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
- ->join('工单_印件资料 y','y.Yj_Gdbh=c.jjcp_gdbh')
- ->order('c.UniqId desc')
- ->page($page,$limit)
- ->select();
- $total = db()->table('成品入仓')->where($option)->count();
- }else{
- if (isset($req['cpmc']) && !empty($req['cpmc'])){
- //查询工单表
- $gd = db()->table('工单_基本资料')
- ->where('Gd_cpmc', 'LIKE', '%'.$req['cpmc'].'%')
- ->column('Gd_gdbh');
- $where = ['c.jjcp_gdbh'=>['in', $gd]];
- $option = ['jjcp_gdbh'=>['in', $gd]];
- //客户编号
- $rows = db()->table('成品入仓')->alias('c')
- ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
- rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh,
- c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj,
- rtrim(c.jjcp_smb) as jjcp_smb, rtrim(y.yj_Yjdh) as yj_Yjdh, rtrim(y.yj_yjmc) as yj_yjmc,
- rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
- rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, LEFT(c.成品编码,4) as 客户编号, rtrim(g.Gd_客户名称) as Gd_客户名称,
- rtrim(c.机型备注) as 机型备注, rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
- ->where($where)
- ->where('y.yj_Yjno=c.jjcp_yjno')
- ->where('g.Gd_cpdh=c.jjcp_cpdh')
- ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
- ->join('工单_印件资料 y','y.Yj_Gdbh=c.jjcp_gdbh')
- ->order('c.UniqId desc')
- ->page($page,$limit)
- ->select();
- $total = db()->table('成品入仓')->where($option)->count();
- }else{
- $this->error('参数错误');
- }
- }
- foreach ($rows as $key=>$value) {
- $row = db()->table('成品入仓')
- ->field('LEFT(Sys_rq, 10) as Sys_rq,jjcp_sl')
- ->where(['jjcp_gdbh'=>$value['jjcp_gdbh'], 'jjcp_cpdh'=>$value['jjcp_cpdh']])
- ->order('Sys_rq desc')
- ->select();
- $rows[$key]['jjcp_sls'] = 0;
- foreach ($row as $k=>$v) {
- $rows[$key]['jjcp_sls'] += $v['jjcp_sl'];
- }
- if ($value['订单数量']!=0){
- $rows[$key]['完成率'] = number_format($rows[$key]['jjcp_sls']/$value['订单数量']/100,2);
- }else{
- $rows[$key]['完成率'] = '';
- }
- $rows[$key]['订单数量'] = floatval($value['订单数量']*10000);
- $rows[$key]['最近入仓日期'] = $row[0]['Sys_rq'];
- $rows[$key]['Mod_rq'] = $value['Mod_rq']=='1900-01-01 00:00:00' ? '' :$value['Mod_rq'];
- }
- $data = [
- 'total' => $total,
- 'rows' => $rows,
- ];
- $this->success('成功',$data);
- }
- /**
- * 获取信息
- * @ApiMethod (GET)
- * @param string $UniqId UniqId
- */
- public function getInfo()
- {
- //get请求
- if(!$this->request->isGet()){
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- if (isset($req['UniqId']) && !empty($req['UniqId'])){
- $UniqId = $req['UniqId'];
- }else{
- $this->error('参数错误');
- }
- //客户编号
- $rows = db()->table('成品入仓')->alias('c')
- ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
- rtrim(c.jjcp_num) as jjcp_num,
- c.jjcp_gdbh, c.jjcp_yjno, rtrim(c.订单编号) as 订单编号,
- rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
- rtrim(c.成品编码) as 成品编码, rtrim(c.成品名称) as 成品名称,
- rtrim(c.客户料号) as 客户料号,
- rtrim(c.jjcp_smb) as jjcp_smb, LEFT(c.jjcp_sj, 10) as jjcp_sj,
- c.jjcp_sl, rtrim(c.jjcp_dw) as jjcp_dw,
- g.订单数量*10000 as 订单数量, rtrim(c.机型备注) as 机型备注, rtrim(c.jjcp_desc) as jjcp_desc,
- rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
- ->where('c.UniqId',$UniqId)
- ->where('g.Gd_cpdh=c.jjcp_cpdh')
- ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
- ->find();
- $rows['jjcp_sls'] = db()->table('成品入仓')
- ->where(['jjcp_gdbh'=>$rows['jjcp_gdbh'], 'jjcp_cpdh'=>$rows['jjcp_cpdh']])
- ->sum('jjcp_sl');
- $this->success('成功',$rows);
- }
- /**
- * 获取仓库信息
- * @ApiMethod (GET)
- * @param string keyword 关键词
- */
- public function getCk()
- {
- //get请求
- if(!$this->request->isGet()){
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- $key_word = '';
- if (isset($req['key_word']) && !empty($req['key_word'])){
- $key_word = $req['key_word'];
- }
- $rs = db()->table('物料_仓库信息')
- ->field('rtrim(编号) as 编号, rtrim(名称) as 名称')
- ->where('编号|名称','like','%'.$key_word.'%')
- ->where('名称','in',['面材仓库','主要产成品'])
- ->select();
- $this->success('成功',$rs);
- }
- /**
- * 查询印件工序及产品名称
- * @ApiMethod (GET)
- * @param string $gdbh 工单编号
- */
- public function getGd()
- {
- //get请求
- if(!$this->request->isGet()){
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- if (isset($req['gdbh']) && !empty($req['gdbh'])){
- $gdbh = $req['gdbh'];
- }else{
- $this->error('参数错误');
- }
- $rows = db()->table('工单_基本资料')->alias('g')
- ->field('g.Gd_gdbh, j.yj_yjno, rtrim(g.销售订单号) as 销售订单号, rtrim(j.yj_Yjdh) as yj_Yjdh, rtrim(j.yj_yjmc) as yj_yjmc, rtrim(g.成品代号) as 成品代号, rtrim(g.成品名称) as 成品名称, rtrim(g.客户料号) as 客户料号')
- ->where(['g.Gd_gdbh'=>$gdbh])
- ->join(['产品_印件资料'=>'j'],'g.Gd_cpdh=j.yj_yjdh and g.成品代号=j.yj_cpdh')
- ->order('j.yj_yjno asc')
- ->select();
- foreach ($rows as $key=>$value){
- $rows[$key]['gdyj'] = $value['Gd_gdbh'].' -'.sprintf("%02d", $value['yj_yjno']).'-'.$value['yj_yjmc'];
- }
- $this->success('成功',$rows);
- }
- /**
- * 查询工单数量
- * @ApiMethod (GET)
- * @param string $gdbh 工单编号
- * @param string $cpdh 产品代号
- * @param string $rcsl 入仓数量
- */
- public function getGdsl()
- {
- //get请求
- if(!$this->request->isGet()){
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- if (isset($req['gdbh']) && !empty($req['gdbh'])){
- $gdbh = $req['gdbh'];
- }else{
- $this->error('参数错误');
- }
- if (isset($req['cpdh']) && !empty($req['cpdh'])){
- $cpdh = $req['cpdh'];
- }else{
- $this->error('参数错误');
- }
- // if (isset($req['rcsl'])){
- // $rcsl = $req['rcsl'];
- // }else{
- // $this->error('参数错误');
- // }
- $rows = db()->table('工单_基本资料')->alias('g')
- ->field('订单数量*10000 as 订单数量, gd_statu')
- ->where(['Gd_gdbh'=>$gdbh, 'Gd_cpdh'=>$cpdh])
- ->find();
- if (!$rows) $this->error('未查询到记录');
- $rows['jjcp_sls'] = db()->table('成品入仓')
- ->where(['jjcp_gdbh'=>$gdbh, 'jjcp_cpdh'=>$cpdh])
- ->sum('jjcp_sl');
- // if ($rows['订单数量']<($rows['jjcp_sls']+$rcsl) || mb_substr($rows['gd_statu'],-3,3)=='已完工'){
- // $this->error('已完工或入仓数量超过订单数量',$rows);
- // }
- $this->success('成功',$rows);
- }
- /**
- * 新增
- * @ApiMethod (POST)
- * @param string
- */
- public function add()
- {
- if(!$this->request->isPost()){
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- $arr = [
- 'Sys_id',
- '入仓类型', '仓库编号', '仓库名称',
- 'jjcp_num',
- 'jjcp_gdbh', 'jjcp_yjno', '订单编号',
- 'jjcp_cpdh', 'jjcp_cpmc',
- '成品编码', '成品名称',
- '客户料号',
- 'jjcp_smb', 'jjcp_sj',
- 'jjcp_sl', 'jjcp_dw',
- '机型备注',
- 'jjcp_desc'
- ];
- $data = [];
- foreach ($arr as $key => $value){
- if (!isset($req[$value])){
- $this->error('参数错误',$value,$key+1);
- }
- $data[$value] = $req[$value];
- }
- $data['Sys_rq'] = date('Y-m-d H:i:s');
- //开启事务
- db()->startTrans();
- try{
- $sql = db()->table('成品入仓')->fetchSql(true)->insert($data);
- $bool = db()->query($sql);
- // 提交事务
- db()->commit();
- } catch (\Exception $e) {
- // 回滚事务
- db()->rollback();
- $this->error($e->getMessage());
- }
- if($bool===false) $this->error('失败');
- $this->success('成功');
- }
- /**
- * 修改
- * @ApiMethod (POST)
- */
- public function edit()
- {
- if(!$this->request->isPost()){
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- $arr = [
- '入仓类型', '仓库编号', '仓库名称',
- 'jjcp_num',
- 'jjcp_gdbh', 'jjcp_yjno', '订单编号',
- 'jjcp_cpdh', 'jjcp_cpmc',
- '成品编码', '成品名称',
- '客户料号',
- 'jjcp_smb', 'jjcp_sj',
- 'jjcp_sl', 'jjcp_dw',
- '机型备注',
- 'jjcp_desc'
- ];
- $data = [];
- foreach ($arr as $key => $value){
- if (!isset($req[$value])){
- continue;
- }
- $data[$value] = $req[$value];
- }
- if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
- $this->error('参数错误','UniqId',100);
- }
- if (count($data)==0){
- $this->error('参数错误','',111);
- }
- $data['Mod_rq'] = date('Y-m-d H:i:s');
- //开启事务
- db()->startTrans();
- try{
- $sql = db()->table('成品入仓')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
- $bool = db()->query($sql);
- // 提交事务
- db()->commit();
- } catch (\Exception $e) {
- // 回滚事务
- db()->rollback();
- $this->error($e->getMessage());
- }
- if($bool===false) $this->error('失败');
- $this->success('成功');
- }
- /**
- * 修改
- * @ApiMethod (POST)
- * @param string 'UniqId'
- */
- public function del()
- {
- if(!$this->request->isPost()){
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
- $this->error('参数错误','UniqId',100);
- }
- //开启事务
- db()->startTrans();
- try{
- $bool = db()->table('成品入仓')->where('UniqId',$req['UniqId'])->delete();
- // 提交事务
- db()->commit();
- } catch (\Exception $e) {
- // 回滚事务
- db()->rollback();
- $this->error($e->getMessage());
- }
- if($bool===false) $this->error('失败');
- $this->success('成功');
- }
- /**
- * 月度A
- * @ApiMethod (POST)
- * @param string start_time
- * @param string end_time
- * @param string file_name
- * @param array fields
- */
- public function monthExportA(){
- if(!$this->request->isGet()){
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- $arr = [
- 'start_time', 'end_time', 'file_name'
- ];
- foreach ($arr as $key => $value){
- if (!isset($req[$value])){
- $this->error('参数错误',$value,$key+1);
- }
- }
- if (!(isset($req['fields']) && count($req['fields'])!=0)){
- $this->error('参数错误','fields',100);
- }
- $arr = [
- '入仓类型' =>['入仓类型'],
- '仓库编号' =>['仓库编号'],
- '仓库名称' =>['仓库名称'],
- 'jjcp_gdbh' =>['工单编号'],
- 'jjcp_cpdh' =>['入仓存货编号'],
- 'jjcp_cpmc' =>['入仓存货名称'],
- 'jjcp_sl' =>['入仓数量'],
- 'jjcp_dw' =>['单位'],
- 'jjcp_sj' =>['入仓时间'],
- 'jjcp_smb' =>['首末板'],
- 'jjcp_num' =>['单据编号'],
- '订单编号' =>['订单编号'],
- ];
- $data[0] = [];
- foreach ($req['fields'] as $k=>$v){
- if(array_key_exists($v,$arr)){
- array_push($data[0],$arr[$v][0]);
- }
- }
- //客户编号
- $rows = db()->table('成品入仓')->alias('c')
- ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
- c.jjcp_gdbh, rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
- c.jjcp_sl, rtrim(c.jjcp_dw) as jjcp_dw, c.jjcp_sj,
- rtrim(c.jjcp_smb) as jjcp_smb,
- rtrim(c.jjcp_num) as jjcp_num, rtrim(g.销售订单号) as 订单编号
- ')
- ->where('c.jjcp_sj','between time',[$req['start_time'], $req['end_time']])
- ->order('c.jjcp_sj asc')
- ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
- ->where('g.Gd_cpdh=c.jjcp_cpdh')
- ->select();
- foreach ($rows as $key=>$value) {
- $subArray = [];
- foreach ($arr as $k=>$v){
- $subArray[$k] = $rows[$key][$k];
- }
- array_push($data,$subArray);
- }
- $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
- }
- /**
- * 工序汇总导出
- * @ApiMethod (POST)
- * @param string date
- * @param string sys_id
- * @param array fields
- */
- public function export(){
- if(!$this->request->isGet()){
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- if (!isset($req['date']) || empty($req['date'])) $this->error('参数缺失');
- if (!(isset($req['fields']) && count($req['fields'])!=0)){
- $this->error('参数错误','fields',100);
- }
- if(strpos($req['date'],'-')){
- $where = ['c.Sys_rq'=>['like','%'.$req['date'].'%']];
- }else{
- $where = ['c.jjcp_gdbh'=>$req['date']];
- }
- if (isset($req['sys_id']) && !empty($req['sys_id'])){
- $where['c.Sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
- }
- $arr = [
- '入仓类型' =>['入仓类型'],
- '仓库编号' =>['仓库编号'],
- '仓库名称' =>['仓库名称'],
- 'jjcp_num' =>['入仓单号'],
- 'jjcp_gdbh' =>['工单编号'],
- 'jjcp_yjno' =>['印件号'],
- 'jjcp_sl' =>['入仓数量'],
- 'jjcp_sls' =>['累计入仓数量'],
- '订单数量' =>['订单数量'],
- '完成率' =>['完成率'],
- 'jjcp_dw' =>['单位'],
- 'jjcp_sj' =>['入仓时间'],
- 'jjcp_smb' =>['首末板'],
- 'jjcp_cpdh' =>['印件代号'],
- 'jjcp_cpmc' =>['印件名称'],
- '成品编码' =>['产品编号'],
- '成品名称' =>['产品名称'],
- '客户料号' =>['客户料号'],
- 'jjcp_desc' =>['备注'],
- '客户编号' =>['客户编号'],
- 'Gd_客户名称' =>['客户名称'],
- '最近入仓日期' =>['最近入仓日期'],
- '机型备注' =>['机型备注'],
- ];
- $data[0] = [];
- foreach ($req['fields'] as $k=>$v){
- if(array_key_exists($v,$arr)){
- array_push($data[0],$arr[$v][0]);
- }
- }
- //客户编号
- $rows = db()->table('成品入仓')->alias('c')
- ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
- rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh,
- c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj,
- rtrim(c.jjcp_smb) as jjcp_smb, rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
- rtrim(c.成品编码) as 成品编码, rtrim(c.成品名称) as 成品名称,
- rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, LEFT(c.成品编码,4) as 客户编号, rtrim(g.Gd_客户名称) as Gd_客户名称,
- rtrim(c.机型备注) as 机型备注')
- ->where($where)
- ->where('g.Gd_cpdh=c.jjcp_cpdh')
- ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
- ->order('c.UniqId desc')
- ->select();
- foreach ($rows as $key=>$value) {
- $row = db()->table('成品入仓')
- ->field('LEFT(Sys_rq, 10) as Sys_rq,jjcp_sl')
- ->where(['jjcp_gdbh'=>$value['jjcp_gdbh'], 'jjcp_cpdh'=>$value['jjcp_cpdh']])
- ->order('Sys_rq desc')
- ->select();
- $subArray = [];
- foreach ($arr as $k=>$v){
- if($k=='jjcp_sls'){
- $subArray[$k] = 0;
- foreach ($row as $n) {
- $subArray[$k] += $n['jjcp_sl'];
- }
- }else if($k=='完成率'){
- if ($value['订单数量']!=0){
- $subArray[$k] = 0;
- foreach ($row as $n) {
- $subArray[$k] += $n['jjcp_sl'];
- }
- $subArray[$k] = number_format($subArray[$k]/$value['订单数量']/100,2);
- }else{
- $subArray[$k] = '';
- }
- }else if($k=='最近入仓日期'){
- $subArray[$k] = $row[0]['Sys_rq'];
- }else{
- $subArray[$k] = $rows[$key][$k];
- }
- }
- array_push($data,$subArray);
- }
- $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
- }
- }
|