diff --git a/webapp/classes/OrderCtrl.php b/webapp/classes/OrderCtrl.php new file mode 100644 index 0000000..2eeb998 --- /dev/null +++ b/webapp/classes/OrderCtrl.php @@ -0,0 +1,141 @@ + $redis_conf['host'], + 'port' => $redis_conf['port'], + 'passwd' => $redis_conf['passwd'] + )); + return $r; + } + + protected function getMysql() + { + $mysql_conf = getMysqlConfig(); + $conn = new phpcommon\Mysql(array( + 'host' => $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => 'paydb' + )); + return $conn; + } + + public function getOrderByCp($orderid) + { + $conn = $this->getMysql(); + $row = $conn->execQueryOne('SELECT * FROM orderinfo ' . + 'WHERE orderid=:orderid;', + array( + ':orderid' => $orderid + ) + ); + return $row; + } + + public function getOrderBySp($channel, $sp_orderid) + { + $conn = $this->getMysql(); + $row = $conn->execQueryOne('SELECT * FROM orderinfo ' . + 'WHERE channel=:channel AND sp_orderid=:sp_orderid;', + array( + ':channel' => $channel, + ':sp_orderid' => $sp_orderid + ) + ); + return $row; + } + + public function addOrder($order_info) + { + return $this->internalAddOrder($order_info); + } + + public function addPreOrder($pre_order_info) + { + $pre_order_info['sp_orderid'] = ''; + $pre_order_info['sp_amount'] = 0; + $pre_order_info['sp_confirm_time'] = 0; + $pre_order_info['sp_pay_result'] = 0; + return $this->internalAddOrder($pre_order_info); + } + + private function internalAddOrder($order_info) + { + $conf = $this->getProduceConf($order_info['itemid']); + if (!$conf) { + die(); + } + $gameid = !empty($order_info['gameid']) ? $order_info['gameid'] : 1009; + $conn = $this->getMysql(); + $ret = $conn->execScript('INSERT INTO orderinfo(orderid, roleid, server_id, channel, ' . + ' gameid, openid, itemid, try_count, price, ipv4, status, ' . + ' confirmtime, createtime, sp_orderid, sp_amount, ' . + ' sp_confirm_time, sp_pay_result, ' . + ' charge_yb, gift_yb, att_data, attr_type, attr_value) ' . + 'VALUES (:orderid, :roleid, :server_id, :channel, ' . + ' :gameid, :openid, :itemid, :try_count, :price, :ipv4, :status, ' . + ' :confirmtime, :createtime, :sp_orderid, :sp_amount, ' . + ' :sp_confirm_time, :sp_pay_result, ' . + ' :charge_yb, :gift_yb, :att_data, :attr_type, :attr_value);', + array( + ':orderid' => $order_info['orderid'], + ':roleid' => $order_info['roleid'], + ':server_id' => $order_info['server_id'], + ':channel' => $order_info['channel'], + ':gameid' => $gameid, + ':openid' => $order_info['openid'], + ':itemid' => $order_info['itemid'], + ':try_count' => 0, + ':price' => $conf['money'], + ':ipv4' => $order_info['ipv4'], + ':status' => 0, + ':confirmtime' => 0, + ':createtime' => time(), + + ':sp_orderid' => $order_info['sp_orderid'], + ':sp_amount' => $order_info['sp_amount'], + ':sp_confirm_time' => $order_info['sp_confirm_time'], + ':sp_pay_result' => $order_info['sp_pay_result'], + + ':charge_yb' => $conf['money'] * 10, + ':gift_yb' => 0, + ':att_data' => '', + ':attr_type' => $conf['type'], + ':attr_value' => $conf['index'], + ) + ); + return $ret; + } + + public function spPayConfirm($orderid, $sp_orderid, $sp_amount) + { + $conn = $this->getMysql(); + $ret = $conn->execScript('UPDATE orderinfo SET ' . + ' sp_orderid = :sp_orderid, ' . + ' sp_amount = :sp_amount, ' . + ' sp_confirm_time = :sp_confirm_time, ' . + ' sp_pay_result = :sp_pay_result ' . + 'WHERE orderid = :orderid;', + array( + ':orderid' => $orderid, + + ':sp_orderid' => $sp_orderid, + ':sp_amount' => $sp_amount, + ':sp_confirm_time' => time(), + ':sp_pay_result' => 1, + ) + ); + return $ret; + } + +}