/** * Auther:langxi * 根据赎回债权字典进行赎回操作 * @param $Redeem */ private static function Set_redeem($Redeem) { foreach ($Redeem as $k => $v) { //order表金额赎回 $order = Order::findOne($v['order_id']); $order->money = $order['money'] - $v['thirdmoney']; if ($order['money'] == '0') { $order->status = Order::STATUS_DELETE; } $order = $order->save(); if (!$order) { $result = array('errorNum' => '1', 'errorMsg' => '转让债权赎回失败', 'data' => null); return $result; } //thirdorder表金额赎回 $thirdorder = Thirdorder::findOne($v['thirdorder_id']); $thirdorder->money = $thirdorder['money'] - $v['thirdmoney']; if ($thirdorder['money'] == '0') { $thirdorder->status = Thirdorder::STATUS_DELETED; } $thirdorder->mcmoney = $thirdorder['mcmoney'] + $v['thirdmoney']; //记录最大债权增加 $thirdorder->ocmoney = $thirdorder['ocmoney'] - $v['thirdmoney']; //记录原始债权金额减少 $thirdorder = $thirdorder->save(); if (!$thirdorder) { $result = array('errorNum' => '1', 'errorMsg' => '第三方转让债权失败', 'data' => null); return $result; } //thirdproduct第三方债权已投金额减少 $thirdproduct = Thirdproduct::findOne($v['thirdproduct_id']); $thirdproduct->invest_sum = $thirdproduct['invest_sum'] - $v['thirdmoney']; $thirdproduct->mcmoney = $thirdproduct['mcmoney'] + $v['thirdmoney']; //赎回导致最大债权人金额增加 $thirdproduct = $thirdproduct->save(); if (!$thirdproduct) { $result = array('errorNum' => '1', 'errorMsg' => '赎回第三方债权已投金额失败', 'data' => null); return $result; } //获取债权的最大债权人id,将用户赎回的钱从最大债权人的账户中减去 $maxcreditor = Thirdproduct::find()->select(['maxcreditor'])->where(['id' => $v['thirdproduct_id']])->asArray()->one(); $maxcreditor = $maxcreditor['maxcreditor']; $is_max = Catmiddle::find()->where(['cid' => '1', 'uid' => $maxcreditor])->asArray()->one(); if (!$is_max) { $result = array('errorNum' => '1', 'errorMsg' => '最大债权人异常', 'data' => null); return $result; } $max_info = Info::findOne($maxcreditor); $max_info->balance = $max_info['balance'] - $v['thirdmoney']; $max_info = $max_info->save(); if (!$max_info) { $result = array('errorNum' => '1', 'errorMsg' => '消减最大债权人账户金额失败', 'data' => null); return $result; } //写入职员账户记录表中 $member_id = Order::find()->select(['member_id'])->where(['id' => $v['order_id']])->asArray()->one(); $member_id = $member_id['member_id']; $clerk = new ClerkLog(); $clerk->member_id = $member_id; $clerk->clerk_id = $maxcreditor; $clerk->behav = ClerkLog::CLERK_BEHAV_TWO; $clerk->step = $v['thirdmoney']; $clerk->remark = '最大债权人'; $clerk = $clerk->save(); if (!$clerk) { throw new ErrorException('写入职员账户记录失败'); } } return true; }