WorkOrderVerification.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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 WorkOrderVerification 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 (GET)
  24. */
  25. public function getTab()
  26. {
  27. //get请求
  28. if(!$this->request->isGet()){
  29. $this->error('请求方式错误');
  30. }
  31. $rows = db()->table('db_qczl')
  32. ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
  33. ->group('date')
  34. ->order('UniqId desc')
  35. ->limit(30)
  36. ->select();
  37. $arr = db()->table('db_qczl')
  38. ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(sys_id) as count')
  39. ->where('sys_rq','>=',$rows[29]['date'])
  40. ->group('date, sys_id')
  41. ->select();
  42. foreach($rows as $key=>$value){
  43. $rows[$key]['sys'] = [];
  44. foreach($arr as $k=>$v){
  45. if($value['date'] == $v['date']){
  46. unset($v['date']);
  47. array_push($rows[$key]['sys'],$v);
  48. unset($arr[$k]);
  49. }
  50. }
  51. $rows[$key]['date'] = str_replace('-', '.', $rows[$key]['date']);
  52. }
  53. $this->success('成功',$rows);
  54. }
  55. /**
  56. * 获取工单核验单列表
  57. * @ApiMethod (GET)
  58. * @param string $date 时间
  59. * @param string $sys_id 用户
  60. */
  61. public function getList()
  62. {
  63. //get请求
  64. if(!$this->request->isGet()){
  65. $this->error('请求方式错误');
  66. }
  67. $req = $this->request->param();
  68. $page = 1;
  69. $limit = 15;
  70. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  71. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  72. $where = [];
  73. if (isset($req['date']) && !empty($req['date'])){
  74. $where['sys_rq'] = ['LIKE',$req['date'].'%'];
  75. }
  76. if (isset($req['sys_id']) && !empty($req['sys_id'])) $where['sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
  77. if (isset($req['order']) && !empty($req['order'])) $where['qczl_gdbh'] = $req['order'];
  78. $rows = db()->table('db_qczl')
  79. ->field('qczl_gdbh, qczl_yjno, LEFT(qczl_rq, 10) as qczl_rq, qczl_num, rtrim(qczl_NumDesc) as qczl_NumDesc, qczl_fp,
  80. fp_lb1, fp_lb2, fp_lb3, fp_lb4, fp_lb5, fp_lb6, fp_lb7, fp_lb8, fp_lb9, fp_lb10, fp_lb11, fp_lb12, fp_lb13, fp_lb14, fp_lb15, fp_lb16, fp_lb17,
  81. fp_sl1, fp_sl2, fp_sl3, fp_sl4, fp_sl5, fp_sl6, fp_sl7, fp_sl8, fp_sl9, fp_sl10, fp_sl11, fp_sl12, fp_sl13, fp_sl14, fp_sl15, fp_sl16, fp_sl17,
  82. rtrim(sys_id) as sys_id,UniqId')
  83. ->where($where)
  84. ->order('UniqId desc')
  85. ->page($page,$limit)
  86. ->select();
  87. $total = db()->table('db_qczl')->where($where)->count();
  88. $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
  89. foreach ($rows as $key=>$value){
  90. $rows[$key]['Gd_cpmc'] = array_key_exists($value['qczl_gdbh'],$gd) ? sprintf("%02d", $value['qczl_yjno']).'-'.trim($gd[$value['qczl_gdbh']]) : '';
  91. for ($i=1;$i<=17;$i++){
  92. if ($value['fp_sl'.$i]==0){
  93. $rows[$key]['sl_lb'.$i] = '';
  94. }else{
  95. $rows[$key]['sl_lb'.$i] = trim($value['fp_sl'.$i].'-->'.$value['fp_lb'.$i]);
  96. }
  97. unset($rows[$key]['fp_sl'.$i]);
  98. unset($rows[$key]['fp_lb'.$i]);
  99. }
  100. }
  101. $data = [
  102. 'total' => $total,
  103. 'rows' => $rows,
  104. ];
  105. $this->success('成功',$data);
  106. }
  107. /**
  108. * 获取工单核验单信息
  109. * @ApiMethod (GET)
  110. * @param string $UniqId UniqId
  111. */
  112. public function getInfo()
  113. {
  114. //get请求
  115. if(!$this->request->isGet()){
  116. $this->error('请求方式错误');
  117. }
  118. $req = $this->request->param();
  119. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  120. $UniqId = $req['UniqId'];
  121. }else{
  122. $this->error('参数错误');
  123. }
  124. $rows = db()->table('db_qczl')->alias('d')
  125. ->field('d.*, ')
  126. ->join('工单_基本资料 g', 'd.')
  127. ->where('d.UniqId',$UniqId)
  128. ->select();
  129. $this->success('成功',$rows);
  130. }
  131. /**
  132. * 获取单个工单核检单信息
  133. * @ApiMethod GET
  134. * @params string UniqId
  135. */
  136. public function getOneWorkOrder(){
  137. if (Request::instance()->isGet() == false){
  138. $this->error('非法请求');
  139. }
  140. $params = Request::instance()->param();
  141. if (!isset($params['UniqId']) || empty($params['UniqId'])){
  142. $this->error('参数错误');
  143. }
  144. $field = '';
  145. $list = Db::name('db_qczl')->where('UniqId',$params['UniqId'])->find();
  146. $list['fp_name1'] = '';
  147. if (!empty($list['fp_bh1'])){
  148. $list['fp_name1'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh1'])->value('rtrim(员工姓名)');
  149. }
  150. $list['fp_name2'] = '';
  151. if (!empty($list['fp_bh2'])){
  152. $list['fp_name2'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh2'])->value('rtrim(员工姓名)');
  153. }
  154. $list['fp_name3'] = '';
  155. if (!empty($list['fp_bh3'])){
  156. $list['fp_name3'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh3'])->value('rtrim(员工姓名)');
  157. }
  158. $list['fp_name4'] = '';
  159. if (!empty($list['fp_bh4'])){
  160. $list['fp_name4'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh4'])->value('rtrim(员工姓名)');
  161. }
  162. $list['fp_name5'] = '';
  163. if (!empty($list['fp_bh5'])){
  164. $list['fp_name5'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh5'])->value('rtrim(员工姓名)');
  165. }
  166. $list['fp_name6'] = '';
  167. if (!empty($list['fp_bh6'])){
  168. $list['fp_name6'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh6'])->value('rtrim(员工姓名)');
  169. }
  170. $list['fp_name7'] = '';
  171. if (!empty($list['fp_bh7'])){
  172. $list['fp_name7'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh7'])->value('rtrim(员工姓名)');
  173. }
  174. $list['fp_name8'] = '';
  175. if (!empty($list['fp_bh8'])){
  176. $list['fp_name8'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh8'])->value('rtrim(员工姓名)');
  177. }
  178. $list['fp_name9'] = '';
  179. if (!empty($list['fp_bh9'])){
  180. $list['fp_name9'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh9'])->value('rtrim(员工姓名)');
  181. }
  182. $list['fp_name10'] = '';
  183. if (!empty($list['fp_bh10'])){
  184. $list['fp_name10'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh10'])->value('rtrim(员工姓名)');
  185. }
  186. $list['fp_name11'] = '';
  187. if (!empty($list['fp_bh11'])){
  188. $list['fp_name11'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh11'])->value('rtrim(员工姓名)');
  189. }
  190. $list['fp_name12'] = '';
  191. if (!empty($list['fp_bh12'])){
  192. $list['fp_name12'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh12'])->value('rtrim(员工姓名)');
  193. }
  194. $list['fp_name13'] = '';
  195. if (!empty($list['fp_bh13'])){
  196. $list['fp_name13'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh13'])->value('rtrim(员工姓名)');
  197. }
  198. $max = Db::name('设备_产量计酬')->where('sczl_gdbh',$list['qczl_gdbh'])->field('MAX(sczl_num) as sczl_num')->find();
  199. $list['total_liucheng'] = $max['sczl_num'];
  200. $this->success('请求成功',$list);
  201. }
  202. /**
  203. * 获取工单基本信息
  204. * @ApiMethod GET
  205. * @params string order
  206. */
  207. public function getOrderInfo(){
  208. if (Request::instance()->isGet() == false){
  209. $this->error('非法请求');
  210. }
  211. $params = Request::instance()->param();
  212. if (!isset($params['order']) || empty($params['order'])){
  213. $this->error('参数错误');
  214. }
  215. $list = Db::name('工单_基本资料')->alias('a')
  216. ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh','left')
  217. ->where('a.Gd_gdbh',$params['order'])
  218. ->where('a.行号',1)
  219. ->field('a.Gd_cpmc,b.yj_Yjno,b.yj_yjmc')
  220. ->find();
  221. $this->success('请求成功',$list);
  222. }
  223. /**
  224. * 获取印件名称及工序
  225. * @ApiMethod GET
  226. * @params string order
  227. * @params string yj_no
  228. */
  229. public function getYjInfo(){
  230. if (Request::instance()->isGet() == false){
  231. $this->error('非法请求');
  232. }
  233. $params = Request::instance()->param();
  234. if (!isset($params['order']) || empty($params['order'])){
  235. $this->error('参数错误');
  236. }
  237. if (!isset($params['yj_no']) || empty($params['yj_no'])){
  238. $this->error('参数错误');
  239. }
  240. $where['Yj_Gdbh'] = $params['order'];
  241. $where['yj_Yjno'] = $params['yj_no'];
  242. $list = Db::name('工单_印件资料')->where($where)->field('yj_yjmc')->find();
  243. $option['Gy0_gdbh'] = $params['order'];
  244. $option['Gy0_yjno'] = $params['yj_no'];
  245. $option['Gy0_site'] = '检验车间';
  246. $option['Gy0_gxmc'] = array('not in',['包装','外发加工','废挑正','成品防护']);
  247. $gxList = Db::name('工单_工艺资料')->where($option)->field('Gy0_gxh,rtrim(Gy0_gxmc) as Gy0_gxmc,rtrim(Add_gxmc) as Add_gxmc')->select();
  248. $max = Db::name('设备_产量计酬')->where('sczl_gdbh',$params['order'])->where('sczl_yjno',$params['yj_no'])->field('MAX(sczl_num) as sczl_num')->value('sczl_num');
  249. $list['gx_data'] = $gxList;
  250. $list['max_num'] = $max;
  251. $this->success('请求成功',$list);
  252. }
  253. /**
  254. * 获取废品分类
  255. * @ApiMethod GET
  256. * @params string search
  257. */
  258. public function getWastInfo(){
  259. if (Request::instance()->isGet() == false){
  260. $this->error('非法请求');
  261. }
  262. $params = Request::instance()->param();
  263. if (!isset($params['search']) || empty($params['search'])){
  264. $this->error('参数错误');
  265. }
  266. $where['分类'] = '废品分类';
  267. $where['名称'] = array('like','%'.$params['search'].'%');
  268. $data = Db::name('erp_常用字典')->where($where)->column('名称');
  269. // 分割字符串并合并相同项
  270. $resultArray = [];
  271. foreach ($data as $item) {
  272. $parts = explode('_', $item);
  273. // 使用第一个部分作为一级键,第二个部分作为二级键
  274. $firstKey = $parts[0];
  275. $secondKey = $parts[1];
  276. $thirdValue = $parts[2];
  277. $resultArray[$firstKey][$secondKey][] = $thirdValue;
  278. }
  279. // 对废品分类下的数组进行升序排序
  280. if (isset($resultArray['data']['废品分类'])) {
  281. foreach ($resultArray['data']['废品分类'] as &$category) {
  282. // 判断是关联数组(单凹等)还是索引数组(分切等)
  283. if (is_array($category) && !empty($category) && is_array(current($category))) {
  284. foreach ($category as &$subCategory) {
  285. ksort($subCategory);
  286. }
  287. } else {
  288. ksort($category);
  289. }
  290. }
  291. }
  292. $this->success('请求成功',$resultArray);
  293. }
  294. /**
  295. *获取工序及责任组长
  296. * @ApiMethod GET
  297. * @params string type
  298. * @params string order
  299. */
  300. public function getGxAndLeader(){
  301. if (Request::instance()->isGet() == false){
  302. $this->error('非法请求');
  303. }
  304. $params = Request::instance()->param();
  305. if (!isset($params['type']) || empty($params['type'])){
  306. $this->error('参数错误');
  307. }
  308. if (!isset($params['order']) || empty($params['order'])){
  309. $this->error('参数错误');
  310. }
  311. $type = trim($params['type']);
  312. $waste = Db::name('erp_常用字典')->where('名称','like','%'.$type.'%')->find();
  313. if (empty($waste)){
  314. $this->error('未查询到废品分类');
  315. }
  316. $wasteType = explode('_',substr($waste['名称'],0,-1));
  317. $searchArr = explode('-',$wasteType[1]);
  318. $search = substr($searchArr[1],0,6);
  319. $where['a.sczl_gdbh'] = $params['order'];
  320. $where['a.sczl_type'] = array('like','%'.$search.'%');
  321. $list = Db::name('设备_产量计酬')->alias('a')
  322. ->join('人事_基本资料 b','a.sczl_bh1 = b.员工编号','left')
  323. ->where($where)->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
  324. ->select();
  325. $count = count($list);
  326. $list[$count]['sczl_gxmc'] = '99-外发加工';
  327. $list[$count]['sczl_bzdh'] = 'A班';
  328. $list[$count]['sczl_jtbh'] = '';
  329. $list[$count]['sczl_bh1'] = '000000';
  330. $list[$count]['name'] = '计时工';
  331. $this->success('请求成功',$list);
  332. }
  333. /**
  334. * 修改工单核检单
  335. * @ApiMethod POST
  336. * @params array data
  337. */
  338. public function edit(){
  339. if (Request::instance()->isPost() == false){
  340. $this->error('非法请求');
  341. }
  342. $params = Request::instance()->post();
  343. if (!isset($params['UniqId'])){
  344. $this->error('参数不能为空');
  345. }
  346. $id = $params['UniqId'];
  347. unset($params['UniqId']);
  348. $sql = Db::name('db_qczl')->where('UniqId',$id)->fetchSql(true)->update($params);
  349. $res = Db::query($sql);
  350. if ($res !== 0){
  351. $this->success('更新成功');
  352. }else{
  353. $this->error('更新失败');
  354. }
  355. }
  356. /**
  357. * 工单核检废品分布
  358. * @ApiMethod GET
  359. * @params string order
  360. */
  361. public function wasteDistribution(){
  362. if (Request::instance()->isGet() == false){
  363. $this->error('非法请求');
  364. }
  365. $params = Request::instance()->param();
  366. if (!isset($params['order']) || empty($params['order'])){
  367. $this->error('参数错误');
  368. }
  369. $field = '
  370. rtrim(fp_lb1) as fp_lb1,rtrim(fp_lb2) as fp_lb2,rtrim(fp_lb3) as fp_lb3,rtrim(fp_lb4) as fp_lb4,rtrim(fp_lb5) as fp_lb5,rtrim(fp_lb6) as fp_lb6,rtrim(fp_lb7) as fp_lb7,
  371. rtrim(fp_lb8) as fp_lb8,rtrim(fp_lb9) as fp_lb9,rtrim(fp_lb10) as fp_lb10,rtrim(fp_lb11) as fp_lb11,rtrim(fp_lb12) as fp_lb12,rtrim(fp_lb13) as fp_lb13,
  372. fp_sl1,fp_sl2,fp_sl3,fp_sl4,fp_sl5,fp_sl6,fp_sl7,fp_sl8,fp_sl9,fp_sl10,fp_sl11,fp_sl12,fp_sl13
  373. ';
  374. $data = Db::name('db_qczl')->name('db_qczl')->where('qczl_gdbh',$params['order'])->field($field)->select();
  375. if (empty($data)){
  376. $this->error('暂无废品数据');
  377. }
  378. // 用于存储废品类别和对应废品数量的数组
  379. $categories = array();
  380. // 循环遍历原始数组
  381. foreach ($data as $item) {
  382. // 提取废品类别和对应废品数量
  383. foreach ($item as $key => $value) {
  384. if (strpos($key, "fp_lb") === 0) {
  385. $categoryKey = $key;
  386. $quantityKey = str_replace("fp_lb", "fp_sl", $key);
  387. $quantityValue = $item[$quantityKey];
  388. if (!isset($categories[$value])) {
  389. $categories[$value] = 0;
  390. }
  391. $categories[$value] += (int)$quantityValue;
  392. }
  393. }
  394. }
  395. ksort($categories);
  396. $wasteTotal = Db::name('db_qczl')->where('qczl_gdbh',$params['order'])->sum('qczl_fp');
  397. if (empty($wasteTotal)){
  398. $wasteTotal = 0;
  399. }
  400. $where['a.Gd_gdbh'] = $params['order'];
  401. $where['a.行号'] = 1;
  402. $gdInfo = Db::name('工单_基本资料')->alias('a')
  403. ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh','left')
  404. ->where($where)->field('a.Gd_gdbh,a.实际投料,b.yj_Yjno,b.yj_yjmc')->find();
  405. $gdInfo['yj_Yjno'] = $gdInfo['yj_Yjno'] > 10 ? $gdInfo['yj_Yjno']:'0'.$gdInfo['yj_Yjno'];
  406. $gdInfo['实际投料'] = (int)($gdInfo['实际投料'] * 10000);
  407. $gdInfo['wasteTotal'] = $wasteTotal;
  408. $finishNum = Db::name('成品入仓')->where('jjcp_gdbh',$params['order'])->sum('jjcp_sl');
  409. $gdInfo['passRate'] = '';
  410. if (!empty($finishNum)){
  411. $gdInfo['passRate'] = number_format((int)$finishNum/$gdInfo['实际投料']*100,2).'%';
  412. }
  413. //左侧废品数据
  414. $wasteData = array();
  415. $i = 0;
  416. foreach ($categories as $key=>$value){
  417. if ($value != 0){
  418. $wasteData[$i]['type'] = $key;
  419. $wasteData[$i]['num'] = $value;
  420. $wasteData[$i]['lossesRate'] = number_format($value/$gdInfo['实际投料']*100,4).'%';
  421. $wasteData[$i]['wasteRate'] = number_format($value/$wasteTotal*100,2).'%';
  422. $i++;
  423. }
  424. }
  425. // 按首字母相同的键将值相加
  426. $newArray = array();
  427. foreach ($categories as $key => $value) {
  428. $firstLetter = strtoupper(substr($key, 0, 1)); // 获取首字母并转换为大写
  429. if (!isset($newArray[$firstLetter])) {
  430. $newArray[$firstLetter] = 0;
  431. }
  432. $newArray[$firstLetter] += $value;
  433. }
  434. // 去掉值为零的项
  435. $newArray = array_filter($newArray, function($value) {
  436. return $value !== 0;
  437. });
  438. //右侧废品数据
  439. $rightData = array();
  440. $i = 0;
  441. $name = array();
  442. foreach ($newArray as $key=>$value){
  443. $item = Db::name('erp_常用字典')->where('名称','like','%'.$key.'%')->value('名称');
  444. $item = explode('_',substr($item,0,-1));
  445. $rightData[$i]['type'] = $item[1];
  446. $rightData[$i]['rate'] = number_format($value/$wasteTotal*100,0).'%';
  447. $name[$i] = $item[1];
  448. $i++;
  449. }
  450. $gdInfo['wasteData'] = $wasteData;
  451. $gdInfo['rightData'] = $rightData;
  452. $gdInfo['rightTitle'] = $name;
  453. $this->success('请求成功',$gdInfo);
  454. }
  455. /**
  456. * 工单工期异常调整
  457. * @ApiMethod GET
  458. * @params string order
  459. * 计划产量计算方式:上个工序计划产量-(基础损耗+损耗率*上个工序计划产量)*损耗系数*计损色数)
  460. * lastNum - (Gy0_Rate0 + Gy0_Rate1 * lastNum )* 损耗系数(Gy0_Rate3) * Gy0_Ms
  461. */
  462. public function getOrderDate(){
  463. if (Request::instance()->isGet() == false){
  464. $this->error('非法请求');
  465. }
  466. $params = Request::instance()->param();
  467. if (!isset($params['order']) || empty($params['order'])){
  468. $this->error('参数错误');
  469. }
  470. $where['a.Gy0_gdbh'] = $params['order'];
  471. $where['a.Gy0_sbbh'] = array('neq',' ');
  472. $productNum = Db::name('工单_基本资料')->where('Gd_gdbh',$params['order'])->value('计划投料');
  473. $gyData = Db::name('工单_工艺资料')->alias('a')
  474. ->join('设备_产量计酬 b','a.Gy0_gdbh = b.sczl_gdbh and a.Gy0_gxh = b.sczl_gxh','left')
  475. ->where($where)
  476. ->field('a.Gy0_yjno,a.Gy0_gxh,rtrim(a.Gy0_gxmc) as Gy0_gxmc,a.Gy0_sbbh,a.Gy0_Rate0,a.Gy0_Rate1,a.损耗系数 as Gy0_Rate3,a.Gy0_Ms,a.Gy0_SITE,a.Gy0_计划接货数,a.PD_WG,
  477. sum(b.sczl_cl) as cl')
  478. ->group('a.Gy0_gxh')
  479. ->select();
  480. $lastNum = $productNum;
  481. $res = [];
  482. foreach ($gyData as $key=> $process) {
  483. $res[$key]['Gy0_yjno'] = $process['Gy0_yjno'] > 10 ? $process['Gy0_yjno'] : '0'.$process['Gy0_yjno'];
  484. $res[$key]['Gy0_gxh'] = $process['Gy0_gxh'] > 10 ? $process['Gy0_gxh'] : '0'.$process['Gy0_gxh'];
  485. $res[$key]['Gy0_gxmc'] = $process['Gy0_gxmc'];
  486. $res[$key]['Gy0_sbbh'] = $process['Gy0_sbbh'];
  487. $res[$key]['PD_WG'] = $process['PD_WG'];
  488. $res[$key]['finish'] = empty($process['cl']) ? 0: (int)$process['cl'];
  489. // 计算工序计划产量
  490. if ($process["Gy0_gxh"] == "1") {
  491. // 第一道工序直接使用初始计划产量
  492. $Num = $lastNum;
  493. } else {
  494. $Gy0_Ms = $gyData[$key-1]['Gy0_Ms'];
  495. $Gy0_Rate0 = $gyData[$key-1]['Gy0_Rate0'];
  496. $Gy0_Rate1 = $gyData[$key-1]['Gy0_Rate1'];
  497. $Gy0_Rate3 = $gyData[$key-1]['Gy0_Rate3'];
  498. // 大于第一道工序,使用上一道工序的计划产量
  499. // 根据公式计算工序计划产量
  500. if ($Gy0_Ms != "0.00") {
  501. $Num = $lastNum - ($Gy0_Rate0 + $Gy0_Rate1 * $lastNum) * $Gy0_Rate3 * $Gy0_Ms;
  502. } else {
  503. $Num = $lastNum - ($Gy0_Rate0 + $Gy0_Rate1 * $lastNum) * $Gy0_Rate3;
  504. }
  505. }
  506. if (trim($process['Gy0_SITE']) == '检验车间'){
  507. $res[$key]['plan'] = (int)$process['Gy0_计划接货数'];
  508. }else{
  509. $res[$key]['plan'] = (int)round($Num);
  510. }
  511. $finish_rate = $res[$key]['finish']/$res[$key]['plan'];
  512. $res[$key]['finish_rate'] = '';
  513. if ($finish_rate != 0){
  514. $res[$key]['finish_rate'] = number_format($finish_rate*100,2).'%';
  515. }
  516. // 更新 $lastNum 为当前工序的计划产量
  517. $lastNum = $Num;
  518. }
  519. $this->success('请求成功',$res);
  520. }
  521. }