$params['in_out'], 'property_commission_id' => $params['property_commission_id'], 'amount' => $params['amount'], 'status' => $params['status'], 'remark' => $params['remark'], 'property_head_id' => $params['property_head_id'], ]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 编辑 * @param array $params * @return bool * @author likeadmin * @date 2024/09/20 16:31 */ public static function edit(array $params): bool { Db::startTrans(); try { $status = PropertySurplusLog::where('id', $params['id'])->value('status'); if($status != 0){ throw new Exception('状态不允许操作'); } if(intval($params['status']) === 1){ $res = self::EntryCash($params); } if(intval($params['status']) === 2){ $res = self::CancelCash($params); } if(!$res){ throw new Exception(self::getError()); } /*PropertySurplusLog::where('id', $params['id'])->update([ 'in_out' => $params['in_out'], 'property_commission_id' => $params['property_commission_id'], 'amount' => $params['amount'], 'status' => $params['status'], 'remark' => $params['remark'], 'property_head_id' => $params['property_head_id'], ]);*/ Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 删除 * @param array $params * @return bool * @author likeadmin * @date 2024/09/20 16:31 */ public static function delete(array $params): bool { return PropertySurplusLog::destroy($params['id']); } /** * @notes 获取详情 * @param $params * @return array * @author likeadmin * @date 2024/09/20 16:31 */ public static function detail($params): array { return PropertySurplusLog::findOrEmpty($params['id'])->toArray(); } /** * 提现入账 * @param $params * @return false|true */ public static function EntryCash($params) { Db::startTrans(); try { $propertySurplusLogInfo = PropertySurplusLog::where([ "id" => $params['id'], 'in_out' => 2, 'status' => 0 ])->findOrEmpty(); if($propertySurplusLogInfo->isEmpty()){ throw new Exception('申请中记录不存在'); } $propertySurplusLogInfo = $propertySurplusLogInfo->toArray(); $propertyHeadId = $propertySurplusLogInfo['property_head_id']; $amount = $propertySurplusLogInfo['amount']; // 更新 出账记录-已入账 PropertySurplusLog::where(['id' => $params['id']])->update(['status' => 1]); // 更新 物业负责人已提收益 PropertyHead::where(['id' => $propertyHeadId])->update(['extract_profit_amount' => Db::raw('extract_profit_amount+'.$amount)]); Db::commit(); return true; }catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * 提现取消 * @param $params * @return false|true */ public static function CancelCash($params) { Db::startTrans(); try { $propertySurplusLogInfo = PropertySurplusLog::where([ "id" => $params['id'], 'in_out' => 2, 'status' => 0 ])->findOrEmpty(); if($propertySurplusLogInfo->isEmpty()){ throw new Exception('申请中记录不存在'); } $propertySurplusLogInfo = $propertySurplusLogInfo->toArray(); $propertyHeadId = $propertySurplusLogInfo['property_head_id']; $amount = $propertySurplusLogInfo['amount']; // 更新 出账记录-取消 PropertySurplusLog::where(['id' => $params['id']])->update(['status' => 2]); // 更新 物业负责人剩余收益 金额恢复 PropertyHead::where(['id' => $propertyHeadId])->update(['surplus_profit_amount' => Db::raw('surplus_profit_amount+'.$amount)]); Db::commit(); return true; }catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } }