Esempio n. 1
0
 public function actionGetData($channelName)
 {
     $channel = Channel::find()->where(['channelName' => $channelName])->one();
     if (!Yii::$app->user->isGuest) {
         UserChannel::updateUserLastAccess($channel, Yii::$app->user->identity->id);
     }
     UserChannel::clearOfflineUsers();
     $result = json_encode(['usersList' => $channel->formattedUsers, 'messages' => $channel->formattedMessages]);
     return $result;
 }
Esempio n. 2
0
 public function actionChannelreport()
 {
     $listChannel = Channel::find()->where('enabled<>0')->asArray()->all();
     $startDate = strtotime(Yii::$app->request->get('startdate') . ' 00:00:00');
     $endDate = strtotime(Yii::$app->request->get('enddate') . ' 23:59:59');
     for ($i = 0; $i < count($listChannel); $i++) {
         $baseQuery = Record::find()->andWhere(['channel_id' => $listChannel[$i]['id']]);
         $baseQuery->andWhere(['>', 'created_at', $startDate]);
         $baseQuery->andWhere(['<', 'created_at', $endDate]);
         $tempQuery = clone $baseQuery;
         $listChannel[$i]['total'] = $tempQuery->count();
         $tempQuery = clone $baseQuery;
         $listChannel[$i]['validcount'] = $tempQuery->andWhere(['is_valid' => 1])->count();
         $tempQuery = clone $baseQuery;
         $listChannel[$i]['reservecount'] = $tempQuery->andWhere(['is_reserve' => 1])->count();
         $tempQuery = clone $baseQuery;
         $listChannel[$i]['arrivedcount'] = $tempQuery->andWhere(['is_arrive' => 1])->count();
         //消费
         $totalCost = 0;
         $cost = ChannelCost::find()->where('startdate>=:startdate and enddate<=:enddate and channel_id=:channel_id', [':startdate' => $startDate, ':enddate' => $endDate, ':channel_id' => $listChannel[$i]['id']])->sum('fee');
         $totalCost += $cost;
         //后开始还未到结束日期的费用
         $channelCost = ChannelCost::find()->where('startdate>=:startdate and enddate>:enddate and channel_id=:channel_id', [':startdate' => $startDate, ':enddate' => $endDate, ':channel_id' => $listChannel[$i]['id']])->all();
         foreach ($channelCost as $tmpCost) {
             $days = ceil(($tmpCost['enddate'] - $tmpCost['startdate']) / 86400);
             $avgCost = $tmpCost['fee'] / $days;
             //平均每天费用
             $days = ceil(($endDate - $tmpCost['startdate']) / 86400);
             $cost = round($avgCost * $days, 2);
             $totalCost += $cost;
         }
         //先开始提前结束的费用
         $channelCost = ChannelCost::find()->where('startdate<:startdate and enddate<=:enddate and channel_id=:channel_id', [':startdate' => $startDate, ':enddate' => $endDate, ':channel_id' => $listChannel[$i]['id']])->all();
         foreach ($channelCost as $tmpCost) {
             $days = ceil(($tmpCost['enddate'] - $tmpCost['startdate']) / 86400);
             $avgCost = $tmpCost['fee'] / $days;
             $days = ceil(($tmpCost['enddate'] - $startDate) / 86400);
             $cost = round($avgCost * $days, 2);
             $totalCost += $cost;
         }
         //提前开始还未结束的费用
         $channelCost = ChannelCost::find()->where('startdate<:startdate and enddate>:enddate and channel_id=:channel_id', [':startdate' => $startDate, ':enddate' => $endDate, ':channel_id' => $listChannel[$i]['id']])->all();
         foreach ($channelCost as $tmpCost) {
             $days = ceil(($tmpCost['enddate'] - $tmpCost['startdate']) / 86400);
             $avgCost = $tmpCost['fee'] / $days;
             $days = ceil(($endDate - $startDate) / 86400);
             $cost = round($avgCost * $days, 2);
             $totalCost += $cost;
         }
         $listChannel[$i]['cost'] = $totalCost;
     }
     return $this->renderPartial('channelreport', ['model' => $listChannel]);
 }
Esempio n. 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Channel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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(['id' => $this->id]);
     $query->andFilterWhere(['like', 'channelName', $this->channelName])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Esempio n. 4
0
 /**
  * @param array $data
  * Пытается распарсить значения сообщения из массива, что приходит с пост-запросом обычно
  */
 public function parse($data)
 {
     if (!Yii::$app->user->isGuest) {
         $this->senderId = Yii::$app->user->identity->id;
     }
     if ($data['message']) {
         $this->messageText = $data['message'];
     }
     if ($data['channelName']) {
         $channel = Channel::find()->where(['channelName' => $data['channelName']])->one();
         if ($channel) {
             $this->channelId = $channel->id;
         }
     }
     if ($data['receiver'] && strlen($data['receiver']) > 0) {
         $receiverUser = User::find()->where(['username' => $data['receiver']])->one();
         if ($receiverUser) {
             $this->receiverId = $receiverUser->id;
         } else {
             $this->receiverId = 0;
         }
     }
 }
Esempio n. 5
0
 public function actionAppointment()
 {
     $listDepartment = ArrayHelper::map(Department::find()->where('enabled<>0')->all(), 'id', 'name');
     $listChannel = ArrayHelper::map(Channel::find()->where('enabled<>0')->all(), 'id', 'name');
     $listDoctor = ArrayHelper::map(Doctor::find()->where('enabled<>0')->all(), 'id', 'name');
     $listUser = ArrayHelper::map(User::find()->where('enabled<>0')->all(), 'id', 'username');
     return $this->render('appointment', ['model' => new Record(), 'listDepartment' => $listDepartment, 'listChannel' => $listChannel, 'listDoctor' => $listDoctor, 'listUser' => $listUser]);
 }
Esempio n. 6
0
 public function actionCost()
 {
     $listChannel = ArrayHelper::map(Channel::find()->where('enabled<>0')->all(), 'id', 'name');
     return $this->render('cost', ['model' => new ChannelCost(), 'listChannel' => $listChannel]);
 }