request->isGet()){ $this->error('请求错误'); } $params = $this->request->param(); if (!isset($params['month']) || empty($params['month'])) { $this->error('参数错误'); } db('糊盒工资汇总')->where('sczl_rq','like',$params['month'].'%')->delete(); $where = ['a.sczl_rq' => ['between', [$params['startDay'].' 00:00:00', $params['endDay'].' 23:59:59']]]; //糊盒计件产量 $filds = "a.sczl_gdbh as 工单编号,a.sczl_gxmc as 工序名称,a.sczl_cl as 产量,a.sczl_rq as 日期, a.sczl_dedh as 定额代号,a.工价系数,a.保养工时,a.装版工时,a.异常工时,a.设备运行工时,a.role,a.sczl_jtbh,b.Gd_cpdh,b.Gd_cpmc,a.price"; $list = db('设备_糊盒报工资料') ->alias('a') ->join('工单_基本资料 b', 'a.sczl_gdbh = b.Gd_gdbh ','left') ->field($filds) ->where($where) ->group('a.Uid') ->select(); $data = []; foreach ($list as $k=>$v){ $result = $this->salaryCalculationClass($v['role']); $salary = $v['产量'] * $v['price']; for ($i = 1; $i <= 30; $i++) { $bh = $result['bh'.$i]; $name = $result['员工姓名'.$i]; $rate = $result['rate'.$i]; if (!empty($bh) && $bh !== '') { $wage = $salary * $rate; $data[] = [ 'sczl_gdbh' => $v['工单编号'], 'sczl_gxmc' => $v['工序名称'], 'sczl_rq' => $v['日期'], 'sczl_cl' => $v['产量'], 'sczl_dedh' => $v['定额代号'], '工价系数' => $v['工价系数'], '保养工时' => $v['保养工时'], '装版工时' => $v['装版工时'], '异常工时' => $v['异常工时'], '设备运行工时' => $v['设备运行工时'], 'sczl_jtbh' => $v['sczl_jtbh'], 'cpdh' => $v['Gd_cpdh'], 'cpmc' => $v['Gd_cpmc'], 'bh' => $bh, 'rate' => $rate, 'name' => $name, 'salary' => $wage, 'price' => $v['price'], 'sys_id' => $params['sys_id'], 'sys_rq' => date('Y-m-d H:i:s',time()) ]; } } } $sql = db('糊盒工资汇总')->fetchSql(true)->insertAll($data); $res = db()->query($sql); if ($res !== false){ $this->success('成功'); }else{ $this->error('失败'); } } protected function salaryCalculationClass($role) { // 构建查询对象 $query = db('糊盒报工班组')->alias('a')->where('a.id', $role); // 构建字段列表 $fieldParts = []; // 添加 bh 和 rate 字段 for ($i = 1; $i <= 30; $i++) { $fieldParts[] = "a.bh{$i}"; $fieldParts[] = "a.rate{$i}"; } // 添加 JOIN 和员工姓名字段 for ($i = 1; $i <= 30; $i++) { $table = 'b' . $i; $fieldParts[] = "{$table}.员工姓名 as 员工姓名{$i}"; $query->join("人事_基本资料 {$table}", "a.bh{$i} = {$table}.员工编号", 'left'); } // 设置字段 $query->field(implode(',', $fieldParts)); return $query->find(); } }