| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use Monolog\Handler\IFTTTHandler;
- use Overtrue\Socialite\Providers\WeWorkProvider;
- use think\Db;
- use think\Request;
- use function fast\e;
- /**
- * 产品_工艺库
- */
- class ProcessLib extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- public function index(){
- $this->success('产品_工艺资料库');
- }
- /**
- * 新增产品工艺库(批量新增)
- */
- public function ProcessAdd()
- {
- if (!Request::instance()->isPost()) {
- $this->error('非法请求');
- }
- $params = Request::instance()->param();
- // 接收前端传的 列表 + 操作人
- $sys_id = $params['sys_id'];
- $process_list = $params['process_list'];
- // 校验数据
- if (empty($process_list)) {
- $this->error('请传入工艺数据');
- }
- // ========== 自动生成 GY 编号 ==========
- $lastCode = db('产品_工艺库')
- ->order('id desc')
- ->whereNull('mod_rq')
- ->value('gy_code');
- if ($lastCode) {
- $num = intval(str_replace('GY', '', $lastCode)) + 1;
- } else {
- $num = 1;
- }
- // ========== 组装批量插入数据 ==========
- $insertData = [];
- foreach ($process_list as $item) {
- // 过滤空数据
- if (empty($item['gy_name'])) continue;
- $insertData[] = [
- 'gy_code' => 'GY' . str_pad($num, 6, '0', STR_PAD_LEFT),
- 'gy_name' => $item['gy_name'],
- 'big_process' => $item['big_process'],
- 'standard_hour' => $item['standard_hour'],
- 'standard_score' => $item['standard_score'],
- 'status' => 1,
- 'sys_id' => $sys_id,
- 'createtime' => date('Y-m-d H:i:s')
- ];
- $num++;
- }
- if (empty($insertData)) {
- $this->error('无有效数据');
- }
- $result = db('产品_工艺库')->insertAll($insertData);
- return $result
- ? $this->success('新增成功')
- : $this->error('新增失败');
- }
- /**
- * 获取产品工艺库
- */
- public function ProcessList(){
- if (Request::instance()->isGet() == false){
- $this->error('非法请求');
- }
- $params = Request::instance()->param();
- $where = [];
- if (!empty($params['search'])){
- $where['gy_code|gy_name|big_process'] = array('like','%'.$params['search'].'%');
- }
- if (!empty($params['code'])){
- $where['big_process'] = array('like','%'.$params['code'].'%');
- }
- $limit = $params['limit'];
- if (empty($limit)){
- $limit = 30;
- }
- $pages = $params['page'];
- if (empty($pages)){
- $pages = 1;
- }
- $list = Db::name('产品_工艺库')
- ->field('
- id,
- gy_code,
- gy_name,
- big_process,
- standard_hour,
- standard_score,
- sys_id,
- createtime as 创建时间,
- updatetime as 修改时间
- ')
- ->whereNull('mod_rq')->where($where)->page($pages)->limit($limit)->order('id desc')->select();
- $total = Db::name('产品_工艺库')->whereNull('mod_rq')->where($where)->count();
- $data['list'] = $list;
- $data['total'] = $total;
- $this->success('获取成功',$data);
- }
- /**
- * 修改产品工艺库
- */
- public function ProcessEdit(){
- if (!Request::instance()->isPost()) {
- $this->error('非法请求');
- }
- $params = Request::instance()->param();
- if (empty($params['id'])) {
- $this->error('请选择要修改的数据');
- }
- if (empty($params['gy_name'])) {
- $this->error('工序名称不能为空');
- }
- //修改数据
- $data = [
- 'gy_name' => $params['gy_name'],
- 'big_process' => $params['big_process'],
- 'standard_hour' => $params['standard_hour'],
- 'standard_score' => $params['standard_score'],
- 'sys_id' => $params['sys_id'],
- 'updatetime' => date('Y-m-d H:i:s')
- ];
- $result = db('产品_工艺库')
- ->where('id', $params['id'])
- ->whereNull('mod_rq')
- ->update($data);
- if ($result !== false) {
- $this->success('修改成功');
- } else {
- $this->error('修改失败');
- }
- }
- /**
- * 删除产品工艺库
- */
- public function ProcessDelete(){
- if (!Request::instance()->isPost()) {
- $this->error('非法请求');
- }
- $params = Request::instance()->param();
- $ids = $params['id'] ?? '';
- if (empty($ids)) {
- $this->error('请选择需要删除的数据');
- }
- // 转成数组
- $idArray = explode(',', $ids);
- $result = \db('产品_工艺库')
- ->where('id', 'in', $idArray)
- ->update(['mod_rq' => date('Y-m-d H:i:s')]);
- if ($result !== false) {
- $this->success('删除成功');
- } else {
- $this->error('删除失败');
- }
- }
- }
|