Inspect.php 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  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 Inspect 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. *
  24. * @ApiMethod GET
  25. */
  26. public function getInspectCount(){
  27. if (Request::instance()->isGet() == false){
  28. $this->error('非法请求');
  29. }
  30. $sql = 'SELECT DISTINCT DATE(sys_rq) AS sys_rq FROM `db_手工检验` ORDER BY sys_rq DESC LIMIT 30 ';
  31. $list = Db::query($sql);
  32. foreach ($list as $key => $value){
  33. $where = [$value['sys_rq'].'00:00:00',$value['sys_rq'].'24:00:00'];
  34. $dataCount = db()->table('db_手工检验')->where('sys_rq','between time',$where)->field('rtrim(sys_id) as sys_id')->order('sys_id asc')->select();
  35. $list[$key]['count'] = count($dataCount);
  36. // 提取 sys_id 列成新数组
  37. $sysIds = array_column($dataCount, 'sys_id');
  38. //统计每个不同的 sys_id 的数量
  39. $counts = array_count_values($sysIds);
  40. $i = 0;
  41. foreach ($counts as $k=>$v){
  42. $list[$key]['sys'][$i]['sys_id'] = $k;
  43. $list[$key]['sys'][$i]['count'] = $v;
  44. $i++;
  45. }
  46. }
  47. $this->success('请求成功',$list);
  48. }
  49. /**
  50. * 获取手工检验左侧菜单栏
  51. * 通过工单
  52. * @ApiMethod GET
  53. */
  54. public function getInspectCountByGdbh(){
  55. if (Request::instance()->isGet() == false){
  56. $this->error('非法请求');
  57. }
  58. $sql = 'SELECT DISTINCT sczl_gdbh FROM `db_手工检验` ORDER BY sczl_gdbh DESC LIMIT 65 ';
  59. $list = Db::query($sql);
  60. foreach ($list as $key => $value){
  61. $dataCount = db()->table('db_手工检验')->alias('d')
  62. ->where('sczl_gdbh',$value['sczl_gdbh'])
  63. ->where('SUBSTR(d.sczl_yjgx,1,2) = g.yj_Yjno')
  64. ->field('rtrim(d.sys_id) as sys_id, rtrim(g.yj_yjmc) as yj_yjmc')
  65. ->join(['工单_印件资料'=>'g'],'d.sczl_gdbh=g.Yj_Gdbh')
  66. ->order('sys_id asc')
  67. ->select();
  68. $list[$key]['cpmc'] = $dataCount[0]['yj_yjmc'];
  69. // 提取 sys_id 列成新数组
  70. $sysIds = array_column($dataCount, 'sys_id');
  71. //统计每个不同的 sys_id 的数量
  72. $counts = array_count_values($sysIds);
  73. $i = 0;
  74. foreach ($counts as $k=>$v){
  75. $list[$key]['sys'][$i]['sys_id'] = $k;
  76. $list[$key]['sys'][$i]['count'] = $v;
  77. $i++;
  78. }
  79. }
  80. $this->success('请求成功',$list);
  81. }
  82. /**
  83. * 获取某个日期手工单据
  84. *
  85. * @ApiMethod GET
  86. * @params string date
  87. */
  88. public function getDateList(){
  89. if (Request::instance()->isGet() == false){
  90. $this->error('非法请求');
  91. }
  92. $params = Request::instance()->param();
  93. if (!isset($params['date']) || empty($params['date'])) $this->error('参数缺失');
  94. $page = 1;
  95. $limit = 15;
  96. if (isset($params['page']) && !empty($params['page'])) $page = $params['page'];
  97. if (isset($params['limit']) && !empty($params['limit'])) $limit = $params['limit'];
  98. if(strpos($params['date'],'-')){
  99. $where = ['a.sys_rq'=>['like','%'.$params['date'].'%']];
  100. $option = ['sys_rq'=>['like','%'.$params['date'].'%']];
  101. }else{
  102. $where = ['a.sczl_gdbh'=>$params['date']];
  103. $option = ['sczl_gdbh'=>$params['date']];
  104. }
  105. if (isset($params['sys_id']) && !empty($params['sys_id'])){
  106. $where['a.sys_id'] = ['LIKE','%'.$params['sys_id'].'%'];
  107. $option['sys_id'] = ['LIKE','%'.$params['sys_id'].'%'];
  108. }
  109. $field = 'a.sczl_gdbh,a.sczl_yjgx,rtrim(a.sczl_gxmc) as sczl_gxmc,DATE(a.sczl_rq) as sczl_rq,a.sczl_cl,a.sczl_dedh,a.sczl_废品率系数,a.sczl_检验类别,a.sczl_bh0,
  110. rtrim(a.qczl_NumDesc) as qczl_NumDesc,rtrim(a.sys_id) as sys_id,a.sys_rq,a.mod_rq,a.UniqId,b.千件工价,b.日定额,rtrim(c.员工姓名) as 员工姓名,rtrim(d.yj_yjmc) as yj_yjmc';
  111. $list = db()->table('db_手工检验')->alias('a')
  112. ->join('dic_lzde b','a.sczl_dedh = b.sys_bh','left')
  113. ->join('人事_基本资料 c','a.sczl_bh0 = c.员工编号','left')
  114. ->join('工单_印件资料 d','a.sczl_gdbh = d.Yj_Gdbh','left')
  115. ->where($where)
  116. ->where('SUBSTR(a.sczl_yjgx,1,2) = d.yj_Yjno')
  117. ->field($field)->page($page,$limit)->order('a.sczl_rq,a.UniqId asc')->select();
  118. $count = db()->table('db_手工检验')->where($option)->count();
  119. $data['data'] = $list;
  120. $data['total'] = $count;
  121. $this->success('请求成功',$data);
  122. }
  123. /**
  124. * 获取机器检验左侧菜单栏
  125. *
  126. * @ApiMethod GET
  127. */
  128. public function getMachineCount(){
  129. if (Request::instance()->isGet() == false){
  130. $this->error('非法请求');
  131. }
  132. $sql = 'SELECT DISTINCT DATE(sys_rq) AS sys_rq FROM `db_机器检验` ORDER BY sys_rq DESC LIMIT 30 ';
  133. $list = Db::query($sql);
  134. foreach ($list as $key => $value){
  135. $where = [$value['sys_rq'].'00:00:00',$value['sys_rq'].'24:00:00'];
  136. $dataCount = db()->table('db_机器检验')->where('sys_rq','between time',$where)->field('rtrim(sys_id) as sys_id')->order('sys_id asc')->select();
  137. $list[$key]['count'] = count($dataCount);
  138. // 提取 sys_id 列成新数组
  139. $sysIds = array_column($dataCount, 'sys_id');
  140. //统计每个不同的 sys_id 的数量
  141. $counts = array_count_values($sysIds);
  142. $i = 0;
  143. foreach ($counts as $k=>$v){
  144. $list[$key]['sys'][$i]['sys_id'] = $k;
  145. $list[$key]['sys'][$i]['count'] = $v;
  146. $i++;
  147. }
  148. }
  149. $this->success('请求成功',$list);
  150. }
  151. /**
  152. * 获取某个日期机器单据
  153. *
  154. * @ApiMethod GET
  155. * @params string date
  156. */
  157. public function getDateMachine(){
  158. if (Request::instance()->isGet() == false){
  159. $this->error('非法请求');
  160. }
  161. $params = Request::instance()->param();
  162. if (!isset($params['date']) || empty($params['date'])) $this->error('参数缺失');
  163. $page = 1;
  164. $limit = 15;
  165. if (isset($params['page']) && !empty($params['page'])) $page = $params['page'];
  166. if (isset($params['limit']) && !empty($params['limit'])) $limit = $params['limit'];
  167. if(strpos($params['date'],'-')){
  168. $where = ['a.sys_rq'=>['like','%'.$params['date'].'%']];
  169. $option = ['sys_rq'=>['like','%'.$params['date'].'%']];
  170. }else{
  171. $where = ['a.sczl_gdbh'=>$params['date']];
  172. $option = ['sczl_gdbh'=>$params['date']];
  173. }
  174. if (isset($params['sys_id']) && !empty($params['sys_id'])){
  175. $where['a.sys_id'] = ['LIKE','%'.$params['sys_id'].'%'];
  176. $option['sys_id'] = ['LIKE','%'.$params['sys_id'].'%'];
  177. }
  178. $field = 'a.sczl_gdbh,trim(a.sczl_yjgx) as sczl_yjgx,rtrim(a.sczl_gxmc) as sczl_gxmc,a.sczl_jtbh,a.sczl_bzdh,DATE(a.sczl_rq) as sczl_rq,a.sczl_cl,rtrim(a.sczl_单据类型) as sczl_单据类型,
  179. a.sczl_设备运行工时,a.sczl_dedh,a.sczl_废品率系数,rtrim(a.sczl_检验类别) as sczl_检验类别,a.sczl_bh1,a.sczl_bh2,a.sczl_bh3,a.sczl_bh4,a.qczl_NumDesc,rtrim(a.sys_id) as sys_id,
  180. a.sys_rq,a.mod_rq,a.UniqId,b.千件工价,b.日定额,rtrim(c1.员工姓名) as sczl_bh1_name,rtrim(c2.员工姓名) as sczl_bh2_name,rtrim(c3.员工姓名) as sczl_bh3_name,
  181. rtrim(c4.员工姓名) as sczl_bh4_name,rtrim(d.yj_yjmc) as yj_yjmc';
  182. $list = db()->table('db_机器检验')->alias('a')
  183. ->join('dic_lzde b','a.sczl_dedh = b.sys_bh','left')
  184. ->join('人事_基本资料 c1','a.sczl_bh1 = c1.员工编号','left')
  185. ->join('人事_基本资料 c2','a.sczl_bh2 = c2.员工编号','left')
  186. ->join('人事_基本资料 c3','a.sczl_bh3 = c3.员工编号','left')
  187. ->join('人事_基本资料 c4','a.sczl_bh4 = c4.员工编号','left')
  188. ->join('工单_印件资料 d','a.sczl_gdbh = d.Yj_Gdbh','left')
  189. ->where($where)
  190. ->where('SUBSTR(a.sczl_yjgx,1,2) = d.yj_Yjno')
  191. ->field($field)->page($page,$limit)->order('a.UniqId desc')->select();
  192. $count = db()->table('db_机器检验')->where($option)->count();
  193. $data['data'] = $list;
  194. $data['total'] = $count;
  195. $this->success('请求成功',$data);
  196. }
  197. /**
  198. * 定位
  199. * @ApiMethod (GET)
  200. * @param string $gdbh 工单编号
  201. * @param string $cpmc 产品名称
  202. * @param string $page 页码
  203. * @param string $limit 数量
  204. */
  205. public function locate()
  206. {
  207. //get请求
  208. if(!$this->request->isGet()){
  209. $this->error('请求方式错误');
  210. }
  211. $req = $this->request->param();
  212. $page = 1;
  213. $limit = 15;
  214. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  215. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  216. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  217. $where = [
  218. 'a.sczl_gdbh'=>[ 'like', '%' . $req['gdbh'] . '%']
  219. ];
  220. $field = 'a.sczl_gdbh,a.sczl_yjgx,rtrim(a.sczl_gxmc) as sczl_gxmc,DATE(a.sczl_rq) as sczl_rq,a.sczl_cl,a.sczl_dedh,a.sczl_废品率系数,a.sczl_检验类别,a.sczl_bh0,
  221. rtrim(a.qczl_NumDesc) as qczl_NumDesc,rtrim(a.sys_id) as sys_id,a.sys_rq,a.mod_rq,a.UniqId,b.千件工价,b.日定额,rtrim(c.员工姓名) as 员工姓名,rtrim(d.yj_yjmc) as yj_yjmc';
  222. $rows = db()->table('db_手工检验')->alias('a')
  223. ->join('dic_lzde b','a.sczl_dedh = b.sys_bh','left')
  224. ->join('人事_基本资料 c','a.sczl_bh0 = c.员工编号','left')
  225. ->join('工单_印件资料 d','a.sczl_gdbh = d.Yj_Gdbh','left')
  226. ->where($where)
  227. ->where('SUBSTR(a.sczl_yjgx,1,2) = d.yj_Yjno')
  228. ->field($field)->page($page,$limit)->order('a.sczl_rq,a.UniqId asc')->select();
  229. $option['sczl_gdbh'] = [ 'like', '%' . $req['gdbh'] . '%'];
  230. $total = db()->table('db_手工检验')->where($option)->count();
  231. }else{
  232. if (isset($req['cpmc']) && !empty($req['cpmc'])){
  233. //查询工单表
  234. $gd = db()->table('工单_基本资料')
  235. ->where('Gd_cpmc', 'LIKE', '%'.$req['cpmc'].'%')
  236. ->column('Gd_gdbh');
  237. $where = [
  238. 'a.sczl_gdbh'=>['in', $gd]
  239. ];
  240. $field = 'a.sczl_gdbh,a.sczl_yjgx,rtrim(a.sczl_gxmc) as sczl_gxmc,DATE(a.sczl_rq) as sczl_rq,a.sczl_cl,a.sczl_dedh,a.sczl_废品率系数,a.sczl_检验类别,a.sczl_bh0,
  241. rtrim(a.qczl_NumDesc) as qczl_NumDesc,rtrim(a.sys_id) as sys_id,a.sys_rq,a.mod_rq,a.UniqId,b.千件工价,b.日定额,rtrim(c.员工姓名) as 员工姓名,rtrim(d.yj_yjmc) as yj_yjmc';
  242. $rows = db()->table('db_手工检验')->alias('a')
  243. ->join('dic_lzde b','a.sczl_dedh = b.sys_bh','left')
  244. ->join('人事_基本资料 c','a.sczl_bh0 = c.员工编号','left')
  245. ->join('工单_印件资料 d','a.sczl_gdbh = d.Yj_Gdbh','left')
  246. ->where($where)
  247. ->where('SUBSTR(a.sczl_yjgx,1,2) = d.yj_Yjno')
  248. ->field($field)->page($page,$limit)->order('a.sczl_rq,a.UniqId asc')->select();
  249. $option['sczl_gdbh'] = ['in', $gd];
  250. $total = db()->table('db_手工检验')->where($option)->count();
  251. }else{
  252. $this->error('参数错误');
  253. }
  254. }
  255. $data = [
  256. 'total' => $total,
  257. 'rows' => $rows,
  258. ];
  259. $this->success('成功',$data);
  260. }
  261. /**
  262. * 定位
  263. * @ApiMethod (GET)
  264. * @param string $gdbh 工单编号
  265. * @param string $cpmc 产品名称
  266. * @param string $page 页码
  267. * @param string $limit 数量
  268. */
  269. public function machineLocate()
  270. {
  271. //get请求
  272. if(!$this->request->isGet()){
  273. $this->error('请求方式错误');
  274. }
  275. $req = $this->request->param();
  276. $page = 1;
  277. $limit = 15;
  278. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  279. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  280. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  281. $where = [
  282. 'sczl_gdbh'=>[ 'like', '%' . $req['gdbh'] . '%']
  283. ];
  284. $where['a.sczl_单据类型'] = '初检单';
  285. $field = 'a.sczl_gdbh,trim(a.sczl_yjgx) as sczl_yjgx,rtrim(a.sczl_gxmc) as sczl_gxmc,a.sczl_jtbh,a.sczl_bzdh,DATE(a.sczl_rq) as sczl_rq,a.sczl_cl,rtrim(a.sczl_单据类型) as sczl_单据类型,
  286. a.sczl_设备运行工时,a.sczl_dedh,a.sczl_废品率系数,rtrim(a.sczl_检验类别) as sczl_检验类别,a.sczl_bh1,a.sczl_bh2,a.sczl_bh3,a.sczl_bh4,a.qczl_NumDesc,rtrim(a.sys_id) as sys_id,
  287. a.sys_rq,a.mod_rq,a.UniqId,b.千件工价,b.日定额,rtrim(c1.员工姓名) as sczl_bh1_name,rtrim(c2.员工姓名) as sczl_bh2_name,rtrim(c3.员工姓名) as sczl_bh3_name,
  288. rtrim(c4.员工姓名) as sczl_bh4_name,rtrim(d.yj_yjmc) as yj_yjmc';
  289. $rows = db()->table('db_机器检验')->alias('a')
  290. ->join('dic_lzde b','a.sczl_dedh = b.sys_bh','left')
  291. ->join('人事_基本资料 c1','a.sczl_bh1 = c1.员工编号','left')
  292. ->join('人事_基本资料 c2','a.sczl_bh2 = c2.员工编号','left')
  293. ->join('人事_基本资料 c3','a.sczl_bh3 = c3.员工编号','left')
  294. ->join('人事_基本资料 c4','a.sczl_bh4 = c4.员工编号','left')
  295. ->join('工单_印件资料 d','a.sczl_gdbh = d.Yj_Gdbh','left')
  296. ->where($where)
  297. ->where('SUBSTR(a.sczl_yjgx,1,2) = d.yj_Yjno')
  298. ->field($field)->page($page,$limit)->order('a.sczl_rq asc,a.UniqId desc')->select();
  299. $option['sczl_单据类型'] = '初检单';
  300. $option['sczl_gdbh'] = [ 'like', '%' . $req['gdbh'] . '%'];
  301. $total = db()->table('db_机器检验')->where($option)->count();
  302. }else{
  303. if (isset($req['cpmc']) && !empty($req['cpmc'])){
  304. //查询工单表
  305. $gd = db()->table('工单_基本资料')
  306. ->where('Gd_cpmc', 'LIKE', '%'.$req['cpmc'].'%')
  307. ->column('Gd_gdbh');
  308. $where = [
  309. 'sczl_gdbh'=>['in', $gd]
  310. ];
  311. $where['a.sczl_单据类型'] = '初检单';
  312. $field = 'a.sczl_gdbh,trim(a.sczl_yjgx) as sczl_yjgx,rtrim(a.sczl_gxmc) as sczl_gxmc,a.sczl_jtbh,a.sczl_bzdh,DATE(a.sczl_rq) as sczl_rq,a.sczl_cl,rtrim(a.sczl_单据类型) as sczl_单据类型,
  313. a.sczl_设备运行工时,a.sczl_dedh,a.sczl_废品率系数,rtrim(a.sczl_检验类别) as sczl_检验类别,a.sczl_bh1,a.sczl_bh2,a.sczl_bh3,a.sczl_bh4,a.qczl_NumDesc,rtrim(a.sys_id) as sys_id,
  314. a.sys_rq,a.mod_rq,a.UniqId,b.千件工价,b.日定额,rtrim(c1.员工姓名) as sczl_bh1_name,rtrim(c2.员工姓名) as sczl_bh2_name,rtrim(c3.员工姓名) as sczl_bh3_name,
  315. rtrim(c4.员工姓名) as sczl_bh4_name,rtrim(d.yj_yjmc) as yj_yjmc';
  316. $rows = db()->table('db_机器检验')->alias('a')
  317. ->join('dic_lzde b','a.sczl_dedh = b.sys_bh','left')
  318. ->join('人事_基本资料 c1','a.sczl_bh1 = c1.员工编号','left')
  319. ->join('人事_基本资料 c2','a.sczl_bh2 = c2.员工编号','left')
  320. ->join('人事_基本资料 c3','a.sczl_bh3 = c3.员工编号','left')
  321. ->join('人事_基本资料 c4','a.sczl_bh4 = c4.员工编号','left')
  322. ->join('工单_印件资料 d','a.sczl_gdbh = d.Yj_Gdbh','left')
  323. ->where($where)
  324. ->where('SUBSTR(a.sczl_yjgx,1,2) = d.yj_Yjno')
  325. ->field($field)->page($page,$limit)->order('a.sczl_rq asc,a.UniqId desc')->select();
  326. $option['sczl_单据类型'] = '初检单';
  327. $option['sczl_gdbh'] = ['in', $gd];
  328. $total = db()->table('db_机器检验')->where($option)->count();
  329. }else{
  330. $this->error('参数错误');
  331. }
  332. }
  333. $data = [
  334. 'total' => $total,
  335. 'rows' => $rows,
  336. ];
  337. $this->success('成功',$data);
  338. }
  339. /**
  340. * 获取信息
  341. * @ApiMethod (GET)
  342. * @param string $UniqId UniqId
  343. */
  344. public function getInfo()
  345. {
  346. //get请求
  347. if(!$this->request->isGet()){
  348. $this->error('请求方式错误');
  349. }
  350. $req = $this->request->param();
  351. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  352. $UniqId = $req['UniqId'];
  353. }else{
  354. $this->error('参数错误');
  355. }
  356. $where['a.UniqId'] = $UniqId;
  357. $field = 'DATE(a.sczl_rq) as sczl_rq, a.sczl_bzdh,a.sczl_bh0, rtrim(c0.员工姓名) as sczl_bh0_name, a.sczl_cl0, a.sczl_fp0,
  358. a.sczl_gdbh,trim(a.sczl_yjgx) as sczl_yjgx,rtrim(a.sczl_gxmc) as sczl_gxmc,rtrim(d.yj_yjmc) as yj_yjmc,
  359. a.sczl_cl,rtrim(a.sczl_dedh) as sczl_dedh,rtrim(a.sczl_检验类别) as sczl_检验类别,a.sczl_废品率系数,
  360. a.sczl_jsss,a.sczl_冲定额,a.qczl_Num as 流程单号1,a.qczl_NumDesc1 as 流程单号2,a.qczl_NumDesc2 as 流程单号3,
  361. a.qczl_NumDesc3 as 流程单号4,a.qczl_NumDesc4 as 流程单号5,a.qczl_NumDesc5 as 流程单号6,
  362. a.qczl_NumDesc6 as 流程单号7,a.qczl_NumDesc7 as 流程单号8,a.qczl_NumDesc8 as 流程单号9,
  363. rtrim(a.qczl_NumDesc) as qczl_NumDesc,rtrim(a.sczl_desc) as sczl_desc,
  364. a.sczl_bh1,a.sczl_bh2,a.sczl_bh3,a.sczl_bh4,a.sczl_bh5, a.sczl_bh6,
  365. a.sczl_bh7,a.sczl_bh8,a.sczl_bh9,a.sczl_bh10,a.sczl_bh11, a.sczl_bh12,
  366. rtrim(c1.员工姓名) as sczl_bh1_name,rtrim(c2.员工姓名) as sczl_bh2_name,
  367. rtrim(c3.员工姓名) as sczl_bh3_name,rtrim(c4.员工姓名) as sczl_bh4_name,
  368. rtrim(c5.员工姓名) as sczl_bh5_name,rtrim(c6.员工姓名) as sczl_bh6_name,
  369. rtrim(c7.员工姓名) as sczl_bh7_name,rtrim(c8.员工姓名) as sczl_bh8_name,
  370. rtrim(c9.员工姓名) as sczl_bh9_name,rtrim(c10.员工姓名) as sczl_bh10_name,
  371. rtrim(c11.员工姓名) as sczl_bh11_name,rtrim(c12.员工姓名) as sczl_bh12_name,
  372. a.sczl_cl1,a.sczl_cl2,a.sczl_cl3,a.sczl_cl4,a.sczl_cl5,a.sczl_cl6,
  373. a.sczl_cl7,a.sczl_cl8,a.sczl_cl9,a.sczl_cl10,a.sczl_cl11,a.sczl_cl12,
  374. a.sczl_fp1,a.sczl_fp2,a.sczl_fp3,a.sczl_fp4,a.sczl_fp5,a.sczl_fp6,
  375. a.sczl_fp7,a.sczl_fp8,a.sczl_fp9,a.sczl_fp10,a.sczl_fp11,a.sczl_fp12';
  376. $rows = db()->table('db_手工检验')->alias('a')
  377. ->join('人事_基本资料 c0','a.sczl_bh0 = c0.员工编号','left')
  378. ->join('人事_基本资料 c1','a.sczl_bh1 = c1.员工编号','left')
  379. ->join('人事_基本资料 c2','a.sczl_bh2 = c2.员工编号','left')
  380. ->join('人事_基本资料 c3','a.sczl_bh3 = c3.员工编号','left')
  381. ->join('人事_基本资料 c4','a.sczl_bh4 = c4.员工编号','left')
  382. ->join('人事_基本资料 c5','a.sczl_bh5 = c5.员工编号','left')
  383. ->join('人事_基本资料 c6','a.sczl_bh6 = c6.员工编号','left')
  384. ->join('人事_基本资料 c7','a.sczl_bh7 = c7.员工编号','left')
  385. ->join('人事_基本资料 c8','a.sczl_bh8 = c8.员工编号','left')
  386. ->join('人事_基本资料 c9','a.sczl_bh9 = c9.员工编号','left')
  387. ->join('人事_基本资料 c10','a.sczl_bh10 = c10.员工编号','left')
  388. ->join('人事_基本资料 c11','a.sczl_bh11 = c11.员工编号','left')
  389. ->join('人事_基本资料 c12','a.sczl_bh12 = c12.员工编号','left')
  390. ->join('工单_印件资料 d','a.sczl_gdbh = d.Yj_Gdbh','left')
  391. ->where($where)
  392. ->where('SUBSTR(a.sczl_yjgx,1,2) = d.yj_Yjno')
  393. ->field($field)->find();
  394. $this->success('成功',$rows);
  395. }
  396. /**
  397. * 获取信息
  398. * @ApiMethod (GET)
  399. * @param string $UniqId UniqId
  400. */
  401. public function getMachineInfo()
  402. {
  403. //get请求
  404. if(!$this->request->isGet()){
  405. $this->error('请求方式错误');
  406. }
  407. $req = $this->request->param();
  408. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  409. $UniqId = $req['UniqId'];
  410. }else{
  411. $this->error('参数错误');
  412. }
  413. $where['a.UniqId'] = $UniqId;
  414. $field = 'a.sczl_gdbh,trim(a.sczl_yjgx) as sczl_yjgx,rtrim(a.sczl_gxmc) as sczl_gxmc,
  415. a.sczl_jtbh,a.sczl_bzdh,DATE(a.sczl_rq) as sczl_rq,a.sczl_cl,a.sczl_PgCl,
  416. rtrim(a.sczl_单据类型) as sczl_单据类型,rtrim(a.sczl_dedh) as sczl_dedh,
  417. a.sczl_装版工时,a.sczl_保养工时,a.sczl_异常停机工时,a.sczl_设备运行工时,
  418. a.sczl_废品率系数,rtrim(a.sczl_检验类别) as sczl_检验类别,
  419. a.sczl_bh1,a.sczl_bh2,a.sczl_bh3,a.sczl_bh4,a.sczl_bh5, a.sczl_bh6,a.sczl_bh7,a.sczl_bh8,
  420. a.qczl_Num as 流程单号1,a.qczl_NumDesc1 as 流程单号2,a.qczl_NumDesc2 as 流程单号3,
  421. a.qczl_NumDesc3 as 流程单号4,a.qczl_NumDesc4 as 流程单号5,a.qczl_NumDesc5 as 流程单号6,
  422. a.qczl_NumDesc6 as 流程单号7,a.qczl_NumDesc7 as 流程单号8,a.qczl_NumDesc8 as 流程单号9,
  423. a.qczl_NumDesc,a.sczl_desc,
  424. rtrim(c1.员工姓名) as sczl_bh1_name,rtrim(c2.员工姓名) as sczl_bh2_name,
  425. rtrim(c3.员工姓名) as sczl_bh3_name,rtrim(c4.员工姓名) as sczl_bh4_name,
  426. rtrim(c5.员工姓名) as sczl_bh5_name,rtrim(c6.员工姓名) as sczl_bh6_name,
  427. rtrim(c7.员工姓名) as sczl_bh7_name,rtrim(c8.员工姓名) as sczl_bh8_name,
  428. rtrim(d.yj_yjmc) as yj_yjmc';
  429. $rows = db()->table('db_机器检验')->alias('a')
  430. ->join('dic_lzde b','a.sczl_dedh = b.sys_bh','left')
  431. ->join('人事_基本资料 c1','a.sczl_bh1 = c1.员工编号','left')
  432. ->join('人事_基本资料 c2','a.sczl_bh2 = c2.员工编号','left')
  433. ->join('人事_基本资料 c3','a.sczl_bh3 = c3.员工编号','left')
  434. ->join('人事_基本资料 c4','a.sczl_bh4 = c4.员工编号','left')
  435. ->join('人事_基本资料 c5','a.sczl_bh5 = c5.员工编号','left')
  436. ->join('人事_基本资料 c6','a.sczl_bh6 = c6.员工编号','left')
  437. ->join('人事_基本资料 c7','a.sczl_bh7 = c7.员工编号','left')
  438. ->join('人事_基本资料 c8','a.sczl_bh8 = c8.员工编号','left')
  439. ->join('工单_印件资料 d','a.sczl_gdbh = d.Yj_Gdbh','left')
  440. ->where($where)
  441. ->where('SUBSTR(a.sczl_yjgx,1,2) = d.yj_Yjno')
  442. ->field($field)->find();
  443. $this->success('成功',$rows);
  444. }
  445. /**
  446. * 查询印件工序及产品名称
  447. * @ApiMethod (GET)
  448. * @param string $gdbh 工单编号
  449. * @param string $gxmc 工序名称
  450. */
  451. public function getGxMc()
  452. {
  453. //get请求
  454. if(!$this->request->isGet()){
  455. $this->error('请求方式错误');
  456. }
  457. $req = $this->request->param();
  458. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  459. $gdbh = $req['gdbh'];
  460. }else{
  461. $this->error('参数错误');
  462. }
  463. $gxmc = ['手检','手检(圆切)','次品检','抽检','大张翻检'];
  464. $gxmcs = [];
  465. foreach ($gxmc as $k=>$v){
  466. array_push($gxmcs,['like','%'.$v.'%']);
  467. }
  468. array_push($gxmcs,'OR');
  469. $rows = db()->table('工单_基本资料')->alias('g')
  470. ->field('rtrim(g.Gd_cpmc) as Gd_cpmc, c.Gy0_yjno, c.Gy0_gxh, rtrim(c.Gy0_gxmc) as Gy0_gxmc')
  471. ->where(['g.Gd_gdbh'=>$gdbh])
  472. ->where(['c.Gy0_gxmc'=>$gxmcs])
  473. ->join(['产品_印件资料'=>'j'],'g.Gd_cpdh=j.yj_yjdh and g.成品代号=j.yj_cpdh')
  474. ->join(['工单_工艺资料'=>'c'],'c.Gy0_gdbh=g.Gd_gdbh and c.Gy0_yjno=j.yj_Yjno')
  475. ->select();
  476. foreach ($rows as $key=>$value){
  477. $rows[$key]['jyGx'] = sprintf("%02d", $value['Gy0_yjno']).'-'.$value['Gy0_gxh'];
  478. }
  479. $this->success('成功',$rows);
  480. }
  481. /**
  482. * 查询印件工序及产品名称
  483. * @ApiMethod (GET)
  484. * @param string $gdbh 工单编号
  485. * @param string $gxmc 工序名称
  486. */
  487. public function getMachineGxMc()
  488. {
  489. //get请求
  490. if(!$this->request->isGet()){
  491. $this->error('请求方式错误');
  492. }
  493. $req = $this->request->param();
  494. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  495. $gdbh = $req['gdbh'];
  496. }else{
  497. $this->error('参数错误');
  498. }
  499. $gxmc = ['机检'];
  500. $gxmcs = [];
  501. foreach ($gxmc as $k=>$v){
  502. array_push($gxmcs,['like','%'.$v.'%']);
  503. }
  504. array_push($gxmcs,'OR');
  505. $rows = db()->table('工单_基本资料')->alias('g')
  506. ->field('rtrim(g.Gd_cpmc) as Gd_cpmc, c.Gy0_yjno, c.Gy0_gxh, rtrim(c.Gy0_gxmc) as Gy0_gxmc')
  507. ->where(['g.Gd_gdbh'=>$gdbh])
  508. ->where(['c.Gy0_gxmc'=>$gxmcs])
  509. ->join(['产品_印件资料'=>'j'],'g.Gd_cpdh=j.yj_yjdh and g.成品代号=j.yj_cpdh')
  510. ->join(['工单_工艺资料'=>'c'],'c.Gy0_gdbh=g.Gd_gdbh and c.Gy0_yjno=j.yj_Yjno')
  511. ->select();
  512. foreach ($rows as $key=>$value){
  513. $rows[$key]['jyGx'] = sprintf("%02d", $value['Gy0_yjno']).'-'.$value['Gy0_gxh'];
  514. }
  515. $this->success('成功',$rows);
  516. }
  517. /**
  518. * 查询定额代号
  519. * @ApiMethod (GET)
  520. */
  521. public function getDedh()
  522. {
  523. //get请求
  524. if(!$this->request->isGet()){
  525. $this->error('请求方式错误');
  526. }
  527. $row = db()->table('dic_lzde')
  528. ->field('Key_, sys_bh, rtrim(sys_mc) as sys_mc')
  529. ->where('sys_mc','初检(手工)')
  530. ->find();
  531. $rows = db()->table('dic_lzde')
  532. ->field('sys_bh, rtrim(sys_mc) as sys_mc')
  533. // ->where('Parent',$row['Key_'])
  534. ->where('sys_bh','like',$row['sys_bh'].'%')
  535. ->where('sys_bh','<>',$row['sys_bh'])
  536. ->select();
  537. $row['bh_mc'] = $rows;
  538. $this->success('成功',$row);
  539. }
  540. /**
  541. * 查询定额代号
  542. * @ApiMethod (GET)
  543. */
  544. public function getMachineDedh()
  545. {
  546. //get请求
  547. if(!$this->request->isGet()){
  548. $this->error('请求方式错误');
  549. }
  550. // $req = $this->request->param();
  551. // if (isset($req['sys_mc']) && !empty($req['sys_mc'])){
  552. // $sys_mc = $req['sys_mc'];
  553. // }else{
  554. // $this->error('参数错误');
  555. // }
  556. $row = db()->table('dic_lzde')
  557. ->field('Key_, sys_bh, rtrim(sys_mc) as sys_mc')
  558. ->where('适用机型','JP01#')
  559. ->find();
  560. $rows = db()->table('dic_lzde')
  561. ->field('sys_bh, rtrim(sys_mc) as sys_mc')
  562. // ->where('Parent',$row['Key_'])
  563. ->where('sys_bh','like',$row['sys_bh'].'%')
  564. ->where('sys_bh','<>',$row['sys_bh'])
  565. ->select();
  566. $row['bh_mc'] = $rows;
  567. $this->success('成功',$row);
  568. }
  569. /**
  570. * 查询废品系数
  571. * @ApiMethod (GET)
  572. */
  573. public function getScrapFactor()
  574. {
  575. //get请求
  576. if(!$this->request->isGet()){
  577. $this->error('请求方式错误');
  578. }
  579. $req = $this->request->param();
  580. isset($req['gdbh']) && !empty($req['gdbh']) ? $gdbh = $req['gdbh'] : $this->error('参数错误');
  581. isset($req['yjno']) && !empty($req['yjno']) ? $yjno = $req['yjno'] : $this->error('参数错误');
  582. isset($req['gxh']) && !empty($req['gxh']) ? $gxh = $req['gxh'] : $this->error('参数错误');
  583. isset($req['type']) && !empty($req['type']) ? $type = $req['type'] : $this->error('参数错误');
  584. switch ($type){
  585. case '正品板':
  586. $field = '人工检_正品板 as num';
  587. case '次品板':
  588. $field = '人工检_次品板 as num';
  589. case '废品板':
  590. $field = '人工检_废检 as num';
  591. }
  592. $rows = db()->table('工单_工艺资料')
  593. ->field($field)
  594. ->where(['Gy0_gdbh'=>$gdbh, 'Gy0_yjno'=>$yjno, 'Gy0_gxh'=>$gxh])
  595. ->find();
  596. $this->success('成功',$rows);
  597. }
  598. /**
  599. * 查询废品系数
  600. * @ApiMethod (GET)
  601. */
  602. public function getMachineScrapFactor()
  603. {
  604. //get请求
  605. if(!$this->request->isGet()){
  606. $this->error('请求方式错误');
  607. }
  608. $req = $this->request->param();
  609. isset($req['gdbh']) && !empty($req['gdbh']) ? $gdbh = $req['gdbh'] : $this->error('参数错误');
  610. isset($req['yjno']) && !empty($req['yjno']) ? $yjno = $req['yjno'] : $this->error('参数错误');
  611. isset($req['gxh']) && !empty($req['gxh']) ? $gxh = $req['gxh'] : $this->error('参数错误');
  612. isset($req['type']) && !empty($req['type']) ? $type = $req['type'] : $this->error('参数错误');
  613. switch ($type){
  614. case '正品板':
  615. $field = '机检_正品板 as num';
  616. case '次品板':
  617. $field = '机检_次品板 as num';
  618. case '废品板':
  619. $field = '机检_废检 as num';
  620. }
  621. $rows = db()->table('工单_工艺资料')
  622. ->field($field)
  623. ->where(['Gy0_gdbh'=>$gdbh, 'Gy0_yjno'=>$yjno, 'Gy0_gxh'=>$gxh])
  624. ->find();
  625. $this->success('成功',$rows);
  626. }
  627. /**
  628. * 查询机台
  629. * @ApiMethod (GET)
  630. */
  631. public function getJtbh()
  632. {
  633. //get请求
  634. if(!$this->request->isGet()){
  635. $this->error('请求方式错误');
  636. }
  637. $req = $this->request->param();
  638. if (isset($req['sys_mc']) && !empty($req['sys_mc'])){
  639. $sys_mc = $req['sys_mc'];
  640. }else{
  641. $this->error('参数错误');
  642. }
  643. // $row = db()->table('dic_lzde')
  644. // ->field('Key_, sys_bh, rtrim(sys_mc) as sys_mc')
  645. // ->where('sys_mc',$sys_mc)
  646. // ->find();
  647. $rows = db()->table('dic_lzde')->alias('d')
  648. ->field('rtrim(s.设备编号) as jtbh, rtrim(s.设备名称) as jtmc')
  649. // ->where('Parent',$row['Key_'])
  650. ->where('d.适用机型','like','JP%')
  651. ->join(['设备_基本资料'=>'s'],'d.适用机型=s.设备编号')
  652. ->select();
  653. $this->success('成功',$rows);
  654. }
  655. /**
  656. * 新增
  657. * @ApiMethod (POST)
  658. * @param string
  659. */
  660. public function add()
  661. {
  662. if(!$this->request->isPost()){
  663. $this->error('请求方式错误');
  664. }
  665. $req = $this->request->param();
  666. //sczl_num, sczl_gs, sczl_fp
  667. $arr = [
  668. 'sys_id','sczl_rq','sczl_bzdh','sczl_bh0','sczl_cl0','sczl_fp0',
  669. 'sczl_gdbh','sczl_yjgx','sczl_gxmc',
  670. 'sczl_cl','sczl_dedh','sczl_检验类别','sczl_废品率系数',
  671. 'sczl_jsss','sczl_冲定额',
  672. 'qczl_Num','qczl_NumDesc1','qczl_NumDesc2','qczl_NumDesc3','qczl_NumDesc4',
  673. 'qczl_NumDesc5','qczl_NumDesc6','qczl_NumDesc7','qczl_NumDesc8','qczl_NumDesc',
  674. 'sczl_bh1','sczl_bh2','sczl_bh3','sczl_bh4','sczl_bh5', 'sczl_bh6',
  675. 'sczl_bh7','sczl_bh8','sczl_bh9','sczl_bh10','sczl_bh11', 'sczl_bh12',
  676. 'sczl_cl1','sczl_cl2','sczl_cl3','sczl_cl4','sczl_cl5','sczl_cl6',
  677. 'sczl_cl7','sczl_cl8','sczl_cl9','sczl_cl10','sczl_cl11','sczl_cl12',
  678. 'sczl_fp1','sczl_fp2','sczl_fp3','sczl_fp4','sczl_fp5','sczl_fp6',
  679. 'sczl_fp7','sczl_fp8','sczl_fp9','sczl_fp10','sczl_fp11','sczl_fp12','sczl_desc'
  680. ];
  681. $data = [];
  682. foreach ($arr as $key => $value){
  683. if (!(isset($req[$value]))){
  684. $this->error('参数错误',$value,$key+1);
  685. }
  686. $data[$value] = $req[$value];
  687. }
  688. $data['sys_rq'] = date('Y-m-d H:i:s');
  689. //开启事务
  690. db()->startTrans();
  691. try{
  692. $sql = db()->table('db_手工检验')->fetchSql(true)->insert($data);
  693. $bool = db()->query($sql);
  694. // 提交事务
  695. db()->commit();
  696. } catch (\Exception $e) {
  697. // 回滚事务
  698. db()->rollback();
  699. $this->error($e->getMessage());
  700. }
  701. if($bool===false) $this->error('失败');
  702. $this->success('成功');
  703. }
  704. /**
  705. * 新增
  706. * @ApiMethod (POST)
  707. * @param string
  708. */
  709. public function machineAdd()
  710. {
  711. if(!$this->request->isPost()){
  712. $this->error('请求方式错误');
  713. }
  714. $req = $this->request->param();
  715. //sczl_num, sczl_NumDesc, sczl_fp
  716. $arr = [
  717. 'sys_id','sczl_rq','sczl_bzdh',
  718. 'sczl_gdbh','sczl_yjgx','sczl_gxmc',
  719. 'sczl_jtbh','sczl_单据类型','sczl_检验类别','sczl_废品率系数',
  720. 'sczl_cl','sczl_PgCl','sczl_dedh',
  721. 'qczl_Num','qczl_NumDesc1','qczl_NumDesc2','qczl_NumDesc3','qczl_NumDesc4',
  722. 'qczl_NumDesc5','qczl_NumDesc6','qczl_NumDesc7','qczl_NumDesc8','qczl_NumDesc',
  723. 'sczl_装版工时','sczl_保养工时','sczl_异常停机工时','sczl_设备运行工时',
  724. 'sczl_bh1','sczl_bh2','sczl_bh3','sczl_bh4','sczl_bh5', 'sczl_bh6','sczl_bh7','sczl_bh8',
  725. 'sczl_desc'
  726. ];
  727. $data = [];
  728. foreach ($arr as $key => $value){
  729. if (!(isset($req[$value]))){
  730. $this->error('参数错误',$value,$key+1);
  731. }
  732. $data[$value] = $req[$value];
  733. }
  734. $data['sys_rq'] = date('Y-m-d H:i:s');
  735. //开启事务
  736. db()->startTrans();
  737. try{
  738. $sql = db()->table('db_机器检验')->fetchSql(true)->insert($data);
  739. $bool = db()->query($sql);
  740. // 提交事务
  741. db()->commit();
  742. } catch (\Exception $e) {
  743. // 回滚事务
  744. db()->rollback();
  745. $this->error($e->getMessage());
  746. }
  747. if($bool===false) $this->error('失败');
  748. $this->success('成功');
  749. }
  750. /**
  751. * 修改
  752. * @ApiMethod (POST)
  753. * @param string 'UniqId'
  754. */
  755. public function edit()
  756. {
  757. if(!$this->request->isPost()){
  758. $this->error('请求方式错误');
  759. }
  760. $req = $this->request->param();
  761. $arr = [
  762. 'sczl_rq','sczl_bzdh','sczl_bh0','sczl_cl0','sczl_fp0',
  763. 'sczl_gdbh','sczl_yjgx','sczl_gxmc',
  764. 'sczl_cl','sczl_dedh','sczl_检验类别','sczl_废品率系数',
  765. 'sczl_jsss','sczl_冲定额',
  766. 'qczl_Num','qczl_NumDesc1','qczl_NumDesc2','qczl_NumDesc3','qczl_NumDesc4',
  767. 'qczl_NumDesc5','qczl_NumDesc6','qczl_NumDesc7','qczl_NumDesc8','qczl_NumDesc',
  768. 'sczl_bh1','sczl_bh2','sczl_bh3','sczl_bh4','sczl_bh5', 'sczl_bh6',
  769. 'sczl_bh7','sczl_bh8','sczl_bh9','sczl_bh10','sczl_bh11', 'sczl_bh12',
  770. 'sczl_cl1','sczl_cl2','sczl_cl3','sczl_cl4','sczl_cl5','sczl_cl6',
  771. 'sczl_cl7','sczl_cl8','sczl_cl9','sczl_cl10','sczl_cl11','sczl_cl12',
  772. 'sczl_fp1','sczl_fp2','sczl_fp3','sczl_fp4','sczl_fp5','sczl_fp6',
  773. 'sczl_fp7','sczl_fp8','sczl_fp9','sczl_fp10','sczl_fp11','sczl_fp12','sczl_desc'
  774. ];
  775. $data = [];
  776. foreach ($arr as $key => $value){
  777. if (!(isset($req[$value]))){
  778. continue;
  779. }
  780. $data[$value] = $req[$value];
  781. }
  782. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  783. $this->error('参数错误','UniqId',100);
  784. }
  785. $data['mod_rq'] = date('Y-m-d H:i:s');
  786. //开启事务
  787. db()->startTrans();
  788. try{
  789. $sql = db()->table('db_手工检验')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
  790. $bool = db()->query($sql);
  791. // 提交事务
  792. db()->commit();
  793. } catch (\Exception $e) {
  794. // 回滚事务
  795. db()->rollback();
  796. $this->error($e->getMessage());
  797. }
  798. if($bool===false) $this->error('失败');
  799. $this->success('成功');
  800. }
  801. /**
  802. * 修改
  803. * @ApiMethod (POST)
  804. * @param string 'UniqId'
  805. */
  806. public function machineEdit()
  807. {
  808. if(!$this->request->isPost()){
  809. $this->error('请求方式错误');
  810. }
  811. $req = $this->request->param();
  812. $arr = [
  813. 'sys_id','sczl_rq','sczl_bzdh',
  814. 'sczl_gdbh','sczl_yjgx','sczl_gxmc',
  815. 'sczl_jtbh','sczl_单据类型','sczl_检验类别','sczl_废品率系数',
  816. 'sczl_cl','sczl_PgCl','sczl_dedh',
  817. 'qczl_Num','qczl_NumDesc1','qczl_NumDesc2','qczl_NumDesc3','qczl_NumDesc4',
  818. 'qczl_NumDesc5','qczl_NumDesc6','qczl_NumDesc7','qczl_NumDesc8','qczl_NumDesc',
  819. 'sczl_装版工时','sczl_保养工时','sczl_异常停机工时','sczl_设备运行工时',
  820. 'sczl_bh1','sczl_bh2','sczl_bh3','sczl_bh4','sczl_bh5', 'sczl_bh6','sczl_bh7','sczl_bh8',
  821. 'sczl_desc'
  822. ];
  823. $data = [];
  824. foreach ($arr as $key => $value){
  825. if (!(isset($req[$value]))){
  826. continue;
  827. }
  828. $data[$value] = $req[$value];
  829. }
  830. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  831. $this->error('参数错误','UniqId',100);
  832. }
  833. $data['mod_rq'] = date('Y-m-d H:i:s');
  834. //开启事务
  835. db()->startTrans();
  836. try{
  837. $sql = db()->table('db_机器检验')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
  838. $bool = db()->query($sql);
  839. // 提交事务
  840. db()->commit();
  841. } catch (\Exception $e) {
  842. // 回滚事务
  843. db()->rollback();
  844. $this->error($e->getMessage());
  845. }
  846. if($bool===false) $this->error('失败');
  847. $this->success('成功');
  848. }
  849. /**
  850. * 修改
  851. * @ApiMethod (POST)
  852. * @param string 'UniqId'
  853. */
  854. public function del()
  855. {
  856. if(!$this->request->isPost()){
  857. $this->error('请求方式错误');
  858. }
  859. $req = $this->request->param();
  860. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  861. $this->error('参数错误','UniqId',100);
  862. }
  863. //开启事务
  864. db()->startTrans();
  865. try{
  866. $bool = db()->table('db_手工检验')->where('UniqId',$req['UniqId'])->delete();
  867. // 提交事务
  868. db()->commit();
  869. } catch (\Exception $e) {
  870. // 回滚事务
  871. db()->rollback();
  872. $this->error($e->getMessage());
  873. }
  874. if($bool===false) $this->error('失败');
  875. $this->success('成功');
  876. }
  877. /**
  878. * 修改
  879. * @ApiMethod (POST)
  880. * @param string 'UniqId'
  881. */
  882. public function machineDel()
  883. {
  884. if(!$this->request->isPost()){
  885. $this->error('请求方式错误');
  886. }
  887. $req = $this->request->param();
  888. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  889. $this->error('参数错误','UniqId',100);
  890. }
  891. //开启事务
  892. db()->startTrans();
  893. try{
  894. $bool = db()->table('db_机器检验')->where('UniqId',$req['UniqId'])->delete();
  895. // 提交事务
  896. db()->commit();
  897. } catch (\Exception $e) {
  898. // 回滚事务
  899. db()->rollback();
  900. $this->error($e->getMessage());
  901. }
  902. if($bool===false) $this->error('失败');
  903. $this->success('成功');
  904. }
  905. /**
  906. * 工序汇总导出
  907. * @ApiMethod (GET)
  908. * @param string date
  909. * @param string sys_id
  910. * @param array fields
  911. */
  912. public function export(){
  913. if(!$this->request->isGet()){
  914. $this->error('请求方式错误');
  915. }
  916. $req = $this->request->param();
  917. $where = [];
  918. if (!isset($req['date']) || empty($req['date'])) $this->error('参数缺失');
  919. if (!(isset($req['fields']) && count($req['fields'])!=0)){
  920. $this->error('参数错误','fields',100);
  921. }
  922. if(strpos($req['date'],'-')){
  923. $where = ['a.sys_rq'=>['like','%'.$req['date'].'%']];
  924. }else{
  925. $where = ['a.sczl_gdbh'=>$req['date']];
  926. }
  927. if (isset($req['sys_id']) && !empty($req['sys_id'])){
  928. $where['a.sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
  929. }
  930. $field = '';
  931. $arr = [
  932. 'sczl_gdyj' =>['工单印件','CONCAT(a.sczl_gdbh, "--", rtrim(d.yj_yjmc)) as sczl_gdyj'],
  933. 'sczl_yjgx' =>['印件工序','CONCAT(rtrim(a.sczl_yjgx), " -", rtrim(a.sczl_gxmc)) as sczl_yjgx'],
  934. 'sczl_rq' =>['日期','LEFT(a.sczl_rq, 10) as sczl_rq'],
  935. 'sczl_cl' =>['计件产量','a.sczl_cl'],
  936. '千件工价' =>['千件工价','b.千件工价'],
  937. 'sczl_检验类别' =>['检验类别','rtrim(a.sczl_检验类别) as sczl_检验类别'],
  938. 'sczl_废品率系数' =>['废品率系数','a.sczl_废品率系数'],
  939. '日定额' =>['日定额','b.日定额'],
  940. 'sczl_bh0' =>['组长编号','a.sczl_bh0'],
  941. 'name' =>['组长姓名','rtrim(c.员工姓名) as name'],
  942. 'qczl_NumDesc' =>['流程单备注','a.qczl_NumDesc'],
  943. ];
  944. $data[0] = [];
  945. foreach ($req['fields'] as $k=>$v){
  946. if(array_key_exists($v,$arr)){
  947. if ($k==0){
  948. $field .= $arr[$v][1];
  949. }else{
  950. $field .= ','.$arr[$v][1];
  951. }
  952. array_push($data[0],$arr[$v][0]);
  953. }
  954. }
  955. $rows = db()->table('db_手工检验')->alias('a')
  956. ->join('dic_lzde b','a.sczl_dedh = b.sys_bh','left')
  957. ->join('人事_基本资料 c','a.sczl_bh0 = c.员工编号','left')
  958. ->join('工单_印件资料 d','a.sczl_gdbh = d.Yj_Gdbh','left')
  959. ->where($where)
  960. ->where('SUBSTR(a.sczl_yjgx,1,2) = d.yj_Yjno')
  961. ->field($field)->order('a.sczl_rq,a.UniqId asc')->select();
  962. foreach ($rows as $key=>$value) {
  963. if (isset($value['sczl_cl'])) $value['sczl_cl'] = floatval($value['sczl_cl']);
  964. if (isset($value['千件工价'])) $value['千件工价'] = floatval($value['千件工价']);
  965. $subArray = [];
  966. foreach ($req['fields'] as $k=>$v){
  967. if(array_key_exists($v,$arr)){
  968. if($value[$v]){
  969. array_push($subArray,$value[$v]);
  970. }else{
  971. array_push($subArray,'');
  972. }
  973. }
  974. }
  975. array_push($data,$subArray);
  976. }
  977. $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
  978. }
  979. /**
  980. * 工序汇总导出
  981. * @ApiMethod (GET)
  982. * @param string file_name
  983. * @param string date
  984. * @param string sys_id
  985. * @param array fields
  986. */
  987. public function machineExport(){
  988. if(!$this->request->isGet()){
  989. $this->error('请求方式错误');
  990. }
  991. $req = $this->request->param();
  992. if (!isset($req['date']) || empty($req['date'])) $this->error('参数缺失');
  993. if (!(isset($req['fields']) && count($req['fields'])!=0)){
  994. $this->error('参数错误','fields',100);
  995. }
  996. if(strpos($req['date'],'-')){
  997. $where = ['a.sys_rq'=>['like','%'.$req['date'].'%']];
  998. }else{
  999. $where = ['a.sczl_gdbh'=>$req['date']];
  1000. }
  1001. if (isset($req['sys_id']) && !empty($req['sys_id'])){
  1002. $where['a.sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
  1003. }
  1004. $field = '';
  1005. $arr = [
  1006. 'sczl_单据类型' =>['分类','rtrim(a.sczl_单据类型) as sczl_单据类型'],
  1007. 'sczl_gdyj' =>['工单印件','CONCAT(a.sczl_gdbh, "--", rtrim(d.yj_yjmc)) as sczl_gdyj'],
  1008. 'sczl_yjgx' =>['印件工序','CONCAT(rtrim(a.sczl_yjgx), " -", rtrim(a.sczl_gxmc)) as sczl_yjgx'],
  1009. 'sczl_jtbh' =>['机台编号','a.sczl_jtbh'],
  1010. 'sczl_rq' =>['日期','LEFT(a.sczl_rq, 10) as sczl_rq'],
  1011. 'sczl_cl' =>['计件产量','a.sczl_cl'],
  1012. 'sczl_检验类别' =>['检验类别','rtrim(a.sczl_检验类别) as sczl_检验类别'],
  1013. 'sczl_废品率系数' =>['废品率系数','a.sczl_废品率系数'],
  1014. '日定额' =>['日定额','b.日定额'],
  1015. 'sczl_bh1' =>['员工姓名1','rtrim(c1.员工姓名) as sczl_bh1'],
  1016. 'sczl_bh2' =>['员工姓名2','rtrim(c2.员工姓名) as sczl_bh2'],
  1017. 'sczl_bh3' =>['员工姓名3','rtrim(c3.员工姓名) as sczl_bh3'],
  1018. 'sczl_bh4' =>['员工姓名4','rtrim(c4.员工姓名) as sczl_bh4'],
  1019. 'sczl_bzdh' =>['班组代号','a.sczl_bzdh'],
  1020. '千件工价' =>['千件工价','b.千件工价'],
  1021. 'sczl_设备运行工时' =>['通电工时','a.sczl_设备运行工时'],
  1022. 'qczl_NumDesc' =>['流程单备注','a.qczl_NumDesc'],
  1023. ];
  1024. $data[0] = [];
  1025. foreach ($req['fields'] as $k=>$v){
  1026. if(array_key_exists($v,$arr)){
  1027. if ($k==0){
  1028. $field .= $arr[$v][1];
  1029. }else{
  1030. $field .= ','.$arr[$v][1];
  1031. }
  1032. array_push($data[0],$arr[$v][0]);
  1033. }
  1034. }
  1035. $rows = db()->table('db_机器检验')->alias('a')
  1036. ->join('dic_lzde b','a.sczl_dedh = b.sys_bh','left')
  1037. ->join('人事_基本资料 c1','a.sczl_bh1 = c1.员工编号','left')
  1038. ->join('人事_基本资料 c2','a.sczl_bh2 = c2.员工编号','left')
  1039. ->join('人事_基本资料 c3','a.sczl_bh3 = c3.员工编号','left')
  1040. ->join('人事_基本资料 c4','a.sczl_bh4 = c4.员工编号','left')
  1041. ->join('工单_印件资料 d','a.sczl_gdbh = d.Yj_Gdbh','left')
  1042. ->where($where)
  1043. ->where('SUBSTR(a.sczl_yjgx,1,2) = d.yj_Yjno')
  1044. ->field($field)->order('a.UniqId desc')->select();
  1045. foreach ($rows as $key=>$value) {
  1046. if (isset($value['sczl_cl'])) $value['sczl_cl'] = floatval($value['sczl_cl']);
  1047. if (isset($value['千件工价'])) $value['千件工价'] = floatval($value['千件工价']);
  1048. if (isset($value['sczl_设备运行工时'])) $value['sczl_设备运行工时'] = floatval($value['sczl_设备运行工时']);
  1049. $subArray = [];
  1050. foreach ($req['fields'] as $k=>$v){
  1051. if(array_key_exists($v,$arr)){
  1052. if($value[$v]){
  1053. array_push($subArray,$value[$v]);
  1054. }else{
  1055. array_push($subArray,'');
  1056. }
  1057. }
  1058. }
  1059. array_push($data,$subArray);
  1060. }
  1061. $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
  1062. }
  1063. /**
  1064. * 月度汇总导出
  1065. * @ApiMethod (GET)
  1066. * @param string month
  1067. * @param string file_name
  1068. * @param array fields
  1069. */
  1070. public function monthExport(){
  1071. if(!$this->request->isGet()){
  1072. $this->error('请求方式错误');
  1073. }
  1074. $req = $this->request->param();
  1075. if (isset($req['date']) && !empty($req['date'])){
  1076. $where = ['a.sczl_rq'=>['like','%'.$req['date'].'%']];
  1077. }else{
  1078. $this->error('参数缺失');
  1079. }
  1080. if (!(isset($req['fields']) && count($req['fields'])!=0)){
  1081. $this->error('参数错误','fields',100);
  1082. }
  1083. $field = '';
  1084. $arr = [
  1085. 'sczl_rq' =>['日期','LEFT(a.sczl_rq, 10) as sczl_rq'],
  1086. 'sczl_gdbh' =>['工单编号','a.sczl_gdbh'],
  1087. 'sczl_gdyj' =>['工单印件','rtrim(d.yj_yjmc) as sczl_gdyj'],
  1088. 'sczl_yjgx' =>['印件工序','CONCAT(rtrim(a.sczl_yjgx), " -", rtrim(a.sczl_gxmc)) as sczl_yjgx'],
  1089. 'sczl_cl' =>['计件产量','sum(a.sczl_cl) as sczl_cl'],
  1090. ];
  1091. $data[0] = [];
  1092. foreach ($req['fields'] as $k=>$v){
  1093. if(array_key_exists($v,$arr)){
  1094. if ($k==0){
  1095. $field .= $arr[$v][1];
  1096. }else{
  1097. $field .= ','.$arr[$v][1];
  1098. }
  1099. array_push($data[0],$arr[$v][0]);
  1100. }
  1101. }
  1102. $rows = db()->table('db_手工检验')->alias('a')
  1103. ->field($field)
  1104. ->where($where)
  1105. ->where('SUBSTR(a.sczl_yjgx,1,2) = d.yj_Yjno')
  1106. ->join('工单_印件资料 d', 'a.sczl_gdbh = d.Yj_Gdbh', 'left')
  1107. ->group('a.sczl_gdbh, d.yj_yjmc, a.sczl_yjgx')
  1108. ->order('a.sczl_gdbh asc')
  1109. ->select();
  1110. foreach ($rows as $key=>$value) {
  1111. if (isset($value['sczl_cl'])) $value['sczl_cl'] = floatval($value['sczl_cl']);
  1112. $subArray = [];
  1113. foreach ($req['fields'] as $k=>$v){
  1114. if(array_key_exists($v,$arr)){
  1115. if($value[$v]){
  1116. array_push($subArray,$value[$v]);
  1117. }else{
  1118. array_push($subArray,'');
  1119. }
  1120. }
  1121. }
  1122. array_push($data,$subArray);
  1123. }
  1124. $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
  1125. }
  1126. /**
  1127. * 手检流程单统计导出
  1128. * @ApiMethod (GET)
  1129. * @param string start_time
  1130. * @param string end_time
  1131. * @param string file_name
  1132. * @param array fields
  1133. */
  1134. public function handInspectExport(){
  1135. if(!$this->request->isGet()){
  1136. $this->error('请求方式错误');
  1137. }
  1138. $req = $this->request->param();
  1139. $arr = [
  1140. 'start_time', 'end_time', 'file_name'
  1141. ];
  1142. foreach ($arr as $key => $value){
  1143. if (!isset($req[$value])){
  1144. $this->error('参数错误',$value,$key+1);
  1145. }
  1146. }
  1147. if (!(isset($req['fields']) && count($req['fields'])!=0)){
  1148. $this->error('参数错误','fields',100);
  1149. }
  1150. $field = '';
  1151. $arr = [
  1152. 'sczl_gdbh' =>['工单编号',''],
  1153. 'sczl_yjgx' =>['印件工序','rtrim(sczl_yjgx) as sczl_yjgx'],
  1154. 'sczl_gxmc' =>['工序名称','rtrim(sczl_gxmc) as sczl_gxmc'],
  1155. 'sczl_rq' =>['日期','sczl_rq'],
  1156. 'sczl_Num' =>['流程单号','qczl_Num,qczl_NumDesc1,qczl_NumDesc2,qczl_NumDesc3,qczl_NumDesc4,qczl_NumDesc5,qczl_NumDesc6,qczl_NumDesc7,qczl_NumDesc8'],
  1157. 'sczl_cl' =>['质检产量','qczl_Num,qczl_NumDesc1,qczl_NumDesc2,qczl_NumDesc3,qczl_NumDesc4,qczl_NumDesc5,qczl_NumDesc6,qczl_NumDesc7,qczl_NumDesc8,sczl_cl'],
  1158. ];
  1159. $data[0] = [];
  1160. foreach ($req['fields'] as $k=>$v){
  1161. if(array_key_exists($v,$arr)){
  1162. if ($k==0){
  1163. $field .= $arr[$v][1];
  1164. }else{
  1165. $field .= ','.$arr[$v][1];
  1166. }
  1167. array_push($data[0],$arr[$v][0]);
  1168. }
  1169. }
  1170. $rows = db()->table('db_手工检验')
  1171. ->field('sczl_gdbh,'.$field)
  1172. ->where('sczl_rq',['>=',$req['start_time']],['<=',$req['end_time']],'and')
  1173. ->where('qczl_Num|qczl_NumDesc1|qczl_NumDesc2|qczl_NumDesc3|qczl_NumDesc4|qczl_NumDesc5|qczl_NumDesc6|qczl_NumDesc7|qczl_NumDesc8','<>',0)
  1174. ->order('sczl_gdbh asc')
  1175. ->select();
  1176. $data = [];
  1177. $brr = [
  1178. 'qczl_Num','qczl_NumDesc1','qczl_NumDesc2','qczl_NumDesc3','qczl_NumDesc4',
  1179. 'qczl_NumDesc5','qczl_NumDesc6','qczl_NumDesc7','qczl_NumDesc8'
  1180. ];
  1181. foreach($rows as $key=>$value){
  1182. $flag = 0;
  1183. foreach($brr as $ke=>$va){
  1184. if ($value[$va]!=0){
  1185. $subArray = [];
  1186. foreach ($req['fields'] as $k=>$v) {
  1187. if (array_key_exists($v, $arr)) {
  1188. if ($v=='sczl_cl'){
  1189. if ($flag==0){
  1190. $subArray['sczl_cl'] = $value['sczl_cl'];
  1191. }else{
  1192. $subArray['sczl_cl'] = 0;
  1193. }
  1194. }else if ($v=='sczl_Num'){
  1195. $subArray['sczl_Num'] = $value[$va];
  1196. }else{
  1197. $subArray[$v] = $value[$v];
  1198. }
  1199. }
  1200. }
  1201. $flag++;
  1202. if(array_key_exists($value['sczl_gdbh'].'-'.$value['sczl_rq'].'-'.$value[$va],$data)){
  1203. if(array_key_exists('sczl_cl',$subArray)){
  1204. $data[$value['sczl_gdbh'].'-'.$value['sczl_rq'].'-'.$value[$va]]['sczl_cl'] += $value['sczl_cl'];
  1205. }
  1206. }else{
  1207. $data[$value['sczl_gdbh'].'-'.$value['sczl_rq'].'-'.$value[$va]] = $subArray;
  1208. }
  1209. }
  1210. }
  1211. }
  1212. $data = array_values($data);
  1213. $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
  1214. }
  1215. }