OtherCountDocument.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use \think\Request;
  5. use \think\Db;
  6. /**
  7. * 其他计件单据维护接口
  8. */
  9. class OtherCountDocument extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 首页
  15. *
  16. */
  17. public function index()
  18. {
  19. $this->success('请求成功');
  20. }
  21. /**
  22. * 获取其他计件单据侧边栏
  23. * @ApiMethod (GET)
  24. */
  25. public function getTab()
  26. {
  27. //get请求
  28. if(!$this->request->isGet()){
  29. $this->error('请求方式错误');
  30. }
  31. // $rows = db()->table('db_拉料计件')
  32. // ->field('LEFT(Sczl_rq, 7) as date, CAST(sum(Sczl_cl) AS SIGNED) as counts')
  33. // ->group('LEFT(Sczl_rq, 7)')
  34. // ->order('UniqId desc')
  35. // ->paginate(13);
  36. //halt($rows);
  37. // $rows->each(function ($item){
  38. // $arr = db()->table('db_拉料计件')->alias('l')
  39. // ->field('rtrim(l.Sczl_bh1) as Sczl_bh1, rtrim(r.员工姓名) as name, sum(l.Sczl_cl) as count')
  40. // ->where('l.sczl_rq','LIKE',$item['date'].'%')
  41. // ->join(['人事_基本资料'=>'r'],'l.Sczl_bh1 = r.员工编号')
  42. // ->group('Sczl_bh1')
  43. // ->select();
  44. //
  45. // $item['sys']=$arr;
  46. // });
  47. // halt($rows);
  48. $rows = db()->table('db_拉料计件')
  49. ->field('LEFT(Sczl_rq, 7) as date, CAST(sum(Sczl_cl) AS SIGNED) as counts')
  50. ->group('date')
  51. ->order('UniqId desc')
  52. ->limit(13)
  53. ->select();
  54. // halt($rows);
  55. $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
  56. foreach($rows as $key=>$value){
  57. $arr = db()->table('db_拉料计件')
  58. ->field('rtrim(Sczl_bh1) as Sczl_bh1, CAST(sum(Sczl_cl) AS SIGNED) as count')
  59. ->where('sczl_rq','LIKE',$value['date'].'%')
  60. ->group('Sczl_bh1')
  61. ->select();
  62. foreach ($arr as $k=>$v) {
  63. $arr[$k]['name'] = array_key_exists($v['Sczl_bh1'],$rs) ? trim($rs[$v['Sczl_bh1']]) : '';
  64. }
  65. $rows[$key]['sys'] = $arr;
  66. $rows[$key]['date'] = str_replace('-', '', $rows[$key]['date']);
  67. }
  68. $this->success('成功',$rows);
  69. }
  70. /**
  71. * 获取其他计件单据列表
  72. * @ApiMethod (GET)
  73. * @param string $date 时间
  74. * @param string $Sczl_bh1 员工编号
  75. * @param string $order 工单编号
  76. */
  77. public function getList()
  78. {
  79. //get请求
  80. if(!$this->request->isGet()){
  81. $this->error('请求方式错误');
  82. }
  83. $req = $this->request->param();
  84. $page = 1;
  85. $limit = 15;
  86. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  87. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  88. $where = [];
  89. if (isset($req['date']) && !empty($req['date'])){
  90. $where['a.Sczl_rq'] = ['LIKE',$req['date'].'%'];
  91. }
  92. if (!empty($req['order']) && (!empty($req['date']) || !empty($req['Sczl_bh1']))){
  93. $this->error('参数错误');
  94. }
  95. if (isset($req['Sczl_bh1']) && !empty($req['Sczl_bh1'])) $where['a.Sczl_bh1'] = $req['Sczl_bh1'];
  96. if (isset($req['order']) && !empty($req['order'])) $where['a.Sczl_gdbh'] = $req['order'];
  97. $rows = db()->table('db_拉料计件')->alias('a')
  98. ->join('dic_lzde b','a.Sczl_dedh = b.sys_bh','left')
  99. ->field('rtrim(a.sczl_Type) as sczl_Type, LEFT(a.Sczl_rq, 10) as Sczl_rq, a.Sczl_bh1, a.sczl_gdbh, CAST(a.Sczl_cl AS SIGNED) as Sczl_cl,
  100. rtrim(a.Sczl_desc) as Sczl_desc, rtrim(a.Sczl_gxmc) as Sczl_gxmc, a.sczl_yjno, a.sczl_gxh, rtrim(a.sys_id) as sys_id, a.sys_rq, a.mod_rq, a.UniqId,b.sys_bh,rtrim(sys_mc) as sys_mc')
  101. ->where($where)
  102. ->page($page,$limit)
  103. ->order('a.Sczl_rq asc, a.UniqId asc')
  104. ->select();
  105. $total = db()->table('db_拉料计件')->alias('a')
  106. ->join('dic_lzde b','a.Sczl_dedh = b.sys_bh','left')
  107. ->where($where)->count();
  108. $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
  109. $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
  110. foreach ($rows as $key=>$value) {
  111. $rows[$key]['mod_rq'] = $value['mod_rq']=='1900-01-01 00:00:00' ? '' :$value['mod_rq'];
  112. $rows[$key]['Gd_cpmc'] = array_key_exists($value['sczl_gdbh'],$gd) ? trim($gd[$value['sczl_gdbh']]) : '';
  113. $rows[$key]['name'] = array_key_exists($value['Sczl_bh1'],$rs) ? trim($rs[$value['Sczl_bh1']]) : '';
  114. }
  115. $data = [
  116. 'total' => $total,
  117. 'rows' => $rows,
  118. ];
  119. $this->success('成功',$data);
  120. }
  121. /**
  122. * 获取其他计件单据信息
  123. * @ApiMethod (GET)
  124. * @param string $UniqId UniqId
  125. */
  126. public function getInfo()
  127. {
  128. //get请求
  129. if(!$this->request->isGet()){
  130. $this->error('请求方式错误');
  131. }
  132. $req = $this->request->param();
  133. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  134. $UniqId = $req['UniqId'];
  135. }else{
  136. $this->error('参数错误');
  137. }
  138. $rows = db()->table('db_拉料计件')->alias('a')
  139. ->field('a.*,rtrim(d.员工姓名) as name,rtrim(c.sys_mc) as sys_mc,rtrim(b.成品名称) as product_name')
  140. ->join('人事_基本资料 d', 'a.Sczl_bh1 = d.员工编号','left')
  141. ->join('工单_基本资料 b', 'a.Sczl_gdbh = b.Gd_gdbh','left')
  142. ->join('dic_lzde c', 'a.Sczl_dedh = c.sys_bh','left')
  143. ->where('a.UniqId',$UniqId)
  144. ->select();
  145. $this->success('成功',$rows);
  146. }
  147. /**
  148. * 查询印件工序及产品名称
  149. * @ApiMethod (GET)
  150. * @param string $gdbh 工单编号
  151. * @param string $gxmc 工序名称
  152. */
  153. public function getGxMc()
  154. {
  155. //get请求
  156. if(!$this->request->isGet()){
  157. $this->error('请求方式错误');
  158. }
  159. $req = $this->request->param();
  160. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  161. $gdbh = $req['gdbh'];
  162. }else{
  163. $this->error('参数错误');
  164. }
  165. if (isset($req['keyword']) && !empty($req['keyword'])){
  166. $keyword = $req['keyword'];
  167. }else{
  168. $keyword = '';
  169. }
  170. $rows = db()->table('工单_印件资料')->alias('g')
  171. ->field('rtrim(g.yj_yjmc) as Gd_cpmc, g.yj_Yjno as Gy0_yjno, c.Gy0_gxh, rtrim(c.Gy0_gxmc) as Gy0_gxmc, rtrim(c.Add_gxmc) as Add_gxmc')
  172. ->where(['g.Yj_Gdbh' => $gdbh])
  173. ->where(function ($query) use ($keyword) {
  174. $query->where(function ($query) use ($keyword) {
  175. $query->where('c.Gy0_yjno', 'like', '%' . $keyword . '%')
  176. ->whereOr('c.Gy0_gxh', 'like', '%' . $keyword . '%')
  177. ->whereOr('c.Add_gxmc', 'like', '%' . $keyword . '%');
  178. });
  179. $query->whereOr(function ($query) use ($keyword) {
  180. $query->where('c.Add_gxmc', '=', '')
  181. ->where(function ($query) use ($keyword) {
  182. $query->where('c.Gy0_yjno', 'like', '%' . $keyword . '%')
  183. ->whereOr('c.Gy0_gxh', 'like', '%' . $keyword . '%')
  184. ->whereOr('c.Gy0_gxmc', 'like', '%' . $keyword . '%');
  185. });
  186. });
  187. })
  188. ->join(['工单_工艺资料'=>'c'],'c.Gy0_gdbh=g.Yj_Gdbh and g.yj_Yjno=c.Gy0_yjno')
  189. ->select();
  190. foreach ($rows as $key=>$value){
  191. if($value['Add_gxmc'] != ''){
  192. $rows[$key]['jyGx'] = sprintf("%02d", $value['Gy0_yjno']).'-'.sprintf("%02d", $value['Gy0_gxh']).'-'.$value['Add_gxmc'];
  193. }else{
  194. $rows[$key]['jyGx'] = sprintf("%02d", $value['Gy0_yjno']).'-'.sprintf("%02d", $value['Gy0_gxh']).'-'.$value['Gy0_gxmc'];
  195. }
  196. }
  197. $this->success('成功',$rows);
  198. }
  199. /**
  200. * 查询定额代号
  201. * @ApiMethod (GET)
  202. */
  203. public function getDedh()
  204. {
  205. //get请求
  206. if(!$this->request->isGet()){
  207. $this->error('请求方式错误');
  208. }
  209. $row = db('dic_lzde')
  210. ->field('Key_, sys_bh, rtrim(sys_mc) as sys_mc')
  211. ->where('sys_mc','包装')
  212. ->find();
  213. $rows = db('dic_lzde')
  214. ->field('Key_, sys_bh, rtrim(sys_mc) as sys_mc')
  215. ->where('Parent',$row['Key_'])
  216. ->order('sys_bh asc')
  217. ->select();
  218. foreach ($rows as $key=>$value){
  219. $bool = db('dic_lzde')
  220. ->field('Key_,sys_bh, rtrim(sys_mc) as sys_mc')
  221. ->where('Parent',$value['Key_'])
  222. ->order('sys_bh asc')
  223. ->select();
  224. if ($bool){
  225. foreach ($bool as $k=>$v){
  226. $bool1 = db('dic_lzde')
  227. ->field('sys_bh, rtrim(sys_mc) as sys_mc')
  228. ->where('Parent',$v['Key_'])
  229. ->order('sys_bh asc')
  230. ->select();
  231. if ($bool1){
  232. $bool[$k]['bh_mc'] = $bool1;
  233. }
  234. }
  235. $rows[$key]['bh_mc'] = $bool;
  236. }
  237. }
  238. $row['bh_mc'] = $rows;
  239. $this->success('成功',$row);
  240. }
  241. /**
  242. * 新增
  243. * @ApiMethod (POST)
  244. * @param string
  245. */
  246. public function add()
  247. {
  248. if(!$this->request->isPost()){
  249. $this->error('请求方式错误');
  250. }
  251. $req = $this->request->param();
  252. $arr = [
  253. 'Sys_id',
  254. 'Sczl_bh1',
  255. 'sczl_Type',
  256. 'Sczl_rq',
  257. 'Sczl_gdbh',
  258. 'Sczl_gxmc',
  259. 'sczl_gxh',
  260. 'Sczl_cl',
  261. 'Sczl_dedh',
  262. 'Sczl_desc',
  263. ];
  264. $data = [];
  265. foreach ($arr as $key => $value){
  266. if (!isset($req[$value])){
  267. $this->error('参数错误',$value,$key+1);
  268. }
  269. $data[$value] = $req[$value];
  270. }
  271. $data['Sys_rq'] = date('Y-m-d H:i:s');
  272. //查询UniqId
  273. $UniqId = db()->table('db_拉料计件')->max('UniqId');
  274. $data['UniqId'] = $UniqId+1;
  275. //开启事务
  276. db()->startTrans();
  277. try{
  278. $sql = db()->table('db_拉料计件')->fetchSql(true)->insert($data);
  279. $bool = db()->query($sql);
  280. // 提交事务
  281. db()->commit();
  282. } catch (\Exception $e) {
  283. // 回滚事务
  284. db()->rollback();
  285. $this->error($e->getMessage());
  286. }
  287. if($bool===false) $this->error('失败');
  288. $this->success('成功');
  289. }
  290. /**
  291. * 拉料计件产量维护修改
  292. * @ApiMethod POST
  293. * @params array data
  294. */
  295. public function edit(){
  296. if (Request::instance()->isPost() == false){
  297. $this->error('非法请求');
  298. }
  299. $params = Request::instance()->post();
  300. if (!isset($params) || !isset($params['UniqId'])){
  301. $this->error('参数不能为空');
  302. }
  303. $uniqId = $params['UniqId'];
  304. unset($params['UniqId']);
  305. $sql = Db::name('db_拉料计件')->where('UniqId',$uniqId)->fetchSql(true)->update($params);
  306. $res = Db::query($sql);
  307. if ($res !== false){
  308. $this->success('更新成功');
  309. }else{
  310. $this->error('更新失败');
  311. }
  312. }
  313. /**
  314. * 修改
  315. * @ApiMethod (POST)
  316. * @param string 'UniqId'
  317. */
  318. public function del()
  319. {
  320. if(!$this->request->isPost()){
  321. $this->error('请求方式错误');
  322. }
  323. $req = $this->request->param();
  324. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  325. $this->error('参数错误','UniqId',100);
  326. }
  327. //开启事务
  328. db()->startTrans();
  329. try{
  330. $bool = db()->table('db_拉料计件')->where('UniqId',$req['UniqId'])->delete();
  331. // 提交事务
  332. db()->commit();
  333. } catch (\Exception $e) {
  334. // 回滚事务
  335. db()->rollback();
  336. $this->error($e->getMessage());
  337. }
  338. if($bool===false) $this->error('失败');
  339. $this->success('成功');
  340. }
  341. }