AluminumElectroplated.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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['sys_id']) || !isset($params['day'])) {
  61. $this->error('参数错误');
  62. }
  63. $list = \db('物料_电化铝领用记录')
  64. ->alias('a')
  65. ->join('工单_印件资料 b', 'a.st_gdbh = b.Yj_Gdbh and a.st_yjno = yj_Yjno')
  66. ->join('物料_存货编码 c', 'a.st_wlbh = c.物料代码')
  67. ->join('工单_基本资料 d', 'a.st_gdbh = d.Gd_gdbh')
  68. ->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 领用数量,
  69. a.机台,a.st_desc as 备注,a.Uniqid,rtrim(d.成品名称) as 成品名称,rtrim(b.yj_yjmc) as 印件名称,rtrim(c.物料名称) as 物料名称,
  70. rtrim(c.领用单位) as 单位,b.yj_Yjdh as 印件代号,a.sys_rq as 创建时间,rtrim(d.成品代号) as 成品代号')
  71. ->where('a.st_rq', 'like',$params['day'].'%')
  72. ->where('a.sys_id', $params['sys_id'])
  73. ->select();
  74. if (empty($list)) {
  75. $this->error('未找到数据');
  76. }else{
  77. $this->success('成功',$list);
  78. }
  79. }
  80. /**
  81. * 电化铝领用记录详情
  82. * @return void
  83. * @throws \think\db\exception\DataNotFoundException
  84. * @throws \think\db\exception\ModelNotFoundException
  85. * @throws \think\exception\DbException
  86. */
  87. public function getElectroplatedDetail()
  88. {
  89. if ($this->request->isGet() === false) {
  90. $this->error('请求错误');
  91. }
  92. $params = $this->request->param();
  93. if (empty($params) || !isset($params['Uniqid'])) {
  94. $this->error('参数错误');
  95. }
  96. $list = \db('物料_电化铝领用记录')
  97. ->alias('a')
  98. ->join('工单_印件资料 b', 'a.st_gdbh = b.Yj_Gdbh and a.st_yjno = yj_Yjno')
  99. ->join('物料_存货编码 c', 'a.st_wlbh = c.物料代码')
  100. ->join('工单_基本资料 d', 'a.st_gdbh = d.Gd_gdbh')
  101. ->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 领用数量,
  102. a.机台,a.st_desc as 备注,a.Uniqid,rtrim(d.成品名称) as 成品名称,rtrim(b.yj_yjmc) as 印件名称,rtrim(c.物料名称) as 物料名称,rtrim(c.领用单位) as 单位')
  103. ->where('a.Uniqid', $params['Uniqid'])
  104. ->find();
  105. if(empty($list)){
  106. $this->error('未找到数据');
  107. }else{
  108. $this->success('成功',$list);
  109. }
  110. }
  111. /**
  112. * 电化铝领用记录修改
  113. * @return void
  114. * @throws \think\Exception
  115. * @throws \think\db\exception\BindParamException
  116. * @throws \think\exception\PDOException
  117. */
  118. public function getElectroplatedUpdate()
  119. {
  120. if ($this->request->isPost() === false) {
  121. $this->error('请求错误');
  122. }
  123. $params = Request::instance()->param();
  124. if (empty($params) || !isset($params['Uniqid'])) {
  125. $this->error('参数错误');
  126. }
  127. $data = $params;
  128. unset($params['Uniqid']);
  129. $params['mod_rq'] = date('Y-m-d H:i:s',time());
  130. $sql = \db('物料_电化铝领用记录')
  131. ->where('Uniqid', $data['Uniqid'])
  132. ->fetchSql(true)
  133. ->update($params);
  134. $res = \db()->query($sql);
  135. if ($res === false){
  136. $this->error('修改失败');
  137. }else{
  138. $this->success('修改成功');
  139. }
  140. }
  141. /**
  142. * 电化铝领用记录添加
  143. * @return void
  144. * @throws \think\db\exception\BindParamException
  145. * @throws \think\exception\PDOException
  146. */
  147. public function getElectroplatedAdd()
  148. {
  149. if ($this->request->isPost() === false) {
  150. $this->error('请求错误');
  151. }
  152. $params = Request::instance()->param();
  153. if (empty($params)) {
  154. $this->error('参数错误');
  155. }
  156. $params['sys_rq'] = date('Y-m-d H:i:s', time());
  157. $sql = db('物料_电化铝领用记录')
  158. ->fetchSql(true)
  159. ->insert($params);
  160. $res = db()->query($sql);
  161. if ($res === false) {
  162. $this->error('新增失败');
  163. }else{
  164. $this->success('添加成功');
  165. }
  166. }
  167. /**
  168. * 电化铝领用记录删除
  169. * @return void
  170. * @throws \think\Exception
  171. * @throws \think\exception\PDOException
  172. */
  173. public function getElectroplatedDelete()
  174. {
  175. if ($this->request->isGet() === false) {
  176. $this->error('请求错误');
  177. }
  178. $params = $this->request->param();
  179. if (empty($params) || !isset($params['UniqId'])) {
  180. $this->error('参数错误');
  181. }
  182. $id = explode(',', $params['UniqId']);
  183. $res = db('物料_电化铝领用记录')
  184. ->whereIn('id', $id)
  185. ->delete();
  186. if ($res === false) {
  187. $this->error('删除失败');
  188. }else{
  189. $this->success('删除成功');
  190. }
  191. }
  192. /**
  193. * 获取物料信息
  194. * @return void
  195. * @throws \think\db\exception\DataNotFoundException
  196. * @throws \think\db\exception\ModelNotFoundException
  197. * @throws \think\exception\DbException
  198. */
  199. public function getMaterials()
  200. {
  201. if ($this->request->isGet() === false) {
  202. $this->error('请求错误');
  203. }
  204. $params = $this->request->param();
  205. if (empty($params) || !isset($params['gdbh']) || !isset($params['yjno'])) {
  206. $this->error('参数错误');
  207. }
  208. $list = db('工单_印件资料')
  209. ->alias('a')
  210. ->join('物料_收发记录 b', 'a.Yj_Gdbh = b.st_gdbh and yj_Yjdh = b.cpdh', 'left')
  211. ->join('物料_存货编码 c', 'b.st_wlbh = c.物料代码', 'left')
  212. ->field('b.st_wlbh as 物料代码,b.供方批次,rtrim(c.物料名称) as 物料名称,rtrim(c.领用单位) as 单位')
  213. ->where('a.Yj_Gdbh', $params['gdbh'])
  214. ->where('a.yj_Yjno', $params['yjno'])
  215. ->where(function ($query) {
  216. $query->where('b.仓库编号', '203')
  217. ->whereOr('b.仓库编号', 'Y203');
  218. })
  219. ->group('b.供方批次')
  220. ->select();
  221. if (empty($list)) {
  222. $this->error('未找到数据');
  223. }else{
  224. $this->success('成功', $list);
  225. }
  226. }
  227. /**
  228. * 查询机台编号
  229. * @return void
  230. */
  231. public function getMachine()
  232. {
  233. if ($this->request->isGet() === false) {
  234. $this->error('请求错误');
  235. }
  236. $params = $this->request->param();
  237. if (empty($params)) {
  238. $this->error('未输入关键字');
  239. }
  240. $machineList = db('设备_基本资料')
  241. ->where('设备编号','like', '%'.$params['search'].'%')
  242. ->where('sys_sbID','<>','')
  243. ->whereNotNull('sys_sbID')
  244. ->order('设备编号 asc')
  245. ->column('rtrim(设备编号) as 设备编号');
  246. if (empty($machineList)) {
  247. $this->error('未找到数据');
  248. }else{
  249. $this->success('成功', $machineList);
  250. }
  251. }
  252. }