WorkOrderVerification.php 36 KB

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