| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?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['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['Sczl_bh1'] = $req['Sczl_bh1'];
- if (isset($req['order']) && !empty($req['order'])) $where['Sczl_gdbh'] = $req['order'];
- $rows = db()->table('db_拉料计件')
- ->field('rtrim(sczl_Type) as sczl_Type, LEFT(Sczl_rq, 10) as Sczl_rq, Sczl_bh1, sczl_gdbh, CAST(Sczl_cl AS SIGNED) as Sczl_cl,
- rtrim(Sczl_desc) as Sczl_desc, rtrim(Sczl_gxmc) as Sczl_gxmc, sczl_yjno, sczl_gxh, rtrim(sys_id) as sys_id, sys_rq, mod_rq, UniqId')
- ->where($where)
- ->page($page,$limit)
- ->order('Sczl_rq asc, UniqId asc')
- ->select();
- $total = db()->table('db_拉料计件')->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('d')
- ->field('d.*, ')
- ->join('工单_基本资料 g', 'd.')
- ->where('d.UniqId',$UniqId)
- ->select();
- $this->success('成功',$rows);
- }
- /**
- * 拉料计件产量维护修改
- * @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 GET
- * @params string Sczl_bh1
- * @params string Sczl_gdbh
- * @params string Sczl_dedh
- */
- public function getOtherInfo(){
- if (Request::instance()->isGet() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->param();
- if (empty($params['Sczl_bh1']) && empty($params['Sczl_gdbh']) && empty($params['Sczl_dedh']) ){
- $this->error('参数错误');
- }
- $data = [];
- if (!empty($params['Sczl_bh1'])){
- $data = Db::name('人事_基本资料')->where('员工编号',$params['Sczl_bh1'])->field('rtrim(员工姓名) as name')->find();
- }
- if (!empty($params['Sczl_gdbh'])){
- $data = Db::name('工单_基本资料')->where('Gd_gdbh',$params['Sczl_gdbh'])->field('rtrim(成品名称) as name')->find();
- }
- if (!empty($params['Sczl_dedh'])){
- $data = Db::name('dic_lzde')->where('sys_bh',$params['Sczl_dedh'])->field('rtrim(sys_mc) as name')->find();
- }
- $this->success('请求成功',$data);
- }
- }
|