public function actionMajor() { $model = new Statistics(); $result = $model->getMajor(); $data = $model->convert_json($result); //var_dump($data);die; return $this->render('major', ['jsondata' => $data]); }
protected function _get_social_differential($info, $days = 5) { $stats = new Statistics(); $stat = $stats->get($info['_id'], date('Y-m-d', strtotime('-' . $days . ' days'))); $items = array('facebook' => array('details.likes', 'insights.engaged_users'), 'twitter' => array('details.statuses_count', 'details.followers_count'), 'instagram' => array('counts.followed_by'), 'google-youtube' => array('statistics.subscriberCount', 'statistics.videoCount'), 'google-analytics' => array('ga_data.ga:sessions'), 'vine' => array('followerCount'), 'klout' => array('score.score')); $result = array(); foreach ($items as $k => $fields) { if (!($a = MongoDoc::get($info, 'social.' . $k))) { continue; } $c = array(); if ($stat) { foreach ($fields as $f) { //echo 'VAL', PHP_EOL; //var_dump($f, 'social.'.$k.'.'.$f, MongoDoc::get($stat, 'social.'.$k.'.'.$f, null)); //var_dump($f, MongoDoc::get($a, $f, null)); $p = 1.0; if ($stat && ($v_old = MongoDoc::get($stat, 'social.' . $k . '.' . $f, null)) !== null && ($v_new = MongoDoc::get($a, $f, null)) !== null) { /* switch ($k.'.'.$f) { case 'twitter.details.statuses_count': $x = strtotime(MongoDoc::get($a, 'details.created_at')); $d = floor((time() - $x)/(3600*24)); $v_new1 = $d? ($v_new / $d) : 0; $d -= $days; $v_old1 = $d? ($v_new / $d) : 0; $c['details.statuses_per_day'] = round(($v_new1 - $v_old1)*100/$v_new1, 4); break; } */ //echo 'Found value: ', $v_new, ' - ' , $v_old, PHP_EOL; if ($v_new + $v_old == 0) { $p = 0; } else { if ($v_new) { $p = round(($v_new - $v_old) * 100 / $v_new, 4); } } } $c[$f] = $p; } } if ($c) { $result[$k] = $c; } } return MongoDoc::explode($result); }
protected function _insert_statistics($u) { $stats = new Statistics(); $items = array('facebook' => array('details.likes', 'insights.engaged_users'), 'twitter' => array('details.statuses_count', 'details.followers_count'), 'instagram' => array('counts.followed_by'), 'google-youtube' => array('statistics.subscriberCount', 'statistics.videoCount'), 'google-analytics' => array('ga_data.ga:sessions'), 'vine' => array('followerCount'), 'klout' => array('score.score')); $data = array(); foreach ($items as $k => $fields) { if (!($a = MongoDoc::get($u, 'social.' . $k))) { continue; } $c = array(); foreach ($fields as $f) { $c[$f] = MongoDoc::get($a, $f, 0); } if ($c) { $data[$k] = $c; } } if ($data) { try { $stats->save($u['_id'], date('Y-m-d'), array('social' => MongoDoc::explode($data))); } catch (\Exception $e) { echo 'Error updating document: ', $e->getMessage(), PHP_EOL; } } }
} } return $data['credit']; }], ['attribute' => '添加时间', 'value' => function ($data) { return $data['create_time']; }], ['class' => 'yii\\grid\\Column', 'header' => '审核状态', 'content' => function ($data) { $html = CommodityOrder::$Audits[$data['statu']]; if ($data['statu'] == CommodityOrder::$_AUDIT_PEND) { $html = '<a href="#" data-type="select" data-name="statu" data-pk="' . $data['id'] . '" data-value="' . $data['statu'] . '" data-title="审核状态">' . CommodityOrder::$Audits[$data['statu']] . '</a>'; } return $html; }], ['class' => 'yii\\grid\\Column', 'header' => '实收金额', 'content' => function ($data) { if (empty($data['real_income'])) { $data['real_income'] = '0.00'; } $statistics = Statistics::find()->where('coid = :coid', [':coid' => $data['id']])->one(); $style = ''; if (!empty($statistics)) { $total = $statistics->corpus + $statistics->total_fee; if ($data['real_income'] != '0.00' && $data['real_income'] < $total) { $style = 'style="color:red;"'; } } return '<a href="#" ' . $style . ' data-type="text" data-name="real_income" data-pk="' . $data['id'] . '" data-value="' . $data['real_income'] . '" data-title="实收金额">' . $data['real_income'] . '</a>'; }], ['class' => 'yii\\grid\\ActionColumn', 'header' => '操作', 'template' => '{allot} {view}', 'buttons' => ['allot' => function ($url, $data, $key) { $icon = '<span class="glyphicon glyphicon-user"></span>'; $html = '<a style="color:#d1d1d1;" title="分配">' . $icon . '</a>'; if ($data['statu'] == CommodityOrder::$_AUDIT_ACCESS) { $html = '<a href="allot?id=' . $data['id'] . '" title="分配">' . $icon . '</a>'; } return $html;
public function actionWlan() { $model = new Statistics(); $result = $model->getWlan(); $data = $model->convert_json($result); //var_dump($data);die; $title = json_encode(array('text' => '校园无线网')); return $this->render('pie', ['jsondata' => $data, 'title' => $title]); }
public function actionUpdateAuditStatu() { $id = Yii::$app->request->post('pk'); //$name = Yii::$app->request->post('name'); $value = Yii::$app->request->post('value'); $order = Order::findOne($id); if ($order->statu != Order::$_AUDIT_PEND) { $result = ['status' => 'error', 'msg' => '该商品已审核!']; echo json_encode($result); return; } $order->statu = $value; if ($order->save()) { $total_num = Order::find()->where('shop = :shop and commodity = :commodity and statu = :statu', [':shop' => $order->shop, ':commodity' => $order->commodity, ':statu' => Order::$_AUDIT_ACCESS])->count(); $fact_fee = Order::find()->where('shop = :shop and commodity = :commodity and statu = :statu', [':shop' => $order->shop, ':commodity' => $order->commodity, ':statu' => Order::$_AUDIT_ACCESS])->sum('fee'); $total_income = Order::find()->where('shop = :shop and commodity = :commodity and statu = :statu', [':shop' => $order->shop, ':commodity' => $order->commodity, ':statu' => Order::$_AUDIT_ACCESS])->sum('money'); $statistics = Statistics::find()->where('shop = :shop and commodity = :commodity', [':shop' => $order->shop, ':commodity' => $order->commodity])->one(); if (!empty($statistics)) { $statistics->total_num = $total_num; $statistics->fact_fee = $fact_fee; //intval($order->fee); $statistics->total_income = $total_income; //floatval($order->money); $statistics->save(); } } $result = ['status' => 'sucess']; echo json_encode($result); }
public function actionUpdateRealIncome() { $id = Yii::$app->request->post('pk'); //$name = Yii::$app->request->post('name'); $value = Yii::$app->request->post('value'); $commodityOrder = CommodityOrder::findOne($id); $commodityOrder->real_income = $value; if ($commodityOrder->save()) { $statistics = Statistics::find()->where('coid = :coid', [':coid' => $commodityOrder->id])->one(); $statistics->real_income = $value; $statistics->save(); } $result = ['status' => 'sucess']; echo json_encode($result); }
public function actionExportcsv() { $model = new StatisticsSearchForm(); $model->load(Yii::$app->request->post()); $query = (new Query())->from(Statistics::tableName())->where('1=1'); if (!empty($model->shop)) { $query->andWhere('shop=:shop', [':shop' => $model->shop]); } if (!empty($model->commodity)) { $query->andWhere('commodity like :commodity', [':commodity' => '%' . $model->commodity . '%']); } if (!empty($model->platform)) { $query->andWhere('platform=:platform', [':platform' => $model->platform]); } if (!empty($model->btime)) { $query->andWhere('handle_time >= :handle_time', [':handle_time' => $model->btime]); } if (!empty($model->etime)) { $query->andWhere('handle_time <= :handle_time', [':handle_time' => $model->etime]); } if ($this->user->rid == 3) { $query->andWhere('uid = :uid', [':uid' => $this->user->id]); } $query->orderBy('handle_time desc'); $pages = new Pagination(['totalCount' => $query->count(), 'pageSize' => '20']); $query->limit($pages->limit)->offset($pages->offset); $statisticss = $query->all(); $info = array(); foreach ($statisticss as $statistics) { $row = array(); $row[] = $statistics['shop']; $row[] = $statistics['platform']; $row[] = $statistics['commodity']; $row[] = $statistics['corpus']; if ($this->user->rid != 4) { $row[] = $statistics['real_income']; } $row[] = $statistics['total_income']; if ($this->user->rid != 4) { $row[] = $statistics['total_fee']; } $row[] = $statistics['corpus'] - $statistics['total_income']; $row[] = $statistics['total_num']; $row[] = $statistics['budget_num']; $row[] = $statistics['handle_time']; array_push($info, $row); } $detail = ''; $subject = mb_convert_encoding("店铺,平台,商品,本金,已收金额,差额,提交笔数,商家笔数,执行时间\n", "CP936", "UTF-8"); if ($this->user->rid != 4) { $subject = mb_convert_encoding("店铺,平台,商品,本金,实收金额,已收金额,总佣金,差额,提交笔数,商家笔数,执行时间\n", "CP936", "UTF-8"); } foreach ($info as $v) { foreach ($v as $value) { $value = preg_replace('/\\s+/', ' ', $value); $detail .= strlen($value) > 11 && is_numeric($value) ? '[' . $value . '],' : $value . ','; } $detail = $detail . "\n"; } $filename = time() . '_报表统计.csv'; ob_end_clean(); header('Content-Encoding: none'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . $filename); header('Pragma: no-cache'); header('Expires: 0'); echo $subject; $detail = iconv("utf-8", "gb2312", $detail); echo $detail; }