AluminumElectroplated.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Request;
  5. /**
  6. * 电化铝领用记录
  7. */
  8. class AluminumElectroplated extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. /**
  13. * 电化铝领用管理左侧菜单栏
  14. * @return void
  15. * @throws \think\db\exception\DataNotFoundException
  16. * @throws \think\db\exception\ModelNotFoundException
  17. * @throws \think\exception\DbException
  18. */
  19. public function getTab()
  20. {
  21. if ($this->request->isGet() === false) {
  22. $this->error('请求错误');
  23. }
  24. //获取最后上传日期
  25. $lastDay = db('物料_电化铝领用记录')
  26. ->order('Uniqid desc')
  27. ->value('st_rq');
  28. $nextDay = date('Y-m-d', strtotime($lastDay . ' -1 month'));
  29. $list = db('物料_电化铝领用记录')
  30. ->field('DATE(st_rq) as st_rq, sys_id, COUNT(*) as count')
  31. ->where('st_rq', '>=', $nextDay . ' 00:00:00') // 最小值
  32. ->where('st_rq', '<=', $lastDay) // 最大值
  33. ->group('st_rq, sys_id')
  34. ->order('st_rq DESC')
  35. ->select();
  36. $data = [];
  37. if (!empty($list)){
  38. foreach ($list as $k=>$v){
  39. if (isset($data[$v['st_rq']]) == false){
  40. $data[$v['st_rq']] = [];
  41. }
  42. $data[$v['st_rq']][] = $v['sys_id'].'【记录数'.$v['count'].'】';
  43. }
  44. }
  45. $this->success('成功',$data);
  46. }
  47. /**
  48. * 电化铝领用列表
  49. * @return void
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. * @throws \think\exception\DbException
  53. */
  54. public function getElectroplatedList()
  55. {
  56. if ($this->request->isGet() === false) {
  57. $this->error('请求错误');
  58. }
  59. $params = $this->request->param();
  60. if (empty($params) || !isset($params['day'])) {
  61. $this->error('参数错误');
  62. }
  63. $where['st_rq'] = ['like',$params['day'].'%'];
  64. if (isset($params['sys_id'])) {
  65. $where['a.sys_id'] = $params['sys_id'];
  66. }
  67. $list = \db('物料_电化铝领用记录')
  68. ->alias('a')
  69. ->join('工单_印件资料 b', 'a.st_gdbh = b.Yj_Gdbh and a.st_yjno = yj_Yjno')
  70. ->join('物料_存货编码 c', 'a.st_wlbh = c.物料代码')
  71. ->join('工单_基本资料 d', 'a.st_gdbh = d.Gd_gdbh')
  72. ->field('a.st_gdbh, a.st_yjno, a.st_wlbh, a.st_rq,a.st_jylb,a.采购单号,a.供方批次,a.卷宽,a.卷长,a.领用宽度,a.st_sl as 领用数量,
  73. a.机台,a.st_desc as 备注,a.Uniqid,rtrim(d.成品名称) as 成品名称,rtrim(b.yj_yjmc) as 印件名称,rtrim(c.物料名称) as 物料名称,
  74. rtrim(c.领用单位) as 单位,b.yj_Yjdh as 印件代号,a.sys_rq as 创建时间,rtrim(d.成品代号) as 成品代号')
  75. ->where($where)
  76. ->select();
  77. if (empty($list)) {
  78. $this->error('未找到数据');
  79. }else{
  80. $this->success('成功',$list);
  81. }
  82. }
  83. /**
  84. * 电化铝领用记录详情
  85. * @return void
  86. * @throws \think\db\exception\DataNotFoundException
  87. * @throws \think\db\exception\ModelNotFoundException
  88. * @throws \think\exception\DbException
  89. */
  90. public function getElectroplatedDetail()
  91. {
  92. if ($this->request->isGet() === false) {
  93. $this->error('请求错误');
  94. }
  95. $params = $this->request->param();
  96. if (empty($params) || !isset($params['Uniqid'])) {
  97. $this->error('参数错误');
  98. }
  99. $list = \db('物料_电化铝领用记录')
  100. ->alias('a')
  101. ->join('工单_印件资料 b', 'a.st_gdbh = b.Yj_Gdbh and a.st_yjno = yj_Yjno')
  102. ->join('物料_存货编码 c', 'a.st_wlbh = c.物料代码')
  103. ->join('工单_基本资料 d', 'a.st_gdbh = d.Gd_gdbh')
  104. ->field('a.st_gdbh, a.st_yjno, a.st_wlbh, a.st_rq,a.st_jylb,a.采购单号,a.供方批次,a.卷宽,a.卷长,a.领用宽度,a.st_sl as 领用数量,
  105. a.机台,a.st_desc as 备注,a.Uniqid,rtrim(d.成品名称) as 成品名称,rtrim(b.yj_yjmc) as 印件名称,rtrim(c.物料名称) as 物料名称,rtrim(c.领用单位) as 单位')
  106. ->where('a.Uniqid', $params['Uniqid'])
  107. ->find();
  108. if(empty($list)){
  109. $this->error('未找到数据');
  110. }else{
  111. $this->success('成功',$list);
  112. }
  113. }
  114. /**
  115. * 电化铝领用记录修改
  116. * @return void
  117. * @throws \think\Exception
  118. * @throws \think\db\exception\BindParamException
  119. * @throws \think\exception\PDOException
  120. */
  121. public function getElectroplatedUpdate()
  122. {
  123. if ($this->request->isPost() === false) {
  124. $this->error('请求错误');
  125. }
  126. $params = Request::instance()->param();
  127. if (empty($params) || !isset($params['Uniqid'])) {
  128. $this->error('参数错误');
  129. }
  130. $data = $params;
  131. unset($params['Uniqid']);
  132. $params['mod_rq'] = date('Y-m-d H:i:s',time());
  133. $sql = \db('物料_电化铝领用记录')
  134. ->where('Uniqid', $data['Uniqid'])
  135. ->fetchSql(true)
  136. ->update($params);
  137. $res = \db()->query($sql);
  138. if ($res === false){
  139. $this->error('修改失败');
  140. }else{
  141. $this->success('修改成功');
  142. }
  143. }
  144. /**
  145. * 电化铝领用记录添加
  146. * @return void
  147. * @throws \think\db\exception\BindParamException
  148. * @throws \think\exception\PDOException
  149. */
  150. public function getElectroplatedAdd()
  151. {
  152. if ($this->request->isPost() === false) {
  153. $this->error('请求错误');
  154. }
  155. $params = Request::instance()->param();
  156. if (empty($params)) {
  157. $this->error('参数错误');
  158. }
  159. $params['sys_rq'] = date('Y-m-d H:i:s', time());
  160. $sql = db('物料_电化铝领用记录')
  161. ->fetchSql(true)
  162. ->insert($params);
  163. $res = db()->query($sql);
  164. if ($res === false) {
  165. $this->error('新增失败');
  166. }else{
  167. $this->success('添加成功');
  168. }
  169. }
  170. /**
  171. * 电化铝领用记录删除
  172. * @return void
  173. * @throws \think\Exception
  174. * @throws \think\exception\PDOException
  175. */
  176. public function getElectroplatedDelete()
  177. {
  178. if ($this->request->isGet() === false) {
  179. $this->error('请求错误');
  180. }
  181. $params = $this->request->param();
  182. if (empty($params) || !isset($params['UniqId'])) {
  183. $this->error('参数错误');
  184. }
  185. $id = explode(',', $params['UniqId']);
  186. $res = db('物料_电化铝领用记录')
  187. ->whereIn('id', $id)
  188. ->delete();
  189. if ($res === false) {
  190. $this->error('删除失败');
  191. }else{
  192. $this->success('删除成功');
  193. }
  194. }
  195. /**
  196. * 获取物料信息
  197. * @return void
  198. * @throws \think\db\exception\DataNotFoundException
  199. * @throws \think\db\exception\ModelNotFoundException
  200. * @throws \think\exception\DbException
  201. */
  202. public function getMaterials()
  203. {
  204. if ($this->request->isGet() === false) {
  205. $this->error('请求错误');
  206. }
  207. $params = $this->request->param();
  208. if (empty($params) || !isset($params['gdbh']) || !isset($params['yjno'])) {
  209. $this->error('参数错误');
  210. }
  211. $list = db('工单_印件资料')
  212. ->alias('a')
  213. ->join('物料_收发记录 b', 'a.Yj_Gdbh = b.st_gdbh and yj_Yjdh = b.cpdh', 'left')
  214. ->join('物料_存货编码 c', 'b.st_wlbh = c.物料代码', 'left')
  215. ->field('b.st_wlbh as 物料代码,b.供方批次,rtrim(c.物料名称) as 物料名称,rtrim(c.领用单位) as 单位')
  216. ->where('a.Yj_Gdbh', $params['gdbh'])
  217. ->where('a.yj_Yjno', $params['yjno'])
  218. ->where(function ($query) {
  219. $query->where('b.仓库编号', '203')
  220. ->whereOr('b.仓库编号', 'Y203');
  221. })
  222. ->group('b.供方批次')
  223. ->select();
  224. if (empty($list)) {
  225. $this->error('未找到数据');
  226. }else{
  227. $this->success('成功', $list);
  228. }
  229. }
  230. /**
  231. * 查询机台编号
  232. * @return void
  233. */
  234. public function getMachine()
  235. {
  236. if ($this->request->isGet() === false) {
  237. $this->error('请求错误');
  238. }
  239. $params = $this->request->param();
  240. if (empty($params)) {
  241. $this->error('未输入关键字');
  242. }
  243. $machineList = db('设备_基本资料')
  244. ->where('设备编号','like', '%'.$params['search'].'%')
  245. ->where('sys_sbID','<>','')
  246. ->whereNotNull('sys_sbID')
  247. ->order('设备编号 asc')
  248. ->column('rtrim(设备编号) as 设备编号');
  249. if (empty($machineList)) {
  250. $this->error('未找到数据');
  251. }else{
  252. $this->success('成功', $machineList);
  253. }
  254. }
  255. }