ReportingWork.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 ReportingWork 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. * @ApiMethod POST
  24. * @params
  25. */
  26. public function setMachineStatus(){
  27. if (Request::instance()->isPost() == false){
  28. $this->error('非法请求');
  29. }
  30. $params = Request::instance()->post();
  31. if (!isset($params['machine']) || empty($params['machine'])){
  32. $this->error('参数不能为空');
  33. }
  34. $machine = $params['machine'].'#';
  35. $data = [];
  36. $lastData = Db::name('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
  37. if ($lastData['UniqId'] < 160000000){
  38. $id = 160000000;
  39. }else{
  40. $id = $lastData['UniqId'] + 1;
  41. }
  42. if (empty($params['order'])){
  43. unset($lastData['UniqId']);
  44. $data = $lastData;
  45. $data['当前状态'] = $params['status'];
  46. }else{
  47. $data['当前状态'] = $params['status'];
  48. $data['时间'] = date('Y-m-d H:i:s');
  49. $data['设备编号'] = $machine;
  50. $data['工单编号'] = $params['order'];
  51. $data['印件号'] = $params['yjno'];
  52. $data['工序号'] = (int)substr($params['gy_name'],0,2);
  53. $data['工序名称'] = $params['gy_name'];
  54. $data['当班产量'] = $params['production_now'];
  55. $data['累计产量'] = $params['production_all'];
  56. $class = explode(',',$params['class']);
  57. $where = [];
  58. $where['sczl_jtbh'] = $machine;
  59. for ($i=1;$i<=count($class);$i++){
  60. $where['sczl_bh'.$i] = $class[$i-1];
  61. }
  62. $classData = Db::name('设备_班组资料')->where($where)->field('sczl_bzdh,UniqId')->find();
  63. $data['班组编号'] = $classData['sczl_bzdh'];
  64. $data['班组ID'] = $classData['UniqId'];
  65. // 获取当前时间
  66. $current_time = time();
  67. // 设置时间范围
  68. $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  69. $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  70. $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  71. $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  72. // 判断当前时间属于哪个时间范围
  73. if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  74. $data['开工时间'] = date('Y-m-d') . ' 08:30:00';
  75. } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  76. $data['开工时间'] = date('Y-m-d') . ' 20:30:00';
  77. } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  78. $data['开工时间'] = date('Y-m-d',strtotime('+1 day')) . ' 08:30:00';
  79. }
  80. $option['Gy0_gdbh'] = $params['order'];
  81. $option['Gy0_yjno'] = $params['yjno'];
  82. $option['Gy0_gxh'] = $data['工序号'];
  83. $data['任务ID'] = Db::name('工单_工艺资料')->where($option)->value('UniqId');
  84. }
  85. $data['UniqId'] = $id;
  86. $sql = Db::name('设备_产量采集')->fetchSql(true)->insert($data);
  87. $res = Db::query($sql);
  88. if ($res === false){
  89. $this->success('设置失败');
  90. }else{
  91. $this->error('设置成功');
  92. }
  93. }
  94. /**
  95. * 设置工单工序完工
  96. * @ApiMethod POST
  97. * @params string order
  98. * @params string yjno
  99. * @params string gxh
  100. */
  101. public function setProcessStatus(){
  102. if (Request::instance()->isPost() == false){
  103. $this->error('非法请求');
  104. }
  105. $params = Request::instance()->post();
  106. if (!isset($params['order']) || empty($params['order'])){
  107. $this->error('参数不能为空');
  108. }
  109. if (!isset($params['yjno']) || empty($params['yjno'])){
  110. $this->error('参数不能为空');
  111. }
  112. if (!isset($params['gxh']) || empty($params['gxh'])){
  113. $this->error('参数不能为空');
  114. }
  115. $where['Gy0_gdbh'] = $params['order'];
  116. $where['Gy0_yjno'] = $params['yjno'];
  117. $where['Gy0_gxh'] = $params['gxh'];
  118. $date = date('Y-m-d H:i:s');
  119. $res = Db::name('工单_工艺资料')->where($where)->setField('PD_WG',$date);
  120. if ($res === false){
  121. $this->success('设置失败');
  122. }else{
  123. $this->error('设置成功');
  124. }
  125. }
  126. /**
  127. * 根据机台获取生产信息
  128. * @ApiMethod GET
  129. * @params string machine
  130. */
  131. public function getProduceInfo(){
  132. if (Request::instance()->isGet() == false) {
  133. $this->error('非法请求');
  134. }
  135. $params = Request::instance()->param();
  136. if (!isset($params['machine']) || empty($params['machine'])) {
  137. $this->error('参数错误');
  138. }
  139. $machine = $params['machine'].'#';
  140. $data = Db::name('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
  141. $list = [];
  142. $list['order'] = $data['工单编号'];
  143. $list['yjno'] = $data['印件号'];
  144. $name = Db::name('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品名称');
  145. $list['product_name'] = rtrim($name);
  146. $where['Gy0_gdbh'] = $data['工单编号'];
  147. $where['Gy0_yjno'] = $data['印件号'];
  148. $where['Gy0_gxh'] = $data['工序号'];
  149. $gxmc = Db::name('工单_工艺资料')->where($where)->value('Gy0_gxmc');
  150. $list['gxmc'] = rtrim($gxmc);
  151. $this->success('请求成功',$list);
  152. }
  153. /**
  154. * 根据员工编号获取姓名
  155. * @ApiMethod GET
  156. * @params string code
  157. */
  158. public function getStaffName(){
  159. if (Request::instance()->isGet() == false) {
  160. $this->error('非法请求');
  161. }
  162. $params = Request::instance()->param();
  163. if (!isset($params['code']) || empty($params['code'])) {
  164. $this->error('参数错误');
  165. }
  166. if (substr($params['code'],0,2) == 'ZM'){
  167. $code = $params['code'];
  168. }else{
  169. if (strlen($params['code']) != 5){
  170. $length = strlen($params['code']);
  171. $len = 5 -$length;
  172. $str = '';
  173. for ($i=0;$i<$len;$i++){
  174. $str .= '0';
  175. }
  176. $code = 'ZM'.$str.$params['code'];
  177. }else{
  178. $code = 'ZM'.$params['code'];
  179. }
  180. }
  181. $data = Db::name('人事_基本资料')->where('员工编号',$code)->value('员工姓名');
  182. $this->success('请求成功',rtrim($data));
  183. }
  184. /**
  185. * 提交巡查记录
  186. * @ApiMethod POST
  187. * @params
  188. */
  189. public function submitPatrolRecord(){
  190. }
  191. }