/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = PurchasedItem::find()->joinWith('ticket'); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['ticket_id' => SORT_DESC]]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['item_type_id' => $this->item_type_id]); $query->andFilterWhere(['like', 'item_name', $this->item_name])->andFilterWhere(['or', ['ticket_id' => $this->ticket_id], ['like', Ticket::tableName() . '.title', $this->ticket_id]]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Ticket::find()->current()->joinWith(['invoice.location', 'invoice.location.client']); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50], 'sort' => ['defaultOrder' => ['status_id' => SORT_ASC]]]); $dataProvider->sort->attributes['location_id'] = ['asc' => [Client::tableName() . '.name' => SORT_ASC, Location::tableName() . '.name' => SORT_ASC], 'desc' => [Client::tableName() . '.name' => SORT_DESC, Location::tableName() . '.name' => SORT_DESC]]; $dataProvider->sort->attributes['status_id'] = ['asc' => [Ticket::tableName() . '.status_id' => SORT_DESC], 'desc' => [Ticket::tableName() . '.status_id' => SORT_ASC]]; $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere([Location::tableName() . '.id' => $this->location_id, Ticket::tableName() . '.status_id' => $this->status_id, Ticket::tableName() . '.priority_id' => $this->priority_id, Ticket::tableName() . '.bill_type_id' => $this->bill_type_id]); $query->andFilterWhere(['like', Ticket::tableName() . '.id', $this->id]); return $dataProvider; }
/** * @param integer $invoice_id * @return $this */ public function invoice($invoice_id) { $this->andWhere([Ticket::tableName() . '.invoice_id' => $invoice_id]); return $this; }
public function hourly($hourly = true) { $this->joinWith('note.ticket')->andWhere([\common\models\Ticket::tableName() . '.bill_type_id' => $hourly ? Ticket::BILL_HOURLY : Ticket::BILL_PROACTIVE]); return $this; }
/** * 创建工单 * @return string|\yii\web\Response */ public function actionAdd_ticket() { $ticketModel = new Ticket(); $ticketCdataModel = new TicketCdata(); if (Yii::$app->request->post()) { $ticketForm = Yii::$app->request->post('Ticket'); $ticketCdataForm = Yii::$app->request->post('TicketCdata'); $fileForm = Yii::$app->request->post('File'); $ticketTopicRelationForm = Yii::$app->request->post('TicketTopicRelation'); $ticketModel->number = $ticketModel->newTicketNumber(); $ticketModel->user_id = Yii::$app->user->identity->id; $ticketModel->status_id = TicketStatus::CREATED; $ticketModel->type_id = Ticket::FEEDBACK_TICKET_TYPE; $ticketModel->source_id = 1; $ticketModel->ip_address = Yii::$app->request->getUserIP(); $ticketModel->created = date("Y-m-d H:i:s"); $ticketModel->updated = date("Y-m-d H:i:s"); $ticketCdataModel->subject = $ticketCdataForm['subject']; $ticketCdataModel->detail = $ticketCdataForm['detail']; $ticketCdataModel->priority = 1; //事务 $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { if (!$ticketModel->save()) { throw new Exception("数据存储失败,请检查数据库配置(error:1001)"); } $ticketCdataModel->ticket_id = $ticketModel->ticket_id; if (!$ticketCdataModel->save()) { throw new Exception("数据存储失败,请检查数据库配置(error:1002)"); } if (!empty($fileForm['file_index']) && is_array($fileForm['file_index'])) { foreach ($fileForm['file_index'] as $k => $v) { $fileModel = new File(); $fileModel->attribute = Ticket::tableName(); $fileModel->attribute_id = $ticketModel->ticket_id; $fileModel->file_name = $v['name']; $fileModel->file_index = $v['path']; $fileModel->size = $v['size']; $fileModel->type = $v['type']; if (!$fileModel->save()) { throw new Exception("数据存储失败,请检查数据库配置(error:1003)"); } } } if (!empty($ticketTopicRelationForm['topic_id']) && is_array($ticketTopicRelationForm['topic_id'])) { foreach ($ticketTopicRelationForm['topic_id'] as $v) { $ticketTopicRelationModel = new TicketTopicRelation(); $ticketTopicRelationModel->ticket_id = $ticketModel->ticket_id; $ticketTopicRelationModel->topic_id = $v; if (!$ticketTopicRelationModel->save()) { throw new Exception("数据存储失败,请检查数据库配置(error:1004)"); } } } $transaction->commit(); } catch (Exception $e) { $transaction->rollBack(); return $this->redirect(array('add_ticket')); } return $this->redirect(array('detail', 'number' => $ticketModel->number)); } else { $topicModel = new TicketTopic(); $topic_list = $topicModel->find()->select(array('topic_name', 'topic_id'))->indexBy('topic_id')->column(); $fileModel = new File(); $ticketTopicRelationModel = new TicketTopicRelation(); return $this->render('add_ticket', array('ticketModel' => $ticketModel, 'ticketCdataModel' => $ticketCdataModel, 'fileModel' => $fileModel, 'ticketTopicRelationModel' => $ticketTopicRelationModel, 'topic_list' => $topic_list)); } }