public function createKa91Pay($Order, $Pay) { $oOrder = new Lm_Order(); $oUser = new Lm_User(); $this->db->begin(); $Order['OrderId'] = date("YmdHis", $Order['OrderTime']) . sprintf("%03d", $Order['AppId']) . sprintf("%03d", $Order['PartnerId']) . sprintf("%04d", rand(1, 9999)); //支付订单 $Pay['OrderId'] = $Order['OrderId']; $Pay['PayId'] = date("YmdHis", $Pay['PayedTime']) . sprintf("%04d", rand(1, 9999)); $Date = date("Ym", $Pay['PayedTime']); $table_date = $this->createUserPayTableDate($Date); $table_user = $this->createUserPayTableUser($Pay['AcceptUserId']); $table_first = Base_Widget::getDbTable($this->table_first); $Date = $this->db->insert($table_date, $Pay); $User = $this->db->insert($table_user, $Pay); $first = $this->db->insert($table_first, $Pay); //合作方订单唯一保证 $StageOrderArr = array('OrderId' => $Pay['OrderId'], 'StageOrder' => $Pay['StageOrder']); $InsertStageOrder = $this->insertKa91StageOrder($StageOrderArr); //给收款方加余额 $UserCoinUpdate = $oUser->updateUserCoin($Pay['AcceptUserId'], $Pay['Coin']); //给支付方加积分,如无支付方帐号,则不加 $UserCreditUpdate = $Pay['PayUserId'] ? $oUser->updateUserCredit($Pay['PayUserId'], $Pay['Coin']) : 1; //生成订单 $Order['PayId'] = $Pay['PayId']; $Date = date("Ym", $Order['OrderTime']); $table_date = $oOrder->createUserOrderTableDate($Date); $table_user = $oOrder->createUserOrderTableUser($Order['AcceptUserId']); $table_to_insert = $table_date; $order_date = $this->db->insert($table_to_insert, $Order); if (intval($order_date) && intval($order_date) != 23000) { $table_to_insert = $table_user; $user = $this->db->insert($table_to_insert, $Order); } if ($InsertStageOrder && $Date && $User && $UserCoinUpdate && $UserCreditUpdate && $order_date && $user) { $this->db->commit(); return $Pay['OrderId']; } else { $this->db->rollBack(); return false; } }
public function ExchangeFail($ExchangeId) { $ExchangeInfo = $this->getQueuedExchange($ExchangeId); if ($ExchangeInfo['ExchangeId']) { $this->db->begin(); //移除到兑换失败队列 unset($ExchangeInfo['ToSendTime']); $addErrorExchangeQueue = $this->addErrorExchange($ExchangeInfo); $delExchangeQueue = $this->deleteExchangeQueue($ExchangeInfo['ExchangeId']); $updateOrderStatus = false; //更新订单状态 if ($ExchangeInfo['OrderId']) { $oOrder = new Lm_Order(); $updateOrderStatus = $oOrder->updateOrder($ExchangeInfo['OrderId'], $ExchangeInfo['UserId'], array('OrderStatus' => '3')); } else { $updateOrderStatus = true; } //退款 $oUser = new Lm_User(); $coinUpdate = $oUser->updateUserCoin($ExchangeInfo['UserId'], $ExchangeInfo['Coin']); if ($addErrorExchangeQueue && $delExchangeQueue && $updateOrderStatus && $coinUpdate) { $this->db->commit(); return true; } else { $this->db->rollback(); return false; } } else { return false; } }