Beispiel #1
0
 public static function addMerchant($name, $password, $stores, $privs)
 {
     $type = self::MERCHANT;
     $user = new self();
     $transaction = \Bootstrap::getApp()->getDi()->getTransactions()->get();
     $user->setTransaction($transaction);
     $user->name = $name;
     $user->password = \Plugins\Common::generatePassword($password);
     $user->type = $type;
     if (!$user->save()) {
         foreach ($user->getMessages() as $message) {
             $transaction->rollback($message->getMessage());
         }
         return false;
     }
     $result = $user->addMerchantStore($stores);
     $role = new \Model\Admin\Role();
     $role->setTransaction($transaction);
     $role->name = $name;
     if (!$role->save()) {
         foreach ($user->getMessages() as $message) {
             $transaction->rollback($message->getMessage());
         }
         return false;
     }
     $result = $role->setRolePermission($privs);
     if (!$result['result']) {
         $transaction->rollback();
         return false;
     }
     $user->role_id = $role->id;
     if (!$user->save()) {
         foreach ($user->getMessages() as $message) {
             $transaction->rollback($message->getMessage());
         }
         return false;
     }
     $transaction->commit();
     return true;
 }
Beispiel #2
0
 public function run()
 {
     $this->initAll();
     try {
         //todo 按模块 判断 ,错误时输出json或者html页面
         $response = $this->handle();
         echo $response->getContent();
     } catch (\Exception $e) {
         if ($e instanceof \Library\AjaxException) {
             \Plugins\Common::echoError($e->getCode(), $e->getMessage());
         } else {
             echo get_class($e), ": ", $e->getMessage(), "\n";
             echo " File=", $e->getFile(), "\n";
             echo " Line=", $e->getLine(), "\n";
             echo $e->getTraceAsString();
         }
     }
 }