コード例 #1
0
ファイル: InfoController.php プロジェクト: wuwenhan/huoqiwang
 /**
  * Displays a single Info model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $model = $this->findModel($id);
     $sina = new sina();
     $smember = SinaMember::find()->andWhere(['uid' => $model->member_id])->andWhere(['status' => SinaMember::STATUS_BINGING])->one();
     if ($smember) {
         //$sina = new sina();
         $model->sinamoney = $sina->query_balance($smember->identity_id);
         //var_dump($model->sinamoney);
         //判定是员工才更新余额
         $user = Catmiddle::find()->where(['uid' => $model->member_id])->one();
         if ($user) {
             if ($user->cid == '1' || $user->cid == '2' || $user->cid == '3') {
                 Info::updateAll(['balance' => $model->sinamoney['balance']], ['member_id' => $id]);
                 $model->balance = $model->sinamoney['balance'];
             }
         } else {
             $model->balance = Info::findOne($id)->balance;
         }
     } else {
         \Yii::$app->getSession()->setFlash('warning', '该用户没用绑定新浪账户');
     }
     return $this->render('view', ['model' => $model]);
 }
コード例 #2
0
ファイル: Withdrawals.php プロジェクト: wuwenhan/huoqiwang
 /**
  * Authre:langxi
  *
  * 用户赎回操作
  */
 public static function User_redeem($member_id, $money, $update = 0)
 {
     ini_set('max_execution_time', 60);
     //判断用户是否可进行赎回操作
     $is_go = Info::find()->select(['status'])->where(['member_id' => $member_id])->asArray()->one();
     if ($is_go['status'] > 0) {
         $result = array('errorNum' => '1', 'errorMsg' => '处理中,请稍后再试', 'data' => null);
         return $result;
     }
     Info::updateAll(['status' => Info::GO_THREE], ['member_id' => $member_id]);
     //进行操作,状态变为处理中
     //检查用户一日赎回
     $check_redeem = self::check_redeem($member_id, $money);
     if ($check_redeem) {
         Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
         //            $result = array('errorNum' => '1', 'errorMsg' => $check_redeem, 'data' => null);
         return $check_redeem;
     }
     //判断赎回金额是否小于新浪账户与网站账户余额的差值,若小于则网站端进行赎回操作,先赎回利息,然后赎回订单中的金额。
     //若大于求取差值获取到网站需要赎回的金额和新浪部分需要赎回的金额,然后两端分别进行赎回操作,先赎回利息,然后赎回订单中的金额
     $asset = Info::find()->where(['member_id' => $member_id])->asArray()->one();
     $bank_card = $asset['bank_card'];
     //获取用户在投收益
     $profit = $asset['profit'];
     //判断用户赎回金额是否可赎回。
     $order_money = (new \yii\db\Query())->select(['money'])->from('fund_orders')->where(['member_id' => $member_id])->andWhere(['>', 'money', '0'])->sum('money');
     //增加了活动红包begin
     if ($update) {
         $red_money = member::get_user_red_packet($member_id, $update);
         if (!$red_money['errorNum']) {
             $red = $red_money['data']['red_sum'];
             $order_money = $order_money + $red;
         }
     }
     ////活动红包end
     if ($order_money + $profit < $money) {
         Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
         //赎回结束,操作状态变回常态
         $result = array('errorNum' => '1', 'errorMsg' => '赎回金额大于可赎回金额,请重新输入', 'data' => null);
         return $result;
     }
     $w_blance = self::showBlance($member_id);
     //网站余额
     $s_blance = sinapay::querySinaBalance($member_id);
     //调用第三方接口查看新浪账户可用余额(含货币基金
     if ($s_blance['errorNum']) {
         Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
         //赎回结束,操作状态变回常态
         $result = array('errorNum' => '1', 'errorMsg' => $s_blance['errorMsg'], 'data' => null);
         return $result;
     }
     if ($w_blance > $s_blance['data']['available_balance']) {
         Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
         //赎回结束,操作状态变回常态
         $result = array('errorNum' => '1', 'errorMsg' => '账户异常请联系客服', 'data' => null);
         return $result;
     }
     $m_fund = $s_blance['data']['available_balance'] - $w_blance;
     //新浪账户比网站账户多的钱--新浪的货币基金
     $red_packet = 0;
     $red = 0;
     //如果赎回和活动红包有关系 TODO
     if ($update) {
         //赎回时必须有在投金额
         $invest = $asset['invest'];
         if ($invest && $invest >= 1) {
             //获取那个时间点的金额
             $red_money = member::get_user_red_packet($member_id, $update);
             if (!$red_money['errorNum']) {
                 $red = $red_money['data']['red_sum'];
                 if ((double) $red > (double) $money) {
                     //如果只是提取一部分红包
                     $return = array('errorNum' => '1', 'errorMsg' => '红包必须全部赎回', 'data' => null);
                     return $return;
                 }
             } else {
                 $return = array('errorNum' => '1', 'errorMsg' => $red_money['errorMsg'], 'data' => null);
                 return $return;
             }
         }
     }
     //应该扣除红包的金额
     $red_packet = $red;
     //$m_fund ---新浪的货币基金
     //货币基金大于用户要赎回的资金--发上几率比较小
     if ($m_fund > $money) {
         //事物回滚
         $transaction = \Yii::$app->db->beginTransaction();
         try {
             //赎回金额小于新浪账户与网站账户的差值,仅网站端进行赎回操作
             $profit = (new \yii\db\Query())->select(['profit'])->from('asset_info')->where(['member_id' => $member_id])->one();
             //TODO --添加了红包++++++$red_packet;
             $profit = $profit['profit'] + $red_packet;
             //用户的可用收益
             // money 减去红包
             if ($money <= $profit) {
                 // 红包表的处理
                 if ($update) {
                     $info = Info::findOne($member_id);
                     $info->profit = $info['profit'] + $red_packet;
                     $info = $info->save();
                     if (!$info) {
                         throw new ErrorException('红包赎回失败', 6001);
                     }
                     $flag = member::draw_red_packet($member_id, $update);
                     if ($flag['errorNum']) {
                         throw new ErrorException('红包赎回失败', 6001);
                     }
                 }
                 //赎回金额小于等于用户可用收益
                 $info = Info::findOne($member_id);
                 $info->profit = $info['profit'] - $money;
                 $info = $info->save();
                 if (!$info) {
                     throw new ErrorException('赎回失败', 6001);
                 }
                 $info = Info::findOne(['member_id' => $member_id]);
                 $info->balance = $info->balance + $money;
                 $info = $info->save();
                 if (!$info) {
                     throw new ErrorException('赎回金额放入余额失败', 4002);
                 }
                 //由网站设定好的支付利息的账户进行利息支付
                 $sina_config = SinaConfig::find()->select(['sinapay_give_accrual'])->asArray()->one();
                 $profit_id = $sina_config['sinapay_give_accrual'];
                 $profit_info = Info::findOne($profit_id);
                 $profit_info->balance = $profit_info['balance'] - $money;
                 $profit_info = $profit_info->save();
                 if (!$profit_info) {
                     throw new ErrorException('支付利息账户资金减少失败');
                 }
                 //写入职员账户记录表中
                 $clerk = new ClerkLog();
                 $clerk->member_id = $member_id;
                 $clerk->clerk_id = $profit_id;
                 $clerk->behav = ClerkLog::CLERK_BEHAV_TWO;
                 $clerk->step = $money;
                 $clerk->remark = '支付利息职员';
                 $clerk = $clerk->save();
                 if (!$clerk) {
                     throw new ErrorException('写入职员账户记录失败');
                 }
                 //赎回成功进行提现记录
                 $assetlog = new Log();
                 $assetlog->member_id = $member_id;
                 $assetlog->step = $money;
                 $assetlog->action = 'Withdrawals/Redeem';
                 $assetlog->status = self::RSUCCEED;
                 //赎回成功
                 $assetlog->bankcard = $bank_card;
                 $assetlog->remark = '赎回成功';
                 $assetlog->save();
             } else {
                 //赎回金额大于用户可用收益
                 $info = Info::findOne($member_id);
                 $info->profit = 0;
                 $info = $info->save();
                 if (!$info) {
                     throw new ErrorException('赎回收益失败', 6001);
                 }
                 if ($update) {
                     $flag = member::draw_red_packet($member_id, $update);
                     if ($flag['errorNum']) {
                         throw new ErrorException('红包赎回失败', 6001);
                     }
                 }
                 //由网站设定好的支付利息的账户进行利息支付
                 $sina_config = SinaConfig::find()->select(['sinapay_give_accrual'])->asArray()->one();
                 $profit_id = $sina_config['sinapay_give_accrual'];
                 $profit_info = Info::findOne($profit_id);
                 $profit_info->balance = $profit_info['balance'] - $profit;
                 $profit_info = $profit_info->save();
                 if (!$profit_info) {
                     throw new ErrorException('支付利息账户资金减少失败');
                 }
                 //写入职员账户记录表中
                 $clerk = new ClerkLog();
                 $clerk->member_id = $member_id;
                 $clerk->clerk_id = $profit_id;
                 $clerk->behav = ClerkLog::CLERK_BEHAV_TWO;
                 $clerk->step = $profit;
                 $clerk->remark = '支付利息职员';
                 $clerk = $clerk->save();
                 if (!$clerk) {
                     throw new ErrorException('写入职员账户记录失败');
                 }
                 $redeem_money = $money - $profit;
                 // TODO
                 $Redeem = self::Redeem($member_id, $redeem_money);
                 if (!$Redeem) {
                     throw new ErrorException('生成赎回字典失败', 4002);
                 } else {
                     $Redeem = self::Set_redeem($Redeem);
                     if (!$Redeem) {
                         throw new ErrorException('赎回失败');
                     } else {
                         $info = Info::findOne(['member_id' => $member_id]);
                         $info->balance = $info->balance + $money;
                         $info->invest = $info['invest'] - $redeem_money;
                         $info = $info->save();
                         if (!$info) {
                             throw new ErrorException('赎回金额放入余额失败', 4002);
                         }
                         //赎回成功进行提现记录
                         $assetlog = new Log();
                         $assetlog->member_id = $member_id;
                         $assetlog->step = $redeem_money;
                         $assetlog->action = 'Withdrawals/Redeem';
                         $assetlog->status = self::RSUCCEED;
                         //赎回成功
                         $assetlog->bankcard = $bank_card;
                         $assetlog->remark = '赎回成功';
                         $assetlog->save();
                     }
                 }
             }
             $transaction->commit();
             Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
             //赎回结束,操作状态变回常态
             $result = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => null);
             return $result;
         } catch (\Exception $e) {
             $transaction->rollBack();
             //对提现失败信息进行记录
             $remark = $e->getMessage();
             \Yii::error($e->getTraceAsString(), 'app');
             $assetlog = new Log();
             $assetlog->member_id = $member_id;
             $assetlog->step = $money;
             $assetlog->action = 'Withdrawals/Redeem';
             $assetlog->status = self::RERROR;
             //赎回失败
             $assetlog->bankcard = $bank_card;
             $assetlog->remark = '赎回失败' . $remark;
             $assetlog->save();
             Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
             //赎回结束,操作状态变回常态
             $result = array('errorNum' => '1', 'errorMsg' => $remark, 'data' => null);
             return $result;
         }
     } else {
         //赎回金额大于新浪账户与网站账户的差值,取得新浪端赎回金额,网站与新浪都进行赎回操作
         //---新浪货币基金不足以支撑赎回操作---$s_money ---除去新浪货币基金后要进行的赎回金额
         $s_money = $money - $m_fund;
         //新浪端赎回金额
         $profit = (new \yii\db\Query())->select(['profit'])->from('asset_info')->where(['member_id' => $member_id])->one();
         $profit = $profit['profit'];
         //用户的可用收益
         ///进行收益的赎回----假定把红包加到用户收益内
         //++++用户收益足以满足用户的赎回操作---用户直接赎回投资的收益就可以了
         if ($s_money <= $profit + $red_packet) {
             //事物回滚  赎回收益
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 //红包处理---加用户收益 TODO
                 if ($update) {
                     $info = Info::findOne($member_id);
                     $info->profit = $info['profit'] + $red_packet;
                     $info = $info->save();
                     if (!$info) {
                         throw new ErrorException('红包赎回失败', 6001);
                     }
                     $flag = member::draw_red_packet($member_id, $update);
                     if ($flag['errorNum']) {
                         throw new ErrorException('红包赎回失败', 6001);
                     }
                 }
                 //用户收益足以满足用户的赎回操作---用户直接赎回投资的收益就可以了
                 $info = Info::findOne($member_id);
                 $info->profit = $info['profit'] - $s_money;
                 $info = $info->save();
                 if (!$info) {
                     throw new ErrorException('赎回失败', 6001);
                 }
                 //用户只是赎回在投收益---网站给只利息就行了
                 $sina_config = SinaConfig::find()->select(['sinapay_give_accrual'])->asArray()->one();
                 $profit_id = $sina_config['sinapay_give_accrual'];
                 $profit_info = Info::findOne($profit_id);
                 $profit_info->balance = $profit_info['balance'] - $s_money;
                 $profit_info = $profit_info->save();
                 if (!$profit_info) {
                     throw new ErrorException('支付利息账户资金减少失败');
                 }
                 //写入职员账户记录表中
                 $clerk = new ClerkLog();
                 $clerk->member_id = $member_id;
                 $clerk->clerk_id = $profit_id;
                 $clerk->behav = ClerkLog::CLERK_BEHAV_TWO;
                 $clerk->step = $money;
                 $clerk->remark = '支付利息职员';
                 $clerk = $clerk->save();
                 if (!$clerk) {
                     throw new ErrorException('写入职员账户记录失败');
                 }
                 //--网站账户处理成功了----调用第三方新浪接口赎回收益
                 $sina_ransom = sinapay::giveInterest($member_id, $s_money);
                 //赎回收益
                 if ($sina_ransom['errorNum']) {
                     throw new ErrorException($sina_ransom['errorMsg'], 7002);
                 }
                 //更新网站中账户的余额和收益---涉及到货币基金--用户更新数据用$money---实际给付是$s_money
                 $info = Info::findOne(['member_id' => $member_id]);
                 $info->balance = $info->balance + $money;
                 $info = $info->save();
                 if (!$info) {
                     throw new ErrorException('赎回金额放入余额失败', 4002);
                 }
                 //赎回成功进行赎回记录
                 $assetlog = new Log();
                 $assetlog->member_id = $member_id;
                 $assetlog->step = $money;
                 $assetlog->action = 'Withdrawals/Redeem';
                 $assetlog->status = self::RSUCCEED;
                 //赎回成功
                 $assetlog->bankcard = $bank_card;
                 $assetlog->remark = '赎回成功';
                 $assetlog->save();
                 $transaction->commit();
                 Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
                 //赎回结束,操作状态变回常态
                 $result = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => null);
                 return $result;
             } catch (\Exception $e) {
                 $transaction->rollBack();
                 //对提现失败信息进行记录
                 $remark = $e->getMessage();
                 \Yii::error($e->getTraceAsString(), 'app');
                 $assetlog = new Log();
                 $assetlog->member_id = $member_id;
                 $assetlog->step = $money;
                 $assetlog->action = 'Withdrawals/Redeem';
                 $assetlog->status = self::RERROR;
                 //赎回失败
                 $assetlog->bankcard = $bank_card;
                 $assetlog->remark = '赎回失败' . $remark;
                 $assetlog->save();
                 Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
                 //赎回结束,操作状态变回常态
                 $result = array('errorNum' => '1', 'errorMsg' => $remark, 'data' => null);
                 return $result;
             }
         } else {
             //用户的赎回金额大于用户可用收益---需要进行债权赎回操作
             $rh_money = 0;
             //赎回金额
             //如果有活动红包奖励--进行红包加到收益里操作
             //收益大于0,首先赎回收益
             if ($profit + $red_packet > 0) {
                 //事物回滚 赎回收益
                 $transaction = \Yii::$app->db->beginTransaction();
                 try {
                     //红包操作---增加用户的账户再投收益
                     $profit = $profit + $red_packet;
                     if ($update) {
                         $flag = member::draw_red_packet($member_id, $update);
                         if ($flag['errorNum']) {
                             throw new ErrorException('红包赎回失败', 6001);
                         }
                     }
                     //$s_money 是大于用户当前账户中的再投收益的--已经怎加活动奖励红包
                     $info = Info::findOne($member_id);
                     $info->profit = 0;
                     $info = $info->save();
                     if (!$info) {
                         throw new ErrorException('赎回收益失败', 6001);
                     }
                     //由网站设定好的支付利息的账户进行利息支付---再投收益全部赎回了
                     $sina_config = SinaConfig::find()->select(['sinapay_give_accrual'])->asArray()->one();
                     $profit_id = $sina_config['sinapay_give_accrual'];
                     $profit_info = Info::findOne($profit_id);
                     $profit_info->balance = $profit_info['balance'] - $profit;
                     $profit_info = $profit_info->save();
                     if (!$profit_info) {
                         throw new ErrorException('支付利息账户资金减少失败');
                     }
                     //写入职员账户记录表中
                     $clerk = new ClerkLog();
                     $clerk->member_id = $member_id;
                     $clerk->clerk_id = $profit_id;
                     $clerk->behav = ClerkLog::CLERK_BEHAV_TWO;
                     $clerk->step = $profit;
                     $clerk->remark = '支付利息职员';
                     $clerk = $clerk->save();
                     if (!$clerk) {
                         throw new ErrorException('写入职员账户记录失败');
                     }
                     $info = Info::findOne(['member_id' => $member_id]);
                     $info->balance = $info->balance + $profit;
                     $info = $info->save();
                     if (!$info) {
                         throw new ErrorException('赎回收益放入余额失败', 4002);
                     }
                     $sina_ransom = sinapay::giveInterest($member_id, (string) $profit);
                     //调用第三方接口赎回收益
                     if ($sina_ransom['errorNum']) {
                         throw new ErrorException($sina_ransom['errorMsg'], 7002);
                     }
                     //记录用户的赎回金额
                     $rh_money = $profit;
                     $transaction->commit();
                 } catch (\Exception $e) {
                     $transaction->rollBack();
                     //对提现失败信息进行记录
                     $remark = $e->getMessage();
                     \Yii::error($e->getTraceAsString(), 'app');
                     $assetlog = new Log();
                     $assetlog->member_id = $member_id;
                     $assetlog->step = $money;
                     $assetlog->action = 'Withdrawals/Redeem';
                     $assetlog->status = self::RERROR;
                     //赎回失败
                     $assetlog->bankcard = $bank_card;
                     $assetlog->remark = '赎回失败' . $remark;
                     $assetlog->save();
                     Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
                     //赎回结束,操作状态变回常态
                     $result = array('errorNum' => '1', 'errorMsg' => $remark, 'data' => null);
                     return $result;
                 }
             }
             //用户已经赎回了所有的再投收益---计算还需要进行多少的债权赎回操作
             $money = $money - $profit;
             $redeem_dic = self::Redeem($member_id, $money);
             //获取债权字典--进行债权的赎回操作
             foreach ($redeem_dic as $k => $v) {
                 if ($v['thirdmoney'] == 0) {
                     continue;
                 }
                 //事物回滚
                 $transaction = \Yii::$app->db->beginTransaction();
                 try {
                     //网站赎回部分
                     //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) {
                         throw new ErrorException('赎回转让债权失败');
                     }
                     //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) {
                         throw new ErrorException('赎回第三方转让债权失败');
                     }
                     //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) {
                         throw new ErrorException('赎回第三方债权已投金额失败');
                     }
                     //获取债权的最大债权人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) {
                         throw new ErrorException('最大债权人异常');
                     }
                     $max_info = Info::findOne($maxcreditor);
                     $max_info->balance = $max_info['balance'] - $v['thirdmoney'];
                     $max_info = $max_info->save();
                     if (!$max_info) {
                         throw new ErrorException('消减最大债权人账户金额失败');
                     }
                     //写入职员账户记录表中
                     $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('写入职员账户记录失败');
                     }
                     //新浪赎回部分???
                     $k_money = $s_money - $v['thirdmoney'];
                     //赎回金额
                     if ($k_money > 0) {
                         $s_money = $k_money;
                         //获取最大债权人
                         $maxcreditor = (new \yii\db\Query())->select(['maxcreditor'])->from('fund_thirdproduct')->where(['id' => $v['thirdproduct_id']])->one();
                         $maxcreditor = $maxcreditor['maxcreditor'];
                         //调用第三方新浪接口赎回
                         //
                         $money_sina = sprintf("%.2f", $v['thirdmoney']);
                         if ($money_sina > 0) {
                             $sina_ransom = sinapay::sinaRansom($member_id, $money_sina, $maxcreditor);
                             //暂定38为支付利息的用户id
                             if ($sina_ransom['errorNum']) {
                                 throw new ErrorException($sina_ransom['errorMsg'], 7002);
                             }
                         }
                         $info = Info::findOne(['member_id' => $member_id]);
                         $info->balance = $info->balance + $v['thirdmoney'];
                         $info->invest = $info['invest'] - $v['thirdmoney'];
                         $info = $info->save();
                         if (!$info) {
                             $money_log = $money - $s_money + $v['thirdmoney'];
                             throw new ErrorException('成功赎回' . $money_log . '元', 4002);
                         }
                         $rh_money = $rh_money + $v['thirdmoney'];
                         //赎回金额
                     } else {
                         //获取最大债权人
                         $maxcreditor = (new \yii\db\Query())->select(['maxcreditor'])->from('fund_thirdproduct')->where(['id' => $v['thirdproduct_id']])->one();
                         $maxcreditor = $maxcreditor['maxcreditor'];
                         //调用第三方新浪接口赎回
                         $money_sina = sprintf("%.2f", $s_money);
                         if ($money_sina) {
                             $sina_ransom = sinapay::sinaRansom($member_id, $money_sina, $maxcreditor);
                             //暂定38为支付利息的用户id
                             if ($sina_ransom['errorNum']) {
                                 throw new ErrorException($sina_ransom['errorMsg'], 7002);
                             }
                         }
                         $info = Info::findOne(['member_id' => $member_id]);
                         $info->balance = $info->balance + $s_money + $m_fund;
                         $info->invest = $info['invest'] - $s_money - $m_fund;
                         $info = $info->save();
                         if (!$info) {
                             $money_log = $money - $s_money + $m_fund;
                             throw new ErrorException('赎回' . $money_log . '元', 4002);
                         }
                         $rh_money = $rh_money + $s_money + $m_fund;
                         //赎回金额
                     }
                     $transaction->commit();
                 } catch (\Exception $e) {
                     $transaction->rollBack();
                     //对提现失败信息进行记录
                     $remark = $e->getMessage();
                     \Yii::error($e->getTraceAsString(), 'app');
                     $assetlog = new Log();
                     $assetlog->member_id = $member_id;
                     $assetlog->step = $s_money;
                     $assetlog->action = 'Withdrawals/Redeem';
                     $assetlog->status = self::RERROR;
                     //赎回失败
                     $assetlog->bankcard = $bank_card;
                     $assetlog->remark = '赎回失败' . $remark;
                     $assetlog->save();
                     Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
                     $result = array('errorNum' => '1', 'errorMsg' => $remark, 'data' => null);
                     return $result;
                     break;
                 }
             }
             $assetlog = new Log();
             $assetlog->member_id = $member_id;
             $assetlog->step = $rh_money;
             $assetlog->action = 'Withdrawals/Redeem';
             $assetlog->status = self::RSUCCEED;
             //赎回成功
             $assetlog->bankcard = $bank_card;
             $assetlog->remark = '赎回' . $rh_money . '元';
             //赎回金额
             $assetlog->save();
         }
         Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
         //赎回结束,操作状态变回常态
         $result = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => null);
         return $result;
     }
 }
