CostAccounting.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  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('成本v23_月度成本明细')
  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. 'Sys_id' => $value['sys_id'],
  75. 'Sys_rq' => date('Y-m-d H:i:s', time())
  76. ];
  77. }
  78. $sql = db('成本v23_各月人工')->fetchSql(true)->insertAll($data);
  79. $res = db()->query($sql);
  80. if ($res !== false) {
  81. $this->success('新增成功');
  82. }else{
  83. $this->error('添加失败');
  84. }
  85. }
  86. /**
  87. * 月度人工维护列表
  88. * @return void
  89. * @throws \think\db\exception\DataNotFoundException
  90. * @throws \think\db\exception\ModelNotFoundException
  91. * @throws \think\exception\DbException
  92. */
  93. public function ArtificialAddList()
  94. {
  95. if($this->request->isGet() === false){
  96. $this->error('请求错误');
  97. }
  98. $param = $this->request->param();
  99. if (empty($param) || empty($param['Sys_ny'])) {
  100. $this->error('参数错误');
  101. }
  102. $list = db('成本v23_各月人工')
  103. ->where('Sys_ny', $param['Sys_ny'])
  104. ->field('Sys_ny, 车间, 一线工资总额, Sys_id as 创建用户, Sys_rq as 创建时间,Mod_rq as 修订时间,UniqID')
  105. ->select();
  106. $this->success('成功', $list);
  107. }
  108. /**
  109. * 月度人工维护修改
  110. * @return void
  111. * @throws \think\Exception
  112. * @throws \think\db\exception\BindParamException
  113. * @throws \think\exception\PDOException
  114. */
  115. public function ArtificialEdit()
  116. {
  117. if($this->request->isPost() === false){
  118. $this->error('请求错误');
  119. }
  120. $param = Request::instance()->post();
  121. if (empty($param)) {
  122. $this->error('参数错误');
  123. }
  124. $i = 0;
  125. foreach ($param as $value) {
  126. $sql = db('成本v23_各月人工')
  127. ->where('UniqID', $value['UniqID'])
  128. ->fetchSql(true)
  129. ->update(['一线工资总额'=>$value['number'],'Mod_rq'=>date('Y-m-d H:i:s', time())]);
  130. $res = db()->query($sql);
  131. if ($res === false) {
  132. $i++;
  133. }
  134. }
  135. if ($i === 0) {
  136. $this->success('修改成功');
  137. }else{
  138. $this->error('修改失败');
  139. }
  140. }
  141. /**
  142. * 月度人工数据右侧上方列表
  143. * @return void
  144. * @throws \think\db\exception\DataNotFoundException
  145. * @throws \think\db\exception\ModelNotFoundException
  146. * @throws \think\exception\DbException
  147. */
  148. public function ArtificialList()
  149. {
  150. if (!$this->request->isGet()) {
  151. $this->error('仅支持GET请求');
  152. }
  153. $month = $this->request->param('month');
  154. if (empty($month)) {
  155. $this->error('month参数缺失或为空');
  156. }
  157. $list = db('成本v23_各月人工')->alias('a')
  158. ->join('设备_基本资料 b', 'a.车间 = b.使用部门')
  159. ->join('绩效工资汇总 c', 'a.Sys_ny = c.sys_ny AND c.sczl_jtbh = b.设备编号')
  160. ->join('成本_各月其他费用 d', 'a.Sys_ny = d.sys_ny','left')
  161. ->field([
  162. 'a.Sys_ny' => '年月',
  163. 'rtrim(a.车间)' => '车间',
  164. 'SUM(c.个人计件工资) + SUM(c.个人加班工资)' => '人工分摊因子总额',
  165. 'a.一线工资总额' => '车间实发工资',
  166. 'd.部门人员工资' => '部门人员工资实发',
  167. 'd.管理人员工资' => '管理人员工资实发'
  168. ])
  169. ->where('a.Sys_ny', $month)
  170. ->group('a.Sys_ny, a.车间')
  171. ->select();
  172. if (empty($list)) {
  173. $this->success('未找到匹配数据', []);
  174. }
  175. $this->success('获取成功', $list);
  176. }
  177. /**
  178. * 月度人工数据下方工单详情
  179. * @return void
  180. * @throws \think\db\exception\DataNotFoundException
  181. * @throws \think\db\exception\ModelNotFoundException
  182. * @throws \think\exception\DbException
  183. */
  184. public function ArtificialDetailList()
  185. {
  186. if ($this->request->isGet() === false) {
  187. $this->error('请求错误');
  188. }
  189. $param = $this->request->param();
  190. if (empty($param)) {
  191. $this->error('参数错误');
  192. }
  193. $month = $param['month'];
  194. $sist = $param['sist'];
  195. $list = db('工单_质量考核汇总')
  196. ->alias('a')
  197. ->join('设备_基本资料 b', 'a.sczl_jtbh = b.设备编号')
  198. ->join('工单_印件资料 c', 'a.Gy0_gdbh = c.Yj_Gdbh and a.印件及工序 = c.yj_Yjno')
  199. ->join('工单_工艺资料 d', 'a.Gy0_gdbh = d.Gy0_gdbh and a.印件及工序 = d.Gy0_yjno and a.工序 = d.Gy0_gxh')
  200. ->field([
  201. 'a.sys_ny' => '年月',
  202. 'a.Gy0_gdbh' => '工单编号',
  203. 'a.印件及工序' => '印件号',
  204. 'a.工序' => '工序号',
  205. 'c.yj_yjmc' => '印件名称',
  206. 'd.Gy0_gxmc' => '工序名称',
  207. 'a.印件工序产量' => '班组车头产量',
  208. 'd.工价系数' => '工序难度系数',
  209. 'SUM(a.CjsJe)' => '计件工资',
  210. 'rtrim(b.使用部门)' => '车间名称',
  211. ])
  212. ->where('a.Sys_ny', $month)
  213. ->where('b.使用部门', $sist)
  214. ->group('a.Sys_ny, a.Gy0_gdbh,a.印件及工序,a.印件及工序')
  215. ->order('a.Gy0_gdbh')
  216. ->select();
  217. if (empty($list)) {
  218. $this->success('未找到数据');
  219. }else{
  220. $this->success('成功', $list);
  221. }
  222. }
  223. /**
  224. * 水电气直接费用右侧列表
  225. * @return void
  226. * @throws \think\db\exception\DataNotFoundException
  227. * @throws \think\db\exception\ModelNotFoundException
  228. * @throws \think\exception\DbException
  229. */
  230. public function shuidianqiList()
  231. {
  232. if ($this->request->isGet() === false) {
  233. $this->error('请求错误');
  234. }
  235. $param = $this->request->param();
  236. if (empty($param)) {
  237. $this->error('参数错误');
  238. }
  239. $month = $param['month'];
  240. $sist = $param['sist'];
  241. $list = db('成本_各月水电气')
  242. ->field('rtrim(部门名称) as 部门名称,rtrim(设备编号) as 设备编号,rtrim(科目名称) as 设备名称,rtrim(耗电量) as 耗电量,
  243. rtrim(单位电价) as 单位电价,rtrim(耗气量) as 耗气量,rtrim(单位气价) as 单位气价,rtrim(Sys_id) as 创建用户,Sys_rq as 创建时间,UniqID,耗电量*单位电价 as 直接费用合计')
  244. ->where('Sys_ny', $month)
  245. ->where('部门名称', $sist)
  246. ->where('费用类型', '直接')
  247. ->group('Sys_ny, Sys_rq, UniqID')
  248. ->select();
  249. if (empty($list)) {
  250. $this->success('未找到数据');
  251. }else{
  252. $this->success('成功', $list);
  253. }
  254. }
  255. /**
  256. * 水电气下方工单详情
  257. * @return void
  258. * @throws \think\db\exception\DataNotFoundException
  259. * @throws \think\db\exception\ModelNotFoundException
  260. * @throws \think\exception\DbException
  261. */
  262. public function shuidianqiDetailList()
  263. {
  264. if ($this->request->isGet() === false) {
  265. $this->error('请求错误');
  266. }
  267. $param = $this->request->param();
  268. if (empty($param)) {
  269. $this->error('参数错误');
  270. }
  271. $month = substr($param['month'], 0, 4) . '-' . substr($param['month'], 4, 2);
  272. $machine = $param['machine'];
  273. $list = db('设备_产量计酬')
  274. ->alias('a')
  275. ->join('工单_印件资料 b', 'a.sczl_gdbh = b.Yj_Gdbh and a.sczl_yjno = b.yj_Yjno')
  276. ->field('a.sczl_gdbh as 工单编号,b.yj_yjmc as 印件名称,a.sczl_yjno as 印件号,a.sczl_gxh as 工序号,
  277. sum(a.sczl_cl)*a.sczl_ls as 班组车头产量,sum(a.sczl_设备运行工时) as 占用机时')
  278. ->where('a.sczl_rq','like', '%'.$month.'%')
  279. ->where('a.sczl_jtbh', $machine)
  280. ->group('a.sczl_gdbh, a.sczl_yjno, a.sczl_gxh')
  281. ->select();
  282. if (empty($list)) {
  283. $this->success('未找到数据');
  284. }
  285. foreach ($list as $k => $v) {
  286. $list[$k]['计件产量'] = $v['班组车头产量'];
  287. $list[$k]['水电气分摊因子'] = $v['占用机时'];
  288. $list[$k]['年月'] = $param['month'];
  289. }
  290. $this->success('成功', $list);
  291. }
  292. /**
  293. * 水电气分摊费用
  294. * @return void
  295. * @throws \think\db\exception\DataNotFoundException
  296. * @throws \think\db\exception\ModelNotFoundException
  297. * @throws \think\exception\DbException
  298. */
  299. public function shuidianqifentanList()
  300. {
  301. if ($this->request->isGet() === false) {
  302. $this->error('请求错误');
  303. }
  304. $param = $this->request->param();
  305. if (empty($param)) {
  306. $this->error('参数错误');
  307. }
  308. $month = $param['month'];
  309. $list = db('成本_各月水电气')
  310. ->field('rtrim(部门名称) as 部门名称,rtrim(设备编号) as 设备编号,rtrim(科目名称) as 设备名称,rtrim(耗电量) as 耗电量,
  311. rtrim(单位电价) as 单位电价,rtrim(耗气量) as 耗气量,rtrim(单位气价) as 单位气价,rtrim(Sys_id) as 创建用户,Sys_rq as 创建时间,UniqID,耗电量*单位电价 as 直接费用合计')
  312. ->where('Sys_ny', $month)
  313. ->where('费用类型', '分摊')
  314. ->group('Sys_ny, Sys_rq, UniqID')
  315. ->select();
  316. if (empty($list)) {
  317. $this->success('未找到数据');
  318. }else{
  319. $this->success('成功', $list);
  320. }
  321. }
  322. /**
  323. * 各月工单人工明细
  324. * @return void
  325. * @throws \think\db\exception\BindParamException
  326. * @throws \think\db\exception\DataNotFoundException
  327. * @throws \think\db\exception\ModelNotFoundException
  328. * @throws \think\exception\DbException
  329. * @throws \think\exception\PDOException
  330. */
  331. public function ChromaticityAdd()
  332. {
  333. if ($this->request->isGet() === false) {
  334. $this->error('请求错误');
  335. }
  336. $param = $this->request->param();
  337. if (empty($param)) {
  338. $this->error('参数错误');
  339. }
  340. $list = db('绩效工资汇总')
  341. ->alias('a')
  342. ->join('工单_工艺资料 b','a.sczl_gdbh = b.Gy0_gdbh and a.sczl_yjno = b.Gy0_yjno and a.sczl_gxh = b.Gy0_gxh')
  343. ->join('设备_基本资料 c','a.sczl_jtbh = c.设备编号','LEFT')
  344. ->join('工单_印件资料 d','a.sczl_gdbh = d.Yj_Gdbh and a.sczl_yjno = d.yj_Yjno')
  345. ->field('a.sczl_gdbh as 工单编号,a.sczl_yjno as 印件号,a.sczl_gxh as 工序号,sum(a.班组车头产量) as 班组车头产量,b.Gy0_gxmc as 工序名称,
  346. a.sczl_ms as 墨色数,c.使用部门,b.印刷方式,b.版距,b.工价系数,a.sczl_jtbh,d.yj_yjmc as 印件名称,sum(a.车头产量占用机时) as 占用机时,a.sys_rq as 年月,
  347. a.工序难度系数,sum(a.班组换算产量) as 班组换算产量,a.千件工价')
  348. ->where('a.sys_ny', $param['month'])
  349. ->group('a.sczl_gdbh,a.sczl_yjno,a.sczl_gxh,a.sczl_jtbh')
  350. ->select();
  351. $data = [];
  352. foreach ($list as $k => $v) {
  353. if ($v['版距'] === '0.0'){
  354. $list[$k]['版距'] = 1000;
  355. }
  356. if ($v['墨色数'] === '0.00'){
  357. $list[$k]['墨色数'] = 1;
  358. }
  359. if (strpos($v['工序名称'],'切废')){
  360. $list[$k]['墨色数'] = 0.2;
  361. }
  362. $chanliang = $v['班组车头产量']*$v['工序难度系数'] + $v['班组换算产量'];
  363. $data[] = [
  364. '车间名称' => $v['使用部门'],
  365. 'sys_ny' => $param['month'],
  366. 'sczl_gdbh' => $v['工单编号'],
  367. '印件名称' => $v['印件名称'],
  368. 'sczl_yjno' => $v['印件号'],
  369. 'sczl_gxh' => $v['工序号'],
  370. '工序名称' => $v['工序名称'],
  371. 'sczl_jtbh' => $v['sczl_jtbh'],
  372. '卷张换算系数' => $list[$k]['版距']/1000,
  373. '占用机时' => $v['占用机时'],
  374. '班组车头产量' => $v['班组车头产量'],
  375. 'sczl_ms' => $list[$k]['墨色数'],
  376. '工序难度系数' => $v['工序难度系数'],
  377. '班组换算产量' => $v['班组换算产量'],
  378. '千件工价' => $v['千件工价'],
  379. '计件产量' => $chanliang,
  380. '水电分摊因子' => $v['占用机时'],
  381. '材料分摊因子' => $chanliang,
  382. '人工分摊因子' => ($chanliang/1000)*$v['千件工价'],
  383. 'Sys_id' => $param['sys_id'],
  384. 'Sys_rq' => date('Y-m-d H:i:s', time())
  385. ];
  386. }
  387. $sql = db('成本v23_月度成本明细')->fetchSql(true)->insertAll($data);
  388. $res = db()->query($sql);
  389. if ($res !== false) {
  390. $this->success('成功');
  391. }else{
  392. $this->error('失败');
  393. }
  394. }
  395. /**
  396. * 各月工单色度数
  397. * @return void
  398. * @throws \think\db\exception\BindParamException
  399. * @throws \think\db\exception\DataNotFoundException
  400. * @throws \think\db\exception\ModelNotFoundException
  401. * @throws \think\exception\DbException
  402. * @throws \think\exception\PDOException
  403. */
  404. public function ChromaticityDetailAdd()
  405. {
  406. if ($this->request->isGet() === false) {
  407. $this->error('请求错误');
  408. }
  409. $param = $this->request->param();
  410. if (empty($param)) {
  411. $this->error('参数错误');
  412. }
  413. $monthArr = db('成本v23_月度成本明细')->where(['sys_ny' => $param['month']])->select();
  414. if (empty($monthArr)) {
  415. $this->error('请先创建月度数据...');
  416. }
  417. $sist = ['胶印车间','凹丝印车间','印后车间','检验车间'];
  418. $list = db('成本v23_月度成本明细')
  419. ->alias('a')
  420. ->join('设备_基本资料 b','a.sczl_jtbh = b.设备编号')
  421. ->join('工单_工艺资料 c','a.sczl_gdbh = c.Gy0_gdbh and a.sczl_yjno = c.Gy0_yjno and a.sczl_gxh = c.Gy0_gxh')
  422. ->field('a.sczl_gdbh,a.sczl_yjno,a.sczl_gxh,a.sczl_jtbh,a.工序名称,sum(a.计件产量) as 产量,a.sczl_jtbh,a.sczl_ms,b.使用部门,
  423. sum(a.占用机时) as 通电工时,c.Gy0_dedh,c.Gy0_gxmc')
  424. ->where('a.sys_ny', $param['month'])
  425. ->whereIn('车间名称',$sist)
  426. ->group('a.sczl_gdbh,a.sczl_yjno,a.sczl_gxh,a.sczl_jtbh')
  427. ->select();
  428. if (empty($list)) {
  429. $this->error('没找到生产数据');
  430. }
  431. $data = [];
  432. foreach ($list as $k => $v) {
  433. if ($v['sczl_ms'] === '0.00'){
  434. $list[$k]['sczl_ms'] = 1;
  435. }
  436. if (strpos($v['Gy0_gxmc'],'切废') !== false){
  437. $list[$k]['sczl_ms'] = 0.2;
  438. }
  439. $data[] = [
  440. '年月' => $param['month'],
  441. 'sczl_gdbh' => $v['sczl_gdbh'],
  442. 'sczl_yjno' => $v['sczl_yjno'],
  443. 'sczl_gxh' => $v['sczl_gxh'],
  444. 'sczl_jtbh' => $v['sczl_jtbh'],
  445. 'sczl_gxmc' => $v['工序名称'],
  446. 'sczl_ms' => $v['sczl_ms'],
  447. 'sczl_dedh' => $v['Gy0_dedh'],
  448. '通电时间' => $v['通电工时'],
  449. 'sczl_cl' => $v['产量'],
  450. '部门' => $v['使用部门'],
  451. 'Sys_ID' => $param['sys_id'],
  452. 'Sys_Rq' => date('Y-m-d H:i:s', time())
  453. ];
  454. }
  455. if (db('成本_各月色度数')->where('年月',$param['month'])->count() !== 0) {
  456. db('成本_各月色度数')->where('年月',$param['month'])->delete();
  457. }
  458. $sql = db('成本_各月色度数')->fetchSql(true)->insertAll($data);
  459. $res = db()->query($sql);
  460. if ($res !== false) {
  461. $this->success('成功');
  462. }else{
  463. $this->error('失败');
  464. }
  465. }
  466. /**
  467. * 各月车间色度数列表
  468. * @return void
  469. * @throws \think\db\exception\DataNotFoundException
  470. * @throws \think\db\exception\ModelNotFoundException
  471. * @throws \think\exception\DbException
  472. */
  473. public function ChromaticityDetailList()
  474. {
  475. if ($this->request->isGet() === false) {
  476. $this->error('请求错误');
  477. }
  478. $param = $this->request->param();
  479. if (empty($param)) {
  480. $this->error('参数错误');
  481. }
  482. // 执行统计查询
  483. $stats = db('成本_各月色度数')
  484. ->field([
  485. 'rtrim(部门) AS workshop',
  486. 'SUM(sczl_cl * IF(sczl_ms=0, 1, sczl_ms)) AS total'
  487. ])
  488. ->where('部门', '<>', '') // 过滤空车间数据
  489. ->where('sczl_cl', '>', 0) // 过滤无效产量
  490. ->where('年月', $param['month'])
  491. ->group('部门')
  492. ->select();
  493. // 构造中文返回结果
  494. $result = [];
  495. foreach ($stats as $item) {
  496. $result[] = [
  497. '年月' => $param['month'],
  498. '车间' => $item['workshop'],
  499. '色度数' => number_format($item['total'], 2)
  500. ];
  501. }
  502. $this->success('成功', $result);
  503. }
  504. /**
  505. * 车间色度数详情列表
  506. * @return void
  507. * @throws \think\db\exception\DataNotFoundException
  508. * @throws \think\db\exception\ModelNotFoundException
  509. * @throws \think\exception\DbException
  510. */
  511. public function MonochromaticDetailList()
  512. {
  513. if ($this->request->isGet() === false) {
  514. $this->error('请求错误');
  515. }
  516. $param = $this->request->param();
  517. if (empty($param)) {
  518. $this->error('参数错误');
  519. }
  520. $list = db('成本_各月色度数')
  521. ->where('年月', $param['month'])
  522. ->where('部门', $param['sist'])
  523. ->order('sczl_gdbh')
  524. ->select();
  525. $this->success('成功', $list);
  526. }
  527. /**
  528. * 车间成本核算汇总
  529. * @return void
  530. * @throws \think\db\exception\DataNotFoundException
  531. * @throws \think\db\exception\ModelNotFoundException
  532. * @throws \think\exception\DbException
  533. */
  534. public function SummaryCostAccountingList()
  535. {
  536. if ($this->request->isGet() === false) {
  537. $this->error('请求错误');
  538. }
  539. $param = $this->request->param();
  540. if (empty($param)) {
  541. $this->error('参数错误');
  542. }
  543. $page = $this->request->param('page', 1);
  544. $pageSize = $this->request->param('limit', 30);
  545. $total = db('成本v23_月度成本明细')
  546. ->where('车间名称', $param['sist'])
  547. ->where('sys_ny', $param['month'])
  548. ->count();
  549. $list = db('成本v23_月度成本明细')
  550. ->where('车间名称', $param['sist'])
  551. ->where('sys_ny', $param['month'])
  552. ->order('sczl_gdbh')
  553. ->page($page, $pageSize)
  554. ->select();
  555. $data = [
  556. 'total' => $total,
  557. 'list' => $list,
  558. ];
  559. if (empty($list)) {
  560. $this->error('未找到数据');
  561. }else{
  562. $this->success('成功', $data);
  563. }
  564. }
  565. /**
  566. * 创建各月水电气分摊
  567. * @return void
  568. * @throws \think\db\exception\BindParamException
  569. * @throws \think\exception\PDOException
  570. */
  571. public function UtilitiesAdd()
  572. {
  573. if ($this->request->isPost() === false) {
  574. $this->error('请求错误');
  575. }
  576. $param = Request::instance()->post();
  577. if (empty($param)) {
  578. $this->error('参数错误');
  579. }
  580. $data = [];
  581. $currentTime = date('Y-m-d H:i:s');
  582. foreach ($param as $item) {
  583. // 验证必要字段是否存在
  584. if (empty($item['sys_ny']) || empty($item['sist']) || empty($item['科目名称'])) {
  585. $this->error('缺少必要参数');
  586. }
  587. // 确保数值字段正确处理为 decimal 类型
  588. $data[] = [
  589. 'Sys_ny' => $item['sys_ny'],
  590. '部门名称' => $item['sist'],
  591. '费用类型' => '分摊',
  592. '科目名称' => $item['科目名称'],
  593. '耗电量' => isset($item['耗电量']) ? (float)$item['耗电量'] : 0.00,
  594. '单位电价' => isset($item['单位电价']) ? (float)$item['单位电价'] : 0.00,
  595. '耗气量' => isset($item['耗气量']) ? (float)$item['耗气量'] : 0.00,
  596. '单位气价' => isset($item['单位气价']) ? (float)$item['单位气价'] : 0.00,
  597. 'Sys_id' => $item['sys_id'] ?? '',
  598. 'Sys_rq' => $currentTime
  599. ];
  600. }
  601. $result = db('成本_各月水电气')->where('Sys_ny', $data[0]['Sys_ny'])->where('费用类型','分摊')->delete();
  602. $sql = db('成本_各月水电气')->fetchSql(true)->insertAll($data);
  603. $res = db()->query($sql);
  604. if ($res !== false) {
  605. $this->success('成功');
  606. }else{
  607. $this->error('失败');
  608. }
  609. }
  610. /**
  611. * 各月水电气分摊费用列表
  612. * @return void
  613. * @throws \think\db\exception\DataNotFoundException
  614. * @throws \think\db\exception\ModelNotFoundException
  615. * @throws \think\exception\DbException
  616. */
  617. public function UtilitiesList()
  618. {
  619. if($this->request->isGet() === false){
  620. $this->error('请求错误');
  621. }
  622. $param = $this->request->param();
  623. if (empty($param)) {
  624. $this->error('参数错误');
  625. }
  626. $list = db('成本_各月水电气')
  627. ->field('rtrim(部门名称) as 部门名称,rtrim(科目名称) as 科目名称,耗电量,单位电价,耗气量,单位气价')
  628. ->where('费用类型', '分摊')
  629. ->where('Sys_ny', $param['month'])
  630. ->group('部门名称,科目名称')
  631. ->select();
  632. if (empty($list)) {
  633. $list = db('成本_各月水电气')
  634. ->field('rtrim(部门名称) as 部门名称,rtrim(科目名称) as 科目名称')
  635. ->where('费用类型', '分摊')
  636. ->group('部门名称,科目名称')
  637. ->select();
  638. }
  639. foreach ($list as $k => $v) {
  640. $list[$k]['年月'] = $param['month'];
  641. }
  642. $this->success('成功', $list);
  643. }
  644. /**
  645. * 成本汇总左侧列表
  646. * @return void
  647. */
  648. public function getSummaryTab()
  649. {
  650. if ($this->request->isGet() === false) {
  651. $this->error('请求错误');
  652. }
  653. $months = db('成本v23_月度成本明细')
  654. ->field('sys_ny AS year_month')
  655. ->group('Sys_ny')
  656. ->order('Sys_ny DESC')
  657. ->column('Sys_ny');
  658. $sist = ['胶印车间','凹丝印车间','印后车间','检验车间'];
  659. $data = [];
  660. foreach ($months as $month) {
  661. $data[$month] = $sist;
  662. }
  663. $this->success('成功', $data);
  664. }
  665. //计算每个车间色度数
  666. private function CountSistChromaticity($month,$sist)
  667. {
  668. $data = db('成本v23_月度成本明细')
  669. ->where('sys_ny', $month)
  670. ->where('车间名称', $sist)
  671. ->group('车间名称')
  672. ->value('班组车头产量*sczl_ms as 色度数');
  673. return $data;
  674. }
  675. //计算每个机台色度数
  676. private function CountMachineChromatic($month,$sist)
  677. {
  678. $data = db('成本v23_月度成本明细')
  679. ->where('sys_ny', $month)
  680. ->where('车间名称', $sist)
  681. ->group('sczl_jtbh')
  682. ->value('班组车头产量*sczl_ms as 色度数');
  683. return $data;
  684. }
  685. //水电气分摊费用下方明细列表
  686. // public function shuidianqiMachineDetailList()
  687. // {
  688. // if ($this->request->isGet() === false) {
  689. // $this->error('请求错误');
  690. // }
  691. // $param = $this->request->param();
  692. // if (empty($param)) {
  693. // $this->error('参数错误');
  694. // }
  695. // $list = db('设备_基本资料')
  696. // ->alias('a')
  697. // ->join('成本_各月分摊系数 b', 'a.设备编号 = b.设备编号', 'LEFT')
  698. // ->field()
  699. //
  700. // }
  701. /**
  702. * 其他待摊费用
  703. * @return void
  704. * @throws \think\db\exception\BindParamException
  705. * @throws \think\exception\PDOException
  706. */
  707. public function PrepaidExpensesListEdit()
  708. {
  709. if ($this->request->isPost() === false) {
  710. $this->error('请求错误');
  711. }
  712. $param = Request::instance()->post();
  713. if (empty($param)) {
  714. $this->error('参数错误');
  715. }
  716. $data = [
  717. 'sys_ny' => $param['month'],
  718. '部门人员工资' => $param['salary1'],
  719. '管理人员工资' => $param['salary2'],
  720. '场地租金' => $param['rental'],
  721. '待摊折旧' => $param['depreciation'],
  722. '工资成本占比' => $param['proportion'],
  723. '其他' => $param['rest'],
  724. '后勤人员工资' => $param['profit'],
  725. 'sys_id' => $param['sys_id'],
  726. ];
  727. $result = db('成本_各月其他费用')->where('sys_ny', $param['month'])->count();
  728. if ($result > 0) {
  729. $data['mod_rq'] = date('Y-m-d H:i:s', time());
  730. $sql = db('成本_各月其他费用')->where('sys_ny', $param['month'])->fetchSql(true)->update($data);
  731. }else{
  732. $data['sys_rq'] = date('Y-m-d H:i:s', time());
  733. $sql = db('成本_各月其他费用')
  734. ->fetchSql(true)
  735. ->insert($data);
  736. }
  737. $res = db()->query($sql);
  738. if ($res !== false) {
  739. $this->success('成功');
  740. }else{
  741. $this->error('失败');
  742. }
  743. }
  744. /**
  745. * 其他待摊费用列表
  746. * @return void
  747. * @throws \think\db\exception\DataNotFoundException
  748. * @throws \think\db\exception\ModelNotFoundException
  749. * @throws \think\exception\DbException
  750. */
  751. public function PrepaidExpensesList()
  752. {
  753. if ($this->request->isGet() === false) {
  754. $this->error('请求错误');
  755. }
  756. $param = $this->request->param();
  757. if (empty($param)) {
  758. $this->error('参数错误');
  759. }
  760. $list = db('成本_各月其他费用')
  761. ->where('sys_ny', $param['month'])
  762. ->field('sys_ny as 年月,部门人员工资,管理人员工资,场地租金,待摊折旧,工资成本占比,其他,后勤人员工资,sys_id as 创建用户,sys_rq as 创建时间,mod_rq as 修改时间,UniqID')
  763. ->find();
  764. if (empty($list)) {
  765. $this->error('未找到数据');
  766. }else{
  767. $this->success('成功', $list);
  768. }
  769. }
  770. /**
  771. * 参考其他费用参考月份
  772. * @return void
  773. * @throws \think\db\exception\BindParamException
  774. * @throws \think\db\exception\DataNotFoundException
  775. * @throws \think\db\exception\ModelNotFoundException
  776. * @throws \think\exception\DbException
  777. * @throws \think\exception\PDOException
  778. */
  779. public function PrepaidExpensesDetailCopy()
  780. {
  781. if ($this->request->isGet() === false) {
  782. $this->error('请求错误');
  783. }
  784. $param = $this->request->param();
  785. if (empty($param)) {
  786. $this->error('参数错误');
  787. }
  788. $formMonth = $param['formMonth'];
  789. $toMonth = $param['toMonth'];
  790. $list = db('成本_各月其他费用')
  791. ->where('sys_ny', $formMonth)
  792. ->field('管理人员工资,场地租金,待摊折旧,工资成本占比,后勤人员工资')
  793. ->find();
  794. $list['sys_ny'] = $toMonth;
  795. $list['sys_id'] = $param['sys_id'];
  796. $list['sys_rq'] = date('Y-m-d H:i:s', time());
  797. $sql = db('成本_各月其他费用')
  798. ->fetchSql(true)
  799. ->insert($list);
  800. $res = db()->query($sql);
  801. if ($res !== false) {
  802. $this->success('成功');
  803. }else{
  804. $this->error('失败');
  805. }
  806. }
  807. /**
  808. * 各月水电气直接费用创建
  809. * @return void
  810. * @throws \think\db\exception\BindParamException
  811. * @throws \think\db\exception\DataNotFoundException
  812. * @throws \think\db\exception\ModelNotFoundException
  813. * @throws \think\exception\DbException
  814. * @throws \think\exception\PDOException
  815. */
  816. public function shuidianqiDetailAdd()
  817. {
  818. if ($this->request->isGet() === false) {
  819. $this->error('请求错误');
  820. }
  821. $param = $this->request->param();
  822. if (empty($param)) {
  823. $this->error('参数错误');
  824. }
  825. $month = substr($param['month'], 0, 4) . '-' . substr($param['month'], 4, 2);
  826. $sist = ['胶印车间','凹丝印车间','印后车间'];
  827. $list = db('设备_产量计酬')
  828. ->alias('a')
  829. ->join('设备_基本资料 b', 'a.sczl_jtbh = b.设备编号')
  830. ->where('a.sczl_rq', 'like', $month . '%')
  831. ->where('b.sys_sbID','<>','')
  832. ->where('b.使用部门','in',$sist)
  833. ->field('a.sczl_jtbh,sum(a.sczl_设备运行工时) as 通电工时,b.使用部门,rtrim(b.设备名称) as 设备名称')
  834. ->order('b.使用部门,a.sczl_jtbh')
  835. ->group('a.sczl_jtbh')
  836. ->select();
  837. $data = [];
  838. foreach ($list as $k => $v) {
  839. $data[] = [
  840. 'Sys_ny' => $param['month'],
  841. '部门名称' => $v['使用部门'],
  842. '费用类型' => '直接',
  843. '设备编号' => $v['sczl_jtbh'],
  844. '科目名称' => $v['设备名称'],
  845. '耗电量' => $v['通电工时'],
  846. '单位电价' => 0.69,
  847. 'Sys_id' => $param['sys_id'],
  848. 'Sys_rq' => date('Y-m-d H:i:s', time()),
  849. ];
  850. }
  851. $sql = db('成本_各月水电气')->fetchSql(true)->insertAll($data);
  852. $res = db()->query($sql);
  853. if ($res !== false) {
  854. $this->success('成功');
  855. }else{
  856. $this->error('失败');
  857. }
  858. }
  859. /**
  860. * 获取各车间人工分摊因子比例
  861. * @param string $month 年月
  862. * @return array
  863. */
  864. protected function WageRatio($month)
  865. {
  866. try {
  867. // 使用一次查询获取所有需要的数据
  868. $result = db('成本v23_月度成本明细')
  869. ->where('sys_ny', $month)
  870. ->whereNotNull('车间名称')
  871. ->field('
  872. SUM(人工分摊因子) as total,
  873. rtrim(车间名称) as workshop_name,
  874. SUM(人工分摊因子) as workshop_total
  875. ')
  876. ->group('车间名称')
  877. ->select();
  878. if (empty($result)) {
  879. return [];
  880. }
  881. // 计算总人工分摊因子
  882. $total = array_sum(array_column($result, 'workshop_total'));
  883. // 计算每个车间的比例
  884. $data = [];
  885. foreach ($result as $item) {
  886. if ($total > 0) {
  887. $data[$item['workshop_name']] = number_format($item['workshop_total'] / $total, 2);
  888. } else {
  889. $data[$item['workshop_name']] = 0;
  890. }
  891. }
  892. return $data;
  893. } catch (\Exception $e) {
  894. // 记录日志
  895. \think\facade\Log::error('WageRatio计算失败: ' . $e->getMessage());
  896. return [];
  897. }
  898. }
  899. /**
  900. * 获取指定部门各月的色度数数据
  901. * @param string $month 年月
  902. * @param string $sist 部门
  903. * @return array
  904. */
  905. protected function WageRatioMonth($month, $sist)
  906. {
  907. try {
  908. // 使用一次查询获取数据和总数
  909. $query = db('成本_各月色度数')
  910. ->where(['年月' => $month, '部门' => $sist]);
  911. // 计算总数
  912. $total = $query->value('SUM(sczl_cl * CASE
  913. WHEN sczl_ms = 0 OR sczl_ms IS NULL OR sczl_ms = \'\' THEN 1
  914. ELSE sczl_ms
  915. END)');
  916. // 获取列表数据
  917. $list = $query->field("
  918. sczl_gdbh,
  919. sczl_yjno,
  920. sczl_gxh,
  921. sczl_jtbh,
  922. sczl_cl,
  923. CASE
  924. WHEN sczl_ms = 0 OR sczl_ms IS NULL OR sczl_ms = ''
  925. THEN 1
  926. ELSE sczl_ms
  927. END as sczl_ms
  928. ")->select();
  929. return [
  930. 'total' => $total ?: 0, // 防止空值
  931. 'list' => $list ?: [], // 防止空值
  932. ];
  933. } catch (\Exception $e) {
  934. \think\facade\Log::error('WageRatioMonth查询失败: ' . $e->getMessage());
  935. return ['total' => 0, 'list' => []];
  936. }
  937. }
  938. /**
  939. * 计算工资分配
  940. * @param string $month 年月
  941. * @param string $sist 部门
  942. * @param float $ratio 比例
  943. * @param string $type 类型
  944. * @param float $amount 金额
  945. * @return array
  946. */
  947. protected function WageRatioCalculation($month, $sist, $ratio, $type, $amount)
  948. {
  949. try {
  950. $data = [];
  951. $chromaNumber = $this->WageRatioMonth($month, $sist);
  952. if (empty($chromaNumber['list']) || $chromaNumber['total'] == 0) {
  953. return [];
  954. }
  955. $money = $ratio * $amount;
  956. $name = $type === '部门人员工资' ? '车间人工' : '部门人工附加';
  957. foreach ($chromaNumber['list'] as $item) {
  958. if ($chromaNumber['total'] > 0) {
  959. $perAmount = ($item['sczl_cl'] * $item['sczl_ms'] / $chromaNumber['total']) * $money;
  960. $data[] = [
  961. 'name' => $name,
  962. 'money' => round($perAmount, 2),
  963. 'sczl_gdbh' => $item['sczl_gdbh'],
  964. 'sczl_yjno' => $item['sczl_yjno'],
  965. 'sczl_gxh' => $item['sczl_gxh'],
  966. 'sczl_jtbh' => $item['sczl_jtbh'],
  967. ];
  968. }
  969. }
  970. return $data;
  971. } catch (\Exception $e) {
  972. \think\facade\Log::error('WageRatioCalculation计算失败: ' . $e->getMessage());
  973. return [];
  974. }
  975. }
  976. /**
  977. * 工资费用分配主函数(优化版)
  978. */
  979. public function WageExpensesList()
  980. {
  981. // 参数验证
  982. if (!$this->request->isGet()) {
  983. throw new \Exception('请求错误,仅支持GET请求');
  984. }
  985. $param = $this->request->param();
  986. if (empty($param) || !isset($param['month'])) {
  987. throw new \Exception('参数错误,缺少必要参数');
  988. }
  989. $month = trim($param['month']);
  990. // 获取工资比例
  991. $wageRatio = $this->WageRatio($month);
  992. if (empty($wageRatio)) {
  993. throw new \Exception('未找到该月的人工分摊因子数据');
  994. }
  995. // 获取月度工资数据
  996. $monthWage = db('成本_各月其他费用')
  997. ->where('sys_ny', $month)
  998. ->field('部门人员工资,管理人员工资')
  999. ->find();
  1000. if (empty($monthWage)) {
  1001. throw new \Exception('未找到该月的工资数据');
  1002. }
  1003. // 准备批量更新数据
  1004. $updateData = [];
  1005. $updateCount = 0;
  1006. // 遍历所有车间
  1007. foreach ($wageRatio as $workshopName => $ratio) {
  1008. // 计算两种类型的工资分配
  1009. $updateTypes = [
  1010. '部门人员工资' => '车间人工',
  1011. '管理人员工资' => '部门人工附加'
  1012. ];
  1013. foreach ($updateTypes as $wageType => $fieldName) {
  1014. if (!isset($monthWage[$wageType])) {
  1015. continue;
  1016. }
  1017. $calculatedData = $this->WageRatioCalculation(
  1018. $month,
  1019. $workshopName,
  1020. $ratio,
  1021. $wageType,
  1022. $monthWage[$wageType]
  1023. );
  1024. // 收集更新数据
  1025. foreach ($calculatedData as $item) {
  1026. if (!empty($item['sczl_gdbh'])) {
  1027. // 构建唯一标识作为更新条件
  1028. $conditions = [
  1029. 'sczl_gdbh' => $item['sczl_gdbh'],
  1030. 'sczl_gxh' => $item['sczl_gxh'] ?? null,
  1031. 'sczl_jtbh' => $item['sczl_jtbh'] ?? null,
  1032. 'sczl_yjno' => $item['sczl_yjno'] ?? null,
  1033. ];
  1034. // 生成唯一标识字符串
  1035. $uniqCondition = http_build_query(array_filter($conditions));
  1036. $updateData[] = [
  1037. 'condition' => $uniqCondition, // 用于去重的条件
  1038. 'conditions' => $conditions, // 实际查询条件
  1039. 'field' => $item['name'],
  1040. 'value' => $item['money'],
  1041. 'month' => $month
  1042. ];
  1043. $updateCount++;
  1044. }
  1045. }
  1046. }
  1047. }
  1048. // 批量更新
  1049. $updatedRows = $this->batchUpdateData($updateData,$month);
  1050. // 返回成功结果
  1051. return json([
  1052. 'code' => 200,
  1053. 'msg' => '工资分配完成',
  1054. 'data' => [
  1055. 'updated_rows' => $updatedRows,
  1056. 'update_count' => $updateCount,
  1057. 'workshop_count' => count($wageRatio)
  1058. ]
  1059. ]);
  1060. }
  1061. /**
  1062. * 批量更新数据(原生SQL版本)
  1063. * @param array $updateData 更新数据
  1064. * @param string $month 月份
  1065. * @return int 更新的行数
  1066. */
  1067. private function batchUpdateData(array $updateData, string $month)
  1068. {
  1069. if (empty($updateData)) {
  1070. return 0;
  1071. }
  1072. $updatedRows = 0;
  1073. // 按字段分组
  1074. $groupedData = [];
  1075. foreach ($updateData as $item) {
  1076. $field = $item['field'];
  1077. $groupedData[$field][] = $item;
  1078. }
  1079. // 对每个字段进行批量更新
  1080. foreach ($groupedData as $field => $items) {
  1081. // 构建CASE WHEN语句
  1082. $caseWhens = [];
  1083. $gdbhList = [];
  1084. foreach ($items as $item) {
  1085. $baseCondition = "sczl_gdbh = '{$item['conditions']['sczl_gdbh']}'";
  1086. // 添加其他可选条件
  1087. $conditions = [$baseCondition];
  1088. if (!empty($item['conditions']['sczl_gxh'])) {
  1089. $conditions[] = "sczl_gxh = '{$item['conditions']['sczl_gxh']}'";
  1090. }
  1091. if (!empty($item['conditions']['sczl_jtbh'])) {
  1092. $conditions[] = "sczl_jtbh = '{$item['conditions']['sczl_jtbh']}'";
  1093. }
  1094. if (!empty($item['conditions']['sczl_yjno'])) {
  1095. $conditions[] = "sczl_yjno = '{$item['conditions']['sczl_yjno']}'";
  1096. }
  1097. $whenCondition = implode(' AND ', $conditions);
  1098. $caseWhens[] = "WHEN {$whenCondition} THEN {$item['value']}";
  1099. $gdbhList[] = $item['conditions']['sczl_gdbh'];
  1100. }
  1101. if (empty($caseWhens)) {
  1102. continue;
  1103. }
  1104. // 去重
  1105. $gdbhList = array_unique($gdbhList);
  1106. $gdbhStr = implode("','", $gdbhList);
  1107. $caseStr = implode(' ', $caseWhens);
  1108. // 构建SQL
  1109. $sql = "UPDATE 成本v23_月度成本明细
  1110. SET {$field} = CASE {$caseStr} ELSE {$field} END
  1111. WHERE sczl_gdbh IN ('{$gdbhStr}') AND sys_ny = '{$month}'";
  1112. // 执行SQL
  1113. $result = db()->execute($sql);
  1114. $updatedRows += $result;
  1115. }
  1116. return $updatedRows;
  1117. }
  1118. /**
  1119. * 获取工资分配详情(调试用)
  1120. */
  1121. public function getWageDistributionDetail($month)
  1122. {
  1123. $wageRatio = $this->WageRatio($month);
  1124. $distribution = [];
  1125. foreach ($wageRatio as $workshop => $ratio) {
  1126. $distribution[$workshop] = [
  1127. 'ratio' => $ratio,
  1128. 'data' => $this->WageRatioMonth($month, $workshop)
  1129. ];
  1130. }
  1131. return $distribution;
  1132. }
  1133. //获取工单编号
  1134. public function getmonthWorkorderList($month)
  1135. {
  1136. $worderList = db('成本v23_月度成本明细')
  1137. ->alias('a')
  1138. ->join('工单_印件资料 b','a.sczl_gdbh = b.Yj_Gdbh and a.sczl_yjno = b.yj_Yjno')
  1139. ->join('物料_收发记录 c', 'a.sczl_gdbh = c.st_gdbh and b.yj_Yjdh = c.cpdh')
  1140. ->field('a.sczl_gdbh,a.sczl_yjno,c.st_wlbh,rtrim(c.st_jylb) as st_jylb,c.仓库编号,c.st_jtbh,
  1141. rtrim(c.cpdh) as cpdh,c.领用单价,c.st_oldSl,c.Uniqid')
  1142. ->group('a.sczl_gdbh,cpdh,c.st_wlbh,c.Uniqid')
  1143. ->where('a.sys_ny', $month)
  1144. ->where('c.领用单价','<>',0)
  1145. ->select();
  1146. $data = [];
  1147. foreach ($worderList as $item) {
  1148. if (preg_match("/[A-Za-z]/", $item['仓库编号'])) {
  1149. $sist = $item['仓库编号'];
  1150. } else {
  1151. $sist = 'Y' . $item['仓库编号'];
  1152. }
  1153. if (!isset($data[$sist])) {
  1154. $data[$sist] = [];
  1155. }
  1156. $data[$sist][] = [
  1157. 'gdbh' => $item['sczl_gdbh'],
  1158. 'yjno' => $item['sczl_yjno'],
  1159. 'st_wlbh' => $item['st_wlbh'],
  1160. 'jtbh' => $item['st_jtbh'],
  1161. 'cpdh' => $item['cpdh'],
  1162. 'price' => $item['领用单价'],
  1163. 'st_sl' => $item['st_oldSl'],
  1164. 'Uniqid' => $item['Uniqid']
  1165. ];
  1166. }
  1167. halt($data);
  1168. }
  1169. //获取分摊材料数据
  1170. // public function MaterialsShareList($month)
  1171. // {
  1172. // $year = substr($month, 0, 4) . '-' . substr($month, 4, 2);
  1173. // $list = db('物料_收发记录')
  1174. // ->field(['rtrim(st_jylb) as st_jylb', 'st_oldSl', '领用单价', '仓库编号','rtrim(st_jtbh) as jtbh'])
  1175. // ->where([
  1176. // 'st_rq' => ['like',$year . '%'],
  1177. // ])
  1178. // ->whereNotIn('st_jylb', ['生产领料','制版领用'])
  1179. // ->select();
  1180. // $data = [];
  1181. // foreach ($list as $item) {
  1182. // if ($item['st_jylb'] == '修理领用') {
  1183. //
  1184. // }}
  1185. // if (!isset($data[$item['st_jylb']])) {
  1186. // $data[$item['st_jylb']] = [];
  1187. // }
  1188. // $data[$item['st_jylb']][] = [
  1189. // 'sl' => $item['st_oldSl'],
  1190. // 'price' => $item['领用单价'],
  1191. // 'sist' => $item['仓库编号'],
  1192. // 'jtbh' => $item['jtbh'],
  1193. // ];
  1194. // }
  1195. // halt($data);
  1196. // }
  1197. }