コード例 #1
0
 /**
  * @brief 提现付款给用户账号成功
  *
  * @return  public function 
  * @retval   
  * @see 
  * @note 
  * @author 吕宝贵
  * @date 2015/12/06 20:31:42
  **/
 public function processWithdrawPaySuccess($payId, $paySuccessCallback)
 {
     $payable = Payable::findOne($payId);
     if (!$payable) {
         $this->addError('display-error', '获取付款记录信息失败');
         return false;
     }
     //处理交易信息
     $trans = $payable->trans;
     $trans->status = Trans::PAY_STATUS_FINISHED;
     if (!$trans->save()) {
         $this->addError('display-error', '交易信息保存失败');
         return false;
     }
     $withdrawUser = $this->getUserAccount($payable->receive_uid);
     //完成冻结,将款项从冻结中减除
     if ($withdrawUser->finishFreeze($trans->total_money)) {
         return true;
     } else {
         $this->addError('display-error', '减除用户冻结余额时出错!');
         $this->addErrors($withdrawUser->getErrors());
         return false;
     }
     //冻结记录完成
     $freeze = Freeze::fineOne(['trans_id' => $trans->id, 'type' => Freeze::FREEZE_TYPE_WITHDRAW]);
     if (!$freeze) {
         $this->addError('display-error', '冻结记录不存在');
         return false;
     }
     if (!$freeze->finishFreeze()) {
         $this->addError('display-error', '冻结记录无法更改状态');
         return false;
     }
     //用户设定的回调操作
     $callbackData['id'] = $withdrawId;
     return call_user_func($paySuccessCallback, $callbackData);
 }
コード例 #2
0
ファイル: Account.php プロジェクト: lubaogui/yii2-account
 /**
  * @brief 处理实际的提现流程,只有在提现审核通过之后才会调用此方法 
  * 来产生trans
  *
  * @return  public function 
  * @author 吕宝贵
  * @date 2015/12/06 17:44:54
  **/
 public function processWithdraw($withdrawId)
 {
     $withdraw = UserWithdraw::findOne($withdrawId);
     if (empty($withdraw)) {
         $this->addError(__METHOD__, '提现申请记录不存在');
         return false;
     }
     $withdrawUser = $this->getUserAccount($withdraw->uid);
     //生成trans
     $trans = new Trans();
     $trans->trans_id_ext = $withdrawId;
     $trans->trans_type_id = Trans::TRANS_TYPE_WITHDRAW;
     $trans->status = Trans::PAY_STATUS_WAITPAY;
     $trans->pay_mode = Trans::PAY_MODE_DIRECTPAY;
     $trans->total_money = $withdraw->money;
     $trans->from_uid = $withdraw->uid;
     $trans->to_uid = $withdraw->uid;
     $trans->currency = 1;
     if (!$trans->save()) {
         $this->addError('display-error', '处理提现时保存交易信息出错');
         $this->addErrors($trans->getErrors());
         return false;
     }
     $freeze = Freeze::findOne(['source_id' => $withdraw->id]);
     if (!$freeze) {
         $this->addError('display-error', '找不到冻结记录');
         return false;
     }
     //设置freeze记录关联的transId
     $freeze->trans_id = $trans->id;
     if (!$freeze->save()) {
         $this->addError('display-error', '冻结记录回写交易信息失败');
         $this->addErrors($freeze->getErrors());
         return false;
     }
     //生成打款记录
     $payable = null;
     if (!($payable = Payable::findOne(['trans_id' => $trans->id]))) {
         $payable = new Payable();
     }
     $payable->trans_id = $trans->id;
     $payable->pay_uid = 0;
     $payable->receive_uid = $trans->to_uid;
     $payable->currency = 1;
     $payable->money = $trans->total_money;
     $payable->status = Payable::PAY_STATUS_WAITPAY;
     $payable->pay_method = Payable::PAY_METHOD_DIRECTPAY;
     //保存打款记录,供财务下载打款处理
     if ($payable->save()) {
         return true;
     } else {
         $this->addErrors($payable->getErrors());
         return false;
     }
 }
