PieceWork.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use \think\Request;
  5. use \think\Db;
  6. /**
  7. * 计件定额管理接口
  8. */
  9. class PieceWork extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 首页
  15. *
  16. */
  17. public function index()
  18. {
  19. $this->success('请求成功');
  20. }
  21. /**
  22. * 获取单个计件定额
  23. *
  24. * @ApiMethod POST
  25. * @params string code
  26. */
  27. public function getOnePieceWork(){
  28. if (Request::instance()->isGet() == false){
  29. $this->error('非法请求');
  30. }
  31. $params = Request::instance()->param();
  32. $code = $params['code'];
  33. if (!isset($code)){
  34. $this->error('参数不能为空');
  35. }
  36. $where['sys_bh'] = $code;
  37. $field = 'rtrim(sys_bh) as sys_bh,rtrim(sys_mc) as sys_mc,rtrim(适用工序) as sygx,rtrim(适用机型) as syjx,
  38. 日定额 as daily_quota,千件工价 as thousand_piece ,补产标准 as production_standard,机长比例 as fir_proportion,副机比例 as sec_proportion,
  39. 调墨比例 as ink_proportion,二手比例 as second_hand_proportion,飞达比例 as feeder_proportion,辅助比例 as auxiliary_proportion,放卷比例 as unwinder_proportion,
  40. 分切1比例 as cutting_one_proportion,分切2比例 as cutting_two_proportion,检验比例 as inspect_proportion';
  41. $data = Db::name('dic_lzde')->where($where)->field($field)->select();
  42. $this->success('请求成功',$data);
  43. }
  44. /**
  45. * 获取计件定额列表
  46. *
  47. * @ApiMethod GET
  48. *
  49. */
  50. public function getPieceWork(){
  51. if (Request::instance()->isGet() == false){
  52. $this->error('非法请求');
  53. }
  54. $field = 'Key_,Parent,rtrim(sys_bh) as sys_bh, rtrim(sys_mc) as sys_mc,rtrim(适用工序) as gx,rtrim(适用机型) as jx';
  55. $list = Db::name('dic_lzde')->field($field)->order('sys_bh')->select();
  56. $data = [];
  57. $machineData = [];
  58. $handData = [];
  59. foreach ($list as $key=>$value){
  60. if (substr($value['sys_bh'],0,3) == '020' && $value['Parent'] == '1_'){//机器作业计件定额
  61. $machineData[$key] = $value;
  62. }
  63. if (substr($value['sys_bh'],0,3) == '030' && $value['Parent'] == '196_'){//人工作业计件定额
  64. $handData[$key] = $value;
  65. }
  66. }
  67. //对机器作业计件定额的数组进行处理
  68. $machineData = array_values($machineData);
  69. foreach ($machineData as $k=>$v){
  70. $child = Db::name('dic_lzde')->where('Parent',$v['Key_'])->field($field)->select();
  71. if (!empty($child)){
  72. $machineData[$k]['child'] = $child;
  73. foreach ($child as $i=>$j){
  74. if ($v['sys_mc'] == '检验车间'){ //找出检验车间机器下面的数据
  75. $children = Db::name('dic_lzde')->where('Parent',$j['Key_'])->field($field)->select();
  76. $machineData[$k]['child'][$i]['children'] = $children;
  77. } else{
  78. $machineData[$k]['child'][$i]['children'] = [];
  79. }
  80. }
  81. }
  82. }
  83. $data['machineData'] = $machineData;
  84. //对手工作业计件定额的数组进行处理
  85. $handData = array_values($handData);
  86. foreach ($handData as $k=>$v){
  87. $child = Db::name('dic_lzde')->where('Parent',$v['Key_'])->field($field)->select();
  88. if (!empty($child)){
  89. $handData[$k]['child'] = $child;
  90. foreach ($child as $i=>$j){
  91. $children = Db::name('dic_lzde')->where('Parent',$j['Key_'])->field($field)->select();
  92. if (!empty($children)){
  93. $handData[$k]['child'][$i]['children'] = $children;
  94. } else{
  95. $handData[$k]['child'][$i]['children'] = [];
  96. }
  97. }
  98. }else{
  99. $handData[$k]['child'] = [];
  100. }
  101. }
  102. $data['handData'] = $handData;
  103. $this->success('请求成功',$data);
  104. }
  105. }