ProcessLib.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use Monolog\Handler\IFTTTHandler;
  5. use Overtrue\Socialite\Providers\WeWorkProvider;
  6. use think\Db;
  7. use think\Request;
  8. use function fast\e;
  9. /**
  10. * 产品_工艺库
  11. */
  12. class ProcessLib extends Api
  13. {
  14. protected $noNeedLogin = ['*'];
  15. protected $noNeedRight = ['*'];
  16. public function index(){
  17. $this->success('产品_工艺资料库');
  18. }
  19. /**
  20. * 新增产品工艺库(批量新增)
  21. */
  22. public function ProcessAdd()
  23. {
  24. if (!Request::instance()->isPost()) {
  25. $this->error('非法请求');
  26. }
  27. $params = Request::instance()->param();
  28. // 接收前端传的 列表 + 操作人
  29. $sys_id = $params['sys_id'];
  30. $process_list = $params['process_list'];
  31. // 校验数据
  32. if (empty($process_list)) {
  33. $this->error('请传入工艺数据');
  34. }
  35. // ========== 自动生成 GY 编号 ==========
  36. $lastCode = db('产品_工艺库')
  37. ->order('id desc')
  38. ->whereNull('mod_rq')
  39. ->value('gy_code');
  40. if ($lastCode) {
  41. $num = intval(str_replace('GY', '', $lastCode)) + 1;
  42. } else {
  43. $num = 1;
  44. }
  45. // ========== 组装批量插入数据 ==========
  46. $insertData = [];
  47. foreach ($process_list as $item) {
  48. // 过滤空数据
  49. if (empty($item['gy_name'])) continue;
  50. $insertData[] = [
  51. 'gy_code' => 'GY' . str_pad($num, 6, '0', STR_PAD_LEFT),
  52. 'gy_name' => $item['gy_name'],
  53. 'big_process' => $item['big_process'],
  54. 'standard_hour' => $item['standard_hour'],
  55. 'standard_score' => $item['standard_score'],
  56. 'status' => 1,
  57. 'sys_id' => $sys_id,
  58. 'createtime' => date('Y-m-d H:i:s')
  59. ];
  60. $num++;
  61. }
  62. if (empty($insertData)) {
  63. $this->error('无有效数据');
  64. }
  65. $result = db('产品_工艺库')->insertAll($insertData);
  66. return $result
  67. ? $this->success('新增成功')
  68. : $this->error('新增失败');
  69. }
  70. /**
  71. * 获取产品工艺库
  72. */
  73. public function ProcessList(){
  74. if (Request::instance()->isGet() == false){
  75. $this->error('非法请求');
  76. }
  77. $params = Request::instance()->param();
  78. $where = [];
  79. if (!empty($params['search'])){
  80. $where['gy_code|gy_name|big_process'] = array('like','%'.$params['search'].'%');
  81. }
  82. if (!empty($params['code'])){
  83. $where['big_process'] = array('like','%'.$params['code'].'%');
  84. }
  85. $limit = $params['limit'];
  86. if (empty($limit)){
  87. $limit = 30;
  88. }
  89. $pages = $params['page'];
  90. if (empty($pages)){
  91. $pages = 1;
  92. }
  93. $list = Db::name('产品_工艺库')
  94. ->field('
  95. id,
  96. gy_code,
  97. gy_name,
  98. big_process,
  99. standard_hour,
  100. standard_score,
  101. sys_id,
  102. createtime as 创建时间,
  103. updatetime as 修改时间
  104. ')
  105. ->whereNull('mod_rq')->where($where)->page($pages)->limit($limit)->order('id desc')->select();
  106. $total = Db::name('产品_工艺库')->whereNull('mod_rq')->where($where)->count();
  107. $data['list'] = $list;
  108. $data['total'] = $total;
  109. $this->success('获取成功',$data);
  110. }
  111. /**
  112. * 修改产品工艺库
  113. */
  114. public function ProcessEdit(){
  115. if (!Request::instance()->isPost()) {
  116. $this->error('非法请求');
  117. }
  118. $params = Request::instance()->param();
  119. if (empty($params['id'])) {
  120. $this->error('请选择要修改的数据');
  121. }
  122. if (empty($params['gy_name'])) {
  123. $this->error('工序名称不能为空');
  124. }
  125. //修改数据
  126. $data = [
  127. 'gy_name' => $params['gy_name'],
  128. 'big_process' => $params['big_process'],
  129. 'standard_hour' => $params['standard_hour'],
  130. 'standard_score' => $params['standard_score'],
  131. 'sys_id' => $params['sys_id'],
  132. 'updatetime' => date('Y-m-d H:i:s')
  133. ];
  134. $result = db('产品_工艺库')
  135. ->where('id', $params['id'])
  136. ->whereNull('mod_rq')
  137. ->update($data);
  138. if ($result !== false) {
  139. $this->success('修改成功');
  140. } else {
  141. $this->error('修改失败');
  142. }
  143. }
  144. /**
  145. * 删除产品工艺库
  146. */
  147. public function ProcessDelete(){
  148. if (!Request::instance()->isPost()) {
  149. $this->error('非法请求');
  150. }
  151. $params = Request::instance()->param();
  152. $ids = $params['id'] ?? '';
  153. if (empty($ids)) {
  154. $this->error('请选择需要删除的数据');
  155. }
  156. // 转成数组
  157. $idArray = explode(',', $ids);
  158. $result = \db('产品_工艺库')
  159. ->where('id', 'in', $idArray)
  160. ->update(['mod_rq' => date('Y-m-d H:i:s')]);
  161. if ($result !== false) {
  162. $this->success('删除成功');
  163. } else {
  164. $this->error('删除失败');
  165. }
  166. }
  167. }