Sfoglia il codice sorgente

up - settlement_time

liugc 1 anno fa
parent
commit
80a0d11ebb

+ 3 - 4
app/adminapi/controller/master_worker/EngineerSettlementController.php

@@ -52,17 +52,16 @@ class EngineerSettlementController extends BaseAdminController
     public function add()
     {
         //$params = (new EngineerSettlementValidate())->post();//->goCheck('add');
-        $params = $this->request->post();
-        $params['admin_id'] = $this->adminId;
         try {
+            $params = $this->request->post();
             $params = EngineerSettlementLogic::engineerSettlementValidate($params);
-            $result = EngineerSettlementLogic::add($params);
+            $result = EngineerSettlementLogic::add($params,$this->adminId);
             if (true === $result) {
                 return $this->success('添加成功', [], 1, 1);
             }
             return $this->fail(EngineerSettlementLogic::getError());
         } catch (\Exception $e) {
-            return $this->fail(EngineerSettlementLogic::getError()?:$e->getMessage());
+            return $this->fail($e->getMessage()?:EngineerSettlementLogic::getError());
         }
     }
 

+ 14 - 11
app/adminapi/logic/master_worker/EngineerSettlementLogic.php

@@ -38,7 +38,7 @@ class EngineerSettlementLogic extends BaseLogic
      * @author likeadmin
      * @date 2024/11/15 17:21
      */
-    public static function add(array $params): bool
+    public static function add(array $params, $adminId): bool
     {
         Db::startTrans();
         try {
@@ -65,7 +65,7 @@ class EngineerSettlementLogic extends BaseLogic
                         'title' => '财务打款',
                         'change_amount' => $param['total_settlement_amount'],
                         'review_status' => 3,
-                        'admin_id' => $param['admin_id'],
+                        'admin_id' => $adminId,
                         'remark' => '财务打款',
                         'create_time' => time(),
                         'update_time' => time(),
@@ -153,9 +153,8 @@ class EngineerSettlementLogic extends BaseLogic
     public static function engineerSettlementValidate($params)
     {
         try {
+            if(empty($params)) throw new \Exception('表格数据为空');
             foreach ($params as &$param) {
-                $masterWorker = MasterWorker::where('id', $param['master_worker_id'])->where('worker_number', $param['worker_number'])->findOrFail();
-                if($masterWorker->user_money < $param['total_settlement_amount']) throw new \Exception('余额不足');
                 //判断日期时间格式是否正确 2024/1/1 00:00:00 或 2024-1-1 00:00:00
                 if(!preg_match('/^[0-9]{4}\/[0-9]{1,2}\/[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}$/', $param['settlement_time'])
                     && !preg_match('/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}$/', $param['settlement_time'])){
@@ -163,20 +162,24 @@ class EngineerSettlementLogic extends BaseLogic
                 }else{
                     $param['settlement_time'] = date('Y-m-d H:i:s', strtotime($param['settlement_time']));
                 }
-                if(!is_float($param['original_balance']) || !is_float($param['total_settlement_amount']) || !is_float($param['deduction_amount']) || !is_float($param['final_settlement_amount'])){
+                if(!is_numeric($param['original_balance']) || !is_numeric($param['total_settlement_amount']) || !is_numeric($param['deduction_amount']) || !is_numeric($param['final_settlement_amount'])){
                     throw new \Exception('金额格式错误');
                 }
-                if(!is_int($param['master_worker_id'])){
-                    throw new \Exception('工程师ID格式错误');
+                if(!preg_match('/^[0-9]*$/', $param['worker_number'])){
+                    throw new \Exception('工程师ID格式错误:'.$param['master_worker_id']);
                 }
-                if(!is_numeric($param['worker_number'])){
-                    throw new \Exception('工程师编号格式错误');
+                if(!preg_match('/^[0-9]*$/', $param['master_worker_id'])){
+                    throw new \Exception('工程师ID格式错误:'.$param['master_worker_id']);
                 }
+                $masterWorker = MasterWorker::where('id', $param['master_worker_id'])->where('worker_number', $param['worker_number'])->findOrEmpty();
+                if($masterWorker->isEmpty()) throw new \Exception('工程师不存在:'.$param['master_worker_id']);
+                if($masterWorker->user_money < $param['total_settlement_amount']) throw new \Exception('余额不足');
             }
+            return $params;
         } catch (\Exception $e) {
-                throw new \Exception($e->getMessage());
+            throw new \Exception($e->getMessage());
         }
-        return $params;
+
     }