OtherCountDocument.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. * @param string
  151. */
  152. public function add()
  153. {
  154. if(!$this->request->isPost()){
  155. $this->error('请求方式错误');
  156. }
  157. $req = $this->request->param();
  158. $arr = [
  159. 'Sys_id',
  160. 'Sczl_bh1',
  161. 'sczl_Type',
  162. 'Sczl_rq',
  163. 'Sczl_gdbh',
  164. 'Sczl_gxmc',
  165. 'sczl_gxh',
  166. 'Sczl_cl',
  167. 'Sczl_dedh',
  168. 'Sczl_desc',
  169. ];
  170. $data = [];
  171. foreach ($arr as $key => $value){
  172. if (!isset($req[$value])){
  173. $this->error('参数错误',$value,$key+1);
  174. }
  175. $data[$value] = $req[$value];
  176. }
  177. $data['Sys_rq'] = date('Y-m-d H:i:s');
  178. //查询UniqId
  179. $UniqId = db()->table('db_拉料计件')->max('UniqId');
  180. $data['UniqId'] = $UniqId+1;
  181. //开启事务
  182. db()->startTrans();
  183. try{
  184. $sql = db()->table('db_拉料计件')->fetchSql(true)->insert($data);
  185. $bool = db()->query($sql);
  186. // 提交事务
  187. db()->commit();
  188. } catch (\Exception $e) {
  189. // 回滚事务
  190. db()->rollback();
  191. $this->error($e->getMessage());
  192. }
  193. if($bool===false) $this->error('失败');
  194. $this->success('成功');
  195. }
  196. /**
  197. * 拉料计件产量维护修改
  198. * @ApiMethod POST
  199. * @params array data
  200. */
  201. public function edit(){
  202. if (Request::instance()->isPost() == false){
  203. $this->error('非法请求');
  204. }
  205. $params = Request::instance()->post();
  206. if (!isset($params) || !isset($params['UniqId'])){
  207. $this->error('参数不能为空');
  208. }
  209. $uniqId = $params['UniqId'];
  210. unset($params['UniqId']);
  211. $sql = Db::name('db_拉料计件')->where('UniqId',$uniqId)->fetchSql(true)->update($params);
  212. $res = Db::query($sql);
  213. if ($res !== false){
  214. $this->success('更新成功');
  215. }else{
  216. $this->error('更新失败');
  217. }
  218. }
  219. /**
  220. * 修改
  221. * @ApiMethod (POST)
  222. * @param string 'UniqId'
  223. */
  224. public function del()
  225. {
  226. if(!$this->request->isPost()){
  227. $this->error('请求方式错误');
  228. }
  229. $req = $this->request->param();
  230. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  231. $this->error('参数错误','UniqId',100);
  232. }
  233. //开启事务
  234. db()->startTrans();
  235. try{
  236. $bool = db()->table('db_拉料计件')->where('UniqId',$req['UniqId'])->delete();
  237. // 提交事务
  238. db()->commit();
  239. } catch (\Exception $e) {
  240. // 回滚事务
  241. db()->rollback();
  242. $this->error($e->getMessage());
  243. }
  244. if($bool===false) $this->error('失败');
  245. $this->success('成功');
  246. }
  247. }