FinishedProductWarehousing.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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. // $sql = 'SELECT DISTINCT Gd_客户代号 FROM `工单_基本资料` ORDER BY Gd_客户代号 DESC';
  64. // $rows = db()->query($sql);
  65. $rows = db()->table('成品入仓')->alias('c')
  66. ->field('g.Gd_khdh')
  67. ->join('工单_基本资料 g','c.jjcp_gdbh = g.Gd_gdbh')
  68. // ->distinct('g.Gd_khdh')
  69. ->order('c.Sys_rq desc')
  70. ->select();
  71. halt($rows);
  72. $arr = db()->table('成品入仓')
  73. ->field('sczl_gdbh,rtrim(sys_id) as sys_id')
  74. ->where('sczl_gdbh','>=',$rows[64]['sczl_gdbh'])
  75. ->select();
  76. $brr = [];
  77. foreach($arr as $k=>$v){
  78. if(array_key_exists($v['sczl_gdbh'],$brr)){
  79. if(array_key_exists($v['sys_id'],$brr[$v['sczl_gdbh']])){
  80. $brr[$v['sczl_gdbh']][$v['sys_id']] += 1;
  81. }else{
  82. $brr[$v['sczl_gdbh']][$v['sys_id']] = 1;
  83. }
  84. }else{
  85. $brr[$v['sczl_gdbh']][$v['sys_id']] = 1;
  86. }
  87. }
  88. foreach($rows as $key=>$value){
  89. $rows[$key]['sys'] = $brr[$value['sczl_gdbh']];
  90. $rows[$key]['yj_yjmc'] = trim($value['yj_yjmc']);
  91. }
  92. $this->success('成功',$rows);
  93. }
  94. /**
  95. * 列表
  96. * @ApiMethod (GET)
  97. * @param string $date 时间
  98. * @param string $sys_id 用户
  99. */
  100. public function getList()
  101. {
  102. //get请求
  103. if(!$this->request->isGet()){
  104. $this->error('请求方式错误');
  105. }
  106. $req = $this->request->param();
  107. if (!isset($req['date']) || empty($req['date'])) $this->error('参数缺失');
  108. $page = 1;
  109. $limit = 15;
  110. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  111. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  112. if(strpos($req['date'],'-')){
  113. $where = ['c.Sys_rq'=>['like','%'.$req['date'].'%']];
  114. $option = ['Sys_rq'=>['like','%'.$req['date'].'%']];
  115. }else{
  116. $where = ['c.sczl_gdbh'=>$req['date']];
  117. $option = ['sczl_gdbh'=>$req['date']];
  118. }
  119. if (isset($req['sys_id']) && !empty($req['sys_id'])){
  120. $where['c.Sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
  121. $option['Sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
  122. }
  123. //客户编号
  124. $rows = db()->table('成品入仓')->alias('c')
  125. ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
  126. rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh,
  127. c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj,
  128. rtrim(c.jjcp_smb) as jjcp_smb, rtrim(y.yj_Yjdh) as yj_Yjdh, rtrim(y.yj_yjmc) as yj_yjmc,
  129. rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  130. rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, g.Gd_khdh, rtrim(g.Gd_khdh) as Gd_khdh, rtrim(g.Gd_客户名称) as Gd_客户名称,
  131. rtrim(c.机型备注) as 机型备注, rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
  132. ->where($where)
  133. ->where('y.yj_Yjno=c.jjcp_yjno')
  134. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  135. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  136. ->join('工单_印件资料 y','y.Yj_Gdbh=c.jjcp_gdbh')
  137. ->order('c.UniqId desc')
  138. ->page($page,$limit)
  139. ->select();
  140. $total = db()->table('成品入仓')->where($option)->count();
  141. foreach ($rows as $key=>$value) {
  142. $row = db()->table('成品入仓')
  143. ->field('LEFT(Sys_rq, 10) as Sys_rq,jjcp_sl')
  144. ->where('jjcp_gdbh',$value['jjcp_gdbh'])
  145. ->order('Sys_rq desc')
  146. ->select();
  147. $rows[$key]['jjcp_sls'] = 0;
  148. foreach ($row as $k=>$v) {
  149. $rows[$key]['jjcp_sls'] += $v['jjcp_sl'];
  150. }
  151. if ($value['订单数量']!=0){
  152. $rows[$key]['完成率'] = number_format($rows[$key]['jjcp_sls']/$value['订单数量']/100,2);
  153. }else{
  154. $rows[$key]['完成率'] = '';
  155. }
  156. $rows[$key]['订单数量'] = floatval($value['订单数量']*10000);
  157. $rows[$key]['最近入仓日期'] = $row[0]['Sys_rq'];
  158. $rows[$key]['Mod_rq'] = $value['Mod_rq']=='1900-01-01 00:00:00' ? '' :$value['Mod_rq'];
  159. }
  160. $data = [
  161. 'total' => $total,
  162. 'rows' => $rows,
  163. ];
  164. $this->success('成功',$data);
  165. }
  166. /**
  167. * 定位
  168. * @ApiMethod (GET)
  169. * @param string $gdbh 工单编号
  170. * @param string $cpmc 产品名称
  171. * @param string $page 页码
  172. * @param string $limit 数量
  173. */
  174. public function locate()
  175. {
  176. //get请求
  177. if(!$this->request->isGet()){
  178. $this->error('请求方式错误');
  179. }
  180. $req = $this->request->param();
  181. $page = 1;
  182. $limit = 15;
  183. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  184. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  185. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  186. $where = ['c.jjcp_gdbh'=>[ 'like', '%' . $req['gdbh'] . '%']];
  187. $option = ['jjcp_gdbh'=>[ 'like', '%' . $req['gdbh'] . '%']];
  188. //客户编号
  189. $rows = db()->table('成品入仓')->alias('c')
  190. ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
  191. rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh,
  192. c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj,
  193. rtrim(c.jjcp_smb) as jjcp_smb, rtrim(y.yj_Yjdh) as yj_Yjdh, rtrim(y.yj_yjmc) as yj_yjmc,
  194. rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  195. rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, g.Gd_khdh, rtrim(g.Gd_khdh) as Gd_khdh, rtrim(g.Gd_客户名称) as Gd_客户名称,
  196. rtrim(c.机型备注) as 机型备注, rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
  197. ->where($where)
  198. ->where('y.yj_Yjno=c.jjcp_yjno')
  199. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  200. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  201. ->join('工单_印件资料 y','y.Yj_Gdbh=c.jjcp_gdbh')
  202. ->order('c.UniqId desc')
  203. ->page($page,$limit)
  204. ->select();
  205. $total = db()->table('成品入仓')->where($option)->count();
  206. }else{
  207. if (isset($req['cpmc']) && !empty($req['cpmc'])){
  208. //查询工单表
  209. $gd = db()->table('工单_基本资料')
  210. ->where('Gd_cpmc', 'LIKE', '%'.$req['cpmc'].'%')
  211. ->column('Gd_gdbh');
  212. $where = ['c.jjcp_gdbh'=>['in', $gd]];
  213. $option = ['jjcp_gdbh'=>['in', $gd]];
  214. //客户编号
  215. $rows = db()->table('成品入仓')->alias('c')
  216. ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
  217. rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh,
  218. c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj,
  219. rtrim(c.jjcp_smb) as jjcp_smb, rtrim(y.yj_Yjdh) as yj_Yjdh, rtrim(y.yj_yjmc) as yj_yjmc,
  220. rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  221. rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, g.Gd_khdh, rtrim(g.Gd_khdh) as Gd_khdh, rtrim(g.Gd_客户名称) as Gd_客户名称,
  222. rtrim(c.机型备注) as 机型备注, rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
  223. ->where($where)
  224. ->where('y.yj_Yjno=c.jjcp_yjno')
  225. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  226. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  227. ->join('工单_印件资料 y','y.Yj_Gdbh=c.jjcp_gdbh')
  228. ->order('c.UniqId desc')
  229. ->page($page,$limit)
  230. ->select();
  231. $total = db()->table('成品入仓')->where($option)->count();
  232. }else{
  233. $this->error('参数错误');
  234. }
  235. }
  236. foreach ($rows as $key=>$value) {
  237. $row = db()->table('成品入仓')
  238. ->field('LEFT(Sys_rq, 10) as Sys_rq,jjcp_sl')
  239. ->where('jjcp_gdbh',$value['jjcp_gdbh'])
  240. ->order('Sys_rq desc')
  241. ->select();
  242. $rows[$key]['jjcp_sls'] = 0;
  243. foreach ($row as $k=>$v) {
  244. $rows[$key]['jjcp_sls'] += $v['jjcp_sl'];
  245. }
  246. if ($value['订单数量']!=0){
  247. $rows[$key]['完成率'] = number_format($rows[$key]['jjcp_sls']/$value['订单数量']/100,2);
  248. }else{
  249. $rows[$key]['完成率'] = '';
  250. }
  251. $rows[$key]['订单数量'] = floatval($value['订单数量']*10000);
  252. $rows[$key]['最近入仓日期'] = $row[0]['Sys_rq'];
  253. $rows[$key]['Mod_rq'] = $value['Mod_rq']=='1900-01-01 00:00:00' ? '' :$value['Mod_rq'];
  254. }
  255. $data = [
  256. 'total' => $total,
  257. 'rows' => $rows,
  258. ];
  259. $this->success('成功',$data);
  260. }
  261. /**
  262. * 获取信息
  263. * @ApiMethod (GET)
  264. * @param string $UniqId UniqId
  265. */
  266. public function getInfo()
  267. {
  268. //get请求
  269. if(!$this->request->isGet()){
  270. $this->error('请求方式错误');
  271. }
  272. $req = $this->request->param();
  273. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  274. $UniqId = $req['UniqId'];
  275. }else{
  276. $this->error('参数错误');
  277. }
  278. //客户编号
  279. $rows = db()->table('成品入仓')->alias('c')
  280. ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
  281. rtrim(c.jjcp_num) as jjcp_num,
  282. c.jjcp_gdbh, c.jjcp_yjno, rtrim(c.订单编号) as 订单编号,
  283. rtrim(y.yj_Yjdh) as yj_Yjdh, rtrim(y.yj_yjmc) as yj_yjmc,
  284. rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  285. rtrim(c.客户料号) as 客户料号,
  286. rtrim(c.jjcp_smb) as jjcp_smb, LEFT(c.jjcp_sj, 10) as jjcp_sj,
  287. c.jjcp_sl, rtrim(c.jjcp_dw) as jjcp_dw,
  288. g.订单数量, rtrim(c.机型备注) as 机型备注, rtrim(c.jjcp_desc) as jjcp_desc,
  289. rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
  290. ->where('c.UniqId',$UniqId)
  291. ->where('y.yj_Yjno=c.jjcp_yjno')
  292. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  293. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  294. ->join('工单_印件资料 y','y.Yj_Gdbh=c.jjcp_gdbh')
  295. ->find();
  296. $rows['jjcp_sls'] = db()->table('成品入仓')
  297. ->where('jjcp_gdbh',$rows['jjcp_gdbh'])
  298. ->order('Sys_rq desc')
  299. ->sum('jjcp_sl');
  300. $rows['订单数量'] = floatval($rows['订单数量']*10000);
  301. $this->success('成功',$rows);
  302. }
  303. /**
  304. * 查询印件工序及产品名称
  305. * @ApiMethod (GET)
  306. * @param string $gdbh 工单编号
  307. * @param string $gxmc 工序名称
  308. */
  309. public function getGxMc()
  310. {
  311. //get请求
  312. if(!$this->request->isGet()){
  313. $this->error('请求方式错误');
  314. }
  315. $req = $this->request->param();
  316. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  317. $gdbh = $req['gdbh'];
  318. }else{
  319. $this->error('参数错误');
  320. }
  321. $gxmc = ['包装','成品防护'];
  322. $gxmcs = [];
  323. foreach ($gxmc as $k=>$v){
  324. array_push($gxmcs,['like','%'.$v.'%']);
  325. }
  326. array_push($gxmcs,'OR');
  327. $rows = db()->table('工单_基本资料')->alias('g')
  328. ->field('rtrim(g.Gd_cpmc) as Gd_cpmc, c.Gy0_yjno, c.Gy0_gxh, rtrim(c.Gy0_gxmc) as Gy0_gxmc')
  329. ->where(['g.Gd_gdbh'=>$gdbh])
  330. ->where(['c.Gy0_gxmc'=>$gxmcs])
  331. ->join(['产品_印件资料'=>'j'],'g.Gd_cpdh=j.yj_yjdh and g.成品代号=j.yj_cpdh')
  332. ->join(['工单_工艺资料'=>'c'],'c.Gy0_gdbh=g.Gd_gdbh and c.Gy0_yjno=j.yj_yjno')
  333. ->select();
  334. foreach ($rows as $key=>$value){
  335. $rows[$key]['jyGx'] = sprintf("%02d", $value['Gy0_yjno']).'-'.$value['Gy0_gxh'];
  336. }
  337. $this->success('成功',$rows);
  338. }
  339. /**
  340. * 查询员工名称
  341. * @ApiMethod (GET)
  342. * @param string $sczl_bh 员工编号
  343. */
  344. public function getYg()
  345. {
  346. //get请求
  347. if(!$this->request->isGet()){
  348. $this->error('请求方式错误');
  349. }
  350. $req = $this->request->param();
  351. if (isset($req['sczl_bh']) && !empty($req['sczl_bh'])){
  352. $sczl_bh = $req['sczl_bh'];
  353. }else{
  354. $this->error('参数错误');
  355. }
  356. $rs = db()->table('人事_基本资料')->field('rtrim(员工姓名) as ygxm')->where('员工编号',$sczl_bh)->find();
  357. if(!$rs){
  358. $this->error('失败');
  359. }
  360. $this->success('成功',$rs);
  361. }
  362. /**
  363. * 新增
  364. * @ApiMethod (POST)
  365. * @param string 'sys_id','sczl_rq', 'sczl_bh', 'sczl_jsss', 'sczl_冲定额', 'sczl_bzdh',
  366. 'sczl_gdbh1', 'sczl_gdbh2', 'sczl_gdbh3', 'sczl_gdbh4', 'sczl_gdbh5', 'sczl_gdbh6',
  367. 'sczl_yjGx1', 'sczl_yjGx2', 'sczl_yjGx3', 'sczl_yjGx4', 'sczl_yjGx5', 'sczl_yjGx6',
  368. 'sczl_gxmc1', 'sczl_gxmc2', 'sczl_gxmc3', 'sczl_gxmc4', 'sczl_gxmc5', 'sczl_gxmc6',
  369. 'sczl_cl1', 'sczl_cl2', 'sczl_cl3', 'sczl_cl4', 'sczl_cl5', 'sczl_cl6',
  370. 'sczl_PgCl1', 'sczl_PgCl2', 'sczl_PgCl3', 'sczl_PgCl4', 'sczl_PgCl5', 'sczl_PgCl6',
  371. 'sczl_返工产量1', 'sczl_返工产量2', 'sczl_返工产量3', 'sczl_返工产量4', 'sczl_返工产量5', 'sczl_返工产量6',
  372. 'sczl_计产系数1', 'sczl_计产系数2', 'sczl_计产系数3', 'sczl_计产系数4', 'sczl_计产系数5', 'sczl_计产系数6',
  373. 'sczl_Jtbh1','sczl_Jtbh2', 'sczl_Jtbh3', 'sczl_Jtbh4', 'sczl_Jtbh5', 'sczl_Jtbh6',
  374. 'sczl_dedh1', 'sczl_dedh2', 'sczl_dedh3', 'sczl_dedh4', 'sczl_dedh5', 'sczl_dedh6',
  375. 'sczl_desc'
  376. */
  377. public function add()
  378. {
  379. if(!$this->request->isPost()){
  380. $this->error('请求方式错误');
  381. }
  382. $req = $this->request->param();
  383. $arr = [
  384. 'sys_id','sczl_rq', 'sczl_bh', 'sczl_jsss', 'sczl_冲定额', 'sczl_bzdh',
  385. 'sczl_gdbh1', 'sczl_gdbh2', 'sczl_gdbh3', 'sczl_gdbh4', 'sczl_gdbh5', 'sczl_gdbh6',
  386. 'sczl_yjGx1', 'sczl_yjGx2', 'sczl_yjGx3', 'sczl_yjGx4', 'sczl_yjGx5', 'sczl_yjGx6',
  387. 'sczl_gxmc1', 'sczl_gxmc2', 'sczl_gxmc3', 'sczl_gxmc4', 'sczl_gxmc5', 'sczl_gxmc6',
  388. 'sczl_cl1', 'sczl_cl2', 'sczl_cl3', 'sczl_cl4', 'sczl_cl5', 'sczl_cl6',
  389. 'sczl_PgCl1', 'sczl_PgCl2', 'sczl_PgCl3', 'sczl_PgCl4', 'sczl_PgCl5', 'sczl_PgCl6',
  390. 'sczl_返工产量1', 'sczl_返工产量2', 'sczl_返工产量3', 'sczl_返工产量4', 'sczl_返工产量5', 'sczl_返工产量6',
  391. 'sczl_计产系数1', 'sczl_计产系数2', 'sczl_计产系数3', 'sczl_计产系数4', 'sczl_计产系数5', 'sczl_计产系数6',
  392. 'sczl_Jtbh1','sczl_Jtbh2', 'sczl_Jtbh3', 'sczl_Jtbh4', 'sczl_Jtbh5', 'sczl_Jtbh6',
  393. 'sczl_dedh1', 'sczl_dedh2', 'sczl_dedh3', 'sczl_dedh4', 'sczl_dedh5', 'sczl_dedh6',
  394. 'sczl_desc'
  395. ];
  396. $data = [];
  397. foreach ($arr as $key => $value){
  398. if (!isset($req[$value])){
  399. $this->error('参数错误',$value,$key+1);
  400. }
  401. $data[$value] = $req[$value];
  402. }
  403. $data['sys_rq'] = date('Y-m-d H:i:s');
  404. //开启事务
  405. db()->startTrans();
  406. try{
  407. $sql = db()->table('成品入仓')->fetchSql(true)->insert($data);
  408. $bool = db()->query($sql);
  409. // 提交事务
  410. db()->commit();
  411. } catch (\Exception $e) {
  412. // 回滚事务
  413. db()->rollback();
  414. $this->error($e->getMessage());
  415. }
  416. if($bool===false) $this->error('失败');
  417. $this->success('成功');
  418. }
  419. /**
  420. * 修改
  421. * @ApiMethod (POST)
  422. * @param string 'UniqId','sczl_rq',
  423. 'sczl_gdbh1', 'sczl_gdbh2', 'sczl_gdbh3', 'sczl_gdbh4', 'sczl_gdbh5', 'sczl_gdbh6',
  424. 'sczl_yjGx1', 'sczl_yjGx2', 'sczl_yjGx3', 'sczl_yjGx4', 'sczl_yjGx5', 'sczl_yjGx6',
  425. 'sczl_gxmc1', 'sczl_gxmc2', 'sczl_gxmc3', 'sczl_gxmc4', 'sczl_gxmc5', 'sczl_gxmc6',
  426. 'sczl_cl1', 'sczl_cl2', 'sczl_cl3', 'sczl_cl4', 'sczl_cl5', 'sczl_cl6',
  427. 'sczl_PgCl1', 'sczl_PgCl2', 'sczl_PgCl3', 'sczl_PgCl4', 'sczl_PgCl5', 'sczl_PgCl6',
  428. 'sczl_clAdd1', 'sczl_clAdd2', 'sczl_clAdd3', 'sczl_clAdd4', 'sczl_clAdd5', 'sczl_clAdd6'
  429. */
  430. public function edit()
  431. {
  432. if(!$this->request->isPost()){
  433. $this->error('请求方式错误');
  434. }
  435. $req = $this->request->param();
  436. $arr = [
  437. 'sys_id','sczl_rq', 'sczl_bh', 'sczl_jsss', 'sczl_冲定额', 'sczl_bzdh',
  438. 'sczl_gdbh1', 'sczl_gdbh2', 'sczl_gdbh3', 'sczl_gdbh4', 'sczl_gdbh5', 'sczl_gdbh6',
  439. 'sczl_yjGx1', 'sczl_yjGx2', 'sczl_yjGx3', 'sczl_yjGx4', 'sczl_yjGx5', 'sczl_yjGx6',
  440. 'sczl_gxmc1', 'sczl_gxmc2', 'sczl_gxmc3', 'sczl_gxmc4', 'sczl_gxmc5', 'sczl_gxmc6',
  441. 'sczl_cl1', 'sczl_cl2', 'sczl_cl3', 'sczl_cl4', 'sczl_cl5', 'sczl_cl6',
  442. 'sczl_PgCl1', 'sczl_PgCl2', 'sczl_PgCl3', 'sczl_PgCl4', 'sczl_PgCl5', 'sczl_PgCl6',
  443. 'sczl_返工产量1', 'sczl_返工产量2', 'sczl_返工产量3', 'sczl_返工产量4', 'sczl_返工产量5', 'sczl_返工产量6',
  444. 'sczl_计产系数1', 'sczl_计产系数2', 'sczl_计产系数3', 'sczl_计产系数4', 'sczl_计产系数5', 'sczl_计产系数6',
  445. 'sczl_Jtbh1','sczl_Jtbh2', 'sczl_Jtbh3', 'sczl_Jtbh4', 'sczl_Jtbh5', 'sczl_Jtbh6',
  446. 'sczl_dedh1', 'sczl_dedh2', 'sczl_dedh3', 'sczl_dedh4', 'sczl_dedh5', 'sczl_dedh6',
  447. 'sczl_desc'
  448. ];
  449. $data = [];
  450. foreach ($arr as $key => $value){
  451. if (!isset($req[$value])){
  452. continue;
  453. }
  454. $data[$value] = $req[$value];
  455. }
  456. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  457. $this->error('参数错误','UniqId',100);
  458. }
  459. if (count($data)==0){
  460. $this->error('参数错误','',111);
  461. }
  462. $data['mod_rq'] = date('Y-m-d H:i:s');
  463. //开启事务
  464. db()->startTrans();
  465. try{
  466. $sql = db()->table('成品入仓')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
  467. $bool = db()->query($sql);
  468. // 提交事务
  469. db()->commit();
  470. } catch (\Exception $e) {
  471. // 回滚事务
  472. db()->rollback();
  473. $this->error($e->getMessage());
  474. }
  475. if($bool===false) $this->error('失败');
  476. $this->success('成功');
  477. }
  478. /**
  479. * 修改
  480. * @ApiMethod (POST)
  481. * @param string 'UniqId'
  482. */
  483. public function del()
  484. {
  485. if(!$this->request->isPost()){
  486. $this->error('请求方式错误');
  487. }
  488. $req = $this->request->param();
  489. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  490. $this->error('参数错误','UniqId',100);
  491. }
  492. //开启事务
  493. db()->startTrans();
  494. try{
  495. $bool = db()->table('成品入仓')->where('UniqId',$req['UniqId'])->delete();
  496. // 提交事务
  497. db()->commit();
  498. } catch (\Exception $e) {
  499. // 回滚事务
  500. db()->rollback();
  501. $this->error($e->getMessage());
  502. }
  503. if($bool===false) $this->error('失败');
  504. $this->success('成功');
  505. }
  506. /**
  507. * 导出到excel
  508. * @ApiMethod (POST)
  509. * @param string gxmc
  510. * @param string start_time
  511. * @param string end_time
  512. * @param string file_name
  513. * @param array fields
  514. */
  515. public function processExport(){
  516. if(!$this->request->isPost()){
  517. $this->error('请求方式错误');
  518. }
  519. $req = $this->request->param();
  520. $arr = [
  521. 'gxmc','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. $field = '';
  532. $arr = [
  533. 'sczl_rq' =>['日期','LEFT(sczl_rq, 10) as sczl_rq'],
  534. 'sczl_bh' =>['员工编号','sczl_bh'],
  535. 'sczl_name' =>['员工姓名','sczl_bh'],
  536. 'sczl_jsss' =>['计时时数','sczl_jsss'],
  537. 'sczl_gdbh' =>['工单编号','sczl_gdbh1, sczl_gdbh2, sczl_gdbh3, sczl_gdbh4, sczl_gdbh5, sczl_gdbh6'],
  538. 'sczl_yjmc' =>['印件名称','sczl_gdbh1, sczl_gdbh2, sczl_gdbh3, sczl_gdbh4, sczl_gdbh5, sczl_gdbh6'],
  539. 'sczl_yjGx' =>['印件工序','rtrim(sczl_yjGx1) as sczl_yjGx1, rtrim(sczl_yjGx2) as sczl_yjGx2, rtrim(sczl_yjGx3) as sczl_yjGx3, rtrim(sczl_yjGx4) as sczl_yjGx4, rtrim(sczl_yjGx5) as sczl_yjGx5, rtrim(sczl_yjGx6) as sczl_yjGx6'],
  540. 'sczl_gxmc' =>['工序名称','rtrim(sczl_gxmc1) as sczl_gxmc1, rtrim(sczl_gxmc2) as sczl_gxmc2, rtrim(sczl_gxmc3) as sczl_gxmc3, rtrim(sczl_gxmc4) as sczl_gxmc4, rtrim(sczl_gxmc5) as sczl_gxmc5, rtrim(sczl_gxmc6) as sczl_gxmc6'],
  541. 'sczl_cl' =>['产量','sczl_cl1, sczl_cl2, sczl_cl3, sczl_cl4, sczl_cl5, sczl_cl6'],
  542. 'sczl_PgCl' =>['每箱产量','sczl_PgCl1, sczl_PgCl2, sczl_PgCl3, sczl_PgCl4, sczl_PgCl5, sczl_PgCl6'],
  543. 'sczl_计产系数' =>['计产系数','sczl_计产系数1, sczl_计产系数2, sczl_计产系数3, sczl_计产系数4, sczl_计产系数5, sczl_计产系数6'],
  544. 'sczl_dedh' =>['定额代号','rtrim(sczl_dedh1) as sczl_dedh1, rtrim(sczl_dedh2) as sczl_dedh2, rtrim(sczl_dedh3) as sczl_dedh3, rtrim(sczl_dedh4) as sczl_dedh4, rtrim(sczl_dedh5) as sczl_dedh5, rtrim(sczl_dedh6) as sczl_dedh6']
  545. ];
  546. $data[0] = [];
  547. foreach ($req['fields'] as $k=>$v){
  548. if(array_key_exists($v,$arr)){
  549. if ($k==0){
  550. $field .= $arr[$v][1];
  551. }else{
  552. $field .= ','.$arr[$v][1];
  553. }
  554. array_push($data[0],$arr[$v][0]);
  555. }
  556. }
  557. //根据条件查询数据
  558. $rows = db()->table('成品入仓')
  559. ->field($field)
  560. ->where('sczl_rq','between',[$req['start_time'],$req['end_time']])
  561. ->where(['sczl_gxmc1|sczl_gxmc2|sczl_gxmc3|sczl_gxmc4|sczl_gxmc5|sczl_gxmc6'=>['like','%'.$req['gxmc'].'%']])
  562. ->select();
  563. $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
  564. $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
  565. for ($i = 1; $i <= 6; $i++) {
  566. foreach ($rows as $key=>$value){
  567. if (trim($value['sczl_gdbh'.$i])=='') continue;
  568. if (trim($value['sczl_gxmc'.$i])!=$req['gxmc']) continue;
  569. $subArray = [];
  570. foreach ($req['fields'] as $k=>$v){
  571. if(array_key_exists($v,$arr)){
  572. if($v=='sczl_rq' || $v=='sczl_jsss' || $v=='sczl_bh'){
  573. if($value[$v]){
  574. array_push($subArray,$value[$v]);
  575. }else{
  576. array_push($subArray,'');
  577. }
  578. }else if($v=='sczl_name'){
  579. $name = array_key_exists($value['sczl_bh'],$rs) ? trim($rs[$value['sczl_bh']]) : '';
  580. if($name){
  581. array_push($subArray,$name);
  582. }else{
  583. array_push($subArray,'');
  584. }
  585. }else if($v=='sczl_yjmc'){
  586. $cpmc = array_key_exists($value['sczl_gdbh'.$i],$gd) ? trim($gd[$value['sczl_gdbh'.$i]]) : '';
  587. if($cpmc){
  588. array_push($subArray,$cpmc);
  589. }else{
  590. array_push($subArray,'');
  591. }
  592. }else{
  593. if($value[$v.$i]){
  594. array_push($subArray,$value[$v.$i]);
  595. }else{
  596. array_push($subArray,'');
  597. }
  598. }
  599. }
  600. }
  601. array_push($data,$subArray);
  602. }
  603. }
  604. $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
  605. }
  606. /**
  607. * 工序汇总导出
  608. * @ApiMethod (POST)
  609. * @param string date
  610. * @param string sys_id
  611. * @param array fields
  612. */
  613. public function export(){
  614. if(!$this->request->isGet()){
  615. $this->error('请求方式错误');
  616. }
  617. $req = $this->request->param();
  618. $where = [];
  619. if (isset($req['date']) && !empty($req['date'])){
  620. $where['sys_rq'] = ['LIKE',$req['date'].'%'];
  621. }else{
  622. $this->error('参数错误');
  623. }
  624. if (isset($req['sys_id']) && !empty($req['sys_id'])) $where['sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
  625. if (!(isset($req['fields']) && count($req['fields'])!=0)){
  626. $this->error('参数错误','fields',100);
  627. }
  628. $field = '';
  629. $arr = [
  630. 'sczl_bh' =>['员工编号','sczl_bh'],
  631. 'sczl_name' =>['员工姓名','sczl_bh'],
  632. 'sczl_rq' =>['生产日期','LEFT(sczl_rq, 10) as sczl_rq'],
  633. 'sczl_bzdh' =>['班组','sczl_bzdh'],
  634. 'sczl_cl' =>['包装产量','sczl_cl1 + sczl_cl2 + sczl_cl3 + sczl_cl4 + sczl_cl5 + sczl_cl6 as sczl_cl'],
  635. 'sczl_fgcl' =>['返工产量','sczl_返工产量1 + sczl_返工产量2 + sczl_返工产量3 + sczl_返工产量4 + sczl_返工产量5 + sczl_返工产量6 as sczl_fgcl'],
  636. 'sczl_jjcl' =>['计件产量','sczl_cl1 + sczl_cl2 + sczl_cl3 + sczl_cl4 + sczl_cl5 + sczl_cl6 + sczl_返工产量1 + sczl_返工产量2 + sczl_返工产量3 + sczl_返工产量4 + sczl_返工产量5 + sczl_返工产量6 as sczl_jjcl'],
  637. 'sczl_gdbh1' =>['相关工单','sczl_gdbh1'],
  638. ];
  639. $data[0] = [];
  640. foreach ($req['fields'] as $k=>$v){
  641. if(array_key_exists($v,$arr)){
  642. if ($k==0){
  643. $field .= $arr[$v][1];
  644. }else{
  645. $field .= ','.$arr[$v][1];
  646. }
  647. array_push($data[0],$arr[$v][0]);
  648. }
  649. }
  650. $rows = db()->table('成品入仓')
  651. ->field($field)
  652. ->where($where)
  653. ->select();
  654. $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
  655. foreach ($rows as $key=>$value) {
  656. if (isset($value['sczl_cl'])) $value['sczl_cl'] = floatval($value['sczl_cl']);
  657. if (isset($value['sczl_fgcl'])) $value['sczl_fgcl'] = floatval($value['sczl_fgcl']);
  658. if (isset($value['sczl_jjcl'])) $value['sczl_jjcl'] = floatval($value['sczl_jjcl']);
  659. $subArray = [];
  660. foreach ($req['fields'] as $k=>$v){
  661. if(array_key_exists($v,$arr)){
  662. if($v=='sczl_name'){
  663. $name = array_key_exists($value['sczl_bh'],$rs) ? trim($rs[$value['sczl_bh']]) : '';
  664. if($name){
  665. array_push($subArray,$name);
  666. }else{
  667. array_push($subArray,'');
  668. }
  669. }else{
  670. if($value[$v]){
  671. array_push($subArray,$value[$v]);
  672. }else{
  673. array_push($subArray,'');
  674. }
  675. }
  676. }
  677. }
  678. array_push($data,$subArray);
  679. }
  680. $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
  681. }
  682. }