xinzeng

AccountTransaction.php

<?php

namespace Mirror\ApiBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * AccountTransaction
 *
 * @ORM\Table(name="account_transaction", indexes={@ORM\Index(name="NewIndex1", columns={"user_id"})})
 * @ORM\Entity
 */
class AccountTransaction
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var integer
     *
     * @ORM\Column(name="user_id", type="integer", nullable=false)
     */
    private $userId;
    
    /**
     * @var integer
     *
     * @ORM\Column(name="account_id", type="integer", nullable=false)
     */
    private $accountId;
    
    /**
     * @var string
     *
     * @ORM\Column(name="type", type="string", length=255, nullable=false)
     */
    private $type;
    
    /**
     * @var string
     *
     * @ORM\Column(name="mop", type="string", length=255, nullable=false)
     */
    private $mop;
    
    /**
     * @var string
     *
     * @ORM\Column(name="third_no", type="string", length=255, nullable=false)
     */
    private $thirdNo;
    
    /**
     * @var string
     *
     * @ORM\Column(name="status", type="string", length=255, nullable=false)
     */
    private $status;
    
    /**
     * @var \DateTime
     *
     * @ORM\Column(name="create_on", type="datetime", nullable=false)
     */
    private $createOn;
    
    /**
     * @var integer
     *
     * @ORM\Column(name="create_by", type="integer", nullable=false)
     */
    private $createBy;
    
    /**
     * @var \DateTime
     *
     * @ORM\Column(name="update_on", type="datetime", nullable=false)
     */
    private $updateOn;
    
    /**
     * @var integer
     *
     * @ORM\Column(name="update_by", type="integer", nullable=false)
     */
    private $updateBy;


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set userId
     *
     * @param integer $userId
     * @return Account
     */
    public function setUserId($userId)
    {
        $this->userId = $userId;

        return $this;
    }

    /**
     * Get userId
     *
     * @return integer 
     */
    public function getUserId()
    {
        return $this->userId;
    }
    
    /**
     * Set accountId
     *
     * @param integer $accountId
     * @return WithdrawRequest
     */
    public function setAccountId($accountId)
    {
    	$this->accountId = $accountId;
    
    	return $this;
    }
    
    /**
     * Get accountId
     *
     * @return integer
     */
    public function getAccountId()
    {
    	return $this->accountId;
    }
    
    /**
     * Set type
     *
     * @param string $type
     * @return AccountTransaction
     */
    public function setType($type)
    {
    	$this->type = $type;
    
    	return $this;
    }
    
    /**
     * Get type
     *
     * @return string
     */
    public function getType()
    {
    	return $this->type;
    }
    
    /**
     * Set mop
     *
     * @param string $mop
     * @return AccountTransaction
     */
    public function setMop($mop)
    {
    	$this->mop = $mop;
    
    	return $this;
    }
    
    /**
     * Get mop
     *
     * @return string
     */
    public function getMop()
    {
    	return $this->mop;
    }
    
    /**
     * Set thirdNo
     *
     * @param string $thirdNo
     * @return AccountTransaction
     */
    public function setThirdNo($thirdNo)
    {
    	$this->thirdNo = $thirdNo;
    
    	return $this;
    }
    
    /**
     * Get thirdNo
     *
     * @return string
     */
    public function getThirdNo()
    {
    	return $this->thirdNo;
    }
    
    /**
     * Set status
     *
     * @param string $status
     * @return WithdrawRequest
     */
    public function setStatus($status)
    {
    	$this->status = $status;
    
    	return $this;
    }
    
    /**
     * Get status
     *
     * @return string
     */
    public function getStatus()
    {
    	return $this->status;
    }
    
    
    /**
     * Set createOn
     *
     * @param \DateTime $createOn
     * @return Account
     */
    public function setCreateOn($createOn)
    {
    	$this->createOn = $createOn;
    
    	return $this;
    }
    
    /**
     * Get createOn
     *
     * @return \DateTime
     */
    public function getCreateOn()
    {
    	return $this->createOn;
    }
    
    /**
     * Set createBy
     *
     * @param integer $createBy
     * @return Account
     */
    public function setCreateBy($createBy)
    {
    	$this->createBy = $createBy;
    
    	return $this;
    }
    
    /**
     * Get createBy
     *
     * @return integer
     */
    public function getCreateBy()
    {
    	return $this->createBy;
    }
    
    /**
     * Set updateOn
     *
     * @param \DateTime $updateOn
     * @return Account
     */
    public function setUpdateOn($updateOn)
    {
    	$this->updateOn = $updateOn;
    
    	return $this;
    }
    
    /**
     * Get updateOn
     *
     * @return \DateTime
     */
    public function getUpdateOn()
    {
    	return $this->updateOn;
    }
    
    /**
     * Set updateBy
     *
     * @param integer $updateBy
     * @return Account
     */
    public function setUpdateBy($updateBy)
    {
    	$this->updateBy = $updateBy;
    
    	return $this;
    }
    
    /**
     * Get updateBy
     *
     * @return integer
     */
    public function getUpdateBy()
    {
    	return $this->updateBy;
    }
    
}