コード例 #3
0
ファイル: sinapay.php プロジェクト: wuwenhan/huoqiwang
 /**
  * 用户解绑定银行卡
  * @param $uid
  * @return array
  */
 public static function unbinding_bank_card($uid)
 {
     $flag = self::getIdentity($uid);
     if (!$flag) {
         $return = array('errorNum' => '1', 'errorMsg' => '用户不存在', 'data' => null);
         return $return;
     }
     //获取付款用户的用户信息
     $SinaBank = SinaBank::find()->where(['uid' => $uid, 'identity_id' => $flag, 'status' => SinaBank::STATUS_BINGING])->one();
     if (!$SinaBank) {
         $return = array('errorNum' => '1', 'errorMsg' => '用户没有绑定银行卡', 'data' => null);
         return $return;
     }
     $identity_id = $flag;
     $card_id = $SinaBank->card_id;
     $sina = new sina();
     $unbinding = $sina->unbinding_bank_card($identity_id, $card_id);
     if ($unbinding) {
         if ($unbinding['response_code'] == 'APPLY_SUCCESS') {
             $SinaBank->status = SinaBank::STATUS_DELETED;
             $SinaBank->msg = '用户解绑定银行卡';
             if ($SinaBank->save()) {
                 //修改网站账户信息---清除账户中的信息
                 Info::updateAll(['bank_card_phone' => '', 'bank_card' => ''], ['member_id' => $uid]);
                 UcenterMember::updateAll(['status' => UcenterMember::STATUS_REAL], ['id' => $uid]);
                 $return = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => null);
                 return $return;
             } else {
                 $return = array('errorNum' => '1', 'errorMsg' => '网站解绑失败', 'data' => null);
                 return $return;
             }
         } else {
             $return = array('errorNum' => '1', 'errorMsg' => $unbinding['response_message'], 'data' => null);
             return $return;
         }
     } else {
         $return = array('errorNum' => '1', 'errorMsg' => '新浪接口错误', 'data' => null);
         return $return;
     }
 }