コード例 #3
0
ファイル: BaseAccount.php プロジェクト: lubaogui/yii2-account
 /**
  * @brief 用户帐户变动的核心函数,所有的变动都需要通过此函数来记录
  *
  * @return  public function 
  * @retval   
  * @see 
  * @note 
  * @author 吕宝贵
  * @date 2015/12/30 14:39:00
  **/
 protected function balance($uid, $balanceType, $money, $transId, $description, $currency)
 {
     $freezeCat = false;
     $freeze = null;
     $trans = null;
     Yii::warning('进入balance页面', __METHOD__);
     Yii::warning('uid and balanceType:' . $uid . '---' . $balanceType, __METHOD__);
     if (in_array($balanceType, [UserAccount::BALANCE_TYPE_FREEZE, UserAccount::BALANCE_TYPE_UNFREEZE, UserAccount::BALANCE_TYPE_FINISH_FREEZE])) {
         $freezeCat = true;
         $freeze = Freeze::findOne($transId);
         if (!$freeze) {
             $this->addError('trans', '不存在该交易订单');
             return false;
         }
     } else {
         //根据交易号查找对应的交易
         $trans = Trans::findOne($transId);
         if (!$trans) {
             $this->addError('trans', '不存在该交易订单');
             return false;
         }
     }
     Yii::warning('获取用户帐户', __METHOD__);
     $userAccount = $this->getUserAccount($uid);
     Yii::warning('判断账户变更类型', __METHOD__);
     switch ($balanceType) {
         case UserAccount::BALANCE_TYPE_PLUS:
             $userAccount->plus($money);
             break;
         case UserAccount::BALANCE_TYPE_MINUS:
             $userAccount->minus($money);
             break;
         case UserAccount::BALANCE_TYPE_FREEZE:
             Yii::warning('进入帐号金额冻结');
             $userAccount->freeze($money);
             break;
         case UserAccount::BALANCE_TYPE_UNFREEZE:
             $userAccount->unFreeze($money);
             break;
         case UserAccount::BALANCE_TYPE_FINISH_FREEZE:
             $userAccount->finishFreeze($money);
             break;
         default:
             $this->addError(__METHOD__, '不支持提交的账户操作类型');
             return false;
     }
     if ($userAccount->save()) {
         //记录账单
         Yii::warning('产生用户账单', __METHOD__);
         $bill = new Bill();
         $bill->uid = $userAccount->uid;
         if (!$freezeCat) {
             $bill->trans_id = $trans->id;
             $bill->trans_type_id = $trans->trans_type_id;
             $bill->trans_type_name = $trans->transType->name;
         } else {
             $bill->trans_id = $freeze->id;
         }
         $bill->money = $money;
         $bill->balance_type = $balanceType;
         $bill->currency = $currency;
         $bill->description = $description;
         if (!$bill->save()) {
             $this->addErrors($bill->getErrors());
             return false;
         }
         Yii::warning('产生账户快照', __METHOD__);
         //账户快照产生
         $accountLog = new UserAccountLog();
         $accountLog->uid = $userAccount->uid;
         $accountLog->account_type = $userAccount->type;
         $accountLog->currency = $currency;
         if (!$freezeCat) {
             $accountLog->trans_id = $trans->id;
         } else {
             $accountLog->trans_id = $freeze->id;
         }
         $accountLog->balance = $userAccount->balance;
         $accountLog->deposit = $userAccount->deposit;
         $accountLog->frozen_money = $userAccount->frozen_money;
         $accountLog->balance_type = $balanceType;
         $accountLog->trans_money = $money;
         $accountLog->trans_desc = $description;
         Yii::warning('保存账户信息', __METHOD__);
         if (!$accountLog->save()) {
             //$this->addErrors($accountLog->getErrors());
             Yii::warning('保存账户快照失败', __METHOD__);
             Yii::warning($accountLog->getErrors(), __METHOD__);
             return false;
         } else {
             Yii::warning('保存账户快照成功', __METHOD__);
             return true;
         }
     } else {
         return false;
     }
 }
コード例 #4
0
ファイル: Trans.php プロジェクト: tqsq2005/yii2-account
 /**
  * @brief 获取交易对应的冻结记录,只有在提现场景下,该值才不为空
  *
  * @return  public function 
  * @retval   
  * @see 
  * @note 
  * @author 吕宝贵
  * @date 2016/01/03 20:58:56
  **/
 public function getFreeze()
 {
     return $this->hasOne(Freeze::className(), ['trans_id' => 'id']);
 }