WorkOrderVerification.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  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 = 'qczl_gdbh,qczl_Pygd,qczl_yjno,qczl_gxh,qczl_gxmc,qczl_type,qczl_rq,qczl_num,qczl_fp,
  145. qczl_NumDesc,qczl_NumDesc1,qczl_NumDesc2,qczl_NumDesc3,qczl_NumDesc4,qczl_NumDesc5,qczl_NumDesc6,qczl_NumDesc7,qczl_NumDesc8,
  146. 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,trim(fp_lb14) as fp_lb14,trim(fp_lb15) as fp_lb15,trim(fp_lb16) as fp_lb16,trim(fp_lb17) as fp_lb17,
  147. 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
  148. fp_bh1,fp_bh2,fp_bh3,fp_bh4,fp_bh5,fp_bh6,fp_bh7,fp_bh8,fp_bh9,fp_bh10,fp_bh11,fp_bh12,fp_bh13,
  149. fp_bz1,fp_bz2,fp_bz3,fp_bz4,fp_bz5,fp_bz6,fp_bz7,fp_bz8,fp_bz9,fp_bz10,fp_bz11,fp_bz12,fp_bz13,
  150. fp_gxmc1,fp_gxmc2,fp_gxmc3,fp_gxmc4,fp_gxmc5,fp_gxmc6,fp_gxmc7,fp_gxmc8,fp_gxmc9,fp_gxmc10,fp_gxmc11,fp_gxmc12,fp_gxmc13,
  151. sys_id,rtrim(sys_rq) as sys_rq,UniqId';
  152. $list = db('db_qczl')->where('UniqId',$params['UniqId'])->field($field)->find();
  153. $list['fp_name1'] = '';
  154. if (!empty($list['fp_bh1'])){
  155. $list['fp_name1'] = db('人事_基本资料')->where('员工编号',$list['fp_bh1'])->value('rtrim(员工姓名)');
  156. }
  157. $list['fp_name2'] = '';
  158. if (!empty($list['fp_bh2'])){
  159. $list['fp_name2'] = db('人事_基本资料')->where('员工编号',$list['fp_bh2'])->value('rtrim(员工姓名)');
  160. }
  161. $list['fp_name3'] = '';
  162. if (!empty($list['fp_bh3'])){
  163. $list['fp_name3'] = db('人事_基本资料')->where('员工编号',$list['fp_bh3'])->value('rtrim(员工姓名)');
  164. }
  165. $list['fp_name4'] = '';
  166. if (!empty($list['fp_bh4'])){
  167. $list['fp_name4'] = db('人事_基本资料')->where('员工编号',$list['fp_bh4'])->value('rtrim(员工姓名)');
  168. }
  169. $list['fp_name5'] = '';
  170. if (!empty($list['fp_bh5'])){
  171. $list['fp_name5'] = db('人事_基本资料')->where('员工编号',$list['fp_bh5'])->value('rtrim(员工姓名)');
  172. }
  173. $list['fp_name6'] = '';
  174. if (!empty($list['fp_bh6'])){
  175. $list['fp_name6'] = db('人事_基本资料')->where('员工编号',$list['fp_bh6'])->value('rtrim(员工姓名)');
  176. }
  177. $list['fp_name7'] = '';
  178. if (!empty($list['fp_bh7'])){
  179. $list['fp_name7'] = db('人事_基本资料')->where('员工编号',$list['fp_bh7'])->value('rtrim(员工姓名)');
  180. }
  181. $list['fp_name8'] = '';
  182. if (!empty($list['fp_bh8'])){
  183. $list['fp_name8'] = db('人事_基本资料')->where('员工编号',$list['fp_bh8'])->value('rtrim(员工姓名)');
  184. }
  185. $list['fp_name9'] = '';
  186. if (!empty($list['fp_bh9'])){
  187. $list['fp_name9'] = db('人事_基本资料')->where('员工编号',$list['fp_bh9'])->value('rtrim(员工姓名)');
  188. }
  189. $list['fp_name10'] = '';
  190. if (!empty($list['fp_bh10'])){
  191. $list['fp_name10'] = db('人事_基本资料')->where('员工编号',$list['fp_bh10'])->value('rtrim(员工姓名)');
  192. }
  193. $list['fp_name11'] = '';
  194. if (!empty($list['fp_bh11'])){
  195. $list['fp_name11'] = db('人事_基本资料')->where('员工编号',$list['fp_bh11'])->value('rtrim(员工姓名)');
  196. }
  197. $list['fp_name12'] = '';
  198. if (!empty($list['fp_bh12'])){
  199. $list['fp_name12'] = db('人事_基本资料')->where('员工编号',$list['fp_bh12'])->value('rtrim(员工姓名)');
  200. }
  201. $list['fp_name13'] = '';
  202. if (!empty($list['fp_bh13'])){
  203. $list['fp_name13'] = db('人事_基本资料')->where('员工编号',$list['fp_bh13'])->value('rtrim(员工姓名)');
  204. }
  205. $max = db('设备_产量计酬')->where('sczl_gdbh',$list['qczl_gdbh'])->field('MAX(sczl_num) as sczl_num')->find();
  206. $list['total_liucheng'] = $max['sczl_num'];
  207. $this->success('请求成功',$list);
  208. }
  209. /**
  210. * 获取工单基本信息
  211. * @ApiMethod GET
  212. * @params string order
  213. */
  214. public function getOrderInfo(){
  215. if (Request::instance()->isGet() == false){
  216. $this->error('非法请求');
  217. }
  218. $params = Request::instance()->param();
  219. if (!isset($params['order']) || empty($params['order'])){
  220. $this->error('参数错误');
  221. }
  222. $list = db('工单_基本资料')->alias('a')
  223. ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh','left')
  224. ->where('a.Gd_gdbh',$params['order'])
  225. ->where('a.行号',1)
  226. ->field('a.Gd_cpmc,b.yj_Yjno,b.yj_yjmc')
  227. ->find();
  228. $this->success('请求成功',$list);
  229. }
  230. /**
  231. * 获取印件名称及工序
  232. * @ApiMethod GET
  233. * @params string order
  234. * @params string yj_no
  235. */
  236. public function getYjInfo(){
  237. if (Request::instance()->isGet() == false){
  238. $this->error('非法请求');
  239. }
  240. $params = Request::instance()->param();
  241. if (!isset($params['order']) || empty($params['order'])){
  242. $this->error('参数错误');
  243. }
  244. if (!isset($params['yj_no']) || empty($params['yj_no'])){
  245. $this->error('参数错误');
  246. }
  247. $where['Yj_Gdbh'] = $params['order'];
  248. $where['yj_Yjno'] = $params['yj_no'];
  249. $list = db('工单_印件资料')->where($where)->field('yj_yjmc')->find();
  250. $option['Gy0_gdbh'] = $params['order'];
  251. $option['Gy0_yjno'] = $params['yj_no'];
  252. $option['Gy0_site'] = '检验车间';
  253. $option['Gy0_gxmc'] = array('not in',['包装','外发加工','废挑正','成品防护']);
  254. $gxList = db('工单_工艺资料')->where($option)->field('Gy0_gxh,rtrim(Gy0_gxmc) as Gy0_gxmc,rtrim(Add_gxmc) as Add_gxmc')->select();
  255. $max = db('设备_产量计酬')->where('sczl_gdbh',$params['order'])->where('sczl_yjno',$params['yj_no'])->field('MAX(sczl_num) as sczl_num')->value('sczl_num');
  256. $list['gx_data'] = $gxList;
  257. $list['max_num'] = $max;
  258. $this->success('请求成功',$list);
  259. }
  260. /**
  261. * 获取废品分类
  262. * @ApiMethod GET
  263. * @params string search
  264. */
  265. public function getWastInfo(){
  266. if (Request::instance()->isGet() == false){
  267. $this->error('非法请求');
  268. }
  269. $params = Request::instance()->param();
  270. if (!isset($params['search']) || empty($params['search'])){
  271. $this->error('参数错误');
  272. }
  273. $where['分类'] = '废品分类';
  274. $where['名称'] = array('like','%'.$params['search'].'%');
  275. $data = db('erp_常用字典')->where($where)->column('名称');
  276. // 分割字符串并合并相同项
  277. $resultArray = [];
  278. foreach ($data as $item) {
  279. $parts = explode('_', $item);
  280. // 使用第一个部分作为一级键,第二个部分作为二级键
  281. $firstKey = $parts[0];
  282. $secondKey = $parts[1];
  283. $thirdValue = $parts[2];
  284. $resultArray[$firstKey][$secondKey][] = $thirdValue;
  285. }
  286. // 对废品分类下的数组进行升序排序
  287. if (isset($resultArray['data']['废品分类'])) {
  288. foreach ($resultArray['data']['废品分类'] as &$category) {
  289. // 判断是关联数组(单凹等)还是索引数组(分切等)
  290. if (is_array($category) && !empty($category) && is_array(current($category))) {
  291. foreach ($category as &$subCategory) {
  292. ksort($subCategory);
  293. }
  294. } else {
  295. ksort($category);
  296. }
  297. }
  298. }
  299. $this->success('请求成功',$resultArray);
  300. }
  301. /**
  302. *获取工序及责任组长
  303. * @ApiMethod GET
  304. * @params string type
  305. * @params string order
  306. */
  307. public function getGxAndLeader(){
  308. if (Request::instance()->isGet() == false){
  309. $this->error('非法请求');
  310. }
  311. $params = Request::instance()->param();
  312. if (!isset($params['type']) || empty($params['type'])){
  313. $this->error('参数错误');
  314. }
  315. if (!isset($params['order']) || empty($params['order'])){
  316. $this->error('参数错误');
  317. }
  318. $type = trim($params['type']);
  319. $waste = db('erp_常用字典')->where('名称','like','%'.$type.'%')->find();
  320. if (empty($waste)){
  321. $this->error('未查询到废品分类');
  322. }
  323. $wasteType = explode('_',substr($waste['名称'],0,-1));
  324. $searchArr = explode('-',$wasteType[1]);
  325. $search = substr($searchArr[1],0,6);
  326. $where['a.sczl_gdbh'] = $params['order'];
  327. $where['a.sczl_type'] = array('like','%'.$search.'%');
  328. $list = db('设备_产量计酬')->alias('a')
  329. ->join('人事_基本资料 b','a.sczl_bh1 = b.员工编号','left')
  330. ->where($where)->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
  331. ->select();
  332. $count = count($list);
  333. $list[$count]['sczl_gxmc'] = '99-外发加工';
  334. $list[$count]['sczl_bzdh'] = 'A班';
  335. $list[$count]['sczl_jtbh'] = '';
  336. $list[$count]['sczl_bh1'] = '000000';
  337. $list[$count]['name'] = '计时工';
  338. $this->success('请求成功',$list);
  339. }
  340. /**
  341. * 修改工单核检单
  342. * @ApiMethod POST
  343. * @params array data
  344. */
  345. public function edit(){
  346. if (Request::instance()->isPost() == false){
  347. $this->error('非法请求');
  348. }
  349. $params = Request::instance()->post();
  350. if (!isset($params['UniqId'])){
  351. $this->error('参数不能为空');
  352. }
  353. $id = $params['UniqId'];
  354. unset($params['UniqId']);
  355. $sql = db('db_qczl')->where('UniqId',$id)->fetchSql(true)->update($params);
  356. $res = Db::query($sql);
  357. if ($res !== 0){
  358. $this->success('更新成功');
  359. }else{
  360. $this->error('更新失败');
  361. }
  362. }
  363. /**
  364. * 工单核检废品分布
  365. * @ApiMethod GET
  366. * @params string order
  367. */
  368. public function wasteDistribution(){
  369. if (Request::instance()->isGet() == false){
  370. $this->error('非法请求');
  371. }
  372. $params = Request::instance()->param();
  373. if (!isset($params['order']) || empty($params['order'])){
  374. $this->error('参数错误');
  375. }
  376. $field = '
  377. 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,
  378. 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,
  379. 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
  380. ';
  381. $data = db('db_qczl')->name('db_qczl')->where('qczl_gdbh',$params['order'])->field($field)->select();
  382. if (empty($data)){
  383. $this->error('暂无废品数据');
  384. }
  385. // 用于存储废品类别和对应废品数量的数组
  386. $categories = array();
  387. // 循环遍历原始数组
  388. foreach ($data as $item) {
  389. // 提取废品类别和对应废品数量
  390. foreach ($item as $key => $value) {
  391. if (strpos($key, "fp_lb") === 0) {
  392. $categoryKey = $key;
  393. $quantityKey = str_replace("fp_lb", "fp_sl", $key);
  394. $quantityValue = $item[$quantityKey];
  395. if (!isset($categories[$value])) {
  396. $categories[$value] = 0;
  397. }
  398. $categories[$value] += (int)$quantityValue;
  399. }
  400. }
  401. }
  402. ksort($categories);
  403. $wasteTotal = db('db_qczl')->where('qczl_gdbh',$params['order'])->sum('qczl_fp');
  404. if (empty($wasteTotal)){
  405. $wasteTotal = 0;
  406. }
  407. $where['a.Gd_gdbh'] = $params['order'];
  408. $where['a.行号'] = 1;
  409. $gdInfo = db('工单_基本资料')->alias('a')
  410. ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh','left')
  411. ->where($where)->field('a.Gd_gdbh,a.实际投料,b.yj_Yjno,b.yj_yjmc')->find();
  412. $gdInfo['yj_Yjno'] = $gdInfo['yj_Yjno'] > 10 ? $gdInfo['yj_Yjno']:'0'.$gdInfo['yj_Yjno'];
  413. $gdInfo['实际投料'] = (int)($gdInfo['实际投料'] * 10000);
  414. $gdInfo['wasteTotal'] = $wasteTotal;
  415. $finishNum = db('成品入仓')->where('jjcp_gdbh',$params['order'])->sum('jjcp_sl');
  416. $gdInfo['passRate'] = '';
  417. if (!empty($finishNum)){
  418. $gdInfo['passRate'] = number_format((int)$finishNum/$gdInfo['实际投料']*100,2).'%';
  419. }
  420. //左侧废品数据
  421. $wasteData = array();
  422. $i = 0;
  423. foreach ($categories as $key=>$value){
  424. if ($value != 0){
  425. $wasteData[$i]['type'] = $key;
  426. $wasteData[$i]['num'] = $value;
  427. $wasteData[$i]['lossesRate'] = number_format($value/$gdInfo['实际投料']*100,4).'%';
  428. $wasteData[$i]['wasteRate'] = number_format($value/$wasteTotal*100,2).'%';
  429. $i++;
  430. }
  431. }
  432. // 按首字母相同的键将值相加
  433. $newArray = array();
  434. foreach ($categories as $key => $value) {
  435. $firstLetter = strtoupper(substr($key, 0, 1)); // 获取首字母并转换为大写
  436. if (!isset($newArray[$firstLetter])) {
  437. $newArray[$firstLetter] = 0;
  438. }
  439. $newArray[$firstLetter] += $value;
  440. }
  441. // 去掉值为零的项
  442. $newArray = array_filter($newArray, function($value) {
  443. return $value !== 0;
  444. });
  445. //右侧废品数据
  446. $rightData = array();
  447. $i = 0;
  448. $name = array();
  449. foreach ($newArray as $key=>$value){
  450. $item = db('erp_常用字典')->where('名称','like','%'.$key.'%')->value('名称');
  451. $item = explode('_',substr($item,0,-1));
  452. $rightData[$i]['type'] = $item[1];
  453. $rightData[$i]['rate'] = number_format($value/$wasteTotal*100,0).'%';
  454. $name[$i] = $item[1];
  455. $i++;
  456. }
  457. $gdInfo['wasteData'] = $wasteData;
  458. $gdInfo['rightData'] = $rightData;
  459. $gdInfo['rightTitle'] = $name;
  460. $this->success('请求成功',$gdInfo);
  461. }
  462. /**
  463. * 获取工单工序状态
  464. * @ApiMethod GET
  465. * @params string order
  466. * 计划产量计算方式:上个工序计划产量-(基础损耗+损耗率*上个工序计划产量)*损耗系数*计损色数)
  467. * lastNum - (Gy0_Rate0 + Gy0_Rate1 * lastNum )* 损耗系数(Gy0_Rate3) * Gy0_Ms
  468. */
  469. public function getOrderDate(){
  470. if (Request::instance()->isGet() == false){
  471. $this->error('非法请求');
  472. }
  473. $params = Request::instance()->param();
  474. if (!isset($params['order']) || empty($params['order'])){
  475. $this->error('参数错误');
  476. }
  477. $where['a.Gy0_gdbh'] = $params['order'];
  478. $where['a.Gy0_sbbh'] = array('neq',' ');
  479. $productNum = db('工单_基本资料')->where('Gd_gdbh',$params['order'])->value('计划投料');
  480. $gyData = db('工单_工艺资料')->alias('a')
  481. ->join('设备_产量计酬 b','a.Gy0_gdbh = b.sczl_gdbh and a.Gy0_gxh = b.sczl_gxh','left')
  482. ->where($where)
  483. ->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,
  484. a.UniqId,sum(b.sczl_cl) as cl')
  485. ->group('a.Gy0_gxh')
  486. ->select();
  487. $lastNum = $productNum;
  488. $res = [];
  489. foreach ($gyData as $key=> $process) {
  490. $res[$key]['UniqId'] = $process['UniqId'];
  491. $res[$key]['Gy0_yjno'] = $process['Gy0_yjno'] > 10 ? $process['Gy0_yjno'] : '0'.$process['Gy0_yjno'];
  492. $res[$key]['Gy0_gxh'] = $process['Gy0_gxh'] > 10 ? $process['Gy0_gxh'] : '0'.$process['Gy0_gxh'];
  493. $res[$key]['Gy0_gxmc'] = $process['Gy0_gxmc'];
  494. $res[$key]['Gy0_sbbh'] = rtrim($process['Gy0_sbbh']);
  495. $res[$key]['PD_WG'] = $process['PD_WG'];
  496. $res[$key]['finish'] = empty($process['cl']) ? 0: (int)$process['cl'];
  497. // 计算工序计划产量
  498. if ($process["Gy0_gxh"] == "1") {
  499. // 第一道工序直接使用初始计划产量
  500. $Num = $lastNum;
  501. } else {
  502. $Gy0_Ms = $gyData[$key-1]['Gy0_Ms'];
  503. $Gy0_Rate0 = $gyData[$key-1]['Gy0_Rate0'];
  504. $Gy0_Rate1 = $gyData[$key-1]['Gy0_Rate1'];
  505. $Gy0_Rate3 = $gyData[$key-1]['Gy0_Rate3'];
  506. // 大于第一道工序,使用上一道工序的计划产量
  507. // 根据公式计算工序计划产量
  508. if ($Gy0_Ms != "0.00") {
  509. $Num = $lastNum - ($Gy0_Rate0 + $Gy0_Rate1 * $lastNum) * $Gy0_Rate3 * $Gy0_Ms;
  510. } else {
  511. $Num = $lastNum - ($Gy0_Rate0 + $Gy0_Rate1 * $lastNum) * $Gy0_Rate3;
  512. }
  513. }
  514. if (trim($process['Gy0_SITE']) == '检验车间'){
  515. $res[$key]['plan'] = (int)$process['Gy0_计划接货数'];
  516. }else{
  517. $res[$key]['plan'] = (int)round($Num);
  518. }
  519. $finish_rate = $res[$key]['finish']/$res[$key]['plan'];
  520. $res[$key]['finish_rate'] = '';
  521. if ($finish_rate != 0){
  522. $res[$key]['finish_rate'] = number_format($finish_rate*100,2).'%';
  523. }
  524. // 更新 $lastNum 为当前工序的计划产量
  525. $lastNum = $Num;
  526. }
  527. $this->success('请求成功',$res);
  528. }
  529. /**
  530. * 工单工序状态更正
  531. * @ApiMethod POST
  532. * @params string UniqId
  533. * @params string date
  534. */
  535. public function editOrderFinishDate(){
  536. if (Request::instance()->isPost() == false){
  537. $this->error('非法请求');
  538. }
  539. $params = Request::instance()->post();
  540. if (!isset($params['UniqId']) || !isset($params['date'])){
  541. $this->error('参数错误');
  542. }
  543. if (empty($params['UniqId'])){
  544. $this->error('参数不能为空');
  545. }
  546. if (empty($params['date'])){
  547. $params['date'] = '1900-01-01 00:00:00';
  548. }
  549. $res = db('工单_工艺资料')->where('UniqId',$params['UniqId'])->setField('PD_WG',$params['date']);
  550. if ($res != false){
  551. $this->success('更新成功');
  552. }else{
  553. $this->error('更新失败');
  554. }
  555. }
  556. /**
  557. * 工单工序生产进程菜单栏
  558. * @ApiMethod GET
  559. * @params string order
  560. */
  561. public function getOrderProcessLeft(){
  562. if (Request::instance()->isGet() == false){
  563. $this->error('非法请求');
  564. }
  565. $params = Request::instance()->param();
  566. if (!isset($params['order']) || empty($params['order'])){
  567. $this->error('参数错误');
  568. }
  569. $where['Gd_gdbh'] = $params['order'];
  570. $where['行号'] = 1;
  571. //工单基本资料
  572. $info = db('工单_基本资料')->where($where)->field('rtrim(成品代号) as code,rtrim(成品名称) as name')->find();
  573. //工艺资料
  574. $option['Gy0_gdbh'] = $params['order'];
  575. $gyInfo = db('工单_工艺资料')
  576. ->where($option)
  577. ->where(function ($query) {
  578. $query->where('Gy0_sbbh', '<>', '')
  579. ->whereOr('Gy0_gxmc', '核检')
  580. ->whereOr('Gy0_gxmc', '成品防护');
  581. })
  582. ->field('Gy0_yjno,Gy0_gxh')
  583. ->select();
  584. foreach ($gyInfo as $key=>$value){
  585. $gyInfo[$key]['Gy0_yjno'] = $value['Gy0_yjno'] > 10 ? $value['Gy0_yjno'] : '0'.$value['Gy0_yjno'];
  586. $gyInfo[$key]['Gy0_gxh'] = $value['Gy0_gxh'] > 10 ? $value['Gy0_gxh'] : '0'.$value['Gy0_gxh'];
  587. }
  588. $res['Gd_info'] = $info;
  589. $res['Gy_info'] = $gyInfo;
  590. $this->success('请求成功',$res);
  591. }
  592. /**
  593. * 工单工序生产进程右侧
  594. * @ApiMethod GET
  595. * @params string order
  596. * @params string gxNo
  597. */
  598. public function getOrderProcessRight(){
  599. if (Request::instance()->isGet() == false){
  600. $this->error('非法请求');
  601. }
  602. $params = Request::instance()->param();
  603. if (!isset($params['order']) || empty($params['order'])){
  604. $this->error('参数错误');
  605. }
  606. if (!isset($params['gxNo']) || empty($params['gxNo'])){
  607. $this->error('参数错误');
  608. }
  609. $total = db('设备_产量计酬')->where('sczl_gdbh',$params['order'])->order('sczl_num')->column('distinct(sczl_num)');
  610. $where['sczl_gxh'] = (int)$params['gxNo'];
  611. $where['sczl_gdbh'] = $params['order'];
  612. $process = db('设备_产量计酬')->where($where)->order('sczl_num')->column('distinct(sczl_num)');
  613. $res['total_process'] = $total;
  614. $res['process'] = $process;
  615. $this->success('请求成功',$res);
  616. }
  617. /**
  618. * 核检废品日统计
  619. * @ApiMethod GET
  620. * @params date start_date
  621. * @params date end_date
  622. */
  623. public function getDaysWast()
  624. {
  625. if (Request::instance()->isGet() == false) {
  626. $this->error('非法请求');
  627. }
  628. $params = Request::instance()->param();
  629. if (!isset($params['start_date']) || empty($params['start_date'])) {
  630. $this->error('参数错误');
  631. }
  632. if (!isset($params['end_date']) || empty($params['end_date'])) {
  633. $this->error('参数错误');
  634. }
  635. $where['qczl_rq'] = array('between time', [$params['start_date'], $params['start_date']]);
  636. $field = '
  637. 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,
  638. 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,
  639. 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,
  640. fp_bh1,fp_bh2,fp_bh3,fp_bh4,fp_bh5,fp_bh6,fp_bh7,fp_bh8,fp_bh9,fp_bh10,fp_bh11,fp_bh12,fp_bh13,
  641. rtrim(fp_bz1) as fp_bz1, rtrim(fp_bz2) as fp_bz2, rtrim(fp_bz3) as fp_bz3, rtrim(fp_bz4) as fp_bz4, rtrim(fp_bz5) as fp_bz5, rtrim(fp_bz6) as fp_bz6, rtrim(fp_bz7) as fp_bz7,
  642. rtrim(fp_bz8) as fp_bz8, rtrim(fp_bz9) as fp_bz9, rtrim(fp_bz10) as fp_bz10, rtrim(fp_bz11) as fp_bz11, rtrim(fp_bz12) as fp_bz12, rtrim(fp_bz13) as fp_bz13,
  643. qczl_rq
  644. ';
  645. $data = db('db_qczl')
  646. ->where($where)
  647. ->where(function ($query) {
  648. for ($i = 1; $i <= 13; $i++) {
  649. $query->whereOr("fp_lb$i", 'like', '%K%','AND',"fp_sl$i",'>',0);
  650. }
  651. })
  652. ->field($field)->select();
  653. $list = [];
  654. $j = 0;
  655. foreach ($data as $entry) {
  656. for ($i = 1; $i <= 13; $i++) {
  657. $labelKey = "fp_lb" . $i;
  658. $slKey = "fp_sl" . $i;
  659. $bhKey = "fp_bh" . $i;
  660. $bzKey = "fp_bz" . $i;
  661. if (!empty($entry[$labelKey])) {
  662. if ((substr($entry[$labelKey],0,3) == 'K02' || substr($entry[$labelKey],0,3) == 'K01') && $entry[$slKey] != '0'){
  663. $list[$j]['fp_lb'] = $entry[$labelKey];
  664. $list[$j]['fp_sl'] = $entry[$slKey];
  665. $list[$j]['fp_bh'] = $entry[$bhKey];
  666. $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)');
  667. $list[$j]['fp_name'] = empty($name) ? '计时工' : $name;
  668. $list[$j]['fp_bz'] = $entry[$bzKey];
  669. $list[$j]['qczl_rq'] = $entry['qczl_rq'];
  670. $j++;
  671. }
  672. }
  673. }
  674. }
  675. $resultArray = array();
  676. foreach ($list as $item) {
  677. $found = false;
  678. foreach ($resultArray as &$resultItem) {
  679. if ($item["fp_lb"] === $resultItem["fp_lb"] && $item["fp_bh"] === $resultItem["fp_bh"]) {
  680. $resultItem["fp_sl"] += (int)$item["fp_sl"];
  681. $found = true;
  682. break;
  683. }
  684. }
  685. if (!$found) {
  686. $resultArray[] = $item;
  687. }
  688. }
  689. // 使用usort进行排序
  690. usort($resultArray, function($a, $b) {
  691. // First, sort by fp_lb (K01/K02)
  692. $compareLb = strcmp($a['fp_lb'], $b['fp_lb']);
  693. if ($compareLb !== 0) {
  694. return $compareLb;
  695. }
  696. // If fp_lb is the same, prioritize B班 over A班
  697. $compareBz = strcmp($a['fp_bz'], $b['fp_bz']);
  698. if ($compareBz !== 0) {
  699. return (trim($a['fp_bz']) === 'B班') ? -1 : 1;
  700. }
  701. // If fp_bz is the same, sort by fp_bh
  702. $compareBh = strcmp($a['fp_bh'], $b['fp_bh']);
  703. return $compareBh;
  704. });
  705. $this->success('请求成功',$resultArray);
  706. }
  707. /**
  708. * 月度核检废品责任人统计
  709. * @ApiMethod GET
  710. * @params string date
  711. */
  712. public function getMonthPeopleTotal(){
  713. if (Request::instance()->isGet() == false) {
  714. $this->error('非法请求');
  715. }
  716. $params = Request::instance()->param();
  717. if (!isset($params['date']) || empty($params['date'])) {
  718. $this->error('参数错误');
  719. }
  720. }
  721. /**
  722. * 工单质检废品统计
  723. * @ApiMethod GET
  724. * @params string order
  725. */
  726. public function getOrderWasteTotal(){
  727. if (Request::instance()->isGet() == false) {
  728. $this->error('非法请求');
  729. }
  730. $params = Request::instance()->param();
  731. if (!isset($params['order']) || empty($params['order'])) {
  732. $this->error('参数错误');
  733. }
  734. $field = '
  735. rtrim(a.fp_lb1) as fp_lb1,rtrim(a.fp_lb2) as fp_lb2,rtrim(a.fp_lb3) as fp_lb3,rtrim(a.fp_lb4) as fp_lb4,rtrim(a.fp_lb5) as fp_lb5,rtrim(a.fp_lb6) as fp_lb6,rtrim(a.fp_lb7) as fp_lb7,
  736. rtrim(a.fp_lb8) as fp_lb8,rtrim(a.fp_lb9) as fp_lb9,rtrim(a.fp_lb10) as fp_lb10,rtrim(a.fp_lb11) as fp_lb11,rtrim(a.fp_lb12) as fp_lb12,rtrim(a.fp_lb13) as fp_lb13,
  737. a.fp_sl1,a.fp_sl2,a.fp_sl3,a.fp_sl4,a.fp_sl5,a.fp_sl6,a.fp_sl7,a.fp_sl8,a.fp_sl9,a.fp_sl10,a.fp_sl11,a.fp_sl12,a.fp_sl13,
  738. a.fp_bh1,a.fp_bh2,a.fp_bh3,a.fp_bh4,a.fp_bh5,a.fp_bh6,a.fp_bh7,a.fp_bh8,a.fp_bh9,a.fp_bh10,a.fp_bh11,a.fp_bh12,a.fp_bh13,
  739. rtrim(a.fp_gxmc1) as fp_gxmc1, rtrim(a.fp_gxmc2) as fp_gxmc2, rtrim(a.fp_gxmc3) as fp_gxmc3, rtrim(a.fp_gxmc4) as fp_gxmc4, rtrim(a.fp_gxmc5) as fp_gxmc5, rtrim(a.fp_gxmc6) as fp_gxmc6,
  740. rtrim(a.fp_gxmc7) as fp_gxmc7,rtrim(a.fp_gxmc8) as fp_gxmc8, rtrim(a.fp_gxmc9) as fp_gxmc9, rtrim(a.fp_gxmc10) as fp_gxmc10, rtrim(a.fp_gxmc11) as fp_gxmc11, rtrim(a.fp_gxmc12) as fp_gxmc12,
  741. rtrim(a.fp_gxmc13) as fp_gxmc13,a.qczl_num,a.qczl_yjno,rtrim(b.成品代号) as product_code,rtrim(b.成品名称) as product_name,b.订单数量,rtrim(b.计量单位) as 计量单位,b.实际投料,b.交货日期,
  742. c.yj_ls,d.jjcp_sl,d.jjcp_sj
  743. ';
  744. $where['a.qczl_gdbh'] = $params['order'];
  745. $where['b.行号'] = 1;
  746. $data = db('db_qczl')->alias('a')
  747. ->join('工单_基本资料 b','a.qczl_gdbh = b.Gd_gdbh','left')
  748. ->join('工单_印件资料 c','a.qczl_gdbh = c.Yj_Gdbh','left')
  749. ->join('成品入仓 d','a.qczl_gdbh = d.jjcp_gdbh','left')
  750. ->where($where)
  751. ->field($field)->select();
  752. $list = [];
  753. $j = 0;
  754. foreach ($data as $entry) {
  755. for ($i = 1; $i <= 13; $i++) {
  756. $labelKey = "fp_lb" . $i;
  757. $slKey = "fp_sl" . $i;
  758. $bhKey = "fp_bh" . $i;
  759. $gxhKey = "fp_gxmc". $i;
  760. if (!empty($entry[$labelKey]) && $entry[$slKey] > 0) {
  761. $list[$j]['fp_lb'] = $entry[$labelKey];
  762. $list[$j]['fp_sl'] = $entry[$slKey];
  763. $list[$j]['fp_bh'] = $entry[$bhKey];
  764. $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)');
  765. $list[$j]['fp_name'] = $name;
  766. $list[$j]['fp_gxh'] = empty(substr($entry[$gxhKey],0,2)) ? "0" : substr($entry[$gxhKey],0,2);
  767. $list[$j]['qczl_num'] = $entry['qczl_num'];
  768. $list[$j]['qczl_yjno'] = $entry['qczl_yjno'];
  769. $list[$j]['product_code'] = $entry['product_code'];
  770. $list[$j]['product_name'] = $entry['product_name'];
  771. $list[$j]['订单数量'] = $entry['订单数量'];
  772. $list[$j]['计量单位'] = $entry['计量单位'];
  773. $list[$j]['交货日期'] = substr($entry['交货日期'],0,10);
  774. $list[$j]['yj_ls'] = $entry['yj_ls'];
  775. $list[$j]['jjcp_sl'] = $entry['jjcp_sl'];
  776. $list[$j]['jjcp_sj'] = substr($entry['jjcp_sj'],0,10);
  777. $j++;
  778. }
  779. }
  780. }
  781. $summedData = [];
  782. foreach ($list as $item) {
  783. $key = $item['qczl_num'] . $item['fp_lb'];
  784. if (!isset($summedData[$key])) {
  785. $summedData[$key] = $item;
  786. } else {
  787. $summedData[$key]['fp_sl'] += $item['fp_sl'];
  788. }
  789. }
  790. $fpGxhColumn = array_column($summedData, 'fp_gxh');
  791. $qczlNumColumn = array_column($summedData, 'qczl_num');
  792. $fpLbColumn = array_column($summedData, 'fp_lb');
  793. array_multisort($fpGxhColumn, SORT_ASC, $qczlNumColumn, SORT_ASC, $fpLbColumn, SORT_ASC, $summedData);
  794. $summedData = array_values($summedData);
  795. $this->success('请求成功',$summedData);
  796. }
  797. }