request->post(); $customId = $post['customId'] ?? 0; $remark = $post['remark'] ?? ''; $custom = CustomClass::getByID($customId, true); if (empty($custom)) { util::fail('没有找到客户'); } if ($custom->shopId != $this->shopId) { util::fail('不是你的客户'); } $hdId = $custom->hdId; $hd = HdClass::getByID($hdId, true); if (empty($hd)) { util::fail('客户信息缺失,编号7756'); } $amount = $post['amount'] ?? 0; if (empty($amount)) { util::fail('请填写金额'); } if ($amount < 0) { util::fail('金额要大于0'); } $staff = $this->shopAdmin; if (isset($this->shopAdmin->founder) == false || $this->shopAdmin->founder != 2) { util::fail('管理员才能操作'); } if ($staff->finance == 0) { util::fail('没有财务权限'); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $shop = $this->shop; $staffId = $staff->id; $staffName = $staff->name; $params = [ 'remark' => $remark, 'staffId' => $staffId, 'staffName' => $staffName, ]; DeductClass::doDeduct($shop, $custom, $hd, $amount, $params); $transaction->commit(); util::complete('减少成功'); } catch (\Exception $exception) { $transaction->rollBack(); Yii::info("减少报错:" . $exception->getMessage()); util::fail('减少失败'); } } }