FinishedProductWarehousing.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. /**
  5. * 成品入仓维护接口
  6. */
  7. class FinishedProductWarehousing extends Api
  8. {
  9. protected $noNeedLogin = ['*'];
  10. protected $noNeedRight = ['*'];
  11. /**
  12. * 首页
  13. *
  14. */
  15. public function index()
  16. {
  17. $this->success('请求成功');
  18. }
  19. /**
  20. * 侧边栏
  21. * @ApiMethod (GET)
  22. */
  23. public function getTab()
  24. {
  25. //get请求
  26. if(!$this->request->isGet()){
  27. $this->error('请求方式错误');
  28. }
  29. $rows = db()->table('成品入仓')
  30. ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
  31. ->group('date')
  32. ->order('UniqId desc')
  33. ->limit(50)
  34. ->select();
  35. $arr = db()->table('成品入仓')
  36. ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(sys_id) as count')
  37. ->where('sys_rq','>=',$rows[49]['date'])
  38. ->group('date, sys_id')
  39. ->select();
  40. foreach($rows as $key=>$value){
  41. $rows[$key]['sys'] = [];
  42. foreach($arr as $k=>$v){
  43. if($value['date'] == $v['date']){
  44. unset($v['date']);
  45. array_push($rows[$key]['sys'],$v);
  46. unset($arr[$k]);
  47. }
  48. }
  49. $rows[$key]['date'] = str_replace('-', '.', $rows[$key]['date']);
  50. }
  51. $this->success('成功',$rows);
  52. }
  53. /**
  54. * 侧边栏
  55. * @ApiMethod (GET)
  56. */
  57. public function getTabByGdbh()
  58. {
  59. //get请求
  60. if(!$this->request->isGet()){
  61. $this->error('请求方式错误');
  62. }
  63. $rows = db()->table('成品入仓')
  64. ->field('jjcp_gdbh, rtrim(jjcp_cpdh) as jjcp_cpdh, LEFT(Sys_rq, 10) as Sys_rq')
  65. ->order('Sys_rq desc')
  66. ->select();
  67. $arr = db()->table('工单_基本资料')
  68. ->column('CONCAT(Gd_gdbh, "-", rtrim(Gd_cpdh)) AS gdcp, CONCAT(rtrim(Gd_khdh), " 【", rtrim(Gd_khmc)) AS kh');
  69. $data = [];
  70. foreach ($rows as $value) {
  71. $key = $value['jjcp_gdbh'].'-'.$value['jjcp_cpdh'];
  72. if (isset($arr[$key]) && !isset($data[$arr[$key]])) {
  73. $data[$arr[$key]] = $value['Sys_rq'];
  74. }
  75. }
  76. // 对键进行升序排序
  77. uksort($data, function($a, $b) use ($data) {
  78. if ($data[$a] == $data[$b]) {
  79. return ($a > $b) ? 1 : -1; // 在值相同的情况下,根据键进行升序排列
  80. }
  81. return ($data[$a] < $data[$b]) ? 1 : -1;
  82. });
  83. $this->success('成功',$data);
  84. }
  85. /**
  86. * 列表
  87. * @ApiMethod (GET)
  88. * @param string $date 时间
  89. * @param string $sys_id 用户
  90. */
  91. public function getList()
  92. {
  93. //get请求
  94. if(!$this->request->isGet()){
  95. $this->error('请求方式错误');
  96. }
  97. $req = $this->request->param();
  98. if (!isset($req['date'])) $this->error('参数缺失');
  99. $page = 1;
  100. $limit = 15;
  101. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  102. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  103. if(strpos($req['date'],'-')){
  104. $where = ['c.Sys_rq'=>['like','%'.$req['date'].'%']];
  105. $option = ['Sys_rq'=>['like','%'.$req['date'].'%']];
  106. }else{
  107. $where = [];
  108. $option = [];
  109. }
  110. if (isset($req['sys_id']) && !empty($req['sys_id'])){
  111. $where['c.Sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
  112. $option['Sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
  113. }
  114. //客户编号
  115. $rows = db()->table('成品入仓')->alias('c')
  116. ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
  117. rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh,
  118. c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj,
  119. rtrim(c.jjcp_smb) as jjcp_smb, rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  120. rtrim(c.成品编码) as 成品编码, rtrim(c.成品名称) as 成品名称,
  121. rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, LEFT(c.成品编码,4) as 客户编号, rtrim(g.Gd_客户名称) as Gd_客户名称,
  122. rtrim(c.机型备注) as 机型备注, rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
  123. ->where($where)
  124. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  125. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  126. ->order('c.UniqId desc')
  127. ->page($page,$limit)
  128. ->select();
  129. $total = db()->table('成品入仓')->where($option)->count();
  130. foreach ($rows as $key=>$value) {
  131. $row = db()->table('成品入仓')
  132. ->field('LEFT(Sys_rq, 10) as Sys_rq,jjcp_sl')
  133. ->where(['jjcp_gdbh'=>$value['jjcp_gdbh'], 'jjcp_cpdh'=>$value['jjcp_cpdh']])
  134. ->order('Sys_rq desc')
  135. ->select();
  136. $rows[$key]['jjcp_sls'] = 0;
  137. foreach ($row as $k=>$v) {
  138. $rows[$key]['jjcp_sls'] += $v['jjcp_sl'];
  139. }
  140. if ($value['订单数量']!=0){
  141. $rows[$key]['完成率'] = number_format($rows[$key]['jjcp_sls']/$value['订单数量']/100,2);
  142. }else{
  143. $rows[$key]['完成率'] = '';
  144. }
  145. $rows[$key]['订单数量'] = floatval($value['订单数量']*10000);
  146. $rows[$key]['最近入仓日期'] = $row[0]['Sys_rq'];
  147. $rows[$key]['Mod_rq'] = $value['Mod_rq']=='1900-01-01 00:00:00' ? '' :$value['Mod_rq'];
  148. }
  149. $data = [
  150. 'total' => $total,
  151. 'rows' => $rows,
  152. ];
  153. $this->success('成功',$data);
  154. }
  155. /**
  156. * 定位
  157. * @ApiMethod (GET)
  158. * @param string $gdbh 工单编号
  159. * @param string $cpmc 产品名称
  160. * @param string $page 页码
  161. * @param string $limit 数量
  162. */
  163. public function locate()
  164. {
  165. //get请求
  166. if(!$this->request->isGet()){
  167. $this->error('请求方式错误');
  168. }
  169. $req = $this->request->param();
  170. $page = 1;
  171. $limit = 15;
  172. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  173. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  174. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  175. $where = ['c.jjcp_gdbh'=>[ 'like', '%' . $req['gdbh'] . '%']];
  176. $option = ['jjcp_gdbh'=>[ 'like', '%' . $req['gdbh'] . '%']];
  177. //客户编号
  178. $rows = db()->table('成品入仓')->alias('c')
  179. ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
  180. rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh,
  181. c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj,
  182. rtrim(c.jjcp_smb) as jjcp_smb, rtrim(y.yj_Yjdh) as yj_Yjdh, rtrim(y.yj_yjmc) as yj_yjmc,
  183. rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  184. rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, LEFT(c.成品编码,4) as 客户编号, rtrim(g.Gd_客户名称) as Gd_客户名称,
  185. rtrim(c.机型备注) as 机型备注, rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
  186. ->where($where)
  187. ->where('y.yj_Yjno=c.jjcp_yjno')
  188. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  189. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  190. ->join('工单_印件资料 y','y.Yj_Gdbh=c.jjcp_gdbh')
  191. ->order('c.UniqId desc')
  192. ->page($page,$limit)
  193. ->select();
  194. $total = db()->table('成品入仓')->where($option)->count();
  195. }else{
  196. if (isset($req['cpmc']) && !empty($req['cpmc'])){
  197. //查询工单表
  198. $gd = db()->table('工单_基本资料')
  199. ->where('Gd_cpmc', 'LIKE', '%'.$req['cpmc'].'%')
  200. ->column('Gd_gdbh');
  201. $where = ['c.jjcp_gdbh'=>['in', $gd]];
  202. $option = ['jjcp_gdbh'=>['in', $gd]];
  203. //客户编号
  204. $rows = db()->table('成品入仓')->alias('c')
  205. ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
  206. rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh,
  207. c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj,
  208. rtrim(c.jjcp_smb) as jjcp_smb, rtrim(y.yj_Yjdh) as yj_Yjdh, rtrim(y.yj_yjmc) as yj_yjmc,
  209. rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  210. rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, LEFT(c.成品编码,4) as 客户编号, rtrim(g.Gd_客户名称) as Gd_客户名称,
  211. rtrim(c.机型备注) as 机型备注, rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
  212. ->where($where)
  213. ->where('y.yj_Yjno=c.jjcp_yjno')
  214. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  215. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  216. ->join('工单_印件资料 y','y.Yj_Gdbh=c.jjcp_gdbh')
  217. ->order('c.UniqId desc')
  218. ->page($page,$limit)
  219. ->select();
  220. $total = db()->table('成品入仓')->where($option)->count();
  221. }else{
  222. $this->error('参数错误');
  223. }
  224. }
  225. foreach ($rows as $key=>$value) {
  226. $row = db()->table('成品入仓')
  227. ->field('LEFT(Sys_rq, 10) as Sys_rq,jjcp_sl')
  228. ->where(['jjcp_gdbh'=>$value['jjcp_gdbh'], 'jjcp_cpdh'=>$value['jjcp_cpdh']])
  229. ->order('Sys_rq desc')
  230. ->select();
  231. $rows[$key]['jjcp_sls'] = 0;
  232. foreach ($row as $k=>$v) {
  233. $rows[$key]['jjcp_sls'] += $v['jjcp_sl'];
  234. }
  235. if ($value['订单数量']!=0){
  236. $rows[$key]['完成率'] = number_format($rows[$key]['jjcp_sls']/$value['订单数量']/100,2);
  237. }else{
  238. $rows[$key]['完成率'] = '';
  239. }
  240. $rows[$key]['订单数量'] = floatval($value['订单数量']*10000);
  241. $rows[$key]['最近入仓日期'] = $row[0]['Sys_rq'];
  242. $rows[$key]['Mod_rq'] = $value['Mod_rq']=='1900-01-01 00:00:00' ? '' :$value['Mod_rq'];
  243. }
  244. $data = [
  245. 'total' => $total,
  246. 'rows' => $rows,
  247. ];
  248. $this->success('成功',$data);
  249. }
  250. /**
  251. * 获取信息
  252. * @ApiMethod (GET)
  253. * @param string $UniqId UniqId
  254. */
  255. public function getInfo()
  256. {
  257. //get请求
  258. if(!$this->request->isGet()){
  259. $this->error('请求方式错误');
  260. }
  261. $req = $this->request->param();
  262. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  263. $UniqId = $req['UniqId'];
  264. }else{
  265. $this->error('参数错误');
  266. }
  267. //客户编号
  268. $rows = db()->table('成品入仓')->alias('c')
  269. ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
  270. rtrim(c.jjcp_num) as jjcp_num,
  271. c.jjcp_gdbh, c.jjcp_yjno, rtrim(c.订单编号) as 订单编号,
  272. rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  273. rtrim(c.成品编码) as 成品编码, rtrim(c.成品名称) as 成品名称,
  274. rtrim(c.客户料号) as 客户料号,
  275. rtrim(c.jjcp_smb) as jjcp_smb, LEFT(c.jjcp_sj, 10) as jjcp_sj,
  276. c.jjcp_sl, rtrim(c.jjcp_dw) as jjcp_dw,
  277. g.订单数量*10000 as 订单数量, rtrim(c.机型备注) as 机型备注, rtrim(c.jjcp_desc) as jjcp_desc,
  278. rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
  279. ->where('c.UniqId',$UniqId)
  280. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  281. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  282. ->find();
  283. $rows['jjcp_sls'] = db()->table('成品入仓')
  284. ->where(['jjcp_gdbh'=>$rows['jjcp_gdbh'], 'jjcp_cpdh'=>$rows['jjcp_cpdh']])
  285. ->sum('jjcp_sl');
  286. $this->success('成功',$rows);
  287. }
  288. /**
  289. * 获取仓库信息
  290. * @ApiMethod (GET)
  291. * @param string keyword 关键词
  292. */
  293. public function getCk()
  294. {
  295. //get请求
  296. if(!$this->request->isGet()){
  297. $this->error('请求方式错误');
  298. }
  299. $req = $this->request->param();
  300. $key_word = '';
  301. if (isset($req['key_word']) && !empty($req['key_word'])){
  302. $key_word = $req['key_word'];
  303. }
  304. $rs = db()->table('物料_仓库信息')
  305. ->field('rtrim(编号) as 编号, rtrim(名称) as 名称')
  306. ->where('编号|名称','like','%'.$key_word.'%')
  307. ->where('名称','in',['面材仓库','主要产成品'])
  308. ->select();
  309. $this->success('成功',$rs);
  310. }
  311. /**
  312. * 查询印件工序及产品名称
  313. * @ApiMethod (GET)
  314. * @param string $gdbh 工单编号
  315. */
  316. public function getGd()
  317. {
  318. //get请求
  319. if(!$this->request->isGet()){
  320. $this->error('请求方式错误');
  321. }
  322. $req = $this->request->param();
  323. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  324. $gdbh = $req['gdbh'];
  325. }else{
  326. $this->error('参数错误');
  327. }
  328. $rows = db()->table('工单_基本资料')->alias('g')
  329. ->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 客户料号')
  330. ->where(['g.Gd_gdbh'=>$gdbh])
  331. ->join(['产品_印件资料'=>'j'],'g.Gd_cpdh=j.yj_yjdh and g.成品代号=j.yj_cpdh')
  332. ->order('j.yj_yjno asc')
  333. ->select();
  334. foreach ($rows as $key=>$value){
  335. $rows[$key]['gdyj'] = $value['Gd_gdbh'].' -'.sprintf("%02d", $value['yj_yjno']).'-'.$value['yj_yjmc'];
  336. }
  337. $this->success('成功',$rows);
  338. }
  339. /**
  340. * 查询工单数量
  341. * @ApiMethod (GET)
  342. * @param string $gdbh 工单编号
  343. * @param string $cpdh 产品代号
  344. * @param string $rcsl 入仓数量
  345. */
  346. public function getGdsl()
  347. {
  348. //get请求
  349. if(!$this->request->isGet()){
  350. $this->error('请求方式错误');
  351. }
  352. $req = $this->request->param();
  353. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  354. $gdbh = $req['gdbh'];
  355. }else{
  356. $this->error('参数错误');
  357. }
  358. if (isset($req['cpdh']) && !empty($req['cpdh'])){
  359. $cpdh = $req['cpdh'];
  360. }else{
  361. $this->error('参数错误');
  362. }
  363. // if (isset($req['rcsl'])){
  364. // $rcsl = $req['rcsl'];
  365. // }else{
  366. // $this->error('参数错误');
  367. // }
  368. $rows = db()->table('工单_基本资料')->alias('g')
  369. ->field('订单数量*10000 as 订单数量, gd_statu')
  370. ->where(['Gd_gdbh'=>$gdbh, 'Gd_cpdh'=>$cpdh])
  371. ->find();
  372. if (!$rows) $this->error('未查询到记录');
  373. $rows['jjcp_sls'] = db()->table('成品入仓')
  374. ->where(['jjcp_gdbh'=>$gdbh, 'jjcp_cpdh'=>$cpdh])
  375. ->sum('jjcp_sl');
  376. // if ($rows['订单数量']<($rows['jjcp_sls']+$rcsl) || mb_substr($rows['gd_statu'],-3,3)=='已完工'){
  377. // $this->error('已完工或入仓数量超过订单数量',$rows);
  378. // }
  379. $this->success('成功',$rows);
  380. }
  381. /**
  382. * 新增
  383. * @ApiMethod (POST)
  384. * @param string
  385. */
  386. public function add()
  387. {
  388. if(!$this->request->isPost()){
  389. $this->error('请求方式错误');
  390. }
  391. $req = $this->request->param();
  392. $arr = [
  393. 'Sys_id',
  394. '入仓类型', '仓库编号', '仓库名称',
  395. 'jjcp_num',
  396. 'jjcp_gdbh', 'jjcp_yjno', '订单编号',
  397. 'jjcp_cpdh', 'jjcp_cpmc',
  398. '成品编码', '成品名称',
  399. '客户料号',
  400. 'jjcp_smb', 'jjcp_sj',
  401. 'jjcp_sl', 'jjcp_dw',
  402. '机型备注',
  403. 'jjcp_desc'
  404. ];
  405. $data = [];
  406. foreach ($arr as $key => $value){
  407. if (!isset($req[$value])){
  408. $this->error('参数错误',$value,$key+1);
  409. }
  410. $data[$value] = $req[$value];
  411. }
  412. $data['Sys_rq'] = date('Y-m-d H:i:s');
  413. //开启事务
  414. db()->startTrans();
  415. try{
  416. $sql = db()->table('成品入仓')->fetchSql(true)->insert($data);
  417. $bool = db()->query($sql);
  418. // 提交事务
  419. db()->commit();
  420. } catch (\Exception $e) {
  421. // 回滚事务
  422. db()->rollback();
  423. $this->error($e->getMessage());
  424. }
  425. if($bool===false) $this->error('失败');
  426. $this->success('成功');
  427. }
  428. /**
  429. * 修改
  430. * @ApiMethod (POST)
  431. */
  432. public function edit()
  433. {
  434. if(!$this->request->isPost()){
  435. $this->error('请求方式错误');
  436. }
  437. $req = $this->request->param();
  438. $arr = [
  439. '入仓类型', '仓库编号', '仓库名称',
  440. 'jjcp_num',
  441. 'jjcp_gdbh', 'jjcp_yjno', '订单编号',
  442. 'jjcp_cpdh', 'jjcp_cpmc',
  443. '成品编码', '成品名称',
  444. '客户料号',
  445. 'jjcp_smb', 'jjcp_sj',
  446. 'jjcp_sl', 'jjcp_dw',
  447. '机型备注',
  448. 'jjcp_desc'
  449. ];
  450. $data = [];
  451. foreach ($arr as $key => $value){
  452. if (!isset($req[$value])){
  453. continue;
  454. }
  455. $data[$value] = $req[$value];
  456. }
  457. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  458. $this->error('参数错误','UniqId',100);
  459. }
  460. if (count($data)==0){
  461. $this->error('参数错误','',111);
  462. }
  463. $data['Mod_rq'] = date('Y-m-d H:i:s');
  464. //开启事务
  465. db()->startTrans();
  466. try{
  467. $sql = db()->table('成品入仓')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
  468. $bool = db()->query($sql);
  469. // 提交事务
  470. db()->commit();
  471. } catch (\Exception $e) {
  472. // 回滚事务
  473. db()->rollback();
  474. $this->error($e->getMessage());
  475. }
  476. if($bool===false) $this->error('失败');
  477. $this->success('成功');
  478. }
  479. /**
  480. * 修改
  481. * @ApiMethod (POST)
  482. * @param string 'UniqId'
  483. */
  484. public function del()
  485. {
  486. if(!$this->request->isPost()){
  487. $this->error('请求方式错误');
  488. }
  489. $req = $this->request->param();
  490. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  491. $this->error('参数错误','UniqId',100);
  492. }
  493. //开启事务
  494. db()->startTrans();
  495. try{
  496. $bool = db()->table('成品入仓')->where('UniqId',$req['UniqId'])->delete();
  497. // 提交事务
  498. db()->commit();
  499. } catch (\Exception $e) {
  500. // 回滚事务
  501. db()->rollback();
  502. $this->error($e->getMessage());
  503. }
  504. if($bool===false) $this->error('失败');
  505. $this->success('成功');
  506. }
  507. /**
  508. * 月度A
  509. * @ApiMethod (POST)
  510. * @param string start_time
  511. * @param string end_time
  512. * @param string file_name
  513. * @param array fields
  514. */
  515. public function monthExportA(){
  516. if(!$this->request->isGet()){
  517. $this->error('请求方式错误');
  518. }
  519. $req = $this->request->param();
  520. $arr = [
  521. 'start_time', 'end_time', 'file_name'
  522. ];
  523. foreach ($arr as $key => $value){
  524. if (!isset($req[$value])){
  525. $this->error('参数错误',$value,$key+1);
  526. }
  527. }
  528. if (!(isset($req['fields']) && count($req['fields'])!=0)){
  529. $this->error('参数错误','fields',100);
  530. }
  531. $arr = [
  532. '入仓类型' =>['入仓类型'],
  533. '仓库编号' =>['仓库编号'],
  534. '仓库名称' =>['仓库名称'],
  535. 'jjcp_gdbh' =>['工单编号'],
  536. 'jjcp_cpdh' =>['入仓存货编号'],
  537. 'jjcp_cpmc' =>['入仓存货名称'],
  538. 'jjcp_sl' =>['入仓数量'],
  539. 'jjcp_dw' =>['单位'],
  540. 'jjcp_sj' =>['入仓时间'],
  541. 'jjcp_smb' =>['首末板'],
  542. 'jjcp_num' =>['单据编号'],
  543. '订单编号' =>['订单编号'],
  544. ];
  545. $data[0] = [];
  546. foreach ($req['fields'] as $k=>$v){
  547. if(array_key_exists($v,$arr)){
  548. array_push($data[0],$arr[$v][0]);
  549. }
  550. }
  551. //客户编号
  552. $rows = db()->table('成品入仓')->alias('c')
  553. ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
  554. c.jjcp_gdbh, rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  555. c.jjcp_sl, rtrim(c.jjcp_dw) as jjcp_dw, c.jjcp_sj,
  556. rtrim(c.jjcp_smb) as jjcp_smb,
  557. rtrim(c.jjcp_num) as jjcp_num, rtrim(g.销售订单号) as 订单编号
  558. ')
  559. ->where('c.jjcp_sj','between time',[$req['start_time'], $req['end_time']])
  560. ->order('c.jjcp_sj asc')
  561. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  562. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  563. ->select();
  564. foreach ($rows as $key=>$value) {
  565. $subArray = [];
  566. foreach ($arr as $k=>$v){
  567. $subArray[$k] = $rows[$key][$k];
  568. }
  569. array_push($data,$subArray);
  570. }
  571. $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
  572. }
  573. /**
  574. * 工序汇总导出
  575. * @ApiMethod (POST)
  576. * @param string date
  577. * @param string sys_id
  578. * @param array fields
  579. */
  580. public function export(){
  581. if(!$this->request->isGet()){
  582. $this->error('请求方式错误');
  583. }
  584. $req = $this->request->param();
  585. if (!isset($req['date']) || empty($req['date'])) $this->error('参数缺失');
  586. if (!(isset($req['fields']) && count($req['fields'])!=0)){
  587. $this->error('参数错误','fields',100);
  588. }
  589. if(strpos($req['date'],'-')){
  590. $where = ['c.Sys_rq'=>['like','%'.$req['date'].'%']];
  591. }else{
  592. $where = ['c.jjcp_gdbh'=>$req['date']];
  593. }
  594. if (isset($req['sys_id']) && !empty($req['sys_id'])){
  595. $where['c.Sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
  596. }
  597. $arr = [
  598. '入仓类型' =>['入仓类型'],
  599. '仓库编号' =>['仓库编号'],
  600. '仓库名称' =>['仓库名称'],
  601. 'jjcp_num' =>['入仓单号'],
  602. 'jjcp_gdbh' =>['工单编号'],
  603. 'jjcp_yjno' =>['印件号'],
  604. 'jjcp_sl' =>['入仓数量'],
  605. 'jjcp_sls' =>['累计入仓数量'],
  606. '订单数量' =>['订单数量'],
  607. '完成率' =>['完成率'],
  608. 'jjcp_dw' =>['单位'],
  609. 'jjcp_sj' =>['入仓时间'],
  610. 'jjcp_smb' =>['首末板'],
  611. 'jjcp_cpdh' =>['印件代号'],
  612. 'jjcp_cpmc' =>['印件名称'],
  613. '成品编码' =>['产品编号'],
  614. '成品名称' =>['产品名称'],
  615. '客户料号' =>['客户料号'],
  616. 'jjcp_desc' =>['备注'],
  617. '客户编号' =>['客户编号'],
  618. 'Gd_客户名称' =>['客户名称'],
  619. '最近入仓日期' =>['最近入仓日期'],
  620. '机型备注' =>['机型备注'],
  621. ];
  622. $data[0] = [];
  623. foreach ($req['fields'] as $k=>$v){
  624. if(array_key_exists($v,$arr)){
  625. array_push($data[0],$arr[$v][0]);
  626. }
  627. }
  628. //客户编号
  629. $rows = db()->table('成品入仓')->alias('c')
  630. ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
  631. rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh,
  632. c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj,
  633. rtrim(c.jjcp_smb) as jjcp_smb, rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  634. rtrim(c.成品编码) as 成品编码, rtrim(c.成品名称) as 成品名称,
  635. rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, LEFT(c.成品编码,4) as 客户编号, rtrim(g.Gd_客户名称) as Gd_客户名称,
  636. rtrim(c.机型备注) as 机型备注')
  637. ->where($where)
  638. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  639. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  640. ->order('c.UniqId desc')
  641. ->select();
  642. foreach ($rows as $key=>$value) {
  643. $row = db()->table('成品入仓')
  644. ->field('LEFT(Sys_rq, 10) as Sys_rq,jjcp_sl')
  645. ->where(['jjcp_gdbh'=>$value['jjcp_gdbh'], 'jjcp_cpdh'=>$value['jjcp_cpdh']])
  646. ->order('Sys_rq desc')
  647. ->select();
  648. $subArray = [];
  649. foreach ($arr as $k=>$v){
  650. if($k=='jjcp_sls'){
  651. $subArray[$k] = 0;
  652. foreach ($row as $n) {
  653. $subArray[$k] += $n['jjcp_sl'];
  654. }
  655. }else if($k=='完成率'){
  656. if ($value['订单数量']!=0){
  657. $subArray[$k] = 0;
  658. foreach ($row as $n) {
  659. $subArray[$k] += $n['jjcp_sl'];
  660. }
  661. $subArray[$k] = number_format($subArray[$k]/$value['订单数量']/100,2);
  662. }else{
  663. $subArray[$k] = '';
  664. }
  665. }else if($k=='最近入仓日期'){
  666. $subArray[$k] = $row[0]['Sys_rq'];
  667. }else{
  668. $subArray[$k] = $rows[$key][$k];
  669. }
  670. }
  671. array_push($data,$subArray);
  672. }
  673. $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
  674. }
  675. }