PackagingProcessOutput.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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. }
  199. $this->success('成功',$rows);
  200. }
  201. /**
  202. * 查询印件工序及产品名称
  203. * @ApiMethod (GET)
  204. * @param string $gdbh 工单编号
  205. * @param string $gxmc 工序名称
  206. */
  207. public function getGxMc()
  208. {
  209. //get请求
  210. if(!$this->request->isGet()){
  211. $this->error('请求方式错误');
  212. }
  213. $req = $this->request->param();
  214. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  215. $gdbh = $req['gdbh'];
  216. }else{
  217. $this->error('参数错误');
  218. }
  219. $gxmc = ['包装'];
  220. $gxmcs = [];
  221. foreach ($gxmc as $k=>$v){
  222. array_push($gxmcs,['like','%'.$v.'%']);
  223. }
  224. array_push($gxmcs,'OR');
  225. $rows = db()->table('工单_印件资料')->alias('g')
  226. ->field('rtrim(g.yj_yjmc) as Gd_cpmc, g.yj_Yjno as Gy0_yjno, c.Gy0_gxh, rtrim(c.Gy0_gxmc) as Gy0_gxmc')
  227. ->where(['g.Yj_Gdbh'=>$gdbh])
  228. ->where(['c.Gy0_gxmc'=>$gxmcs])
  229. ->join(['工单_工艺资料'=>'c'],'c.Gy0_gdbh=g.Yj_Gdbh and g.yj_Yjno=c.Gy0_yjno')
  230. ->select();
  231. foreach ($rows as $key=>$value){
  232. $rows[$key]['jyGx'] = sprintf("%02d", $value['Gy0_yjno']).'-'.$value['Gy0_gxh'];
  233. }
  234. $this->success('成功',$rows);
  235. }
  236. /**
  237. * 新增
  238. * @ApiMethod (POST)
  239. * @param string 'sys_id','sczl_rq',
  240. */
  241. public function add()
  242. {
  243. if(!$this->request->isPost()){
  244. $this->error('请求方式错误');
  245. }
  246. $req = $this->request->param();
  247. $arr = [
  248. 'sys_id','sczl_rq',
  249. 'sczl_gdbh1', 'sczl_gdbh2', 'sczl_gdbh3', 'sczl_gdbh4', 'sczl_gdbh5', 'sczl_gdbh6',
  250. 'sczl_yjGx1', 'sczl_yjGx2', 'sczl_yjGx3', 'sczl_yjGx4', 'sczl_yjGx5', 'sczl_yjGx6',
  251. 'sczl_gxmc1', 'sczl_gxmc2', 'sczl_gxmc3', 'sczl_gxmc4', 'sczl_gxmc5', 'sczl_gxmc6',
  252. 'sczl_cl1', 'sczl_cl2', 'sczl_cl3', 'sczl_cl4', 'sczl_cl5', 'sczl_cl6',
  253. 'sczl_PgCl1', 'sczl_PgCl2', 'sczl_PgCl3', 'sczl_PgCl4', 'sczl_PgCl5', 'sczl_PgCl6',
  254. 'sczl_clAdd1', 'sczl_clAdd2', 'sczl_clAdd3', 'sczl_clAdd4', 'sczl_clAdd5', 'sczl_clAdd6'
  255. ];
  256. $data = [];
  257. foreach ($arr as $key => $value){
  258. if (!isset($req[$value])){
  259. $this->error('参数错误',$value,$key+1);
  260. }
  261. $data[$value] = $req[$value];
  262. }
  263. $data['sys_rq'] = date('Y-m-d H:i:s');
  264. //查询UniqId
  265. $UniqId = db()->table('db_包装产量预报')->max('UniqId');
  266. $data['UniqId'] = $UniqId < 10000000 ? 10000000 : $UniqId + 1;
  267. //开启事务
  268. db()->startTrans();
  269. try{
  270. $sql = db()->table('db_包装产量预报')->fetchSql(true)->insert($data);
  271. $bool = db()->query($sql);
  272. // 提交事务
  273. db()->commit();
  274. } catch (\Exception $e) {
  275. // 回滚事务
  276. db()->rollback();
  277. $this->error($e->getMessage());
  278. }
  279. if($bool===false) $this->error('失败');
  280. $this->success('成功');
  281. }
  282. /**
  283. * 修改
  284. * @ApiMethod (POST)
  285. * @param string 'UniqId',
  286. */
  287. public function edit()
  288. {
  289. if(!$this->request->isPost()){
  290. $this->error('请求方式错误');
  291. }
  292. $req = $this->request->param();
  293. $arr = [
  294. 'sczl_rq',
  295. 'sczl_gdbh1', 'sczl_gdbh2', 'sczl_gdbh3', 'sczl_gdbh4', 'sczl_gdbh5', 'sczl_gdbh6',
  296. 'sczl_yjGx1', 'sczl_yjGx2', 'sczl_yjGx3', 'sczl_yjGx4', 'sczl_yjGx5', 'sczl_yjGx6',
  297. 'sczl_gxmc1', 'sczl_gxmc2', 'sczl_gxmc3', 'sczl_gxmc4', 'sczl_gxmc5', 'sczl_gxmc6',
  298. 'sczl_cl1', 'sczl_cl2', 'sczl_cl3', 'sczl_cl4', 'sczl_cl5', 'sczl_cl6',
  299. 'sczl_PgCl1', 'sczl_PgCl2', 'sczl_PgCl3', 'sczl_PgCl4', 'sczl_PgCl5', 'sczl_PgCl6',
  300. 'sczl_clAdd1', 'sczl_clAdd2', 'sczl_clAdd3', 'sczl_clAdd4', 'sczl_clAdd5', 'sczl_clAdd6'
  301. ];
  302. $data = [];
  303. foreach ($arr as $key => $value){
  304. if (!isset($req[$value])){
  305. $this->error('参数错误',$value,$key+1);
  306. }
  307. $data[$value] = $req[$value];
  308. }
  309. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  310. $this->error('参数错误','UniqId',100);
  311. }
  312. $data['mod_rq'] = date('Y-m-d H:i:s');
  313. //开启事务
  314. db()->startTrans();
  315. try{
  316. $sql = db()->table('db_包装产量预报')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
  317. $bool = db()->query($sql);
  318. // 提交事务
  319. db()->commit();
  320. } catch (\Exception $e) {
  321. // 回滚事务
  322. db()->rollback();
  323. $this->error($e->getMessage());
  324. }
  325. if($bool===false) $this->error('失败');
  326. $this->success('成功');
  327. }
  328. /**
  329. * 修改
  330. * @ApiMethod (POST)
  331. * @param string 'UniqId'
  332. */
  333. public function del()
  334. {
  335. if(!$this->request->isPost()){
  336. $this->error('请求方式错误');
  337. }
  338. $req = $this->request->param();
  339. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  340. $this->error('参数错误','UniqId',100);
  341. }
  342. //开启事务
  343. db()->startTrans();
  344. try{
  345. $bool = db()->table('db_包装产量预报')->where('UniqId',$req['UniqId'])->delete();
  346. // 提交事务
  347. db()->commit();
  348. } catch (\Exception $e) {
  349. // 回滚事务
  350. db()->rollback();
  351. $this->error($e->getMessage());
  352. }
  353. if($bool===false) $this->error('失败');
  354. $this->success('成功');
  355. }
  356. }