CostParameter.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Request;
  5. use function fast\e;
  6. /**
  7. * 财务管理-》成本参数管理
  8. */
  9. class CostParameter extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 成本参数管理左侧菜单栏
  15. * @return void
  16. */
  17. public function GetTab()
  18. {
  19. if ($this->request->isGet() === false){
  20. $this->error('请求错误');
  21. }
  22. $list = db('设备_基本资料')
  23. ->where('sys_sbID','<>', '')
  24. ->whereNotNull('sys_sbID')
  25. ->group('使用部门')
  26. ->column('rtrim(使用部门)');
  27. $this->success('成功', $list);
  28. }
  29. /**
  30. * 成本参数管理机台列表
  31. * @return void
  32. * @throws \think\db\exception\DataNotFoundException
  33. * @throws \think\db\exception\ModelNotFoundException
  34. * @throws \think\exception\DbException
  35. */
  36. public function MachineList()
  37. {
  38. if ($this->request->isGet() === false){
  39. $this->error('请求错误');
  40. }
  41. $param = $this->request->param();
  42. if (empty($param)){
  43. $this->error('参数错误');
  44. }
  45. $where = [];
  46. if (isset($param['sist']) && !empty($param['sist'])){
  47. $where['使用部门'] = $param['sist'];
  48. }
  49. $field = 'rtrim(使用部门) as 使用部门,设备编号,rtrim(设备名称) as 设备名称,原值,年折旧额,A_折旧月数 as 年折旧月数,A_月标准工时 as 月标准工时,
  50. A_小时折旧额 as 小时折旧额,平均车速 as 最高限速,产能系数,sys_sbID as MES地址,通讯口,通道号,sys_id as 创建用户,sys_rq as 创建时间,mod_rq as 修改时间,UniqId';
  51. $list = \db('设备_基本资料')
  52. ->where($where)
  53. ->whereNotNull('sys_sbID')
  54. ->field($field)
  55. ->order('设备编号')
  56. ->select();
  57. $this->success('成功', $list);
  58. }
  59. /**
  60. * 机台信息详情
  61. * @return void
  62. * @throws \think\db\exception\DataNotFoundException
  63. * @throws \think\db\exception\ModelNotFoundException
  64. * @throws \think\exception\DbException
  65. */
  66. public function MachineDetail()
  67. {
  68. if ($this->request->isGet() === false){
  69. $this->error('请求错误');
  70. }
  71. $param = $this->request->param();
  72. if (empty($param) || empty($param['UniqId'])){
  73. $this->error('参数错误');
  74. }
  75. $field = 'rtrim(使用部门) as 使用部门,设备编号,rtrim(设备名称) as 设备名称,原值,年折旧额,A_折旧月数 as 年折旧月数,A_月标准工时 as 月标准工时,
  76. A_小时折旧额 as 小时折旧额,平均车速 as 最高限速,产能系数,rtrim(sys_sbID) as 关联地址,通讯口 as 通讯端口,通道号,UniqId,rtrim(设备类别) as 设备等级,rtrim(供应商) as 供应商,
  77. rtrim(出厂编号) as 出厂编号,安装日期,rtrim(财务编号) as 资产编号';
  78. $list = \db('设备_基本资料')
  79. ->where('UniqId', $param['UniqId'])
  80. ->field($field)
  81. ->find();
  82. if (empty($list)){
  83. $this->error('未找到数据');
  84. }else{
  85. $this->success('成功', $list);
  86. }
  87. }
  88. /**
  89. * 设备信息修改
  90. * @return void
  91. * @throws \think\Exception
  92. * @throws \think\db\exception\BindParamException
  93. * @throws \think\exception\PDOException
  94. */
  95. public function MachineUpdate()
  96. {
  97. if ($this->request->isPost() === false){
  98. $this->error('请求错误');
  99. }
  100. $param = Request::instance()->post();
  101. if (empty($param) || empty($param['UniqId'])){
  102. $this->error('参数错误');
  103. }
  104. $data = [
  105. '设备名称' => $param['设备名称'],
  106. '供应商' => $param['供应商'],
  107. '出厂编号' => $param['出厂编号'],
  108. '安装日期' => $param['安装日期'],
  109. '财务编号' => $param['资产编号'],
  110. '设备类别' => $param['设备等级'],
  111. '原值' => $param['原值'],
  112. '年折旧额' => $param['年折旧额'],
  113. 'A_折旧月数' => $param['年折旧月数'],
  114. 'A_月标准工时' => $param['月标准工时'],
  115. 'A_小时折旧额' => $param['小时折旧额'],
  116. '平均车速' => $param['最高限速'],
  117. '产能系数' => $param['产能系数'],
  118. 'sys_sbID' => $param['关联地址'],
  119. '通讯口' => $param['通讯端口'],
  120. '通道号' => $param['通道号'],
  121. 'mod_rq' => date('Y-m-d H:i:s', time()),
  122. ];
  123. $sql = \db('设备_基本资料')
  124. ->where('UniqId', $param['UniqId'])
  125. ->fetchSql(true)
  126. ->update($data);
  127. $res = db()->query($sql);
  128. if ($res === false){
  129. $this->error('修改失败');
  130. }else{
  131. $this->success('修改成功');
  132. }
  133. }
  134. /**
  135. * 设备信息删除
  136. * @return void
  137. * @throws \think\Exception
  138. * @throws \think\exception\PDOException
  139. */
  140. public function MachineDelete()
  141. {
  142. if ($this->request->isGet() === false){
  143. $this->error('请求错误');
  144. }
  145. $param = $this->request->param();
  146. if (empty($param) || empty($param['UniqId'])){
  147. $this->error('参数错误');
  148. }
  149. $res = \db('设备_基本资料')
  150. ->where('UniqId', $param['UniqId'])
  151. ->delete();
  152. if ($res === false){
  153. $this->error('删除失败');
  154. }else{
  155. $this->success('删除成功');
  156. }
  157. }
  158. /**
  159. * 设备信息新增
  160. * @return void
  161. * @throws \think\db\exception\BindParamException
  162. * @throws \think\exception\PDOException
  163. */
  164. public function MachineAdd()
  165. {
  166. if ($this->request->isPost() === false){
  167. $this->error('请求错误');
  168. }
  169. $param = Request::instance()->post();
  170. if (empty($param) || empty($param['设备编号'])){
  171. $this->error('参数错误');
  172. }
  173. $data = [
  174. '使用部门' => $param['使用部门'],
  175. '设备编号' => $param['设备编号'],
  176. '设备名称' => $param['设备名称'],
  177. '供应商' => $param['供应商'],
  178. '出厂编号' => $param['出厂编号'],
  179. '安装日期' => $param['安装日期'],
  180. '财务编号' => $param['资产编号'],
  181. '设备类别' => $param['设备等级'],
  182. '原值' => $param['原值'],
  183. '年折旧额' => $param['年折旧额'],
  184. 'A_折旧月数' => $param['年折旧月数'],
  185. 'A_月标准工时' => $param['月标准工时'],
  186. 'A_小时折旧额' => $param['小时折旧额'],
  187. '平均车速' => $param['最高限速'],
  188. '产能系数' => $param['产能系数'],
  189. 'sys_sbID' => $param['关联地址'],
  190. '通讯口' => $param['通讯端口'],
  191. '通道号' => $param['通道号'],
  192. 'sys_rq' => date('Y-m-d H:i:s', time()),
  193. 'sys_id' => $param['sys_id'],
  194. ];
  195. $sql = db('设备_基本资料')
  196. ->fetchSql(true)
  197. ->insert($data);
  198. $res = db()->query($sql);
  199. if ($res === false){
  200. $this->error('添加失败');
  201. }else{
  202. $this->success('添加成功');
  203. }
  204. }
  205. }