コード例 #4
0
ファイル: Invest.php プロジェクト: wuwenhan/huoqiwang
 /**
  * Auther:langxi
  * $member_id:用户id,$product_id:项目id,$money:用户投资钱数
  * 用户投资
  */
 public static function invest($member_id, $product_id, $money)
 {
     ini_set('max_execution_time', 60);
     $member_id = (int) $member_id;
     $product_id = (int) $product_id;
     $money = (double) $money;
     //判断用户是否可进行投资操作
     $is_go = Info::find()->select(['status'])->where(['member_id' => $member_id])->asArray()->one();
     if ($is_go['status'] > 0) {
         Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
         $result = array('errorNum' => '1', 'errorMsg' => '处理中,请稍后再试', 'data' => null);
         return $result;
     }
     Info::updateAll(['status' => Info::GO_TWO], ['member_id' => $member_id]);
     //进行操作,状态变为投资处理中
     //检测用户投资资金,次数
     $check_invest = self::check_invest($member_id, $product_id, $money);
     if ($check_invest['errorNum']) {
         Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
         return $check_invest;
     }
     //检测用户状态
     $checkMember = self::checkMember($member_id);
     if ($checkMember) {
         Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
         return $checkMember;
     }
     //检测用户账户余额是否满足投资金额
     $card = Info::find()->where(['member_id' => $member_id])->asArray()->one();
     if ($card['balance'] < $money) {
         Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
         $result = array('errorNum' => '1', 'errorMsg' => '账户金额不足,请进行充值', 'data' => null);
         return $result;
     }
     //检测投资金额是否满足项目的每次投资最大最小额度限制
     $checkMoney = self::checkMoney($product_id, $money);
     if ($checkMoney) {
         Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
         return $checkMoney;
     }
     //检测项目状态
     $checkProduct = self::checkProduct($product_id, $money);
     if ($checkProduct) {
         Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
         return $checkProduct;
     }
     $asset = Info::find()->where(['member_id' => $member_id])->asArray()->one();
     $bank_card = $asset['bank_card'];
     //用户银行卡
     $product = Product::find()->where(['id' => $product_id])->asArray()->one();
     $end_at = $product['end_at'];
     //项目投资终止时间
     //事物回滚
     $transaction = \Yii::$app->db->beginTransaction();
     try {
         //将账户中的钱取出,放入冻结金额中
         $asset = Info::findOne($member_id);
         $asset->balance = $asset['balance'] - $money;
         $asset->freeze = $asset['freeze'] + $money;
         $asset = $asset->save();
         if (!$asset) {
             throw new ErrorException('投资失败', 4002);
         }
         if ($product['type'] == Product::TYPE_THIRD) {
             //进行投资将钱放入order中  type=1债权转让项目(一对多)
             $order = new Order();
             $order->member_id = $member_id;
             $order->product_id = $product_id;
             $order->type = Product::TYPE_THIRD;
             $order->money = $money;
             $order->start_money = $money;
             $order->status = Order::STATUS_ACTIVE;
             //1标识订单状态进行
             $order->start_at = time();
             $order->end_at = $end_at;
             $order = $order->save();
             if (!$order) {
                 throw new ErrorException('投资失败', 4002);
             }
         } else {
             //进行投资将钱放入order中   type=0债权项目(一对一)
             $order = new Order();
             $order->member_id = $member_id;
             $order->product_id = $product_id;
             $order->type = Product::TYPE_PRO;
             $order->money = $money;
             $order->start_money = $money;
             $order->status = Order::STATUS_ACTIVE;
             //1标识订单状态进行
             $order->start_at = time();
             $order->end_at = $end_at;
             $order = $order->save();
             if (!$order) {
                 throw new ErrorException('投资失败', 4002);
             }
         }
         //检测用户是否投资过该项目,进行项目投资人数加一处理,项目已投金额增长
         $check_people = self::check_people($member_id, $product_id);
         if ($check_people) {
             $product = Product::find()->where(['id' => $product_id])->asArray()->one();
             $product_money = $product['invest_sum'] + $money;
             $total_money = $product['amount'];
             if ($product_money > $total_money) {
                 throw new ErrorException('您投资的金额大于该项目剩余的额度', 4002);
             }
             $product = Product::findOne($product_id);
             $product->invest_sum = $product['invest_sum'] + $money;
             if ($product['amount'] - $product['invest_sum'] < 10) {
                 $product->status = Product::STATUS_OUT;
             }
             $product->invest_people = $product['invest_people'] + 1;
             $res = $product->save();
             if (!$res) {
                 throw new ErrorException('项目已投金额、投资人数增加失败', 4002);
             }
         } else {
             $product = Product::find()->where(['id' => $product_id])->asArray()->one();
             $product_money = $product['invest_sum'] + $money;
             $total_money = $product['amount'];
             if ($product_money > $total_money) {
                 throw new ErrorException('您投资的金额大于该项目剩余的额度', 4002);
             }
             $product = Product::findOne($product_id);
             $product->invest_sum = $product['invest_sum'] + $money;
             if ($product['amount'] - $product['invest_sum'] < 10) {
                 $product->status = Product::STATUS_OUT;
             }
             $res = $product->save();
             if (!$res) {
                 throw new ErrorException('项目已投金额增加失败', 4002);
             }
         }
         //type=1为一对多项目债权转让,等于0为债权项目一对一(只存在于product表中于thirdproduct无关)
         //获取用户此次投资此项目的债权字典
         $thirdArr = self::creditor_dic($product_id, $money);
         //按照生成的债权字典,将钱分配给债权表
         $setthird = self::set_Third($thirdArr, $member_id);
         if ($setthird) {
             return $setthird;
         }
         //删减用户账户冻结金额
         $asset = Info::find()->where(['member_id' => $member_id])->asArray()->one();
         $freeze = $asset['freeze'];
         //获取用户账户新的冻结金额
         $asset = Info::findOne($member_id);
         $asset->freeze = $freeze - $money;
         $asset->invest = $asset['invest'] + $money;
         $asset->total_invest = $asset['total_invest'] + $money;
         //网站投资流程完成,增加用户累计投资额
         $asset = $asset->save();
         if (!$asset) {
             throw new ErrorException('删减冻结金额失败', 4002);
         }
         //投资成功进行投资记录
         $assetlog = new Log();
         $assetlog->member_id = $member_id;
         $assetlog->product_id = $product_id;
         $assetlog->step = $money;
         $assetlog->action = 'Invest/invest';
         $assetlog->status = self::INVESTSUCCEED;
         //2标识投资成功
         $assetlog->bankcard = $bank_card;
         $assetlog->remark = '投资成功';
         $assetlog->save();
         //处理债权字典,生成用于第三方代收的数据字典,键值为用户id,值为钱数 , $sina_pay为第三方代收函数需要的参数
         $sina_dic = array();
         foreach ($thirdArr as $v) {
             $sina_dic['m' . $v['maxcreditor']][] = array($v['mcmoney'], $v['maxcreditor']);
             $sina_dic['c' . $v['creditor']][] = array($v['ocmoney'], $v['creditor']);
         }
         $sina_pay = array();
         foreach ($sina_dic as $key => $val) {
             foreach ($val as $k => $v) {
                 if (!isset($sina_pay[$v['1']])) {
                     $sina_pay[$v['1']] = $v['0'];
                 } else {
                     $sina_pay[$v['1']] += $v['0'];
                 }
             }
         }
         //过滤掉金额为空的数组,得到第三方代收函数需要的参数,$sina_pay
         foreach ($sina_pay as $key => $value) {
             if (empty($value)) {
                 unset($sina_pay[$key]);
             }
         }
         //调用封装好的第三方接口
         $sina_invest = sinapay::invest((string) $member_id, (string) $product_id, (string) $money);
         //托管代收接口
         if ($sina_invest['errorNum']) {
             throw new ErrorException($sina_invest['errorMsg'], 7001);
         }
         $sina_peyee = sinapay::batchPay($sina_pay, $sina_invest['data']['out_trade_no']);
         //托管批量代付接口
         if ($sina_peyee['errorNum']) {
             $sina_refund = sinapay::hostingRefund($sina_invest['data']['identity_id'], $sina_invest['data']['out_trade_no'], $sina_invest['data']['money']);
             if ($sina_refund['errorNum']) {
                 throw new ErrorException($sina_refund['errorMsg'], 7001);
             }
             throw new ErrorException($sina_peyee['errorMsg'], 7001);
         }
         //总投资记录
         $total_log = self::total_log($member_id, $money);
         if ($total_log) {
             return $total_log;
         }
         $transaction->commit();
         Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
         $result = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => null);
         return $result;
     } catch (\Exception $e) {
         $transaction->rollBack();
         //对投资失败信息进行记录
         $remark = $e->getMessage();
         $assetlog = new Log();
         $assetlog->member_id = $member_id;
         $assetlog->product_id = $product_id;
         $assetlog->step = $money;
         $assetlog->action = 'Invest/Invest';
         $assetlog->status = self::INVESTERROR;
         //-2标识投资失败
         $assetlog->bankcard = $bank_card;
         $assetlog->remark = $remark;
         $assetlog->save();
         $result = array('errorNum' => '1', 'errorMsg' => $remark, 'data' => null);
         Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
         return $result;
     }
 }
