| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- /**
- * 糊盒成品入仓维护接口
- */
- class GluFinishedProductWarehousing extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 侧边栏
- * @ApiMethod (GET)
- */
- public function getTab()
- {
- //get请求
- if(!$this->request->isGet()){
- $this->error('请求方式错误');
- }
- $rows = db('糊盒成品入仓')
- ->field('LEFT(Sys_rq, 10) as date, COUNT(*) as counts')
- ->group('date')
- ->order('UniqId desc')
- ->limit(50)
- ->select();
- $num = db('糊盒成品入仓')
- ->where('Sys_rq','>=',$rows[count($rows)-1]['date'])
- ->count();
- $arr = db('糊盒成品入仓')
- ->field('LEFT(Sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(*) as count')
- ->where('Sys_rq','>=',$rows[count($rows)-1]['date'])
- ->group('date, sys_id')
- ->limit($num)
- ->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)
- * @param string $date 时间
- * @param string $sys_id 用户
- */
- public function getList()
- {
- // 验证请求方式
- if (!$this->request->isGet()) {
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- if (!isset($req['date'])) {
- $this->error('参数缺失');
- }
- // 设置分页参数,默认值
- $page = isset($req['page']) && !empty($req['page']) ? intval($req['page']) : 1;
- $limit = isset($req['limit']) && !empty($req['limit']) ? intval($req['limit']) : 20;
- // 构建查询条件
- 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'] . '%'];
- }
- // 获取总数
- $total = db('糊盒成品入仓')->where($option)->count();
- // 查询数据(带分页)
- $rows = db('糊盒成品入仓')->alias('c')
- ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
- rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh,
- 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.成品编码,'.config('product_code_digit').') 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)
- ->join('工单_基本资料 g', 'g.Gd_gdbh=c.jjcp_gdbh AND g.Gd_cpdh=c.jjcp_cpdh')
- ->order('c.UniqId desc')
- ->limit(($page - 1) * $limit, $limit)
- ->select();
- // 处理数据
- foreach ($rows as $key => $value) {
- $row = db('糊盒成品入仓')
- ->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('糊盒成品入仓')->alias('c')
- ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
- rtrim(c.jjcp_num) as jjcp_num,
- c.jjcp_gdbh, 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('糊盒成品入仓')
- ->where(['jjcp_gdbh'=>$rows['jjcp_gdbh'], 'jjcp_cpdh'=>$rows['jjcp_cpdh']])
- ->sum('jjcp_sl');
- $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_cpdh', 'jjcp_cpmc',
- '成品编码', '成品名称',
- '客户料号',
- 'jjcp_smb', 'jjcp_sj',
- 'jjcp_sl', 'jjcp_dw',
- '机型备注',
- 'jjcp_desc'
- ];
- $name = \db('工单_印件资料')
- ->where('Yj_Gdbh',$req['jjcp_gdbh'])
- ->value('yj_yjmc');
- if ($name !== $req['jjcp_cpmc']){
- $this->error('产品名称错误');
- }
- $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');
- //判断当前工单是否存在已提交模版
- $existingRecord = db('糊盒成品入仓')
- ->where('jjcp_gdbh', $data['jjcp_gdbh'])
- ->where('jjcp_smb', '<>', '') // 判断 jjcp_smb 不为空
- ->find();
- if ($existingRecord) {
- $this->error($existingRecord['jjcp_gdbh'].'工单已经进入末版,无法继续操作');
- }
- //开启事务
- db()->startTrans();
- try{
- $sql = db('糊盒成品入仓')->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_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');
- //判断当前工单是否存在已提交模版
- if ($data['jjcp_smb'] === '末 板'){
- $existingRecord = db('糊盒成品入仓')
- ->where('jjcp_gdbh', $data['jjcp_gdbh'])
- ->where('jjcp_smb', '<>', '') // 判断 jjcp_smb 不为空
- ->find();
- if ($existingRecord && $existingRecord['UniqId'] !== (int)$req['UniqId']) {
- $this->error($existingRecord['jjcp_gdbh'].'工单已经进入末版,无法继续操作');
- }
- };
- //开启事务
- db()->startTrans();
- try{
- $sql = db('糊盒成品入仓')->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('糊盒成品入仓')->where('UniqId',$req['UniqId'])->delete();
- // 提交事务
- db()->commit();
- } catch (\Exception $e) {
- // 回滚事务
- db()->rollback();
- $this->error($e->getMessage());
- }
- if($bool===false) $this->error('失败');
- $this->success('成功');
- }
- /**
- * 获取工单信息
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- 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('工单_基本资料')
- ->field('Gd_gdbh, rtrim(销售订单号) as 销售订单号, rtrim(Gd_cpdh) as yj_Yjdh,
- rtrim(Gd_cpmc) as yj_yjmc, rtrim(成品代号) as 成品代号, rtrim(成品名称) as 成品名称,
- rtrim(客户料号) as 客户料号,行号')
- ->where(['Gd_gdbh'=>$gdbh])
- ->select();
- foreach ($rows as $key=>$value){
- $rows[$key]['gdyj'] = $value['Gd_gdbh'].' -'.$value['行号'].'-'.$value['yj_yjmc'];
- }
- $this->success('成功',$rows);
- }
- }
|