CostAccounting.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Request;
  5. /**
  6. * 各月制造费用维护
  7. */
  8. class CostAccounting extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. /**
  13. * 各月制造费用维护菜单
  14. * @return void
  15. */
  16. public function getTab()
  17. {
  18. // 1. 请求方法验证
  19. if (!$this->request->isGet()) {
  20. $this->error('仅支持GET请求');
  21. }
  22. // 2. 使用静态变量避免重复创建数组
  23. static $tabs, $sist;
  24. if ($tabs === null) {
  25. $tabs = [
  26. '1、月度人工数据',
  27. '2、水电气直接费用',
  28. '3、水电气分摊费用',
  29. '4、其他待摊费用',
  30. '5、车间色度数'
  31. ];
  32. $sist = ['胶印车间', '凹丝印车间', '印后车间'];
  33. }
  34. // 3. 数据库查询优化
  35. $months = db('成本_各月水电气')
  36. ->field('Sys_ny AS year_month')
  37. ->group('Sys_ny')
  38. ->order('Sys_ny DESC')
  39. ->column('Sys_ny');
  40. // 4. 使用模板构建策略
  41. $data = [];
  42. $template = [];
  43. // 预构建模板
  44. foreach ($tabs as $tab) {
  45. $template[$tab] = ($tab === '2、水电气直接费用') ? $sist : $tab;
  46. }
  47. // 仅需单次循环赋值
  48. foreach ($months as $month) {
  49. $data[$month] = $template;
  50. }
  51. $this->success('成功', $data);
  52. }
  53. /**
  54. * 月度车间人工维护
  55. * @return void
  56. * @throws \think\db\exception\BindParamException
  57. * @throws \think\exception\PDOException
  58. */
  59. public function ArtificialAdd()
  60. {
  61. if($this->request->isPost() === false){
  62. $this->error('请求错误');
  63. }
  64. $param = Request::instance()->post();
  65. if (empty($param)) {
  66. $this->error('参数错误');
  67. }
  68. $data = [];
  69. foreach ($param as $key => $value) {
  70. $data[$key] = [
  71. 'Sys_ny' => $value['sys_ny'],
  72. '车间' => $value['sist'],
  73. '一线工资总额' => $value['number'],
  74. '系数' => 1.2,
  75. '应发工资' => $value['number'] * 1.2,
  76. 'Sys_id' => $value['sys_id'],
  77. 'Sys_rq' => date('Y-m-d H:i:s', time())
  78. ];
  79. }
  80. $sql = db('成本v23_各月人工')->fetchSql(true)->insertAll($data);
  81. $res = db()->query($sql);
  82. if ($res !== false) {
  83. $this->success('新增成功');
  84. }else{
  85. $this->error('添加失败');
  86. }
  87. }
  88. /**
  89. * 月度人工维护列表
  90. * @return void
  91. * @throws \think\db\exception\DataNotFoundException
  92. * @throws \think\db\exception\ModelNotFoundException
  93. * @throws \think\exception\DbException
  94. */
  95. public function ArtificialAddList()
  96. {
  97. if($this->request->isGet() === false){
  98. $this->error('请求错误');
  99. }
  100. $param = $this->request->param();
  101. if (empty($param) || empty($param['Sys_ny'])) {
  102. $this->error('参数错误');
  103. }
  104. $list = db('成本v23_各月人工')
  105. ->where('Sys_ny', $param['Sys_ny'])
  106. ->field('Sys_ny, 车间, 一线工资总额, Sys_id as 创建用户, Sys_rq as 创建时间,Mod_rq as 修订时间,UniqID')
  107. ->select();
  108. $this->success('成功', $list);
  109. }
  110. /**
  111. * 月度人工维护修改
  112. * @return void
  113. * @throws \think\Exception
  114. * @throws \think\db\exception\BindParamException
  115. * @throws \think\exception\PDOException
  116. */
  117. public function ArtificialEdit()
  118. {
  119. if($this->request->isPost() === false){
  120. $this->error('请求错误');
  121. }
  122. $param = Request::instance()->post();
  123. if (empty($param)) {
  124. $this->error('参数错误');
  125. }
  126. $i = 0;
  127. foreach ($param as $value) {
  128. $sql = db('成本v23_各月人工')
  129. ->where('UniqID', $value['UniqID'])
  130. ->fetchSql(true)
  131. ->update(['一线工资总额'=>$value['number'],'Mod_rq'=>date('Y-m-d H:i:s', time())]);
  132. $res = db()->query($sql);
  133. if ($res === false) {
  134. $i++;
  135. }
  136. }
  137. if ($i === 0) {
  138. $this->success('修改成功');
  139. }else{
  140. $this->error('修改失败');
  141. }
  142. }
  143. /**
  144. * 月度人工数据右侧上方列表
  145. * @return void
  146. * @throws \think\db\exception\DataNotFoundException
  147. * @throws \think\db\exception\ModelNotFoundException
  148. * @throws \think\exception\DbException
  149. */
  150. public function ArtificialList()
  151. {
  152. if (!$this->request->isGet()) {
  153. $this->error('仅支持GET请求');
  154. }
  155. $month = $this->request->param('month');
  156. if (empty($month)) {
  157. $this->error('month参数缺失或为空');
  158. }
  159. $list = db('成本v23_各月人工')->alias('a')
  160. ->join('设备_基本资料 b', 'a.车间 = b.使用部门')
  161. ->join('绩效工资汇总 c', 'a.Sys_ny = c.sys_ny AND c.sczl_jtbh = b.设备编号')
  162. ->join('成本_各月其他费用 d', 'a.Sys_ny = d.sys_ny','left')
  163. ->field([
  164. 'a.Sys_ny' => '年月',
  165. 'rtrim(a.车间)' => '车间',
  166. 'SUM(c.个人计件工资) + SUM(c.个人加班工资)' => '人工分摊因子总额',
  167. 'a.一线工资总额' => '车间实发工资',
  168. 'd.部门人员工资' => '部门人员工资实发',
  169. 'd.管理人员工资' => '管理人员工资实发'
  170. ])
  171. ->where('a.Sys_ny', $month)
  172. ->group('a.Sys_ny, a.车间')
  173. ->select();
  174. if (empty($list)) {
  175. $this->success('未找到匹配数据', []);
  176. }
  177. $this->success('获取成功', $list);
  178. }
  179. /**
  180. * 月度人工数据下方工单详情
  181. * @return void
  182. * @throws \think\db\exception\DataNotFoundException
  183. * @throws \think\db\exception\ModelNotFoundException
  184. * @throws \think\exception\DbException
  185. */
  186. public function ArtificialDetailList()
  187. {
  188. if ($this->request->isGet() === false) {
  189. $this->error('请求错误');
  190. }
  191. $param = $this->request->param();
  192. if (empty($param)) {
  193. $this->error('参数错误');
  194. }
  195. $month = $param['month'];
  196. $sist = $param['sist'];
  197. $list = db('工单_质量考核汇总')
  198. ->alias('a')
  199. ->join('设备_基本资料 b', 'a.sczl_jtbh = b.设备编号')
  200. ->join('工单_印件资料 c', 'a.Gy0_gdbh = c.Yj_Gdbh and a.印件及工序 = c.yj_Yjno')
  201. ->join('工单_工艺资料 d', 'a.Gy0_gdbh = d.Gy0_gdbh and a.印件及工序 = d.Gy0_yjno and a.工序 = d.Gy0_gxh')
  202. ->field([
  203. 'a.sys_ny' => '年月',
  204. 'a.Gy0_gdbh' => '工单编号',
  205. 'a.印件及工序' => '印件号',
  206. 'a.工序' => '工序号',
  207. 'c.yj_yjmc' => '印件名称',
  208. 'd.Gy0_gxmc' => '工序名称',
  209. 'a.印件工序产量' => '班组车头产量',
  210. 'd.工价系数' => '工序难度系数',
  211. 'SUM(a.CjsJe)' => '计件工资',
  212. 'rtrim(b.使用部门)' => '车间名称',
  213. ])
  214. ->where('a.Sys_ny', $month)
  215. ->where('b.使用部门', $sist)
  216. ->group('a.Sys_ny, a.Gy0_gdbh,a.印件及工序,a.印件及工序')
  217. ->order('a.Gy0_gdbh')
  218. ->select();
  219. if (empty($list)) {
  220. $this->success('未找到数据');
  221. }else{
  222. $this->success('成功', $list);
  223. }
  224. }
  225. /**
  226. * 水电气直接费用右侧列表
  227. * @return void
  228. * @throws \think\db\exception\DataNotFoundException
  229. * @throws \think\db\exception\ModelNotFoundException
  230. * @throws \think\exception\DbException
  231. */
  232. public function shuidianqiList()
  233. {
  234. if ($this->request->isGet() === false) {
  235. $this->error('请求错误');
  236. }
  237. $param = $this->request->param();
  238. if (empty($param)) {
  239. $this->error('参数错误');
  240. }
  241. $month = $param['month'];
  242. $sist = $param['sist'];
  243. $list = db('成本_各月水电气')
  244. ->field('rtrim(部门名称) as 部门名称,rtrim(设备编号) as 设备编号,rtrim(科目名称) as 设备名称,rtrim(耗电量) as 耗电量,
  245. rtrim(单位电价) as 单位电价,rtrim(耗气量) as 耗气量,rtrim(单位气价) as 单位气价,rtrim(Sys_id) as 创建用户,Sys_rq as 创建时间,UniqID,耗电量*单位电价 as 直接费用合计')
  246. ->where('Sys_ny', $month)
  247. ->where('部门名称', $sist)
  248. ->where('费用类型', '直接')
  249. ->group('Sys_ny, Sys_rq, UniqID')
  250. ->select();
  251. if (empty($list)) {
  252. $this->success('未找到数据');
  253. }else{
  254. $this->success('成功', $list);
  255. }
  256. }
  257. /**
  258. * 水电气下方工单详情
  259. * @return void
  260. * @throws \think\db\exception\DataNotFoundException
  261. * @throws \think\db\exception\ModelNotFoundException
  262. * @throws \think\exception\DbException
  263. */
  264. public function shuidianqiDetailList()
  265. {
  266. if ($this->request->isGet() === false) {
  267. $this->error('请求错误');
  268. }
  269. $param = $this->request->param();
  270. if (empty($param)) {
  271. $this->error('参数错误');
  272. }
  273. $month = substr($param['month'], 0, 4) . '-' . substr($param['month'], 4, 2);
  274. $machine = $param['machine'];
  275. $list = db('设备_产量计酬')
  276. ->alias('a')
  277. ->join('工单_印件资料 b', 'a.sczl_gdbh = b.Yj_Gdbh and a.sczl_yjno = b.yj_Yjno')
  278. ->field('a.sczl_gdbh as 工单编号,b.yj_yjmc as 印件名称,a.sczl_yjno as 印件号,a.sczl_gxh as 工序号,
  279. sum(a.sczl_cl)*a.sczl_ls as 班组车头产量,sum(a.sczl_设备运行工时) as 占用机时')
  280. ->where('a.sczl_rq','like', '%'.$month.'%')
  281. ->where('a.sczl_jtbh', $machine)
  282. ->group('a.sczl_gdbh, a.sczl_yjno, a.sczl_gxh')
  283. ->select();
  284. if (empty($list)) {
  285. $this->success('未找到数据');
  286. }
  287. foreach ($list as $k => $v) {
  288. $list[$k]['计件产量'] = $v['班组车头产量'];
  289. $list[$k]['水电气分摊因子'] = $v['占用机时'];
  290. $list[$k]['年月'] = $param['month'];
  291. }
  292. $this->success('成功', $list);
  293. }
  294. /**
  295. * 水电气分摊费用
  296. * @return void
  297. * @throws \think\db\exception\DataNotFoundException
  298. * @throws \think\db\exception\ModelNotFoundException
  299. * @throws \think\exception\DbException
  300. */
  301. public function shuidianqifentanList()
  302. {
  303. if ($this->request->isGet() === false) {
  304. $this->error('请求错误');
  305. }
  306. $param = $this->request->param();
  307. if (empty($param)) {
  308. $this->error('参数错误');
  309. }
  310. $month = $param['month'];
  311. $list = db('成本_各月水电气')
  312. ->field('rtrim(部门名称) as 部门名称,rtrim(设备编号) as 设备编号,rtrim(科目名称) as 设备名称,rtrim(耗电量) as 耗电量,
  313. rtrim(单位电价) as 单位电价,rtrim(耗气量) as 耗气量,rtrim(单位气价) as 单位气价,rtrim(Sys_id) as 创建用户,Sys_rq as 创建时间,UniqID,耗电量*单位电价 as 直接费用合计')
  314. ->where('Sys_ny', $month)
  315. ->where('费用类型', '分摊')
  316. ->group('Sys_ny, Sys_rq, UniqID')
  317. ->select();
  318. if (empty($list)) {
  319. $this->success('未找到数据');
  320. }else{
  321. $this->success('成功', $list);
  322. }
  323. }
  324. /**
  325. * 各月工单人工明细
  326. * @return void
  327. * @throws \think\db\exception\BindParamException
  328. * @throws \think\db\exception\DataNotFoundException
  329. * @throws \think\db\exception\ModelNotFoundException
  330. * @throws \think\exception\DbException
  331. * @throws \think\exception\PDOException
  332. */
  333. public function ChromaticityAdd()
  334. {
  335. if ($this->request->isGet() === false) {
  336. $this->error('请求错误');
  337. }
  338. $param = $this->request->param();
  339. if (empty($param)) {
  340. $this->error('参数错误');
  341. }
  342. $list = db('绩效工资汇总')
  343. ->alias('a')
  344. ->join('工单_工艺资料 b','a.sczl_gdbh = b.Gy0_gdbh and a.sczl_yjno = b.Gy0_yjno and a.sczl_gxh = b.Gy0_gxh')
  345. ->join('设备_基本资料 c','a.sczl_jtbh = c.设备编号','LEFT')
  346. ->join('工单_印件资料 d','a.sczl_gdbh = d.Yj_Gdbh and a.sczl_yjno = d.yj_Yjno')
  347. ->field('a.sczl_gdbh as 工单编号,a.sczl_yjno as 印件号,a.sczl_gxh as 工序号,sum(a.班组车头产量) as 班组车头产量,b.Gy0_gxmc as 工序名称,
  348. a.sczl_ms as 墨色数,c.使用部门,b.印刷方式,b.版距,b.工价系数,a.sczl_jtbh,d.yj_yjmc as 印件名称,sum(a.车头产量占用机时) as 占用机时,a.sys_rq as 年月,
  349. a.工序难度系数,sum(a.班组换算产量) as 班组换算产量,a.千件工价')
  350. ->where('a.sys_ny', $param['month'])
  351. ->group('a.sczl_gdbh,a.sczl_yjno,a.sczl_gxh,a.sczl_jtbh')
  352. ->select();
  353. $data = [];
  354. foreach ($list as $k => $v) {
  355. if ($v['版距'] === '0.0'){
  356. $list[$k]['版距'] = 1000;
  357. }
  358. if ($v['墨色数'] === '0.00'){
  359. $list[$k]['墨色数'] = 1;
  360. }
  361. if (strpos($v['工序名称'],'切废')){
  362. $list[$k]['墨色数'] = 0.2;
  363. }
  364. $chanliang = $v['班组车头产量']*$v['工序难度系数'] + $v['班组换算产量'];
  365. $data[] = [
  366. '车间名称' => $v['使用部门'],
  367. 'sys_ny' => $param['month'],
  368. 'sczl_gdbh' => $v['工单编号'],
  369. '印件名称' => $v['印件名称'],
  370. 'sczl_yjno' => $v['印件号'],
  371. 'sczl_gxh' => $v['工序号'],
  372. '工序名称' => $v['工序名称'],
  373. 'sczl_jtbh' => $v['sczl_jtbh'],
  374. '卷张换算系数' => $list[$k]['版距']/1000,
  375. '占用机时' => $v['占用机时'],
  376. '班组车头产量' => $v['班组车头产量'],
  377. 'sczl_ms' => $list[$k]['墨色数'],
  378. '工序难度系数' => $v['工序难度系数'],
  379. '班组换算产量' => $v['班组换算产量'],
  380. '千件工价' => $v['千件工价'],
  381. '计件产量' => $chanliang,
  382. '水电分摊因子' => $v['占用机时'],
  383. '材料分摊因子' => $chanliang,
  384. '人工分摊因子' => ($chanliang/1000)*$v['千件工价'],
  385. 'Sys_id' => $param['sys_id'],
  386. 'Sys_rq' => date('Y-m-d H:i:s', time())
  387. ];
  388. }
  389. $sql = db('成本v23_月度成本明细')->fetchSql(true)->insertAll($data);
  390. $res = db()->query($sql);
  391. if ($res !== false) {
  392. $this->success('成功');
  393. }else{
  394. $this->error('失败');
  395. }
  396. }
  397. /**
  398. * 各月工单色度数
  399. * @return void
  400. * @throws \think\db\exception\BindParamException
  401. * @throws \think\db\exception\DataNotFoundException
  402. * @throws \think\db\exception\ModelNotFoundException
  403. * @throws \think\exception\DbException
  404. * @throws \think\exception\PDOException
  405. */
  406. public function ChromaticityDetailAdd()
  407. {
  408. if ($this->request->isGet() === false) {
  409. $this->error('请求错误');
  410. }
  411. $param = $this->request->param();
  412. if (empty($param)) {
  413. $this->error('参数错误');
  414. }
  415. $month = substr($param['month'], 0, 4) . '-' . substr($param['month'], 4, 2);
  416. $list = db('设备_产量计酬')
  417. ->alias('a')
  418. ->join('设备_基本资料 b','a.sczl_jtbh = b.设备编号')
  419. ->join('工单_工艺资料 c','a.sczl_gdbh = c.Gy0_gdbh and a.sczl_yjno = c.Gy0_yjno and a.sczl_gxh = c.Gy0_gxh')
  420. ->field('a.sczl_gdbh,a.sczl_yjno,a.sczl_gxh,a.sczl_jtbh,a.sczl_gxmc,sum(a.sczl_cl) as 产量,a.sczl_jtbh,a.sczl_ms,b.使用部门,
  421. sum(a.sczl_设备运行工时) as 通电工时,a.sczl_dedh,c.Gy0_gxmc')
  422. ->where('a.sczl_rq','like', $month.'%')
  423. ->group('a.sczl_gdbh,a.sczl_yjno,a.sczl_gxh,a.sczl_jtbh')
  424. ->select();
  425. if (empty($list)) {
  426. $this->error('没找到生产数据');
  427. }
  428. $data = [];
  429. foreach ($list as $k => $v) {
  430. if ($v['sczl_ms'] === '0.00'){
  431. $list[$k]['sczl_ms'] = 1;
  432. }
  433. if (strpos($v['Gy0_gxmc'],'切废') !== false){
  434. $list[$k]['sczl_ms'] = 0.2;
  435. }
  436. $data[] = [
  437. '年月' => $param['month'],
  438. 'sczl_gdbh' => $v['sczl_gdbh'],
  439. 'sczl_yjno' => $v['sczl_yjno'],
  440. 'sczl_gxh' => $v['sczl_gxh'],
  441. 'sczl_jtbh' => $v['sczl_jtbh'],
  442. 'sczl_gxmc' => $v['sczl_gxmc'],
  443. 'sczl_ms' => $v['sczl_ms'],
  444. 'sczl_dedh' => $v['sczl_dedh'],
  445. '通电时间' => $v['通电工时'],
  446. 'sczl_cl' => $v['产量'],
  447. '部门' => $v['使用部门'],
  448. 'Sys_ID' => $param['sys_id'],
  449. 'Sys_Rq' => date('Y-m-d H:i:s', time())
  450. ];
  451. }
  452. if (db('成本_各月色度数')->where('年月',$param['month'])->count() !== 0) {
  453. db('成本_各月色度数')->where('年月',$param['month'])->delete();
  454. }
  455. $sql = db('成本_各月色度数')->fetchSql(true)->insertAll($data);
  456. $res = db()->query($sql);
  457. if ($res !== false) {
  458. $this->success('成功');
  459. }else{
  460. $this->error('失败');
  461. }
  462. }
  463. /**
  464. * 各月车间色度数列表
  465. * @return void
  466. * @throws \think\db\exception\DataNotFoundException
  467. * @throws \think\db\exception\ModelNotFoundException
  468. * @throws \think\exception\DbException
  469. */
  470. public function ChromaticityDetailList()
  471. {
  472. if ($this->request->isGet() === false) {
  473. $this->error('请求错误');
  474. }
  475. $param = $this->request->param();
  476. if (empty($param)) {
  477. $this->error('参数错误');
  478. }
  479. // 执行统计查询
  480. $stats = db('成本_各月色度数')
  481. ->field([
  482. 'rtrim(部门) AS workshop',
  483. 'SUM(sczl_cl * IF(sczl_ms=0, 1, sczl_ms)) AS total'
  484. ])
  485. ->where('部门', '<>', '') // 过滤空车间数据
  486. ->where('sczl_cl', '>', 0) // 过滤无效产量
  487. ->where('年月', $param['month'])
  488. ->group('部门')
  489. ->select();
  490. // 构造中文返回结果
  491. $result = [];
  492. foreach ($stats as $item) {
  493. $result[] = [
  494. '年月' => $param['month'],
  495. '车间' => $item['workshop'],
  496. '色度数' => number_format($item['total'], 2)
  497. ];
  498. }
  499. $this->success('成功', $result);
  500. }
  501. /**
  502. * 车间色度数详情列表
  503. * @return void
  504. * @throws \think\db\exception\DataNotFoundException
  505. * @throws \think\db\exception\ModelNotFoundException
  506. * @throws \think\exception\DbException
  507. */
  508. public function MonochromaticDetailList()
  509. {
  510. if ($this->request->isGet() === false) {
  511. $this->error('请求错误');
  512. }
  513. $param = $this->request->param();
  514. if (empty($param)) {
  515. $this->error('参数错误');
  516. }
  517. $list = db('成本_各月色度数')
  518. ->where('年月', $param['month'])
  519. ->where('部门', $param['sist'])
  520. ->order('sczl_gdbh')
  521. ->select();
  522. $this->success('成功', $list);
  523. }
  524. /**
  525. * 车间成本核算汇总
  526. * @return void
  527. * @throws \think\db\exception\DataNotFoundException
  528. * @throws \think\db\exception\ModelNotFoundException
  529. * @throws \think\exception\DbException
  530. */
  531. public function SummaryCostAccountingList()
  532. {
  533. if ($this->request->isGet() === false) {
  534. $this->error('请求错误');
  535. }
  536. $param = $this->request->param();
  537. if (empty($param)) {
  538. $this->error('参数错误');
  539. }
  540. $list = db('成本v23_月度成本明细')
  541. ->where('车间名称', $param['sist'])
  542. ->where('sys_ny', $param['month'])
  543. ->order('sczl_gdbh')
  544. ->select();
  545. if (empty($list)) {
  546. $this->error('未找到数据');
  547. }else{
  548. $this->success('成功', $list);
  549. }
  550. }
  551. /**
  552. * 创建各月水电气分摊
  553. * @return void
  554. * @throws \think\db\exception\BindParamException
  555. * @throws \think\exception\PDOException
  556. */
  557. public function UtilitiesAdd()
  558. {
  559. if ($this->request->isPost() === false) {
  560. $this->error('请求错误');
  561. }
  562. $param = Request::instance()->post();
  563. if (empty($param)) {
  564. $this->error('参数错误');
  565. }
  566. $data = [];
  567. foreach ($param as $k => $v) {
  568. $data[] = [
  569. 'Sys_ny' => $v['sys_ny'],
  570. '部门名称' => $v['sist'],
  571. '费用类型' => '分摊',
  572. '科目名称' => $v['科目名称'],
  573. '耗电量' => $v['耗电量'],
  574. '单位电价' => $v['单位电价'],
  575. '耗气量' => $v['耗气量'],
  576. '单位气价' => $v['单位气价'],
  577. 'Sys_id' => $v['sys_id'],
  578. 'Sys_rq' => date('Y-m-d H:i:s', time())
  579. ];
  580. }
  581. $result = db('成本_各月水电气')->where('Sys_ny', $data[0]['sys_ny'])->where('费用类型','分摊')->delete();
  582. $sql = db('成本_各月水电气')->fetchSql(true)->insertAll($data);
  583. $res = db()->query($sql);
  584. if ($res !== false) {
  585. $this->success('成功');
  586. }else{
  587. $this->error('失败');
  588. }
  589. }
  590. /**
  591. * 各月水电气分摊费用列表
  592. * @return void
  593. * @throws \think\db\exception\DataNotFoundException
  594. * @throws \think\db\exception\ModelNotFoundException
  595. * @throws \think\exception\DbException
  596. */
  597. public function UtilitiesList()
  598. {
  599. if($this->request->isGet() === false){
  600. $this->error('请求错误');
  601. }
  602. $param = $this->request->param();
  603. if (empty($param)) {
  604. $this->error('参数错误');
  605. }
  606. $list = db('成本_各月水电气')
  607. ->field('rtrim(部门名称) as 部门名称,rtrim(科目名称) as 科目名称,耗电量,单位电价,耗气量,单位气价')
  608. ->where('费用类型', '分摊')
  609. ->where('Sys_ny', $param['month'])
  610. ->group('部门名称,科目名称')
  611. ->select();
  612. if (empty($list)) {
  613. $list = db('成本_各月水电气')
  614. ->field('rtrim(部门名称) as 部门名称,rtrim(科目名称) as 科目名称')
  615. ->where('费用类型', '分摊')
  616. ->group('部门名称,科目名称')
  617. ->select();
  618. }
  619. foreach ($list as $k => $v) {
  620. $list[$k]['年月'] = $param['month'];
  621. }
  622. $this->success('成功', $list);
  623. }
  624. /**
  625. * 成本汇总左侧列表
  626. * @return void
  627. */
  628. public function getSummaryTab()
  629. {
  630. if ($this->request->isGet() === false) {
  631. $this->error('请求错误');
  632. }
  633. $months = db('成本v23_月度成本明细')
  634. ->field('sys_ny AS year_month')
  635. ->group('Sys_ny')
  636. ->order('Sys_ny DESC')
  637. ->column('Sys_ny');
  638. $sist = ['胶印车间','凹丝印车间','印后车间','检验车间'];
  639. $data = [];
  640. foreach ($months as $month) {
  641. $data[$month] = $sist;
  642. }
  643. $this->success('成功', $data);
  644. }
  645. //计算每个车间色度数
  646. private function CountSistChromaticity($month,$sist)
  647. {
  648. $data = db('成本v23_月度成本明细')
  649. ->where('sys_ny', $month)
  650. ->where('车间名称', $sist)
  651. ->group('车间名称')
  652. ->value('班组车头产量*sczl_ms as 色度数');
  653. return $data;
  654. }
  655. //计算每个机台色度数
  656. private function CountMachineChromatic($month,$sist)
  657. {
  658. $data = db('成本v23_月度成本明细')
  659. ->where('sys_ny', $month)
  660. ->where('车间名称', $sist)
  661. ->group('sczl_jtbh')
  662. ->value('班组车头产量*sczl_ms as 色度数');
  663. return $data;
  664. }
  665. //水电气分摊费用下方明细列表
  666. // public function shuidianqiMachineDetailList()
  667. // {
  668. // if ($this->request->isGet() === false) {
  669. // $this->error('请求错误');
  670. // }
  671. // $param = $this->request->param();
  672. // if (empty($param)) {
  673. // $this->error('参数错误');
  674. // }
  675. // $sist = ['胶印车间','凹丝印车间','印后车间','检验车间'];
  676. // if (strpos($param['sist'],'车间') === false) {
  677. // $number = db('成本_各月水电气')
  678. // ->where('Sys_ny', $param['month'])
  679. // ->where('部门名称', $param['sist'])
  680. // ->where('费用类型', '分摊')
  681. // ->value('');
  682. // }else{
  683. // $machineList = db('设备_基本资料')
  684. // ->where('使用部门', $param['sist'])
  685. // ->where('sys_sbID', '<>', '')
  686. // ->order('设备编号')
  687. // ->column('设备编号');
  688. // }
  689. //
  690. // }
  691. //其他待摊费用
  692. public function PrepaidExpensesList()
  693. {
  694. if ($this->request->isGet() === false) {
  695. $this->error('请求错误');
  696. }
  697. $param = $this->request->param();
  698. if (empty($param)) {
  699. $this->error('参数错误');
  700. }
  701. }
  702. }