PieceWork.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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('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('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('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('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('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('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. /**
  106. * 获取日定额参数
  107. * @ApiMethod POST
  108. * @params string code
  109. */
  110. public function getPieceParams(){
  111. if(!$this->request->isGet()){
  112. $this->error('非法请求');
  113. }
  114. $req = $this->request->param();
  115. if (!isset($req['code']) || empty($req['code'])){
  116. $this->error('请求参数错误');
  117. }
  118. $where['sys_bh'] = array('like','%'.$req['code'].'%');
  119. $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,
  120. 补产标准 as production_standard,UniqId';
  121. $list = db('dic_lzde')->where($where)->field($field)->select();
  122. $this->success('请求成功',$list);
  123. }
  124. /**
  125. * 批量修改定额参数
  126. * @ApiMethod POST
  127. * @params object data
  128. */
  129. public function editAllParams(){
  130. if (Request::instance()->isPost() == false){
  131. $this->error('非法请求');
  132. }
  133. $params = Request::instance()->post();
  134. if (empty($params) || !isset($params[0]['UniqId'])){
  135. $this->error('参数不能为空');
  136. }
  137. $i = 0;
  138. foreach ($params as $key=>$value){
  139. $data = [];
  140. if (!empty($value['daily_quota'])){
  141. $data['日定额'] = $value['daily_quota'];
  142. }
  143. if (!empty($value['thousand_piece'])){
  144. $data['千件工价'] = $value['thousand_piece'];
  145. }
  146. if (!empty($value['production_standard'])){
  147. $data['补产标准'] = $value['production_standard'];
  148. }
  149. $sql = db('dic_lzde')->where('UniqId',$value['UniqId'])->fetchSql(true)->update($data);
  150. $res = Db::query($sql);
  151. if ($res !== false){
  152. $i++;
  153. }
  154. }
  155. if ($i !== 0){
  156. $this->success('更新成功');
  157. }else{
  158. $this->error('更新失败');
  159. }
  160. }
  161. }