AluminumElectroplated.php 10 KB

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