OrderSuperLoss.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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 OrderSuperLoss 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. if (Request::instance()->isGet() == false) {
  28. $this->error('非法请求');
  29. }
  30. $sql = "SELECT DISTINCT(Gd_gdbh),`年月`,rtrim(`客户编号`) as 客户编号,rtrim(`客户名称`) as 客户名称 FROM `rec_月度废品汇总`
  31. WHERE STR_TO_DATE(`年月`, '%Y%m') >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH) order by 年月 desc,客户编号 asc";
  32. $data = Db::query($sql);
  33. $outputArray = [];
  34. foreach ($data as $item) {
  35. $yearMonth = $item['年月'];
  36. if (!isset($outputArray[$yearMonth])) {
  37. // If key doesn't exist in output array, initialize it
  38. $outputArray[$yearMonth] = [];
  39. }
  40. // Check if the customer already exists in the current yearMonth array
  41. $existingCustomerIndex = null;
  42. foreach ($outputArray[$yearMonth] as $index => $customer) {
  43. if ($customer['客户编号'] === $item['客户编号']) {
  44. $existingCustomerIndex = $index;
  45. break;
  46. }
  47. }
  48. if ($existingCustomerIndex !== null) {
  49. // If customer exists, increment the total
  50. $outputArray[$yearMonth][$existingCustomerIndex]['total']++;
  51. } else {
  52. // If customer doesn't exist, add a new entry
  53. $outputArray[$yearMonth][] = [
  54. '客户名称' => $item['客户名称'],
  55. '客户编号' => $item['客户编号'],
  56. 'total' => 1,
  57. ];
  58. }
  59. }
  60. // 遍历每个年月的数组
  61. $list = [];
  62. foreach ($outputArray as $yearMonth => $orders) {
  63. $totalOrders = 0;
  64. // 遍历每个订单,累加订单数量
  65. foreach ($orders as $order) {
  66. $totalOrders += $order['total'];
  67. }
  68. // 输出每个年月的订单数量
  69. $list[$yearMonth.'-'.$totalOrders] = $orders;
  70. }
  71. $this->success('请求成功',$list);
  72. }
  73. /**
  74. * 获取超节损工单列表
  75. * @ApiMethod GET
  76. * @params string date
  77. * @params string code
  78. * 报废定额=(基础损耗+损耗率*计划产量)*损耗系数*计损色数(特定工序会有,如果无就不乘)
  79. * 允损比例=报废定额/计划产量
  80. * 目标合格率 = 100%-超节损工单中显示工序的允损比例之和
  81. *
  82. */
  83. public function getList(){
  84. if (Request::instance()->isGet() == false) {
  85. $this->error('非法请求');
  86. }
  87. $params = Request::instance()->param();
  88. $where = [];
  89. if (!empty($params['code'])) {
  90. if (!empty($params['search'])) {
  91. $this->error('参数错误');
  92. }
  93. $where['a.客户编号' ] = $params['code'];
  94. }
  95. if (!empty($params['date'])) {
  96. if (!empty($params['search'])) {
  97. $this->error('参数错误');
  98. }
  99. $where['a.年月' ] = $params['date'];
  100. }
  101. if (!empty($params['search'])) {
  102. if (!empty($params['date']) || !empty($params['code'])) {
  103. $this->error('参数错误');
  104. }
  105. $where['a.产品名称'] = array('like','%'.$params['search'].'%');
  106. }
  107. $where['b.行号' ] = 1;
  108. $limit = $params['limit'];
  109. if (empty($limit)){
  110. $limit = 15;
  111. }
  112. $pages = $params['page'];
  113. if (empty($pages)){
  114. $pages = 1;
  115. }
  116. $data = Db::table('rec_月度废品汇总')->alias('a')
  117. ->join('工单_基本资料 b', 'a.Gd_gdbh = b.Gd_gdbh','left')
  118. ->join('工单_印件资料 c', 'a.Gd_gdbh = c.Yj_Gdbh','left')
  119. ->where($where)
  120. ->field('a.Gd_gdbh, SUM(a.废品数量) AS 废品合计, a.年月, rtrim(a.Gd_cpmc) as Gd_cpmc, a.Gd_cpdh, a.实际投料, b.计量单位, c.yj_Yjno, c.yj_ls')
  121. ->group('a.Gd_gdbh')
  122. ->order('a.Gd_cpdh asc,a.年月 desc')
  123. ->fetchSql(true)
  124. ->page($pages)
  125. ->limit($limit)
  126. ->select();
  127. foreach ($data as $key => $value){
  128. //查出成品数量及日期
  129. $cp_sql = "SELECT SUM(jjcp_sl) as cp_sl,MAX(jjcp_sj) as jjcp_sj FROM `成品入仓` WHERE jjcp_gdbh = '{$value['Gd_gdbh']}' GROUP BY jjcp_gdbh";
  130. $cp_data = Db::query($cp_sql);
  131. $data[$key]['warehousing_num'] = $cp_data[0]['cp_sl'];
  132. $data[$key]['warehousing_date'] = substr($cp_data[0]['jjcp_sj'],0,10);
  133. //查出进入超节损的工序,有上报产量的工序就进入超节损
  134. $gxh_sql = "SELECT sczl_gxh FROM
  135. (SELECT sczl_gxh FROM 设备_产量计酬 WHERE sczl_gdbh = '{$value['Gd_gdbh']}'
  136. UNION SELECT sczl_gxh FROM db_sczl WHERE sczl_gdbh = '{$value['Gd_gdbh']}') AS combined_result";
  137. $gxh_arr = Db::query($gxh_sql);
  138. $gxh_values = array_column($gxh_arr, 'sczl_gxh');
  139. $gy_data = Db::name('工单_工艺资料')->where('Gy0_gdbh',$value['Gd_gdbh'])->where('Gy0_gxh','in',$gxh_values)->field('Gy0_计划接货数,Gy0_计划损耗')->select();
  140. $arr = [];
  141. $plan_loss = [];//工单计划损耗
  142. foreach ($gy_data as $k=>$v){
  143. $rate = round($v['Gy0_计划损耗'] / $v['Gy0_计划接货数'],5);
  144. $arr[$k] = floor($rate * 10000) /10000;
  145. $plan_loss[$k] = $v['Gy0_计划损耗'];
  146. }
  147. $target_rate = (1-array_sum($arr))*100;
  148. $data[$key]['target_rate'] =$target_rate.'%'; //目标合格率
  149. $real_rate = $cp_data[0]['cp_sl'] / ($value['实际投料'] * 10000) *100;
  150. $data[$key]['real_rate'] = number_format($real_rate,2) . '%';//实际合格率
  151. //奖惩系数及金额
  152. $data[$key]['reward_rate'] = '';
  153. $data[$key]['reward_money'] = '';
  154. //制程废品
  155. $zzfp_data = Db::name('设备_产量计酬')->where('sczl_gdbh',$value['Gd_gdbh'])->field('SUM(sczl_zcfp) as sczl_zcfp')->select();
  156. $data[$key]['zcfp'] = $zzfp_data[0]['sczl_zcfp'] * $value['yj_ls'];//制程废品
  157. $data[$key]['废品合计'] = $data[$key]['zcfp'] + $value['废品合计'];//废品合计
  158. $data[$key]['intangible_loss'] = $value['实际投料'] *10000 - $cp_data[0]['cp_sl'] - $data[$key]['废品合计'];//工单无形损
  159. //材料废
  160. $waste_l = Db::name('rec_月度废品汇总')->where('Gd_gdbh',$value['Gd_gdbh'])->where('废品类别','like','%L%')->field('SUM(废品数量) as 废品数量')->select();
  161. $data[$key]['material_waste'] = $waste_l[0]['废品数量'];
  162. //零头处理
  163. $waste_w = Db::name('rec_月度废品汇总')->where('Gd_gdbh',$value['Gd_gdbh'])->where('废品类别','like','%M%')->field('SUM(废品数量) as 废品数量')->select();
  164. $data[$key]['minor_processing'] = $waste_w[0]['废品数量'];
  165. //外发废
  166. $out_sql = "SELECT fp_sl1,fp_sl2,fp_sl3,fp_sl4,fp_sl5,fp_sl6,fp_sl7,fp_sl8,fp_sl9,fp_sl10,fp_sl11,fp_sl12,fp_sl13,
  167. fp_lb1,fp_lb2,fp_lb3,fp_lb4,fp_lb5,fp_lb6,fp_lb7,fp_lb8,fp_lb9,fp_lb10,fp_lb11,fp_lb12,fp_lb13,
  168. fp_bh1,fp_bh2,fp_bh3,fp_bh4,fp_bh5,fp_bh6,fp_bh7,fp_bh8,fp_bh9,fp_bh10,fp_bh11,fp_bh12,fp_bh13,
  169. fp_gxmc1,fp_gxmc2,fp_gxmc3,fp_gxmc4,fp_gxmc5,fp_gxmc6,fp_gxmc7,fp_gxmc8,fp_gxmc9,fp_gxmc10,fp_gxmc11,fp_gxmc12,fp_gxmc13
  170. FROM db_qczl WHERE qczl_gdbh = '{$value['Gd_gdbh']}'";
  171. $waste_out = Db::query($out_sql);
  172. $list = [];
  173. $quality = [];
  174. $j = 0;
  175. $m = 0;
  176. foreach ($waste_out as $entry) {
  177. for ($i = 1; $i <= 13; $i++) {
  178. $labelKey = "fp_lb" . $i;
  179. $bhKey = "fp_bh" . $i;
  180. $gxmcKey = "fp_gxmc" . $i;
  181. $slKey = "fp_sl" . $i;
  182. if (!empty($entry[$labelKey])) {
  183. if (substr($entry[$gxmcKey],0,2) == '99'){
  184. $list[$j]= $entry[$slKey];
  185. $j++;
  186. }
  187. }
  188. if (!empty($entry[$bhKey])) {
  189. if ($entry[$bhKey] != '000000' && $entry[$slKey] > 0){
  190. $quality[$m]= $entry[$slKey];
  191. $m++;
  192. }
  193. }
  194. }
  195. }
  196. $data[$key]['waste_out'] = array_sum($list);//外发废
  197. $data[$key]['waste_share'] = '';//分摊废
  198. $data[$key]['plan_loss'] = array_sum($plan_loss);//工单计划损耗
  199. $data[$key]['waste_quality'] = array_sum($quality); //质检废
  200. }
  201. $this->success('请求成功',$data);
  202. }
  203. /**
  204. * 获取工单超节损工艺
  205. * @ApiMethod GET
  206. * @params string order
  207. */
  208. public function getOrderSuperLossGy(){
  209. if (Request::instance()->isGet() == false) {
  210. $this->error('非法请求');
  211. }
  212. $params = Request::instance()->param();
  213. if (!isset($params['order']) || empty($params['order'])) {
  214. $this->error('参数错误');
  215. }
  216. $sql = "SELECT a.Gy0_gdbh,a.Gy0_yjno,a.Gy0_gxh,rtrim(a.Gy0_gxmc) as Gy0_gxmc,rtrim(a.Add_gxmc) as Add_gxmc,a.Gy0_ls,a.Gy0_Rate0,a.Gy0_Rate1,a.损耗系数,a.Gy0_ms,
  217. a.Gy0_计划接货数,a.Gy0_计划损耗,sum(b.sczl_cl) as total_cl,sum(b.sczl_zcfp) as total_fp,sum(c.sczl_cl) as cl,SUM(c.sczl_fp) as fp FROM `工单_工艺资料` a
  218. LEFT JOIN `设备_产量计酬` b ON a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_gxh = b.sczl_gxh
  219. LEFT JOIN `db_sczl` c ON a.Gy0_gdbh = c.sczl_gdbh AND a.Gy0_gxh = c.sczl_gxh
  220. WHERE a.Gy0_gdbh = '{$params['order']}' GROUP BY a.Gy0_gxh";
  221. $data = Db::query($sql);
  222. foreach ($data as $key=>$value){
  223. if (!empty($value['total_cl'])){
  224. $data[$key]['total_cl'] = $value['total_cl'] *$value['Gy0_ls'];
  225. }else{
  226. $data[$key]['total_cl'] =$value['cl'] *$value['Gy0_ls'];
  227. }
  228. if (!empty($value['total_fp'])){
  229. $data[$key]['total_fp'] = $value['total_fp'] *$value['Gy0_ls'];
  230. }else{
  231. $data[$key]['total_fp'] = $value['fp'] *$value['Gy0_ls'];
  232. }
  233. unset($data[$key]['cl']);
  234. unset($data[$key]['fp']);
  235. }
  236. $this->success('请求成功',$data);
  237. }
  238. /**
  239. * 工单超节损统计
  240. * @ApiMethod GET
  241. * @params string order
  242. */
  243. public function getOrderSuperLossCount(){
  244. if (Request::instance()->isGet() == false) {
  245. $this->error('非法请求');
  246. }
  247. $params = Request::instance()->param();
  248. if (!isset($params['order']) || empty($params['order'])) {
  249. $this->error('参数错误');
  250. }
  251. $order = $params['order'];
  252. $field = 'Gd_gdbh,rtrim(成品代号) as 成品代号,rtrim(成品名称) as 成品名称,rtrim(销售订单号) as 销售订单号,订单数量,实际投料';
  253. $data = Db::name('工单_基本资料')->where('Gd_Gdbh',$order)->where('行号',1)->field($field)->find();
  254. //查出成品数量及日期
  255. $cp_sql = "SELECT SUM(jjcp_sl) as cp_sl,MAX(jjcp_sj) as jjcp_sj FROM `成品入仓` WHERE jjcp_gdbh = '{$order}' GROUP BY jjcp_gdbh";
  256. $cp_data = Db::query($cp_sql);
  257. $data['warehousing_num'] = $cp_data[0]['cp_sl'];
  258. $data['warehousing_date'] = substr($cp_data[0]['jjcp_sj'],0,10);
  259. //查出进入超节损的工序,有上报产量的工序就进入超节损
  260. $gxh_sql = "SELECT sczl_gxh FROM
  261. (SELECT sczl_gxh FROM 设备_产量计酬 WHERE sczl_gdbh = '{$order}'
  262. UNION SELECT sczl_gxh FROM db_sczl WHERE sczl_gdbh = '{$order}') AS combined_result";
  263. $gxh_arr = Db::query($gxh_sql);
  264. $gxh_values = array_column($gxh_arr, 'sczl_gxh');
  265. $gy_data = Db::name('工单_工艺资料')
  266. ->alias('a')
  267. ->field([
  268. 'a.Gy0_yjno', 'a.Gy0_gxh', 'RTRIM(a.Gy0_gxmc) as Gy0_gxmc','RTRIM(a.Add_gxmc) as Add_gxmc', 'a.Gy0_ls', 'a.Gy0_计划接货数',
  269. 'a.Gy0_计划损耗', 'a.超节损承担比例','SUM(b.sczl_zcfp) as total_fp','SUM(b.sczl_cl) as total_cl','SUM(c.sczl_cl) as cl','SUM(c.sczl_fp) as fp',
  270. ])
  271. ->join('设备_产量计酬 b', 'a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_gxh = b.sczl_gxh','left')
  272. ->join('db_sczl c', 'a.Gy0_gdbh = c.sczl_gdbh AND a.Gy0_gxh = c.sczl_gxh','left')
  273. ->where([
  274. 'a.Gy0_gdbh' => $order,
  275. 'a.Gy0_gxh' => ['in', $gxh_values]
  276. ])
  277. ->group('a.Gy0_gxh')
  278. ->select();
  279. $arr = [];
  280. $plan_loss = [];//工单计划损耗
  281. foreach ($gy_data as $k=>$v){
  282. $rate = round($v['Gy0_计划损耗'] / $v['Gy0_计划接货数'],5);
  283. $arr[$k] = floor($rate * 10000) /10000;
  284. $plan_loss[$k] = $v['Gy0_计划损耗'];
  285. }
  286. $target_rate = (1-array_sum($arr))*100;
  287. $data['target_rate'] =$target_rate.'%'; //目标合格率
  288. $real_rate = $cp_data[0]['cp_sl'] / ($data['实际投料'] * 10000) *100;
  289. $data['real_rate'] = number_format($real_rate,2) . '%';//实际合格率
  290. //制程废品
  291. $zzfp_data = Db::name('设备_产量计酬')->where('sczl_gdbh',$order)->field('SUM(sczl_zcfp) as sczl_zcfp')->select();
  292. //联数
  293. $ls = Db::name('工单_印件资料')->where('Yj_Gdbh',$order)->value('yj_ls');
  294. //制程废品*ls
  295. $data['zcfp'] = $zzfp_data[0]['sczl_zcfp'] * $ls;
  296. //废品数量
  297. $waste = Db::name('rec_月度废品汇总')->where('Gd_gdbh',$order)->field('SUM(废品数量) as 废品合计')->select();
  298. //废品合计
  299. $waste_total = $data['zcfp'] + $waste[0]['废品合计'];
  300. //工单无形损
  301. $data['intangible_loss'] = $data['实际投料'] *10000 - $cp_data[0]['cp_sl'] - $waste_total;
  302. //材料废
  303. $waste_l = Db::name('rec_月度废品汇总')->where('Gd_gdbh',$order)->where('废品类别','like','%L%')->field('SUM(废品数量) as 废品数量')->select();
  304. $data['material_waste'] = $waste_l[0]['废品数量'];
  305. //零头处理
  306. $waste_w = Db::name('rec_月度废品汇总')->where('Gd_gdbh',$order)->where('废品类别','like','%M%')->field('SUM(废品数量) as 废品数量')->select();
  307. $data['minor_processing'] = $waste_w[0]['废品数量'];
  308. //外发废
  309. $out_sql = "SELECT fp_sl1,fp_sl2,fp_sl3,fp_sl4,fp_sl5,fp_sl6,fp_sl7,fp_sl8,fp_sl9,fp_sl10,fp_sl11,fp_sl12,fp_sl13,
  310. fp_lb1,fp_lb2,fp_lb3,fp_lb4,fp_lb5,fp_lb6,fp_lb7,fp_lb8,fp_lb9,fp_lb10,fp_lb11,fp_lb12,fp_lb13,
  311. fp_bh1,fp_bh2,fp_bh3,fp_bh4,fp_bh5,fp_bh6,fp_bh7,fp_bh8,fp_bh9,fp_bh10,fp_bh11,fp_bh12,fp_bh13,
  312. fp_gxmc1,fp_gxmc2,fp_gxmc3,fp_gxmc4,fp_gxmc5,fp_gxmc6,fp_gxmc7,fp_gxmc8,fp_gxmc9,fp_gxmc10,fp_gxmc11,fp_gxmc12,fp_gxmc13
  313. FROM db_qczl WHERE qczl_gdbh = '{$order}'";
  314. $waste_out = Db::query($out_sql);
  315. $list = [];
  316. $quality = [];
  317. $j = 0;
  318. $m = 0;
  319. foreach ($waste_out as $entry) {
  320. for ($i = 1; $i <= 13; $i++) {
  321. $labelKey = "fp_lb" . $i;
  322. $bhKey = "fp_bh" . $i;
  323. $gxmcKey = "fp_gxmc" . $i;
  324. $slKey = "fp_sl" . $i;
  325. if (!empty($entry[$labelKey])) {
  326. if (substr($entry[$gxmcKey],0,2) == '99'){
  327. $list[$j]= $entry[$slKey];
  328. $j++;
  329. }
  330. }
  331. if (!empty($entry[$bhKey])) {
  332. if ($entry[$bhKey] != '000000' && $entry[$slKey] > 0){
  333. $quality[$m]= $entry[$slKey];
  334. $m++;
  335. }
  336. }
  337. }
  338. }
  339. $data['waste_out'] = array_sum($list);//外发废
  340. //质检废
  341. $data['waste_quality'] = array_sum($quality);
  342. $plan_total = Db::name('工单_工艺资料')->where(['Gy0_gdbh' => $order, 'Gy0_gxh' => ['in', $gxh_values]])->value('SUM(Gy0_计划损耗)');
  343. // halt($plan_total);
  344. //按工序打印
  345. if ($params['type'] == 1){
  346. $total = [];
  347. $total['plan_loss'] = 0;
  348. $total['total_fp'] = 0;
  349. $total['waste_quality'] = 0;
  350. $total['waste_intangible'] = 0;
  351. $total['total_waste'] = 0;
  352. $total['loss'] = 0;
  353. foreach ($gy_data as $k=>$item){
  354. $gy_data[$k]['waste_quality'] = 0;
  355. $gy_data[$k]['total_fp'] = $item['total_fp'] * $item['Gy0_ls'];
  356. $gy_data[$k]['total_cl'] = $item['total_cl'] * $item['Gy0_ls'];
  357. $gy_data[$k]['intangible_loss'] = round($item['Gy0_计划损耗'] / $plan_total * $data['intangible_loss']);
  358. foreach ($waste_out as $entry) {
  359. for ($i = 1; $i <= 13; $i++) {
  360. $gxmcKey = "fp_gxmc" . $i;
  361. $slKey = "fp_sl" . $i;
  362. if ((int)substr($entry[$gxmcKey],0,2) == $item['Gy0_gxh']){
  363. $gy_data[$k]['waste_quality'] += $entry[$slKey];
  364. }
  365. }
  366. }
  367. $gy_data[$k]['total_waste'] = $gy_data[$k]['waste_quality'] + $gy_data[$k]['intangible_loss'] + $gy_data[$k]['total_fp'];
  368. $gy_data[$k]['loss'] = $item['Gy0_计划损耗'] - $gy_data[$k]['total_waste'];
  369. $gy_data[$k]['loss_rate'] = number_format($gy_data[$k]['loss'] / $item['Gy0_计划接货数'],4) * 100 .'%';
  370. $gy_data[$k]['target_loss_rate'] = number_format($item['Gy0_计划损耗'] / $item['Gy0_计划接货数'],4) * 100 .'%';
  371. $gy_data[$k]['actual_loss_rate'] = number_format($gy_data[$k]['total_waste'] / $item['Gy0_计划接货数'],4) * 100 .'%';
  372. $gy_data[$k]['超节损承担比例'] = number_format($item['超节损承担比例'],4) * 100 .'%';
  373. $total['plan_loss'] += $gy_data[$k]['Gy0_计划损耗'];
  374. $total['total_fp'] += $gy_data[$k]['total_fp'];
  375. $total['waste_quality'] += $gy_data[$k]['waste_quality'];
  376. $total['waste_intangible'] += $gy_data[$k]['intangible_loss'];
  377. $total['total_waste'] += $gy_data[$k]['total_waste'];
  378. $total['loss'] += $gy_data[$k]['loss'];
  379. }
  380. $data['gy_data'] = $gy_data;
  381. $data['total'] = $total;
  382. $this->success('请求成功',$data);
  383. }else{ //按班组打印
  384. }
  385. }
  386. /**
  387. * 获取工单工艺
  388. * @ApiMethod GET
  389. * @params string order
  390. */
  391. public function getOrderGy(){
  392. if (Request::instance()->isGet() == false) {
  393. $this->error('非法请求');
  394. }
  395. $params = Request::instance()->param();
  396. if (!isset($params['order']) || empty($params['order'])) {
  397. $this->error('参数错误');
  398. }
  399. $order = $params['order'];
  400. $field = 'Gy0_yjno,Gy0_gxh,rtrim(Gy0_gxmc) as Gy0_gxmc,rtrim(Add_gxmc) as Add_gxmc,Gy0_rate0,Gy0_rate1,损耗系数,无形损承担比例 as loss_one,超节损承担比例 as loss_two,超节损核算单价 as loss_thr,UniqId';
  401. $data = Db::name('工单_工艺资料')->where('Gy0_gdbh',$order)->field($field)->select();
  402. $this->success('请求成功',$data);
  403. }
  404. /**
  405. * 更新工单工艺
  406. * @ApiMethod POST
  407. * @params array data
  408. */
  409. public function updateOrderGy(){
  410. if (Request::instance()->isPost() == false) {
  411. $this->error('非法请求');
  412. }
  413. $params = Request::instance()->request();
  414. if (!isset($params) || !isset($params[0]['UniqId'])){
  415. $this->error('参数不能为空');
  416. }
  417. $i = 0;
  418. foreach ($params as $key=>$value){
  419. $data = [];
  420. $data['无形损承担比例'] = $value['loss_one'];
  421. $data['超节损承担比例'] = $value['loss_two'];
  422. $data['超节损核算单价'] = $value['loss_thr'];
  423. $sql = Db::name('工单_工艺资料')->where('UniqId',$value['UniqId'])->fetchSql(true)->update($data);
  424. $res = Db::query($sql);
  425. if ($res !== false){
  426. $i++;
  427. }
  428. }
  429. if ($i !== 0){
  430. $this->success('更新成功');
  431. }else{
  432. $this->error('更新失败');
  433. }
  434. }
  435. /**
  436. * 获取工单印件考核资料
  437. * @ApiMethod GET
  438. * @params string order
  439. */
  440. public function getOrderYj(){
  441. if (Request::instance()->isGet() == false) {
  442. $this->error('非法请求');
  443. }
  444. $params = Request::instance()->request();
  445. if (!isset($params['order']) || empty($params['order'])) {
  446. $this->error('参数错误');
  447. }
  448. $data = Db::name('工单_印件资料')->where('Yj_gdbh',$params['order'])->field('Yj_gdbh,rtrim(yj_Yjdh) as yj_Yjdh,yj_Yjno,rtrim(yj_yjmc) as yj_yjmc,质量考核')->find();
  449. $this->success('请求成功',$data);
  450. }
  451. /**
  452. * 更新工单印件考核资料
  453. * @ApiMethod POST
  454. * @params array data
  455. */
  456. public function updateOrderYj(){
  457. if (Request::instance()->isPost() == false) {
  458. $this->error('非法请求');
  459. }
  460. $params = Request::instance()->request();
  461. if (!isset($params['order'])){
  462. $this->error('参数不能为空');
  463. }
  464. if (!isset($params['yj_yjno'])){
  465. $this->error('参数不能为空');
  466. }
  467. if (!isset($params['examine'])){
  468. $this->error('参数不能为空');
  469. }
  470. $where['Yj_gdbh'] = $params['order'];
  471. $where['yj_Yjno'] = $params['yj_yjno'];
  472. $res = Db::name('工单_印件资料')->where($where)->setField('质量考核',$params['examine']);
  473. if ($res !== false){
  474. $this->success('更新成功');
  475. }else{
  476. $this->error('更新失败');
  477. }
  478. }
  479. /**
  480. * 获取修正工单实际投料列表
  481. * @ApiMethod GET
  482. * @params string year
  483. * @params string month
  484. */
  485. public function getOrderFeedList(){
  486. if (Request::instance()->isGet() == false) {
  487. $this->error('非法请求');
  488. }
  489. $params = Request::instance()->request();
  490. if (empty($params['year']) || empty($params['month'])) {
  491. $this->error('参数错误');
  492. }
  493. $search = $params['year'].'.'.$params['month'];
  494. $field = "a.Gd_gdbh,rtrim(c.yj_yjdh) as yj_yjdh,c.yj_Yjno, c.yj_ks,c.yj_ls,rtrim(c.yj_zzdh) as yj_zzdh,
  495. rtrim(b.BOM_物料名称) as BOM_物料名称,rtrim(c.yj_tlgg) as yj_tlgg,rtrim(b.BOM_投料单位) as BOM_投料单位,a.订单数量,c.yj_平张投料, b.BOM_实际用量,a.实际投料,a.投料确认,a.UniqId";
  496. $data = Db::name('工单_基本资料')->alias('a')
  497. ->join('工单_印件资料 c','a.Gd_gdbh = c.Yj_Gdbh','left')
  498. ->join('工单_bom资料 b','c.Yj_Gdbh = b.BOM_工单编号 AND c.yj_zzdh = b.BOM_物料编码','left')
  499. ->where('a.投料确认','like','%'.$search.'%')
  500. ->field($field)
  501. ->group('a.Gd_gdbh')
  502. ->order('b.BOM_投料单位,a.UniqId asc')
  503. ->select();
  504. if (empty($data)){
  505. $this->success('请求成功');
  506. }
  507. foreach ($data as $key=>$value){
  508. $len = stripos($value['yj_tlgg'],'/');
  509. if ($len){
  510. $name = substr($value['yj_tlgg'],0,$len);
  511. $len_two = stripos($value['yj_tlgg'],'(');
  512. if ($len_two){
  513. $name = substr($name,0,$len_two);
  514. }
  515. $data[$key]['yj_tlgg'] = $name;
  516. }
  517. $data[$key]['rate'] = '';
  518. }
  519. $this->success('请求成功',$data);
  520. }
  521. /**
  522. * 更新工单实际投料
  523. * @ApiMethod POST
  524. * @params int UniqId
  525. * @params string number
  526. */
  527. public function updateOrderFeed(){
  528. if (Request::instance()->isPost() == false) {
  529. $this->error('非法请求');
  530. }
  531. $params = Request::instance()->post();
  532. if (!isset($params[0]['UniqId']) || empty($params[0]['UniqId'])){
  533. $this->error('参数错误');
  534. }
  535. $i = 0;
  536. foreach ($params as $key=>$value){
  537. if (!empty($value['number'])){
  538. $info = Db::name('工单_基本资料')->where('UniqId',$value['UniqId'])->value('Gd_gdbh');
  539. $res = Db::name('工单_基本资料')->where('UniqId',$value['UniqId'])->setField('实际投料',$value['number']);
  540. $yjRes = Db::name('工单_印件资料')->where('Yj_Gdbh',$info)->setField('yj_实际投料',$value['number']);
  541. if (!$res && !$yjRes){
  542. $i++;
  543. }
  544. }
  545. }
  546. if ($i != 0){
  547. $this->success('更新成功');
  548. }else{
  549. $this->error('更新失败');
  550. }
  551. }
  552. /**
  553. * 工单工序产量统计
  554. * @ApiMethod GET
  555. * @params string order
  556. */
  557. public function getOrderProcessCount(){
  558. if (Request::instance()->isGet() == false) {
  559. $this->error('非法请求');
  560. }
  561. $params = Request::instance()->request();
  562. if (empty($params['order']) || empty($params['order'])) {
  563. $this->error('参数错误');
  564. }
  565. $order = $params['order'];
  566. $sql = "SELECT a.Gy0_yjno,a.Gy0_gxh,rtrim(a.Gy0_gxmc) as Gy0_gxmc,rtrim(a.Add_gxmc) as Add_gxmc,a.Gy0_计划接货数, a.Gy0_ls,a.Gy0_sbbh,a.PD_WG,SUM(b.sczl_cl) as sczl_cl,
  567. SUM(b.sczl_zcfp) as sczl_zcfp,SUM(b.sczl_来料少数) as 来料异常,COUNT(DISTINCT b.sczl_num) as process_num,b.sczl_Pgcl,SUM(c.sczl_cl) as cl,b.sczl_rq
  568. FROM `工单_工艺资料` a
  569. LEFT JOIN `设备_产量计酬` b ON a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_gxh = b.sczl_gxh
  570. LEFT JOIN db_sczl c ON a.Gy0_gdbh = c.sczl_gdbh AND a.Gy0_gxh = c.sczl_gxh
  571. WHERE a.Gy0_gdbh = '{$order}' GROUP BY a.Gy0_gxh";
  572. $data = Db::query($sql);
  573. // halt($data);
  574. //手检数据
  575. $handData = Db::name('db_手工检验')->where('sczl_gdbh',$order)->field('sum(sczl_cl) as cl,rtrim(sczl_yjgx) as sczl_gxh')->select();
  576. // halt($handData);
  577. //包装及成品防护数据
  578. $sql = "SELECT sczl_gdbh1,sczl_gdbh2,sczl_gdbh3,sczl_gdbh4,sczl_gdbh5,sczl_gdbh6,rtrim(sczl_gxmc1) as sczl_gxmc1,rtrim(sczl_gxmc2) as sczl_gxmc2,
  579. rtrim(sczl_gxmc3) as sczl_gxmc3,rtrim(sczl_gxmc4) as sczl_gxmc4,rtrim(sczl_gxmc5) as sczl_gxmc5,rtrim(sczl_gxmc6) as sczl_gxmc6,
  580. sczl_cl1,sczl_cl2,sczl_cl3,sczl_cl4,sczl_cl5,sczl_cl6,sczl_PgCl1,sczl_PgCl2,sczl_PgCl3,sczl_PgCl4,sczl_PgCl5,sczl_PgCl6
  581. FROM `mesdb`.`db_包装计件` WHERE `sczl_gdbh1` LIKE '%{$order}%' OR `sczl_gdbh2` LIKE '%{$order}%'
  582. OR `sczl_gdbh3` LIKE '%{$order}%' OR `sczl_gdbh4` LIKE '%{$order}%' OR `sczl_gdbh5` LIKE '%{$order}%' OR `sczl_gdbh6` LIKE '%{$order}%'";
  583. $package = Db::query($sql);
  584. $list = [];
  585. $j = 0;
  586. foreach ($package as $value){
  587. for ($i = 1; $i <= 6; $i++) {
  588. $gdbhlKey = "sczl_gdbh" . $i;
  589. $gxmcKey = "sczl_gxmc" . $i;
  590. $clKey = "sczl_cl" . $i;
  591. $pgclKey = "sczl_PgCl" . $i;
  592. if ($value[$gdbhlKey] == '2311743' && $value[$clKey] > 0) {
  593. $list[$j]['sczl_gdbh'] = $value[$gdbhlKey];
  594. $list[$j]['sczl_gxmc'] = $value[$gxmcKey];
  595. $list[$j]['sczl_cl'] = $value[$clKey];
  596. $list[$j]['sczl_PgCl'] = $value[$pgclKey];
  597. $j++;
  598. }
  599. }
  600. }
  601. // 创建一个关联数组,用于存储相同 sczl_gxmc 的值和对应的乘积之和
  602. $sumArray = [];
  603. foreach ($list as $item) {
  604. $key = $item['sczl_gxmc'];
  605. $cl = floatval($item['sczl_cl']);
  606. $pgCl = intval($item['sczl_PgCl']);
  607. $product = $cl * $pgCl;
  608. if (!isset($sumArray[$key])) {
  609. $sumArray[$key] = 0;
  610. }
  611. $sumArray[$key] += $product;
  612. }
  613. $handGxh = substr($handData[0]['sczl_gxh'],-2);
  614. // halt($sumArray['包装']);
  615. foreach ($data as $key=>$item){
  616. $data[$key]['折算车头产量'] = round($item['Gy0_计划接货数']/$item['Gy0_ls']);
  617. $data[$key]['制程废品率'] = '';
  618. if ($item['sczl_zcfp'] > 0){
  619. $data[$key]['制程废品率'] = number_format($item['sczl_zcfp']/$item['sczl_cl']*100,4).'%';
  620. }
  621. if ($item['cl'] > 0){
  622. $data[$key]['sczl_cl'] = $item['cl'];
  623. }
  624. if ($item['sczl_Pgcl'] > 0){
  625. $data[$key]['sczl_cl'] = $item['sczl_cl'] * $item['sczl_Pgcl'];
  626. }
  627. if ($item['Gy0_gxh'] == (int)$handGxh){
  628. $data[$key]['sczl_cl'] = $handData[0]['cl'];
  629. }
  630. foreach ($sumArray as $k=>$v){
  631. if ($item['Gy0_gxmc'] == $k){
  632. $data[$key]['sczl_cl'] = $v;
  633. }
  634. }
  635. if (substr($item['PD_WG'],0,4) == '1900'){
  636. $data[$key]['PD_WG'] = '计划';
  637. }else{
  638. $data[$key]['PD_WG'] = '完工';
  639. }
  640. }
  641. $this->success('请求成功',$data);
  642. }
  643. }