WorkOrderVerification.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  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[29]['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 GET
  374. * @params string order
  375. */
  376. public function wasteDistribution(){
  377. if (Request::instance()->isGet() == false){
  378. $this->error('非法请求');
  379. }
  380. $params = Request::instance()->param();
  381. if (!isset($params['order']) || empty($params['order'])){
  382. $this->error('参数错误');
  383. }
  384. $field = '
  385. 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,
  386. 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,
  387. 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
  388. ';
  389. $data = db('db_qczl')->name('db_qczl')->where('qczl_gdbh',$params['order'])->field($field)->select();
  390. if (empty($data)){
  391. $this->error('暂无废品数据');
  392. }
  393. // 用于存储废品类别和对应废品数量的数组
  394. $categories = array();
  395. // 循环遍历原始数组
  396. foreach ($data as $item) {
  397. // 提取废品类别和对应废品数量
  398. foreach ($item as $key => $value) {
  399. if (strpos($key, "fp_lb") === 0) {
  400. $categoryKey = $key;
  401. $quantityKey = str_replace("fp_lb", "fp_sl", $key);
  402. $quantityValue = $item[$quantityKey];
  403. if (!isset($categories[$value])) {
  404. $categories[$value] = 0;
  405. }
  406. $categories[$value] += (int)$quantityValue;
  407. }
  408. }
  409. }
  410. ksort($categories);
  411. $wasteTotal = db('db_qczl')->where('qczl_gdbh',$params['order'])->sum('qczl_fp');
  412. if (empty($wasteTotal)){
  413. $wasteTotal = 0;
  414. }
  415. $where['a.Gd_gdbh'] = $params['order'];
  416. $where['a.行号'] = 1;
  417. $gdInfo = db('工单_基本资料')->alias('a')
  418. ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh','left')
  419. ->where($where)->field('a.Gd_gdbh,a.实际投料,b.yj_Yjno,b.yj_yjmc')->find();
  420. $gdInfo['yj_Yjno'] = $gdInfo['yj_Yjno'] > 10 ? $gdInfo['yj_Yjno']:'0'.$gdInfo['yj_Yjno'];
  421. $gdInfo['实际投料'] = (int)($gdInfo['实际投料'] * 10000);
  422. $gdInfo['wasteTotal'] = $wasteTotal;
  423. $finishNum = db('成品入仓')->where('jjcp_gdbh',$params['order'])->sum('jjcp_sl');
  424. $gdInfo['passRate'] = '';
  425. if (!empty($finishNum)){
  426. $gdInfo['passRate'] = number_format((int)$finishNum/$gdInfo['实际投料']*100,2).'%';
  427. }
  428. //左侧废品数据
  429. $wasteData = array();
  430. $i = 0;
  431. foreach ($categories as $key=>$value){
  432. if ($value != 0){
  433. $wasteData[$i]['type'] = $key;
  434. $wasteData[$i]['num'] = $value;
  435. $wasteData[$i]['lossesRate'] = number_format($value/$gdInfo['实际投料']*100,4).'%';
  436. $wasteData[$i]['wasteRate'] = number_format($value/$wasteTotal*100,2).'%';
  437. $i++;
  438. }
  439. }
  440. // 按首字母相同的键将值相加
  441. $newArray = array();
  442. foreach ($categories as $key => $value) {
  443. $firstLetter = strtoupper(substr($key, 0, 1)); // 获取首字母并转换为大写
  444. if (!isset($newArray[$firstLetter])) {
  445. $newArray[$firstLetter] = 0;
  446. }
  447. $newArray[$firstLetter] += $value;
  448. }
  449. // 去掉值为零的项
  450. $newArray = array_filter($newArray, function($value) {
  451. return $value !== 0;
  452. });
  453. //右侧废品数据
  454. $rightData = array();
  455. $i = 0;
  456. $name = array();
  457. foreach ($newArray as $key=>$value){
  458. $item = db('erp_常用字典')->where('名称','like','%'.$key.'%')->value('名称');
  459. $item = explode('_',substr($item,0,-1));
  460. $rightData[$i]['type'] = $item[1];
  461. $rightData[$i]['rate'] = number_format($value/$wasteTotal*100,0).'%';
  462. $name[$i] = $item[1];
  463. $i++;
  464. }
  465. $gdInfo['wasteData'] = $wasteData;
  466. $gdInfo['rightData'] = $rightData;
  467. $gdInfo['rightTitle'] = $name;
  468. $this->success('请求成功',$gdInfo);
  469. }
  470. /**
  471. * 获取工单工序状态
  472. * @ApiMethod GET
  473. * @params string order
  474. * 计划产量计算方式:上个工序计划产量-(基础损耗+损耗率*上个工序计划产量)*损耗系数*计损色数)
  475. * lastNum - (Gy0_Rate0 + Gy0_Rate1 * lastNum )* 损耗系数(Gy0_Rate3) * Gy0_Ms
  476. */
  477. public function getOrderDate(){
  478. if (Request::instance()->isGet() == false){
  479. $this->error('非法请求');
  480. }
  481. $params = Request::instance()->param();
  482. if (!isset($params['order']) || empty($params['order'])){
  483. $this->error('参数错误');
  484. }
  485. $where['a.Gy0_gdbh'] = $params['order'];
  486. $where['a.Gy0_sbbh'] = array('neq',' ');
  487. $productNum = db('工单_基本资料')->where('Gd_gdbh',$params['order'])->value('计划投料');
  488. $gyData = db('工单_工艺资料')->alias('a')
  489. ->join('设备_产量计酬 b','a.Gy0_gdbh = b.sczl_gdbh and a.Gy0_gxh = b.sczl_gxh','left')
  490. ->where($where)
  491. ->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,
  492. a.UniqId,sum(b.sczl_cl) as cl')
  493. ->group('a.Gy0_gxh')
  494. ->select();
  495. $lastNum = $productNum;
  496. $res = [];
  497. foreach ($gyData as $key=> $process) {
  498. $res[$key]['UniqId'] = $process['UniqId'];
  499. $res[$key]['Gy0_yjno'] = $process['Gy0_yjno'] > 10 ? $process['Gy0_yjno'] : '0'.$process['Gy0_yjno'];
  500. $res[$key]['Gy0_gxh'] = $process['Gy0_gxh'] > 10 ? $process['Gy0_gxh'] : '0'.$process['Gy0_gxh'];
  501. $res[$key]['Gy0_gxmc'] = $process['Gy0_gxmc'];
  502. $res[$key]['Gy0_sbbh'] = rtrim($process['Gy0_sbbh']);
  503. $res[$key]['PD_WG'] = $process['PD_WG'];
  504. $res[$key]['finish'] = empty($process['cl']) ? 0: (int)$process['cl'];
  505. // 计算工序计划产量
  506. if ($process["Gy0_gxh"] == "1") {
  507. // 第一道工序直接使用初始计划产量
  508. $Num = $lastNum;
  509. } else {
  510. $Gy0_Ms = $gyData[$key-1]['Gy0_Ms'];
  511. $Gy0_Rate0 = $gyData[$key-1]['Gy0_Rate0'];
  512. $Gy0_Rate1 = $gyData[$key-1]['Gy0_Rate1'];
  513. $Gy0_Rate3 = $gyData[$key-1]['Gy0_Rate3'];
  514. // 大于第一道工序,使用上一道工序的计划产量
  515. // 根据公式计算工序计划产量
  516. if ($Gy0_Ms != "0.00") {
  517. $Num = $lastNum - ($Gy0_Rate0 + $Gy0_Rate1 * $lastNum) * $Gy0_Rate3 * $Gy0_Ms;
  518. } else {
  519. $Num = $lastNum - ($Gy0_Rate0 + $Gy0_Rate1 * $lastNum) * $Gy0_Rate3;
  520. }
  521. }
  522. if (trim($process['Gy0_SITE']) == '检验车间'){
  523. $res[$key]['plan'] = (int)$process['Gy0_计划接货数'];
  524. }else{
  525. $res[$key]['plan'] = (int)round($Num);
  526. }
  527. $finish_rate = $res[$key]['finish']/$res[$key]['plan'];
  528. $res[$key]['finish_rate'] = '';
  529. if ($finish_rate != 0){
  530. $res[$key]['finish_rate'] = number_format($finish_rate*100,2).'%';
  531. }
  532. // 更新 $lastNum 为当前工序的计划产量
  533. $lastNum = $Num;
  534. }
  535. $this->success('请求成功',$res);
  536. }
  537. /**
  538. * 工单工序状态更正
  539. * @ApiMethod POST
  540. * @params string UniqId
  541. * @params string date
  542. */
  543. public function editOrderFinishDate(){
  544. if (Request::instance()->isPost() == false){
  545. $this->error('非法请求');
  546. }
  547. $params = Request::instance()->post();
  548. if (!isset($params['UniqId']) || !isset($params['date'])){
  549. $this->error('参数错误');
  550. }
  551. if (empty($params['UniqId'])){
  552. $this->error('参数不能为空');
  553. }
  554. if (empty($params['date'])){
  555. $params['date'] = '1900-01-01 00:00:00';
  556. }
  557. $res = db('工单_工艺资料')->where('UniqId',$params['UniqId'])->setField('PD_WG',$params['date']);
  558. if ($res != false){
  559. $this->success('更新成功');
  560. }else{
  561. $this->error('更新失败');
  562. }
  563. }
  564. /**
  565. * 工单工序生产进程菜单栏
  566. * @ApiMethod GET
  567. * @params string order
  568. */
  569. public function getOrderProcessLeft(){
  570. if (Request::instance()->isGet() == false){
  571. $this->error('非法请求');
  572. }
  573. $params = Request::instance()->param();
  574. if (!isset($params['order']) || empty($params['order'])){
  575. $this->error('参数错误');
  576. }
  577. $where['Gd_gdbh'] = $params['order'];
  578. $where['行号'] = 1;
  579. //工单基本资料
  580. $info = db('工单_基本资料')->where($where)->field('rtrim(成品代号) as code,rtrim(成品名称) as name')->find();
  581. //工艺资料
  582. $option['Gy0_gdbh'] = $params['order'];
  583. $gyInfo = db('工单_工艺资料')
  584. ->where($option)
  585. ->where(function ($query) {
  586. $query->where('Gy0_sbbh', '<>', '')
  587. ->whereOr('Gy0_gxmc', '核检')
  588. ->whereOr('Gy0_gxmc', '成品防护');
  589. })
  590. ->field('Gy0_yjno,Gy0_gxh')
  591. ->select();
  592. foreach ($gyInfo as $key=>$value){
  593. $gyInfo[$key]['Gy0_yjno'] = $value['Gy0_yjno'] > 10 ? $value['Gy0_yjno'] : '0'.$value['Gy0_yjno'];
  594. $gyInfo[$key]['Gy0_gxh'] = $value['Gy0_gxh'] > 10 ? $value['Gy0_gxh'] : '0'.$value['Gy0_gxh'];
  595. }
  596. $res['Gd_info'] = $info;
  597. $res['Gy_info'] = $gyInfo;
  598. $this->success('请求成功',$res);
  599. }
  600. /**
  601. * 工单工序生产进程右侧
  602. * @ApiMethod GET
  603. * @params string order
  604. * @params string gxNo
  605. */
  606. public function getOrderProcessRight(){
  607. if (Request::instance()->isGet() == false){
  608. $this->error('非法请求');
  609. }
  610. $params = Request::instance()->param();
  611. if (!isset($params['order']) || empty($params['order'])){
  612. $this->error('参数错误');
  613. }
  614. if (!isset($params['gxNo']) || empty($params['gxNo'])){
  615. $this->error('参数错误');
  616. }
  617. $total = db('设备_产量计酬')->where('sczl_gdbh',$params['order'])->order('sczl_num')->column('distinct(sczl_num)');
  618. $where['sczl_gxh'] = (int)$params['gxNo'];
  619. $where['sczl_gdbh'] = $params['order'];
  620. $process = db('设备_产量计酬')->where($where)->order('sczl_num')->column('distinct(sczl_num)');
  621. $res['total_process'] = $total;
  622. $res['process'] = $process;
  623. $this->success('请求成功',$res);
  624. }
  625. /**
  626. * 核检废品日统计
  627. * @ApiMethod GET
  628. * @params date start_date
  629. * @params date end_date
  630. */
  631. public function getDaysWast()
  632. {
  633. if (Request::instance()->isGet() == false) {
  634. $this->error('非法请求');
  635. }
  636. $params = Request::instance()->param();
  637. if (!isset($params['start_date']) || empty($params['start_date'])) {
  638. $this->error('参数错误');
  639. }
  640. if (!isset($params['end_date']) || empty($params['end_date'])) {
  641. $this->error('参数错误');
  642. }
  643. $where['qczl_rq'] = array('between time', [$params['start_date'], $params['end_date']]);
  644. $field = '
  645. 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,
  646. 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,
  647. 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,
  648. 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,
  649. 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,
  650. 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,
  651. qczl_rq
  652. ';
  653. $resultArray = array();
  654. $key = 'getDaysWast'.$params['start_date'].'/'.$params['end_date'];
  655. $is_have_cache = Cache::has($key);
  656. if ($is_have_cache === false){
  657. $data = db('db_qczl')
  658. ->where($where)
  659. ->where(function ($query) {
  660. for ($i = 1; $i <= 13; $i++) {
  661. $query->whereOr("fp_lb$i", 'like', '%K%','AND',"fp_sl$i",'>',0);
  662. }
  663. })
  664. ->field($field)->select();
  665. $list = [];
  666. $j = 0;
  667. foreach ($data as $entry) {
  668. for ($i = 1; $i <= 13; $i++) {
  669. $labelKey = "fp_lb" . $i;
  670. $slKey = "fp_sl" . $i;
  671. $bhKey = "fp_bh" . $i;
  672. $bzKey = "fp_bz" . $i;
  673. if (!empty($entry[$labelKey])) {
  674. if ((substr($entry[$labelKey],0,3) == 'K02' || substr($entry[$labelKey],0,3) == 'K01') && $entry[$slKey] != '0'){
  675. $list[$j]['fp_lb'] = $entry[$labelKey];
  676. $list[$j]['fp_sl'] = $entry[$slKey];
  677. $list[$j]['fp_bh'] = $entry[$bhKey];
  678. $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)');
  679. $list[$j]['fp_name'] = empty($name) ? '计时工' : $name;
  680. $list[$j]['fp_bz'] = $entry[$bzKey];
  681. $list[$j]['qczl_rq'] = $entry['qczl_rq'];
  682. $j++;
  683. }
  684. }
  685. }
  686. }
  687. foreach ($list as $item) {
  688. $found = false;
  689. foreach ($resultArray as &$resultItem) {
  690. if ($item["fp_lb"] === $resultItem["fp_lb"] && $item["fp_bh"] === $resultItem["fp_bh"]) {
  691. $resultItem["fp_sl"] += (int)$item["fp_sl"];
  692. $found = true;
  693. break;
  694. }
  695. }
  696. if (!$found) {
  697. $resultArray[] = $item;
  698. }
  699. }
  700. // 使用usort进行排序
  701. usort($resultArray, function($a, $b) {
  702. // First, sort by fp_lb (K01/K02)
  703. $compareLb = strcmp($a['fp_lb'], $b['fp_lb']);
  704. if ($compareLb !== 0) {
  705. return $compareLb;
  706. }
  707. // If fp_lb is the same, prioritize B班 over A班
  708. $compareBz = strcmp($a['fp_bz'], $b['fp_bz']);
  709. if ($compareBz !== 0) {
  710. return (trim($a['fp_bz']) === 'B班') ? -1 : 1;
  711. }
  712. // If fp_bz is the same, sort by fp_bh
  713. $compareBh = strcmp($a['fp_bh'], $b['fp_bh']);
  714. return $compareBh;
  715. });
  716. Cache::set($key,$resultArray,86400);
  717. }else{
  718. $resultArray = Cache::get($key);
  719. }
  720. $this->success('请求成功',$resultArray);
  721. }
  722. /**
  723. * 月度核检废品责任人统计
  724. * @ApiMethod GET
  725. * @params string date
  726. */
  727. public function getMonthPeopleTotal(){
  728. if (Request::instance()->isGet() == false) {
  729. $this->error('非法请求');
  730. }
  731. $params = Request::instance()->param();
  732. if (!isset($params['date']) || empty($params['date'])) {
  733. $this->error('参数错误');
  734. }
  735. }
  736. /**
  737. * 工单质检废品统计
  738. * @ApiMethod GET
  739. * @params string order
  740. */
  741. public function getOrderWasteTotal(){
  742. if (Request::instance()->isGet() == false) {
  743. $this->error('非法请求');
  744. }
  745. $params = Request::instance()->param();
  746. if (!isset($params['order']) || empty($params['order'])) {
  747. $this->error('参数错误');
  748. }
  749. $field = '
  750. 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,
  751. 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,
  752. 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,
  753. 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,
  754. 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,
  755. 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,
  756. 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.交货日期,
  757. c.yj_ls,d.jjcp_sl,d.jjcp_sj
  758. ';
  759. $where['a.qczl_gdbh'] = $params['order'];
  760. $where['b.行号'] = 1;
  761. $data = db('db_qczl')->alias('a')
  762. ->join('工单_基本资料 b','a.qczl_gdbh = b.Gd_gdbh','left')
  763. ->join('工单_印件资料 c','a.qczl_gdbh = c.Yj_Gdbh','left')
  764. ->join('成品入仓 d','a.qczl_gdbh = d.jjcp_gdbh','left')
  765. ->where($where)
  766. ->field($field)->select();
  767. $list = [];
  768. $j = 0;
  769. foreach ($data as $entry) {
  770. for ($i = 1; $i <= 13; $i++) {
  771. $labelKey = "fp_lb" . $i;
  772. $slKey = "fp_sl" . $i;
  773. $bhKey = "fp_bh" . $i;
  774. $gxhKey = "fp_gxmc". $i;
  775. if (!empty($entry[$labelKey]) && $entry[$slKey] > 0) {
  776. $list[$j]['fp_lb'] = $entry[$labelKey];
  777. $list[$j]['fp_sl'] = $entry[$slKey];
  778. $list[$j]['fp_bh'] = $entry[$bhKey];
  779. $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)');
  780. $list[$j]['fp_name'] = $name;
  781. $list[$j]['fp_gxh'] = empty(substr($entry[$gxhKey],0,2)) ? "0" : substr($entry[$gxhKey],0,2);
  782. $list[$j]['qczl_num'] = $entry['qczl_num'];
  783. $list[$j]['qczl_yjno'] = $entry['qczl_yjno'];
  784. $list[$j]['product_code'] = $entry['product_code'];
  785. $list[$j]['product_name'] = $entry['product_name'];
  786. $list[$j]['订单数量'] = $entry['订单数量'];
  787. $list[$j]['计量单位'] = $entry['计量单位'];
  788. $list[$j]['交货日期'] = substr($entry['交货日期'],0,10);
  789. $list[$j]['yj_ls'] = $entry['yj_ls'];
  790. $list[$j]['jjcp_sl'] = $entry['jjcp_sl'];
  791. $list[$j]['jjcp_sj'] = substr($entry['jjcp_sj'],0,10);
  792. $j++;
  793. }
  794. }
  795. }
  796. $summedData = [];
  797. foreach ($list as $item) {
  798. $key = $item['qczl_num'] . $item['fp_lb'];
  799. if (!isset($summedData[$key])) {
  800. $summedData[$key] = $item;
  801. } else {
  802. $summedData[$key]['fp_sl'] += $item['fp_sl'];
  803. }
  804. }
  805. $fpGxhColumn = array_column($summedData, 'fp_gxh');
  806. $qczlNumColumn = array_column($summedData, 'qczl_num');
  807. $fpLbColumn = array_column($summedData, 'fp_lb');
  808. array_multisort($fpGxhColumn, SORT_ASC, $qczlNumColumn, SORT_ASC, $fpLbColumn, SORT_ASC, $summedData);
  809. $summedData = array_values($summedData);
  810. $this->success('请求成功',$summedData);
  811. }
  812. }