GluFinishedProductWarehousing.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 糊盒成品入仓维护接口
  7. */
  8. class GluFinishedProductWarehousing extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. /**
  13. * 侧边栏
  14. * @ApiMethod (GET)
  15. */
  16. public function getTab()
  17. {
  18. //get请求
  19. if(!$this->request->isGet()){
  20. $this->error('请求方式错误');
  21. }
  22. $rows = db('糊盒成品入仓')
  23. ->field('LEFT(Sys_rq, 10) as date, COUNT(*) as counts')
  24. ->group('date')
  25. ->order('UniqId desc')
  26. ->limit(50)
  27. ->select();
  28. $num = db('糊盒成品入仓')
  29. ->where('Sys_rq','>=',$rows[count($rows)-1]['date'])
  30. ->count();
  31. $arr = db('糊盒成品入仓')
  32. ->field('LEFT(Sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(*) as count')
  33. ->where('Sys_rq','>=',$rows[count($rows)-1]['date'])
  34. ->group('date, sys_id')
  35. ->limit($num)
  36. ->select();
  37. foreach($rows as $key=>$value){
  38. $rows[$key]['sys'] = [];
  39. foreach($arr as $k=>$v){
  40. if($value['date'] == $v['date']){
  41. unset($v['date']);
  42. array_push($rows[$key]['sys'],$v);
  43. unset($arr[$k]);
  44. }
  45. }
  46. $rows[$key]['date'] = str_replace('-', '.', $rows[$key]['date']);
  47. }
  48. $this->success('成功',$rows);
  49. }
  50. /**
  51. * 列表
  52. * @ApiMethod (GET)
  53. * @param string $date 时间
  54. * @param string $sys_id 用户
  55. */
  56. public function getList()
  57. {
  58. // 验证请求方式
  59. if (!$this->request->isGet()) {
  60. $this->error('请求方式错误');
  61. }
  62. $req = $this->request->param();
  63. if (!isset($req['date'])) {
  64. $this->error('参数缺失');
  65. }
  66. // 设置分页参数,默认值
  67. $page = isset($req['page']) && !empty($req['page']) ? intval($req['page']) : 1;
  68. $limit = isset($req['limit']) && !empty($req['limit']) ? intval($req['limit']) : 20;
  69. // 构建查询条件
  70. if (strpos($req['date'], '-')) {
  71. $where = ['c.Sys_rq' => ['like', $req['date'] . '%']];
  72. $option = ['Sys_rq' => ['like', $req['date'] . '%']];
  73. } else {
  74. $where = [];
  75. $option = [];
  76. }
  77. if (isset($req['sys_id']) && !empty($req['sys_id'])) {
  78. $where['c.Sys_id'] = ['LIKE', $req['sys_id'] . '%'];
  79. $option['Sys_id'] = ['LIKE', $req['sys_id'] . '%'];
  80. }
  81. // 获取总数
  82. $total = db('糊盒成品入仓')->where($option)->count();
  83. // 查询数据(带分页)
  84. $rows = db('糊盒成品入仓')->alias('c')
  85. ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
  86. rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh,
  87. c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj,
  88. rtrim(c.jjcp_smb) as jjcp_smb, rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  89. rtrim(c.成品编码) as 成品编码, rtrim(c.成品名称) as 成品名称,
  90. rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, LEFT(c.成品编码,'.config('product_code_digit').') as 客户编号, rtrim(g.Gd_客户名称) as Gd_客户名称,
  91. rtrim(c.机型备注) as 机型备注, rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
  92. ->where($where)
  93. ->join('工单_基本资料 g', 'g.Gd_gdbh=c.jjcp_gdbh AND g.Gd_cpdh=c.jjcp_cpdh')
  94. ->order('c.UniqId desc')
  95. ->limit(($page - 1) * $limit, $limit)
  96. ->select();
  97. // 处理数据
  98. foreach ($rows as $key => $value) {
  99. $row = db('糊盒成品入仓')
  100. ->field('LEFT(Sys_rq, 10) as Sys_rq,jjcp_sl')
  101. ->where(['jjcp_gdbh' => $value['jjcp_gdbh'], 'jjcp_cpdh' => $value['jjcp_cpdh']])
  102. ->order('Sys_rq desc')
  103. ->select();
  104. $rows[$key]['jjcp_sls'] = 0;
  105. foreach ($row as $k => $v) {
  106. $rows[$key]['jjcp_sls'] += $v['jjcp_sl'];
  107. }
  108. if ($value['订单数量'] != 0) {
  109. $rows[$key]['完成率'] = number_format($rows[$key]['jjcp_sls'] / $value['订单数量'] / 100, 2);
  110. } else {
  111. $rows[$key]['完成率'] = '';
  112. }
  113. $rows[$key]['订单数量'] = floatval($value['订单数量'] * 10000);
  114. $rows[$key]['最近入仓日期'] = $row[0]['Sys_rq'];
  115. $rows[$key]['Mod_rq'] = $value['Mod_rq'] == '1900-01-01 00:00:00' ? '' : $value['Mod_rq'];
  116. }
  117. $data = [
  118. 'total' => $total,
  119. 'rows' => $rows,
  120. ];
  121. $this->success('成功', $data);
  122. }
  123. /**
  124. * 获取信息
  125. * @ApiMethod (GET)
  126. * @param string $UniqId UniqId
  127. */
  128. public function getInfo()
  129. {
  130. //get请求
  131. if(!$this->request->isGet()){
  132. $this->error('请求方式错误');
  133. }
  134. $req = $this->request->param();
  135. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  136. $UniqId = $req['UniqId'];
  137. }else{
  138. $this->error('参数错误');
  139. }
  140. //客户编号
  141. $rows = db('糊盒成品入仓')->alias('c')
  142. ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称,
  143. rtrim(c.jjcp_num) as jjcp_num,
  144. c.jjcp_gdbh, rtrim(c.订单编号) as 订单编号,
  145. rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
  146. rtrim(c.成品编码) as 成品编码, rtrim(c.成品名称) as 成品名称,
  147. rtrim(c.客户料号) as 客户料号,
  148. rtrim(c.jjcp_smb) as jjcp_smb, LEFT(c.jjcp_sj, 10) as jjcp_sj,
  149. c.jjcp_sl, rtrim(c.jjcp_dw) as jjcp_dw,
  150. g.订单数量*10000 as 订单数量, rtrim(c.机型备注) as 机型备注, rtrim(c.jjcp_desc) as jjcp_desc,
  151. rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
  152. ->where('c.UniqId',$UniqId)
  153. ->where('g.Gd_cpdh=c.jjcp_cpdh')
  154. ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
  155. ->find();
  156. $rows['jjcp_sls'] = db('糊盒成品入仓')
  157. ->where(['jjcp_gdbh'=>$rows['jjcp_gdbh'], 'jjcp_cpdh'=>$rows['jjcp_cpdh']])
  158. ->sum('jjcp_sl');
  159. $this->success('成功',$rows);
  160. }
  161. /**
  162. * 新增
  163. * @ApiMethod (POST)
  164. * @param string
  165. */
  166. public function add()
  167. {
  168. if(!$this->request->isPost()){
  169. $this->error('请求方式错误');
  170. }
  171. $req = $this->request->param();
  172. $arr = [
  173. 'Sys_id',
  174. '入仓类型', '仓库编号', '仓库名称',
  175. 'jjcp_num',
  176. 'jjcp_gdbh', '订单编号',
  177. 'jjcp_cpdh', 'jjcp_cpmc',
  178. '成品编码', '成品名称',
  179. '客户料号',
  180. 'jjcp_smb', 'jjcp_sj',
  181. 'jjcp_sl', 'jjcp_dw',
  182. '机型备注',
  183. 'jjcp_desc'
  184. ];
  185. $name = \db('工单_基本资料')
  186. ->where('Gd_gdbh',$req['jjcp_gdbh'])
  187. ->value('Gd_cpmc');
  188. if ($name !== $req['jjcp_cpmc']){
  189. $this->error('产品名称错误');
  190. }
  191. $data = [];
  192. foreach ($arr as $key => $value){
  193. if (!isset($req[$value])){
  194. $this->error('参数错误',$value,$key+1);
  195. }
  196. $data[$value] = $req[$value];
  197. }
  198. $data['Sys_rq'] = date('Y-m-d H:i:s');
  199. //判断当前工单是否存在已提交模版
  200. $existingRecord = db('糊盒成品入仓')
  201. ->where('jjcp_gdbh', $data['jjcp_gdbh'])
  202. ->where('jjcp_smb', '<>', '') // 判断 jjcp_smb 不为空
  203. ->find();
  204. if ($existingRecord) {
  205. $this->error($existingRecord['jjcp_gdbh'].'工单已经进入末版,无法继续操作');
  206. }
  207. //开启事务
  208. db()->startTrans();
  209. try{
  210. $sql = db('糊盒成品入仓')->fetchSql(true)->insert($data);
  211. $bool = db()->query($sql);
  212. // 提交事务
  213. db()->commit();
  214. } catch (\Exception $e) {
  215. // 回滚事务
  216. db()->rollback();
  217. $this->error($e->getMessage());
  218. }
  219. if($bool===false) $this->error('失败');
  220. $this->success('成功');
  221. }
  222. /**
  223. * 修改
  224. * @ApiMethod (POST)
  225. */
  226. public function edit()
  227. {
  228. if(!$this->request->isPost()){
  229. $this->error('请求方式错误');
  230. }
  231. $req = $this->request->param();
  232. $arr = [
  233. '入仓类型', '仓库编号', '仓库名称',
  234. 'jjcp_num',
  235. 'jjcp_gdbh','订单编号',
  236. 'jjcp_cpdh', 'jjcp_cpmc',
  237. '成品编码', '成品名称',
  238. '客户料号',
  239. 'jjcp_smb', 'jjcp_sj',
  240. 'jjcp_sl', 'jjcp_dw',
  241. '机型备注',
  242. 'jjcp_desc'
  243. ];
  244. $data = [];
  245. foreach ($arr as $key => $value){
  246. if (!isset($req[$value])){
  247. continue;
  248. }
  249. $data[$value] = $req[$value];
  250. }
  251. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  252. $this->error('参数错误','UniqId',100);
  253. }
  254. if (count($data)==0){
  255. $this->error('参数错误','',111);
  256. }
  257. $data['Mod_rq'] = date('Y-m-d H:i:s');
  258. //判断当前工单是否存在已提交模版
  259. if ($data['jjcp_smb'] === '末 板'){
  260. $existingRecord = db('糊盒成品入仓')
  261. ->where('jjcp_gdbh', $data['jjcp_gdbh'])
  262. ->where('jjcp_smb', '<>', '') // 判断 jjcp_smb 不为空
  263. ->find();
  264. if ($existingRecord && $existingRecord['UniqId'] !== (int)$req['UniqId']) {
  265. $this->error($existingRecord['jjcp_gdbh'].'工单已经进入末版,无法继续操作');
  266. }
  267. };
  268. //开启事务
  269. db()->startTrans();
  270. try{
  271. $sql = db('糊盒成品入仓')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
  272. $bool = db()->query($sql);
  273. // 提交事务
  274. db()->commit();
  275. } catch (\Exception $e) {
  276. // 回滚事务
  277. db()->rollback();
  278. $this->error($e->getMessage());
  279. }
  280. if($bool===false) $this->error('失败');
  281. $this->success('成功');
  282. }
  283. /**
  284. * 删除
  285. * @ApiMethod (POST)
  286. * @param string 'UniqId'
  287. */
  288. public function del()
  289. {
  290. if(!$this->request->isPost()){
  291. $this->error('请求方式错误');
  292. }
  293. $req = $this->request->param();
  294. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  295. $this->error('参数错误','UniqId',100);
  296. }
  297. //开启事务
  298. db()->startTrans();
  299. try{
  300. $bool = db('糊盒成品入仓')->where('UniqId',$req['UniqId'])->delete();
  301. // 提交事务
  302. db()->commit();
  303. } catch (\Exception $e) {
  304. // 回滚事务
  305. db()->rollback();
  306. $this->error($e->getMessage());
  307. }
  308. if($bool===false) $this->error('失败');
  309. $this->success('成功');
  310. }
  311. /**
  312. * 获取工单信息
  313. * @return void
  314. * @throws \think\db\exception\DataNotFoundException
  315. * @throws \think\db\exception\ModelNotFoundException
  316. * @throws \think\exception\DbException
  317. */
  318. public function getGd()
  319. {
  320. //get请求
  321. if(!$this->request->isGet()){
  322. $this->error('请求方式错误');
  323. }
  324. $req = $this->request->param();
  325. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  326. $gdbh = $req['gdbh'];
  327. }else{
  328. $this->error('参数错误');
  329. }
  330. $rows = db('工单_基本资料')
  331. ->field('Gd_gdbh, rtrim(销售订单号) as 销售订单号, rtrim(Gd_cpdh) as yj_Yjdh,
  332. rtrim(Gd_cpmc) as yj_yjmc, rtrim(成品代号) as 成品代号, rtrim(成品名称) as 成品名称,
  333. rtrim(客户料号) as 客户料号,行号')
  334. ->where(['Gd_gdbh'=>$gdbh])
  335. ->select();
  336. foreach ($rows as $key=>$value){
  337. $rows[$key]['gdyj'] = $value['Gd_gdbh'].' -'.$value['行号'].'-'.$value['yj_yjmc'];
  338. }
  339. $this->success('成功',$rows);
  340. }
  341. }