| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?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()->isPost() == 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 适用工序,rtrim(适用机型) as 适用机型,
- 日定额,千件工价,补产标准,机长比例,副机比例,调墨比例,二手比例,飞达比例,辅助比例,放卷比例,分切1比例,分切2比例,检验比例';
- $data = Db::name('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 适用工序,rtrim(适用机型) as 适用机型';
- $list = Db::name('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::name('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::name('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::name('dic_lzde')->where('Parent',$v['Key_'])->field($field)->select();
- if (!empty($child)){
- $handData[$k]['child'] = $child;
- foreach ($child as $i=>$j){
- $children = Db::name('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);
- }
- }
|