OtherCountDocument.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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.Gd_cpmc) as Gd_cpmc, c.Gy0_yjno, c.Gy0_gxh, rtrim(c.Gy0_gxmc) as Gy0_gxmc, rtrim(c.Add_gxmc) as Add_gxmc')
  172. ->where(['g.Gd_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(['产品_印件资料' => 'j'], 'g.Gd_cpdh=j.yj_yjdh and g.成品代号=j.yj_cpdh')
  189. ->join(['工单_工艺资料' => 'c'], 'c.Gy0_gdbh=g.Gd_gdbh and c.Gy0_yjno=j.yj_yjno')
  190. ->select();
  191. foreach ($rows as $key=>$value){
  192. if($value['Add_gxmc'] != ''){
  193. $rows[$key]['jyGx'] = sprintf("%02d", $value['Gy0_yjno']).'-'.sprintf("%02d", $value['Gy0_gxh']).'-'.$value['Add_gxmc'];
  194. }else{
  195. $rows[$key]['jyGx'] = sprintf("%02d", $value['Gy0_yjno']).'-'.sprintf("%02d", $value['Gy0_gxh']).'-'.$value['Gy0_gxmc'];
  196. }
  197. }
  198. $this->success('成功',$rows);
  199. }
  200. /**
  201. * 查询定额代号
  202. * @ApiMethod (GET)
  203. */
  204. public function getDedh()
  205. {
  206. //get请求
  207. if(!$this->request->isGet()){
  208. $this->error('请求方式错误');
  209. }
  210. $row = db('dic_lzde')
  211. ->field('Key_, sys_bh, rtrim(sys_mc) as sys_mc')
  212. ->where('sys_mc','包装')
  213. ->find();
  214. $rows = db('dic_lzde')
  215. ->field('Key_, sys_bh, rtrim(sys_mc) as sys_mc')
  216. ->where('Parent',$row['Key_'])
  217. ->order('sys_bh asc')
  218. ->select();
  219. foreach ($rows as $key=>$value){
  220. $bool = db('dic_lzde')
  221. ->field('Key_,sys_bh, rtrim(sys_mc) as sys_mc')
  222. ->where('Parent',$value['Key_'])
  223. ->order('sys_bh asc')
  224. ->select();
  225. if ($bool){
  226. foreach ($bool as $k=>$v){
  227. $bool1 = db('dic_lzde')
  228. ->field('sys_bh, rtrim(sys_mc) as sys_mc')
  229. ->where('Parent',$v['Key_'])
  230. ->order('sys_bh asc')
  231. ->select();
  232. if ($bool1){
  233. $bool[$k]['bh_mc'] = $bool1;
  234. }
  235. }
  236. $rows[$key]['bh_mc'] = $bool;
  237. }
  238. }
  239. $row['bh_mc'] = $rows;
  240. $this->success('成功',$row);
  241. }
  242. /**
  243. * 新增
  244. * @ApiMethod (POST)
  245. * @param string
  246. */
  247. public function add()
  248. {
  249. if(!$this->request->isPost()){
  250. $this->error('请求方式错误');
  251. }
  252. $req = $this->request->param();
  253. $arr = [
  254. 'Sys_id',
  255. 'Sczl_bh1',
  256. 'sczl_Type',
  257. 'Sczl_rq',
  258. 'Sczl_gdbh',
  259. 'Sczl_gxmc',
  260. 'sczl_gxh',
  261. 'Sczl_cl',
  262. 'Sczl_dedh',
  263. 'Sczl_desc',
  264. ];
  265. $data = [];
  266. foreach ($arr as $key => $value){
  267. if (!isset($req[$value])){
  268. $this->error('参数错误',$value,$key+1);
  269. }
  270. $data[$value] = $req[$value];
  271. }
  272. $data['Sys_rq'] = date('Y-m-d H:i:s');
  273. //查询UniqId
  274. $UniqId = db()->table('db_拉料计件')->max('UniqId');
  275. $data['UniqId'] = $UniqId+1;
  276. //开启事务
  277. db()->startTrans();
  278. try{
  279. $sql = db()->table('db_拉料计件')->fetchSql(true)->insert($data);
  280. $bool = db()->query($sql);
  281. // 提交事务
  282. db()->commit();
  283. } catch (\Exception $e) {
  284. // 回滚事务
  285. db()->rollback();
  286. $this->error($e->getMessage());
  287. }
  288. if($bool===false) $this->error('失败');
  289. $this->success('成功');
  290. }
  291. /**
  292. * 拉料计件产量维护修改
  293. * @ApiMethod POST
  294. * @params array data
  295. */
  296. public function edit(){
  297. if (Request::instance()->isPost() == false){
  298. $this->error('非法请求');
  299. }
  300. $params = Request::instance()->post();
  301. if (!isset($params) || !isset($params['UniqId'])){
  302. $this->error('参数不能为空');
  303. }
  304. $uniqId = $params['UniqId'];
  305. unset($params['UniqId']);
  306. $sql = Db::name('db_拉料计件')->where('UniqId',$uniqId)->fetchSql(true)->update($params);
  307. $res = Db::query($sql);
  308. if ($res !== false){
  309. $this->success('更新成功');
  310. }else{
  311. $this->error('更新失败');
  312. }
  313. }
  314. /**
  315. * 修改
  316. * @ApiMethod (POST)
  317. * @param string 'UniqId'
  318. */
  319. public function del()
  320. {
  321. if(!$this->request->isPost()){
  322. $this->error('请求方式错误');
  323. }
  324. $req = $this->request->param();
  325. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  326. $this->error('参数错误','UniqId',100);
  327. }
  328. //开启事务
  329. db()->startTrans();
  330. try{
  331. $bool = db()->table('db_拉料计件')->where('UniqId',$req['UniqId'])->delete();
  332. // 提交事务
  333. db()->commit();
  334. } catch (\Exception $e) {
  335. // 回滚事务
  336. db()->rollback();
  337. $this->error($e->getMessage());
  338. }
  339. if($bool===false) $this->error('失败');
  340. $this->success('成功');
  341. }
  342. }