FinishedProductWarehousing.php 60 KB

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