| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use \think\Request;
- use \think\Db;
- /**
- * 其他计件单据维护接口
- */
- class OtherCountDocument 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('db_拉料计件')
- // ->field('LEFT(Sczl_rq, 7) as date, CAST(sum(Sczl_cl) AS SIGNED) as counts')
- // ->group('LEFT(Sczl_rq, 7)')
- // ->order('UniqId desc')
- // ->paginate(13);
- //halt($rows);
- // $rows->each(function ($item){
- // $arr = db()->table('db_拉料计件')->alias('l')
- // ->field('rtrim(l.Sczl_bh1) as Sczl_bh1, rtrim(r.员工姓名) as name, sum(l.Sczl_cl) as count')
- // ->where('l.sczl_rq','LIKE',$item['date'].'%')
- // ->join(['人事_基本资料'=>'r'],'l.Sczl_bh1 = r.员工编号')
- // ->group('Sczl_bh1')
- // ->select();
- //
- // $item['sys']=$arr;
- // });
- // halt($rows);
- $rows = db()->table('db_拉料计件')
- ->field('LEFT(Sczl_rq, 7) as date, CAST(sum(Sczl_cl) AS SIGNED) as counts')
- ->group('date')
- ->order('UniqId desc')
- ->limit(13)
- ->select();
- // halt($rows);
- $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
- foreach($rows as $key=>$value){
- $arr = db()->table('db_拉料计件')
- ->field('rtrim(Sczl_bh1) as Sczl_bh1, CAST(sum(Sczl_cl) AS SIGNED) as count')
- ->where('sczl_rq','LIKE',$value['date'].'%')
- ->group('Sczl_bh1')
- ->select();
- foreach ($arr as $k=>$v) {
- $arr[$k]['name'] = array_key_exists($v['Sczl_bh1'],$rs) ? trim($rs[$v['Sczl_bh1']]) : '';
- }
- $rows[$key]['sys'] = $arr;
- $rows[$key]['date'] = str_replace('-', '', $rows[$key]['date']);
- }
- $this->success('成功',$rows);
- }
- /**
- * 获取其他计件单据列表
- * @ApiMethod (GET)
- * @param string $date 时间
- * @param string $Sczl_bh1 员工编号
- * @param string $order 工单编号
- */
- public function getList()
- {
- //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'];
- $where = [];
- if (isset($req['date']) && !empty($req['date'])){
- $where['a.Sczl_rq'] = ['LIKE',$req['date'].'%'];
- }
- if (!empty($req['order']) && (!empty($req['date']) || !empty($req['Sczl_bh1']))){
- $this->error('参数错误');
- }
- if (isset($req['Sczl_bh1']) && !empty($req['Sczl_bh1'])) $where['a.Sczl_bh1'] = $req['Sczl_bh1'];
- if (isset($req['order']) && !empty($req['order'])) $where['a.Sczl_gdbh'] = $req['order'];
- $rows = db()->table('db_拉料计件')->alias('a')
- ->join('dic_lzde b','a.Sczl_dedh = b.sys_bh','left')
- ->field('rtrim(a.sczl_Type) as sczl_Type, LEFT(a.Sczl_rq, 10) as Sczl_rq, a.Sczl_bh1, a.sczl_gdbh, CAST(a.Sczl_cl AS SIGNED) as Sczl_cl,
- rtrim(a.Sczl_desc) as Sczl_desc, rtrim(a.Sczl_gxmc) as Sczl_gxmc, a.sczl_yjno, a.sczl_gxh, rtrim(a.sys_id) as sys_id, a.sys_rq, a.mod_rq, a.UniqId,b.sys_bh,rtrim(sys_mc) as sys_mc')
- ->where($where)
- ->page($page,$limit)
- ->order('a.Sczl_rq asc, a.UniqId asc')
- ->select();
- $total = db()->table('db_拉料计件')->alias('a')
- ->join('dic_lzde b','a.Sczl_dedh = b.sys_bh','left')
- ->where($where)->count();
- $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
- $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
- foreach ($rows as $key=>$value) {
- $rows[$key]['mod_rq'] = $value['mod_rq']=='1900-01-01 00:00:00' ? '' :$value['mod_rq'];
- $rows[$key]['Gd_cpmc'] = array_key_exists($value['sczl_gdbh'],$gd) ? trim($gd[$value['sczl_gdbh']]) : '';
- $rows[$key]['name'] = array_key_exists($value['Sczl_bh1'],$rs) ? trim($rs[$value['Sczl_bh1']]) : '';
- }
- $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('db_拉料计件')->alias('a')
- ->field('a.*,rtrim(d.员工姓名) as name,rtrim(c.sys_mc) as sys_mc,rtrim(b.成品名称) as product_name')
- ->join('人事_基本资料 d', 'a.Sczl_bh1 = d.员工编号','left')
- ->join('工单_基本资料 b', 'a.Sczl_gdbh = b.Gd_gdbh','left')
- ->join('dic_lzde c', 'a.Sczl_dedh = c.sys_bh','left')
- ->where('a.UniqId',$UniqId)
- ->select();
- $this->success('成功',$rows);
- }
- /**
- * 查询印件工序及产品名称
- * @ApiMethod (GET)
- * @param string $gdbh 工单编号
- * @param string $gxmc 工序名称
- */
- public function getGxMc()
- {
- //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['keyword']) && !empty($req['keyword'])){
- $keyword = $req['keyword'];
- }else{
- $keyword = '';
- }
- $rows = db()->table('工单_印件资料')->alias('g')
- ->field('rtrim(g.yj_yjmc) as Gd_cpmc, g.yj_Yjno as Gy0_yjno, c.Gy0_gxh, rtrim(c.Gy0_gxmc) as Gy0_gxmc, rtrim(c.Add_gxmc) as Add_gxmc')
- ->where(['g.Yj_Gdbh' => $gdbh])
- ->where(function ($query) use ($keyword) {
- $query->where(function ($query) use ($keyword) {
- $query->where('c.Gy0_yjno', 'like', '%' . $keyword . '%')
- ->whereOr('c.Gy0_gxh', 'like', '%' . $keyword . '%')
- ->whereOr('c.Add_gxmc', 'like', '%' . $keyword . '%');
- });
- $query->whereOr(function ($query) use ($keyword) {
- $query->where('c.Add_gxmc', '=', '')
- ->where(function ($query) use ($keyword) {
- $query->where('c.Gy0_yjno', 'like', '%' . $keyword . '%')
- ->whereOr('c.Gy0_gxh', 'like', '%' . $keyword . '%')
- ->whereOr('c.Gy0_gxmc', 'like', '%' . $keyword . '%');
- });
- });
- })
- ->join(['工单_工艺资料'=>'c'],'c.Gy0_gdbh=g.Yj_Gdbh and g.yj_Yjno=c.Gy0_yjno')
- ->select();
- foreach ($rows as $key=>$value){
- if($value['Add_gxmc'] != ''){
- $rows[$key]['jyGx'] = sprintf("%02d", $value['Gy0_yjno']).'-'.sprintf("%02d", $value['Gy0_gxh']).'-'.$value['Add_gxmc'];
- }else{
- $rows[$key]['jyGx'] = sprintf("%02d", $value['Gy0_yjno']).'-'.sprintf("%02d", $value['Gy0_gxh']).'-'.$value['Gy0_gxmc'];
- }
- }
- $this->success('成功',$rows);
- }
- /**
- * 查询定额代号
- * @ApiMethod (GET)
- */
- public function getDedh()
- {
- //get请求
- if(!$this->request->isGet()){
- $this->error('请求方式错误');
- }
- $row = db('dic_lzde')
- ->field('Key_, sys_bh, rtrim(sys_mc) as sys_mc')
- ->where('sys_mc','包装')
- ->find();
- $rows = db('dic_lzde')
- ->field('Key_, sys_bh, rtrim(sys_mc) as sys_mc')
- ->where('Parent',$row['Key_'])
- ->order('sys_bh asc')
- ->select();
- foreach ($rows as $key=>$value){
- $bool = db('dic_lzde')
- ->field('Key_,sys_bh, rtrim(sys_mc) as sys_mc')
- ->where('Parent',$value['Key_'])
- ->order('sys_bh asc')
- ->select();
- if ($bool){
- foreach ($bool as $k=>$v){
- $bool1 = db('dic_lzde')
- ->field('sys_bh, rtrim(sys_mc) as sys_mc')
- ->where('Parent',$v['Key_'])
- ->order('sys_bh asc')
- ->select();
- if ($bool1){
- $bool[$k]['bh_mc'] = $bool1;
- }
- }
- $rows[$key]['bh_mc'] = $bool;
- }
- }
- $row['bh_mc'] = $rows;
- $this->success('成功',$row);
- }
- /**
- * 新增
- * @ApiMethod (POST)
- * @param string
- */
- public function add()
- {
- if(!$this->request->isPost()){
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- $arr = [
- 'Sys_id',
- 'Sczl_bh1',
- 'sczl_Type',
- 'Sczl_rq',
- 'Sczl_gdbh',
- 'Sczl_gxmc',
- 'sczl_gxh',
- 'Sczl_cl',
- 'Sczl_dedh',
- 'Sczl_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');
- //查询UniqId
- $UniqId = db()->table('db_拉料计件')->max('UniqId');
- $data['UniqId'] = $UniqId+1;
- //开启事务
- db()->startTrans();
- try{
- $sql = db()->table('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
- * @params array data
- */
- public function edit(){
- if (Request::instance()->isPost() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->post();
- if (!isset($params) || !isset($params['UniqId'])){
- $this->error('参数不能为空');
- }
- $uniqId = $params['UniqId'];
- unset($params['UniqId']);
- $sql = Db::name('db_拉料计件')->where('UniqId',$uniqId)->fetchSql(true)->update($params);
- $res = Db::query($sql);
- if ($res !== false){
- $this->success('更新成功');
- }else{
- $this->error('更新失败');
- }
- }
- /**
- * 修改
- * @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('db_拉料计件')->where('UniqId',$req['UniqId'])->delete();
- // 提交事务
- db()->commit();
- } catch (\Exception $e) {
- // 回滚事务
- db()->rollback();
- $this->error($e->getMessage());
- }
- if($bool===false) $this->error('失败');
- $this->success('成功');
- }
- }
|