Jelajahi Sumber

糊盒工资计算

unknown 3 bulan lalu
induk
melakukan
33b4a3edd7
1 mengubah file dengan 76 tambahan dan 6 penghapusan
  1. 76 6
      application/api/controller/GluSalaryCalculation.php

+ 76 - 6
application/api/controller/GluSalaryCalculation.php

@@ -4,7 +4,7 @@ namespace app\api\controller;
 
 use app\common\controller\Api;
 
-class GlluSalaryCalculation extends Api
+class GluSalaryCalculation extends Api
 {
     protected $noNeedLogin = ['*'];
     protected $noNeedRight = ['*'];
@@ -19,15 +19,85 @@ class GlluSalaryCalculation extends Api
         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_yjno as 印件号,a.sczl_gxh as 工序号,a.sczl_gxmc as 工序名称,a.sczl_cl as 产量,a.sczl_rq as 日期,
-        a.sczl_ls as 联数,a.sczl_dedh as 定额代号,a.工价系数,a.保养工时,a.装版工时,a.异常工时,设备运行工时,a.role,a.sczl_jtbh,b.yj_cpdh,b.yj_yjmc"
+        $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.Yj_Gdbh and a.sczl_yjno = b.yj_Yjno')
+            ->join('工单_基本资料 b', 'a.sczl_gdbh = b.Gd_gdbh ','left')
             ->field($filds)
-            ->where(['month' => $params['month']])
+            ->where($where)
+            ->group('a.Uid')
             ->select();
-        halt($list);
+        $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_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();
     }
 }