/** * Create easypay trade. * @see \Zend\Mvc\Controller\AbstractActionController::indexAction() */ public function indexAction() { if ($this->verifyRequest()) { $this->appendTitle('收银台'); $this->layout()->setVariable('is_cashier_page', true); $dbAdapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'); /** * Check the parameters if they are valid. */ $parameters = $this->getRequest()->getQuery(); // if merchant exsist // if trade|redirect_url|notify_url|sign empty // if price is a floating numberic $exception = new \Exception('Parameters is invalid!'); if (empty(trim($parameters['trade'])) || empty(trim($parameters['redirect_url'])) || empty(trim($parameters['notify_url'])) || empty(trim($parameters['sign']))) { throw $exception; } if (!is_numeric(trim($parameters['price']))) { throw $exception; } $merchant_validator = new \Zend\Validator\Db\NoRecordExists(array('table' => 'merchant', 'field' => 'name', 'adapter' => $dbAdapter)); if ($merchant_validator->isValid(intval($parameters['merchant']))) { throw $exception; } /** * Check if there is an exsist trade. */ $GetMerchantIdByName = $this->getServiceLocator()->get('GetMerchantIdByName'); $merchant_id = $GetMerchantIdByName($parameters['merchant']); $trade = $this->getTrade($merchant_id, trim($parameters['trade'])); $trade_id = null; $payment_interface_type = null; if (!empty($trade)) { // Trade exsist. if ($trade->pay_status) { throw new \Exception('Trade had payed before!'); } else { // Update the exsist trade $trade->price = trim($parameters['price']); $trade->redirect_url = trim($parameters['redirect_url']); $trade->notify_url = trim($parameters['notify_url']); $trade->save(); $trade_id = $trade->id; $payment_interface_type = $trade->payment_interface_type; } } else { // Trade not exsist. // Create a new trade $tableGateway = new TableGateway('trade', $dbAdapter, new Feature\RowGatewayFeature('id')); $tableGateway->insert(array('merchant_id' => $merchant_id, 'merchant_trade_id' => trim($parameters['trade']), 'redirect_url' => trim($parameters['redirect_url']), 'notify_url' => trim($parameters['notify_url']), 'price' => trim($parameters['price']), 'pay_status' => 0, 'create_time' => date('Y-n-j H:i:s', time()))); $trade_id = $tableGateway->getLastInsertValue(); } return array('price' => trim($parameters['price']), 'merchant' => $parameters['merchant'], 'trade' => trim($parameters['trade']), 'selected_payment' => $payment_interface_type); } else { throw new \Exception('Bad Reaquest !'); } }
public function subscribeAction() { $this->init(); $this->checkLogin(); $this->googlePlusLogin(); $form = new SubscribeForm(); $request = $this->getRequest(); if ($request->isPost()) { $subscribe = new Subscribe(); $form->setInputFilter($subscribe->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $name = $request->getPost('name'); $email = $request->getPost('email'); $Data = array(); $Data['email'] = $email; $Data['name'] = $name; $Data['created_on'] = date("Y-m-d"); $Data['active'] = 1; //$adapter = $this->tableGateway->getAdapter(); $dbAdapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'); $validator = new \Zend\Validator\Db\NoRecordExists(array('table' => 'subscriber_signup', 'field' => 'email', 'adapter' => $dbAdapter)); if ($validator->isValid($email)) { // email address appears to be valid $sql = new Sql($dbAdapter); $insert = $sql->insert('subscriber_signup'); $insert->values($Data); $statement = $sql->prepareStatementForSqlObject($insert); $results = $statement->execute(); $return_id = $dbAdapter->getDriver()->getLastGeneratedValue(); if ($return_id) { $this->flashMessenger()->addMessage('Your subscription has been created !'); } return $this->redirect()->toRoute('index', array('action' => 'subscribe')); } else { //$this->flashMessenger()->addMessage('A record matching the input was found!'); $this->layout()->setVariable('message', $validator->getMessages()); // email address is invalid; print the reasons //foreach ($validator->getMessages() as $message) { //echo "$message\n"; //} } } } return new ViewModel(array('form' => $form, 'flashMessages' => $this->flashmessenger()->getMessages())); }
/** * @param \User\Model\User $user * @return array */ public function validateSignupInfo(\User\Model\User $user) { $error = array(); $validateRequire = new \Zend\Validator\StringLength(array('min' => 6)); $validateEmail = new \Zend\Validator\EmailAddress(); $validateUsername = new \Zend\Validator\Db\NoRecordExists(array('table' => 'users', 'field' => 'username', 'adapter' => $this->getServiceLocator()->get('dbAdapter'))); $validateUserEmail = new \Zend\Validator\Db\NoRecordExists(array('table' => 'users', 'field' => 'email', 'adapter' => $this->getServiceLocator()->get('dbAdapter'))); if (!$validateUsername->isValid($user->getUsername())) { $error['username'] = self::DULICATE_USERNAME; } if (!$validateRequire->isValid($user->getUsername())) { $error['username'] = self::USERNAME_REQUIRED; } if (!$validateRequire->isValid($user->getPassword())) { $error['password'] = self::PASSWORD_REQUIRED; } if (!$validateUserEmail->isValid($user->getEmail())) { $error['email'] = self::DULICATE_USEREMAIL; } if (!$validateEmail->isValid($user->getEmail())) { $error['email'] = self::INVALID_EMAIL_FORMAT; } return $error; }