WorkOrderVerification.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161
  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. if(!cache('WorkOrderVerification-getTable')){
  33. $time = date('Y-m-d',time()-8640000);
  34. $rows = db()->table('db_qczl')
  35. ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
  36. ->where('sys_rq','>=',$time)
  37. ->group('date')
  38. ->order('date desc')
  39. ->limit(30)
  40. ->select();
  41. $arr = db()->table('db_qczl')
  42. ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(*) as count')
  43. ->where('sys_rq','>=',$rows[count($rows)-1]['date'])
  44. ->group('date, sys_id')
  45. ->select();
  46. foreach($rows as $key=>$value){
  47. $rows[$key]['sys'] = [];
  48. foreach($arr as $k=>$v){
  49. if($value['date'] == $v['date']){
  50. unset($v['date']);
  51. array_push($rows[$key]['sys'],$v);
  52. unset($arr[$k]);
  53. }
  54. }
  55. $rows[$key]['date'] = str_replace('-', '.', $rows[$key]['date']);
  56. }
  57. //设置缓存
  58. cache('WorkOrderVerification-getTable',$rows,3600);
  59. }else{
  60. $rows = cache('WorkOrderVerification-getTable');
  61. }
  62. $this->success('成功',$rows);
  63. }
  64. /**
  65. * 获取工单核验单侧边栏通过工单编号
  66. * @ApiMethod (GET)
  67. */
  68. public function getTabByGdbh()
  69. {
  70. //get请求
  71. if(!$this->request->isGet()){
  72. $this->error('请求方式错误');
  73. }
  74. $date = date('Y-m-d',strtotime("-1 year"));
  75. $rows = db()->table('db_qczl')->alias('d')
  76. ->field('d.qczl_gdbh, rtrim(y.Gd_cpmc) as Gd_cpmc')
  77. ->join('工单_基本资料 y','y.Gd_gdbh = d.qczl_gdbh','left')
  78. ->where('d.sys_rq','>=',$date)
  79. ->group('d.qczl_gdbh')
  80. ->order('d.qczl_gdbh desc')
  81. ->limit(65)
  82. ->select();
  83. $arr = db()->table('db_qczl')
  84. ->field('qczl_gdbh, rtrim(sys_id) as sys_id, COUNT(*) as count')
  85. ->where('qczl_gdbh','>=',$rows[count($rows)-1]['qczl_gdbh'])
  86. ->group('qczl_gdbh, sys_id')
  87. ->select();
  88. foreach($rows as $key=>$value){
  89. $rows[$key]['sys'] = [];
  90. foreach($arr as $k=>$v){
  91. if($value['qczl_gdbh'] == $v['qczl_gdbh']){
  92. unset($v['qczl_gdbh']);
  93. array_push($rows[$key]['sys'],$v);
  94. unset($arr[$k]);
  95. }
  96. }
  97. }
  98. $this->success('成功',$rows);
  99. }
  100. /**
  101. * 获取工单核验单列表
  102. * @ApiMethod (GET)
  103. * @param string $date 时间
  104. * @param string $sys_id 用户
  105. */
  106. public function getList()
  107. {
  108. //get请求
  109. if(!$this->request->isGet()){
  110. $this->error('请求方式错误');
  111. }
  112. $req = $this->request->param();
  113. $page = 1;
  114. $limit = 15;
  115. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  116. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  117. $where = [];
  118. if (isset($req['date']) && !empty($req['date'])){
  119. $where['sys_rq'] = ['LIKE',$req['date'].'%'];
  120. }
  121. if (isset($req['sys_id']) && !empty($req['sys_id'])) $where['sys_id'] = ['LIKE',$req['sys_id'].'%'];
  122. if (isset($req['order']) && !empty($req['order'])) $where['qczl_gdbh'] = $req['order'];
  123. if (isset($req['cpmc']) && !empty($req['cpmc'])){
  124. //查询工单表
  125. $gd = db('工单_基本资料')
  126. ->where('Gd_cpmc', 'LIKE', '%'.$req['cpmc'].'%')
  127. ->column('Gd_gdbh');
  128. $where['qczl_gdbh'] = ['in', $gd];
  129. }
  130. $rows = db()->table('db_qczl')
  131. ->field('qczl_gdbh, qczl_yjno, LEFT(qczl_rq, 10) as qczl_rq, qczl_num, rtrim(qczl_NumDesc) as qczl_NumDesc, qczl_fp,
  132. 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,
  133. 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,
  134. 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,
  135. rtrim(sys_id) as sys_id,UniqId')
  136. ->where($where)
  137. ->order('qczl_gdbh,qczl_yjno,qczl_num')
  138. ->page($page,$limit)
  139. ->select();
  140. $total = db()->table('db_qczl')->where($where)->count();
  141. $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
  142. foreach ($rows as $key=>$value){
  143. $rows[$key]['Gd_cpmc'] = array_key_exists($value['qczl_gdbh'],$gd) ? sprintf("%02d", $value['qczl_yjno']).'-'.trim($gd[$value['qczl_gdbh']]) : '';
  144. for ($i=1;$i<=17;$i++){
  145. if ($value['fp_sl'.$i]==0){
  146. $rows[$key]['sl_lb'.$i] = '';
  147. }else{
  148. $rows[$key]['sl_lb'.$i] = trim($value['fp_sl'.$i].'-->'.$value['fp_lb'.$i].'('.$value['fp_bh'.$i].')');
  149. }
  150. unset($rows[$key]['fp_sl'.$i]);
  151. unset($rows[$key]['fp_lb'.$i]);
  152. }
  153. }
  154. $data = [
  155. 'total' => $total,
  156. 'rows' => $rows,
  157. ];
  158. $this->success('成功',$data);
  159. }
  160. /**
  161. * 获取工单核验单信息
  162. * @ApiMethod (GET)
  163. * @param string $UniqId UniqId
  164. */
  165. public function getInfo()
  166. {
  167. //get请求
  168. if(!$this->request->isGet()){
  169. $this->error('请求方式错误');
  170. }
  171. $req = $this->request->param();
  172. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  173. $UniqId = $req['UniqId'];
  174. }else{
  175. $this->error('参数错误');
  176. }
  177. $rows = db()->table('db_qczl')->alias('d')
  178. ->field('d.*, ')
  179. ->join('工单_基本资料 g', 'd.')
  180. ->where('d.UniqId',$UniqId)
  181. ->select();
  182. $this->success('成功',$rows);
  183. }
  184. /**
  185. * 获取单个工单核检单信息
  186. * @ApiMethod GET
  187. * @params string UniqId
  188. */
  189. public function getOneWorkOrder(){
  190. if (Request::instance()->isGet() == false){
  191. $this->error('非法请求');
  192. }
  193. $params = Request::instance()->param();
  194. if (!isset($params['UniqId']) || empty($params['UniqId'])){
  195. $this->error('参数错误');
  196. }
  197. $field = 'qczl_gdbh,qczl_Pygd,qczl_yjno,qczl_gxh,qczl_gxmc,qczl_type,qczl_rq,qczl_num,qczl_fp,
  198. qczl_NumDesc,qczl_NumDesc1,qczl_NumDesc2,qczl_NumDesc3,qczl_NumDesc4,qczl_NumDesc5,qczl_NumDesc6,qczl_NumDesc7,qczl_NumDesc8,
  199. 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,
  200. 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,
  201. 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,
  202. 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,
  203. 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,
  204. sys_id,rtrim(sys_rq) as sys_rq,UniqId';
  205. $list = db('db_qczl')->where('UniqId',$params['UniqId'])->field($field)->find();
  206. $list['fp_name1'] = '';
  207. if (!empty($list['fp_bh1'])){
  208. $list['fp_name1'] = db('人事_基本资料')->where('员工编号',$list['fp_bh1'])->value('rtrim(员工姓名)');
  209. }
  210. $list['fp_name2'] = '';
  211. if (!empty($list['fp_bh2'])){
  212. $list['fp_name2'] = db('人事_基本资料')->where('员工编号',$list['fp_bh2'])->value('rtrim(员工姓名)');
  213. }
  214. $list['fp_name3'] = '';
  215. if (!empty($list['fp_bh3'])){
  216. $list['fp_name3'] = db('人事_基本资料')->where('员工编号',$list['fp_bh3'])->value('rtrim(员工姓名)');
  217. }
  218. $list['fp_name4'] = '';
  219. if (!empty($list['fp_bh4'])){
  220. $list['fp_name4'] = db('人事_基本资料')->where('员工编号',$list['fp_bh4'])->value('rtrim(员工姓名)');
  221. }
  222. $list['fp_name5'] = '';
  223. if (!empty($list['fp_bh5'])){
  224. $list['fp_name5'] = db('人事_基本资料')->where('员工编号',$list['fp_bh5'])->value('rtrim(员工姓名)');
  225. }
  226. $list['fp_name6'] = '';
  227. if (!empty($list['fp_bh6'])){
  228. $list['fp_name6'] = db('人事_基本资料')->where('员工编号',$list['fp_bh6'])->value('rtrim(员工姓名)');
  229. }
  230. $list['fp_name7'] = '';
  231. if (!empty($list['fp_bh7'])){
  232. $list['fp_name7'] = db('人事_基本资料')->where('员工编号',$list['fp_bh7'])->value('rtrim(员工姓名)');
  233. }
  234. $list['fp_name8'] = '';
  235. if (!empty($list['fp_bh8'])){
  236. $list['fp_name8'] = db('人事_基本资料')->where('员工编号',$list['fp_bh8'])->value('rtrim(员工姓名)');
  237. }
  238. $list['fp_name9'] = '';
  239. if (!empty($list['fp_bh9'])){
  240. $list['fp_name9'] = db('人事_基本资料')->where('员工编号',$list['fp_bh9'])->value('rtrim(员工姓名)');
  241. }
  242. $list['fp_name10'] = '';
  243. if (!empty($list['fp_bh10'])){
  244. $list['fp_name10'] = db('人事_基本资料')->where('员工编号',$list['fp_bh10'])->value('rtrim(员工姓名)');
  245. }
  246. $list['fp_name11'] = '';
  247. if (!empty($list['fp_bh11'])){
  248. $list['fp_name11'] = db('人事_基本资料')->where('员工编号',$list['fp_bh11'])->value('rtrim(员工姓名)');
  249. }
  250. $list['fp_name12'] = '';
  251. if (!empty($list['fp_bh12'])){
  252. $list['fp_name12'] = db('人事_基本资料')->where('员工编号',$list['fp_bh12'])->value('rtrim(员工姓名)');
  253. }
  254. $list['fp_name13'] = '';
  255. if (!empty($list['fp_bh13'])){
  256. $list['fp_name13'] = db('人事_基本资料')->where('员工编号',$list['fp_bh13'])->value('rtrim(员工姓名)');
  257. }
  258. $max = db('设备_产量计酬')->where('sczl_gdbh',$list['qczl_gdbh'])->field('MAX(sczl_num) as sczl_num')->find();
  259. $list['total_liucheng'] = $max['sczl_num'];
  260. $this->success('请求成功',$list);
  261. }
  262. /**
  263. * 获取工单基本信息
  264. * @ApiMethod GET
  265. * @params string order
  266. */
  267. public function getOrderInfo(){
  268. if (Request::instance()->isGet() == false){
  269. $this->error('非法请求');
  270. }
  271. $params = Request::instance()->param();
  272. if (!isset($params['order']) || empty($params['order'])){
  273. $this->error('参数错误');
  274. }
  275. $list = db('工单_基本资料')->alias('a')
  276. ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh','left')
  277. ->where('a.Gd_gdbh',$params['order'])
  278. // ->where('a.行号',1)
  279. ->field('a.Gd_cpmc,b.yj_Yjno,b.yj_yjmc')
  280. ->group('a.Gd_gdbh,b.yj_Yjno')
  281. ->select();
  282. $this->success('请求成功',$list);
  283. }
  284. /**
  285. * 获取印件名称及工序
  286. * @ApiMethod GET
  287. * @params string order
  288. * @params string yj_no
  289. */
  290. public function getYjInfo(){
  291. if (Request::instance()->isGet() == false){
  292. $this->error('非法请求');
  293. }
  294. $params = Request::instance()->param();
  295. if (!isset($params['order']) || empty($params['order'])){
  296. $this->error('参数错误');
  297. }
  298. if (!isset($params['yj_no']) || empty($params['yj_no'])){
  299. $this->error('参数错误');
  300. }
  301. $where['Yj_Gdbh'] = $params['order'];
  302. $where['yj_Yjno'] = $params['yj_no'];
  303. $list = db('工单_印件资料')->where($where)->field('yj_yjmc')->find();
  304. $option['Gy0_gdbh'] = $params['order'];
  305. $option['Gy0_yjno'] = $params['yj_no'];
  306. $option['Gy0_gxmc|Add_gxmc'] = ['like','%'.'核检'.'%'];
  307. // $option['Gy0_site'] = '印后车间';
  308. // $option['Gy0_gxmc'] = array('not in',['包装','外发加工','废挑正','成品防护']);
  309. $gxList = db('工单_工艺资料')->where($option)->field('Gy0_gxh,rtrim(Gy0_gxmc) as Gy0_gxmc,rtrim(Add_gxmc) as Add_gxmc')->select();
  310. $max = db('设备_产量计酬')->where('sczl_gdbh',$params['order'])->where('sczl_yjno',$params['yj_no'])->field('MAX(sczl_num) as sczl_num')->value('sczl_num');
  311. $list['gx_data'] = $gxList;
  312. $list['max_num'] = $max;
  313. $this->success('请求成功',$list);
  314. }
  315. /**
  316. * 获取废品分类
  317. * @ApiMethod GET
  318. * @params string search
  319. */
  320. public function getWastInfo(){
  321. if (Request::instance()->isGet() == false){
  322. $this->error('非法请求');
  323. }
  324. $params = Request::instance()->param();
  325. $where['分类'] = '废品分类';
  326. $where['禁用状态'] = 1;
  327. if (!empty($params['search'])){
  328. $where['名称'] = array('like','%'.$params['search'].'%');
  329. }
  330. $data = db('erp_常用字典')->where($where)->order('次序 desc')->column('名称');
  331. // 分割字符串并合并相同项
  332. $resultArray = [];
  333. foreach ($data as $item) {
  334. $parts = explode('_', $item);
  335. // 使用第一个部分作为一级键,第二个部分作为二级键
  336. $firstKey = $parts[0];
  337. $secondKey = $parts[1];
  338. $thirdValue = $parts[2];
  339. $resultArray[$firstKey][$secondKey][] = $thirdValue;
  340. }
  341. // 对废品分类下的数组进行升序排序
  342. if (isset($resultArray['data']['废品分类'])) {
  343. foreach ($resultArray['data']['废品分类'] as &$category) {
  344. // 判断是关联数组(单凹等)还是索引数组(分切等)
  345. if (is_array($category) && !empty($category) && is_array(current($category))) {
  346. foreach ($category as &$subCategory) {
  347. ksort($subCategory);
  348. }
  349. } else {
  350. ksort($category);
  351. }
  352. }
  353. }
  354. $this->success('请求成功',$resultArray);
  355. }
  356. /**
  357. *获取工序及责任组长
  358. * @ApiMethod GET
  359. * @params string type
  360. * @params string order
  361. */
  362. public function getGxAndLeader(){
  363. if (Request::instance()->isGet() == false){
  364. $this->error('非法请求');
  365. }
  366. $params = Request::instance()->param();
  367. if (!isset($params['type']) || empty($params['type'])){
  368. $this->error('参数错误');
  369. }
  370. if (!isset($params['order']) || empty($params['order'])){
  371. $this->error('参数错误');
  372. }
  373. if (!isset($params['yjno']) || empty($params['yjno'])){
  374. $this->error('参数错误');
  375. }
  376. $type = trim($params['type']);
  377. $waste = db('erp_常用字典')->where('名称','like','%'.$type.'%')->find();
  378. if (empty($waste)){
  379. $this->error('未查询到废品分类');
  380. }
  381. $wasteType = explode('_',substr($waste['名称'],0,-1));
  382. $searchArr = explode('-',$wasteType[1]);
  383. $where['a.sczl_gdbh'] = $params['order'];
  384. $where['a.sczl_yjno'] = $params['yjno'];
  385. //模切和凹凸的废品类型相同
  386. if ($searchArr[1] === '模切凹凸'){
  387. $list = db('设备_产量计酬')->alias('a')
  388. ->join('人事_基本资料 b', 'a.sczl_bh1 = b.员工编号', 'left')
  389. ->where($where)
  390. ->where(function($query) {
  391. $query->where('a.sczl_type', 'like', '%模切%')
  392. ->whereOr('a.sczl_type', 'like', '%凹凸%');
  393. })
  394. ->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
  395. ->select();
  396. }elseif ($searchArr[1] === '拆片'){
  397. $search = substr($searchArr[1],0,6);
  398. $where['a.sczl_type'] = array('like','%'.$search.'%');
  399. $list = db('db_sczl')->alias('a')
  400. ->join('人事_基本资料 b','a.sczl_bh1 = b.员工编号','left')
  401. ->where($where)
  402. ->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
  403. ->select();
  404. }elseif($searchArr[1] === '检验'){
  405. $where['a.sczl_gxmc'] = ['like','%'.'检'.'%'];
  406. $list = db('设备_产量计酬')->alias('a')
  407. ->join('人事_基本资料 b','a.sczl_bh1 = b.员工编号','left')
  408. ->where($where)
  409. ->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
  410. ->select();
  411. }elseif ($searchArr[1] === '胶印'){
  412. $gxmcArray = ['裁切','滚切','胶印','上光','切废'];
  413. $list = db('设备_产量计酬')->alias('a')
  414. ->join('人事_基本资料 b', 'a.sczl_bh1 = b.员工编号', 'left')
  415. ->where($where) // 保留其他筛选条件
  416. ->where(function($query) use ($gxmcArray) {
  417. foreach ($gxmcArray as $word) {
  418. $query->whereOr('a.sczl_gxmc', 'like', "%{$word}%");
  419. }
  420. })
  421. ->field('distinct(a.sczl_gxmc), a.sczl_bzdh, a.sczl_jtbh, a.sczl_bh1, b.员工姓名 as name')
  422. ->order('a.sczl_gxh', 'asc')
  423. ->select();
  424. }else{
  425. $search = substr($searchArr[1],0,6);
  426. $where['a.sczl_type'] = array('like','%'.$search.'%');
  427. $list = db('设备_产量计酬')->alias('a')
  428. ->join('人事_基本资料 b','a.sczl_bh1 = b.员工编号','left')
  429. ->where($where)
  430. ->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
  431. ->select();
  432. }
  433. $count = count($list);
  434. $list[$count]['sczl_gxmc'] = '99-外发加工';
  435. $list[$count]['sczl_bzdh'] = 'A班';
  436. $list[$count]['sczl_jtbh'] = '';
  437. $list[$count]['sczl_bh1'] = '000000';
  438. $list[$count]['name'] = '计时工';
  439. $this->success('请求成功',$list);
  440. }
  441. /**
  442. * 修改工单核检单
  443. * @ApiMethod POST
  444. * @params array data
  445. */
  446. public function edit(){
  447. if (Request::instance()->isPost() == false){
  448. $this->error('非法请求');
  449. }
  450. $params = Request::instance()->post();
  451. if (!isset($params['UniqId'])){
  452. $this->error('参数不能为空');
  453. }
  454. $id = $params['UniqId'];
  455. unset($params['UniqId']);
  456. $sql = db('db_qczl')->where('UniqId',$id)->fetchSql(true)->update($params);
  457. $res = Db::query($sql);
  458. if ($res !== 0){
  459. cache('WorkOrderVerification-getTable',null);
  460. $this->success('更新成功');
  461. }else{
  462. $this->error('更新失败');
  463. }
  464. }
  465. /**
  466. * 新增工单核检单
  467. * @ApiMethod POST
  468. * @params array data
  469. */
  470. public function add(){
  471. if (Request::instance()->isPost() == false){
  472. $this->error('非法请求');
  473. }
  474. $params = Request::instance()->post();
  475. $UniqId = db('db_qczl')->order('UniqId desc')->value('UniqId');
  476. if ($UniqId < 10000000){
  477. $UniqId = 10000000;
  478. }else{
  479. $UniqId = $UniqId + 1;
  480. }
  481. $params['UniqId'] = $UniqId;
  482. $params['sys_rq'] = date('Y-m-d H:i:s');
  483. $res = \db('db_qczl')->insert($params);
  484. if ($res !== false){
  485. cache('WorkOrderVerification-getTable',null);
  486. $this->success('新增成功');
  487. }else{
  488. $this->error('新增失败');
  489. }
  490. }
  491. /**
  492. * 工单核检废品分布
  493. * @ApiMethod GET
  494. * @params string order
  495. */
  496. public function wasteDistribution(){
  497. if (Request::instance()->isGet() == false){
  498. $this->error('非法请求');
  499. }
  500. $params = Request::instance()->param();
  501. if (!isset($params['order']) || empty($params['order'])){
  502. $this->error('参数错误');
  503. }
  504. if (!isset($params['yjno']) || empty($params['yjno'])){
  505. $this->error('参数错误');
  506. }
  507. $field = '
  508. 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,
  509. 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,
  510. 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,qczl_yjno
  511. ';
  512. // $data = db('db_qczl')->name('db_qczl')->where('qczl_gdbh',$params['order'])->field($field)->select();
  513. $data = db('db_qczl')->name('db_qczl')
  514. ->where('qczl_gdbh',$params['order'])
  515. ->where('qczl_yjno', $params['yjno'])
  516. ->field($field)->select();
  517. if (empty($data)){
  518. $this->error('暂无废品数据');
  519. }
  520. // 用于存储废品类别和对应废品数量的数组
  521. $categories = array();
  522. // 循环遍历原始数组
  523. foreach ($data as $item) {
  524. // 提取废品类别和对应废品数量
  525. foreach ($item as $key => $value) {
  526. if (strpos($key, "fp_lb") === 0) {
  527. $categoryKey = $key;
  528. $quantityKey = str_replace("fp_lb", "fp_sl", $key);
  529. $quantityValue = $item[$quantityKey];
  530. if (!isset($categories[$value])) {
  531. $categories[$value] = 0;
  532. }
  533. $categories[$value] += (int)$quantityValue;
  534. }
  535. }
  536. }
  537. ksort($categories);
  538. $wasteTotal = db('db_qczl')->where('qczl_gdbh',$params['order'])->sum('qczl_fp');
  539. if (empty($wasteTotal)){
  540. $wasteTotal = 0;
  541. }
  542. $where['a.Gd_gdbh'] = $params['order'];
  543. $where['a.行号'] = $params['yjno'];
  544. $gdInfo = db('工单_基本资料')->alias('a')
  545. ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh','left')
  546. ->where($where)->field('a.Gd_gdbh,a.实际投料,b.yj_Yjno,b.yj_yjmc')->find();
  547. $gdInfo['yj_Yjno'] = $gdInfo['yj_Yjno'] > 10 ? $gdInfo['yj_Yjno']:'0'.$gdInfo['yj_Yjno'];
  548. $gdInfo['实际投料'] = (int)($gdInfo['实际投料'] * 10000);
  549. $gdInfo['wasteTotal'] = $wasteTotal;
  550. $finishNum = db('成品入仓')->where('jjcp_gdbh',$params['order'])->where('jjcp_yjno',$params['yjno'])->sum('jjcp_sl');
  551. $gdInfo['passRate'] = '';
  552. if (!empty($finishNum)){
  553. $gdInfo['passRate'] = number_format((int)$finishNum/$gdInfo['实际投料']*100,2).'%';
  554. }
  555. //左侧废品数据
  556. $wasteData = array();
  557. $i = 0;
  558. foreach ($categories as $key=>$value){
  559. if ($value != 0){
  560. $wasteData[$i]['type'] = $key;
  561. $wasteData[$i]['num'] = $value;
  562. $wasteData[$i]['lossesRate'] = number_format($value/$gdInfo['实际投料']*100,4).'%';
  563. $wasteData[$i]['wasteRate'] = number_format($value/$wasteTotal*100,2).'%';
  564. $i++;
  565. }
  566. }
  567. // 按首字母相同的键将值相加
  568. $newArray = array();
  569. foreach ($categories as $key => $value) {
  570. $firstLetter = strtoupper(substr($key, 0, 1)); // 获取首字母并转换为大写
  571. if (!isset($newArray[$firstLetter])) {
  572. $newArray[$firstLetter] = 0;
  573. }
  574. $newArray[$firstLetter] += $value;
  575. }
  576. // 去掉值为零的项
  577. $newArray = array_filter($newArray, function($value) {
  578. return $value !== 0;
  579. });
  580. //右侧废品数据
  581. $rightData = array();
  582. $i = 0;
  583. $name = array();
  584. foreach ($newArray as $key=>$value){
  585. $item = db('erp_常用字典')->where('名称','like','%'.$key.'%')->value('名称');
  586. $item = explode('_',substr($item,0,-1));
  587. $rightData[$i]['type'] = $item[1];
  588. $rightData[$i]['rate'] = number_format($value/$wasteTotal*100,0).'%';
  589. $name[$i] = $item[1];
  590. $i++;
  591. }
  592. $gdInfo['wasteData'] = $wasteData;
  593. $gdInfo['rightData'] = $rightData;
  594. $gdInfo['rightTitle'] = $name;
  595. $this->success('请求成功',$gdInfo);
  596. }
  597. /**
  598. * 获取工单工序状态
  599. * @ApiMethod GET
  600. * @params string order
  601. * 计划产量计算方式:上个工序计划产量-(基础损耗+损耗率*上个工序计划产量)*损耗系数*计损色数)
  602. * lastNum - (Gy0_Rate0 + Gy0_Rate1 * lastNum )* 损耗系数(Gy0_Rate3) * Gy0_Ms
  603. */
  604. public function getOrderDate(){
  605. if (Request::instance()->isGet() == false){
  606. $this->error('非法请求');
  607. }
  608. $params = Request::instance()->param();
  609. if (!isset($params['order']) || empty($params['order'])){
  610. $this->error('参数错误');
  611. }
  612. $where['a.Gy0_gdbh'] = $params['order'];
  613. $where['a.Gy0_sbbh'] = array('neq',' ');
  614. $productNum = db('工单_基本资料')->where('Gd_gdbh',$params['order'])->value('计划投料');
  615. $gyData = db('工单_工艺资料')->alias('a')
  616. ->join('设备_产量计酬 b','a.Gy0_gdbh = b.sczl_gdbh and a.Gy0_gxh = b.sczl_gxh','left')
  617. ->where($where)
  618. ->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,
  619. a.UniqId,sum(b.sczl_cl) as cl')
  620. ->group('a.Gy0_gxh')
  621. ->select();
  622. $lastNum = $productNum;
  623. $res = [];
  624. foreach ($gyData as $key=> $process) {
  625. $res[$key]['UniqId'] = $process['UniqId'];
  626. $res[$key]['Gy0_yjno'] = $process['Gy0_yjno'] > 10 ? $process['Gy0_yjno'] : '0'.$process['Gy0_yjno'];
  627. $res[$key]['Gy0_gxh'] = $process['Gy0_gxh'] > 10 ? $process['Gy0_gxh'] : '0'.$process['Gy0_gxh'];
  628. $res[$key]['Gy0_gxmc'] = $process['Gy0_gxmc'];
  629. $res[$key]['Gy0_sbbh'] = rtrim($process['Gy0_sbbh']);
  630. $res[$key]['PD_WG'] = $process['PD_WG'];
  631. $res[$key]['finish'] = empty($process['cl']) ? 0: (int)$process['cl'];
  632. // 计算工序计划产量
  633. if ($process["Gy0_gxh"] == "1") {
  634. // 第一道工序直接使用初始计划产量
  635. $Num = $lastNum;
  636. } else {
  637. $Gy0_Ms = $gyData[$key-1]['Gy0_Ms'];
  638. $Gy0_Rate0 = $gyData[$key-1]['Gy0_Rate0'];
  639. $Gy0_Rate1 = $gyData[$key-1]['Gy0_Rate1'];
  640. $Gy0_Rate3 = $gyData[$key-1]['Gy0_Rate3'];
  641. // 大于第一道工序,使用上一道工序的计划产量
  642. // 根据公式计算工序计划产量
  643. if ($Gy0_Ms != "0.00") {
  644. $Num = $lastNum - ($Gy0_Rate0 + $Gy0_Rate1 * $lastNum) * $Gy0_Rate3 * $Gy0_Ms;
  645. } else {
  646. $Num = $lastNum - ($Gy0_Rate0 + $Gy0_Rate1 * $lastNum) * $Gy0_Rate3;
  647. }
  648. }
  649. if (trim($process['Gy0_SITE']) == '检验车间'){
  650. $res[$key]['plan'] = (int)$process['Gy0_计划接货数'];
  651. }else{
  652. $res[$key]['plan'] = (int)round($Num);
  653. }
  654. $finish_rate = $res[$key]['finish']/$res[$key]['plan'];
  655. $res[$key]['finish_rate'] = '';
  656. if ($finish_rate != 0){
  657. $res[$key]['finish_rate'] = number_format($finish_rate*100,2).'%';
  658. }
  659. // 更新 $lastNum 为当前工序的计划产量
  660. $lastNum = $Num;
  661. }
  662. $this->success('请求成功',$res);
  663. }
  664. /**
  665. * 工单工序状态更正
  666. * @ApiMethod POST
  667. * @params string UniqId
  668. * @params string date
  669. */
  670. public function editOrderFinishDate(){
  671. if (Request::instance()->isPost() == false){
  672. $this->error('非法请求');
  673. }
  674. $params = Request::instance()->post();
  675. if (!isset($params['UniqId']) || !isset($params['date'])){
  676. $this->error('参数错误');
  677. }
  678. if (empty($params['UniqId'])){
  679. $this->error('参数不能为空');
  680. }
  681. if (empty($params['date'])){
  682. $params['date'] = '1900-01-01 00:00:00';
  683. }
  684. $res = db('工单_工艺资料')->where('UniqId',$params['UniqId'])->setField('PD_WG',$params['date']);
  685. if ($res != false){
  686. $this->success('更新成功');
  687. }else{
  688. $this->error('更新失败');
  689. }
  690. }
  691. /**
  692. * 工单工序生产进程菜单栏
  693. * @ApiMethod GET
  694. * @params string order
  695. */
  696. public function getOrderProcessLeft(){
  697. if (Request::instance()->isGet() == false){
  698. $this->error('非法请求');
  699. }
  700. $params = Request::instance()->param();
  701. if (!isset($params['order']) || empty($params['order'])){
  702. $this->error('参数错误');
  703. }
  704. if (!isset($params['yjno']) || empty($params['yjno'])){
  705. $this->error('参数错误');
  706. }
  707. $where['Gd_gdbh'] = $params['order'];
  708. // $where['行号'] = 1;
  709. //工单基本资料
  710. $info = db('工单_基本资料')->where($where)->field('rtrim(成品代号) as code,rtrim(成品名称) as name')->find();
  711. //工艺资料
  712. $option['Gy0_gdbh'] = $params['order'];
  713. $option['Gy0_yjno'] = $params['yjno'];
  714. $gyInfo = db('工单_工艺资料')
  715. ->where($option)
  716. ->where(function ($query) {
  717. $query->where('Gy0_sbbh', '<>', '')
  718. ->whereOr('Gy0_gxmc', '核检')
  719. ->whereOr('Gy0_gxmc', '抽检')
  720. ->whereOr('Gy0_gxmc', '成品防护');
  721. })
  722. ->field('Gy0_yjno,Gy0_gxh,rtrim(Gy0_gxmc) as Gy0_gxmc')
  723. ->select();
  724. foreach ($gyInfo as $key=>$value){
  725. $gyInfo[$key]['Gy0_yjno'] = $value['Gy0_yjno'] > 10 ? $value['Gy0_yjno'] : '0'.$value['Gy0_yjno'];
  726. $gyInfo[$key]['Gy0_gxh'] = $value['Gy0_gxh'] > 10 ? $value['Gy0_gxh'] : '0'.$value['Gy0_gxh'];
  727. }
  728. $res['Gd_info'] = $info;
  729. $res['Gy_info'] = $gyInfo;
  730. $this->success('请求成功',$res);
  731. }
  732. /**
  733. * 工单工序生产进程右侧
  734. * @ApiMethod GET
  735. * @params string order
  736. * @params string gxNo
  737. */
  738. public function getOrderProcessRight(){
  739. if (Request::instance()->isGet() == false){
  740. $this->error('非法请求');
  741. }
  742. $params = Request::instance()->param();
  743. if (!isset($params['order']) || empty($params['order'])){
  744. $this->error('参数错误');
  745. }
  746. if (!isset($params['yjno']) || empty($params['yjno'])){
  747. $this->error('参数错误');
  748. }
  749. if (!isset($params['gxNo']) || empty($params['gxNo'])){
  750. $this->error('参数错误');
  751. }
  752. $total = db('设备_产量计酬')->where('sczl_gdbh',$params['order'])->where('sczl_yjno',$params['yjno'])->order('sczl_num')->column('distinct(sczl_num)');
  753. $where['sczl_gxh'] = (int)$params['gxNo'];
  754. $where['sczl_gdbh'] = $params['order'];
  755. $where['sczl_yjno'] = $params['yjno'];
  756. //机器设备数据
  757. $process = db('设备_产量计酬')->where($where)->order('sczl_num')->column('distinct(sczl_num)');
  758. //手工数据
  759. $option['qczl_gdbh'] = $params['order'];
  760. $option['qczl_gxh'] = (int)$params['gxNo'];
  761. $option['qczl_yjno'] = $params['yjno'];
  762. $handProcess = db('db_qczl')->where($option)->field('qczl_num,qczl_NumDesc1,qczl_NumDesc2,qczl_NumDesc3,qczl_NumDesc4,qczl_NumDesc5,qczl_NumDesc6,qczl_NumDesc7,qczl_NumDesc8')->select();
  763. // 提取数据
  764. $result = array();
  765. foreach ($handProcess as $subArray) {
  766. $qczl_num = $subArray["qczl_num"];
  767. $result[] = $qczl_num;
  768. // 提取以qczl_NumDesc开头的键对应的值
  769. for ($i = 1; $i <= 8; $i++) {
  770. $key = "qczl_NumDesc" . $i;
  771. if ($subArray[$key] != 0){
  772. $result[] = $subArray[$key];
  773. }
  774. }
  775. }
  776. // 去重
  777. $result = array_unique($result);
  778. // 对结果进行排序
  779. sort($result);
  780. $res['total_process'] = $total;
  781. $res['process'] = $process;
  782. if (empty($process)){
  783. $res['process'] = $result;
  784. }
  785. $this->success('请求成功',$res);
  786. }
  787. /**
  788. * 核检废品日统计
  789. * @ApiMethod GET
  790. * @params date start_date
  791. * @params date end_date
  792. */
  793. public function getDaysWast()
  794. {
  795. if (Request::instance()->isGet() == false) {
  796. $this->error('非法请求');
  797. }
  798. $params = Request::instance()->param();
  799. if (!isset($params['start_date']) || empty($params['start_date'])) {
  800. $this->error('参数错误');
  801. }
  802. if (!isset($params['end_date']) || empty($params['end_date'])) {
  803. $this->error('参数错误');
  804. }
  805. $where['qczl_rq'] = array('between time', [$params['start_date'], $params['end_date']]);
  806. $field = '
  807. 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,
  808. 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,
  809. 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,
  810. 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,
  811. 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,
  812. 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,
  813. qczl_rq
  814. ';
  815. $resultArray = array();
  816. $key = 'getDaysWast'.$params['start_date'].'/'.$params['end_date'];
  817. $is_have_cache = Cache::has($key);
  818. if ($is_have_cache === false){
  819. $data = db('db_qczl')
  820. ->where($where)
  821. ->where(function ($query) {
  822. for ($i = 1; $i <= 13; $i++) {
  823. $query->whereOr("fp_lb$i", 'like', '%K%','AND',"fp_sl$i",'>',0);
  824. }
  825. })
  826. ->field($field)->select();
  827. $list = [];
  828. $j = 0;
  829. foreach ($data as $entry) {
  830. for ($i = 1; $i <= 13; $i++) {
  831. $labelKey = "fp_lb" . $i;
  832. $slKey = "fp_sl" . $i;
  833. $bhKey = "fp_bh" . $i;
  834. $bzKey = "fp_bz" . $i;
  835. if (!empty($entry[$labelKey])) {
  836. if ((substr($entry[$labelKey],0,3) == 'K02' || substr($entry[$labelKey],0,3) == 'K01') && $entry[$slKey] != '0'){
  837. $list[$j]['fp_lb'] = $entry[$labelKey];
  838. $list[$j]['fp_sl'] = $entry[$slKey];
  839. $list[$j]['fp_bh'] = $entry[$bhKey];
  840. $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)');
  841. $list[$j]['fp_name'] = empty($name) ? '计时工' : $name;
  842. $list[$j]['fp_bz'] = $entry[$bzKey];
  843. $list[$j]['qczl_rq'] = $entry['qczl_rq'];
  844. $j++;
  845. }
  846. }
  847. }
  848. }
  849. foreach ($list as $item) {
  850. $found = false;
  851. foreach ($resultArray as &$resultItem) {
  852. if ($item["fp_lb"] === $resultItem["fp_lb"] && $item["fp_bh"] === $resultItem["fp_bh"]) {
  853. $resultItem["fp_sl"] += (int)$item["fp_sl"];
  854. $found = true;
  855. break;
  856. }
  857. }
  858. if (!$found) {
  859. $resultArray[] = $item;
  860. }
  861. }
  862. // 使用usort进行排序
  863. usort($resultArray, function($a, $b) {
  864. // First, sort by fp_lb (K01/K02)
  865. $compareLb = strcmp($a['fp_lb'], $b['fp_lb']);
  866. if ($compareLb !== 0) {
  867. return $compareLb;
  868. }
  869. // If fp_lb is the same, prioritize B班 over A班
  870. $compareBz = strcmp($a['fp_bz'], $b['fp_bz']);
  871. if ($compareBz !== 0) {
  872. return (trim($a['fp_bz']) === 'B班') ? -1 : 1;
  873. }
  874. // If fp_bz is the same, sort by fp_bh
  875. $compareBh = strcmp($a['fp_bh'], $b['fp_bh']);
  876. return $compareBh;
  877. });
  878. Cache::set($key,$resultArray,86400);
  879. }else{
  880. $resultArray = Cache::get($key);
  881. }
  882. $this->success('请求成功',$resultArray);
  883. }
  884. /**
  885. * 月度核检废品责任人统计
  886. * @ApiMethod GET
  887. * @params string date
  888. */
  889. public function getMonthPeopleTotal(){
  890. if (Request::instance()->isGet() == false) {
  891. $this->error('非法请求');
  892. }
  893. $params = Request::instance()->param();
  894. if (!isset($params['date']) || empty($params['date'])) {
  895. $this->error('参数错误');
  896. }
  897. }
  898. /**
  899. * 工单质检废品统计
  900. * @ApiMethod GET
  901. * @params string order
  902. */
  903. public function getOrderWasteTotal(){
  904. if (Request::instance()->isGet() == false) {
  905. $this->error('非法请求');
  906. }
  907. $params = Request::instance()->param();
  908. if (!isset($params['order']) || empty($params['order'])) {
  909. $this->error('参数错误');
  910. }
  911. $field = '
  912. 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,
  913. 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,
  914. 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,
  915. 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,
  916. 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,
  917. 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,
  918. 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.交货日期,
  919. c.yj_ls,d.jjcp_sl,d.jjcp_sj
  920. ';
  921. $where['a.qczl_gdbh'] = $params['order'];
  922. $where['a.qczl_yjno'] = $params['yjno'];
  923. $data = db('db_qczl')->alias('a')
  924. ->join('工单_基本资料 b','a.qczl_gdbh = b.Gd_gdbh AND a.qczl_yjno = b.行号','left')
  925. ->join('工单_印件资料 c','a.qczl_gdbh = c.Yj_Gdbh AND a.qczl_yjno = c.yj_Yjno','left')
  926. ->join('成品入仓 d','a.qczl_gdbh = d.jjcp_gdbh AND a.qczl_yjno = d.jjcp_yjno','left')
  927. ->where($where)
  928. ->field($field)
  929. ->group('a.qczl_yjno,a.sys_rq')
  930. ->select();
  931. $list = [];
  932. $j = 0;
  933. foreach ($data as $entry) {
  934. for ($i = 1; $i <= 13; $i++) {
  935. $labelKey = "fp_lb" . $i;
  936. $slKey = "fp_sl" . $i;
  937. $bhKey = "fp_bh" . $i;
  938. $gxhKey = "fp_gxmc". $i;
  939. if (!empty($entry[$labelKey]) && $entry[$slKey] > 0) {
  940. $list[$j]['fp_lb'] = $entry[$labelKey];
  941. $list[$j]['fp_sl'] = $entry[$slKey];
  942. $list[$j]['fp_bh'] = $entry[$bhKey];
  943. $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)');
  944. $list[$j]['fp_name'] = $name;
  945. $list[$j]['fp_gxh'] = empty(substr($entry[$gxhKey],0,2)) ? "0" : substr($entry[$gxhKey],0,2);
  946. $list[$j]['qczl_num'] = $entry['qczl_num'];
  947. $list[$j]['qczl_yjno'] = $entry['qczl_yjno'];
  948. $list[$j]['product_code'] = $entry['product_code'];
  949. $list[$j]['product_name'] = $entry['product_name'];
  950. $list[$j]['订单数量'] = $entry['订单数量'];
  951. $list[$j]['计量单位'] = $entry['计量单位'];
  952. $list[$j]['交货日期'] = substr($entry['交货日期'],0,10);
  953. $list[$j]['yj_ls'] = $entry['yj_ls'];
  954. $list[$j]['jjcp_sl'] = $entry['jjcp_sl'];
  955. $list[$j]['jjcp_sj'] = substr($entry['jjcp_sj'],0,10);
  956. $j++;
  957. }
  958. }
  959. }
  960. $summedData = [];
  961. foreach ($list as $item) {
  962. $key = $item['qczl_num'] . $item['fp_lb'];
  963. // // if (!isset($summedData[$key])) {
  964. // // $summedData[$key] = $item;
  965. // // } else {
  966. // // $summedData[$key]['fp_sl'] += $item['fp_sl'];
  967. // // }
  968. $summedData[$key] = $item;
  969. }
  970. $fpGxhColumn = array_column($summedData, 'fp_gxh');
  971. $qczlNumColumn = array_column($summedData, 'qczl_num');
  972. $fpLbColumn = array_column($summedData, 'fp_lb');
  973. array_multisort($fpGxhColumn, SORT_ASC, $qczlNumColumn, SORT_ASC, $fpLbColumn, SORT_ASC, $summedData);
  974. $summedData = array_values($summedData);
  975. $summedData = mb_convert_encoding($summedData,'UTF-8','auto');
  976. $this->success('请求成功',$summedData);
  977. }
  978. /**
  979. * 工单核检单删除
  980. * @return void
  981. * @throws \think\Exception
  982. * @throws \think\exception\PDOException
  983. */
  984. public function del()
  985. {
  986. if ($this->request->isGet() === false){
  987. $this->error('请求错误');
  988. }
  989. $param = $this->request->param();
  990. if (empty($param['UniqId'])){
  991. $this->error('参数错误');
  992. }
  993. $res = \db('db_qczl')
  994. ->where('UniqId',$param['UniqId'])
  995. ->delete();
  996. if ($res !== false){
  997. $this->success('删除成功');
  998. }else{
  999. $this->error('产出失败');
  1000. }
  1001. }
  1002. public function getJunkdata()
  1003. {
  1004. if ($this->request->isGet() === false){
  1005. $this->error('请求错误');
  1006. }
  1007. $param = $this->request->param();
  1008. if (empty($param)){
  1009. $this->error('参数错误');
  1010. }
  1011. $sql = "SELECT
  1012. a.jjcp_gdbh,
  1013. a.jjcp_yjno,
  1014. a.jjcp_sj,
  1015. a.jjcp_sl,
  1016. a.成品名称,
  1017. b.fp_lb1,
  1018. b.fp_lb2,
  1019. b.fp_lb3,
  1020. b.fp_lb4,
  1021. b.fp_lb5,
  1022. b.fp_lb6,
  1023. b.fp_lb7,
  1024. b.fp_lb8,
  1025. b.fp_lb9,
  1026. b.fp_lb10,
  1027. b.fp_lb11,
  1028. b.fp_lb12,
  1029. b.fp_lb13,
  1030. b.fp_gxmc1,
  1031. b.fp_gxmc2,
  1032. b.fp_gxmc3,
  1033. b.fp_gxmc4,
  1034. b.fp_gxmc5,
  1035. b.fp_gxmc6,
  1036. b.fp_gxmc7,
  1037. b.fp_gxmc8,
  1038. b.fp_gxmc9,
  1039. b.fp_gxmc10,
  1040. b.fp_gxmc11,
  1041. b.fp_gxmc12,
  1042. b.fp_gxmc13,
  1043. b.fp_sl1,
  1044. b.fp_sl2,
  1045. b.fp_sl3,
  1046. b.fp_sl4,
  1047. b.fp_sl5,
  1048. b.fp_sl6,
  1049. b.fp_sl7,
  1050. b.fp_sl8,
  1051. b.fp_sl9,
  1052. b.fp_sl10,
  1053. b.fp_sl11,
  1054. b.fp_sl12,
  1055. b.fp_sl13,
  1056. sum(b.qczl_fp) as fp,
  1057. b.UniqId,
  1058. c.实际投料 * 10000
  1059. FROM
  1060. `成品入仓` `a`
  1061. LEFT JOIN db_qczl b ON a.jjcp_gdbh = b.qczl_gdbh AND a.jjcp_yjno = b.qczl_yjno
  1062. JOIN `工单_基本资料` c ON a.jjcp_gdbh = c.Gd_gdbh AND a.jjcp_yjno = c.`行号`
  1063. WHERE
  1064. (a.jjcp_sj LIKE '2024-07%'
  1065. OR a.jjcp_sj LIKE '2024-08%')
  1066. AND (b.qczl_fp <> null or b.qczl_fp > 0)
  1067. AND a.成品编码 like 'J0031%'
  1068. GROUP BY
  1069. b.UniqId";
  1070. $res = \db()->query($sql);
  1071. // halt($res);
  1072. $data = [];
  1073. foreach ($res as $key=>$value){
  1074. if (isset($data[$value['jjcp_gdbh']]) === false){
  1075. if (isset($data[$value['jjcp_gdbh']][$value['jjcp_yjno']]) === false){
  1076. $data[$value['jjcp_gdbh']][$value['jjcp_yjno']] = [];
  1077. }
  1078. }
  1079. if (isset($data[$value['jjcp_gdbh']][$value['jjcp_yjno']]['废品总数']) === false){
  1080. $data[$value['jjcp_gdbh']][$value['jjcp_yjno']]['废品总数'] = $value['fp'];
  1081. }else{
  1082. $data[$value['jjcp_gdbh']][$value['jjcp_yjno']]['废品总数'] += $value['fp'];
  1083. }
  1084. $data[$value['jjcp_gdbh']][$value['jjcp_yjno']]['实际投料'] = $value['c.实际投料 * 10000'];
  1085. for ($i=1;$i<14;$i++){
  1086. if ($value['fp_gxmc'.$i] !== ''){
  1087. if (isset($data[$value['jjcp_gdbh']][$value['jjcp_yjno']][$value['fp_lb'.$i]]) === false){
  1088. $data[$value['jjcp_gdbh']][$value['jjcp_yjno']][$value['fp_lb'.$i]] = $value['fp_sl'.$i];
  1089. }else{
  1090. $data[$value['jjcp_gdbh']][$value['jjcp_yjno']][$value['fp_lb'.$i]] += $value['fp_sl'.$i];
  1091. }
  1092. }
  1093. }
  1094. }
  1095. $list = [];
  1096. foreach ($data as $key=>$value){
  1097. foreach ($value as $k=>$v){
  1098. $i = 0;
  1099. foreach ($v as $kk=>$vv){
  1100. if ($kk !== '废品总数' && $kk !== '实际投料'){
  1101. $list[$key][$k][$i] = [
  1102. '类型' => $kk,
  1103. '数量' => $vv,
  1104. '废品占比' => number_format($vv/$v['废品总数']*100,4).'%',
  1105. '报损占比' => number_format($vv/$v['实际投料']*100,4).'%',
  1106. ];
  1107. $i++;
  1108. $result = [
  1109. '类型' => $kk,
  1110. '数量' => $vv,
  1111. '废品占比' => number_format($vv/$v['废品总数']*100,4).'%',
  1112. '报损占比' => number_format($vv/$v['实际投料']*100,4).'%',
  1113. '工单编号' => $key,
  1114. '印件号' => $k
  1115. ];
  1116. $sql = \db('废品报表')->fetchSql(true)->insert($result);
  1117. $reult = \db()->query($sql);
  1118. }
  1119. }
  1120. }
  1121. }
  1122. // $this->success('成功',$list);
  1123. }
  1124. }