/** * Displays a particular model. * @param integer $id the ID of the model to be displayed */ public function actionIndex() { $this->layout = 'clean'; //$this->layout='main'; //echo \yii\helpers\Json::encode("ok"); //Yii::$app->end(); if (isset($_POST['Company'])) { $id = (int) $_POST['Company']; // //if has access //$database= Company::findOne($id); Yii::info($id); //Yii::$app->user->setState('Database',$database ); //Yii::$app->user->setState('Company',$id); //echo 'ok'; //Company::select($id); Yii::$app->session['company'] = $id; //redirect return \app\helpers\Response::send(200, $id); } if ($this->company != 0) { Yii::$app->session['company'] = 0; //unset(Yii::$app->session['company']); return $this->redirect(\yii\helpers\BaseUrl::base() . '/company/index'); \Yii::$app->end(); } $model = new Company(); ////$model->unsetAttributes(); // clear any default values return $this->render('index', array('model' => $model)); }
public function actionError() { //var_dump (Yii::$app->errorHandler->exception); //exit; $this->layout = 'single'; if (isset(Yii::$app->errorHandler->error) && ($error = Yii::$app->errorHandler->error)) { if (strpos(Yii::$app->request->url, 'api') != true) { //if (Yii::$app->request->isAjaxRequest) // return $error['message']; //else return $this->render('error', ['error' => $error]); } else { return \app\helpers\Response::send($error->statusCode, $error->getMessage()); } } elseif (isset(Yii::$app->errorHandler->exception) && ($exception = Yii::$app->errorHandler->exception)) { if (strpos(Yii::$app->request->url, 'api') != true) { //if (Yii::$app->request->isAjaxRequest) // return $exception['message']; //else return $this->render('error', ['error' => $exception]); } else { return \app\helpers\Response::send($exception->statusCode, $exception->getMessage()); } } else { //if ($error = Yii::$app->errorHandler->error) return \app\helpers\Response::send(500, 'Unknown error'); } }
/** * 操作失败的返回 * @param int $errCode 错误码 * @param string $errorMsg 错误提示信息 * @param array $data 带回到客户端的信息 * @param int $status http status code * @param array $headers http headers * @return \Illuminate\Http\JsonResponse * @throws DeepInException */ public static function errorJSON($errCode, $errorMsg, $data = array(), $status = 200, $headers = array()) { if (!is_array($data)) { throw new DeepInException("JSON返回的数据格式必须是数组形式~!"); } $ret = array(); $ret["ret"] = $errCode == 0 ? 1000 : $errCode; //错误码 $ret["data"] = $data; //带回给客户端的信息 $ret["error_msg"] = $errorMsg; //错误的描述 return \Response::json($ret, $status, $headers); }
public function actionCalc() { $model = new Docdetails(); if (isset($_POST['Docdetails']['line'])) { $i = $_POST['Docdetails']['line']; $model->attributes = $_POST['Docdetails'][$i]; if (isset($_POST['CalcPriceWithVat'])) { return Response::send(200, $model->CalcPriceWithVat()); } if (isset($_POST['CalcPriceWithOutVat'])) { return Response::send(200, $model->CalcPriceWithOutVat()); } return Response::send(200, $model->CalcPrice()); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Item(); if ($model->load(Yii::$app->request->post()) && $model->save()) { if (Yii::$app->request->post('ajax') !== null) { return \app\helpers\Response::send(200, $model); } //$model->pic->saveAs('/to/localFile'); return $this->redirect(array('admin', 'id' => $model->id)); } if (Yii::$app->request->post('ajax') !== null) { return \app\helpers\Response::send(501, $model->errors); } $model->sku = $model->maxId() + 1; $model->parent_item_id = 0; return $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate($type = 0, $parent_account_id = 0) { $model = new Accounts(['type' => (int) $type, 'parent_account_id' => (int) $parent_account_id]); if ($model->load(Yii::$app->request->post()) && $model->save()) { if (Yii::$app->request->post('ajax') !== null) { return \app\helpers\Response::send(200, $model); } //$model->deleteEavAttributes(); //if (isset($_POST['AccounteavE']) && isset($_POST['AccounteavE'])) { // $model->setEavAttributes(array_combine($_POST['AccounteavE'], $_POST['AccounteavV'])); //} if (!$this->hasCallback()) { return $this->redirect(array('accounts/admin/' . $model->type)); } } if (Yii::$app->request->post('ajax') !== null) { return \app\helpers\Response::send(501, $model->errors); } //$model->accType = Acctype::findOne((int) $type); //$model->type = $type; return $this->render('create', array('model' => $model)); }
/** * @param Request $request * @return \Symfony\Component\HttpFoundation\Response * * @api {post} /yzh/account/flush 彻底删除该商户下所有用户 * @apiName PostToolFlush * @apiGroup Tool * * @apiParam {String} partner 商户编号 * * @apiSuccessExample Success-Response: * HTTP/1.1 200 OK * { * "ok": true * } * */ public function flush(Request $request) { $input = $request->all(); Logger::sysInfo('@YzhController flush, begin, clear', $input); $validator = Validator::make($input, ['partner' => 'required']); if ($validator->fails()) { $errors = $validator->errors()->toArray(); return Response::error(FaultCode::PARAMS_ERROR, $errors); } if (!in_array($input['partner'], config('Flush'))) { return Response::error(FaultCode::ACCESS_DENIED); } $results = DB::connection('trial')->select('select I_USER_ID from dealer_user_relation where CH_DEALER_CODE = :code', ['code' => $input['partner']]); if (empty($results)) { return Response::result(['ok' => true]); } $log = []; foreach ($results as $row) { $id = $row->I_USER_ID; $log[] = DB::connection('trial')->delete('delete from users where I_USER_ID = :id', ['id' => $id]); $log[] = DB::connection('trial')->delete('delete from user_account where I_USER_ID = :id', ['id' => $id]); $log[] = DB::connection('trial')->delete('delete from user_bankcards where I_USER_ID = :id', ['id' => $id]); $log[] = DB::connection('trial')->delete('delete from dealer_user_relation where I_USER_ID = :id', ['id' => $id]); } Logger::sysInfo('@YzhController flush, end, log', $log); return Response::result(['ok' => true]); }
/** * 登录 * @param Request $request * @return \Symfony\Component\HttpFoundation\Response * * @api {post} /user/login 登录 * @apiName PostLogin * @apiGroup User * * @apiParam {String} mobile 手机号 * @apiParam {String} password 登录密码 * * @apiSuccessExample Success-Response: * { * uid: 1 * } */ public function login(Request $request) { // input $input = $request->all(); // validate $validator = Validator::make($input, ['mobile' => 'required|size:11', 'password' => 'required|min:6']); if ($validator->fails()) { $errors = $validator->errors()->toArray(); return Response::error(FaultCode::PARAMS_ERROR, $errors); } // grab $user = User::where('mobile', $input['mobile'])->first(); if (is_null($user)) { return Response::error(FaultCode::USER_NOT_EXIST); } // password if (!CommonHelper::comparePassword($input['password'], $user->password, $user->salt)) { return Response::error(FaultCode::PASSWORD_NOT_MATCH); } return Response::result(['uid' => $user->uid]); }
public function actionDelete($model, $id) { if ($this->hasAccess($model . '/delete')) { $modelName = $this->translate($model); $loadedModel = $modelName::findOne($id); // Was a model found? If not, raise an error if ($loadedModel === null) { Response::send(400, sprintf("Error: Didn't find any model <b>%s</b> with ID <b>%s</b>.", $model, $id)); } // Delete the model $num = $loadedModel->delete(); if ($num > 0) { Response::send(200, $num); } else { Response::send(500, sprintf("Error: Couldn't delete model <b>%s</b> with ID <b>%s</b>.", $model, $id)); } } else { Response::send(403, sprintf('Error: Mode <b>delete</b> is not implemented for model <b>%s</b>', $model)); } }
public function actionRefstatus($id) { $model = $this->findModel((int) $id); $model->refstatus = !$model->refstatus; if ($model->save(false)) { return \app\helpers\Response::send(200, true); } else { return \app\helpers\Response::send(500, $model->errors); } }
public function actionGetrate($id) { \app\helpers\Response::send(200, Currates::GetRate($id)); }