WorkOrderVerification.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use \think\Request;
  5. use \think\Db;
  6. use \think\cache;
  7. /**
  8. * 工单核验单维护接口
  9. */
  10. class WorkOrderVerification extends Api
  11. {
  12. protected $noNeedLogin = ['*'];
  13. protected $noNeedRight = ['*'];
  14. /**
  15. * 首页
  16. *
  17. */
  18. public function index()
  19. {
  20. $this->success('请求成功');
  21. }
  22. /**
  23. * 获取工单核验单侧边栏
  24. * @ApiMethod (GET)
  25. */
  26. public function getTab()
  27. {
  28. //get请求
  29. if(!$this->request->isGet()){
  30. $this->error('请求方式错误');
  31. }
  32. $is_have_cache = Cache::get('WorkOrderVerification/getTab');
  33. if ($is_have_cache === false){
  34. $rows = db()->table('db_qczl')
  35. ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
  36. ->group('date')
  37. ->order('UniqId desc')
  38. ->limit(30)
  39. ->select();
  40. $arr = db()->table('db_qczl')
  41. ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(sys_id) as count')
  42. ->where('sys_rq','>=',$rows[count($rows)-1]['date'])
  43. ->group('date, sys_id')
  44. ->select();
  45. foreach($rows as $key=>$value){
  46. $rows[$key]['sys'] = [];
  47. foreach($arr as $k=>$v){
  48. if($value['date'] == $v['date']){
  49. unset($v['date']);
  50. array_push($rows[$key]['sys'],$v);
  51. unset($arr[$k]);
  52. }
  53. }
  54. $rows[$key]['date'] = str_replace('-', '.', $rows[$key]['date']);
  55. }
  56. Cache::set('WorkOrderVerification/getTab',$rows,86400);
  57. }else{
  58. $rows = Cache::get('WorkOrderVerification/getTab');
  59. }
  60. $this->success('成功',$rows);
  61. }
  62. /**
  63. * 获取工单核验单列表
  64. * @ApiMethod (GET)
  65. * @param string $date 时间
  66. * @param string $sys_id 用户
  67. */
  68. public function getList()
  69. {
  70. //get请求
  71. if(!$this->request->isGet()){
  72. $this->error('请求方式错误');
  73. }
  74. $req = $this->request->param();
  75. $page = 1;
  76. $limit = 15;
  77. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  78. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  79. $where = [];
  80. if (isset($req['date']) && !empty($req['date'])){
  81. $where['sys_rq'] = ['LIKE',$req['date'].'%'];
  82. }
  83. if (isset($req['sys_id']) && !empty($req['sys_id'])) $where['sys_id'] = ['LIKE',$req['sys_id'].'%'];
  84. if (isset($req['order']) && !empty($req['order'])) $where['qczl_gdbh'] = $req['order'];
  85. $rows = db()->table('db_qczl')
  86. ->field('qczl_gdbh, qczl_yjno, LEFT(qczl_rq, 10) as qczl_rq, qczl_num, rtrim(qczl_NumDesc) as qczl_NumDesc, qczl_fp,
  87. 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,
  88. 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,
  89. rtrim(sys_id) as sys_id,UniqId')
  90. ->where($where)
  91. ->order('UniqId desc')
  92. ->cache(true,300)
  93. ->page($page,$limit)
  94. ->select();
  95. $total = db()->table('db_qczl')->where($where)->count();
  96. $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
  97. foreach ($rows as $key=>$value){
  98. $rows[$key]['Gd_cpmc'] = array_key_exists($value['qczl_gdbh'],$gd) ? sprintf("%02d", $value['qczl_yjno']).'-'.trim($gd[$value['qczl_gdbh']]) : '';
  99. for ($i=1;$i<=17;$i++){
  100. if ($value['fp_sl'.$i]==0){
  101. $rows[$key]['sl_lb'.$i] = '';
  102. }else{
  103. $rows[$key]['sl_lb'.$i] = trim($value['fp_sl'.$i].'-->'.$value['fp_lb'.$i]);
  104. }
  105. unset($rows[$key]['fp_sl'.$i]);
  106. unset($rows[$key]['fp_lb'.$i]);
  107. }
  108. }
  109. $data = [
  110. 'total' => $total,
  111. 'rows' => $rows,
  112. ];
  113. $this->success('成功',$data);
  114. }
  115. /**
  116. * 获取工单核验单信息
  117. * @ApiMethod (GET)
  118. * @param string $UniqId UniqId
  119. */
  120. public function getInfo()
  121. {
  122. //get请求
  123. if(!$this->request->isGet()){
  124. $this->error('请求方式错误');
  125. }
  126. $req = $this->request->param();
  127. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  128. $UniqId = $req['UniqId'];
  129. }else{
  130. $this->error('参数错误');
  131. }
  132. $rows = db()->table('db_qczl')->alias('d')
  133. ->field('d.*, ')
  134. ->join('工单_基本资料 g', 'd.')
  135. ->where('d.UniqId',$UniqId)
  136. ->select();
  137. $this->success('成功',$rows);
  138. }
  139. /**
  140. * 获取单个工单核检单信息
  141. * @ApiMethod GET
  142. * @params string UniqId
  143. */
  144. public function getOneWorkOrder(){
  145. if (Request::instance()->isGet() == false){
  146. $this->error('非法请求');
  147. }
  148. $params = Request::instance()->param();
  149. if (!isset($params['UniqId']) || empty($params['UniqId'])){
  150. $this->error('参数错误');
  151. }
  152. $field = 'qczl_gdbh,qczl_Pygd,qczl_yjno,qczl_gxh,qczl_gxmc,qczl_type,qczl_rq,qczl_num,qczl_fp,
  153. qczl_NumDesc,qczl_NumDesc1,qczl_NumDesc2,qczl_NumDesc3,qczl_NumDesc4,qczl_NumDesc5,qczl_NumDesc6,qczl_NumDesc7,qczl_NumDesc8,
  154. 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,
  155. 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
  156. 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,
  157. 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,
  158. 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,
  159. sys_id,rtrim(sys_rq) as sys_rq,UniqId';
  160. $list = db('db_qczl')->where('UniqId',$params['UniqId'])->field($field)->find();
  161. $list['fp_name1'] = '';
  162. if (!empty($list['fp_bh1'])){
  163. $list['fp_name1'] = db('人事_基本资料')->where('员工编号',$list['fp_bh1'])->value('rtrim(员工姓名)');
  164. }
  165. $list['fp_name2'] = '';
  166. if (!empty($list['fp_bh2'])){
  167. $list['fp_name2'] = db('人事_基本资料')->where('员工编号',$list['fp_bh2'])->value('rtrim(员工姓名)');
  168. }
  169. $list['fp_name3'] = '';
  170. if (!empty($list['fp_bh3'])){
  171. $list['fp_name3'] = db('人事_基本资料')->where('员工编号',$list['fp_bh3'])->value('rtrim(员工姓名)');
  172. }
  173. $list['fp_name4'] = '';
  174. if (!empty($list['fp_bh4'])){
  175. $list['fp_name4'] = db('人事_基本资料')->where('员工编号',$list['fp_bh4'])->value('rtrim(员工姓名)');
  176. }
  177. $list['fp_name5'] = '';
  178. if (!empty($list['fp_bh5'])){
  179. $list['fp_name5'] = db('人事_基本资料')->where('员工编号',$list['fp_bh5'])->value('rtrim(员工姓名)');
  180. }
  181. $list['fp_name6'] = '';
  182. if (!empty($list['fp_bh6'])){
  183. $list['fp_name6'] = db('人事_基本资料')->where('员工编号',$list['fp_bh6'])->value('rtrim(员工姓名)');
  184. }
  185. $list['fp_name7'] = '';
  186. if (!empty($list['fp_bh7'])){
  187. $list['fp_name7'] = db('人事_基本资料')->where('员工编号',$list['fp_bh7'])->value('rtrim(员工姓名)');
  188. }
  189. $list['fp_name8'] = '';
  190. if (!empty($list['fp_bh8'])){
  191. $list['fp_name8'] = db('人事_基本资料')->where('员工编号',$list['fp_bh8'])->value('rtrim(员工姓名)');
  192. }
  193. $list['fp_name9'] = '';
  194. if (!empty($list['fp_bh9'])){
  195. $list['fp_name9'] = db('人事_基本资料')->where('员工编号',$list['fp_bh9'])->value('rtrim(员工姓名)');
  196. }
  197. $list['fp_name10'] = '';
  198. if (!empty($list['fp_bh10'])){
  199. $list['fp_name10'] = db('人事_基本资料')->where('员工编号',$list['fp_bh10'])->value('rtrim(员工姓名)');
  200. }
  201. $list['fp_name11'] = '';
  202. if (!empty($list['fp_bh11'])){
  203. $list['fp_name11'] = db('人事_基本资料')->where('员工编号',$list['fp_bh11'])->value('rtrim(员工姓名)');
  204. }
  205. $list['fp_name12'] = '';
  206. if (!empty($list['fp_bh12'])){
  207. $list['fp_name12'] = db('人事_基本资料')->where('员工编号',$list['fp_bh12'])->value('rtrim(员工姓名)');
  208. }
  209. $list['fp_name13'] = '';
  210. if (!empty($list['fp_bh13'])){
  211. $list['fp_name13'] = db('人事_基本资料')->where('员工编号',$list['fp_bh13'])->value('rtrim(员工姓名)');
  212. }
  213. $max = db('设备_产量计酬')->where('sczl_gdbh',$list['qczl_gdbh'])->field('MAX(sczl_num) as sczl_num')->find();
  214. $list['total_liucheng'] = $max['sczl_num'];
  215. $this->success('请求成功',$list);
  216. }
  217. /**
  218. * 获取工单基本信息
  219. * @ApiMethod GET
  220. * @params string order
  221. */
  222. public function getOrderInfo(){
  223. if (Request::instance()->isGet() == false){
  224. $this->error('非法请求');
  225. }
  226. $params = Request::instance()->param();
  227. if (!isset($params['order']) || empty($params['order'])){
  228. $this->error('参数错误');
  229. }
  230. $list = db('工单_基本资料')->alias('a')
  231. ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh','left')
  232. ->where('a.Gd_gdbh',$params['order'])
  233. ->where('a.行号',1)
  234. ->field('a.Gd_cpmc,b.yj_Yjno,b.yj_yjmc')
  235. ->find();
  236. $this->success('请求成功',$list);
  237. }
  238. /**
  239. * 获取印件名称及工序
  240. * @ApiMethod GET
  241. * @params string order
  242. * @params string yj_no
  243. */
  244. public function getYjInfo(){
  245. if (Request::instance()->isGet() == false){
  246. $this->error('非法请求');
  247. }
  248. $params = Request::instance()->param();
  249. if (!isset($params['order']) || empty($params['order'])){
  250. $this->error('参数错误');
  251. }
  252. if (!isset($params['yj_no']) || empty($params['yj_no'])){
  253. $this->error('参数错误');
  254. }
  255. $where['Yj_Gdbh'] = $params['order'];
  256. $where['yj_Yjno'] = $params['yj_no'];
  257. $list = db('工单_印件资料')->where($where)->field('yj_yjmc')->find();
  258. $option['Gy0_gdbh'] = $params['order'];
  259. $option['Gy0_yjno'] = $params['yj_no'];
  260. $option['Gy0_site'] = '检验车间';
  261. $option['Gy0_gxmc'] = array('not in',['包装','外发加工','废挑正','成品防护']);
  262. $gxList = db('工单_工艺资料')->where($option)->field('Gy0_gxh,rtrim(Gy0_gxmc) as Gy0_gxmc,rtrim(Add_gxmc) as Add_gxmc')->select();
  263. $max = db('设备_产量计酬')->where('sczl_gdbh',$params['order'])->where('sczl_yjno',$params['yj_no'])->field('MAX(sczl_num) as sczl_num')->value('sczl_num');
  264. $list['gx_data'] = $gxList;
  265. $list['max_num'] = $max;
  266. $this->success('请求成功',$list);
  267. }
  268. /**
  269. * 获取废品分类
  270. * @ApiMethod GET
  271. * @params string search
  272. */
  273. public function getWastInfo(){
  274. if (Request::instance()->isGet() == false){
  275. $this->error('非法请求');
  276. }
  277. $params = Request::instance()->param();
  278. if (!isset($params['search']) || empty($params['search'])){
  279. $this->error('参数错误');
  280. }
  281. $where['分类'] = '废品分类';
  282. $where['名称'] = array('like','%'.$params['search'].'%');
  283. $data = db('erp_常用字典')->where($where)->column('名称');
  284. // 分割字符串并合并相同项
  285. $resultArray = [];
  286. foreach ($data as $item) {
  287. $parts = explode('_', $item);
  288. // 使用第一个部分作为一级键,第二个部分作为二级键
  289. $firstKey = $parts[0];
  290. $secondKey = $parts[1];
  291. $thirdValue = $parts[2];
  292. $resultArray[$firstKey][$secondKey][] = $thirdValue;
  293. }
  294. // 对废品分类下的数组进行升序排序
  295. if (isset($resultArray['data']['废品分类'])) {
  296. foreach ($resultArray['data']['废品分类'] as &$category) {
  297. // 判断是关联数组(单凹等)还是索引数组(分切等)
  298. if (is_array($category) && !empty($category) && is_array(current($category))) {
  299. foreach ($category as &$subCategory) {
  300. ksort($subCategory);
  301. }
  302. } else {
  303. ksort($category);
  304. }
  305. }
  306. }
  307. $this->success('请求成功',$resultArray);
  308. }
  309. /**
  310. *获取工序及责任组长
  311. * @ApiMethod GET
  312. * @params string type
  313. * @params string order
  314. */
  315. public function getGxAndLeader(){
  316. if (Request::instance()->isGet() == false){
  317. $this->error('非法请求');
  318. }
  319. $params = Request::instance()->param();
  320. if (!isset($params['type']) || empty($params['type'])){
  321. $this->error('参数错误');
  322. }
  323. if (!isset($params['order']) || empty($params['order'])){
  324. $this->error('参数错误');
  325. }
  326. $type = trim($params['type']);
  327. $waste = db('erp_常用字典')->where('名称','like','%'.$type.'%')->find();
  328. if (empty($waste)){
  329. $this->error('未查询到废品分类');
  330. }
  331. $wasteType = explode('_',substr($waste['名称'],0,-1));
  332. $searchArr = explode('-',$wasteType[1]);
  333. $search = substr($searchArr[1],0,6);
  334. $where['a.sczl_gdbh'] = $params['order'];
  335. $where['a.sczl_type'] = array('like','%'.$search.'%');
  336. $list = db('设备_产量计酬')->alias('a')
  337. ->join('人事_基本资料 b','a.sczl_bh1 = b.员工编号','left')
  338. ->where($where)->cache(true,86400)->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
  339. ->select();
  340. $count = count($list);
  341. $list[$count]['sczl_gxmc'] = '99-外发加工';
  342. $list[$count]['sczl_bzdh'] = 'A班';
  343. $list[$count]['sczl_jtbh'] = '';
  344. $list[$count]['sczl_bh1'] = '000000';
  345. $list[$count]['name'] = '计时工';
  346. $this->success('请求成功',$list);
  347. }
  348. /**
  349. * 修改工单核检单
  350. * @ApiMethod POST
  351. * @params array data
  352. */
  353. public function edit(){
  354. if (Request::instance()->isPost() == false){
  355. $this->error('非法请求');
  356. }
  357. $params = Request::instance()->post();
  358. if (!isset($params['UniqId'])){
  359. $this->error('参数不能为空');
  360. }
  361. $id = $params['UniqId'];
  362. unset($params['UniqId']);
  363. $sql = db('db_qczl')->where('UniqId',$id)->fetchSql(true)->update($params);
  364. $res = Db::query($sql);
  365. if ($res !== 0){
  366. $this->success('更新成功');
  367. }else{
  368. $this->error('更新失败');
  369. }
  370. }
  371. /**
  372. * 新增工单核检单
  373. * @ApiMethod POST
  374. * @params array data
  375. */
  376. public function add(){
  377. if (Request::instance()->isPost() == false){
  378. $this->error('非法请求');
  379. }
  380. $params = Request::instance()->post();
  381. $UniqId = db('db_qczl')->order('UniqId desc')->value('UniqId');
  382. if ($UniqId < 10000000){
  383. $UniqId = 10000000;
  384. }else{
  385. $UniqId = $UniqId + 1;
  386. }
  387. $params['UniqId'] = $UniqId;
  388. $params['sys_rq'] = date('Y-m-d H:i:s');
  389. $res = \db('db_qczl')->insert($params);
  390. if ($res !== false){
  391. $this->success('新增成功');
  392. }else{
  393. $this->error('新增失败');
  394. }
  395. }
  396. /**
  397. * 工单核检废品分布
  398. * @ApiMethod GET
  399. * @params string order
  400. */
  401. public function wasteDistribution(){
  402. if (Request::instance()->isGet() == false){
  403. $this->error('非法请求');
  404. }
  405. $params = Request::instance()->param();
  406. if (!isset($params['order']) || empty($params['order'])){
  407. $this->error('参数错误');
  408. }
  409. $field = '
  410. 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,
  411. 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,
  412. 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
  413. ';
  414. $data = db('db_qczl')->name('db_qczl')->where('qczl_gdbh',$params['order'])->field($field)->select();
  415. if (empty($data)){
  416. $this->error('暂无废品数据');
  417. }
  418. // 用于存储废品类别和对应废品数量的数组
  419. $categories = array();
  420. // 循环遍历原始数组
  421. foreach ($data as $item) {
  422. // 提取废品类别和对应废品数量
  423. foreach ($item as $key => $value) {
  424. if (strpos($key, "fp_lb") === 0) {
  425. $categoryKey = $key;
  426. $quantityKey = str_replace("fp_lb", "fp_sl", $key);
  427. $quantityValue = $item[$quantityKey];
  428. if (!isset($categories[$value])) {
  429. $categories[$value] = 0;
  430. }
  431. $categories[$value] += (int)$quantityValue;
  432. }
  433. }
  434. }
  435. ksort($categories);
  436. $wasteTotal = db('db_qczl')->where('qczl_gdbh',$params['order'])->sum('qczl_fp');
  437. if (empty($wasteTotal)){
  438. $wasteTotal = 0;
  439. }
  440. $where['a.Gd_gdbh'] = $params['order'];
  441. $where['a.行号'] = 1;
  442. $gdInfo = db('工单_基本资料')->alias('a')
  443. ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh','left')
  444. ->where($where)->field('a.Gd_gdbh,a.实际投料,b.yj_Yjno,b.yj_yjmc')->find();
  445. $gdInfo['yj_Yjno'] = $gdInfo['yj_Yjno'] > 10 ? $gdInfo['yj_Yjno']:'0'.$gdInfo['yj_Yjno'];
  446. $gdInfo['实际投料'] = (int)($gdInfo['实际投料'] * 10000);
  447. $gdInfo['wasteTotal'] = $wasteTotal;
  448. $finishNum = db('成品入仓')->where('jjcp_gdbh',$params['order'])->sum('jjcp_sl');
  449. $gdInfo['passRate'] = '';
  450. if (!empty($finishNum)){
  451. $gdInfo['passRate'] = number_format((int)$finishNum/$gdInfo['实际投料']*100,2).'%';
  452. }
  453. //左侧废品数据
  454. $wasteData = array();
  455. $i = 0;
  456. foreach ($categories as $key=>$value){
  457. if ($value != 0){
  458. $wasteData[$i]['type'] = $key;
  459. $wasteData[$i]['num'] = $value;
  460. $wasteData[$i]['lossesRate'] = number_format($value/$gdInfo['实际投料']*100,4).'%';
  461. $wasteData[$i]['wasteRate'] = number_format($value/$wasteTotal*100,2).'%';
  462. $i++;
  463. }
  464. }
  465. // 按首字母相同的键将值相加
  466. $newArray = array();
  467. foreach ($categories as $key => $value) {
  468. $firstLetter = strtoupper(substr($key, 0, 1)); // 获取首字母并转换为大写
  469. if (!isset($newArray[$firstLetter])) {
  470. $newArray[$firstLetter] = 0;
  471. }
  472. $newArray[$firstLetter] += $value;
  473. }
  474. // 去掉值为零的项
  475. $newArray = array_filter($newArray, function($value) {
  476. return $value !== 0;
  477. });
  478. //右侧废品数据
  479. $rightData = array();
  480. $i = 0;
  481. $name = array();
  482. foreach ($newArray as $key=>$value){
  483. $item = db('erp_常用字典')->where('名称','like','%'.$key.'%')->value('名称');
  484. $item = explode('_',substr($item,0,-1));
  485. $rightData[$i]['type'] = $item[1];
  486. $rightData[$i]['rate'] = number_format($value/$wasteTotal*100,0).'%';
  487. $name[$i] = $item[1];
  488. $i++;
  489. }
  490. $gdInfo['wasteData'] = $wasteData;
  491. $gdInfo['rightData'] = $rightData;
  492. $gdInfo['rightTitle'] = $name;
  493. $this->success('请求成功',$gdInfo);
  494. }
  495. /**
  496. * 获取工单工序状态
  497. * @ApiMethod GET
  498. * @params string order
  499. * 计划产量计算方式:上个工序计划产量-(基础损耗+损耗率*上个工序计划产量)*损耗系数*计损色数)
  500. * lastNum - (Gy0_Rate0 + Gy0_Rate1 * lastNum )* 损耗系数(Gy0_Rate3) * Gy0_Ms
  501. */
  502. public function getOrderDate(){
  503. if (Request::instance()->isGet() == false){
  504. $this->error('非法请求');
  505. }
  506. $params = Request::instance()->param();
  507. if (!isset($params['order']) || empty($params['order'])){
  508. $this->error('参数错误');
  509. }
  510. $where['a.Gy0_gdbh'] = $params['order'];
  511. $where['a.Gy0_sbbh'] = array('neq',' ');
  512. $productNum = db('工单_基本资料')->where('Gd_gdbh',$params['order'])->value('计划投料');
  513. $gyData = db('工单_工艺资料')->alias('a')
  514. ->join('设备_产量计酬 b','a.Gy0_gdbh = b.sczl_gdbh and a.Gy0_gxh = b.sczl_gxh','left')
  515. ->where($where)
  516. ->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,
  517. a.UniqId,sum(b.sczl_cl) as cl')
  518. ->group('a.Gy0_gxh')
  519. ->select();
  520. $lastNum = $productNum;
  521. $res = [];
  522. foreach ($gyData as $key=> $process) {
  523. $res[$key]['UniqId'] = $process['UniqId'];
  524. $res[$key]['Gy0_yjno'] = $process['Gy0_yjno'] > 10 ? $process['Gy0_yjno'] : '0'.$process['Gy0_yjno'];
  525. $res[$key]['Gy0_gxh'] = $process['Gy0_gxh'] > 10 ? $process['Gy0_gxh'] : '0'.$process['Gy0_gxh'];
  526. $res[$key]['Gy0_gxmc'] = $process['Gy0_gxmc'];
  527. $res[$key]['Gy0_sbbh'] = rtrim($process['Gy0_sbbh']);
  528. $res[$key]['PD_WG'] = $process['PD_WG'];
  529. $res[$key]['finish'] = empty($process['cl']) ? 0: (int)$process['cl'];
  530. // 计算工序计划产量
  531. if ($process["Gy0_gxh"] == "1") {
  532. // 第一道工序直接使用初始计划产量
  533. $Num = $lastNum;
  534. } else {
  535. $Gy0_Ms = $gyData[$key-1]['Gy0_Ms'];
  536. $Gy0_Rate0 = $gyData[$key-1]['Gy0_Rate0'];
  537. $Gy0_Rate1 = $gyData[$key-1]['Gy0_Rate1'];
  538. $Gy0_Rate3 = $gyData[$key-1]['Gy0_Rate3'];
  539. // 大于第一道工序,使用上一道工序的计划产量
  540. // 根据公式计算工序计划产量
  541. if ($Gy0_Ms != "0.00") {
  542. $Num = $lastNum - ($Gy0_Rate0 + $Gy0_Rate1 * $lastNum) * $Gy0_Rate3 * $Gy0_Ms;
  543. } else {
  544. $Num = $lastNum - ($Gy0_Rate0 + $Gy0_Rate1 * $lastNum) * $Gy0_Rate3;
  545. }
  546. }
  547. if (trim($process['Gy0_SITE']) == '检验车间'){
  548. $res[$key]['plan'] = (int)$process['Gy0_计划接货数'];
  549. }else{
  550. $res[$key]['plan'] = (int)round($Num);
  551. }
  552. $finish_rate = $res[$key]['finish']/$res[$key]['plan'];
  553. $res[$key]['finish_rate'] = '';
  554. if ($finish_rate != 0){
  555. $res[$key]['finish_rate'] = number_format($finish_rate*100,2).'%';
  556. }
  557. // 更新 $lastNum 为当前工序的计划产量
  558. $lastNum = $Num;
  559. }
  560. $this->success('请求成功',$res);
  561. }
  562. /**
  563. * 工单工序状态更正
  564. * @ApiMethod POST
  565. * @params string UniqId
  566. * @params string date
  567. */
  568. public function editOrderFinishDate(){
  569. if (Request::instance()->isPost() == false){
  570. $this->error('非法请求');
  571. }
  572. $params = Request::instance()->post();
  573. if (!isset($params['UniqId']) || !isset($params['date'])){
  574. $this->error('参数错误');
  575. }
  576. if (empty($params['UniqId'])){
  577. $this->error('参数不能为空');
  578. }
  579. if (empty($params['date'])){
  580. $params['date'] = '1900-01-01 00:00:00';
  581. }
  582. $res = db('工单_工艺资料')->where('UniqId',$params['UniqId'])->setField('PD_WG',$params['date']);
  583. if ($res != false){
  584. $this->success('更新成功');
  585. }else{
  586. $this->error('更新失败');
  587. }
  588. }
  589. /**
  590. * 工单工序生产进程菜单栏
  591. * @ApiMethod GET
  592. * @params string order
  593. */
  594. public function getOrderProcessLeft(){
  595. if (Request::instance()->isGet() == false){
  596. $this->error('非法请求');
  597. }
  598. $params = Request::instance()->param();
  599. if (!isset($params['order']) || empty($params['order'])){
  600. $this->error('参数错误');
  601. }
  602. $where['Gd_gdbh'] = $params['order'];
  603. $where['行号'] = 1;
  604. //工单基本资料
  605. $info = db('工单_基本资料')->where($where)->field('rtrim(成品代号) as code,rtrim(成品名称) as name')->find();
  606. //工艺资料
  607. $option['Gy0_gdbh'] = $params['order'];
  608. $gyInfo = db('工单_工艺资料')
  609. ->where($option)
  610. ->where(function ($query) {
  611. $query->where('Gy0_sbbh', '<>', '')
  612. ->whereOr('Gy0_gxmc', '核检')
  613. ->whereOr('Gy0_gxmc', '成品防护');
  614. })
  615. ->field('Gy0_yjno,Gy0_gxh')
  616. ->select();
  617. foreach ($gyInfo as $key=>$value){
  618. $gyInfo[$key]['Gy0_yjno'] = $value['Gy0_yjno'] > 10 ? $value['Gy0_yjno'] : '0'.$value['Gy0_yjno'];
  619. $gyInfo[$key]['Gy0_gxh'] = $value['Gy0_gxh'] > 10 ? $value['Gy0_gxh'] : '0'.$value['Gy0_gxh'];
  620. }
  621. $res['Gd_info'] = $info;
  622. $res['Gy_info'] = $gyInfo;
  623. $this->success('请求成功',$res);
  624. }
  625. /**
  626. * 工单工序生产进程右侧
  627. * @ApiMethod GET
  628. * @params string order
  629. * @params string gxNo
  630. */
  631. public function getOrderProcessRight(){
  632. if (Request::instance()->isGet() == false){
  633. $this->error('非法请求');
  634. }
  635. $params = Request::instance()->param();
  636. if (!isset($params['order']) || empty($params['order'])){
  637. $this->error('参数错误');
  638. }
  639. if (!isset($params['gxNo']) || empty($params['gxNo'])){
  640. $this->error('参数错误');
  641. }
  642. $total = db('设备_产量计酬')->where('sczl_gdbh',$params['order'])->order('sczl_num')->column('distinct(sczl_num)');
  643. $where['sczl_gxh'] = (int)$params['gxNo'];
  644. $where['sczl_gdbh'] = $params['order'];
  645. $process = db('设备_产量计酬')->where($where)->order('sczl_num')->column('distinct(sczl_num)');
  646. $res['total_process'] = $total;
  647. $res['process'] = $process;
  648. $this->success('请求成功',$res);
  649. }
  650. /**
  651. * 核检废品日统计
  652. * @ApiMethod GET
  653. * @params date start_date
  654. * @params date end_date
  655. */
  656. public function getDaysWast()
  657. {
  658. if (Request::instance()->isGet() == false) {
  659. $this->error('非法请求');
  660. }
  661. $params = Request::instance()->param();
  662. if (!isset($params['start_date']) || empty($params['start_date'])) {
  663. $this->error('参数错误');
  664. }
  665. if (!isset($params['end_date']) || empty($params['end_date'])) {
  666. $this->error('参数错误');
  667. }
  668. $where['qczl_rq'] = array('between time', [$params['start_date'], $params['end_date']]);
  669. $field = '
  670. 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,
  671. 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,
  672. 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,
  673. 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,
  674. 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,
  675. 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,
  676. qczl_rq
  677. ';
  678. $resultArray = array();
  679. $key = 'getDaysWast'.$params['start_date'].'/'.$params['end_date'];
  680. $is_have_cache = Cache::has($key);
  681. if ($is_have_cache === false){
  682. $data = db('db_qczl')
  683. ->where($where)
  684. ->where(function ($query) {
  685. for ($i = 1; $i <= 13; $i++) {
  686. $query->whereOr("fp_lb$i", 'like', '%K%','AND',"fp_sl$i",'>',0);
  687. }
  688. })
  689. ->field($field)->select();
  690. $list = [];
  691. $j = 0;
  692. foreach ($data as $entry) {
  693. for ($i = 1; $i <= 13; $i++) {
  694. $labelKey = "fp_lb" . $i;
  695. $slKey = "fp_sl" . $i;
  696. $bhKey = "fp_bh" . $i;
  697. $bzKey = "fp_bz" . $i;
  698. if (!empty($entry[$labelKey])) {
  699. if ((substr($entry[$labelKey],0,3) == 'K02' || substr($entry[$labelKey],0,3) == 'K01') && $entry[$slKey] != '0'){
  700. $list[$j]['fp_lb'] = $entry[$labelKey];
  701. $list[$j]['fp_sl'] = $entry[$slKey];
  702. $list[$j]['fp_bh'] = $entry[$bhKey];
  703. $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)');
  704. $list[$j]['fp_name'] = empty($name) ? '计时工' : $name;
  705. $list[$j]['fp_bz'] = $entry[$bzKey];
  706. $list[$j]['qczl_rq'] = $entry['qczl_rq'];
  707. $j++;
  708. }
  709. }
  710. }
  711. }
  712. foreach ($list as $item) {
  713. $found = false;
  714. foreach ($resultArray as &$resultItem) {
  715. if ($item["fp_lb"] === $resultItem["fp_lb"] && $item["fp_bh"] === $resultItem["fp_bh"]) {
  716. $resultItem["fp_sl"] += (int)$item["fp_sl"];
  717. $found = true;
  718. break;
  719. }
  720. }
  721. if (!$found) {
  722. $resultArray[] = $item;
  723. }
  724. }
  725. // 使用usort进行排序
  726. usort($resultArray, function($a, $b) {
  727. // First, sort by fp_lb (K01/K02)
  728. $compareLb = strcmp($a['fp_lb'], $b['fp_lb']);
  729. if ($compareLb !== 0) {
  730. return $compareLb;
  731. }
  732. // If fp_lb is the same, prioritize B班 over A班
  733. $compareBz = strcmp($a['fp_bz'], $b['fp_bz']);
  734. if ($compareBz !== 0) {
  735. return (trim($a['fp_bz']) === 'B班') ? -1 : 1;
  736. }
  737. // If fp_bz is the same, sort by fp_bh
  738. $compareBh = strcmp($a['fp_bh'], $b['fp_bh']);
  739. return $compareBh;
  740. });
  741. Cache::set($key,$resultArray,86400);
  742. }else{
  743. $resultArray = Cache::get($key);
  744. }
  745. $this->success('请求成功',$resultArray);
  746. }
  747. /**
  748. * 月度核检废品责任人统计
  749. * @ApiMethod GET
  750. * @params string date
  751. */
  752. public function getMonthPeopleTotal(){
  753. if (Request::instance()->isGet() == false) {
  754. $this->error('非法请求');
  755. }
  756. $params = Request::instance()->param();
  757. if (!isset($params['date']) || empty($params['date'])) {
  758. $this->error('参数错误');
  759. }
  760. }
  761. /**
  762. * 工单质检废品统计
  763. * @ApiMethod GET
  764. * @params string order
  765. */
  766. public function getOrderWasteTotal(){
  767. if (Request::instance()->isGet() == false) {
  768. $this->error('非法请求');
  769. }
  770. $params = Request::instance()->param();
  771. if (!isset($params['order']) || empty($params['order'])) {
  772. $this->error('参数错误');
  773. }
  774. $field = '
  775. 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,
  776. 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,
  777. 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,
  778. 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,
  779. 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,
  780. 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,
  781. 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.交货日期,
  782. c.yj_ls,d.jjcp_sl,d.jjcp_sj
  783. ';
  784. $where['a.qczl_gdbh'] = $params['order'];
  785. $where['b.行号'] = 1;
  786. $data = db('db_qczl')->alias('a')
  787. ->join('工单_基本资料 b','a.qczl_gdbh = b.Gd_gdbh','left')
  788. ->join('工单_印件资料 c','a.qczl_gdbh = c.Yj_Gdbh','left')
  789. ->join('成品入仓 d','a.qczl_gdbh = d.jjcp_gdbh','left')
  790. ->where($where)
  791. ->field($field)->select();
  792. $list = [];
  793. $j = 0;
  794. foreach ($data as $entry) {
  795. for ($i = 1; $i <= 13; $i++) {
  796. $labelKey = "fp_lb" . $i;
  797. $slKey = "fp_sl" . $i;
  798. $bhKey = "fp_bh" . $i;
  799. $gxhKey = "fp_gxmc". $i;
  800. if (!empty($entry[$labelKey]) && $entry[$slKey] > 0) {
  801. $list[$j]['fp_lb'] = $entry[$labelKey];
  802. $list[$j]['fp_sl'] = $entry[$slKey];
  803. $list[$j]['fp_bh'] = $entry[$bhKey];
  804. $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)');
  805. $list[$j]['fp_name'] = $name;
  806. $list[$j]['fp_gxh'] = empty(substr($entry[$gxhKey],0,2)) ? "0" : substr($entry[$gxhKey],0,2);
  807. $list[$j]['qczl_num'] = $entry['qczl_num'];
  808. $list[$j]['qczl_yjno'] = $entry['qczl_yjno'];
  809. $list[$j]['product_code'] = $entry['product_code'];
  810. $list[$j]['product_name'] = $entry['product_name'];
  811. $list[$j]['订单数量'] = $entry['订单数量'];
  812. $list[$j]['计量单位'] = $entry['计量单位'];
  813. $list[$j]['交货日期'] = substr($entry['交货日期'],0,10);
  814. $list[$j]['yj_ls'] = $entry['yj_ls'];
  815. $list[$j]['jjcp_sl'] = $entry['jjcp_sl'];
  816. $list[$j]['jjcp_sj'] = substr($entry['jjcp_sj'],0,10);
  817. $j++;
  818. }
  819. }
  820. }
  821. $summedData = [];
  822. foreach ($list as $item) {
  823. $key = $item['qczl_num'] . $item['fp_lb'];
  824. if (!isset($summedData[$key])) {
  825. $summedData[$key] = $item;
  826. } else {
  827. $summedData[$key]['fp_sl'] += $item['fp_sl'];
  828. }
  829. }
  830. $fpGxhColumn = array_column($summedData, 'fp_gxh');
  831. $qczlNumColumn = array_column($summedData, 'qczl_num');
  832. $fpLbColumn = array_column($summedData, 'fp_lb');
  833. array_multisort($fpGxhColumn, SORT_ASC, $qczlNumColumn, SORT_ASC, $fpLbColumn, SORT_ASC, $summedData);
  834. $summedData = array_values($summedData);
  835. $this->success('请求成功',$summedData);
  836. }
  837. }