PackagingProcessOutput.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. /**
  5. * 包装工序产量维护接口
  6. */
  7. class PackagingProcessOutput 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('db_包装产量预报')
  30. ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
  31. ->group('date')
  32. ->order('UniqId desc')
  33. ->limit(30)
  34. ->select();
  35. $arr = db()->table('db_包装产量预报')
  36. ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(*) as count')
  37. ->where('sys_rq','>=',$rows[count($rows)-1]['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. * @param string $date 时间
  57. * @param string $sys_id 用户
  58. * @param string $page 页码
  59. * @param string $limit 数量
  60. */
  61. public function getList()
  62. {
  63. //get请求
  64. if(!$this->request->isGet()){
  65. $this->error('请求方式错误');
  66. }
  67. $req = $this->request->param();
  68. $page = 1;
  69. $limit = 15;
  70. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  71. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  72. $where = [];
  73. if (isset($req['date']) && !empty($req['date'])){
  74. $where['sys_rq'] = ['LIKE',$req['date'].'%'];
  75. }else{
  76. $this->error('参数错误');
  77. }
  78. if (isset($req['sys_id']) && !empty($req['sys_id'])) $where['sys_id'] = ['LIKE',$req['sys_id'].'%'];
  79. $rows = db()->table('db_包装产量预报')
  80. ->field('rtrim(sys_id) as sys_id, LEFT(sczl_rq, 10) as sczl_rq,
  81. sczl_cl1 + sczl_cl2 + sczl_cl3 + sczl_cl4 + sczl_cl5 + sczl_cl6 as sczl_cl,
  82. (sczl_cl1 * sczl_PgCl1 + sczl_clAdd1) + (sczl_cl2 * sczl_PgCl2 + sczl_clAdd2) + (sczl_cl3 * sczl_PgCl3 + sczl_clAdd3) + (sczl_cl4 * sczl_PgCl4 + sczl_clAdd4) + (sczl_cl5 * sczl_PgCl5 + sczl_clAdd5) + (sczl_cl6 * sczl_PgCl6 + sczl_clAdd6) as sczl_PgCl,
  83. sys_rq, mod_rq, UniqId')
  84. ->where($where)
  85. ->page($page,$limit)
  86. ->select();
  87. $total = db()->table('db_包装产量预报')->where($where)->count();
  88. $sczl_cls = $sczl_PgCls = 0;
  89. foreach ($rows as $key=>$value){
  90. $sczl_cls += $value['sczl_cl'];
  91. $sczl_PgCls += $value['sczl_PgCl'];
  92. $rows[$key]['mod_rq'] = $value['mod_rq']=='1900-01-01 00:00:00' ? '' :$value['mod_rq'];
  93. $rows[$key]['sczl_cl'] = floatval($value['sczl_cl']);
  94. $rows[$key]['sczl_PgCl'] = floatval($value['sczl_PgCl']);
  95. }
  96. $data = [
  97. 'sczl_cls' => $sczl_cls,
  98. 'sczl_PgCls' => $sczl_PgCls,
  99. 'total' => $total,
  100. 'rows' => $rows,
  101. ];
  102. $this->success('成功',$data);
  103. }
  104. /**
  105. * 定位
  106. * @ApiMethod (GET)
  107. * @param string $gdbh 工单编号
  108. * @param string $cpmc 产品名称
  109. * @param string $page 页码
  110. * @param string $limit 数量
  111. */
  112. public function locate()
  113. {
  114. //get请求
  115. if(!$this->request->isGet()){
  116. $this->error('请求方式错误');
  117. }
  118. $req = $this->request->param();
  119. $page = 1;
  120. $limit = 15;
  121. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  122. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  123. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  124. $where = [
  125. 'sczl_gdbh1|sczl_gdbh2|sczl_gdbh3|sczl_gdbh4|sczl_gdbh5|sczl_gdbh6'=>[ 'like', '%' . $req['gdbh'] . '%']
  126. ];
  127. $rows = db()->table('db_包装产量预报')
  128. ->field('rtrim(sys_id) as sys_id, LEFT(sczl_rq, 10) as sczl_rq,
  129. sczl_cl1 + sczl_cl2 + sczl_cl3 + sczl_cl4 + sczl_cl5 + sczl_cl6 as sczl_cl,
  130. (sczl_cl1 * sczl_PgCl1 + sczl_clAdd1) + (sczl_cl2 * sczl_PgCl2 + sczl_clAdd2) + (sczl_cl3 * sczl_PgCl3 + sczl_clAdd3) + (sczl_cl4 * sczl_PgCl4 + sczl_clAdd4) + (sczl_cl5 * sczl_PgCl5 + sczl_clAdd5) + (sczl_cl6 * sczl_PgCl6 + sczl_clAdd6) as sczl_PgCl,
  131. sys_rq, mod_rq, UniqId')
  132. ->where($where)
  133. ->page($page,$limit)
  134. ->select();
  135. $total = db()->table('db_包装产量预报')->where($where)->count();
  136. }else{
  137. if (isset($req['cpmc']) && !empty($req['cpmc'])){
  138. //查询工单表
  139. $gd = db()->table('工单_基本资料')
  140. ->where('Gd_cpmc', 'LIKE', '%'.$req['cpmc'].'%')
  141. ->column('Gd_gdbh');
  142. $where = [
  143. 'sczl_gdbh1|sczl_gdbh2|sczl_gdbh3|sczl_gdbh4|sczl_gdbh5|sczl_gdbh6'=>['in', $gd]
  144. ];
  145. $rows = db()->table('db_包装产量预报')
  146. ->field('rtrim(sys_id) as sys_id, LEFT(sczl_rq, 10) as sczl_rq,
  147. sczl_cl1 + sczl_cl2 + sczl_cl3 + sczl_cl4 + sczl_cl5 + sczl_cl6 as sczl_cl,
  148. (sczl_cl1 * sczl_PgCl1 + sczl_clAdd1) + (sczl_cl2 * sczl_PgCl2 + sczl_clAdd2) + (sczl_cl3 * sczl_PgCl3 + sczl_clAdd3) + (sczl_cl4 * sczl_PgCl4 + sczl_clAdd4) + (sczl_cl5 * sczl_PgCl5 + sczl_clAdd5) + (sczl_cl6 * sczl_PgCl6 + sczl_clAdd6) as sczl_PgCl,
  149. sys_rq, mod_rq, UniqId')
  150. ->where($where)
  151. ->page($page,$limit)
  152. ->select();
  153. $total = db()->table('db_包装产量预报')->where($where)->count();
  154. }else{
  155. $this->error('参数错误');
  156. }
  157. }
  158. foreach ($rows as $key=>$value){
  159. $rows[$key]['mod_rq'] = $value['mod_rq']=='1900-01-01 00:00:00' ? '' :$value['mod_rq'];
  160. $rows[$key]['sczl_cl'] = floatval($value['sczl_cl']);
  161. $rows[$key]['sczl_PgCl'] = floatval($value['sczl_PgCl']);
  162. }
  163. $data = [
  164. 'total' => $total,
  165. 'rows' => $rows,
  166. ];
  167. $this->success('成功',$data);
  168. }
  169. /**
  170. * 获取信息
  171. * @ApiMethod (GET)
  172. * @param string $UniqId UniqId
  173. */
  174. public function getInfo()
  175. {
  176. //get请求
  177. if(!$this->request->isGet()){
  178. $this->error('请求方式错误');
  179. }
  180. $req = $this->request->param();
  181. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  182. $UniqId = $req['UniqId'];
  183. }else{
  184. $this->error('参数错误');
  185. }
  186. // $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
  187. $rows = db()->table('db_包装产量预报')
  188. ->field('LEFT(sczl_rq, 10) as sczl_rq, sczl_gdbh1, sczl_gdbh2, sczl_gdbh3, sczl_gdbh4, sczl_gdbh5, sczl_gdbh6,
  189. 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,
  190. 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,
  191. sczl_cl1, sczl_cl2, sczl_cl3, sczl_cl4, sczl_cl5, sczl_cl6,
  192. sczl_PgCl1, sczl_PgCl2, sczl_PgCl3, sczl_PgCl4, sczl_PgCl5, sczl_PgCl6,
  193. sczl_clAdd1, sczl_clAdd2, sczl_clAdd3, sczl_clAdd4, sczl_clAdd5, sczl_clAdd6')
  194. ->where('UniqId',$UniqId)
  195. ->find();
  196. for ($i=1;$i<=6;$i++){
  197. // $rows['Gd_cpmc'.$i] = array_key_exists($rows['sczl_gdbh'.$i], $gd) ? trim($gd[$rows['sczl_gdbh'.$i]]) : '';
  198. if (!empty($rows['sczl_gdbh'.$i])){
  199. $rows['Gd_cpmc'.$i] = db('工单_印件资料')
  200. ->where('Yj_Gdbh',strtoupper($rows['sczl_gdbh'.$i]))
  201. ->where('yj_Yjno',(int)substr($rows['sczl_yjGx'.$i],0,2))
  202. ->find()['yj_yjmc'];
  203. }
  204. }
  205. $this->success('成功',$rows);
  206. }
  207. /**
  208. * 查询印件工序及产品名称
  209. * @ApiMethod (GET)
  210. * @param string $gdbh 工单编号
  211. * @param string $gxmc 工序名称
  212. */
  213. public function getGxMc()
  214. {
  215. //get请求
  216. if(!$this->request->isGet()){
  217. $this->error('请求方式错误');
  218. }
  219. $req = $this->request->param();
  220. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  221. $gdbh = $req['gdbh'];
  222. }else{
  223. $this->error('参数错误');
  224. }
  225. $gxmc = ['包装','成品防护'];
  226. $gxmcs = [];
  227. foreach ($gxmc as $k=>$v){
  228. array_push($gxmcs,['like','%'.$v.'%']);
  229. }
  230. array_push($gxmcs,'OR');
  231. $rows = db()->table('工单_印件资料')->alias('g')
  232. ->field('rtrim(g.yj_yjmc) as Gd_cpmc, g.yj_Yjno as Gy0_yjno, c.Gy0_gxh, rtrim(c.Gy0_gxmc) as Gy0_gxmc')
  233. ->where(['g.Yj_Gdbh'=>$gdbh])
  234. ->where(['c.Gy0_gxmc'=>$gxmcs])
  235. ->join(['工单_工艺资料'=>'c'],'c.Gy0_gdbh=g.Yj_Gdbh and g.yj_Yjno=c.Gy0_yjno')
  236. ->select();
  237. foreach ($rows as $key=>$value){
  238. $rows[$key]['jyGx'] = sprintf("%02d", $value['Gy0_yjno']).'-'.$value['Gy0_gxh'];
  239. }
  240. $this->success('成功',$rows);
  241. }
  242. /**
  243. * 新增
  244. * @ApiMethod (POST)
  245. * @param string 'sys_id','sczl_rq',
  246. */
  247. public function add()
  248. {
  249. if(!$this->request->isPost()){
  250. $this->error('请求方式错误');
  251. }
  252. $req = $this->request->param();
  253. $arr = [
  254. 'sys_id','sczl_rq',
  255. 'sczl_gdbh1', 'sczl_gdbh2', 'sczl_gdbh3', 'sczl_gdbh4', 'sczl_gdbh5', 'sczl_gdbh6',
  256. 'sczl_yjGx1', 'sczl_yjGx2', 'sczl_yjGx3', 'sczl_yjGx4', 'sczl_yjGx5', 'sczl_yjGx6',
  257. 'sczl_gxmc1', 'sczl_gxmc2', 'sczl_gxmc3', 'sczl_gxmc4', 'sczl_gxmc5', 'sczl_gxmc6',
  258. 'sczl_cl1', 'sczl_cl2', 'sczl_cl3', 'sczl_cl4', 'sczl_cl5', 'sczl_cl6',
  259. 'sczl_PgCl1', 'sczl_PgCl2', 'sczl_PgCl3', 'sczl_PgCl4', 'sczl_PgCl5', 'sczl_PgCl6',
  260. 'sczl_clAdd1', 'sczl_clAdd2', 'sczl_clAdd3', 'sczl_clAdd4', 'sczl_clAdd5', 'sczl_clAdd6'
  261. ];
  262. $data = [];
  263. foreach ($arr as $key => $value){
  264. if (!isset($req[$value])){
  265. $this->error('参数错误',$value,$key+1);
  266. }
  267. $data[$value] = $req[$value];
  268. }
  269. $data['sys_rq'] = date('Y-m-d H:i:s');
  270. //查询UniqId
  271. $UniqId = db()->table('db_包装产量预报')->max('UniqId');
  272. $data['UniqId'] = $UniqId < 10000000 ? 10000000 : $UniqId + 1;
  273. //开启事务
  274. db()->startTrans();
  275. try{
  276. $sql = db()->table('db_包装产量预报')->fetchSql(true)->insert($data);
  277. $bool = db()->query($sql);
  278. // 提交事务
  279. db()->commit();
  280. } catch (\Exception $e) {
  281. // 回滚事务
  282. db()->rollback();
  283. $this->error($e->getMessage());
  284. }
  285. if($bool===false) $this->error('失败');
  286. $this->success('成功');
  287. }
  288. /**
  289. * 修改
  290. * @ApiMethod (POST)
  291. * @param string 'UniqId',
  292. */
  293. public function edit()
  294. {
  295. if(!$this->request->isPost()){
  296. $this->error('请求方式错误');
  297. }
  298. $req = $this->request->param();
  299. $arr = [
  300. 'sczl_rq',
  301. 'sczl_gdbh1', 'sczl_gdbh2', 'sczl_gdbh3', 'sczl_gdbh4', 'sczl_gdbh5', 'sczl_gdbh6',
  302. 'sczl_yjGx1', 'sczl_yjGx2', 'sczl_yjGx3', 'sczl_yjGx4', 'sczl_yjGx5', 'sczl_yjGx6',
  303. 'sczl_gxmc1', 'sczl_gxmc2', 'sczl_gxmc3', 'sczl_gxmc4', 'sczl_gxmc5', 'sczl_gxmc6',
  304. 'sczl_cl1', 'sczl_cl2', 'sczl_cl3', 'sczl_cl4', 'sczl_cl5', 'sczl_cl6',
  305. 'sczl_PgCl1', 'sczl_PgCl2', 'sczl_PgCl3', 'sczl_PgCl4', 'sczl_PgCl5', 'sczl_PgCl6',
  306. 'sczl_clAdd1', 'sczl_clAdd2', 'sczl_clAdd3', 'sczl_clAdd4', 'sczl_clAdd5', 'sczl_clAdd6'
  307. ];
  308. $data = [];
  309. foreach ($arr as $key => $value){
  310. if (!isset($req[$value])){
  311. $this->error('参数错误',$value,$key+1);
  312. }
  313. $data[$value] = $req[$value];
  314. }
  315. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  316. $this->error('参数错误','UniqId',100);
  317. }
  318. $data['mod_rq'] = date('Y-m-d H:i:s');
  319. //开启事务
  320. db()->startTrans();
  321. try{
  322. $sql = db()->table('db_包装产量预报')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
  323. $bool = db()->query($sql);
  324. // 提交事务
  325. db()->commit();
  326. } catch (\Exception $e) {
  327. // 回滚事务
  328. db()->rollback();
  329. $this->error($e->getMessage());
  330. }
  331. if($bool===false) $this->error('失败');
  332. $this->success('成功');
  333. }
  334. /**
  335. * 修改
  336. * @ApiMethod (POST)
  337. * @param string 'UniqId'
  338. */
  339. public function del()
  340. {
  341. if(!$this->request->isPost()){
  342. $this->error('请求方式错误');
  343. }
  344. $req = $this->request->param();
  345. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  346. $this->error('参数错误','UniqId',100);
  347. }
  348. //开启事务
  349. db()->startTrans();
  350. try{
  351. $bool = db()->table('db_包装产量预报')->where('UniqId',$req['UniqId'])->delete();
  352. // 提交事务
  353. db()->commit();
  354. } catch (\Exception $e) {
  355. // 回滚事务
  356. db()->rollback();
  357. $this->error($e->getMessage());
  358. }
  359. if($bool===false) $this->error('失败');
  360. $this->success('成功');
  361. }
  362. }