| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384 |
- <?php
- namespace app\controllers;
- use app\models\Bills;
- use app\models\Images;
- use PhpOffice\PhpWord\Shared\ZipArchive;
- use Yii;
- use app\models\Files;
- use app\models\Lots;
- use app\models\Messages;
- use app\models\LotSearch;
- use app\models\Auctions;
- use yii\helpers\ArrayHelper;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- use yii\web\Response;
- use yii\web\UploadedFile;
- use yii\filters\AccessControl;
- use app\models\Subscriptions;
- use app\models\Eventlog;
- /**
- * LotsController implements the CRUD actions for Lots model.
- */
- class LotsController extends Controller
- {
- public function behaviors()
- {
- return [
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'delete' => ['post'],
- ],
- ],
- 'access' => [
- 'class' => AccessControl::className(),
- 'only' => ['index', 'create', 'view', 'update', 'delete', 'upload', 'download', 'confirm', 'auction'],
- 'rules' => [
- [
- 'allow' => true,
- 'actions' => ['index', 'create', 'view', 'update', 'delete', 'upload', 'download', 'confirm', 'auction'],
- 'roles' => ['@'],
- ],
- ],
- ],
- ];
- }
- /**
- * Lists all Lots models.
- * @return mixed
- */
- public function init()
- {
- if (@!Yii::$app->user->identity->confirmed_at && (@Yii::$app->user->identity->role == 1)) {
- return $this->redirect('/registration/organizer');
- }
- $this->layout = '@app/views/layouts/backend/user';
- parent::init();
- }
- public function actionIndex()
- {
- if (Yii::$app->user->can('org') || Yii::$app->user->can('admin')) {
- $searchModel = new LotSearch();
- $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
- return $this->render('index', [
- 'searchModel' => $searchModel,
- 'dataProvider' => $dataProvider,
- ]);
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
- /**
- * Displays a single Lots model.
- * @param integer $id
- * @return mixed
- */
- public function actionView($id)
- {
- $files = new Files();
- $files->uploads = '../uploads/bids/';
- if (Yii::$app->request->isPost && false != ($file = UploadedFile::getInstances($files, 'file'))) {
- $fileName = $files->uploadFile();
- $model = $this->findModel($id);
- // $file->name = $files->transliteration($file->name);
- //$files->name = $file->name;
- // $path = Yii::$app->params['uploadPath'].$file->name;
- if ($fileName) {
- $files->saveFile([
- 'name' => $fileName,
- 'path' => $files->uploads,
- 'user_id' => Yii::$app->user->identity->id,
- 'auction_id' => $model->auction->id,
- 'lot_id' => $model->id,
- 'type' => 'bid',
- ]);
- Yii::$app->session->setFlash('success', Yii::t('app', 'FileUploaded ID'));
- } else {
- Yii::$app->session->setFlash('danger', Yii::t('app', 'Cannot save file'));
- }
- }
- return $this->render('view', [
- 'model' => $this->findModel($id),
- ]);
- }
- public function actionCreate()
- {
- $model = new Lots();
- $files = new Files();
- $files->uploads = '../uploads/lots/';
- $fileName = $files->uploadFile();
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- if ($fileName) {
- $model->docs_id = $files->saveFile([
- 'name' => $fileName,
- 'path' => $files->uploads,
- 'user_id' => Yii::$app->user->identity->id,
- 'lot_id' => $model->id,
- 'auction_id' => null,
- 'type' => 'lot',
- ]);
- $model->save();
- $model->upload();
- }
- return $this->redirect(['view', 'id' => $model->id]);
- } else {
- return $this->render('create', ['model' => $model]);
- }
- }
- public function actionConfirm($id, $status)
- {
- if (Yii::$app->user->can('admin') || Yii::$app->user->can('org')) {
- $model = $this->findModel($id);
- Yii::$app->response->format = Response::FORMAT_JSON;
- return
- $model->updateAttributes(['status' => $status,]);
- }else{
- return $this->redirect(['view', 'id' => $id]);
- }
- }
- public function actionCircle_down($id)
- {
- if (Yii::$app->user->can('admin')) {
- $model = $this->findModel($id);
- Yii::$app->db->createCommand("UPDATE lots SET step_down=step_down-1 WHERE id=:id")
- ->bindValue(':id', $id)
- ->execute();
- }
- return $this->redirect(['view', 'id' => $id]);
- }
- public function actionCircle_up($id)
- {
- if (Yii::$app->user->can('admin')) {
- $model = $this->findModel($id);
- Yii::$app->db->createCommand("UPDATE lots SET step_down=step_down+1 WHERE id=:id")
- ->bindValue(':id', $id)
- ->execute();
- }
- return $this->redirect(['view', 'id' => $id]);
- }
- public function actionUpdate($id)
- {
- $model = $this->findModel($id);
- $files = new Files();
- $files->uploads = '../uploads/lots/';
- // UploadedFile::getInstances($files, 'file');
- $fileName = $files->uploadFile();
- if ($model->status == 2) {
- Yii::$app->session->setFlash('danger', Yii::t('app', 'LotEditNoSuccess ID'));
- return $this->redirect(['index']);
- } elseif ($model->status == 3) {
- Yii::$app->session->setFlash('danger', Yii::t('app', 'LotEditNoReject ID'));
- return $this->redirect(['index']);
- }
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- if ($fileName) ;
- {
- $model->docs_id = $files->saveFile([
- 'name' => $fileName,
- 'path' => $files->uploads,
- 'user_id' => Yii::$app->user->identity->id,
- 'lot_id' => $model->id,
- 'auction_id' => null,
- 'type' => 'lot',
- ]);
- $model->save();
- $model->upload();
- }
- return $this->redirect(['view', 'id' => $model->id]);
- } else {
- return $this->render('update', [
- 'model' => $model,
- ]);
- }
- }
- public function actionDelete($id)
- {
- $model = $this->findModel($id);
- if ($model->status == 2) {
- Yii::$app->session->setFlash('danger', Yii::t('app', 'LotEditNoSuccess ID'));
- return $this->redirect(['index']);
- } elseif ($model->status == 3) {
- Yii::$app->session->setFlash('danger', Yii::t('app', 'LotEditNoReject ID'));
- return $this->redirect(['index']);
- }
- if ($model->status == 1) {
- if ($model->auction) {
- $model->auction->delete();
- }
- Yii::createObject(Eventlog::className())->PutLog([
- 'user_id' => Yii::$app->user->identity->id,
- 'ip' => Yii::$app->request->getRemoteIP(),
- 'auk_id' => $model->id,
- 'action' => Yii::t('app', 'OrgDeleteAuk ID {action}',
- ['action' => $model->aukname]),
- ]);
- $model->lot_lock = 0;
- $this->findModel($id)->delete();
- Yii::$app->session->setFlash('danger', Yii::t('app', 'Auction deleted successfully'));
- return $this->redirect(['index']);
- } else {
- return $this->render('/message', [
- 'title' => \Yii::t('app', 'Not Permission'),
- 'module' => $this->module,
- ]);
- }
- }
- public function actionAuction($id, $type)
- {
- if(Yii::$app->user->can('admin') || Yii::$app->user->can('org'))
- {
- // print_r($_POST);die();
- $model = $this->findModel($id);
- if($model->status==2 && $model->lot_lock==0 || $model->status==4 && $model->lot_lock==0)
- {
- if(Yii::$app->request->post('date_stop'))
- {
- $date_stop = Yii::$app->request->post('date_stop');
- $time_cont = Yii::$app->request->post('time_cont');
- }
- else
- {
- $date = strtotime($model->auction_date) + 7200;
- $date_stop = date("Y-m-d H:i:s", $date);
- }
- //$date = new \DateTime($model->auction_date);
- // create auction
- $insert = [
- 'user_id' => $model->user_id,
- 'name' => $model->aukname,
- 'lot_id' => $model->id,
- 'lot_num' => $model->num,
- 'date_start' => $model->auction_date,
- 'bidding_date' => $model->bidding_date,
- 'date_stop' => $date_stop,
- 'type_id' => $type,
- 'time_step_down' => $model->time_step_down,
- 'time_cont'=> $time_cont,
- 'step_down'=> $model->step_down,
- 'temp_step_down'=>$model->step_down,
- //'date_stop' => $date->modify('+1 day')->format('Y-m-d H:i:s'),
- ];
- // print_r($insert);die();
- $auction = Yii::createObject(Auctions::className())->CreateAuction($insert);
- Subscriptions::createNewsletter($auction);
- /* Узгоджено організатором */
- if($model->status==4)
- {
- $model->updateAttributes(['lot_lock' => '0']);
- }
- $model->updateAttributes(['lot_lock' => '1']);
- $notes_org = Yii::t('app','AuctionCreatedOnLot ID') .": ". $model->aukname ." / " .
- Yii::t('app','LotNumber ID'). $model->num . " " . $model->name;
- Yii::createObject(Messages::className())->CreateMessage(['user_id' => $model->user_id, 'notes' => $notes_org]);
- Yii::$app->session->setFlash('success', Yii::t('app', 'AuctionCreated ID'));
- return $this->redirect(['index']);
- } elseif ($model->status == 1 || $model->status == 3) {
- Yii::$app->session->setFlash('warning', Yii::t('app', 'NeedConfirmLot ID'));
- return $this->redirect(['view', 'id' => $model->id]);
- }
- else
- {
- Yii::$app->session->setFlash('warning', Yii::t('app', 'LotInAuction ID'));
- return $this->redirect(['view', 'id' => $model->id]);
- }
- } else {
- Yii::$app->session->setFlash('success', Yii::t('app', 'not permission2'));
- return $this->redirect(['view', 'id' => $model->id]);
- }
- }
- public function actionStepChange()
- {
- $id = Yii::$app->request->post('id');
- $value = Yii::$app->request->post('value');
- $model = Lots::findOne(['id' => $id]);
- $model->step_down = $value;
- if (Yii::$app->request->post() && $model->save()) {
- return $this->redirect(['/lots/view', 'id' => $id]);
- }
- }
- public function actionTimeStepChange()
- {
- $id = Yii::$app->request->post('id');
- $value = Yii::$app->request->post('concat_val');
- $model = Lots::findOne(['id' => $id]);
- $model->time_step_down = $value;
- if (Yii::$app->request->post() && $model->save()) {
- return $this->redirect(['/lots/view', 'id' => $id]);
- }
- }
- public function actionClone($id)
- {
- $model = $this->findModel($id);
- $attributes = $model->attributes;
- $attributes['id'] = null;
- $attributes['status'] = 1;
- $attributes['lot_lock'] = 0;
- $attributes['docs_id'] = null;
- $clone = new Lots($attributes);
- if ($clone->load(Yii::$app->request->post()) && $clone->save()) {
- if ((Yii::$app->request->post('agreeCopyFile')) && $model->file) {
- $clone->updateAttributes(['docs_id' => $model->file->copy($clone->id)]);
- } else {
- $clone->updateAttributes(['docs_id' => null]);
- }
- if (Yii::$app->request->post('agreeCopyImg')) {
- foreach ($model->images as $image) {
- $image->copy($clone->id);
- }
- foreach ($model->thumbnails as $thumbnail) {
- $thumbnail->copy($clone->id);
- }
- }
- return $this->redirect(['view', 'id' => $clone->id]);
- } else {
- return $this->render('clone', [
- 'model' => $model,
- ]);
- }
- }
- protected function findModel($id)
- {
- if (($model = Lots::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist . ');
- }
- }
- }
|