Exemplo n.º 1
0
 /**
  * 托管退款操作
  * @param $identity_id 用户标示符
  * @param $orig_outer_trade_no 需要退款的订单号
  * @param $refund_amount 需要退款金额
  * @param $summary 退款说明
  * @return array
  */
 public static function hostingRefund($identity_id, $orig_outer_trade_no, $refund_amount, $summary = '投资失败退款')
 {
     $invest = SinaInvest::findOne(['out_trade_no' => $orig_outer_trade_no, 'identity_id' => $identity_id, 'money' => $refund_amount, 'status' => SinaInvest::STATUS_SUCCESS]);
     if (!$invest) {
         $return = array('errorNum' => '1', 'errorMsg' => '订单信息错误', 'data' => null);
         return $return;
     }
     $sina = new sina();
     $out_trade_no = self::build_order_no();
     $refund = $sina->create_hosting_refund($out_trade_no, $orig_outer_trade_no, $refund_amount, $summary);
     if (!$refund) {
         $return = array('errorNum' => '1', 'errorMsg' => '新浪托管接口失败', 'data' => null);
         return $return;
     }
     if ($refund['response_code'] == "APPLY_SUCCESS") {
         //提交信息成功
         if ($refund['refund_status'] == 'SUCCESS' || $refund['refund_status'] == 'PAY_FINISHED') {
             //退款成功
             $invest->refund_out_trade_no = $out_trade_no;
             $invest->refund_amount = $refund_amount;
             $invest->refund_summary = '中间账户退款';
             $invest->status = SinaInvest::STATUS_REFUND_SUCCESS;
             $invest->msg = '退款';
             if ($invest->save()) {
                 $return = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => null);
                 return $return;
             }
             $return = array('errorNum' => '1', 'errorMsg' => '数据记录失败', 'data' => null);
             return $return;
         } else {
             $invest->refund_out_trade_no = $out_trade_no;
             $invest->refund_amount = $refund_amount;
             $invest->refund_summary = '中间账户退款';
             //                $invest->status = SinaInvest::STATUS_REFUND_ERROR;
             $invest->msg = '退款失败';
             if ($invest->save()) {
                 $return = array('errorNum' => '1', 'errorMsg' => $refund['refund_status'], 'data' => null);
                 return $return;
             }
             $return = array('errorNum' => '1', 'errorMsg' => '数据记录失败', 'data' => null);
             return $return;
         }
     } else {
         $invest->refund_out_trade_no = $out_trade_no;
         $invest->refund_amount = $refund_amount;
         $invest->refund_summary = '中间账户退款';
         //            $invest->status = SinaInvest::STATUS_REFUND_ERROR;
         $invest->msg = $refund['response_message'];
         if ($invest->save()) {
             $return = array('errorNum' => '1', 'errorMsg' => $refund['response_message'], 'data' => null);
             return $return;
         }
         $return = array('errorNum' => '1', 'errorMsg' => '数据记录失败', 'data' => null);
         return $return;
     }
 }
Exemplo n.º 2
0
 /**
  * Finds the SinaInvest model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return SinaInvest the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = SinaInvest::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }