OtherCountDocument.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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['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['Sczl_bh1'] = $req['Sczl_bh1'];
  96. if (isset($req['order']) && !empty($req['order'])) $where['Sczl_gdbh'] = $req['order'];
  97. $rows = db()->table('db_拉料计件')
  98. ->field('rtrim(sczl_Type) as sczl_Type, LEFT(Sczl_rq, 10) as Sczl_rq, Sczl_bh1, sczl_gdbh, CAST(Sczl_cl AS SIGNED) as Sczl_cl,
  99. rtrim(Sczl_desc) as Sczl_desc, rtrim(Sczl_gxmc) as Sczl_gxmc, sczl_yjno, sczl_gxh, rtrim(sys_id) as sys_id, sys_rq, mod_rq, UniqId')
  100. ->where($where)
  101. ->page($page,$limit)
  102. ->order('Sczl_rq asc, UniqId asc')
  103. ->select();
  104. $total = db()->table('db_拉料计件')->where($where)->count();
  105. $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
  106. $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
  107. foreach ($rows as $key=>$value) {
  108. $rows[$key]['mod_rq'] = $value['mod_rq']=='1900-01-01 00:00:00' ? '' :$value['mod_rq'];
  109. $rows[$key]['Gd_cpmc'] = array_key_exists($value['sczl_gdbh'],$gd) ? trim($gd[$value['sczl_gdbh']]) : '';
  110. $rows[$key]['name'] = array_key_exists($value['Sczl_bh1'],$rs) ? trim($rs[$value['Sczl_bh1']]) : '';
  111. }
  112. $data = [
  113. 'total' => $total,
  114. 'rows' => $rows,
  115. ];
  116. $this->success('成功',$data);
  117. }
  118. /**
  119. * 获取其他计件单据信息
  120. * @ApiMethod (GET)
  121. * @param string $UniqId UniqId
  122. */
  123. public function getInfo()
  124. {
  125. //get请求
  126. if(!$this->request->isGet()){
  127. $this->error('请求方式错误');
  128. }
  129. $req = $this->request->param();
  130. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  131. $UniqId = $req['UniqId'];
  132. }else{
  133. $this->error('参数错误');
  134. }
  135. $rows = db()->table('db_拉料计件')->alias('d')
  136. ->field('d.*, ')
  137. ->join('工单_基本资料 g', 'd.')
  138. ->where('d.UniqId',$UniqId)
  139. ->select();
  140. $this->success('成功',$rows);
  141. }
  142. /**
  143. * 拉料计件产量维护修改
  144. * @ApiMethod POST
  145. * @params array data
  146. */
  147. public function edit(){
  148. if (Request::instance()->isPost() == false){
  149. $this->error('非法请求');
  150. }
  151. $params = Request::instance()->post();
  152. if (!isset($params) || !isset($params['UniqId'])){
  153. $this->error('参数不能为空');
  154. }
  155. $uniqId = $params['UniqId'];
  156. unset($params['UniqId']);
  157. $sql = Db::name('db_拉料计件')->where('UniqId',$uniqId)->fetchSql(true)->update($params);
  158. $res = Db::query($sql);
  159. if ($res !== false){
  160. $this->success('更新成功');
  161. }else{
  162. $this->error('更新失败');
  163. }
  164. }
  165. /**
  166. * 获取拉料计件产量维护其他信息
  167. * @ApiMethod GET
  168. * @params string Sczl_bh1
  169. * @params string Sczl_gdbh
  170. * @params string Sczl_dedh
  171. */
  172. public function getOtherInfo(){
  173. if (Request::instance()->isGet() == false){
  174. $this->error('非法请求');
  175. }
  176. $params = Request::instance()->param();
  177. if (empty($params['Sczl_bh1']) && empty($params['Sczl_gdbh']) && empty($params['Sczl_dedh']) ){
  178. $this->error('参数错误');
  179. }
  180. $data = [];
  181. if (!empty($params['Sczl_bh1'])){
  182. $data = Db::name('人事_基本资料')->where('员工编号',$params['Sczl_bh1'])->field('rtrim(员工姓名) as name')->find();
  183. }
  184. if (!empty($params['Sczl_gdbh'])){
  185. $data = Db::name('工单_基本资料')->where('Gd_gdbh',$params['Sczl_gdbh'])->field('rtrim(成品名称) as name')->find();
  186. }
  187. if (!empty($params['Sczl_dedh'])){
  188. $data = Db::name('dic_lzde')->where('sys_bh',$params['Sczl_dedh'])->field('rtrim(sys_mc) as name')->find();
  189. }
  190. $this->success('请求成功',$data);
  191. }
  192. }