Exemple #1
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]);
 }
Exemple #2
0
 public function actionCostedit()
 {
     $data = Yii::$app->request->post('ChannelCost');
     $result = array();
     if (is_numeric($data['id']) && $data['id'] > 0) {
         $model = Record::findOne($data['id']);
         if (!$model) {
             $result['status'] = 0;
             $result['message'] = '未找到该记录';
         }
     } else {
         $model = new ChannelCost();
     }
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             $result['status'] = 1;
             $result['message'] = '保存成功';
         }
     }
     $errors = $model->getFirstErrors();
     if ($errors) {
         $result['status'] = 0;
         $result['message'] = current($errors);
     }
     return $this->renderJson($result);
 }