/library/Model/UserBuying.php
PHP | 311 lines | 235 code | 68 blank | 8 comment | 8 complexity | 836a9946ecf059eb6d54131e8d3909ce MD5 | raw file
- <?php
- /**
- * Created by JetBrains PhpStorm.
- * User: menvil
- * Date: 9/11/12
- * Time: 11:31 PM
- * To change this template use File | Settings | File Templates.
- */
- class UserBuying
- {
- private $userb = null;
- private $tbl = 'UsersBuying';
- public function __construct(){
- $this->userb = new UsersBuying();
- return $this->userb;
- }
- public function add($auctionId=NULL,$productId=NULL, $status='Pending',$transactionId=NULL, $userId=NULL,$winner=0, $cv2 = null, $ip=NULL){
- $this->userb->setAuctionId($auctionId)
- ->setProductId($productId)
- ->setUsersPaymentsTransactionId($transactionId)
- ->setUserId($userId)
- ->setStatus($status)
- ->setStatusDate(date('Y-m-d h:i:s'))
- ->setTrackingNumber($cv2)
- ->setTrackingStatus(NULL)
- ->setWinner($winner)
- ->setIpAddress($ip)
- ->save();
- return $this->userb->getId();
- }
- public function buyItNowPaid($id, $transactionId, $userId= NULL, $shippingId, $ip = NULL)
- {
- // Example of using Doctrine_Query
- try{
- $q = Doctrine_Query::create()
- ->update($this->tbl)
- ->set('status','?','Pending')
- ->set('users_payments_transaction_id',$transactionId)
- ->set('status_date','?',date('Y-m-d h:i:s'))
- ->set('user_id','?',($userId === NULL?new Doctrine_Null():$userId))
- ->set('shipping_id',$shippingId)
- ->set('ip_address','?',($ip === NULL?new Doctrine_Null():$ip))
- ->where('id=?',(int)$id)->execute();
- return true;
- }catch (Exception $e){
- print_r($e->getMessage());
- return false;
- }
- }
- public function membershipPerkPaid($id, $transactionId, $userId = NULL, $ip = NULL)
- {
- $record = Doctrine::getTable($this->tbl)->find((int)$id);
- if($record === NULL)
- return false;
- try{
- $record->setUserId($userId)
- ->setIpAddress($ip)
- ->setStatus('Membership Paid')
- ->setStatusDate(date('Y-m-d h:i:s'))
- ->setUsersPaymentsTransactionId($transactionId)
- ->save();
- }
- catch (Exception $e){
- print_r($e->getMessage());
- var_dump(debug_backtrace());
- return false;
- }
- return true;
- }
- public function getTrackingsUpdate()
- {
- try{
- return Doctrine::getTable($this->tbl)->createQuery('b')
- ->addSelect('b.id, b.tracking_number')
- ->addWhere('b.tracking_number IS NOT NULL')
- ->addWhere('b.tracking_status IS NOT NULL')
- ->addWhere('b.tracking_status !=?','Canceled')
- ->addWhere('b.shipping_number IS NOT NULL')
- ->addWhere('b.status !=?','Canceled')
- ->orderBy('b.id ASC')
- ->limit(100)
- ->fetchArray();
- }
- catch (Exception $e){
- print_r($e->getMessage());
- var_dump(debug_backtrace());
- return false;
- }
- }
- public function addTracking($id, $tracking)
- {
- $record = Doctrine::getTable($this->tbl)->find((int)$id);
- if($record === NULL)
- return false;
- try{
- $record->setTrackingNumber($tracking)
- ->setStatus('Processed')
- ->setStatusDate(date('Y-m-d h:i:s'))
- ->save();
- }
- catch (Exception $e){
- print_r($e->getMessage());
- var_dump(debug_backtrace());
- return false;
- }
- return true;
- }
- public function updateTrackingStatus($id, $status, $number=NULL)
- {
- $record = Doctrine::getTable($this->tbl)->find((int)$id);
- if($record === NULL)
- return false;
- try{
- $record->setTrackingStatus($status)
- ->setTrackingNumber($number)
- ->save();
- }
- catch (Exception $e){
- print_r($e->getMessage());
- var_dump(debug_backtrace());
- return false;
- }
- return true;
- }
- public function updateStatus($id, $status)
- {
- $record = Doctrine::getTable($this->tbl)->find((int)$id);
- if($record === NULL)
- return false;
- if(!in_array($status,Doctrine::getTable($this->tbl)->getEnumValues('status')))
- return false;
- try{
- $record->setStatus($status)
- ->setStatusDate(date('Y-m-d H:i:s'))
- ->save();
- }
- catch (Exception $e){
- print_r($e->getMessage());
- var_dump(debug_backtrace());
- return false;
- }
- return true;
- }
- public function getReadyDeals($userId)
- {
- try{
- return Doctrine::getTable($this->tbl)->createQuery('b')
- ->addWhere('b.user_id=?',(int)$userId)
- ->addWhere('b.status = ?','Paid')->count();
- }catch (Exception $e){
- print_r($e->getMessage());
- var_dump(debug_backtrace());
- return false;
- }
- }
- public function getUserPendingOrders($dealId, $userId)
- {
- try{
- return Doctrine::getTable($this->tbl)->createQuery('b')
- ->addSelect('id')
- ->addWhere('auction_id=?',(int)$dealId)
- ->addWhere('user_id = ?',(int)$userId)
- ->addWhere('status = ?','Pending')
- ->addWhere('winner = 0')->fetchOne();
- }catch (Exception $e){
- print_r($e->getMessage());
- var_dump(debug_backtrace());
- return false;
- }
- }
- public function getUserPendingGrabs($dealId, $userId)
- {
- try{
- return Doctrine::getTable($this->tbl)->createQuery('b')
- ->addSelect('id')
- ->addWhere('auction_id=?',(int)$dealId)
- ->addWhere('user_id = ?',(int)$userId)
- ->addWhere('status IN ("Pending","Perk""Membership Perk")')
- ->addWhere('winner = 1')->fetchOne();
- }catch (Exception $e){
- print_r($e->getMessage());
- var_dump(debug_backtrace());
- return false;
- }
- }
- public function getMembershipPerk($userId)
- {
- try{
- return Doctrine::getTable($this->tbl)->createQuery('b')
- ->addSelect('id')
- ->addWhere('user_id = ?',(int)$userId)
- ->addWhere('status = ?','Membership Perk')
- ->fetchOne();
- }catch (Exception $e){
- print_r($e->getMessage());
- var_dump(debug_backtrace());
- return false;
- }
- }
- public function setPerksAsApplied($dealId, $ip=NULL)
- {
- $record = Doctrine::getTable($this->tbl)->createQuery('b')->where('auction_id=? ',(int)$dealId)->fetchOne();
- if($record === NULL)
- return false;
- try{
- $record->setStatus('Perk Applied')
- ->setIpAddress($ip)->save();
- }catch (Exception $e){
- print_r($e->getMessage());
- var_dump(debug_backtrace());
- return false;
- }
- return true;
- }
- public function setCustomerPo($id, $customerPo)
- {
- $record = Doctrine::getTable($this->tbl)->find((int)$id);
- if($record === NULL)
- return false;
- try{
- $record->setCustomerPo($customerPo)->save();
- }catch (Exception $e){
- print_r($e->getMessage());
- var_dump(debug_backtrace());
- return false;
- }
- return true;
- }
- public function setBranchOrder($id, $branchOrder)
- {
- $record = Doctrine::getTable($this->tbl)->find((int)$id);
- if($record === NULL)
- return false;
- try{
- $record->setBranchOrder($branchOrder)->save();
- }catch (Exception $e){
- print_r($e->getMessage());
- var_dump(debug_backtrace());
- return false;
- }
- return true;
- }
- }