Пример #1
0
 /**
  * @brief 根据用户的输入产生交易记录
  *
  * @return  public function 
  * @retval   
  * @see 
  * @note 
  * @author 吕宝贵
  * @date 2015/12/19 20:39:07
  **/
 public function generateTrans()
 {
     $product = Product::findOne(['pid' => $this->booking->pid]);
     $buyerAccount = Yii::$app->account->getUserAccount(Yii::$app->user->identity['uid']);
     //根据booking_id生成交易记录
     $trans = new Trans();
     $trans->pay_mode = Trans::PAY_MODE_VOUCHPAY;
     $trans->trans_type_id = Trans::TRANS_TYPE_TRADE;
     $trans->currency = 1;
     $trans->total_money = $this->booking->price_final;
     $trans->profit = $this->booking->price_for_platform;
     $trans->money = $trans->total_money - $trans->profit;
     //保证金,目前还没有上
     //$trans->earnest_money = $this->booking->earnest_money;
     $trans->trans_id_ext = $this->booking_id;
     $trans->from_uid = $buyerAccount->uid;
     $trans->to_uid = $this->booking->hug_uid;
     $trans->status = Trans::PAY_STATUS_WAITPAY;
     //1为等待支付状态
     if ($trans->save()) {
         return $trans;
     } else {
         $this->addErrors($trans->getErrors());
         return false;
     }
 }
Пример #2
0
 /**
  * @brief 用于产生用户充值的充值请求记录,在action中判断是否需要充值,如果需要,在此计算充值请求的具体内容
  *
  * @param array 交易的相关信息,以及订单支付的总金额, 充值的金额都需要在此列出
  * @return Receivable 代收款记录信息
  * @see 
  * @note 
  * @author 吕宝贵
  * @date 2015/12/06 17:49:22
  **/
 public function generateReceivableAndChargeTrans($trans, $userAccount)
 {
     $transCharge = null;
     //如果充值的交易已存在,则不再多余生成,复用充值交易
     if (!($transCharge = Trans::find()->where(['trans_id_ext' => $trans->id, 'trans_type_id' => Trans::TRANS_TYPE_CHARGE])->one())) {
         $transCharge = new Trans();
     }
     $transCharge->trans_id_ext = $trans->id;
     $transCharge->trans_type_id = Trans::TRANS_TYPE_CHARGE;
     $transCharge->from_uid = $trans->from_uid;
     $transCharge->to_uid = $trans->to_uid;
     //所有充值交易都为直接交易
     $transCharge->pay_mode = Trans::PAY_MODE_DIRECTPAY;
     $transCharge->total_money = $trans->total_money - $userAccount->balance;
     if (!$transCharge->save()) {
         return false;
     }
     return $this->generateReceivable($transCharge);
 }
Пример #3
0
 /**
  * @brief 用于产生用户充值的充值请求记录,在action中判断是否需要充值,如果需要,在此计算充值请求的具体内容
  *
  * @param array 交易的相关信息,以及订单支付的总金额, 充值的金额都需要在此列出
  * @return Receivable 代收款记录信息
  * @see 
  * @note 
  * @author 吕宝贵
  * @date 2015/12/06 17:49:22
  **/
 public function generateReceivableAndChargeTrans($trans, $userAccount)
 {
     $transCharge = null;
     //如果充值的交易已存在,则不再多余生成,复用充值交易
     if (!($transCharge = Trans::findOne(['trans_id_ext' => $trans->id, 'trans_type_id' => Trans::TRANS_TYPE_CHARGE]))) {
         $transCharge = new Trans();
     }
     $transCharge->trans_id_ext = $trans->id;
     $transCharge->trans_type_id = Trans::TRANS_TYPE_CHARGE;
     $transCharge->from_uid = $trans->from_uid;
     $transCharge->to_uid = $trans->to_uid;
     //所有充值交易都为直接交易
     $transCharge->pay_mode = Trans::PAY_MODE_DIRECTPAY;
     $transCharge->money = $trans->total_money;
     $transCharge->total_money = $trans->total_money - $userAccount->balance;
     if (!$transCharge->save()) {
         $this->addError(__METHOD__, '保存充值交易单时发生错误');
         $this->addErrors($transCharge->getErrors());
         return false;
     }
     //生成收款单,并返回
     return $this->generateReceivable($transCharge);
 }