| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use \think\Request;
- use \think\Db;
- /**
- * 计件定额管理接口
- */
- class PieceWork extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 首页
- *
- */
- public function index()
- {
- $this->success('请求成功');
- }
- /**
- * 获取单个计件定额
- *
- * @ApiMethod POST
- * @params string code
- */
- public function getOnePieceWork(){
- if (Request::instance()->isGet() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->param();
- $code = $params['code'];
- if (!isset($code)){
- $this->error('参数不能为空');
- }
- $where['sys_bh'] = $code;
- $field = 'rtrim(sys_bh) as sys_bh,rtrim(sys_mc) as sys_mc,rtrim(适用工序) as sygx,rtrim(适用机型) as syjx,
- 日定额 as daily_quota,千件工价 as thousand_piece ,补产标准 as production_standard,机长比例 as fir_proportion,副机比例 as sec_proportion,
- 调墨比例 as ink_proportion,二手比例 as second_hand_proportion,飞达比例 as feeder_proportion,辅助比例 as auxiliary_proportion,放卷比例 as unwinder_proportion,
- 分切1比例 as cutting_one_proportion,分切2比例 as cutting_two_proportion,检验比例 as inspect_proportion';
- $data = db('dic_lzde')->where($where)->field($field)->select();
- $this->success('请求成功',$data);
- }
- /**
- * 获取计件定额列表
- *
- * @ApiMethod GET
- *
- */
- public function getPieceWork(){
- if (Request::instance()->isGet() == false){
- $this->error('非法请求');
- }
- $field = 'Key_,Parent,rtrim(sys_bh) as sys_bh, rtrim(sys_mc) as sys_mc,rtrim(适用工序) as gx,rtrim(适用机型) as jx';
- $list = db('dic_lzde')->field($field)->order('sys_bh')->select();
- $data = [];
- $machineData = [];
- $handData = [];
- foreach ($list as $key=>$value){
- if (substr($value['sys_bh'],0,3) == '020' && $value['Parent'] == '1_'){//机器作业计件定额
- $machineData[$key] = $value;
- }
- if (substr($value['sys_bh'],0,3) == '030' && $value['Parent'] == '196_'){//人工作业计件定额
- $handData[$key] = $value;
- }
- }
- //对机器作业计件定额的数组进行处理
- $machineData = array_values($machineData);
- foreach ($machineData as $k=>$v){
- $child = db('dic_lzde')->where('Parent',$v['Key_'])->field($field)->select();
- if (!empty($child)){
- $machineData[$k]['child'] = $child;
- foreach ($child as $i=>$j){
- if ($v['sys_mc'] == '检验车间'){ //找出检验车间机器下面的数据
- $children = db('dic_lzde')->where('Parent',$j['Key_'])->field($field)->select();
- $machineData[$k]['child'][$i]['children'] = $children;
- } else{
- $machineData[$k]['child'][$i]['children'] = [];
- }
- }
- }
- }
- $data['machineData'] = $machineData;
- //对手工作业计件定额的数组进行处理
- $handData = array_values($handData);
- foreach ($handData as $k=>$v){
- $child = db('dic_lzde')->where('Parent',$v['Key_'])->field($field)->select();
- if (!empty($child)){
- $handData[$k]['child'] = $child;
- foreach ($child as $i=>$j){
- $children = db('dic_lzde')->where('Parent',$j['Key_'])->field($field)->select();
- if (!empty($children)){
- $handData[$k]['child'][$i]['children'] = $children;
- } else{
- $handData[$k]['child'][$i]['children'] = [];
- }
- }
- }else{
- $handData[$k]['child'] = [];
- }
- }
- $data['handData'] = $handData;
- $this->success('请求成功',$data);
- }
- /**
- * 获取日定额参数
- * @ApiMethod POST
- * @params string code
- */
- public function getPieceParams(){
- if(!$this->request->isGet()){
- $this->error('非法请求');
- }
- $req = $this->request->param();
- if (!isset($req['code']) || empty($req['code'])){
- $this->error('请求参数错误');
- }
- $where['sys_bh'] = array('like','%'.$req['code'].'%');
- $field = 'rtrim(sys_bh) as sys_bh,rtrim(sys_mc) as sys_mc,rtrim(适用工序) as use_gx,rtrim(适用机型) as use_machine,日定额 as daily_quota,千件工价 as thousand_piece,
- 补产标准 as production_standard,UniqId';
- $list = db('dic_lzde')->where($where)->field($field)->select();
- $this->success('请求成功',$list);
- }
- /**
- * 批量修改定额参数
- * @ApiMethod POST
- * @params object data
- */
- public function editAllParams(){
- if (Request::instance()->isPost() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->post();
- if (empty($params) || !isset($params[0]['UniqId'])){
- $this->error('参数不能为空');
- }
- $i = 0;
- foreach ($params as $key=>$value){
- $data = [];
- if (!empty($value['daily_quota'])){
- $data['日定额'] = $value['daily_quota'];
- }
- if (!empty($value['thousand_piece'])){
- $data['千件工价'] = $value['thousand_piece'];
- }
- if (!empty($value['production_standard'])){
- $data['补产标准'] = $value['production_standard'];
- }
- $sql = db('dic_lzde')->where('UniqId',$value['UniqId'])->fetchSql(true)->update($data);
- $res = Db::query($sql);
- if ($res !== false){
- $i++;
- }
- }
- if ($i !== 0){
- $this->success('更新成功');
- }else{
- $this->error('更新失败');
- }
- }
- }
|