FinishedProductWarehousing.php 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\api\controller\OrderSuperLoss;
  5. use think\db\exception\DataNotFoundException;
  6. use think\db\exception\ModelNotFoundException;
  7. use think\exception\DbException;
  8. use think\Db;
  9. /**
  10. * 成品入仓维护接口
  11. */
  12. class FinishedProductWarehousing extends Api
  13. {
  14. protected $noNeedLogin = ['*'];
  15. protected $noNeedRight = ['*'];
  16. /**
  17. * 首页
  18. *成品入仓测试
  19. */
  20. public function index()
  21. {
  22. $this->success('请求成功');
  23. }
  24. /**
  25. * 侧边栏
  26. * @ApiMethod (GET)
  27. */
  28. public function getTab()
  29. {
  30. //get请求
  31. if(!$this->request->isGet()){
  32. $this->error('请求方式错误');
  33. }
  34. $rows = db('成品入仓')
  35. ->field('LEFT(Sys_rq, 10) as date, COUNT(*) as counts')
  36. ->group('date')
  37. ->order('UniqId desc')
  38. ->limit(50)
  39. ->select();
  40. $num = db('成品入仓')
  41. ->where('Sys_rq','>=',$rows[count($rows)-1]['date'])
  42. ->count();
  43. $arr = db('成品入仓')
  44. ->field('LEFT(Sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(*) as count')
  45. ->where('Sys_rq','>=',$rows[count($rows)-1]['date'])
  46. ->group('date, sys_id')
  47. ->limit($num)
  48. ->select();
  49. foreach($rows as $key=>$value){
  50. $rows[$key]['sys'] = [];
  51. foreach($arr as $k=>$v){
  52. if($value['date'] == $v['date']){
  53. unset($v['date']);
  54. array_push($rows[$key]['sys'],$v);
  55. unset($arr[$k]);
  56. }
  57. }
  58. $rows[$key]['date'] = str_replace('-', '.', $rows[$key]['date']);
  59. }
  60. $this->success('成功',$rows);
  61. }
  62. /**
  63. * 侧边栏
  64. * @ApiMethod (GET)
  65. */
  66. public function getTabByGdbh()
  67. {
  68. //get请求
  69. if(!$this->request->isGet()){
  70. $this->error('请求方式错误');
  71. }
  72. $num = db('成品入仓')->count();
  73. $rows = db('成品入仓')
  74. ->field('jjcp_gdbh, rtrim(jjcp_cpdh) as jjcp_cpdh, LEFT(Sys_rq, 10) as Sys_rq')
  75. ->order('Sys_rq desc')
  76. ->limit($num)
  77. ->select();
  78. $num = db('工单_基本资料')->count();
  79. $arr = db('工单_基本资料')
  80. ->limit($num)
  81. ->column('CONCAT(Gd_gdbh, "-", rtrim(Gd_cpdh)) AS gdcp, CONCAT(rtrim(Gd_khdh), " 【", rtrim(Gd_khmc)) AS kh');
  82. $data = [];
  83. foreach ($rows as $value) {
  84. $key = $value['jjcp_gdbh'].'-'.$value['jjcp_cpdh'];
  85. if (isset($arr[$key]) && !isset($data[$arr[$key]])) {
  86. $data[$arr[$key]] = $value['Sys_rq'];
  87. }
  88. }
  89. // 对键进行升序排序
  90. uksort($data, function($a, $b) use ($data) {
  91. if ($data[$a] == $data[$b]) {
  92. return ($a > $b) ? 1 : -1; // 在值相同的情况下,根据键进行升序排列
  93. }
  94. return ($data[$a] < $data[$b]) ? 1 : -1;
  95. });
  96. $this->success('成功',$data);
  97. }
  98. /**
  99. * 列表
  100. * @ApiMethod (GET)
  101. * @param string $date 时间
  102. * @param string $sys_id 用户
  103. */
  104. public function getList()
  105. {
  106. // 验证请求方式
  107. if (!$this->request->isGet()) {
  108. $this->error('请求方式错误');
  109. }
  110. $req = $this->request->param();
  111. if (!isset($req['date'])) {
  112. $this->error('参数缺失');
  113. }
  114. // 设置分页参数,默认值
  115. $page = isset($req['page']) && !empty($req['page']) ? intval($req['page']) : 1;
  116. $limit = isset($req['limit']) && !empty($req['limit']) ? intval($req['limit']) : 20;
  117. // 构建查询条件
  118. if (strpos($req['date'], '-')) {
  119. $where = ['c.Sys_rq' => ['like', $req['date'] . '%']];
  120. $option = ['Sys_rq' => ['like', $req['date'] . '%']];
  121. } else {
  122. $where = [];
  123. $option = [];
  124. }
  125. if (isset($req['sys_id']) && !empty($req['sys_id'])) {
  126. $where['c.Sys_id'] = ['LIKE', $req['sys_id'] . '%'];
  127. $option['Sys_id'] = ['LIKE', $req['sys_id'] . '%'];
  128. }
  129. // 获取总数
  130. $total = db('成品入仓')->where($option)->count();
  131. // 查询数据(带分页)
  132. $rows = db('成品入仓')->alias('c')
  133. ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
  134. rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh,
  135. c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj,
  136. rtrim(c.jjcp_smb) as jjcp_smb, rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  137. rtrim(c.成品编码) as 成品编码, rtrim(c.成品名称) as 成品名称,
  138. rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, LEFT(c.成品编码,'.config('product_code_digit').') as 客户编号, rtrim(g.Gd_客户名称) as Gd_客户名称,
  139. rtrim(c.机型备注) as 机型备注, rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
  140. ->where($where)
  141. ->join('工单_基本资料 g', 'g.Gd_gdbh=c.jjcp_gdbh AND g.行号 = c.jjcp_yjno AND g.Gd_cpdh=c.jjcp_cpdh')
  142. ->order('c.UniqId desc')
  143. ->limit(($page - 1) * $limit, $limit)
  144. ->select();
  145. // 处理数据
  146. foreach ($rows as $key => $value) {
  147. $row = db('成品入仓')
  148. ->field('LEFT(Sys_rq, 10) as Sys_rq,jjcp_sl')
  149. ->where(['jjcp_gdbh' => $value['jjcp_gdbh'], 'jjcp_cpdh' => $value['jjcp_cpdh']])
  150. ->order('Sys_rq desc')
  151. ->select();
  152. $rows[$key]['jjcp_sls'] = 0;
  153. foreach ($row as $k => $v) {
  154. $rows[$key]['jjcp_sls'] += $v['jjcp_sl'];
  155. }
  156. if ($value['订单数量'] != 0) {
  157. $rows[$key]['完成率'] = number_format($rows[$key]['jjcp_sls'] / $value['订单数量'] / 100, 2);
  158. } else {
  159. $rows[$key]['完成率'] = '';
  160. }
  161. $rows[$key]['订单数量'] = floatval($value['订单数量'] * 10000);
  162. $rows[$key]['最近入仓日期'] = $row[0]['Sys_rq'];
  163. $rows[$key]['Mod_rq'] = $value['Mod_rq'] == '1900-01-01 00:00:00' ? '' : $value['Mod_rq'];
  164. }
  165. $data = [
  166. 'total' => $total,
  167. 'rows' => $rows,
  168. ];
  169. $this->success('成功', $data);
  170. }
  171. /**
  172. * 定位
  173. * @ApiMethod (GET)
  174. * @param string $gdbh 工单编号
  175. * @param string $cpmc 产品名称
  176. * @param string $page 页码
  177. * @param string $limit 数量
  178. */
  179. public function locate()
  180. {
  181. //get请求
  182. if(!$this->request->isGet()){
  183. $this->error('请求方式错误');
  184. }
  185. $req = $this->request->param();
  186. $page = 1;
  187. $limit = 15;
  188. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  189. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  190. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  191. $where = ['c.jjcp_gdbh'=>[ 'like', '%' . $req['gdbh'] . '%']];
  192. $option = ['jjcp_gdbh'=>[ 'like', '%' . $req['gdbh'] . '%']];
  193. //客户编号
  194. $rows = db('成品入仓')->alias('c')
  195. ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
  196. rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh,
  197. c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj,
  198. rtrim(c.jjcp_smb) as jjcp_smb, rtrim(y.yj_Yjdh) as yj_Yjdh, rtrim(y.yj_yjmc) as yj_yjmc,
  199. rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  200. rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, LEFT(c.成品编码,'.config('product_code_digit').') as 客户编号, rtrim(g.Gd_客户名称) as Gd_客户名称,
  201. rtrim(c.机型备注) as 机型备注, rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
  202. ->where($where)
  203. ->where('y.yj_Yjno=c.jjcp_yjno')
  204. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  205. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  206. ->join('工单_印件资料 y','y.Yj_Gdbh=c.jjcp_gdbh')
  207. ->order('c.UniqId desc')
  208. ->page($page,$limit)
  209. ->select();
  210. $total = db('成品入仓')->where($option)->count();
  211. }else{
  212. if (isset($req['cpmc']) && !empty($req['cpmc'])){
  213. //查询工单表
  214. $gd = db('工单_基本资料')
  215. ->where('Gd_cpmc', 'LIKE', '%'.$req['cpmc'].'%')
  216. ->column('Gd_gdbh');
  217. $where = ['c.jjcp_gdbh'=>['in', $gd]];
  218. $option = ['jjcp_gdbh'=>['in', $gd]];
  219. //客户编号
  220. $rows = db('成品入仓')->alias('c')
  221. ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
  222. rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh,
  223. c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj,
  224. rtrim(c.jjcp_smb) as jjcp_smb, rtrim(y.yj_Yjdh) as yj_Yjdh, rtrim(y.yj_yjmc) as yj_yjmc,
  225. rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  226. rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, LEFT(c.成品编码,'.config('product_code_digit').') as 客户编号, rtrim(g.Gd_客户名称) as Gd_客户名称,
  227. rtrim(c.机型备注) as 机型备注, rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
  228. ->where($where)
  229. ->where('y.yj_Yjno=c.jjcp_yjno')
  230. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  231. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  232. ->join('工单_印件资料 y','y.Yj_Gdbh=c.jjcp_gdbh')
  233. ->order('c.UniqId desc')
  234. ->page($page,$limit)
  235. ->select();
  236. $total = db('成品入仓')->where($option)->count();
  237. }else{
  238. $this->error('参数错误');
  239. }
  240. }
  241. foreach ($rows as $key=>$value) {
  242. $row = db('成品入仓')
  243. ->field('LEFT(Sys_rq, 10) as Sys_rq,jjcp_sl')
  244. ->where(['jjcp_gdbh'=>$value['jjcp_gdbh'], 'jjcp_cpdh'=>$value['jjcp_cpdh']])
  245. ->order('Sys_rq desc')
  246. ->select();
  247. $rows[$key]['jjcp_sls'] = 0;
  248. foreach ($row as $k=>$v) {
  249. $rows[$key]['jjcp_sls'] += $v['jjcp_sl'];
  250. }
  251. if ($value['订单数量']!=0){
  252. $rows[$key]['完成率'] = number_format($rows[$key]['jjcp_sls']/$value['订单数量']/100,2);
  253. }else{
  254. $rows[$key]['完成率'] = '';
  255. }
  256. $rows[$key]['订单数量'] = floatval($value['订单数量']*10000);
  257. $rows[$key]['最近入仓日期'] = $row[0]['Sys_rq'];
  258. $rows[$key]['Mod_rq'] = $value['Mod_rq']=='1900-01-01 00:00:00' ? '' :$value['Mod_rq'];
  259. }
  260. $data = [
  261. 'total' => $total,
  262. 'rows' => $rows,
  263. ];
  264. $this->success('成功',$data);
  265. }
  266. /**
  267. * 获取信息
  268. * @ApiMethod (GET)
  269. * @param string $UniqId UniqId
  270. */
  271. public function getInfo()
  272. {
  273. //get请求
  274. if(!$this->request->isGet()){
  275. $this->error('请求方式错误');
  276. }
  277. $req = $this->request->param();
  278. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  279. $UniqId = $req['UniqId'];
  280. }else{
  281. $this->error('参数错误');
  282. }
  283. //客户编号
  284. $rows = db('成品入仓')->alias('c')
  285. ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
  286. rtrim(c.jjcp_num) as jjcp_num,
  287. c.jjcp_gdbh, c.jjcp_yjno, rtrim(c.订单编号) as 订单编号,
  288. rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  289. rtrim(c.成品编码) as 成品编码, rtrim(c.成品名称) as 成品名称,
  290. rtrim(c.客户料号) as 客户料号,
  291. rtrim(c.jjcp_smb) as jjcp_smb, LEFT(c.jjcp_sj, 10) as jjcp_sj,
  292. c.jjcp_sl, rtrim(c.jjcp_dw) as jjcp_dw,
  293. g.订单数量*10000 as 订单数量, rtrim(c.机型备注) as 机型备注, rtrim(c.jjcp_desc) as jjcp_desc,
  294. rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
  295. ->where('c.UniqId',$UniqId)
  296. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  297. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  298. ->find();
  299. $rows['jjcp_sls'] = db('成品入仓')
  300. ->where(['jjcp_gdbh'=>$rows['jjcp_gdbh'], 'jjcp_cpdh'=>$rows['jjcp_cpdh']])
  301. ->sum('jjcp_sl');
  302. $this->success('成功',$rows);
  303. }
  304. /**
  305. * 获取仓库信息
  306. * @ApiMethod (GET)
  307. * @param string keyword 关键词
  308. */
  309. public function getCk()
  310. {
  311. //get请求
  312. if(!$this->request->isGet()){
  313. $this->error('请求方式错误');
  314. }
  315. $req = $this->request->param();
  316. $key_word = '';
  317. if (isset($req['key_word']) && !empty($req['key_word'])){
  318. $key_word = $req['key_word'];
  319. }
  320. $rs = db('物料_仓库信息')
  321. ->field('rtrim(编号) as 编号, rtrim(名称) as 名称')
  322. ->where('编号|名称','like','%'.$key_word.'%')
  323. ->where('名称','in',['面材仓库','主要产成品'])
  324. ->select();
  325. $this->success('成功',$rs);
  326. }
  327. /**
  328. * 查询印件工序及产品名称
  329. * @ApiMethod (GET)
  330. * @param string $gdbh 工单编号
  331. */
  332. public function getGd()
  333. {
  334. //get请求
  335. if(!$this->request->isGet()){
  336. $this->error('请求方式错误');
  337. }
  338. $req = $this->request->param();
  339. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  340. $gdbh = $req['gdbh'];
  341. }else{
  342. $this->error('参数错误');
  343. }
  344. $rows = db('工单_基本资料')->alias('g')
  345. ->field('g.Gd_gdbh, j.yj_yjno, rtrim(g.销售订单号) as 销售订单号, rtrim(j.yj_Yjdh) as yj_Yjdh, rtrim(j.yj_yjmc) as yj_yjmc, rtrim(g.成品代号) as 成品代号, rtrim(g.成品名称) as 成品名称, rtrim(g.客户料号) as 客户料号')
  346. ->where(['g.Gd_gdbh'=>$gdbh])
  347. ->join(['工单_印件资料'=>'j'],'g.Gd_cpdh=j.yj_yjdh and g.Gd_gdbh=j.Yj_Gdbh')
  348. ->group('j.yj_yjno')
  349. ->order('j.yj_yjno asc')
  350. ->select();
  351. foreach ($rows as $key=>$value){
  352. $rows[$key]['gdyj'] = $value['Gd_gdbh'].' -'.sprintf("%02d", $value['yj_yjno']).'-'.$value['yj_yjmc'];
  353. }
  354. $this->success('成功',$rows);
  355. }
  356. /**
  357. * 查询工单数量
  358. * @ApiMethod (GET)
  359. * @param string $gdbh 工单编号
  360. * @param string $cpdh 产品代号
  361. * @param string $rcsl 入仓数量
  362. */
  363. public function getGdsl()
  364. {
  365. //get请求
  366. if(!$this->request->isGet()){
  367. $this->error('请求方式错误');
  368. }
  369. $req = $this->request->param();
  370. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  371. $gdbh = $req['gdbh'];
  372. }else{
  373. $this->error('参数错误');
  374. }
  375. if (isset($req['cpdh']) && !empty($req['cpdh'])){
  376. $cpdh = $req['cpdh'];
  377. }else{
  378. $this->error('参数错误');
  379. }
  380. $rows = db('工单_基本资料')->alias('g')
  381. ->field('订单数量*10000 as 订单数量, gd_statu')
  382. ->where(['Gd_gdbh'=>$gdbh, 'Gd_cpdh'=>$cpdh])
  383. ->find();
  384. if (!$rows) $this->error('未查询到记录');
  385. $rows['jjcp_sls'] = db('成品入仓')
  386. ->where(['jjcp_gdbh'=>$gdbh, 'jjcp_cpdh'=>$cpdh])
  387. ->sum('jjcp_sl');
  388. $this->success('成功',$rows);
  389. }
  390. /**
  391. * 新增
  392. * @ApiMethod (POST)
  393. */
  394. public function add()
  395. {
  396. if (!$this->request->isPost()) {
  397. $this->error('请求方式错误');
  398. }
  399. $req = $this->request->param();
  400. $data = $this->buildAddData($req);
  401. $this->validateProductName($data['jjcp_gdbh'], $data['jjcp_yjno'], $data['jjcp_cpmc']);
  402. $existingEndBoard = $this->findExistingEndBoard($data['jjcp_gdbh'], $data['jjcp_yjno']);
  403. if ($existingEndBoard) {
  404. $this->error(
  405. $existingEndBoard['jjcp_gdbh'] . '工单 -- 印件' . $existingEndBoard['jjcp_yjno'] . '已经进入末版,无法继续操作'
  406. );
  407. }
  408. $this->validateMaterialReceived($data['jjcp_gdbh'], $data['jjcp_yjno']);
  409. $data['UniqId'] = $this->generateFinishStockUniqId();
  410. $mongodb = Db::connect(config('database.mongodb'));
  411. $this->saveFinishStock($data, $mongodb);
  412. // 接单日期在 2026-08-01 及以后,且中间库 U8_06工单资料存在该工单时才同步
  413. if ($this->shouldSyncFinishStockMiddle($data['jjcp_gdbh'])) {
  414. try {
  415. $synchronization = new \app\api\controller\Synchronization();
  416. $synchronization->syncFinishStockMiddle($data['UniqId'], '新增');
  417. } catch (\Exception $e) {
  418. $this->error('成品入仓已保存,但' . $e->getMessage(), ['UniqId' => $data['UniqId']]);
  419. }
  420. }
  421. if ($this->isEndBoard($data['jjcp_smb'])) {
  422. $this->handleEndBoardSuperLoss($data['jjcp_gdbh'], $data['jjcp_yjno']);
  423. }
  424. $this->success('成功', ['UniqId' => $data['UniqId']]);
  425. }
  426. /**
  427. * 查询成品入仓同步操作日志
  428. * @ApiMethod (GET)
  429. * @param int|string $UniqId 成品入仓 UniqId
  430. */
  431. public function getSyncLog()
  432. {
  433. if (!$this->request->isGet()) {
  434. $this->error('请求方式错误');
  435. }
  436. $uniqId = $this->request->param('UniqId');
  437. if ($uniqId === null || $uniqId === '') {
  438. $this->error('参数错误', 'UniqId');
  439. }
  440. $list = db('工单_成品入仓同步操作日志')
  441. ->where('UniqId', (int)$uniqId)
  442. ->field('id,Gdbh,wlbm,yjmc,Yjdh,Yjno,sys_id,sys_rq,type,status,status_msg,UniqId')
  443. ->order('id desc')
  444. ->select();
  445. $this->success('成功', $list ?: []);
  446. }
  447. /**
  448. * 修改
  449. * 前端传:UniqId、数量(jjcp_sl)、smb(jjcp_smb)、sys_id(Sys_id)、时间(jjcp_sj)
  450. * @ApiMethod (POST)
  451. */
  452. public function edit()
  453. {
  454. if (!$this->request->isPost()) {
  455. $this->error('请求方式错误');
  456. }
  457. $req = $this->request->param();
  458. $uniqId = $req['UniqId'] ?? ($req['UniaId'] ?? null);
  459. if ($uniqId === null || trim((string)$uniqId) === '') {
  460. $this->error('参数错误', 'UniqId', 100);
  461. }
  462. $uniqId = (int)$uniqId;
  463. $old = db('成品入仓')->where('UniqId', $uniqId)->find();
  464. if (empty($old)) {
  465. $this->error('未找到成品入仓记录');
  466. }
  467. $hasQty = array_key_exists('jjcp_sl', $req) || array_key_exists('数量', $req);
  468. $hasSmb = array_key_exists('jjcp_smb', $req) || array_key_exists('smb', $req);
  469. $hasSj = array_key_exists('jjcp_sj', $req);
  470. $sysId = $req['Sys_id'] ?? ($req['sys_id'] ?? null);
  471. if (!$hasQty && !$hasSmb && !$hasSj && ($sysId === null || $sysId === '')) {
  472. $this->error('参数错误', '', 111);
  473. }
  474. $data = ['Mod_rq' => date('Y-m-d H:i:s')];
  475. if ($sysId !== null && $sysId !== '') {
  476. $data['Sys_id'] = $sysId;
  477. }
  478. if ($hasSj) {
  479. $data['jjcp_sj'] = $req['jjcp_sj'];
  480. }
  481. $oldQty = (float)$old['jjcp_sl'];
  482. $newQty = $oldQty;
  483. $qtyChanged = false;
  484. if ($hasQty) {
  485. $newQty = (float)($req['jjcp_sl'] ?? $req['数量']);
  486. $data['jjcp_sl'] = $newQty;
  487. $qtyChanged = abs($newQty - $oldQty) > 0.00001;
  488. }
  489. $oldSmb = (string)$old['jjcp_smb'];
  490. $newSmb = $oldSmb;
  491. $smbChanged = false;
  492. if ($hasSmb) {
  493. $newSmb = (string)($req['jjcp_smb'] ?? $req['smb']);
  494. $data['jjcp_smb'] = $newSmb;
  495. $smbChanged = trim($newSmb) !== trim($oldSmb);
  496. }
  497. $sjChanged = false;
  498. if ($hasSj) {
  499. $sjChanged = trim((string)$req['jjcp_sj']) !== trim((string)$old['jjcp_sj']);
  500. }
  501. // 改为末板时,校验同工单同印件是否已有其他末板记录
  502. if ($smbChanged && $this->isEndBoard($newSmb)) {
  503. $existingEndBoard = $this->findExistingEndBoard($old['jjcp_gdbh'], $old['jjcp_yjno']);
  504. if ($existingEndBoard && (int)$existingEndBoard['UniqId'] !== $uniqId) {
  505. $this->error(
  506. $existingEndBoard['jjcp_gdbh'] . '工单 -- 印件' . $existingEndBoard['jjcp_yjno'] . '已经进入末版,无法继续操作'
  507. );
  508. }
  509. }
  510. $mongodb = Db::connect(config('database.mongodb'));
  511. db()->startTrans();
  512. try {
  513. $sql = db('成品入仓')->where('UniqId', $uniqId)->fetchSql(true)->update($data);
  514. $bool = db()->query($sql);
  515. $mongodb->name('finished_products')
  516. ->where('UniqId', $uniqId)
  517. ->update($data);
  518. db()->commit();
  519. } catch (\Exception $e) {
  520. db()->rollback();
  521. $this->error($e->getMessage());
  522. }
  523. if ($bool === false) {
  524. $this->error('失败');
  525. }
  526. // 同步中间表:
  527. // - 数量变更:插入差值为新同步数据(增加为正、减少为负)
  528. // - 仅修改 smb / 时间:正常同步完整数量
  529. // - 数量与其他同时改:只同步差值
  530. if ($this->shouldSyncFinishStockMiddle($old['jjcp_gdbh']) && ($qtyChanged || $smbChanged || $sjChanged)) {
  531. try {
  532. $synchronization = new \app\api\controller\Synchronization();
  533. if ($qtyChanged) {
  534. $qtyDiff = $newQty - $oldQty; // 增加为正,减少为负
  535. $synchronization->syncFinishStockMiddle($uniqId, '修改', $qtyDiff, $sysId);
  536. } else {
  537. $synchronization->syncFinishStockMiddle($uniqId, '修改', null, $sysId);
  538. }
  539. } catch (\Exception $e) {
  540. $this->error('成品入仓已保存,但' . $e->getMessage(), ['UniqId' => $uniqId]);
  541. }
  542. }
  543. if ($smbChanged && $this->isEndBoard($newSmb)) {
  544. $this->handleEndBoardSuperLoss($old['jjcp_gdbh'], $old['jjcp_yjno']);
  545. }
  546. $this->success('成功');
  547. }
  548. /**
  549. * 删除
  550. * 前端传:UniqId、sys_id(Sys_id)
  551. * @ApiMethod (POST)
  552. */
  553. public function del()
  554. {
  555. if (!$this->request->isPost()) {
  556. $this->error('请求方式错误');
  557. }
  558. $req = $this->request->param();
  559. if (!(isset($req['UniqId']) && trim($req['UniqId']) != '')) {
  560. $this->error('参数错误', 'UniqId', 100);
  561. }
  562. $sysId = $req['Sys_id'] ?? ($req['sys_id'] ?? null);
  563. if ($sysId === null || trim((string)$sysId) === '') {
  564. $this->error('参数错误', 'sys_id', 101);
  565. }
  566. $uniqId = (int)$req['UniqId'];
  567. $old = db('成品入仓')->where('UniqId', $uniqId)->find();
  568. if (empty($old)) {
  569. $this->error('未找到成品入仓记录');
  570. }
  571. // 满足同步条件才回冲:MES插入类型=新增,数量取负;不满足则正常删除
  572. if ($this->shouldSyncFinishStockMiddle($old['jjcp_gdbh'])) {
  573. try {
  574. $synchronization = new \app\api\controller\Synchronization();
  575. $synchronization->syncFinishStockMiddle(
  576. $uniqId,
  577. '新增',
  578. -1 * (float)$old['jjcp_sl'],
  579. $sysId
  580. );
  581. } catch (\Exception $e) {
  582. $this->error('同步中间表失败,未删除:' . $e->getMessage(), ['UniqId' => $uniqId]);
  583. }
  584. }
  585. $mongodb = Db::connect(config('database.mongodb'));
  586. db()->startTrans();
  587. try {
  588. $sql = db('成品入仓')->where('UniqId', $uniqId)->fetchSql(true)->delete();
  589. $bool = db()->query($sql);
  590. $mongodb->name('finished_products')
  591. ->where('UniqId', $uniqId)
  592. ->delete();
  593. db()->commit();
  594. } catch (\Exception $e) {
  595. db()->rollback();
  596. $this->error($e->getMessage());
  597. }
  598. if ($bool === false) {
  599. $this->error('失败');
  600. }
  601. $this->success('成功');
  602. }
  603. /**
  604. * excel导出
  605. * @ApiMethod (POST)
  606. * @param string date
  607. * @param string sys_id
  608. * @param array fields
  609. */
  610. public function export(){
  611. if(!$this->request->isGet()){
  612. $this->error('请求方式错误');
  613. }
  614. $req = $this->request->param();
  615. if (!isset($req['date'])) $this->error('参数缺失');
  616. if (!(isset($req['fields']) && count($req['fields'])!=0)){
  617. $this->error('参数错误','fields',100);
  618. }
  619. if(strpos($req['date'],'-')){
  620. $where = ['c.Sys_rq'=>['like',$req['date'].'%']];
  621. }else if(empty($req['date'])){
  622. $where = [];
  623. }else{
  624. $where = ['c.jjcp_gdbh'=>$req['date']];
  625. }
  626. if (isset($req['sys_id']) && !empty($req['sys_id'])){
  627. $where['c.Sys_id'] = ['LIKE',$req['sys_id'].'%'];
  628. }
  629. $arr = [
  630. '入仓类型' =>['入仓类型'],
  631. '仓库编号' =>['仓库编号'],
  632. '仓库名称' =>['仓库名称'],
  633. 'jjcp_num' =>['入仓单号'],
  634. 'jjcp_gdbh' =>['工单编号'],
  635. 'jjcp_yjno' =>['印件号'],
  636. 'jjcp_sl' =>['入仓数量'],
  637. 'jjcp_sls' =>['累计入仓数量'],
  638. '订单数量' =>['订单数量'],
  639. '完成率' =>['完成率'],
  640. 'jjcp_dw' =>['单位'],
  641. 'jjcp_sj' =>['入仓时间'],
  642. 'jjcp_smb' =>['首末板'],
  643. 'jjcp_cpdh' =>['印件代号'],
  644. 'jjcp_cpmc' =>['印件名称'],
  645. '成品编码' =>['产品编号'],
  646. '成品名称' =>['产品名称'],
  647. '客户料号' =>['客户料号'],
  648. 'jjcp_desc' =>['备注'],
  649. '客户编号' =>['客户编号'],
  650. 'Gd_客户名称' =>['客户名称'],
  651. '最近入仓日期' =>['最近入仓日期'],
  652. '机型备注' =>['机型备注'],
  653. ];
  654. $data[0] = [];
  655. foreach ($req['fields'] as $k=>$v){
  656. if(array_key_exists($v,$arr)){
  657. array_push($data[0],$arr[$v][0]);
  658. }
  659. }
  660. $num = db('成品入仓')->alias('c')
  661. ->where($where)
  662. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  663. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  664. ->count();
  665. $rows = [];
  666. for($i=1;$i<=ceil($num/10000);$i++){
  667. $p = $i == ceil($num/10000) ? $num%10000 : 10000;
  668. $r = db('成品入仓')->alias('c')
  669. ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
  670. rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh,
  671. c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj,
  672. rtrim(c.jjcp_smb) as jjcp_smb, rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  673. rtrim(c.成品编码) as 成品编码, rtrim(c.成品名称) as 成品名称,
  674. rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, LEFT(c.成品编码,'.config('product_code_digit').') as 客户编号, rtrim(g.Gd_客户名称) as Gd_客户名称,
  675. rtrim(c.机型备注) as 机型备注')
  676. ->where($where)
  677. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  678. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  679. ->order('c.UniqId desc')
  680. ->limit($i,$p)
  681. ->select();
  682. $rows = array_merge($rows,$r);
  683. }
  684. foreach ($rows as $key=>$value) {
  685. $row = db('成品入仓')
  686. ->field('LEFT(Sys_rq, 10) as Sys_rq,jjcp_sl')
  687. ->where(['jjcp_gdbh'=>$value['jjcp_gdbh'], 'jjcp_cpdh'=>$value['jjcp_cpdh']])
  688. ->order('Sys_rq desc')
  689. ->select();
  690. $subArray = [];
  691. foreach ($arr as $k=>$v){
  692. if($k=='jjcp_sls'){
  693. $subArray[$k] = 0;
  694. foreach ($row as $n) {
  695. $subArray[$k] += $n['jjcp_sl'];
  696. }
  697. }else if($k=='完成率'){
  698. if ($value['订单数量']!=0){
  699. $subArray[$k] = 0;
  700. foreach ($row as $n) {
  701. $subArray[$k] += $n['jjcp_sl'];
  702. }
  703. $subArray[$k] = number_format($subArray[$k]/$value['订单数量']/100,2);
  704. }else{
  705. $subArray[$k] = '';
  706. }
  707. }else if($k=='最近入仓日期'){
  708. $subArray[$k] = $row[0]['Sys_rq'];
  709. }else{
  710. $subArray[$k] = $rows[$key][$k];
  711. }
  712. }
  713. array_push($data,$subArray);
  714. }
  715. $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
  716. }
  717. /**
  718. * 月度A
  719. * @ApiMethod (POST)
  720. * @param string start_time
  721. * @param string end_time
  722. * @param string file_name
  723. * @param array fields
  724. */
  725. public function monthExportA(){
  726. if(!$this->request->isGet()){
  727. $this->error('请求方式错误');
  728. }
  729. $req = $this->request->param();
  730. $arr = [
  731. 'start_time', 'end_time', 'file_name'
  732. ];
  733. foreach ($arr as $key => $value){
  734. if (!isset($req[$value])){
  735. $this->error('参数错误',$value,$key+1);
  736. }
  737. }
  738. if (!(isset($req['fields']) && count($req['fields'])!=0)){
  739. $this->error('参数错误','fields',100);
  740. }
  741. $arr = [
  742. '入仓类型' =>['入仓类型'],
  743. '仓库编号' =>['仓库编号'],
  744. '仓库名称' =>['仓库名称'],
  745. 'jjcp_gdbh' =>['工单编号'],
  746. 'jjcp_cpdh' =>['入仓存货编号'],
  747. 'jjcp_cpmc' =>['入仓存货名称'],
  748. 'jjcp_sl' =>['入仓数量'],
  749. 'jjcp_dw' =>['单位'],
  750. 'jjcp_sj' =>['入仓时间'],
  751. 'jjcp_smb' =>['首末板'],
  752. 'jjcp_num' =>['单据编号'],
  753. '订单编号' =>['订单编号'],
  754. ];
  755. $data[0] = [];
  756. foreach ($req['fields'] as $k=>$v){
  757. if(array_key_exists($v,$arr)){
  758. array_push($data[0],$arr[$v][0]);
  759. }
  760. }
  761. //客户编号
  762. $rows = db('成品入仓')->alias('c')
  763. ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
  764. c.jjcp_gdbh, rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  765. c.jjcp_sl, rtrim(c.jjcp_dw) as jjcp_dw, c.jjcp_sj,
  766. rtrim(c.jjcp_smb) as jjcp_smb,
  767. rtrim(c.jjcp_num) as jjcp_num, rtrim(c.订单编号) as 订单编号
  768. ')
  769. ->where('c.jjcp_sj','between time',[$req['start_time'], $req['end_time']])
  770. ->order('c.jjcp_sj asc')
  771. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  772. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  773. ->select();
  774. foreach ($rows as $key=>$value) {
  775. $subArray = [];
  776. foreach ($arr as $k=>$v){
  777. $subArray[$k] = $rows[$key][$k];
  778. }
  779. array_push($data,$subArray);
  780. }
  781. $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
  782. }
  783. /**
  784. * 月度B
  785. * @ApiMethod (POST)
  786. * @param string start_time
  787. * @param string end_time
  788. * @param string file_name
  789. * @param array fields
  790. */
  791. public function monthExportB(){
  792. if(!$this->request->isGet()){
  793. $this->error('请求方式错误');
  794. }
  795. $req = $this->request->param();
  796. $arr = [
  797. 'start_time', 'end_time', 'file_name'
  798. ];
  799. foreach ($arr as $key => $value){
  800. if (!isset($req[$value])){
  801. $this->error('参数错误',$value,$key+1);
  802. }
  803. }
  804. if (!(isset($req['fields']) && count($req['fields'])!=0)){
  805. $this->error('参数错误','fields',100);
  806. }
  807. $arr = [
  808. '入仓类型' =>['入仓类型'],
  809. '客户编号' =>['客户编号'],
  810. '客户名称' =>['客户名称'],
  811. '产品类别' =>['产品类别'],
  812. 'jjcp_gdbh' =>['工单编号'],
  813. '成品编码' =>['成品编码'],
  814. '成品名称' =>['成品名称'],
  815. 'jjcp_sls' =>['入仓数量'],
  816. '大箱产量' =>['大箱产量'],
  817. '产品单价' =>['万张单价'],
  818. '产值万元' =>['产值万元'],
  819. ];
  820. $data[0] = [];
  821. foreach ($req['fields'] as $k=>$v){
  822. if(array_key_exists($v,$arr)){
  823. array_push($data[0],$arr[$v][0]);
  824. }
  825. }
  826. $rows1 = db('成品入仓')->alias('c')
  827. ->field('rtrim(c.入仓类型) as 入仓类型, LEFT(c.成品编码,'.config('product_code_digit').') as 客户编号, rtrim(b.客户名称) as 客户名称,
  828. rtrim(b.产品类别) as 产品类别, c.jjcp_gdbh,
  829. rtrim(c.成品编码) as 成品编码, rtrim(c.成品名称) as 成品名称
  830. ')
  831. ->where('c.jjcp_sj','between time',[$req['start_time'], $req['end_time']])
  832. ->order('客户编号 asc,b.产品类别 desc,c.成品编码 asc,c.jjcp_gdbh asc')
  833. ->join('产品_基本资料 b','b.产品编号=c.jjcp_cpdh')
  834. ->group('c.jjcp_gdbh')
  835. ->select();
  836. $rows2 = db('成品入仓')
  837. ->field('rtrim(入仓类型) as 入仓类型, rtrim(成品编码) as 客户编号,
  838. rtrim(成品编码) as 客户名称, rtrim(成品编码) as 产品类别,
  839. jjcp_gdbh,rtrim(成品编码) as 成品编码, rtrim(成品名称) as 成品名称
  840. ')
  841. ->where('jjcp_sj','between time',[$req['start_time'], $req['end_time']])
  842. ->where('成品编码','')
  843. ->order('jjcp_gdbh asc')
  844. ->group('jjcp_gdbh')
  845. ->select();
  846. $rows = array_merge($rows2,$rows1);
  847. $num = db('工单_基本资料')->count();
  848. $arr1 = db('工单_基本资料')->limit($num)
  849. ->column('CONCAT(Gd_gdbh, "-", rtrim(Gd_cpdh)) AS gdcp, 产品单价 as 万张单价');
  850. $brr = array_column($rows,'jjcp_gdbh');
  851. $brr = db('成品入仓')
  852. ->where('jjcp_gdbh', 'in', $brr)
  853. ->group('jjcp_gdbh')
  854. ->column('jjcp_gdbh, sum(jjcp_sl)');
  855. foreach ($rows as $key=>$value) {
  856. $subArray = [];
  857. foreach ($arr as $k=>$v){
  858. if($k=='jjcp_sls'){
  859. $subArray[$k] = $brr[$value['jjcp_gdbh']];
  860. }else if ($k=='大箱产量'){
  861. if($value['产品类别']=='条盒'){
  862. $subArray[$k] = $brr[$value['jjcp_gdbh']]/250;
  863. }else if($value['产品类别']=='小盒'){
  864. $subArray[$k] = $brr[$value['jjcp_gdbh']]/2500;
  865. }else{
  866. $subArray[$k] = 0;
  867. }
  868. }else if ($k=='产品单价'){
  869. if($value['产品类别']!=''){
  870. if (array_key_exists($value['jjcp_gdbh'].'-'.$value['成品编码'],$arr1)){
  871. $subArray[$k] = floatval(number_format($arr1[$value['jjcp_gdbh'].'-'.$value['成品编码']],4));
  872. }
  873. }else{
  874. $subArray[$k] = 0;
  875. }
  876. }else if ($k=='产值万元'){
  877. if($value['产品类别']!=''){
  878. if (array_key_exists($value['jjcp_gdbh'].'-'.$value['成品编码'],$arr1)){
  879. $subArray[$k] = floatval(number_format($arr1[$value['jjcp_gdbh'].'-'.$value['成品编码']]*$brr[$value['jjcp_gdbh']]/100000000,2));
  880. }
  881. }else{
  882. $subArray[$k] = 0;
  883. }
  884. }else{
  885. $subArray[$k] = $rows[$key][$k];
  886. }
  887. }
  888. array_push($data,$subArray);
  889. }
  890. $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
  891. }
  892. /**
  893. * 各日统计列表
  894. * @ApiMethod (GET)
  895. * @param string $date 时间
  896. * @param string $sys_id 用户
  897. */
  898. public function getDayList()
  899. {
  900. //get请求
  901. if(!$this->request->isGet()){
  902. $this->error('请求方式错误');
  903. }
  904. $req = $this->request->param();
  905. $page = 1;
  906. $limit = 15;
  907. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  908. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  909. $where = [
  910. 'c.jjcp_smb'=>['<>',''],
  911. ];
  912. if (isset($req['key_word']) && !empty($req['key_word'])){
  913. $where['c.jjcp_sj | c.jjcp_gdbh | c.jjcp_cpmc | c.jjcp_cpdh | g.实际投料'] = ['like','%'.$req['key_word'].'%'];
  914. }
  915. //客户编号
  916. $rows = db('成品入仓')->alias('c')
  917. ->field('LEFT(c.jjcp_sj, 10) as jjcp_sj, c.jjcp_gdbh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  918. rtrim(c.jjcp_cpdh) as jjcp_cpdh, g.实际投料')
  919. ->where($where)
  920. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  921. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  922. ->order('c.jjcp_sj desc')
  923. ->group('c.jjcp_gdbh, c.jjcp_cpdh')
  924. ->page($page,$limit)
  925. ->select();
  926. $total = db('成品入仓')->alias('c')
  927. ->where($where)
  928. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  929. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  930. ->group('c.jjcp_gdbh, c.jjcp_cpdh')
  931. ->count();
  932. $brr = db('成品入仓')
  933. ->group('jjcp_gdbh,jjcp_cpdh')
  934. ->column('CONCAT(jjcp_gdbh, "-", rtrim(jjcp_cpdh)), sum(jjcp_sl)');
  935. foreach ($rows as $key=>$value) {
  936. $rows[$key]['实际投料'] = (string)floatval($value['实际投料']*10000);
  937. if(array_key_exists($value['jjcp_gdbh'].'-'.$value['jjcp_cpdh'],$brr)){
  938. $rows[$key]['入仓数量'] = $brr[$value['jjcp_gdbh'].'-'.$value['jjcp_cpdh']];
  939. if($rows[$key]['实际投料']!=0){
  940. $rows[$key]['投入产出率'] = number_format($rows[$key]['入仓数量']/$rows[$key]['实际投料']*100,2);
  941. }else{
  942. $rows[$key]['投入产出率'] = '';
  943. }
  944. }else{
  945. $rows[$key]['入仓数量'] = '';
  946. $rows[$key]['投入产出率'] = '';
  947. }
  948. }
  949. $data = [
  950. 'total' => $total,
  951. 'rows' => $rows,
  952. ];
  953. $this->success('成功',$data);
  954. }
  955. /**
  956. * 各日统计列表excel导出
  957. * @ApiMethod (POST)
  958. * @param string file_name
  959. * @param array fields
  960. */
  961. public function dayExport()
  962. {
  963. //get请求
  964. if(!$this->request->isPost()){
  965. $this->error('请求方式错误');
  966. }
  967. $req = $this->request->param();
  968. if (!isset($req['file_name'])){
  969. $this->error('参数错误','file_name');
  970. }
  971. if (!(isset($req['fields']) && count($req['fields'])!=0)){
  972. $this->error('参数错误','fields',100);
  973. }
  974. if (isset($req['key_word']) && !empty($req['key_word'])){
  975. $where['c.jjcp_sj | c.jjcp_gdbh | c.jjcp_cpmc | c.jjcp_cpdh | g.实际投料'] = ['like','%'.$req['key_word'].'%'];
  976. }
  977. $arr = [
  978. 'jjcp_gdbh' =>['jjcp_gdbh'],
  979. 'jjcp_yjno' =>['jjcp_yjno'],
  980. 'jjcp_cpmc' =>['印件名称'],
  981. '成品编码' =>['成品编码'],
  982. '成品名称' =>['成品名称'],
  983. '实际投料' =>['实际投料'],
  984. 'jjcp_sls' =>['入仓数量'],
  985. 'jjcp_sj' =>['完工日期'],
  986. ];
  987. $data[0] = [];
  988. foreach ($req['fields'] as $k=>$v){
  989. if(array_key_exists($v,$arr)){
  990. array_push($data[0],$arr[$v][0]);
  991. }
  992. }
  993. $where = [
  994. 'c.jjcp_smb'=>['<>','']
  995. ];
  996. //客户编号
  997. $rows = db('成品入仓')->alias('c')
  998. ->field('c.jjcp_gdbh, c.jjcp_yjno, rtrim(c.jjcp_cpmc) as jjcp_cpmc, rtrim(c.jjcp_cpdh) as jjcp_cpdh,
  999. rtrim(c.成品编码) as 成品编码, rtrim(c.成品名称) as 成品名称, sum(jjcp_sl) as jjcp_sls,
  1000. g.实际投料, LEFT(c.jjcp_sj, 10) as jjcp_sj
  1001. ')
  1002. ->where($where)
  1003. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  1004. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  1005. ->order('c.jjcp_sj desc')
  1006. ->group('c.jjcp_gdbh, c.jjcp_cpdh')
  1007. ->select();
  1008. foreach ($rows as $key=>$value) {
  1009. $subArray = [];
  1010. foreach ($arr as $k=>$v){
  1011. if($k=='实际投料'){
  1012. $subArray[$k] = (string)floatval($value['实际投料']*10000);
  1013. }else{
  1014. $subArray[$k] = $rows[$key][$k];
  1015. }
  1016. }
  1017. array_push($data,$subArray);
  1018. }
  1019. $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
  1020. }
  1021. /**
  1022. * 入仓末板数据统计列表
  1023. * @ApiMethod (GET)
  1024. * @param string $date 时间
  1025. * @param string $sys_id 用户
  1026. */
  1027. public function mbList()
  1028. {
  1029. //get请求
  1030. if(!$this->request->isGet()){
  1031. $this->error('请求方式错误');
  1032. }
  1033. $req = $this->request->param();
  1034. // $page = 1;
  1035. // $limit = 15;
  1036. // if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  1037. // if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  1038. $date = date('Y-m-d',strtotime('-3 month'));
  1039. $arr1 = db('db_包装产量预报')
  1040. ->field('sczl_gdbh1, sczl_gdbh2, sczl_gdbh3, sczl_gdbh4, sczl_gdbh5, sczl_gdbh6,
  1041. cast(substr(sczl_yjGx1,1,2) as signed) as sczl_yjGx1, cast(substr(sczl_yjGx2,1,2) as signed) as sczl_yjGx2,
  1042. cast(substr(sczl_yjGx3,1,2) as signed) as sczl_yjGx3, cast(substr(sczl_yjGx4,1,2) as signed) as sczl_yjGx4,
  1043. cast(substr(sczl_yjGx5,1,2) as signed) as sczl_yjGx5, cast(substr(sczl_yjGx6,1,2) as signed) as sczl_yjGx6,
  1044. (sczl_cl1*sczl_PgCl1+sczl_clAdd1) as sczl_cls1,
  1045. (sczl_cl2*sczl_PgCl2+sczl_clAdd2) as sczl_cls2,
  1046. (sczl_cl3*sczl_PgCl3+sczl_clAdd3) as sczl_cls3,
  1047. (sczl_cl4*sczl_PgCl4+sczl_clAdd4) as sczl_cls4,
  1048. (sczl_cl5*sczl_PgCl5+sczl_clAdd5) as sczl_cls5,
  1049. (sczl_cl6*sczl_PgCl6+sczl_clAdd6) as sczl_cls6
  1050. ')
  1051. ->where('sczl_rq','>=',$date)
  1052. ->select();
  1053. $data1 = [];
  1054. foreach ($arr1 as $k=>$v){
  1055. for ($i=1;$i<=6;$i++){
  1056. if (!empty($v['sczl_gdbh'.$i])){
  1057. $v['sczl_gdbh'.$i] = strtoupper($v['sczl_gdbh'.$i]);
  1058. if(array_key_exists($v['sczl_gdbh'.$i].'-'.$v['sczl_yjGx'.$i],$data1)){
  1059. $data1[$v['sczl_gdbh'.$i].'-'.$v['sczl_yjGx'.$i]] += $v['sczl_cls'.$i];
  1060. }else{
  1061. $data1[$v['sczl_gdbh'.$i].'-'.$v['sczl_yjGx'.$i]] = $v['sczl_cls'.$i];
  1062. }
  1063. }
  1064. }
  1065. }
  1066. krsort($data1);
  1067. //成品入仓中jjcp_smb不为空的工单
  1068. $rows2 = db('成品入仓')
  1069. ->where('jjcp_sj','>=',$date)
  1070. ->group('jjcp_gdbh, jjcp_cpdh')
  1071. ->column("CONCAT( jjcp_gdbh, '-', jjcp_yjno) AS gdyj, max(jjcp_smb) as jjcp_smb,
  1072. sum(jjcp_sl) as jjcp_sls, left(max(jjcp_sj),10) as jjcp_sj,UniqId");
  1073. $data = [];
  1074. foreach($data1 as $key=>$value){
  1075. $subArray = [];
  1076. $gdbh = strtoupper(explode('-',$key)[0]);
  1077. $yjno = explode('-',$key)[1];
  1078. $res = db('工单_印件资料')
  1079. ->where('Yj_Gdbh',$gdbh)
  1080. ->where('yj_Yjno',$yjno)
  1081. ->field('Yj_Gdbh, yj_Yjno, yj_yjmc, yj_成品数量, (yj_平张投料 * yj_ks * yj_ls) as 投料')
  1082. ->find();
  1083. if(!empty($res)){
  1084. $subArray['Yj_Gdbh'] = $res['Yj_Gdbh'];
  1085. $subArray['yj_Yjno'] = $res['yj_Yjno'];
  1086. $subArray['yj_yjmc'] = trim($res['yj_yjmc']);
  1087. $subArray['yj_成品数量'] = (string)floatval($res['yj_成品数量']*10000);
  1088. $subArray['yj_实际投料'] = (string)floatval($res['投料']);
  1089. }else{
  1090. $subArray['Yj_Gdbh'] = '';
  1091. $subArray['yj_Yjno'] = '';
  1092. $subArray['yj_yjmc'] = '';
  1093. $subArray['yj_成品数量'] = '';
  1094. $subArray['yj_实际投料'] = '';
  1095. }
  1096. if(array_key_exists($key,$rows2)){
  1097. $subArray['jjcp_smb'] = $rows2[$key]['jjcp_smb'];
  1098. $subArray['jjcp_sls'] = $rows2[$key]['jjcp_sls'];
  1099. $subArray['jjcp_sj'] = $rows2[$key]['jjcp_sj'];
  1100. }else{
  1101. $subArray['jjcp_smb'] = '';
  1102. $subArray['jjcp_sls'] = '';
  1103. $subArray['jjcp_sj'] = '';
  1104. }
  1105. $subArray['sczl_cls'] = (string)floatval($value);
  1106. array_push($data,$subArray);
  1107. }
  1108. $data = [
  1109. 'total' => count($data),
  1110. 'rows' => $data,
  1111. ];
  1112. $this->success('成功',$data);
  1113. }
  1114. /**
  1115. * 入仓末板数据统计列表excel导出
  1116. * @ApiMethod (POST)
  1117. * @param string file_name
  1118. * @param array fields
  1119. */
  1120. public function mbExport()
  1121. {
  1122. //get请求
  1123. if(!$this->request->isPost()){
  1124. $this->error('请求方式错误');
  1125. }
  1126. $req = $this->request->param();
  1127. if (!isset($req['file_name'])){
  1128. $this->error('参数错误','file_name');
  1129. }
  1130. if (!(isset($req['fields']) && count($req['fields'])!=0)){
  1131. $this->error('参数错误','fields',100);
  1132. }
  1133. $arr = [
  1134. 'Yj_Gdbh' =>['工单编号'],
  1135. 'yj_Yjno' =>['印件号'],
  1136. 'yj_yjmc' =>['印件名称'],
  1137. 'yj_成品数量' =>['计划交货数量'],
  1138. 'yj_实际投料' =>['印件投料'],
  1139. 'sczl_cls' =>['包装产量'],
  1140. 'jjcp_sj' =>['最近入仓时间'],
  1141. 'jjcp_sls' =>['入仓产量'],
  1142. 'status' =>['完工'],
  1143. '缺数' =>['缺数'],
  1144. ];
  1145. $data[0] = [];
  1146. foreach ($req['fields'] as $k=>$v){
  1147. if(array_key_exists($v,$arr)){
  1148. array_push($data[0],$arr[$v][0]);
  1149. }
  1150. }
  1151. $date = date('Y-m-d',strtotime('-3 month'));
  1152. $arr1 = db('db_包装产量预报')
  1153. ->field('sczl_gdbh1, sczl_gdbh2, sczl_gdbh3, sczl_gdbh4, sczl_gdbh5, sczl_gdbh6,
  1154. cast(substr(sczl_yjGx1,1,2) as signed) as sczl_yjGx1, cast(substr(sczl_yjGx2,1,2) as signed) as sczl_yjGx2,
  1155. cast(substr(sczl_yjGx3,1,2) as signed) as sczl_yjGx3, cast(substr(sczl_yjGx4,1,2) as signed) as sczl_yjGx4,
  1156. cast(substr(sczl_yjGx5,1,2) as signed) as sczl_yjGx5, cast(substr(sczl_yjGx6,1,2) as signed) as sczl_yjGx6,
  1157. (sczl_cl1*sczl_PgCl1+sczl_clAdd1) as sczl_cls1,
  1158. (sczl_cl2*sczl_PgCl2+sczl_clAdd2) as sczl_cls2,
  1159. (sczl_cl3*sczl_PgCl3+sczl_clAdd3) as sczl_cls3,
  1160. (sczl_cl4*sczl_PgCl4+sczl_clAdd4) as sczl_cls4,
  1161. (sczl_cl5*sczl_PgCl5+sczl_clAdd5) as sczl_cls5,
  1162. (sczl_cl6*sczl_PgCl6+sczl_clAdd6) as sczl_cls6
  1163. ')
  1164. ->where('sczl_rq','>=',$date)
  1165. ->select();
  1166. $data1 = [];
  1167. foreach ($arr1 as $k=>$v){
  1168. for ($i=1;$i<=6;$i++){
  1169. if(array_key_exists($v['sczl_gdbh'.$i].'-'.$v['sczl_yjGx'.$i],$data1)){
  1170. $data1[$v['sczl_gdbh'.$i].'-'.$v['sczl_yjGx'.$i]] += $v['sczl_cls'.$i];
  1171. }else{
  1172. $data1[$v['sczl_gdbh'.$i].'-'.$v['sczl_yjGx'.$i]] = $v['sczl_cls'.$i];
  1173. }
  1174. }
  1175. }
  1176. krsort($data1);
  1177. //成品入仓中jjcp_smb不为空的工单
  1178. $rows1 = db('成品入仓')
  1179. ->where('jjcp_smb','<>','')
  1180. ->order('jjcp_gdbh desc')
  1181. ->column("CONCAT(jjcp_gdbh, '-', jjcp_yjno) AS gdyj, UniqId");
  1182. $rows2 = db('成品入仓')
  1183. ->where('jjcp_sj','>=',$date)
  1184. ->group('jjcp_gdbh, jjcp_cpdh')
  1185. ->column("CONCAT( jjcp_gdbh, '-', jjcp_yjno) AS gdyj, jjcp_smb,
  1186. sum(jjcp_sl) as jjcp_sls, left(max(jjcp_sj),10) as jjcp_sj");
  1187. $rows3 = db('工单_印件资料')->cache(true,86400)
  1188. ->group('Yj_Gdbh, yj_Yjno')
  1189. ->column("CONCAT( Yj_Gdbh, '-', yj_Yjno) AS gdyj,
  1190. Yj_Gdbh, yj_Yjno, yj_yjmc, yj_成品数量, yj_实际投料");
  1191. foreach($data1 as $key=>$value){
  1192. if(!array_key_exists($key,$rows1)){
  1193. $subArray = [];
  1194. foreach ($arr as $k=>$v){
  1195. if($k=='yj_成品数量' || $k=='yj_实际投料'){
  1196. if(array_key_exists($key,$rows3)){
  1197. $subArray[$k] = (string)floatval($rows3[$key][$k]*10000);
  1198. }else{
  1199. $subArray[$k] = '';
  1200. }
  1201. }else if($k=='Yj_Gdbh' || $k=='yj_Yjno'){
  1202. if(array_key_exists($key,$rows3)){
  1203. $subArray[$k] = $rows3[$key][$k];
  1204. }else{
  1205. $subArray[$k] = '';
  1206. }
  1207. }else if($k=='yj_yjmc'){
  1208. if(array_key_exists($key,$rows3)){
  1209. $subArray[$k] = trim($rows3[$key][$k]);
  1210. }else{
  1211. $subArray[$k] = '';
  1212. }
  1213. }else if($k=='sczl_cls'){
  1214. $subArray[$k] = (string)floatval($value);
  1215. }else if($k=='status'){
  1216. if(array_key_exists($key,$rows2) && $rows2[$key]['jjcp_smb'] !=''){
  1217. $subArray[$k] = '完工';
  1218. }else{
  1219. $subArray[$k] = '';
  1220. }
  1221. }else if($k=='缺数'){
  1222. if(array_key_exists($key,$rows2) && $rows2[$key]['jjcp_smb'] !=''){
  1223. $subArray[$k]['缺数'] = (int)$rows3[$key]['yj_成品数量']-(int)$value;
  1224. }else{
  1225. $subArray[$k] = '';
  1226. }
  1227. }else{
  1228. if(array_key_exists($key,$rows2)){
  1229. $subArray[$k] = $rows2[$key][$k];
  1230. $subArray[$k] = $rows2[$key][$k];
  1231. $subArray[$k] = $rows2[$key][$k];
  1232. }else{
  1233. $subArray[$k] = '';
  1234. $subArray[$k] = '';
  1235. $subArray[$k] = '';
  1236. }
  1237. }
  1238. }
  1239. array_push($data,$subArray);
  1240. }
  1241. }
  1242. $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
  1243. }
  1244. /**
  1245. * 构建新增入仓数据
  1246. * @param array $req
  1247. * @return array
  1248. */
  1249. protected function buildAddData(array $req)
  1250. {
  1251. $fields = [
  1252. 'Sys_id',
  1253. '入仓类型', '仓库编号', '仓库名称',
  1254. 'jjcp_num',
  1255. 'jjcp_gdbh', 'jjcp_yjno', '订单编号',
  1256. 'jjcp_cpdh', 'jjcp_cpmc',
  1257. '成品编码', '成品名称',
  1258. '客户料号',
  1259. 'jjcp_smb', 'jjcp_sj',
  1260. 'jjcp_sl', 'jjcp_dw',
  1261. '机型备注',
  1262. 'jjcp_desc',
  1263. ];
  1264. $data = [];
  1265. foreach ($fields as $index => $field) {
  1266. if (!isset($req[$field])) {
  1267. $this->error('参数错误', $field, $index + 1);
  1268. }
  1269. $data[$field] = $req[$field];
  1270. }
  1271. $data['Sys_rq'] = date('Y-m-d H:i:s');
  1272. return $data;
  1273. }
  1274. /**
  1275. * 校验印件产品名称
  1276. * @param string $gdbh
  1277. * @param string $yjno
  1278. * @param string $cpmc
  1279. */
  1280. protected function validateProductName($gdbh, $yjno, $cpmc)
  1281. {
  1282. $name = db('工单_印件资料')
  1283. ->where('Yj_Gdbh', $gdbh)
  1284. ->where('yj_Yjno', $yjno)
  1285. ->value('yj_yjmc');
  1286. if ($name !== $cpmc) {
  1287. $this->error('产品名称错误');
  1288. }
  1289. }
  1290. /**
  1291. * 查询工单印件是否已存在末版记录
  1292. * @param string $gdbh
  1293. * @param string $yjno
  1294. * @return array|null
  1295. */
  1296. protected function findExistingEndBoard($gdbh, $yjno)
  1297. {
  1298. return db('成品入仓')
  1299. ->where('jjcp_gdbh', $gdbh)
  1300. ->where('jjcp_yjno', $yjno)
  1301. ->where('jjcp_smb', '<>', '')
  1302. ->find();
  1303. }
  1304. /**
  1305. * 校验工单印件是否已完全领料
  1306. * @param string $gdbh
  1307. * @param string $yjno
  1308. */
  1309. protected function validateMaterialReceived($gdbh, $yjno)
  1310. {
  1311. $materialRecord = db('工单_印件资料')
  1312. ->alias('a')
  1313. ->join('物料_收发记录 b', 'a.Yj_Gdbh=b.st_gdbh and a.yj_cpdh=b.cpdh')
  1314. ->where('a.Yj_Gdbh', $gdbh)
  1315. ->where('a.yj_Yjno', $yjno)
  1316. ->group('b.st_wlbh')
  1317. ->order('b.st_wlbh asc')
  1318. ->column('b.st_wlbh');
  1319. $bomRecord = db('工单_印件资料')
  1320. ->alias('a')
  1321. ->join('工单_bom资料 b', 'a.Yj_Gdbh=b.BOM_工单编号 and a.yj_Yjno=b.BOM_工单行号 and a.yj_cpdh=b.BOM_产品编号')
  1322. ->where('a.Yj_Gdbh', $gdbh)
  1323. ->where('a.yj_Yjno', $yjno)
  1324. ->where('b.BOM_实际用量', '<>', 0)
  1325. ->group('b.BOM_物料编码')
  1326. ->order('b.BOM_物料编码 asc')
  1327. ->column('b.BOM_物料编码');
  1328. foreach ($bomRecord as $materialCode) {
  1329. if (!in_array($materialCode, $materialRecord)) {
  1330. $this->error('工单' . $gdbh . '印件' . $yjno . '物料' . $materialCode . '未领料');
  1331. }
  1332. }
  1333. }
  1334. /**
  1335. * 生成成品入仓 UniqId
  1336. * @return int
  1337. */
  1338. protected function generateFinishStockUniqId()
  1339. {
  1340. $uniqId = db('成品入仓')->max('UniqId');
  1341. return $uniqId < 10000000 ? 10000000 : $uniqId + 1;
  1342. }
  1343. /**
  1344. * 保存成品入仓数据到 MySQL 和 MongoDB
  1345. * @param array $data
  1346. * @param mixed $mongodb
  1347. */
  1348. protected function saveFinishStock(array $data, $mongodb)
  1349. {
  1350. db()->startTrans();
  1351. try {
  1352. $sql = db('成品入仓')->fetchSql(true)->insert($data);
  1353. $inserted = db()->query($sql);
  1354. if ($inserted === false) {
  1355. throw new \Exception('MySQL 保存失败');
  1356. }
  1357. $mongodb->name('finished_products')->insert($data);
  1358. db()->commit();
  1359. } catch (\Exception $e) {
  1360. db()->rollback();
  1361. $this->error($e->getMessage());
  1362. }
  1363. }
  1364. /**
  1365. * 判断是否为末版
  1366. * @param string $smb
  1367. * @return bool
  1368. */
  1369. protected function isEndBoard($smb)
  1370. {
  1371. return strpos((string)$smb, '末') !== false;
  1372. }
  1373. /**
  1374. * 是否需要同步成品入仓中间表
  1375. * 规则:
  1376. * 1. 工单编号以 Y 开头,且 >= Y2608001
  1377. * 2. 工单_基本资料.接单日期 >= 2026-08-01
  1378. * 3. 中间库 U8_06工单资料 中存在该工单编号
  1379. * @param string $gdbh
  1380. * @return bool
  1381. */
  1382. protected function shouldSyncFinishStockMiddle($gdbh)
  1383. {
  1384. $gdbh = strtoupper(trim((string)$gdbh));
  1385. if ($gdbh === '' || $gdbh[0] !== 'Y') {
  1386. return false;
  1387. }
  1388. if ((int)substr($gdbh, 1) < 2608001) {
  1389. return false;
  1390. }
  1391. $orderDate = db('工单_基本资料')->where('Gd_gdbh', $gdbh)->value('接单日期');
  1392. if (empty($orderDate)) {
  1393. return false;
  1394. }
  1395. if (strtotime(trim((string)$orderDate)) < strtotime('2026-08-01')) {
  1396. return false;
  1397. }
  1398. // 与 syncFinishStockMiddle 一致:测试库 database.db8;正式库可改为 database.db3
  1399. $middleDb = Db::connect(config('database.db8'));
  1400. $exists = $middleDb->name('U8_06工单资料')->where('工单编号', $gdbh)->count();
  1401. return $exists > 0;
  1402. }
  1403. /**
  1404. * 末版入仓后进入超节损
  1405. * @param string $gdbh
  1406. * @param string $yjno
  1407. */
  1408. protected function handleEndBoardSuperLoss($gdbh, $yjno)
  1409. {
  1410. $orderLoss = new OrderSuperLoss();
  1411. $result = [];
  1412. try {
  1413. $result = $orderLoss->OneOrderSuperLoss($gdbh, $yjno);
  1414. } catch (DataNotFoundException $e) {
  1415. } catch (ModelNotFoundException $e) {
  1416. } catch (DbException $e) {
  1417. }
  1418. if (empty($result)) {
  1419. return;
  1420. }
  1421. db('工单_质量考核汇总')
  1422. ->where('Gy0_gdbh', $gdbh)
  1423. ->where('印件及工序', $yjno)
  1424. ->delete();
  1425. $sql = db('工单_质量考核汇总')->fetchSql(true)->insertAll($result);
  1426. $inserted = db()->query($sql);
  1427. if ($inserted === false) {
  1428. $this->error('超节损数据保存失败');
  1429. }
  1430. }
  1431. }