PackagingProcessOutput.php 15 KB

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