FinishedProductWarehousing.php 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529
  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. $name = \db('工单_印件资料')
  491. ->where('Yj_Gdbh',$req['jjcp_gdbh'])
  492. ->where('yj_Yjno',$req['jjcp_yjno'])
  493. ->value('yj_yjmc');
  494. if ($name !== $req['jjcp_cpmc']){
  495. $this->error('产品名称错误');
  496. }
  497. $data = [];
  498. foreach ($arr as $key => $value){
  499. if (!isset($req[$value])){
  500. $this->error('参数错误',$value,$key+1);
  501. }
  502. $data[$value] = $req[$value];
  503. }
  504. $data['Sys_rq'] = date('Y-m-d H:i:s');
  505. //查询UniqId
  506. $UniqId = db('成品入仓')->max('UniqId');
  507. $data['UniqId'] = $UniqId < 10000000 ? 10000000 : $UniqId + 1;
  508. //判断当前工单是否存在已提交模版
  509. $existingRecord = db('成品入仓')
  510. ->where('jjcp_gdbh', $data['jjcp_gdbh'])
  511. ->where('jjcp_yjno', $data['jjcp_yjno'])
  512. ->where('jjcp_smb', '<>', '') // 判断 jjcp_smb 不为空
  513. ->find();
  514. if ($existingRecord) {
  515. $this->error($existingRecord['jjcp_gdbh'].'工单 -- 印件'.$existingRecord['jjcp_yjno'].'已经进入末版,无法继续操作');
  516. }
  517. //开启事务
  518. db()->startTrans();
  519. try{
  520. $sql = db('成品入仓')->fetchSql(true)->insert($data);
  521. $bool = db()->query($sql);
  522. //新增进MongoDB
  523. $res = $mongodb->name('finished_products')->insert($data);
  524. // 提交事务
  525. db()->commit();
  526. } catch (\Exception $e) {
  527. // 回滚事务
  528. db()->rollback();
  529. $this->error($e->getMessage());
  530. }
  531. if($bool===false) $this->error('失败');
  532. //末版输入进入超节损
  533. $oederLoss = new \app\api\controller\OrderSuperLoss();
  534. if (strpos($data['jjcp_smb'],'末') !== false){
  535. try {
  536. $result = $oederLoss->OneOrderSuperLoss($data['jjcp_gdbh'], $data['jjcp_yjno']);
  537. } catch (DataNotFoundException $e) {
  538. } catch (ModelNotFoundException $e) {
  539. } catch (DbException $e) {
  540. }
  541. db('工单_质量考核汇总')
  542. ->where('Gy0_gdbh',$data['jjcp_gdbh'])
  543. ->where('印件及工序',$data['jjcp_yjno'])
  544. ->delete();
  545. $sql = db('工单_质量考核汇总')->fetchSql(true)->insertAll($result);
  546. $res = db()->query($sql);
  547. if($res===false) $this->error('失败');
  548. }
  549. $this->success('成功');
  550. }
  551. /**
  552. * 修改
  553. * @ApiMethod (POST)
  554. */
  555. public function edit()
  556. {
  557. if(!$this->request->isPost()){
  558. $this->error('请求方式错误');
  559. }
  560. //连接mongodb
  561. $mongodb = Db::connect(config('database.mongodb'));
  562. $req = $this->request->param();
  563. $arr = [
  564. '入仓类型', '仓库编号', '仓库名称',
  565. 'jjcp_num',
  566. 'jjcp_gdbh', 'jjcp_yjno', '订单编号',
  567. 'jjcp_cpdh', 'jjcp_cpmc',
  568. '成品编码', '成品名称',
  569. '客户料号',
  570. 'jjcp_smb', 'jjcp_sj',
  571. 'jjcp_sl', 'jjcp_dw',
  572. '机型备注',
  573. 'jjcp_desc'
  574. ];
  575. $data = [];
  576. foreach ($arr as $key => $value){
  577. if (!isset($req[$value])){
  578. continue;
  579. }
  580. $data[$value] = $req[$value];
  581. }
  582. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  583. $this->error('参数错误','UniqId',100);
  584. }
  585. if (count($data)==0){
  586. $this->error('参数错误','',111);
  587. }
  588. $data['Mod_rq'] = date('Y-m-d H:i:s');
  589. //判断当前工单是否存在已提交模版
  590. if ($data['jjcp_smb'] === '末 板'){
  591. $existingRecord = db('成品入仓')
  592. ->where('jjcp_gdbh', $data['jjcp_gdbh'])
  593. ->where('jjcp_yjno', $data['jjcp_yjno'])
  594. ->where('jjcp_smb', '<>', '') // 判断 jjcp_smb 不为空
  595. ->find();
  596. if ($existingRecord && $existingRecord['UniqId'] !== (int)$req['UniqId']) {
  597. $this->error($existingRecord['jjcp_gdbh'].'工单 -- 印件'.$existingRecord['jjcp_yjno'].'已经进入末版,无法继续操作');
  598. }
  599. };
  600. //开启事务
  601. db()->startTrans();
  602. try{
  603. $sql = db('成品入仓')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
  604. $bool = db()->query($sql);
  605. //同步更新monodb数据
  606. $res = $mongodb->name('finished_products')
  607. ->where('UniqId', (int)$req['UniqId']) // 使用实际的UniqId值
  608. ->update($data);
  609. // 提交事务
  610. db()->commit();
  611. } catch (\Exception $e) {
  612. // 回滚事务
  613. db()->rollback();
  614. $this->error($e->getMessage());
  615. }
  616. $oederLoss = new \app\api\controller\OrderSuperLoss();
  617. if (strpos($data['jjcp_smb'],'末') !== false){
  618. try {
  619. $result = $oederLoss->OneOrderSuperLoss($data['jjcp_gdbh'], $data['jjcp_yjno']);
  620. } catch (DataNotFoundException $e) {
  621. } catch (ModelNotFoundException $e) {
  622. } catch (DbException $e) {
  623. }
  624. db('工单_质量考核汇总')
  625. ->where('Gy0_gdbh',$data['jjcp_gdbh'])
  626. ->where('印件及工序',$data['jjcp_yjno'])
  627. ->delete();
  628. $sql = db('工单_质量考核汇总')->fetchSql(true)->insertAll($result);
  629. $res = db()->query($sql);
  630. if($res===false) $this->error('失败');
  631. }
  632. if($bool===false) $this->error('失败');
  633. $this->success('成功');
  634. }
  635. /**
  636. * 修改
  637. * @ApiMethod (POST)
  638. * @param string 'UniqId'
  639. */
  640. public function del()
  641. {
  642. if(!$this->request->isPost()){
  643. $this->error('请求方式错误');
  644. }
  645. //连接mongodb
  646. $mongodb = Db::connect(config('database.mongodb'));
  647. $req = $this->request->param();
  648. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  649. $this->error('参数错误','UniqId',100);
  650. }
  651. //开启事务
  652. db()->startTrans();
  653. try{
  654. $bool = db('成品入仓')->where('UniqId',$req['UniqId'])->delete();
  655. //同时删除mongdb数据
  656. //同步更新monodb数据
  657. $res = $mongodb->name('finished_products')
  658. ->where('UniqId', (int)$req['UniqId']) // 使用实际的UniqId值
  659. ->delete();
  660. // 提交事务
  661. db()->commit();
  662. } catch (\Exception $e) {
  663. // 回滚事务
  664. db()->rollback();
  665. $this->error($e->getMessage());
  666. }
  667. if($bool===false) $this->error('失败');
  668. $this->success('成功');
  669. }
  670. /**
  671. * excel导出
  672. * @ApiMethod (POST)
  673. * @param string date
  674. * @param string sys_id
  675. * @param array fields
  676. */
  677. public function export(){
  678. if(!$this->request->isGet()){
  679. $this->error('请求方式错误');
  680. }
  681. $req = $this->request->param();
  682. if (!isset($req['date'])) $this->error('参数缺失');
  683. if (!(isset($req['fields']) && count($req['fields'])!=0)){
  684. $this->error('参数错误','fields',100);
  685. }
  686. if(strpos($req['date'],'-')){
  687. $where = ['c.Sys_rq'=>['like',$req['date'].'%']];
  688. }else if(empty($req['date'])){
  689. $where = [];
  690. }else{
  691. $where = ['c.jjcp_gdbh'=>$req['date']];
  692. }
  693. if (isset($req['sys_id']) && !empty($req['sys_id'])){
  694. $where['c.Sys_id'] = ['LIKE',$req['sys_id'].'%'];
  695. }
  696. $arr = [
  697. '入仓类型' =>['入仓类型'],
  698. '仓库编号' =>['仓库编号'],
  699. '仓库名称' =>['仓库名称'],
  700. 'jjcp_num' =>['入仓单号'],
  701. 'jjcp_gdbh' =>['工单编号'],
  702. 'jjcp_yjno' =>['印件号'],
  703. 'jjcp_sl' =>['入仓数量'],
  704. 'jjcp_sls' =>['累计入仓数量'],
  705. '订单数量' =>['订单数量'],
  706. '完成率' =>['完成率'],
  707. 'jjcp_dw' =>['单位'],
  708. 'jjcp_sj' =>['入仓时间'],
  709. 'jjcp_smb' =>['首末板'],
  710. 'jjcp_cpdh' =>['印件代号'],
  711. 'jjcp_cpmc' =>['印件名称'],
  712. '成品编码' =>['产品编号'],
  713. '成品名称' =>['产品名称'],
  714. '客户料号' =>['客户料号'],
  715. 'jjcp_desc' =>['备注'],
  716. '客户编号' =>['客户编号'],
  717. 'Gd_客户名称' =>['客户名称'],
  718. '最近入仓日期' =>['最近入仓日期'],
  719. '机型备注' =>['机型备注'],
  720. ];
  721. $data[0] = [];
  722. foreach ($req['fields'] as $k=>$v){
  723. if(array_key_exists($v,$arr)){
  724. array_push($data[0],$arr[$v][0]);
  725. }
  726. }
  727. $num = db('成品入仓')->alias('c')
  728. ->where($where)
  729. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  730. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  731. ->count();
  732. $rows = [];
  733. for($i=1;$i<=ceil($num/10000);$i++){
  734. $p = $i == ceil($num/10000) ? $num%10000 : 10000;
  735. $r = db('成品入仓')->alias('c')
  736. ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
  737. rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh,
  738. c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj,
  739. rtrim(c.jjcp_smb) as jjcp_smb, rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  740. rtrim(c.成品编码) as 成品编码, rtrim(c.成品名称) as 成品名称,
  741. rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, LEFT(c.成品编码,'.config('product_code_digit').') as 客户编号, rtrim(g.Gd_客户名称) as Gd_客户名称,
  742. rtrim(c.机型备注) as 机型备注')
  743. ->where($where)
  744. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  745. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  746. ->order('c.UniqId desc')
  747. ->limit($i,$p)
  748. ->select();
  749. $rows = array_merge($rows,$r);
  750. }
  751. foreach ($rows as $key=>$value) {
  752. $row = db('成品入仓')
  753. ->field('LEFT(Sys_rq, 10) as Sys_rq,jjcp_sl')
  754. ->where(['jjcp_gdbh'=>$value['jjcp_gdbh'], 'jjcp_cpdh'=>$value['jjcp_cpdh']])
  755. ->order('Sys_rq desc')
  756. ->select();
  757. $subArray = [];
  758. foreach ($arr as $k=>$v){
  759. if($k=='jjcp_sls'){
  760. $subArray[$k] = 0;
  761. foreach ($row as $n) {
  762. $subArray[$k] += $n['jjcp_sl'];
  763. }
  764. }else if($k=='完成率'){
  765. if ($value['订单数量']!=0){
  766. $subArray[$k] = 0;
  767. foreach ($row as $n) {
  768. $subArray[$k] += $n['jjcp_sl'];
  769. }
  770. $subArray[$k] = number_format($subArray[$k]/$value['订单数量']/100,2);
  771. }else{
  772. $subArray[$k] = '';
  773. }
  774. }else if($k=='最近入仓日期'){
  775. $subArray[$k] = $row[0]['Sys_rq'];
  776. }else{
  777. $subArray[$k] = $rows[$key][$k];
  778. }
  779. }
  780. array_push($data,$subArray);
  781. }
  782. $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
  783. }
  784. /**
  785. * 月度A
  786. * @ApiMethod (POST)
  787. * @param string start_time
  788. * @param string end_time
  789. * @param string file_name
  790. * @param array fields
  791. */
  792. public function monthExportA(){
  793. if(!$this->request->isGet()){
  794. $this->error('请求方式错误');
  795. }
  796. $req = $this->request->param();
  797. $arr = [
  798. 'start_time', 'end_time', 'file_name'
  799. ];
  800. foreach ($arr as $key => $value){
  801. if (!isset($req[$value])){
  802. $this->error('参数错误',$value,$key+1);
  803. }
  804. }
  805. if (!(isset($req['fields']) && count($req['fields'])!=0)){
  806. $this->error('参数错误','fields',100);
  807. }
  808. $arr = [
  809. '入仓类型' =>['入仓类型'],
  810. '仓库编号' =>['仓库编号'],
  811. '仓库名称' =>['仓库名称'],
  812. 'jjcp_gdbh' =>['工单编号'],
  813. 'jjcp_cpdh' =>['入仓存货编号'],
  814. 'jjcp_cpmc' =>['入仓存货名称'],
  815. 'jjcp_sl' =>['入仓数量'],
  816. 'jjcp_dw' =>['单位'],
  817. 'jjcp_sj' =>['入仓时间'],
  818. 'jjcp_smb' =>['首末板'],
  819. 'jjcp_num' =>['单据编号'],
  820. '订单编号' =>['订单编号'],
  821. ];
  822. $data[0] = [];
  823. foreach ($req['fields'] as $k=>$v){
  824. if(array_key_exists($v,$arr)){
  825. array_push($data[0],$arr[$v][0]);
  826. }
  827. }
  828. //客户编号
  829. $rows = db('成品入仓')->alias('c')
  830. ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
  831. c.jjcp_gdbh, rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  832. c.jjcp_sl, rtrim(c.jjcp_dw) as jjcp_dw, c.jjcp_sj,
  833. rtrim(c.jjcp_smb) as jjcp_smb,
  834. rtrim(c.jjcp_num) as jjcp_num, rtrim(c.订单编号) as 订单编号
  835. ')
  836. ->where('c.jjcp_sj','between time',[$req['start_time'], $req['end_time']])
  837. ->order('c.jjcp_sj asc')
  838. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  839. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  840. ->select();
  841. foreach ($rows as $key=>$value) {
  842. $subArray = [];
  843. foreach ($arr as $k=>$v){
  844. $subArray[$k] = $rows[$key][$k];
  845. }
  846. array_push($data,$subArray);
  847. }
  848. $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
  849. }
  850. /**
  851. * 月度B
  852. * @ApiMethod (POST)
  853. * @param string start_time
  854. * @param string end_time
  855. * @param string file_name
  856. * @param array fields
  857. */
  858. public function monthExportB(){
  859. if(!$this->request->isGet()){
  860. $this->error('请求方式错误');
  861. }
  862. $req = $this->request->param();
  863. $arr = [
  864. 'start_time', 'end_time', 'file_name'
  865. ];
  866. foreach ($arr as $key => $value){
  867. if (!isset($req[$value])){
  868. $this->error('参数错误',$value,$key+1);
  869. }
  870. }
  871. if (!(isset($req['fields']) && count($req['fields'])!=0)){
  872. $this->error('参数错误','fields',100);
  873. }
  874. $arr = [
  875. '入仓类型' =>['入仓类型'],
  876. '客户编号' =>['客户编号'],
  877. '客户名称' =>['客户名称'],
  878. '产品类别' =>['产品类别'],
  879. 'jjcp_gdbh' =>['工单编号'],
  880. '成品编码' =>['成品编码'],
  881. '成品名称' =>['成品名称'],
  882. 'jjcp_sls' =>['入仓数量'],
  883. '大箱产量' =>['大箱产量'],
  884. '产品单价' =>['万张单价'],
  885. '产值万元' =>['产值万元'],
  886. ];
  887. $data[0] = [];
  888. foreach ($req['fields'] as $k=>$v){
  889. if(array_key_exists($v,$arr)){
  890. array_push($data[0],$arr[$v][0]);
  891. }
  892. }
  893. $rows1 = db('成品入仓')->alias('c')
  894. ->field('rtrim(c.入仓类型) as 入仓类型, LEFT(c.成品编码,'.config('product_code_digit').') as 客户编号, rtrim(b.客户名称) as 客户名称,
  895. rtrim(b.产品类别) as 产品类别, c.jjcp_gdbh,
  896. rtrim(c.成品编码) as 成品编码, rtrim(c.成品名称) as 成品名称
  897. ')
  898. ->where('c.jjcp_sj','between time',[$req['start_time'], $req['end_time']])
  899. ->order('客户编号 asc,b.产品类别 desc,c.成品编码 asc,c.jjcp_gdbh asc')
  900. ->join('产品_基本资料 b','b.产品编号=c.jjcp_cpdh')
  901. ->group('c.jjcp_gdbh')
  902. ->select();
  903. $rows2 = db('成品入仓')
  904. ->field('rtrim(入仓类型) as 入仓类型, rtrim(成品编码) as 客户编号,
  905. rtrim(成品编码) as 客户名称, rtrim(成品编码) as 产品类别,
  906. jjcp_gdbh,rtrim(成品编码) as 成品编码, rtrim(成品名称) as 成品名称
  907. ')
  908. ->where('jjcp_sj','between time',[$req['start_time'], $req['end_time']])
  909. ->where('成品编码','')
  910. ->order('jjcp_gdbh asc')
  911. ->group('jjcp_gdbh')
  912. ->select();
  913. $rows = array_merge($rows2,$rows1);
  914. $num = db('工单_基本资料')->count();
  915. $arr1 = db('工单_基本资料')->limit($num)
  916. ->column('CONCAT(Gd_gdbh, "-", rtrim(Gd_cpdh)) AS gdcp, 产品单价 as 万张单价');
  917. $brr = array_column($rows,'jjcp_gdbh');
  918. $brr = db('成品入仓')
  919. ->where('jjcp_gdbh', 'in', $brr)
  920. ->group('jjcp_gdbh')
  921. ->column('jjcp_gdbh, sum(jjcp_sl)');
  922. foreach ($rows as $key=>$value) {
  923. $subArray = [];
  924. foreach ($arr as $k=>$v){
  925. if($k=='jjcp_sls'){
  926. $subArray[$k] = $brr[$value['jjcp_gdbh']];
  927. }else if ($k=='大箱产量'){
  928. if($value['产品类别']=='条盒'){
  929. $subArray[$k] = $brr[$value['jjcp_gdbh']]/250;
  930. }else if($value['产品类别']=='小盒'){
  931. $subArray[$k] = $brr[$value['jjcp_gdbh']]/2500;
  932. }else{
  933. $subArray[$k] = 0;
  934. }
  935. }else if ($k=='产品单价'){
  936. if($value['产品类别']!=''){
  937. if (array_key_exists($value['jjcp_gdbh'].'-'.$value['成品编码'],$arr1)){
  938. $subArray[$k] = floatval(number_format($arr1[$value['jjcp_gdbh'].'-'.$value['成品编码']],4));
  939. }
  940. }else{
  941. $subArray[$k] = 0;
  942. }
  943. }else if ($k=='产值万元'){
  944. if($value['产品类别']!=''){
  945. if (array_key_exists($value['jjcp_gdbh'].'-'.$value['成品编码'],$arr1)){
  946. $subArray[$k] = floatval(number_format($arr1[$value['jjcp_gdbh'].'-'.$value['成品编码']]*$brr[$value['jjcp_gdbh']]/100000000,2));
  947. }
  948. }else{
  949. $subArray[$k] = 0;
  950. }
  951. }else{
  952. $subArray[$k] = $rows[$key][$k];
  953. }
  954. }
  955. array_push($data,$subArray);
  956. }
  957. $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
  958. }
  959. /**
  960. * 各日统计列表
  961. * @ApiMethod (GET)
  962. * @param string $date 时间
  963. * @param string $sys_id 用户
  964. */
  965. public function getDayList()
  966. {
  967. //get请求
  968. if(!$this->request->isGet()){
  969. $this->error('请求方式错误');
  970. }
  971. $req = $this->request->param();
  972. $page = 1;
  973. $limit = 15;
  974. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  975. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  976. $where = [
  977. 'c.jjcp_smb'=>['<>',''],
  978. ];
  979. if (isset($req['key_word']) && !empty($req['key_word'])){
  980. $where['c.jjcp_sj | c.jjcp_gdbh | c.jjcp_cpmc | c.jjcp_cpdh | g.实际投料'] = ['like','%'.$req['key_word'].'%'];
  981. }
  982. //客户编号
  983. $rows = db('成品入仓')->alias('c')
  984. ->field('LEFT(c.jjcp_sj, 10) as jjcp_sj, c.jjcp_gdbh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  985. rtrim(c.jjcp_cpdh) as jjcp_cpdh, g.实际投料')
  986. ->where($where)
  987. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  988. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  989. ->order('c.jjcp_sj desc')
  990. ->group('c.jjcp_gdbh, c.jjcp_cpdh')
  991. ->page($page,$limit)
  992. ->select();
  993. $total = db('成品入仓')->alias('c')
  994. ->where($where)
  995. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  996. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  997. ->group('c.jjcp_gdbh, c.jjcp_cpdh')
  998. ->count();
  999. $brr = db('成品入仓')
  1000. ->group('jjcp_gdbh,jjcp_cpdh')
  1001. ->column('CONCAT(jjcp_gdbh, "-", rtrim(jjcp_cpdh)), sum(jjcp_sl)');
  1002. foreach ($rows as $key=>$value) {
  1003. $rows[$key]['实际投料'] = (string)floatval($value['实际投料']*10000);
  1004. if(array_key_exists($value['jjcp_gdbh'].'-'.$value['jjcp_cpdh'],$brr)){
  1005. $rows[$key]['入仓数量'] = $brr[$value['jjcp_gdbh'].'-'.$value['jjcp_cpdh']];
  1006. if($rows[$key]['实际投料']!=0){
  1007. $rows[$key]['投入产出率'] = number_format($rows[$key]['入仓数量']/$rows[$key]['实际投料']*100,2);
  1008. }else{
  1009. $rows[$key]['投入产出率'] = '';
  1010. }
  1011. }else{
  1012. $rows[$key]['入仓数量'] = '';
  1013. $rows[$key]['投入产出率'] = '';
  1014. }
  1015. }
  1016. $data = [
  1017. 'total' => $total,
  1018. 'rows' => $rows,
  1019. ];
  1020. $this->success('成功',$data);
  1021. }
  1022. /**
  1023. * 各日统计列表excel导出
  1024. * @ApiMethod (POST)
  1025. * @param string file_name
  1026. * @param array fields
  1027. */
  1028. public function dayExport()
  1029. {
  1030. //get请求
  1031. if(!$this->request->isPost()){
  1032. $this->error('请求方式错误');
  1033. }
  1034. $req = $this->request->param();
  1035. if (!isset($req['file_name'])){
  1036. $this->error('参数错误','file_name');
  1037. }
  1038. if (!(isset($req['fields']) && count($req['fields'])!=0)){
  1039. $this->error('参数错误','fields',100);
  1040. }
  1041. if (isset($req['key_word']) && !empty($req['key_word'])){
  1042. $where['c.jjcp_sj | c.jjcp_gdbh | c.jjcp_cpmc | c.jjcp_cpdh | g.实际投料'] = ['like','%'.$req['key_word'].'%'];
  1043. }
  1044. $arr = [
  1045. 'jjcp_gdbh' =>['jjcp_gdbh'],
  1046. 'jjcp_yjno' =>['jjcp_yjno'],
  1047. 'jjcp_cpmc' =>['印件名称'],
  1048. '成品编码' =>['成品编码'],
  1049. '成品名称' =>['成品名称'],
  1050. '实际投料' =>['实际投料'],
  1051. 'jjcp_sls' =>['入仓数量'],
  1052. 'jjcp_sj' =>['完工日期'],
  1053. ];
  1054. $data[0] = [];
  1055. foreach ($req['fields'] as $k=>$v){
  1056. if(array_key_exists($v,$arr)){
  1057. array_push($data[0],$arr[$v][0]);
  1058. }
  1059. }
  1060. $where = [
  1061. 'c.jjcp_smb'=>['<>','']
  1062. ];
  1063. //客户编号
  1064. $rows = db('成品入仓')->alias('c')
  1065. ->field('c.jjcp_gdbh, c.jjcp_yjno, rtrim(c.jjcp_cpmc) as jjcp_cpmc, rtrim(c.jjcp_cpdh) as jjcp_cpdh,
  1066. rtrim(c.成品编码) as 成品编码, rtrim(c.成品名称) as 成品名称, sum(jjcp_sl) as jjcp_sls,
  1067. g.实际投料, LEFT(c.jjcp_sj, 10) as jjcp_sj
  1068. ')
  1069. ->where($where)
  1070. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  1071. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  1072. ->order('c.jjcp_sj desc')
  1073. ->group('c.jjcp_gdbh, c.jjcp_cpdh')
  1074. ->select();
  1075. foreach ($rows as $key=>$value) {
  1076. $subArray = [];
  1077. foreach ($arr as $k=>$v){
  1078. if($k=='实际投料'){
  1079. $subArray[$k] = (string)floatval($value['实际投料']*10000);
  1080. }else{
  1081. $subArray[$k] = $rows[$key][$k];
  1082. }
  1083. }
  1084. array_push($data,$subArray);
  1085. }
  1086. $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
  1087. }
  1088. /**
  1089. * 入仓末板数据统计列表
  1090. * @ApiMethod (GET)
  1091. * @param string $date 时间
  1092. * @param string $sys_id 用户
  1093. */
  1094. public function mbList()
  1095. {
  1096. //get请求
  1097. if(!$this->request->isGet()){
  1098. $this->error('请求方式错误');
  1099. }
  1100. $req = $this->request->param();
  1101. // $page = 1;
  1102. // $limit = 15;
  1103. // if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  1104. // if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  1105. $date = date('Y-m-d',strtotime('-3 month'));
  1106. $arr1 = db('db_包装产量预报')
  1107. ->field('sczl_gdbh1, sczl_gdbh2, sczl_gdbh3, sczl_gdbh4, sczl_gdbh5, sczl_gdbh6,
  1108. cast(substr(sczl_yjGx1,1,2) as signed) as sczl_yjGx1, cast(substr(sczl_yjGx2,1,2) as signed) as sczl_yjGx2,
  1109. cast(substr(sczl_yjGx3,1,2) as signed) as sczl_yjGx3, cast(substr(sczl_yjGx4,1,2) as signed) as sczl_yjGx4,
  1110. cast(substr(sczl_yjGx5,1,2) as signed) as sczl_yjGx5, cast(substr(sczl_yjGx6,1,2) as signed) as sczl_yjGx6,
  1111. (sczl_cl1*sczl_PgCl1+sczl_clAdd1) as sczl_cls1,
  1112. (sczl_cl2*sczl_PgCl2+sczl_clAdd2) as sczl_cls2,
  1113. (sczl_cl3*sczl_PgCl3+sczl_clAdd3) as sczl_cls3,
  1114. (sczl_cl4*sczl_PgCl4+sczl_clAdd4) as sczl_cls4,
  1115. (sczl_cl5*sczl_PgCl5+sczl_clAdd5) as sczl_cls5,
  1116. (sczl_cl6*sczl_PgCl6+sczl_clAdd6) as sczl_cls6
  1117. ')
  1118. ->where('sczl_rq','>=',$date)
  1119. ->select();
  1120. $data1 = [];
  1121. foreach ($arr1 as $k=>$v){
  1122. for ($i=1;$i<=6;$i++){
  1123. if (!empty($v['sczl_gdbh'.$i])){
  1124. $v['sczl_gdbh'.$i] = strtoupper($v['sczl_gdbh'.$i]);
  1125. if(array_key_exists($v['sczl_gdbh'.$i].'-'.$v['sczl_yjGx'.$i],$data1)){
  1126. $data1[$v['sczl_gdbh'.$i].'-'.$v['sczl_yjGx'.$i]] += $v['sczl_cls'.$i];
  1127. }else{
  1128. $data1[$v['sczl_gdbh'.$i].'-'.$v['sczl_yjGx'.$i]] = $v['sczl_cls'.$i];
  1129. }
  1130. }
  1131. }
  1132. }
  1133. krsort($data1);
  1134. //成品入仓中jjcp_smb不为空的工单
  1135. // $rows1 = db('成品入仓')
  1136. // ->where('jjcp_smb','<>','')
  1137. // ->order('jjcp_gdbh desc')
  1138. // ->column("CONCAT(jjcp_gdbh, '-', jjcp_yjno) AS gdyj, UniqId");
  1139. $rows2 = db('成品入仓')
  1140. ->where('jjcp_sj','>=',$date)
  1141. ->group('jjcp_gdbh, jjcp_cpdh')
  1142. ->column("CONCAT( jjcp_gdbh, '-', jjcp_yjno) AS gdyj, max(jjcp_smb) as jjcp_smb,
  1143. sum(jjcp_sl) as jjcp_sls, left(max(jjcp_sj),10) as jjcp_sj,UniqId");
  1144. // $rows3 = db('工单_印件资料')->cache(true,86400)
  1145. // ->group('Yj_Gdbh, yj_Yjno')
  1146. // ->column("CONCAT( Yj_Gdbh, '-', yj_Yjno) AS gdyj,
  1147. // Yj_Gdbh, yj_Yjno, yj_yjmc, yj_成品数量, yj_实际投料");
  1148. $data = [];
  1149. foreach($data1 as $key=>$value){
  1150. // if(!array_key_exists($key,$rows1)){
  1151. $subArray = [];
  1152. $gdbh = strtoupper(explode('-',$key)[0]);
  1153. $yjno = explode('-',$key)[1];
  1154. $res = db('工单_印件资料')
  1155. ->where('Yj_Gdbh',$gdbh)
  1156. ->where('yj_Yjno',$yjno)
  1157. ->field('Yj_Gdbh, yj_Yjno, yj_yjmc, yj_成品数量, (yj_平张投料 * yj_ks * yj_ls) as 投料')
  1158. ->find();
  1159. if(!empty($res)){
  1160. $subArray['Yj_Gdbh'] = $res['Yj_Gdbh'];
  1161. $subArray['yj_Yjno'] = $res['yj_Yjno'];
  1162. $subArray['yj_yjmc'] = trim($res['yj_yjmc']);
  1163. $subArray['yj_成品数量'] = (string)floatval($res['yj_成品数量']*10000);
  1164. $subArray['yj_实际投料'] = (string)floatval($res['投料']);
  1165. }else{
  1166. $subArray['Yj_Gdbh'] = '';
  1167. $subArray['yj_Yjno'] = '';
  1168. $subArray['yj_yjmc'] = '';
  1169. $subArray['yj_成品数量'] = '';
  1170. $subArray['yj_实际投料'] = '';
  1171. }
  1172. if(array_key_exists($key,$rows2)){
  1173. $subArray['jjcp_smb'] = $rows2[$key]['jjcp_smb'];
  1174. $subArray['jjcp_sls'] = $rows2[$key]['jjcp_sls'];
  1175. $subArray['jjcp_sj'] = $rows2[$key]['jjcp_sj'];
  1176. }else{
  1177. $subArray['jjcp_smb'] = '';
  1178. $subArray['jjcp_sls'] = '';
  1179. $subArray['jjcp_sj'] = '';
  1180. }
  1181. $subArray['sczl_cls'] = (string)floatval($value);
  1182. array_push($data,$subArray);
  1183. }
  1184. // }
  1185. // $rows = db('db_包装产量预报')
  1186. // ->field('sczl_rq,sczl_gdbh1,sczl_gdbh2,sczl_gdbh3,sczl_gdbh4,sczl_gdbh5,sczl_gdbh6,Sys_rq,mod_rq,UniqId')
  1187. // ->where('Sys_rq','>=','2023-10-25')
  1188. // ->select();
  1189. // $uniqueValues = [];
  1190. // foreach ($rows as $row) {
  1191. // $gdbhArray = array($row['sczl_gdbh1'], $row['sczl_gdbh2'], $row['sczl_gdbh3'], $row['sczl_gdbh4'], $row['sczl_gdbh5'], $row['sczl_gdbh6']);
  1192. // $uniqueValues = array_merge($uniqueValues, array_unique($gdbhArray));
  1193. // }
  1194. // $uniqueValues = array_values(array_unique($uniqueValues));
  1195. // halt($uniqueValues);
  1196. // $rows = db('成品入仓')->alias('c')
  1197. // ->field('c.jjcp_gdbh, c.jjcp_yjno, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  1198. // y.yj_成品数量, y.yj_实际投料, rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_smb) as jjcp_smb,
  1199. // sum(c.jjcp_sl) as jjcp_sls, left(max(c.Sys_rq),10) as Sys_rq')
  1200. // ->where($where)
  1201. // ->where('y.yj_Yjdh=c.jjcp_cpdh')
  1202. // ->join('工单_印件资料 y','y.Yj_Gdbh=c.jjcp_gdbh')
  1203. // ->order('c.jjcp_gdbh desc, c.jjcp_yjno asc')
  1204. // ->group('c.jjcp_gdbh, c.jjcp_cpdh')
  1205. // ->page($page,$limit)
  1206. // ->select();
  1207. // $total = db('成品入仓')->alias('c')
  1208. // ->where($where)
  1209. // ->where('y.yj_Yjdh=c.jjcp_cpdh')
  1210. // ->join('工单_印件资料 y','y.Yj_Gdbh=c.jjcp_gdbh')
  1211. // ->group('c.jjcp_gdbh, c.jjcp_cpdh')
  1212. // ->count();
  1213. // $brr = db('成品入仓')
  1214. // ->group('jjcp_gdbh,jjcp_cpdh')
  1215. // ->column('CONCAT(jjcp_gdbh, "-", rtrim(jjcp_cpdh)), sum(jjcp_sl)');
  1216. // $num = db('db_包装产量预报')->count();
  1217. // $arr1 = db('db_包装产量预报')
  1218. // ->field('sczl_gdbh1, sczl_gdbh2, sczl_gdbh3, sczl_gdbh4, sczl_gdbh5, sczl_gdbh6,
  1219. // substr(sczl_yjGx1,2,1) as sczl_yjGx1, substr(sczl_yjGx2,2,1) as sczl_yjGx2,
  1220. // substr(sczl_yjGx3,2,1) as sczl_yjGx3, substr(sczl_yjGx4,2,1) as sczl_yjGx4,
  1221. // substr(sczl_yjGx5,2,1) as sczl_yjGx5, substr(sczl_yjGx6,2,1) as sczl_yjGx6,
  1222. // (sczl_cl1*sczl_PgCl1+sczl_clAdd1) as sczl_cls1,
  1223. // (sczl_cl2*sczl_PgCl2+sczl_clAdd2) as sczl_cls2,
  1224. // (sczl_cl3*sczl_PgCl3+sczl_clAdd3) as sczl_cls3,
  1225. // (sczl_cl4*sczl_PgCl4+sczl_clAdd4) as sczl_cls4,
  1226. // (sczl_cl5*sczl_PgCl5+sczl_clAdd5) as sczl_cls5,
  1227. // (sczl_cl6*sczl_PgCl6+sczl_clAdd6) as sczl_cls6
  1228. // ')
  1229. // ->limit($num)
  1230. // ->select();
  1231. // $data1 = [];
  1232. // foreach ($arr1 as $k=>$v){
  1233. // for ($i=1;$i<=6;$i++){
  1234. // if(array_key_exists($v['sczl_gdbh'.$i].'-'.$v['sczl_yjGx'.$i],$data1)){
  1235. // $data1[$v['sczl_gdbh'.$i].'-'.$v['sczl_yjGx'.$i]] += $v['sczl_cls'.$i];
  1236. // }else{
  1237. // $data1[$v['sczl_gdbh'.$i].'-'.$v['sczl_yjGx'.$i]] = $v['sczl_cls'.$i];
  1238. // }
  1239. // }
  1240. // }
  1241. // foreach ($rows as $key=>$value) {
  1242. // $rows[$key]['yj_成品数量'] = (string)floatval($value['yj_成品数量']*10000);
  1243. // $rows[$key]['yj_实际投料'] = (string)floatval($value['yj_实际投料']*10000);
  1244. // if(array_key_exists($value['jjcp_gdbh'].'-'.$value['jjcp_yjno'],$data1)){
  1245. // $rows[$key]['包装产量'] = $data1[$value['jjcp_gdbh'].'-'.$value['jjcp_yjno']];
  1246. // }else{
  1247. // $rows[$key]['包装产量'] = '';
  1248. // }
  1249. // if(array_key_exists($value['jjcp_gdbh'].'-'.$value['jjcp_cpdh'],$brr)){
  1250. // $rows[$key]['入仓数量'] = $brr[$value['jjcp_gdbh'].'-'.$value['jjcp_cpdh']];
  1251. // }else{
  1252. // $rows[$key]['入仓数量'] = '';
  1253. // }
  1254. // if($value['jjcp_smb'] !=''){
  1255. // $rows[$key]['状态'] = '完工';
  1256. // $rows[$key]['缺数'] = (int)$rows[$key]['yj_成品数量']-(int)$rows[$key]['包装产量'];
  1257. // }else{
  1258. // $rows[$key]['状态'] = '';
  1259. // $rows[$key]['缺数'] = '';
  1260. // }
  1261. // }
  1262. $data = [
  1263. 'total' => count($data),
  1264. 'rows' => $data,
  1265. ];
  1266. $this->success('成功',$data);
  1267. }
  1268. /**
  1269. * 入仓末板数据统计列表excel导出
  1270. * @ApiMethod (POST)
  1271. * @param string file_name
  1272. * @param array fields
  1273. */
  1274. public function mbExport()
  1275. {
  1276. //get请求
  1277. if(!$this->request->isPost()){
  1278. $this->error('请求方式错误');
  1279. }
  1280. $req = $this->request->param();
  1281. if (!isset($req['file_name'])){
  1282. $this->error('参数错误','file_name');
  1283. }
  1284. if (!(isset($req['fields']) && count($req['fields'])!=0)){
  1285. $this->error('参数错误','fields',100);
  1286. }
  1287. $arr = [
  1288. 'Yj_Gdbh' =>['工单编号'],
  1289. 'yj_Yjno' =>['印件号'],
  1290. 'yj_yjmc' =>['印件名称'],
  1291. 'yj_成品数量' =>['计划交货数量'],
  1292. 'yj_实际投料' =>['印件投料'],
  1293. 'sczl_cls' =>['包装产量'],
  1294. 'jjcp_sj' =>['最近入仓时间'],
  1295. 'jjcp_sls' =>['入仓产量'],
  1296. 'status' =>['完工'],
  1297. '缺数' =>['缺数'],
  1298. ];
  1299. $data[0] = [];
  1300. foreach ($req['fields'] as $k=>$v){
  1301. if(array_key_exists($v,$arr)){
  1302. array_push($data[0],$arr[$v][0]);
  1303. }
  1304. }
  1305. $date = date('Y-m-d',strtotime('-3 month'));
  1306. $arr1 = db('db_包装产量预报')
  1307. ->field('sczl_gdbh1, sczl_gdbh2, sczl_gdbh3, sczl_gdbh4, sczl_gdbh5, sczl_gdbh6,
  1308. cast(substr(sczl_yjGx1,1,2) as signed) as sczl_yjGx1, cast(substr(sczl_yjGx2,1,2) as signed) as sczl_yjGx2,
  1309. cast(substr(sczl_yjGx3,1,2) as signed) as sczl_yjGx3, cast(substr(sczl_yjGx4,1,2) as signed) as sczl_yjGx4,
  1310. cast(substr(sczl_yjGx5,1,2) as signed) as sczl_yjGx5, cast(substr(sczl_yjGx6,1,2) as signed) as sczl_yjGx6,
  1311. (sczl_cl1*sczl_PgCl1+sczl_clAdd1) as sczl_cls1,
  1312. (sczl_cl2*sczl_PgCl2+sczl_clAdd2) as sczl_cls2,
  1313. (sczl_cl3*sczl_PgCl3+sczl_clAdd3) as sczl_cls3,
  1314. (sczl_cl4*sczl_PgCl4+sczl_clAdd4) as sczl_cls4,
  1315. (sczl_cl5*sczl_PgCl5+sczl_clAdd5) as sczl_cls5,
  1316. (sczl_cl6*sczl_PgCl6+sczl_clAdd6) as sczl_cls6
  1317. ')
  1318. ->where('sczl_rq','>=',$date)
  1319. ->select();
  1320. $data1 = [];
  1321. foreach ($arr1 as $k=>$v){
  1322. for ($i=1;$i<=6;$i++){
  1323. if(array_key_exists($v['sczl_gdbh'.$i].'-'.$v['sczl_yjGx'.$i],$data1)){
  1324. $data1[$v['sczl_gdbh'.$i].'-'.$v['sczl_yjGx'.$i]] += $v['sczl_cls'.$i];
  1325. }else{
  1326. $data1[$v['sczl_gdbh'.$i].'-'.$v['sczl_yjGx'.$i]] = $v['sczl_cls'.$i];
  1327. }
  1328. }
  1329. }
  1330. krsort($data1);
  1331. //成品入仓中jjcp_smb不为空的工单
  1332. $rows1 = db('成品入仓')
  1333. ->where('jjcp_smb','<>','')
  1334. ->order('jjcp_gdbh desc')
  1335. ->column("CONCAT(jjcp_gdbh, '-', jjcp_yjno) AS gdyj, UniqId");
  1336. $rows2 = db('成品入仓')
  1337. ->where('jjcp_sj','>=',$date)
  1338. ->group('jjcp_gdbh, jjcp_cpdh')
  1339. ->column("CONCAT( jjcp_gdbh, '-', jjcp_yjno) AS gdyj, jjcp_smb,
  1340. sum(jjcp_sl) as jjcp_sls, left(max(jjcp_sj),10) as jjcp_sj");
  1341. $rows3 = db('工单_印件资料')->cache(true,86400)
  1342. ->group('Yj_Gdbh, yj_Yjno')
  1343. ->column("CONCAT( Yj_Gdbh, '-', yj_Yjno) AS gdyj,
  1344. Yj_Gdbh, yj_Yjno, yj_yjmc, yj_成品数量, yj_实际投料");
  1345. foreach($data1 as $key=>$value){
  1346. if(!array_key_exists($key,$rows1)){
  1347. $subArray = [];
  1348. foreach ($arr as $k=>$v){
  1349. if($k=='yj_成品数量' || $k=='yj_实际投料'){
  1350. if(array_key_exists($key,$rows3)){
  1351. $subArray[$k] = (string)floatval($rows3[$key][$k]*10000);
  1352. }else{
  1353. $subArray[$k] = '';
  1354. }
  1355. }else if($k=='Yj_Gdbh' || $k=='yj_Yjno'){
  1356. if(array_key_exists($key,$rows3)){
  1357. $subArray[$k] = $rows3[$key][$k];
  1358. }else{
  1359. $subArray[$k] = '';
  1360. }
  1361. }else if($k=='yj_yjmc'){
  1362. if(array_key_exists($key,$rows3)){
  1363. $subArray[$k] = trim($rows3[$key][$k]);
  1364. }else{
  1365. $subArray[$k] = '';
  1366. }
  1367. }else if($k=='sczl_cls'){
  1368. $subArray[$k] = (string)floatval($value);
  1369. }else if($k=='status'){
  1370. if(array_key_exists($key,$rows2) && $rows2[$key]['jjcp_smb'] !=''){
  1371. $subArray[$k] = '完工';
  1372. }else{
  1373. $subArray[$k] = '';
  1374. }
  1375. }else if($k=='缺数'){
  1376. if(array_key_exists($key,$rows2) && $rows2[$key]['jjcp_smb'] !=''){
  1377. $subArray[$k]['缺数'] = (int)$rows3[$key]['yj_成品数量']-(int)$value;
  1378. }else{
  1379. $subArray[$k] = '';
  1380. }
  1381. }else{
  1382. if(array_key_exists($key,$rows2)){
  1383. $subArray[$k] = $rows2[$key][$k];
  1384. $subArray[$k] = $rows2[$key][$k];
  1385. $subArray[$k] = $rows2[$key][$k];
  1386. }else{
  1387. $subArray[$k] = '';
  1388. $subArray[$k] = '';
  1389. $subArray[$k] = '';
  1390. }
  1391. }
  1392. }
  1393. array_push($data,$subArray);
  1394. }
  1395. }
  1396. $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
  1397. }
  1398. }