OtherCountDocument.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 POST
  150. * @params array data
  151. */
  152. public function edit(){
  153. if (Request::instance()->isPost() == false){
  154. $this->error('非法请求');
  155. }
  156. $params = Request::instance()->post();
  157. if (!isset($params) || !isset($params['UniqId'])){
  158. $this->error('参数不能为空');
  159. }
  160. $uniqId = $params['UniqId'];
  161. unset($params['UniqId']);
  162. $sql = Db::name('db_拉料计件')->where('UniqId',$uniqId)->fetchSql(true)->update($params);
  163. $res = Db::query($sql);
  164. if ($res !== false){
  165. $this->success('更新成功');
  166. }else{
  167. $this->error('更新失败');
  168. }
  169. }
  170. /**
  171. * 获取拉料计件产量维护其他信息
  172. * @ApiMethod GET
  173. * @params string Sczl_bh1
  174. * @params string Sczl_gdbh
  175. * @params string Sczl_dedh
  176. */
  177. public function getOtherInfo(){
  178. if (Request::instance()->isGet() == false){
  179. $this->error('非法请求');
  180. }
  181. $params = Request::instance()->param();
  182. if (empty($params['Sczl_bh1']) && empty($params['Sczl_gdbh']) && empty($params['Sczl_dedh']) ){
  183. $this->error('参数错误');
  184. }
  185. $data = [];
  186. if (!empty($params['Sczl_bh1'])){
  187. $data = Db::name('人事_基本资料')->where('员工编号',$params['Sczl_bh1'])->field('rtrim(员工姓名) as name')->find();
  188. }
  189. if (!empty($params['Sczl_gdbh'])){
  190. $data = Db::name('工单_基本资料')->where('Gd_gdbh',$params['Sczl_gdbh'])->field('rtrim(成品名称) as name')->find();
  191. }
  192. if (!empty($params['Sczl_dedh'])){
  193. $data = Db::name('dic_lzde')->where('sys_bh',$params['Sczl_dedh'])->field('rtrim(sys_mc) as name')->find();
  194. }
  195. $this->success('请求成功',$data);
  196. }
  197. }