コード例 #5
0
ファイル: Withdrawals.php プロジェクト: wuwenhan/huoqiwang
 /**
  * Authre:langxi
  *
  * 用户赎回操作
  */
 public static function User_redeem($member_id, $money)
 {
     ini_set('max_execution_time', 60);
     //判断用户是否可进行赎回操作
     $is_go = Info::find()->select(['status'])->where(['member_id' => $member_id])->asArray()->one();
     if ($is_go['status'] > 0) {
         throw new ErrorException('处理中,请稍后再试');
     }
     Info::updateAll(['status' => Info::GO_THREE], ['member_id' => $member_id]);
     //赎回进行中
     //检查用户一日赎回
     $check_redeem = self::check_redeem($member_id, $money);
     if ($check_redeem) {
         Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
         throw new ErrorException($check_redeem);
     }
     //判断赎回金额是否小于新浪账户与网站账户余额的差值,若小于则网站端进行赎回操作,先赎回利息,然后赎回订单中的金额。
     //若大于求取差值获取到网站需要赎回的金额和新浪部分需要赎回的金额,然后两端分别进行赎回操作,先赎回利息,然后赎回订单中的金额
     $asset = Info::find()->where(['member_id' => $member_id])->asArray()->one();
     $bank_card = $asset['bank_card'];
     //判断用户赎回金额是否可赎回。
     $order_money = (new \yii\db\Query())->select(['money'])->from('fund_orders')->where(['member_id' => $member_id])->andWhere(['>', 'money', '0'])->sum('money');
     if ($order_money + $asset['profit'] < $money) {
         Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
         //赎回结束,操作状态变回常态
         throw new ErrorException('赎回金额大于在投金额,请重新输入');
     }
     $w_blance = self::showBlance($member_id);
     //网站余额
     $s_blance = sinapay::querySinaBalance($member_id);
     //调用第三方接口查看新浪账户可用余额(含货币基金
     if ($s_blance['errorNum']) {
         Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
         //赎回结束,操作状态变回常态
         throw new ErrorException($s_blance['errorMsg'], 7003);
     }
     if ($w_blance > $s_blance['data']['available_balance']) {
         Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
         //赎回结束,操作状态变回常态
         throw new ErrorException('账户异常请联系客服', 7003);
     }
     $m_fund = $s_blance['data']['available_balance'] - $w_blance;
     //新浪账户比网站账户多的钱
     if ($m_fund > $money) {
         //事物回滚
         $transaction = \Yii::$app->db->beginTransaction();
         try {
             //赎回金额小于新浪账户与网站账户的差值,仅网站端进行赎回操作
             $profit = (new \yii\db\Query())->select(['profit'])->from('asset_info')->where(['member_id' => $member_id])->one();
             $profit = $profit['profit'];
             //用户的可用收益
             if ($money <= $profit) {
                 //赎回金额小于等于用户可用收益
                 $info = Info::findOne($member_id);
                 $info->profit = $info['profit'] - $money;
                 $info = $info->save();
                 if (!$info) {
                     throw new ErrorException('赎回失败', 6001);
                 }
                 $info = Info::findOne(['member_id' => $member_id]);
                 $info->balance = $info->balance + $money;
                 $info = $info->save();
                 if (!$info) {
                     throw new ErrorException('赎回金额放入余额失败', 4002);
                 }
                 //由网站设定好的支付利息的账户进行利息支付
                 $sina_config = SinaConfig::find()->select(['sinapay_give_accrual'])->asArray()->one();
                 $profit_id = $sina_config['sinapay_give_accrual'];
                 $profit_info = Info::findOne($profit_id);
                 $profit_info->balance = $profit_info['balance'] - $money;
                 $profit_info = $profit_info->save();
                 if (!$profit_info) {
                     throw new ErrorException('支付利息账户资金减少失败');
                 }
                 //写入职员账户记录表中
                 $clerk = new ClerkLog();
                 $clerk->member_id = $member_id;
                 $clerk->clerk_id = $profit_id;
                 $clerk->behav = ClerkLog::CLERK_BEHAV_TWO;
                 $clerk->step = $money;
                 $clerk->remark = '支付利息职员';
                 $clerk = $clerk->save();
                 if (!$clerk) {
                     throw new ErrorException('写入职员账户记录失败');
                 }
                 //赎回成功进行记录
                 $assetlog = new Log();
                 $assetlog->member_id = $member_id;
                 $assetlog->step = $money;
                 $assetlog->action = 'Withdrawals/Redeem';
                 $assetlog->status = self::RSUCCEED;
                 //赎回成功
                 $assetlog->bankcard = $bank_card;
                 $assetlog->remark = '赎回成功';
                 $assetlog->save();
             } else {
                 //赎回金额大于用户可用收益
                 $info = Info::findOne($member_id);
                 $info->profit = 0;
                 $info = $info->save();
                 if (!$info) {
                     throw new ErrorException('赎回收益失败', 6001);
                 }
                 //由网站设定好的支付利息的账户进行利息支付
                 $sina_config = SinaConfig::find()->select(['sinapay_give_accrual'])->asArray()->one();
                 $profit_id = $sina_config['sinapay_give_accrual'];
                 $profit_info = Info::findOne($profit_id);
                 $profit_info->balance = $profit_info['balance'] - $profit;
                 $profit_info = $profit_info->save();
                 if (!$profit_info) {
                     throw new ErrorException('支付利息账户资金减少失败');
                 }
                 //写入职员账户记录表中
                 $clerk = new ClerkLog();
                 $clerk->member_id = $member_id;
                 $clerk->clerk_id = $profit_id;
                 $clerk->behav = ClerkLog::CLERK_BEHAV_TWO;
                 $clerk->step = $profit;
                 $clerk->remark = '支付利息职员';
                 $clerk = $clerk->save();
                 if (!$clerk) {
                     throw new ErrorException('写入职员账户记录失败');
                 }
                 $redeem_money = $money - $profit;
                 $Redeem = self::Redeem($member_id, $redeem_money);
                 if (!$Redeem) {
                     throw new ErrorException('生成赎回字典失败', 4002);
                 } else {
                     $Redeem = self::Set_redeem($Redeem);
                     if (!$Redeem) {
                         throw new ErrorException('赎回失败');
                     } else {
                         $info = Info::findOne(['member_id' => $member_id]);
                         $info->balance = $info->balance + $money;
                         $info->invest = $info['invest'] - $money;
                         $info = $info->save();
                         if (!$info) {
                             throw new ErrorException('赎回金额放入余额失败', 4002);
                         }
                         //赎回成功进行提现记录
                         $assetlog = new Log();
                         $assetlog->member_id = $member_id;
                         $assetlog->step = $money;
                         $assetlog->action = 'Withdrawals/Redeem';
                         $assetlog->status = self::RSUCCEED;
                         //赎回成功
                         $assetlog->bankcard = $bank_card;
                         $assetlog->remark = '赎回成功';
                         $assetlog->save();
                     }
                 }
             }
             $transaction->commit();
             Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
             //赎回结束,操作状态变回常态
             return true;
         } catch (\Exception $e) {
             $transaction->rollBack();
             //对提现失败信息进行记录
             $remark = $e->getMessage();
             $assetlog = new Log();
             $assetlog->member_id = $member_id;
             $assetlog->step = $money;
             $assetlog->action = 'Withdrawals/Redeem';
             $assetlog->status = self::RERROR;
             //赎回失败
             $assetlog->bankcard = $bank_card;
             $assetlog->remark = '赎回失败' . $remark;
             $assetlog->save();
             Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
             return false;
         }
     } else {
         //赎回金额大于新浪账户与网站账户的差值,取得新浪端赎回金额,网站与新浪都进行赎回操作
         $s_money = $money - $m_fund;
         //新浪端赎回金额
         $profit = (new \yii\db\Query())->select(['profit'])->from('asset_info')->where(['member_id' => $member_id])->one();
         $profit = $profit['profit'];
         //用户的可用收益
         if ($s_money <= $profit) {
             //事物回滚  赎回收益
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 //新浪赎回金额小于等于用户可用收益
                 $info = Info::findOne($member_id);
                 $info->profit = $info['profit'] - $money;
                 $info = $info->save();
                 if (!$info) {
                     throw new ErrorException('赎回失败', 6001);
                 }
                 //由网站设定好的支付利息的账户进行利息支付
                 $sina_config = SinaConfig::find()->select(['sinapay_give_accrual'])->asArray()->one();
                 $profit_id = $sina_config['sinapay_give_accrual'];
                 $profit_info = Info::findOne($profit_id);
                 $profit_info->balance = $profit_info['balance'] - $money;
                 $profit_info = $profit_info->save();
                 if (!$profit_info) {
                     throw new ErrorException('支付利息账户资金减少失败');
                 }
                 //写入职员账户记录表中
                 $clerk = new ClerkLog();
                 $clerk->member_id = $member_id;
                 $clerk->clerk_id = $profit_id;
                 $clerk->behav = ClerkLog::CLERK_BEHAV_TWO;
                 $clerk->step = $money;
                 $clerk->remark = '支付利息职员';
                 $clerk = $clerk->save();
                 if (!$clerk) {
                     throw new ErrorException('写入职员账户记录失败');
                 }
                 //调用第三方新浪接口赎回收益
                 $sina_ransom = sinapay::giveInterest($member_id, $s_money);
                 //赎回收益
                 if ($sina_ransom['errorNum']) {
                     throw new ErrorException($sina_ransom['errorMsg'], 7002);
                 }
                 $info = Info::findOne(['member_id' => $member_id]);
                 $info->balance = $info->balance + $money;
                 $info = $info->save();
                 if (!$info) {
                     throw new ErrorException('赎回金额放入余额失败', 4002);
                 }
                 //赎回成功进行提现记录
                 $assetlog = new Log();
                 $assetlog->member_id = $member_id;
                 $assetlog->step = $money;
                 $assetlog->action = 'Withdrawals/Redeem';
                 $assetlog->status = self::RSUCCEED;
                 //赎回成功
                 $assetlog->bankcard = $bank_card;
                 $assetlog->remark = '赎回成功';
                 $assetlog->trade_no = $sina_ransom['data']['trade_no'];
                 $assetlog->save();
                 $transaction->commit();
                 Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
                 //赎回结束,操作状态变回常态
                 return true;
             } catch (\Exception $e) {
                 $transaction->rollBack();
                 //对提现失败信息进行记录
                 $remark = $e->getMessage();
                 $assetlog = new Log();
                 $assetlog->member_id = $member_id;
                 $assetlog->step = $money;
                 $assetlog->action = 'Withdrawals/Redeem';
                 $assetlog->status = self::RERROR;
                 //赎回失败
                 $assetlog->bankcard = $bank_card;
                 $assetlog->remark = '赎回失败' . $remark;
                 $assetlog->trade_no = $sina_ransom['data']['trade_no'];
                 $assetlog->save();
                 Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
                 return false;
             }
         } else {
             //新浪赎回金额大于用户可用收益
             $rh_money = 0;
             //赎回金额
             if ($profit > 0) {
                 //收益大于0,赎回收益
                 //事物回滚 赎回收益
                 $transaction = \Yii::$app->db->beginTransaction();
                 try {
                     $info = Info::findOne($member_id);
                     $info->profit = 0;
                     $info = $info->save();
                     if (!$info) {
                         throw new ErrorException('赎回收益失败', 6001);
                     }
                     //由网站设定好的支付利息的账户进行利息支付
                     $sina_config = SinaConfig::find()->select(['sinapay_give_accrual'])->asArray()->one();
                     $profit_id = $sina_config['sinapay_give_accrual'];
                     $profit_info = Info::findOne($profit_id);
                     $profit_info->balance = $profit_info['balance'] - $profit;
                     $profit_info = $profit_info->save();
                     if (!$profit_info) {
                         throw new ErrorException('支付利息账户资金减少失败');
                     }
                     //写入职员账户记录表中
                     $clerk = new ClerkLog();
                     $clerk->member_id = $member_id;
                     $clerk->clerk_id = $profit_id;
                     $clerk->behav = ClerkLog::CLERK_BEHAV_TWO;
                     $clerk->step = $profit;
                     $clerk->remark = '支付利息职员';
                     $clerk = $clerk->save();
                     if (!$clerk) {
                         throw new ErrorException('写入职员账户记录失败');
                     }
                     $info = Info::findOne(['member_id' => $member_id]);
                     $info->balance = $info->balance + $profit;
                     $info = $info->save();
                     if (!$info) {
                         throw new ErrorException('赎回收益放入余额失败', 4002);
                     }
                     $sina_ransom = sinapay::giveInterest($member_id, (string) $profit);
                     //调用第三方接口赎回收益
                     if ($sina_ransom['errorNum']) {
                         throw new ErrorException($sina_ransom['errorMsg'], 7002);
                     }
                     $rh_money = $profit;
                     //赎回金额
                     $transaction->commit();
                 } catch (\Exception $e) {
                     $transaction->rollBack();
                     //对提现失败信息进行记录
                     $remark = $e->getMessage();
                     $assetlog = new Log();
                     $assetlog->member_id = $member_id;
                     $assetlog->step = $money;
                     $assetlog->action = 'Withdrawals/Redeem';
                     $assetlog->status = self::RERROR;
                     //赎回失败
                     $assetlog->bankcard = $bank_card;
                     $assetlog->remark = '赎回失败' . $remark;
                     $assetlog->save();
                     Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
                     return false;
                 }
             }
             $money = $money - $profit;
             $redeem_dic = self::Redeem($member_id, $money);
             //获取债权字典
             foreach ($redeem_dic as $k => $v) {
                 //事物回滚
                 $transaction = \Yii::$app->db->beginTransaction();
                 try {
                     //网站赎回部分
                     //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) {
                         throw new ErrorException('赎回转让债权失败');
                     }
                     //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) {
                         throw new ErrorException('赎回第三方转让债权失败');
                     }
                     //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) {
                         throw new ErrorException('赎回第三方债权已投金额失败');
                     }
                     //获取债权的最大债权人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) {
                         throw new ErrorException('最大债权人异常');
                     }
                     $max_info = Info::findOne($maxcreditor);
                     $max_info->balance = $max_info['balance'] - $v['thirdmoney'];
                     $max_info = $max_info->save();
                     if (!$max_info) {
                         throw new ErrorException('消减最大债权人账户金额失败');
                     }
                     //写入职员账户记录表中
                     $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('写入职员账户记录失败');
                     }
                     //新浪赎回部分
                     $k_money = $s_money - $v['thirdmoney'];
                     //赎回金额
                     if ($k_money > 0) {
                         $s_money = $k_money;
                         //获取最大债权人
                         $maxcreditor = (new \yii\db\Query())->select(['maxcreditor'])->from('fund_thirdproduct')->where(['id' => $v['thirdproduct_id']])->one();
                         $maxcreditor = $maxcreditor['maxcreditor'];
                         //调用第三方新浪接口赎回
                         $sina_ransom = sinapay::sinaRansom($member_id, (string) $v['thirdmoney'], $maxcreditor);
                         if ($sina_ransom['errorNum']) {
                             throw new ErrorException($sina_ransom['errorMsg'], 7002);
                         }
                         $info = Info::findOne(['member_id' => $member_id]);
                         $info->balance = $info->balance + $v['thirdmoney'];
                         $info->invest = $info['invest'] - $v['thirdmoney'];
                         $info = $info->save();
                         if (!$info) {
                             $money_log = $money - $s_money + $v['thirdmoney'];
                             throw new ErrorException('成功赎回' . $money_log . '元', 4002);
                         }
                         $rh_money = $rh_money + $v['thirdmoney'];
                         //赎回金额
                     } else {
                         //获取最大债权人
                         $maxcreditor = (new \yii\db\Query())->select(['maxcreditor'])->from('fund_thirdproduct')->where(['id' => $v['thirdproduct_id']])->one();
                         $maxcreditor = $maxcreditor['maxcreditor'];
                         //调用第三方新浪接口赎回
                         $sina_ransom = sinapay::sinaRansom($member_id, (string) $s_money, $maxcreditor);
                         //暂定38为支付利息的用户id
                         if ($sina_ransom['errorNum']) {
                             throw new ErrorException($sina_ransom['errorMsg'], 7002);
                         }
                         $info = Info::findOne(['member_id' => $member_id]);
                         $info->balance = $info->balance + $s_money + $m_fund;
                         $info->invest = $info['invest'] - $s_money - $m_fund;
                         $info = $info->save();
                         if (!$info) {
                             $money_log = $money - $s_money + $m_fund;
                             throw new ErrorException('赎回' . $money_log . '元', 4002);
                         }
                         $rh_money = $rh_money + $s_money + $m_fund;
                         //赎回金额
                     }
                     $transaction->commit();
                 } catch (\Exception $e) {
                     $transaction->rollBack();
                     //对提现失败信息进行记录
                     $remark = $e->getMessage();
                     $assetlog = new Log();
                     $assetlog->member_id = $member_id;
                     $assetlog->step = $s_money;
                     $assetlog->action = 'Withdrawals/Redeem';
                     $assetlog->status = self::RERROR;
                     //赎回失败
                     $assetlog->bankcard = $bank_card;
                     $assetlog->remark = '赎回失败' . $remark;
                     $assetlog->trade_no = $sina_ransom['data']['trade_no'];
                     $assetlog->save();
                     Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
                     throw new ErrorException($remark, 5005);
                     break;
                     //异常跳出赎回操作
                 }
             }
             $assetlog = new Log();
             $assetlog->member_id = $member_id;
             $assetlog->step = $rh_money;
             $assetlog->action = 'Withdrawals/Redeem';
             $assetlog->status = self::RSUCCEED;
             //赎回成功
             $assetlog->bankcard = $bank_card;
             $assetlog->remark = '赎回' . $rh_money . '元';
             $assetlog->trade_no = $sina_ransom['data']['trade_no'];
             $assetlog->save();
         }
         Info::updateAll(['status' => '0'], ['member_id' => $member_id]);
         return true;
     }
 }