AccountTransactionModel.php


<?php

namespace Mirror\ApiBundle\Model;

use Doctrine\ORM\EntityManager;
use Mirror\ApiBundle\Util\Helper;
use Mirror\ApiBundle\Entity\AccountTransaction;

class AccountTransactionModel {
	private $em;
	public function __construct(EntityManager $em) {
		$this->em = $em;
	}
	public function retrieve($arguments) {
		$userId = Helper::getc ( $arguments, 'userId', 0 );
		$criteria = array ();
		if ($userId != 0) {
			$criteria = array_merge ( $criteria, array (
					'userId' => $userId 
			) );
		}
		if (count ( $criteria ) == 0)
			return 0;
		return $this->em->getRepository ( 'MirrorApiBundle:AccountTransaction' )->findOneBy ( $criteria );
	}
	
	public function create($arguments) {
		$userId = Helper::getc ( $arguments, 'userId', 0 );
		$accountId = Helper::getc ( $arguments, 'accountId', 0 );
		$mop = Helper::getc ( $arguments, 'mop', '' );
		$thirdNo = Helper::getc ( $arguments, 'thirdNo', '' );
		$type = Helper::getc ( $arguments, 'type', '' );
		$status = Helper::getc ( $arguments, 'status', '' );
		$createBy = Helper::getc ( $arguments, 'createBy', 0 );
		$updateBy = Helper::getc ( $arguments, 'updateBy', 0 );
		
		$now = new \Datetime ();
		$accountTransaction = new AccountTransaction();
		$accountTransaction->setUserId ( $userId );
		$accountTransaction->setAccountId ( $accountId );
		$accountTransaction->setMop ( $mop );
		$accountTransaction->setThirdNo ( $thirdNo );
		$accountTransaction->setType ( $type );
		$accountTransaction->setStatus ( $type );
		$accountTransaction->setCreateOn ( $now );
		$accountTransaction->setCreateBy ( $createBy );
		$accountTransaction->setUpdateOn ( $now );
		$accountTransaction->setUpdateBy($updateBy);
		
		$this->em->persist ( $accountTransaction );
		$this->em->flush ();
		return $accountTransaction;
	}
	
}

AccountTransactionService.php


<?php

namespace Mirror\ApiBundle\Service;

use Mirror\ApiBundle\Model\AccountTransactionModel;

class AccountTransactionService {
	private $accountTransactionModel;
	
	public function __construct(AccountTransactionModel $accountTransactionModel) {
		$this->accountTransactionModel = $accountTransactionModel;
	}
	
	public function create($userId, $accountId, $mop, $thirdNo, $type, $status, $createBy, $updateBy) {
		$arguments = array (
				'userId' => $userId,
				'accountId' => $accountId,
				'mop' => $mop,
				'thirdNo' => $thirdNo,
				'type' => $type,
				'status' => $status,
				'createBy' => $createBy,
				'updateBy' => $updateBy
		);
		return $this->accountTransactionModel->create ( $arguments );
	}
	
	public function getByUserId($userId) {
		$arguments = array (
				'userId' => $userId 
		);
		return $this->accountTransactionModel->retrieve ( $arguments );
	}
	
}


market/usercontroller.php


public function rechargeSubmitAction(Request $request)
	{
		//create order
		$isLogin = parent::sessionGet ( 'portalLogin', false );
		if (! $isLogin) {
			parent::buildResponse ( 10400, array () );
		}
		$userId = parent::sessionGet ( 'userId', 0 );
		
		$json = $this->get ( 'json_parse' )->parse ( $request );
		$mopCode = $json->get('mop', 0);
		$amount = $json->get('rechargeAmount', 0);	
		$articleNumber = 000;
		$accNo = 000000;
		$realname = '';
		$paperType = 0;
		$paperNumber = '';
		$phone = '';
		$results = $this->get ( 'order_service' )->createNonProdOrder( $userId, $articleNumber, $amount,$accNo,$realname,$paperType,$paperNumber,$phone, 'recharge_order');
		$orderNumber = $results ['orderNumber'];
		
		$userAsset = $this->get ( 'user_asset_service' )->getByUserId ( $userId );
		$accountId = $userAsset->getId();
		$thirdNo = '';
		$type = 'recharge';
		$status = 'submitted';
		$createBy = $userId;
		$updateBy = $userId;
		
		$results = $this->get ( 'account_transaction_service' )->create($userId, $accountId, $mopCode, $thirdNo, $type, $status, $createBy, $updateBy);
		
		$paras = array(
				'orderNumber' => $orderNumber
		);
		
		return $this->render('MirrorMarketBundle:User:rechargeSubmitted.html.twig', $paras);
	}
	
	public function rechargeSuccessAction(Request $request)
	{
		$isLogin = parent::sessionGet ( 'portalLogin', false );
		if (! $isLogin) {
			parent::buildResponse ( 10400, array () );
		}
		$userId = parent::sessionGet ( 'userId', 0 );
		
		$orderId = $request->request->get('orderId');
		$price = (float)($request->request->get('price'));
		$type = $request->request->get('type');
		
		$order = $this->get ( 'order_service' )->getOrderByUserIdAndOrderNumber($userId, $orderId);
		
		$userAsset = $this->get ( 'user_asset_service' )->getByUserId ( $userId );
		$accountId = $userAsset->getId();
		$mopCode = $order->getMop();
		$thirdNo = '';
		$type = 'recharge';		
		$createBy = 0;
		$updateBy = 0;
		
		if($price == $order->getPrice() && $type == $order->getType()){			
			$amountAvailable = (float)($userAsset->getAmountAvailable());
			$this->get ( 'user_asset_service' )->updateAmountAvailable($userId, $amountAvailable + $price);
			$status = 'pay_success';
			$results = $this->get ( 'account_transaction_service' )->create($userId, $accountId, $mopCode, $thirdNo, $type, $status, $createBy, $updateBy);
			return $this->render('MirrorMarketBundle:User:rechargeSuccess.html.twig', array ());
		}
		else{
			$status = 'pay_failed';
			$results = $this->get ( 'account_transaction_service' )->create($userId, $accountId, $mopCode, $thirdNo, $type, $status, $createBy, $updateBy);
			parent::buildResponse ( 10400, array () );
		} 
		
	}


services.yml


account_transaction_model:
        class: Mirror\ApiBundle\Model\AccountTransactionModel
        arguments: [@doctrine.orm.entity_manager]


account_transaction_service:
        class: Mirror\ApiBundle\Service\AccountTransactionService
        arguments: [@account_transaction_model]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值