Charlie 9 years ago
parent
commit
735c94a8f1

+ 412 - 0
www/protected/controllers/MaterialController.php

@@ -0,0 +1,412 @@
+<?php 
+/**
+ * 物资控制器
+ * @author zhouxuchen 2015-09-16
+ */
+class MaterialController extends AdminController {
+
+    // 物资首页
+    public function actionIndex () {
+        $status_option = Material::$status_option;
+        $unit_option = Material::$unit_option;
+        $enable_option = Material::$enable_option;
+        $status = CommonFn::getComboboxData($status_option, 100, true, 100);
+        $type = CommonFn::getComboboxData($unit_option, 100, false, 0);
+        $enable = CommonFn::getComboboxData($enable_option, 100, true, 100);
+
+        // 服务点信息
+        $criteria = new EMongoCriteria();
+        $cursor = Station::model()->findAll($criteria);
+        $rows = CommonFn::getRowsFromCursor($cursor);
+        $parsedRows = Station::model()->parse($rows);
+        $station_data = array();
+        foreach ($parsedRows as $key => $v) {
+            $station_data = array_merge($station_data, array($v['id'] => array('name' => $v['name'])));
+            // $station_data[] = array('name' => $v['name']);
+        }
+
+        $station = CommonFn::getComboboxData($station_data, '', false, '');
+
+        $this->render('index', array(
+            'status'  => $status,
+            'type'    => $type,
+            'enable'  => $enable,
+            'station' => $station
+        ));
+    }
+
+    // 物资列表
+    public function actionList () {
+        $params = CommonFn::getPageParams();
+
+        $id = Yii::app()->request->getParam('id', '');
+        $status = intval(Yii::app()->request->getParam('status', 100));
+        $enable = intval(Yii::app()->request->getParam('enable', 100));
+        $search = Yii::app()->request->getParam('search', '');
+
+        $criteria = new EMongoCriteria($params);
+
+        // 库存状态删选
+        if($status!=100){
+            $criteria->status('==', $status);
+        }
+        // 物资启用状态筛选
+        if($enable!=100){
+            $criteria->enable('==', $enable);
+        }
+
+        if ($search != ''){
+            if (CommonFn::isMongoId($search)){
+                $criteria->_id('==',new MongoId($search));
+            } else {
+                $criteria->name = new MongoRegex('/' . $search . '/');
+            }
+        }
+
+        $cursor = Material::model()->findAll($criteria);
+        $total = $cursor->count();
+        $rows = CommonFn::getRowsFromCursor($cursor);
+        $parsedRows = Material::model()->parse($rows);
+
+        echo CommonFn::composeDatagridData($parsedRows, $total);
+    }
+
+    // 编辑物资信息
+    // 若id被传入则物资信息被编辑,若id未传入则新建一个物资信息
+    public function actionEdit () {
+        $id = Yii::app()->request->getParam('id', '');
+
+        $name = Yii::app()->request->getParam('name', '');
+        $unit = intval(Yii::app()->request->getParam('unit', 0));
+        $stockWarnLine = intval(Yii::app()->request->getParam('stockWarnLine', 0));
+        $price = number_format(Yii::app()->request->getParam('price', 0), 2, '.', '');
+        $enable = intval(Yii::app()->request->getParam('enable', 1));
+        $stock = intval(Yii::app()->request->getParam('stock', 0));
+        $remarks = Yii::app()->request->getParam('remarks', '');
+
+        if (!$unit) {
+            CommonFn::requestAjax(false, '请选择单位');
+            die;
+        }
+
+        if(!$id){
+            $material = new Material();
+            $material->addTime = time();
+            $material->stock = $stock;
+        }else{
+            $criteria = new EMongoCriteria();
+            $criteria->_id = new MongoId($id);
+            $material = Material::model()->find($criteria);
+            if (empty($material)){
+                CommonFn::requestAjax(false, '物资不存在');
+                die;
+            }
+        }
+
+        // 直接修改物资,正式使用后该行注释
+        $material->stock = $stock;
+
+        $material->name = $name;
+        $material->unit = $unit;
+        $material->unit_str = $this->unit_str($unit); // 判断单位str
+        $material->price = $price;
+        $material->stockWarnLine = $stockWarnLine;
+        $material->status = $this->status($material->stock, $material->stockWarnLine);
+        $material->status_str = $this->status_str($material->status); //判断库存状态
+        $material->enable = $enable;
+        $material->enable_str = $this->enable_str($enable);
+        $material->remarks = $remarks;
+        
+        $arr_addMaterial = array('name', 'unit_str', 'unit', 'price', 'stock', 'stockWarnLine', 'addTime', 'user', 'status', 'status_str', 'enable', 'enable_str', 'remarks');
+
+        $success = $material->save(true, $arr_addMaterial);
+
+        CommonFn::requestAjax($success, '', array());
+    }
+
+    /**
+     * 出入库操作
+     * @param obj c_user     : criteria for model `User`
+     * @param obj c_material : criteria for model `Material`
+     * @param obj c_object   : criteria for model `User`
+     * @param obj c_station  : criteria for model `Station`
+     */
+    public function actionStock () {
+        $mid = Yii::app()->request->getParam('mid', '');
+        $operate = intval(Yii::app()->request->getParam('operate', 1));
+        $num = intval(Yii::app()->request->getParam('num', 0));
+        $tot_price = Yii::app()->request->getParam('tot_price', 0);
+        $remarks =Yii::app()->request->getParam('remarks', '');
+        $object = Yii::app()->request->getParam('object', '');
+        $sid = Yii::app()->request->getParam('station', '');
+        $time = time();
+
+        if ($mid == '') {
+            CommonFn::requestAjax(false, '请选择物资');
+            die;
+        }
+
+        if ($num <= 0) {
+            CommonFn::requestAjax(false, '数量错误');
+            die;
+        }
+
+        // 用户信息
+        $user = Yii::app()->user;
+        $email = $user->name;
+        $c_user = new EMongoCriteria();
+        $c_user->email = $email;
+        $userInfo = User::model()->find($c_user);
+
+        // 物资基本信息
+        $c_material = new EMongoCriteria();
+        $c_material->_id = new MongoId($mid);
+        $material = Material::model()->find($c_material);
+        if (empty($material)) {
+            CommonFn::requestAjax(false, '物资不存在');
+            die;
+        }
+
+        $stock = new Stock();
+
+        // 所需要的物资数据
+        $lastStock = $material->stock;
+        $price = $material->price;
+
+        // 入库数量及价格
+        $stock->num = $num;
+        $stock->tot_price = $tot_price != 0 ? $tot_price : $num * $price;
+        $stock->lastStock = $lastStock;
+        $stock->newStock = $this->newStock($lastStock, $num, $operate);
+        if ($stock->newStock < 0) {
+            CommonFn::requestAjax(false, '出库操作错误,请检查数量', array());
+            die;
+        }
+
+        if ($operate == 0) {
+            if ($sid == '') {
+                CommonFn::requestAjax(false, '请选择服务点');
+                die;
+            }
+
+            // 目标用户
+            $c_object = new EMongoCriteria();
+            $c_object->name = $object;
+            $objInfo = User::model()->find($c_object);
+            if (empty($objInfo)) {
+                CommonFn::requestAjax(false, '目标用户不存在');
+                die;
+            } else {
+                $stock->object = $objInfo->_id;
+                $stock->objectName = $objInfo->name;
+            }
+
+            // 服务点信息
+            $c_station = new EMongoCriteria();
+            $c_station->_id = new MongoId($sid);
+            $station = Station::model()->find($c_station);
+            if (empty($station)) {
+                CommonFn::requestAjax(false, '服务点不存在');
+                die;
+            }
+            $stock->station = new MongoId($sid);
+            $stock->stationName = $station->name;
+
+            
+            $arr_addStock = array('mid', 'mname', 'operate', 'operate_str', 'user', 'time', 'username', 'num', 'tot_price', 'lastStock', 'newStock', 'remarks', 'object', 'objectName', 'station', 'stationName');
+        } else {
+            $stock->objectName = '公司总库';
+            $stock->stationName = '无';
+
+            $arr_addStock = array('mid', 'mname', 'operate', 'operate_str', 'user', 'time', 'username', 'num', 'tot_price', 'lastStock', 'newStock', 'remarks', 'objectName', 'stationName');
+        }
+
+        $stock->mid = new MongoId($mid);
+        $stock->mname = $material->name;
+        $stock->operate = $operate;
+        $stock->operate_str = $this->operate_str($operate);
+        $stock->user = $userInfo->_id;
+        $stock->username = $userInfo->name;
+        $stock->time = $time;
+
+        $stock->remarks = $remarks;        
+
+        $material->stock = $stock->newStock;
+        $material->status = $this->status($material->stock, $material->stockWarnLine);
+        $material->status_str = $this->status_str($material->status);
+
+        $arr_addMaterial = array('stock', 'status', 'status_str');
+
+        // 增加库存表记录
+        $success_stock = $stock->save(true, $arr_addStock);
+        // 修改物资表记录
+        $success_material = $material->save(true, $arr_addMaterial);
+        // print_r($stock);die;
+
+        CommonFn::requestAjax($success_stock&$success_material, '', array());
+    }
+
+    // 自动填充用户
+    public function actionSelectUser () {
+        $chars = Yii::app()->request->getParam('user', '');
+
+        $MongoDbAuthManager = new CMongoDbAuthManager();
+        $users_id = $MongoDbAuthManager->getAuthUser('技师');
+
+        $criteria = new EMongoCriteria();
+        $criteria->addCond('name', 'or', new MongoRegex('/'.$chars.'/'));
+        $criteria->addCond('email', 'or', new MongoRegex('/'.$chars.'/'));
+
+        $cursor = User::model()->findAll($criteria);
+        $rows = CommonFn::getRowsFromCursor($cursor);
+        $index = 0;
+        foreach ($rows as $key => $v) {
+            if (in_array($v['_id'], $users_id)) {
+                $arr[] = array(
+                    'id' => $index,
+                    'data' => $v['name'],
+                    'description' => $v['email'],
+                    'uid' => $v['_id'],
+                );
+                $index++;
+            } else {
+                continue;
+            }
+        }
+
+        if (empty($arr)) {
+            $arr = array(
+                'id' => 0,
+                'data' => '',
+                'description' => '',
+                'uid' => -1,
+            );
+        }
+
+        echo json_encode($arr);
+    }
+
+    // 自动填充物资
+    public function actionSelectMaterial () {
+        $chars = Yii::app()->request->getParam('material', '');
+
+        $criteria = new EMongoCriteria();
+        $criteria->name = new MongoRegex('/'.$chars.'/');
+
+        $cursor = Material::model()->findAll($criteria);
+        $rows = CommonFn::getRowsFromCursor($cursor);
+        if (empty($rows)) {
+            $arr = array(
+                'id' => 0,
+                'data' => ''
+            );
+        } else {
+            foreach ($rows as $key => $v) {
+                $arr[] = array(
+                    'id' => $key,
+                    'data' => $v['name']
+                );
+            }
+        }
+
+        echo json_encode($arr);
+    }
+
+    // 判断单位类型
+    protected function unit_str ($type) {
+        switch ($type) {
+            case 1:
+                $unit_str = '瓶';
+                break;
+            case 2:
+                $unit_str = '袋';
+                break;
+            case 3:
+                $unit_str = '盒';
+                break;
+            case 4:
+                $unit_str = '台';
+                break;
+            case 5:
+                $unit_str = '件';
+                break;
+            case 6:
+                $unit_str = '双';
+                break;
+            default:
+                $unit_str = '未找到相应单位';
+                break;
+        }
+
+        return $unit_str;
+    }
+
+    // 判断库存状态(status)
+    protected function status ($stock, $stockWarnLine) {
+        if ($stock > $stockWarnLine && $stockWarnLine >= 0) {
+            $status = 2;
+        } else if ($stock > 0 && $stock <= $stockWarnLine) {
+            $status = 1;
+        } else if ($stock == 0) {
+            $status = 0;
+        } else {
+            $status = 3;
+        }
+
+        return $status;
+    }
+
+    // 判断库存状态(status_str)
+    protected function status_str ($type) {
+        switch ($type) {
+            case 0:
+                $status_str = '无库存';
+                break;
+            case 1:
+                $status_str = '紧张';
+                break;
+            case 2:
+                $status_str = '充足';
+                break;
+            default:
+                $status_str = '未知';
+                break;
+        }
+
+        return $status_str;
+    }
+
+    // 判断物资是否启用
+    protected function enable_str ($type) {
+        if ($type == 1) {
+            $enable_str = '启用';
+        } else {
+            $enable_str = '停用';
+        }
+
+        return $enable_str;
+    }
+
+    // 判断库存操作
+    protected function operate_str ($type) {
+        if ($type == 0) {
+            $operate_str = '出库';
+        } else {
+            $operate_str = '入库';
+        }
+
+        return $operate_str;
+    }
+
+    // 新库存计算
+    protected function newStock ($lastStock, $num, $operate) {
+        if ($operate == 0) {
+            $newStock = $lastStock - $num;
+        } else {
+            $newStock = $lastStock + $num;
+        }
+
+        return $newStock;
+    }
+}
+?>

+ 243 - 0
www/protected/controllers/StockController.php

@@ -0,0 +1,243 @@
+<?php 
+/**
+ * 库存控制器
+ * @author zhouxuchen 2015-09-18
+ */
+class StockController extends AdminController {
+
+    // 显示库存修改信息首页
+    public function actionIndex () {
+        $operate_option = Stock::$operate_option;
+        $operate = CommonFn::getComboboxData($operate_option, 100, true, 100);
+        $objectName = Yii::app()->request->getParam('objectName', '');
+        $stationName = Yii::app()->request->getParam('stationName', '');
+        $fromStockView = (!empty($objectName) || !empty($stationName)) ? true : false;
+
+        // 服务点信息
+        $criteria = new EMongoCriteria();
+        $cursor = Station::model()->findAll($criteria);
+        $rows = CommonFn::getRowsFromCursor($cursor);
+        $parsedRows = Station::model()->parse($rows);
+        $station_data = array();
+        foreach ($parsedRows as $key => $v) {
+            $id = (string)$v['id'];
+            $station_data = array_merge($station_data, array($id => array('name' => $v['name'])));
+        }
+        $station_data = array_merge($station_data, array('noStation' => array('name' => '无')));
+
+        $station = CommonFn::getComboboxData($station_data, 'all', true, 'all');
+
+        $data = array(
+            'operate'       => $operate,
+            'objectName'    => $objectName,
+            'stationName'   => $stationName,
+            'fromStockView' => $fromStockView,
+            'station'       => $station
+        );
+
+        $this->render('index', $data);
+    }
+
+    // 库存操作列表
+    public function actionList () {
+        $params = CommonFn::getPageParams();
+
+        $operate = intval(Yii::app()->request->getParam('operate', 100));
+        $s_mname = Yii::app()->request->getParam('s_mname', '');
+        $s_user = Yii::app()->request->getParam('s_user', '');
+        $date_start = Yii::app()->request->getParam('date_start', '');
+        $date_end = Yii::app()->request->getParam('date_end', '');
+        $station = Yii::app()->request->getParam('station', 'all');
+
+        $criteria = new EMongoCriteria($params);
+
+        // 时间处理
+        if (!empty($date_start) && !empty($date_end)) {
+            // 开始时间处理
+            $timestamp_start = strtotime($date_start);
+            // 结束时间处理,需通过strtotime()增加一天
+            $timestamp_end = strtotime('+1 day', strtotime($date_end));
+
+            $criteria->time('>=', $timestamp_start);
+            $criteria->time('<=', $timestamp_end);
+        }
+
+        // 操作筛选
+        if($operate != 100) {
+            $criteria->operate('==', $operate);
+        }
+
+        // 根据物资名称搜索
+        if ($s_mname != '') {
+            if (CommonFn::isMongoId($s_mname)){
+                $criteria->mid('==',new MongoId($s_mname));
+            } else {
+                $criteria->mname = new MongoRegex('/' . $s_mname . '/');
+            }
+        }
+
+        // 根据目标用户名搜索
+        if ($s_user != '') {
+            if (CommonFn::isMongoId($s_user)){
+                $criteria->object('==', new MongoId($s_user));
+            } else {
+                $criteria->objectName = new MongoRegex('/' . $s_user . '/');
+            }
+        }
+
+        // 根据服务点搜索
+        if ($station != 'all') {
+            if ($station == 'noStation') {
+                $criteria->stationName('==', '无');
+            } else {
+                $criteria->station('==', new MongoId($station));
+            }
+        }
+
+        $cursor = Stock::model()->findAll($criteria);
+        $total = $cursor->count();
+        $rows = CommonFn::getRowsFromCursor($cursor);
+        $parsedRows = Stock::model()->parse($rows);
+
+        // $this->p($parsedRows);die;
+
+        echo CommonFn::composeDatagridData($parsedRows, $total);
+    }
+
+    // 编辑库存操作备注
+    public function actionEdit () {
+        // echo "<pre>";
+        // print_r($_POST);die;
+
+        $id         = Yii::app()->request->getParam('id', '');
+        $objectName = Yii::app()->request->getParam('objectName', '');
+        $station    = Yii::app()->request->getParam('station', '');
+        $remarks    = Yii::app()->request->getParam('remarks', ''); 
+
+        $criteria = new EMongoCriteria();
+        $criteria->_id = new MongoId($id);
+        $stock = Stock::model()->find($criteria);
+        if (empty($stock)) {
+            CommonFn::requestAjax(false, '该条操作不存在');
+        }
+
+        $arr_addStocks = array();
+
+        // 获取目标用户信息
+        if ($objectName != $stock->objectName) {
+            $criteria = new EMongoCriteria();
+            $criteria->name = $objectName;
+            $object_info = User::model()->find($criteria);
+
+            if (count($object_info) == 0) {
+                CommonFn::requestAjax(false, '用户不存在,请检查用户名', array());
+                die;
+            }
+
+            $stock->objectName = $objectName;
+            $stock->object = $object_info->_id;
+            $arr_addStocks[] = 'object';
+            $arr_addStocks[] = 'objectName';
+        }
+
+        // 获取服务点信息
+        if ((string)$station != (string)$stock->station) {
+            $station_id = new MongoId($station);
+            $criteria = new EMongoCriteria();
+            $criteria->_id = $station_id;
+            $station_info = Station::model()->find($criteria);
+
+            $stock->stationName = $station_info->name;
+            $stock->station = $station_id;
+            $arr_addStocks[] = 'stationName';
+            $arr_addStocks[] = 'station';
+        }
+
+        $arr_addStocks[] = 'remarks';
+
+        $stock->remarks = $remarks;
+
+        $success = $stock->save(true, $arr_addStocks);
+
+        CommonFn::requestAjax($success, '', array());
+    }
+
+    // 自动填充服务点信息
+    public function actionSelectStation () {
+        $station = Yii::app()->request->getParam('station', '');
+
+        $criteria = new EMongoCriteria();
+        $criteria->name = new MongoRegex('/'.$station.'/');
+
+        $cursor = Station::model()->findAll($criteria);
+        $rows = CommonFn::getRowsFromCursor($cursor);
+
+        if (empty($rows)) {
+            $arr = array(
+                'id' => 0,
+                'data' => ''
+            );
+        } else {
+            foreach ($rows as $key => $v) {
+                $arr[] = array(
+                    'id' => $key,
+                    'data' => $v['name']
+                );
+            }
+        }
+
+        echo json_encode($arr);
+    }
+
+    /**
+     * 几个私有方法
+     * p           使用<pre>标签打印数据
+     * checkAction 检查减小库存的操作是否超过最小库存量
+     * checkStock  检查库存量所处的状态
+     * unit        判断单位类型
+     */
+    protected function p($arr) {
+        echo '<pre>';
+        print_r($arr);
+        echo '</pre>';
+    }
+
+    // 检查库存是否充足(针对减小库存的操作)
+    protected function checkAction () {
+        // TODO...
+    }
+
+    // 修改库存后检查库存的状态(针对所有操作)
+    protected function checkStock () {
+        // TODO...
+    }
+
+    // 判断单位类型
+    protected function unit ($type) {
+        switch ($type) {
+            case 1:
+                $unit = '瓶';
+                break;
+            case 2:
+                $unit = '袋';
+                break;
+            case 3:
+                $unit = '盒';
+                break;
+            case 4:
+                $unit = '台';
+                break;
+            case 5:
+                $unit = '件';
+                break;
+            default:
+                $unit = '未找到相应单位';
+                break;
+        }
+
+        return $unit;
+    }
+
+}
+
+?>

+ 686 - 0
www/protected/controllers/StockViewStationController.php

@@ -0,0 +1,686 @@
+<?php 
+/**
+ * 库存操作统计控制器(根据服务点)
+ * @author zhouxuchen 2015-10-08
+ */
+class StockViewStationController extends AdminController {
+
+    /**
+     * 首页
+     * 默认显示本周内数据统计及图表
+     */
+    public function actionIndex () {
+        $station = Yii::app()->request->getParam('station', '');
+
+        if ($station != '') {
+            $station = new MongoId($station);
+            $date_end = strtotime(date('Y-m-d', strtotime('+1 day', time())));
+            $date_start = strtotime(date('Y-m-d', strtotime('-6 day', time())));
+
+            $data = $this->getDataByStation($date_start, $date_end, $station);
+            $data_str = $this->getDataStr($data);
+
+            $criteria_station = new EMongoCriteria();
+            $criteria_station->_id('==', $station);
+            $cursor = Station::model()->find($criteria_station);
+            $stationName = $cursor->name;
+
+            $date_arr = $this->getDateArr($date_start, $date_end);
+            $date_str = $this->getTimeStr($date_arr);
+
+            $date_range = date('Y-m-d', $date_start).'至'.date('Y-m-d', strtotime('-1 day', $date_end));
+        } else {
+            $date_range = '';
+            $date_str = '';
+            $data_str = array('price_count'=>'', 'operate_count'=>'');
+            $station = '';
+            $stationName = '';
+        }
+
+        $station_data = $this->getStationComboboxData();
+
+        $this->render('index', array(
+            'date_range'    => $date_range,
+            'date_str'      => $date_str,
+            'price_count'   => $data_str['price_count'],
+            'operate_count' => $data_str['operate_count'],
+            'station'       => (string)$station,
+            'stationName'   => $stationName,
+            'station_data'  => $station_data
+        ));
+    }
+
+    /**
+     * 显示所有服务点在时间范围内的领取情况
+     * @param string date_start | 开始的时间
+     * @param string date_end   | 结束的时间
+     * @param string date_range | 时间范围,用于前端显示
+     * @param array  data       | 时间范围内服务点、总价统计、操作统计
+     */
+    public function actionAll () {
+        $date_start = Yii::app()->request->getParam('date_start', '');
+        $date_end = Yii::app()->request->getParam('date_end', '');
+        // 默认查询当天数据
+        if (empty($date_start) || empty($date_end)) {
+            $date_range = date('Y-m-d', time());
+            $date_start = strtotime(date('Y-m-d', time()));
+            $date_end = strtotime('+1 day', $date_start);
+        } else {
+            $date_range = $date_start == $date_end ? $date_start : $date_start.'至'.$date_end;
+            $date_start = strtotime($date_start);
+            $date_end = strtotime('+1 day', strtotime($date_end));
+        }
+
+        $data = $this->getAll($date_start, $date_end);
+        $data = $data['data'];
+
+        $price_count_arr = array();
+        $stationName_str = '';
+        foreach ($data as $key => $value) {
+            $stationName_str .= '"'.$value['stationName'].'",';
+            $price_count_arr[$value['stationName']] = $value['price_count'];
+        }
+        $stationName_str = substr($stationName_str, 0, mb_strlen($stationName_str)-1);
+
+        $station_data = $this->getStationComboboxData();
+
+        $this->render('all', array(
+            'date_start'      => $date_start,
+            'date_end'        => $date_end,
+            'date_range'      => $date_range,
+            'stationNames'    => $stationName_str,
+            'price_count_arr' => $price_count_arr,
+            'station'         => '',
+            'station_data'    => $station_data
+        ));
+    }
+
+    /**
+     * 左边列表显示
+     */
+    public function actionList () {
+        $merge_data_days = Yii::app()->request->getParam('merge_data_days', false);
+        $merge_data_weeks = Yii::app()->request->getParam('merge_data_weeks', false);
+        $merge_data_months = Yii::app()->request->getParam('merge_data_months', false);
+
+        $stationName = Yii::app()->request->getParam('stationName', '');
+        $date_start = Yii::app()->request->getParam('date_start', '');
+        $date_end = Yii::app()->request->getParam('date_end', '');
+
+        // 时间为空则查询所有数据
+        if (!empty($date_start) && !empty($date_end)) {
+            $date_start = strtotime($date_start);
+            $date_end = strtotime('+1 day', strtotime($date_end));
+        }
+
+        $data = $this->getAll($date_start, $date_end, $stationName, true, $merge_data_days, $merge_data_weeks, $merge_data_months);
+        $total = $data['total'];
+        $data = $data['data'];
+
+        echo CommonFn::composeDatagridData($data, $total);
+    }
+
+    /**
+     * 根据服务点ID查询本月领取情况
+     */
+    public function actionFindByWeeks () {
+        $station = Yii::app()->request->getParam('station', '');
+        // 默认日期已设,二次开发已预留根据时间调整范围的代码
+        $date_end = strtotime('monday', time());
+        if (strtotime(date('Y-m-d', time())) == $date_end) {
+            $date_end = strtotime('+7 day', $date_end);
+        }
+        $date_start = strtotime('-35 day', $date_end);
+
+        if ($station != '') {
+            $station = new MongoId($station);
+            $criteria_station = new EMongoCriteria();
+            $criteria_station->_id = $station;
+            $cursor = Station::model()->find($criteria_station);
+            $stationName = $cursor->name;
+
+            $week_arr = $this->getWeekArr($date_start, $date_end);
+            $week_str = $this->getTimeStr($week_arr);
+            $data_temp = $this->getDataByStation($date_start, $date_end, $station);
+            $data = $this->parseDataByWeeks($data_temp, $date_start, $date_end);
+            $data_str = $this->getDataStr($data);
+            $date_range = $month_range = date('Y-m-d', $date_start).'至'.date('Y-m-d', strtotime('-1 day', $date_end));
+        } else {
+            $date_range = '';
+            $week_str = '';
+            $data_str = array('price_count'=>'', 'operate_count'=>'');
+            $station = '';
+            $stationName = '';
+        }
+
+        $station_data = $this->getStationComboboxData();
+
+        $this->render('findByWeeks', array(
+            'date_range'   => $date_range,
+            'weeks'        => $week_str,
+            'price'        => $data_str['price_count'],
+            'operate'      => $data_str['operate_count'],
+            'station'      => (string)$station,
+            'stationName'  => $stationName,
+            'station_data' => $station_data
+        ));
+    }
+
+    /**
+     * 根据用户ID及月份范围查询领取情况
+     */
+    public function actionFindByMonths () {
+        $station = Yii::app()->request->getParam('station', '');
+        $date_end = strtotime(date('Y-m', strtotime('+1 month', time())));
+        $date_start = strtotime(date('Y-m', strtotime('-5 month', time())));
+
+        if ($station != '') {
+            $data_temp = $this->getDataByStation($date_start, $date_end, $station);
+            $data = $this->parseDataByMonths($data_temp, $date_start, $date_end, $station);
+
+            $station = new MongoId($station);
+            $criteria_station = new EMongoCriteria();
+            $criteria_station->_id = $station;
+            $cursor = Station::model()->find($criteria_station);
+            $stationName = $cursor->name;
+
+            $data_str = $this->getDataStr($data);
+            $month_arr = $this->getMonthArr($date_start, $date_end);
+            $month_str = $this->getTimeStr($month_arr);
+            
+            $month_range = date('Y-m', $date_start).'至'.date('Y-m', strtotime('-1 month', $date_end));
+        } else {
+            $month_range = '';
+            $month_str = '';
+            $data_str = array('price_count'=>'', 'operate_count'=>'');
+            $station = '';
+            $stationName = '';
+        }
+
+        $station_data = $this->getStationComboboxData();
+
+        $this->render('findByMonths', array(
+            'month_range'  => $month_range,
+            'month'        => $month_str,
+            'price'        => $data_str['price_count'],
+            'operate'      => $data_str['operate_count'],
+            'station'      => (string)$station,
+            'stationName'  => $stationName,
+            'station_data' => $station_data
+        ));
+    }
+
+
+    /**
+     * ----------------------------------
+     *
+     *      私有方法,对数据进行整理
+     * 
+     * ----------------------------------
+     */
+
+    /**
+     * 获取所有数据的统计
+     * @param  boolean $empty_data        : 查询的stock结果为空时是否记录
+     * @param  boolean $merge_data_days   : 是否在结果中记录时间范围内(按照天)的单服务点数据
+     * @param  boolean $merge_data_weeks  : 是否在结果中记录时间范围内(按照周)的单服务点数据
+     * @param  boolean $merge_data_months : 是否在结果中记录时间范围内(按照月)的单服务点数据
+     */
+    private function getAll($date_start = '', $date_end = '', $stationName = '', $empty_data = false, $merge_data_days = false, $merge_data_weeks = false, $merge_data_months = false) {
+        $params = CommonFn::getPageParams();
+
+        $data = array();
+        $criteria_station = new EMongoCriteria($params);
+
+        $criteria_station->name = new MongoRegex('/'.$stationName.'/');
+        $cursor = Station::model()->findAll($criteria_station);
+        $total = count($cursor);
+        $stations = CommonFn::getRowsFromCursor($cursor);
+
+        if (empty($stations)) {
+            return $data;
+        }
+
+        foreach ($stations as $key => $value) {
+            $criteria_stock = new EMongoCriteria();
+            $criteria_stock->station = $value['_id'];
+            // 时间为空则查询所有数据
+            if (!empty($date_start) && !empty($date_end)) {
+                $criteria_stock->time('>=', intval($date_start));
+                $criteria_stock->time('<', intval($date_end));
+            }
+            $criteria_stock->sort('time', EMongoCriteria::SORT_ASC);
+
+            $cursor = Stock::model()->findAll($criteria_stock);
+            $stock = CommonFn::getRowsFromCursor($cursor);
+
+            // 若查询数据为空则continue
+            if (empty($stock)) {
+                // 若$empty_data 及$merge_data_days 为真,则加入空数据(针对列表及默认柱状图)
+                if ($empty_data) {
+                    $data_temp = array(
+                        'price_count' => 0,
+                        'operate_count' => 0,
+                        'station' => (string)$value['_id'],
+                        'stationName' => $value['name'],
+                    );
+
+                    // 按照每天整合数据
+                    if ($merge_data_days) {
+                        $date_range = date('Y-m-d', $date_start);
+                        $date_range .= '至'.date('Y-m-d', strtotime('-1 day', $date_end));
+
+                        $date_arr = $this->getDateArr($date_start, $date_end);
+                        $price_count_arr = array();
+                        $operate_count_arr = array();
+                        foreach ($date_arr as $k => $v) {
+                            array_push($price_count_arr, 0);
+                            array_push($operate_count_arr, 0);
+                        }
+
+                        $data_temp['data']['date_range'] = $date_range;
+                        $data_temp['data']['price_count'] = $price_count_arr;
+                        $data_temp['data']['operate_count'] = $operate_count_arr;
+                        $data_temp['data']['date_arr'] = $date_arr;
+                    // 按照每周整合数据
+                    } else if ($merge_data_weeks) {
+                        $date_end = strtotime('monday', time());
+                        if (strtotime(date('Y-m-d', time())) == $date_end) {
+                            $date_end = strtotime('+7 day', $date_end);
+                        }
+                        $date_start = strtotime('-35 day', $date_end);
+                        $date_range = $date_range = $month_range = date('Y-m-d', $date_start).'至'.date('Y-m-d', strtotime('-1 day', $date_end));
+
+                        $week_str = $this->getWeekArr($date_start, $date_end);
+                        $price_count_arr = array();
+                        $operate_count_arr = array();
+                        foreach ($week_arr as $k => $v) {
+                            array_push($price_count_arr, 0);
+                            array_push($operate_count_arr, 0);
+                        }
+
+                        $data_temp['data']['price_count'] = $price_count_arr;
+                        $data_temp['data']['operate_count'] = $operate_count_arr;
+                        $data_temp['data']['week_arr'] = $week_arr;
+                        $data_temp['data']['date_range'] = $date_range;
+                    // 按照每月整合数据
+                    } else if ($merge_data_months) {
+                        $date_end = strtotime(date('Y-m', strtotime('+1 month', time())));
+                        $date_start = strtotime(date('Y-m', strtotime('-5 month', time())));
+                        $month_range = date('Y-m', $date_start).'至'.date(date('Y-m', strtotime('-1 month', $date_end)));
+
+                        $month_arr = $this->getMonthArr($date_start, $date_end);
+                        $price_count_arr = array();
+                        $operate_count_arr = array();
+                        foreach ($month_arr as $k => $v) {
+                            array_push($price_count_arr, 0);
+                            array_push($operate_count_arr, 0);
+                        }
+
+                        $data_temp['data']['price_count'] = $price_count_arr;
+                        $data_temp['data']['operate_count'] = $operate_count_arr;
+                        $data_temp['data']['month_arr'] = $month_arr;
+                        $data_temp['data']['month_range'] = $month_range;
+                    }
+
+                    $data[] = $data_temp;
+                }
+                
+                continue;
+            }
+
+            $data_temp = array();
+            $data_temp['price_count'] = 0;
+            $data_temp['operate_count'] = 0;
+            foreach ($stock as $k => $v) {
+                $data_temp['price_count'] += $v['tot_price'];
+                $data_temp['operate_count']++;
+            }
+            $data_temp['station'] = (string)$value['_id'];
+            $data_temp['stationName'] = $value['name'];
+
+            // 判断并加入每个服务点时间范围内的统计情况(按照天)
+            if ($merge_data_days) {
+                $date_range = date('Y-m-d', $date_start);
+                $date_range .= '至'.date('Y-m-d', strtotime('-1 day', $date_end));
+
+                $data_station_temp_days = $this->parseDataByDays($stock, $date_start, $date_end);
+
+                $date_arr = $this->getDateArr($date_start, $date_end);
+
+                $data_temp['data']['date_range'] = $date_range;
+                
+                $price_count_arr = array();
+                $operate_count_arr = array();
+                foreach ($data_station_temp_days as $key => $value) {
+                    array_push($price_count_arr, $value['price_count']);
+                    array_push($operate_count_arr, $value['operate_count']);
+                }
+
+                $data_temp['data']['price_count'] = $price_count_arr;
+                $data_temp['data']['operate_count'] = $operate_count_arr;
+                $data_temp['data']['date_arr'] = $date_arr;
+            } else if ($merge_data_weeks) {
+                // 默认查询近一个月数据
+                $date_end = strtotime('monday', time());
+                if (strtotime(date('Y-m-d', time())) == $date_end) {
+                    $date_end = strtotime('+7 day', $date_end);
+                }
+                $date_start = strtotime('-35 day', $date_end);
+                $date_range = $date_range = $month_range = date('Y-m-d', $date_start).'至'.date('Y-m-d', strtotime('-1 day', $date_end));
+
+                $data_station_temp = $this->parseDataByDays($stock, $date_start, $date_end);
+                $data_station_temp_weeks = $this->parseDataByWeeks($data_station_temp, $date_start, $date_end);
+
+                $week_arr = $this->getWeekArr($date_start, $date_end);
+
+                $price_count_arr = array();
+                $operate_count_arr = array();
+                foreach ($data_station_temp_weeks as $key => $value) {
+                    array_push($price_count_arr, $value['price_count']);
+                    array_push($operate_count_arr, $value['operate_count']);
+                }
+
+                $data_temp['data']['price_count'] = $price_count_arr;
+                $data_temp['data']['operate_count'] = $operate_count_arr;
+                $data_temp['data']['week_arr'] = $week_arr;
+                $data_temp['data']['date_range'] = $date_range;
+            // 判断并加入每个服务点时间范围内的统计情况(按照月)
+            } else if ($merge_data_months) {
+                // 默认查询最近半年数据
+                $date_end = strtotime(date('Y-m', strtotime('+1 month', time())));
+                $date_start = strtotime(date('Y-m', strtotime('-5 month', time())));
+                $month_range = date('Y-m', $date_start).'至'.date(date('Y-m', strtotime('-1 month', $date_end)));
+
+                $data_station_temp = $this->parseDataByDays($stock, $date_start, $date_end);
+                $data_station_temp_months = $this->parseDataByMonths($data_station_temp, $date_start, $date_end);
+
+                $month_arr = $this->getMonthArr($date_start, $date_end);
+
+                $price_count_arr = array();
+                $operate_count_arr = array();
+                foreach ($data_station_temp_months as $key => $value) {
+                    array_push($price_count_arr, $value['price_count']);
+                    array_push($operate_count_arr, $value['operate_count']);
+                }
+
+                $data_temp['data']['price_count'] = $price_count_arr;
+                $data_temp['data']['operate_count'] = $operate_count_arr;
+                $data_temp['data']['month_arr'] = $month_arr;
+                $data_temp['data']['month_range'] = $month_range;
+            }
+            
+
+            $data[] = $data_temp;
+        }
+
+        $data = array('data' => $data, 'total' => $total);
+
+        return $data;
+    }
+
+    /**
+     * 获取单服务点时间范围内所有数据(Y轴数据)
+     * 按照日期归类
+     * @param timestamp $date_start  : 开始时间
+     * @param timestamp $date_end    : 结束时间
+     * @param MongoID   $station     : 服务点ID
+     */
+    private function getDataByStation ($date_start, $date_end, $station) {
+        $data = array();
+        $date_index = $date_start;
+
+        $criteria = new EMongoCriteria();
+        $criteria->time('>=', $date_start);
+        $criteria->time('<', $date_end);
+        $criteria->station('==', $station);
+        $criteria->sort('time', EMongoCriteria::SORT_ASC);
+
+        $cursor = Stock::model()->findAll($criteria);
+        $rows = CommonFn::getRowsFromCursor($cursor);
+
+        $rows_count = count($rows);
+        $rows_index = 0;
+        while ($date_index < $date_end) {
+            $data_temp = array(
+                'date' => $date_index,
+                'price_count' => 0,
+                'operate_count'=> 0
+            );
+            while ($rows_index < $rows_count) {
+                if ($date_index <= $rows[$rows_index]['time'] && 
+                    $rows[$rows_index]['time'] < strtotime('+1 day', $date_index)) {
+                    $data_temp['price_count'] += $rows[$rows_index]['tot_price'];
+                    $data_temp['operate_count']++;
+                } else {
+                    break;
+                }
+
+                $rows_index++;
+            }
+
+            $data[] = $data_temp;
+            $date_index = strtotime('+1 day', $date_index);
+        }
+
+        return $data;
+    }
+
+    /**
+     * 根据查询Stock表获得的Rows整理数据,按照每天分类
+     * 减少与Mongo的交互,提高性能
+     * @param  array     $rows       : 从Stock表查询的单服务点数据
+     * @param  timestamp $date_start : 开始的时间
+     * @param  timestamp $date_end   : 结束的时间
+     * @return array     $data       : 返回的数据
+     */
+    private function parseDataByDays ($rows, $date_start, $date_end) {
+        $date_index = $date_start;
+        $rows_count = count($rows);
+        $rows_index = 0;
+
+        while ($date_index < $date_end) {
+            $data_temp = array(
+                'date' => $date_index,
+                'price_count' => 0,
+                'operate_count'=> 0
+            );
+
+            while ($rows_index < $rows_count) {
+                if ($date_index <= $rows[$rows_index]['time'] && 
+                    $rows[$rows_index]['time'] < strtotime('+1 day', $date_index)) {
+                    $data_temp['price_count'] += $rows[$rows_index]['tot_price'];
+                    $data_temp['operate_count']++;
+                } else {
+                    break;
+                }
+
+                $rows_index++;
+            }
+
+            $data[] = $data_temp;
+            $date_index = strtotime('+1 day', $date_index);
+        }
+
+        return $data;
+    }
+
+    /**
+     * 按照每周整理单服务点数据
+     */
+    private function parseDataByWeeks ($rows='', $date_start, $date_end, $station='') {
+        if (empty($rows) && $station != '') {
+            $station = new MongoId($station);
+            $rows = $this->getDataByStation($date_start, $date_end, $station);
+        }
+
+        $range = ($date_end - $date_start)/3600/24/7;
+        $data = array();
+
+        $rows_index = 0;
+        $day_count = 1;
+        for ($data_index=0; $data_index < $range; $data_index++) {
+            $data_temp = array(
+                'price_count' => 0,
+                'operate_count' => 0,
+            );
+
+            while ($day_count%8 != 0) {
+                $data_temp['price_count'] += $rows[$rows_index]['price_count'];
+                $data_temp['operate_count'] += $rows[$rows_index]['operate_count'];
+                $rows_index++;
+                $day_count++;
+            }
+
+            $data[] = $data_temp;
+            $day_count = 1;
+        }
+
+        return $data;
+    }
+
+    /**
+     * 按照月份整理单用户数据
+     * @param $date_start timestamp : 开始时间
+     * @param $date_end   timestamp : 结束时间
+     * @param $station    MongoID   : 服务点ID
+     */
+    private function parseDataByMonths ($rows='', $date_start, $date_end, $station='') {
+        if (empty($rows) && $station != '') {
+            $station = new MongoId($station);
+            $rows = $this->getDataByStation($date_start, $date_end, $station);
+        }
+
+        $range = intval(date('m', $date_end)) - intval(date('m', $date_start));
+        $num_of_days = array();
+        for ($i=0; $i<$range; $i++) {
+            $num_of_days[$i] = (strtotime('+'.($i+1).' month', $date_start) - strtotime('+'.$i.' month', $date_start))/3600/24;
+        }
+
+        $data = array();
+        $data_index = 0;
+        $day_count = 0;
+        foreach ($num_of_days as $key => $value) {
+            $day_count += $value;
+            $data_temp = array(
+                'price_count' => 0,
+                'operate_count' => 0
+            );
+
+            while ($data_index < $day_count) {
+                $data_temp['price_count'] += $rows[$data_index]['price_count'];
+                $data_temp['operate_count'] += $rows[$data_index]['operate_count'];
+                $data_index++;
+            }
+
+            $data[] = $data_temp;
+        }
+
+        return $data;
+    }
+
+    /**
+     * 将数据转换为字符串
+     * @param $data array : 需要转换为字符串的数据
+     */
+    private function getDataStr ($data) {
+        $data_str = array(
+            'price_count' => '',
+            'operate_count' => ''
+        );
+
+        $price_count = '';
+        $operate_count = '';
+
+        foreach ($data as $key => $value) {
+            $price_count .= '"'.$value['price_count'].'",';
+            $operate_count .= '"'.$value['operate_count'].'",';
+        }
+
+        $price_count = substr($price_count, 0, strlen($price_count)-1);
+        $operate_count = substr($operate_count, 0, strlen($operate_count)-1);
+        $data_str['price_count'] = $price_count;
+        $data_str['operate_count'] = $operate_count;
+
+        return $data_str;
+    }
+
+    /**
+     * 将时间范围数组转换为字符串
+     * @param  array  $data     : 待转换数据
+     * @return string $data_str : 转换后数据
+     */
+    private function getTimeStr ($data) {
+        $data_str = '';
+        foreach ($data as $key => $value) {
+            $data_str .= '"'.$value.'",';
+        }
+        $data_str = substr($data_str, 0, strlen($data_str)-1);
+
+        return $data_str;
+    }
+
+    /**
+     * 获取日期数组
+     */
+    private function getDateArr ($date_start, $date_end) {
+        $date_arr = array();
+        $date_index = $date_start;
+        while ($date_index < $date_end) {
+            $date_arr[] = date('m-d', $date_index);
+            $date_index = strtotime('+1 day', $date_index);
+        }
+
+        return $date_arr;
+    }
+
+    /**
+     * 获取周数组
+     */
+    private function getWeekArr ($date_start, $date_end) {
+        $week_arr = array();
+        $date_index = $date_start;
+        do {
+            $week_temp = date('m-d', $date_index);
+            $date_index = strtotime('+7 day', $date_index);
+            $week_temp .= '至'.date('m-d', strtotime('-1 day', $date_index));
+
+            $week_arr[] = $week_temp;
+        } while ($date_index < $date_end);
+
+        return $week_arr;
+    }
+
+    /**
+     * 获取月份数组
+     */
+    private function getMonthArr ($date_start, $date_end) {
+        $month_arr = array();
+        $date_index = $date_start;
+        while ($date_index < $date_end) {
+            $month_arr[] = intval(date('m', $date_index)).'月';
+            $date_index = strtotime('+1 month', $date_index);
+        }
+
+        return $month_arr;
+    }
+
+    /**
+     * 获取station的combobox数据
+     */
+    private function getStationComboboxData () {
+        $criteria = new EMongoCriteria();
+        $cursor = Station::model()->findAll($criteria);
+        $rows = CommonFn::getRowsFromCursor($cursor);
+        $parsedRows = Station::model()->parse($rows);
+        $station_data = array();
+        foreach ($parsedRows as $key => $v) {
+            $station_data = array_merge($station_data, array($v['name'] => array('name' => $v['name'])));
+        }
+
+        $station = CommonFn::getComboboxData($station_data, '全部', true, '');
+
+        return $station;
+    }
+}
+?>

+ 659 - 0
www/protected/controllers/StockViewUserController.php

@@ -0,0 +1,659 @@
+<?php 
+/**
+ * 库存操作统计控制器(根据用户)
+ * @author zhouxuchen 2015-09-29
+ */
+class StockViewUserController extends AdminController {
+
+    /**
+     * 首页acion
+     * 默认显示本周内数据统计及图表
+     */
+    public function actionIndex () {
+        $object = intval(Yii::app()->request->getParam('object', 0));
+
+        if ($object != 0) {
+            $date_end = strtotime(date('Y-m-d', strtotime('+1 day', time())));
+            $date_start = strtotime(date('Y-m-d', strtotime('-6 day', time())));
+
+            $data = $this->getDataByUser($date_start, $date_end, $object);
+            $data_str = $this->getDataStr($data);
+
+            $criteria_user = new EMongoCriteria();
+            $criteria_user->_id('==', $object);
+            $cursor = User::model()->find($criteria_user);
+            $objectName = $cursor->name;
+
+            $date_arr = $this->getDateArr($date_start, $date_end);
+            $date_str = $this->getTimeStr($date_arr);
+
+            $date_range = date('Y-m-d', $date_start).'至'.date('Y-m-d', strtotime('-1 day', $date_end));
+        } else {
+            $date_range = '';
+            $date_str = '';
+            $data_str = array('price_count'=>'', 'operate_count'=>'');
+            $object = 0;
+            $objectName = '';
+        }
+
+        $this->render('index', array(
+            'date_range'    => $date_range,
+            'date_str'      => $date_str,
+            'price_count'   => $data_str['price_count'],
+            'operate_count' => $data_str['operate_count'],
+            'object'        => $object,
+            'objectName'    => $objectName
+        ));
+    }
+
+    /**
+     * 显示所有用户在时间范围内的领取情况
+     * @param string date_start | 开始的时间
+     * @param string date_end   | 结束的时间
+     * @param string date_range | 时间范围,用于前端显示
+     * @param array  data       | 时间范围内用户名、总价统计、操作统计
+     */
+    public function actionAll () {
+        $date_start = Yii::app()->request->getParam('date_start', '');
+        $date_end = Yii::app()->request->getParam('date_end', '');
+        // 默认查询当天数据
+        if (empty($date_start) || empty($date_end)) {
+            $date_range = date('Y-m-d', time());
+            $date_start = strtotime(date('Y-m-d', time()));
+            $date_end = strtotime('+1 day', $date_start);
+        } else {
+            $date_range = $date_start == $date_end ? $date_start : $date_start.'至'.$date_end;
+            $date_start = strtotime($date_start);
+            $date_end = strtotime('+1 day', strtotime($date_end));
+        }
+
+        $data = $this->getAll($date_start, $date_end);
+        $data = $data['data'];
+
+        $price_count_arr = array();
+        $objectName_str = '';
+        foreach ($data as $key => $value) {
+            $objectName_str .= '"'.$value['objectName'].'",';
+            $price_count_arr[$value['objectName']] = $value['price_count'];
+        }
+        $objectName_str = substr($objectName_str, 0, mb_strlen($objectName_str)-1);
+
+        $this->render('all', array(
+            'date_start'      => $date_start,
+            'date_end'        => $date_end,
+            'date_range'      => $date_range,
+            'objectNames'     => $objectName_str,
+            'price_count_arr' => $price_count_arr,
+            'object'          => ''
+        ));
+    }
+
+    /**
+     * 左边列表显示
+     * @param criteria_stockViewUser : criteria for StockViewUser
+     * @param criteria_users         : criteria for User
+     */
+    public function actionList () {
+        $merge_data_days = Yii::app()->request->getParam('merge_data_days', false);
+        $merge_data_weeks = Yii::app()->request->getParam('merge_data_weeks', false);
+        $merge_data_months = Yii::app()->request->getParam('merge_data_months', false);
+
+        $objectName = Yii::app()->request->getParam('s_user', '');
+        $date_start = Yii::app()->request->getParam('date_start', '');
+        $date_end = Yii::app()->request->getParam('date_end', '');
+
+        // 时间为空则查询所有数据
+        if (!empty($date_start) && !empty($date_end)) {
+            $date_start = strtotime($date_start);
+            $date_end = strtotime('+1 day', strtotime($date_end));
+        }
+
+        $data = $this->getAll($date_start, $date_end, $objectName, true, $merge_data_days, $merge_data_weeks, $merge_data_months);
+        $total = $data['total'];
+        $data = $data['data'];
+        echo CommonFn::composeDatagridData($data, $total);
+    }
+
+    /**
+     * 根据用户ID查询本月领取情况
+     */
+    public function actionFindByWeeks () {
+        $object = intval(Yii::app()->request->getParam('object', 0));
+        // 默认日期已设,二次开发已预留根据时间调整范围的代码
+        $date_end = strtotime('monday', time());
+        if (strtotime(date('Y-m-d', time())) == $date_end) {
+            $date_end = strtotime('+7 day', $date_end);
+        }
+        $date_start = strtotime('-35 day', $date_end);
+
+        if ($object != 0) {
+            $criteria_user = new EMongoCriteria();
+            $criteria_user->_id = $object;
+            $cursor = User::model()->find($criteria_user);
+            $objectName = $cursor->name;
+
+            $week_arr = $this->getWeekArr($date_start, $date_end);
+            $week_str = $this->getTimeStr($week_arr);
+            $data_temp = $this->getDataByUser($date_start, $date_end, $object);
+            $data = $this->parseDataByWeeks($data_temp, $date_start, $date_end);
+            $data_str = $this->getDataStr($data);
+            $date_range = $month_range = date('Y-m-d', $date_start).'至'.date('Y-m-d', strtotime('-1 day', $date_end));
+        } else {
+            $date_range = '';
+            $week_str = '';
+            $data_str = array('price_count'=>'', 'operate_count'=>'');
+            $object = 0;
+            $objectName = '';
+        }
+
+        $this->render('findByWeeks', array(
+            'date_range' => $date_range,
+            'weeks'      => $week_str,
+            'price'      => $data_str['price_count'],
+            'operate'    => $data_str['operate_count'],
+            'object'     => $object,
+            'objectName' => $objectName
+        ));
+    }
+
+    /**
+     * 根据用户ID及月份范围查询领取情况
+     */
+    public function actionFindByMonths () {
+        $object = intval(Yii::app()->request->getParam('object', 0));
+        $date_end = strtotime(date('Y-m', strtotime('+1 month', time())));
+        $date_start = strtotime(date('Y-m', strtotime('-5 month', time())));
+
+        if ($object != 0) {
+            $data_temp = $this->getDataByUser($date_start, $date_end, $object);
+            $data = $this->parseDataByMonths($data_temp, $date_start, $date_end, $object);
+
+            $criteria_user = new EMongoCriteria();
+            $criteria_user->_id = $object;
+            $cursor = User::model()->find($criteria_user);
+            $objectName = $cursor->name;
+
+            $data_str = $this->getDataStr($data);
+            $month_arr = $this->getMonthArr($date_start, $date_end);
+            $month_str = $this->getTimeStr($month_arr);
+            
+            $month_range = date('Y-m', $date_start).'至'.date('Y-m', strtotime('-1 month', $date_end));
+        } else {
+            $month_range = '';
+            $month_str = '';
+            $data_str = array('price_count'=>'', 'operate_count'=>'');
+            $object = 0;
+            $objectName = '';
+        }
+
+        $this->render('findByMonths', array(
+            'month_range' => $month_range,
+            'month' => $month_str,
+            'price' => $data_str['price_count'],
+            'operate' => $data_str['operate_count'],
+            'object' => $object,
+            'objectName' => $objectName
+        ));
+    }
+
+    /**
+     * ----------------------------------
+     *
+     *      私有方法,对数据进行整理
+     * 
+     * ----------------------------------
+     */
+
+    /**
+     * 获取所有数据的统计
+     * @param  boolean $empty_data        : 查询的stock结果为空时是否记录
+     * @param  boolean $merge_data_days   : 是否在结果中记录时间范围内(按照天)的单用户数据
+     * @param  boolean $merge_data_weeks  : 是否在结果中记录时间范围内(按照周)的单用户数据
+     * @param  boolean $merge_data_months : 是否在结果中记录时间范围内(按照月)的单用户数据
+     */
+    private function getAll($date_start = '', $date_end = '', $objectName = '', $empty_data = false, $merge_data_days = false, $merge_data_weeks = false, $merge_data_months = false) {
+        $params = CommonFn::getPageParams();
+
+        $data = array();
+        $criteria_users = new EMongoCriteria($params);
+
+        // 筛选为技师
+        $MongoDbAuthManager = new CMongoDbAuthManager();
+        $users_id = $MongoDbAuthManager->getAuthUser('技师');
+
+        $criteria_users->name = new MongoRegex('/'.$objectName.'/');
+        $criteria_users->_id('in', $users_id);
+
+        $cursor = User::model()->findAll($criteria_users);
+        $total = count($cursor);
+        $users = CommonFn::getRowsFromCursor($cursor);
+
+        if (empty($users)) {
+            $data = array('total' => 0, 'data' => array());
+            return $data;
+        }
+
+        foreach ($users as $key => $value) {
+            $criteria_stock = new EMongoCriteria();
+            $criteria_stock->object = $value['_id'];
+            // 时间为空则查询所有数据
+            if (!empty($date_start) && !empty($date_end)) {
+                $criteria_stock->time('>=', intval($date_start));
+                $criteria_stock->time('<', intval($date_end));
+            }
+            $criteria_stock->sort('time', EMongoCriteria::SORT_ASC);
+
+            $cursor = Stock::model()->findAll($criteria_stock);
+            $stock = CommonFn::getRowsFromCursor($cursor);
+
+            // 若查询数据为空则continue
+            if (empty($stock)) {
+                // 若$empty_data 及$merge_data_days 为真,则加入空数据(针对列表及默认柱状图)
+                if ($empty_data) {
+                    $data_temp = array(
+                        'price_count' => 0,
+                        'operate_count' => 0,
+                        'object' => $value['_id'],
+                        'objectName' => $value['name'],
+                    );
+
+                    // 按照每天整合数据
+                    if ($merge_data_days) {
+                        $date_range = date('Y-m-d', $date_start);
+                        $date_range .= '至'.date('Y-m-d', strtotime('-1 day', $date_end));
+
+                        $date_arr = $this->getDateArr($date_start, $date_end);
+                        $price_count_arr = array();
+                        $operate_count_arr = array();
+                        foreach ($date_arr as $k => $v) {
+                            array_push($price_count_arr, 0);
+                            array_push($operate_count_arr, 0);
+                        }
+
+                        $data_temp['data']['date_range'] = $date_range;
+                        $data_temp['data']['price_count'] = $price_count_arr;
+                        $data_temp['data']['operate_count'] = $operate_count_arr;
+                        $data_temp['data']['date_arr'] = $date_arr;
+                    // 按照每周整合数据
+                    } else if ($merge_data_weeks) {
+                        $date_end = strtotime('monday', time());
+                        if (strtotime(date('Y-m-d', time())) == $date_end) {
+                            $date_end = strtotime('+7 day', $date_end);
+                        }
+                        $date_start = strtotime('-35 day', $date_end);
+                        $date_range = $date_range = $month_range = date('Y-m-d', $date_start).'至'.date('Y-m-d', strtotime('-1 day', $date_end));
+
+                        $week_str = $this->getWeekArr($date_start, $date_end);
+                        $price_count_arr = array();
+                        $operate_count_arr = array();
+                        foreach ($week_arr as $k => $v) {
+                            array_push($price_count_arr, 0);
+                            array_push($operate_count_arr, 0);
+                        }
+
+                        $data_temp['data']['price_count'] = $price_count_arr;
+                        $data_temp['data']['operate_count'] = $operate_count_arr;
+                        $data_temp['data']['week_arr'] = $week_arr;
+                        $data_temp['data']['date_range'] = $date_range;
+                    // 按照每月整合数据
+                    } else if ($merge_data_months) {
+                        $date_end = strtotime(date('Y-m', strtotime('+1 month', time())));
+                        $date_start = strtotime(date('Y-m', strtotime('-5 month', time())));
+                        $month_range = date('Y-m', $date_start).'至'.date(date('Y-m', strtotime('-1 month', $date_end)));
+
+                        $month_arr = $this->getMonthArr($date_start, $date_end);
+                        $price_count_arr = array();
+                        $operate_count_arr = array();
+                        foreach ($month_arr as $k => $v) {
+                            array_push($price_count_arr, 0);
+                            array_push($operate_count_arr, 0);
+                        }
+
+                        $data_temp['data']['price_count'] = $price_count_arr;
+                        $data_temp['data']['operate_count'] = $operate_count_arr;
+                        $data_temp['data']['month_arr'] = $month_arr;
+                        $data_temp['data']['month_range'] = $month_range;
+                    }
+
+                    $data[] = $data_temp;
+                }
+                
+                continue;
+            }
+
+            $data_temp = array();
+            $data_temp['price_count'] = 0;
+            $data_temp['operate_count'] = 0;
+            foreach ($stock as $k => $v) {
+                $data_temp['price_count'] += $v['tot_price'];
+                $data_temp['operate_count']++;
+            }
+            $data_temp['object'] = $value['_id'];
+            $data_temp['objectName'] = $value['name'];
+
+            // 判断并加入每个用户时间范围内的统计情况(按照天)
+            if ($merge_data_days) {
+                $date_range = date('Y-m-d', $date_start);
+                $date_range .= '至'.date('Y-m-d', strtotime('-1 day', $date_end));
+
+                $data_user_temp_days = $this->parseDataByDays($stock, $date_start, $date_end);
+
+                $date_arr = $this->getDateArr($date_start, $date_end);
+
+                $data_temp['data']['date_range'] = $date_range;
+                
+                $price_count_arr = array();
+                $operate_count_arr = array();
+                foreach ($data_user_temp_days as $key => $value) {
+                    array_push($price_count_arr, $value['price_count']);
+                    array_push($operate_count_arr, $value['operate_count']);
+                }
+
+                $data_temp['data']['price_count'] = $price_count_arr;
+                $data_temp['data']['operate_count'] = $operate_count_arr;
+                $data_temp['data']['date_arr'] = $date_arr;
+            } else if ($merge_data_weeks) {
+                // 默认查询近一个月数据
+                $date_end = strtotime('monday', time());
+                if (strtotime(date('Y-m-d', time())) == $date_end) {
+                    $date_end = strtotime('+7 day', $date_end);
+                }
+                $date_start = strtotime('-35 day', $date_end);
+                $date_range = $date_range = $month_range = date('Y-m-d', $date_start).'至'.date('Y-m-d', strtotime('-1 day', $date_end));
+
+                $data_user_temp = $this->parseDataByDays($stock, $date_start, $date_end);
+                $data_user_temp_weeks = $this->parseDataByWeeks($data_user_temp, $date_start, $date_end);
+
+                $week_arr = $this->getWeekArr($date_start, $date_end);
+
+                $price_count_arr = array();
+                $operate_count_arr = array();
+                foreach ($data_user_temp_weeks as $key => $value) {
+                    array_push($price_count_arr, $value['price_count']);
+                    array_push($operate_count_arr, $value['operate_count']);
+                }
+
+                $data_temp['data']['price_count'] = $price_count_arr;
+                $data_temp['data']['operate_count'] = $operate_count_arr;
+                $data_temp['data']['week_arr'] = $week_arr;
+                $data_temp['data']['date_range'] = $date_range;
+            // 判断并加入每个用户时间范围内的统计情况(按照月)
+            } else if ($merge_data_months) {
+                // 默认查询最近半年数据
+                $date_end = strtotime(date('Y-m', strtotime('+1 month', time())));
+                $date_start = strtotime(date('Y-m', strtotime('-5 month', time())));
+                $month_range = date('Y-m', $date_start).'至'.date(date('Y-m', strtotime('-1 month', $date_end)));
+
+                $data_user_temp = $this->parseDataByDays($stock, $date_start, $date_end);
+                $data_user_temp_months = $this->parseDataByMonths($data_user_temp, $date_start, $date_end);
+
+                $month_arr = $this->getMonthArr($date_start, $date_end);
+
+                $price_count_arr = array();
+                $operate_count_arr = array();
+                foreach ($data_user_temp_months as $key => $value) {
+                    array_push($price_count_arr, $value['price_count']);
+                    array_push($operate_count_arr, $value['operate_count']);
+                }
+
+                $data_temp['data']['price_count'] = $price_count_arr;
+                $data_temp['data']['operate_count'] = $operate_count_arr;
+                $data_temp['data']['month_arr'] = $month_arr;
+                $data_temp['data']['month_range'] = $month_range;
+            }
+            
+
+            $data[] = $data_temp;
+        }
+
+        $data = array('data' => $data, 'total' => $total);
+
+        return $data;
+    }
+
+    /**
+     * 获取单用户时间范围内所有数据(Y轴数据)
+     * 按照日期归类
+     * @param timestamp $date_start : 开始时间
+     * @param timestamp $date_end   : 结束时间
+     * @param number    $object     : 用户ID
+     */
+    private function getDataByUser ($date_start, $date_end, $object) {
+        $data = array();
+        $date_index = $date_start;
+
+        $criteria = new EMongoCriteria();
+        $criteria->time('>=', $date_start);
+        $criteria->time('<', $date_end);
+        $criteria->object('==', $object);
+        $criteria->sort('time', EMongoCriteria::SORT_ASC);
+
+        $cursor = Stock::model()->findAll($criteria);
+        $rows = CommonFn::getRowsFromCursor($cursor);
+
+        $rows_count = count($rows);
+        $rows_index = 0;
+        while ($date_index < $date_end) {
+            $data_temp = array(
+                'date' => $date_index,
+                'price_count' => 0,
+                'operate_count'=> 0
+            );
+            while ($rows_index < $rows_count) {
+                if ($date_index <= $rows[$rows_index]['time'] && 
+                    $rows[$rows_index]['time'] < strtotime('+1 day', $date_index)) {
+                    $data_temp['price_count'] += $rows[$rows_index]['tot_price'];
+                    $data_temp['operate_count']++;
+                } else {
+                    break;
+                }
+
+                $rows_index++;
+            }
+
+            $data[] = $data_temp;
+            $date_index = strtotime('+1 day', $date_index);
+        }
+
+        return $data;
+    }
+
+    /**
+     * 根据查询Stock表获得的Rows整理数据,按照每天分类
+     * 减少与Mongo的交互,提高性能
+     * @param  array     $rows       : 从Stock表查询的单用户数据
+     * @param  timestamp $date_start : 开始的时间
+     * @param  timestamp $date_end   : 结束的时间
+     * @return array     $data       : 返回的数据
+     */
+    private function parseDataByDays ($rows, $date_start, $date_end) {
+        $date_index = $date_start;
+        $rows_count = count($rows);
+        $rows_index = 0;
+
+        while ($date_index < $date_end) {
+            $data_temp = array(
+                'date' => $date_index,
+                'price_count' => 0,
+                'operate_count'=> 0
+            );
+
+            while ($rows_index < $rows_count) {
+                if ($date_index <= $rows[$rows_index]['time'] && 
+                    $rows[$rows_index]['time'] < strtotime('+1 day', $date_index)) {
+                    $data_temp['price_count'] += $rows[$rows_index]['tot_price'];
+                    $data_temp['operate_count']++;
+                } else {
+                    break;
+                }
+
+                $rows_index++;
+            }
+
+            $data[] = $data_temp;
+            $date_index = strtotime('+1 day', $date_index);
+        }
+
+        return $data;
+    }
+
+    /**
+     * 按照每周整理单用户数据
+     */
+    private function parseDataByWeeks ($rows='', $date_start, $date_end, $object=0) {
+        if (empty($rows) && $object != 0) {
+            $rows = $this->getDataByUser($date_start, $date_end, $object);
+        }
+
+        $range = ($date_end - $date_start)/3600/24/7;
+        $data = array();
+
+        $rows_index = 0;
+        $day_count = 1;
+        for ($data_index=0; $data_index < $range; $data_index++) { 
+            $data_temp = array(
+                'price_count' => 0,
+                'operate_count' => 0,
+            );
+
+            while ($day_count%8 != 0) {
+                $data_temp['price_count'] += $rows[$rows_index]['price_count'];
+                $data_temp['operate_count'] += $rows[$rows_index]['operate_count'];
+                $rows_index++;
+                $day_count++;
+            }
+
+            $data[] = $data_temp;
+            $day_count = 1;
+        }
+
+        return $data;
+    }
+
+    /**
+     * 按照月份整理单用户数据
+     * @param $date_start timestamp : 开始时间
+     * @param $date_end   timestamp : 结束时间
+     * @param $object     number    : 用户ID
+     */
+    private function parseDataByMonths ($rows='', $date_start, $date_end, $object=0) {
+        if (empty($rows) && $object != 0) {
+            $rows = $this->getDataByUser($date_start, $date_end, $object);
+        }
+
+        $range = intval(date('m', $date_end)) - intval(date('m', $date_start));
+        $num_of_days = array();
+        for ($i=0; $i<$range; $i++) {
+            $num_of_days[$i] = (strtotime('+'.($i+1).' month', $date_start) - strtotime('+'.$i.' month', $date_start))/3600/24;
+        }
+
+        $data = array();
+        $data_index = 0;
+        $day_count = 0;
+        foreach ($num_of_days as $key => $value) {
+            $day_count += $value;
+            $data_temp = array(
+                'price_count' => 0,
+                'operate_count' => 0
+            );
+
+            while ($data_index < $day_count) {
+                $data_temp['price_count'] += $rows[$data_index]['price_count'];
+                $data_temp['operate_count'] += $rows[$data_index]['operate_count'];
+                $data_index++;
+            }
+
+            $data[] = $data_temp;
+        }
+
+        return $data;
+    }
+
+    /**
+     * 将数据转换为字符串
+     * @param $data array : 需要转换为字符串的数据
+     */
+    private function getDataStr ($data) {
+        $data_str = array(
+            'price_count' => '',
+            'operate_count' => ''
+        );
+
+        $price_count = '';
+        $operate_count = '';
+
+        foreach ($data as $key => $value) {
+            $price_count .= '"'.$value['price_count'].'",';
+            $operate_count .= '"'.$value['operate_count'].'",';
+        }
+
+        $price_count = substr($price_count, 0, strlen($price_count)-1);
+        $operate_count = substr($operate_count, 0, strlen($operate_count)-1);
+        $data_str['price_count'] = $price_count;
+        $data_str['operate_count'] = $operate_count;
+
+        return $data_str;
+    }
+
+    /**
+     * 将时间范围数组转换为字符串
+     * @param  array  $data     : 待转换数据
+     * @return string $data_str : 转换后数据
+     */
+    private function getTimeStr ($data) {
+        $data_str = '';
+        foreach ($data as $key => $value) {
+            $data_str .= '"'.$value.'",';
+        }
+        $data_str = substr($data_str, 0, strlen($data_str)-1);
+
+        return $data_str;
+    }
+
+    /**
+     * 获取日期数组
+     */
+    private function getDateArr ($date_start, $date_end) {
+        $date_arr = array();
+        $date_index = $date_start;
+        while ($date_index < $date_end) {
+            $date_arr[] = date('m-d', $date_index);
+            $date_index = strtotime('+1 day', $date_index);
+        }
+
+        return $date_arr;
+    }
+
+    /**
+     * 获取周数组
+     */
+    private function getWeekArr ($date_start, $date_end) {
+        $week_arr = array();
+        $date_index = $date_start;
+        do {
+            $week_temp = date('m-d', $date_index);
+            $date_index = strtotime('+7 day', $date_index);
+            $week_temp .= '至'.date('m-d', strtotime('-1 day', $date_index));
+
+            $week_arr[] = $week_temp;
+        } while ($date_index < $date_end);
+
+        return $week_arr;
+    }
+
+    /**
+     * 获取月份数组
+     */
+    private function getMonthArr ($date_start, $date_end) {
+        $month_arr = array();
+        $date_index = $date_start;
+        while ($date_index < $date_end) {
+            $month_arr[] = intval(date('m', $date_index)).'月';
+            $date_index = strtotime('+1 month', $date_index);
+        }
+
+        return $month_arr;
+    }
+
+}
+?>

+ 91 - 0
www/protected/modules/o2o/models/Material.php

@@ -0,0 +1,91 @@
+<?php 
+/**
+ * 物资
+ * @author zhouxuchen 2015-09-16
+ */
+class Material extends MongoAr {
+
+    public $_id;
+    public $name;           // 物资的名称
+    public $unit_str;       // 物资的单位(文字)
+    public $unit;           // 物资的单位
+    public $price;          // 物资的单价
+    public $stock;          // 物资的库存
+    public $stockWarnLine;  // 库存警戒线
+    public $addTime;        // 物资加入的时间
+    public $status;         // 物资的库存状态
+    public $status_str;     // 物资的库存状态(文字)
+    public $enable;         // 是否启用此物资
+    public $enable_str;     // 是否启用此物资
+    public $remarks;        // 该物资的备注
+
+    public static $status_option = array(
+        0 => array('name' => '无库存'),
+        1 => array('name' => '紧张'),
+        2 => array('name' => '充足'),
+        3 => array('name' => '未知')
+    );
+
+    public static $enable_option = array(
+        0 => array('name' => '停用'),
+        1 => array('name' => '启用')
+    );
+
+    public static $unit_option = array(
+        1 => array('name' => '瓶'),
+        2 => array('name' => '袋'),
+        3 => array('name' => '盒'),
+        4 => array('name' => '台'),
+        5 => array('name' => '件'),
+        6 => array('name' => '双')
+    );
+
+    public function __construct($scenario='insert') {
+        $this->setMongoDBComponent(Yii::app()->getComponent('mongodb_o2o'));
+        parent::__construct($scenario);
+    }
+
+    public static function model($className = __CLASS__) {
+        return parent::model($className);
+    }
+
+    public static function get($_id) {
+        if(CommonFn::isMongoId($_id)){
+            $criteria = new EMongoCriteria();
+            $criteria->_id('==', $_id);
+            $model = self::model()->find($criteria);
+            return $model;
+        }else{
+            return false;
+        }
+    }
+
+    public function getCollectionName () {
+        return 'material';
+    }
+
+    public function parseRow($row, $output = array()) {
+        $newRow = array();
+        $newRow['id'] = (string)$row['_id'];
+        $newRow['name'] = CommonFn::get_val_if_isset($row, 'name', '');
+        $newRow['unit_str'] = CommonFn::get_val_if_isset($row, 'unit_str', '');
+        $newRow['unit'] = CommonFn::get_val_if_isset($row, 'unit', 0);
+        $newRow['price'] = CommonFn::get_val_if_isset($row, 'price', 0.00);
+        $newRow['stock'] = CommonFn::get_val_if_isset($row, 'stock', 0);
+        $newRow['stockWarnLine'] = CommonFn::get_val_if_isset($row, 'stockWarnLine', 0);
+        $newRow['addTime'] = date('Y-m-d H:i', CommonFn::get_val_if_isset($row, 'addTime', 0));
+        $newRow['status_str'] = CommonFn::get_val_if_isset($row, 'status_str', '');
+        $newRow['status'] = CommonFn::get_val_if_isset($row, 'status', 0);
+
+        $newRow['enable'] = CommonFn::get_val_if_isset($row, 'enable', 0);
+        $newRow['enable_str'] = CommonFn::get_val_if_isset($row, 'enable_str', 0);
+        $newRow['action_user'] = CommonFn::get_val_if_isset($row, 'action_user', '');
+        $newRow['action_time'] = CommonFn::get_val_if_isset($row, 'action_time', '');
+        $newRow['action_log'] = CommonFn::get_val_if_isset($row, 'action_log', '');
+
+        $newRow['material_remarks'] = CommonFn::get_val_if_isset($row, 'remarks', '');
+
+        return $this->output($newRow, $output);
+    }
+}
+?>

+ 84 - 0
www/protected/modules/o2o/models/Stock.php

@@ -0,0 +1,84 @@
+<?php 
+/**
+ * 物资领取情况模型
+ * @author zhouxuchen 2015-09-18
+ */
+class Stock extends MongoAr {
+    public $_id;
+    public $mid;            // 对应物资的id
+    public $mname;          // 对应物资的name
+    public $user;           // 对应的User 的id
+    public $username;       // 对应的Username
+    public $time;           // 操作的时间
+    public $operate;        // 操作的类型 0=>减少 1=>增加
+    public $operate_str;    // 操作的类型
+    public $num;            // 数量
+    public $tot_price;      // 总价
+    public $lastStock;      // 操作前库存数
+    public $newStock;       // 操作后库存数
+    public $remarks;        // 本次操作的备注信息
+    public $object;         // 本次操作的对象ID
+    public $objectName;     // 本次操作对象的name
+    public $station;        // 领取人员所在区域
+    public $stationName;    // 领取人员所在区域的名称
+
+    public static $operate_option = array(
+        1 => array('name' => '入库'),
+        0 => array('name' => '出库')
+    );
+
+    public function __construct($scenario='insert'){
+        $this->setMongoDBComponent(Yii::app()->getComponent('mongodb_o2o'));
+        parent::__construct($scenario);
+    }
+
+    public static function model($className=__CLASS__) {
+        return parent::model($className);
+    }
+
+    public static function get($_id) {
+        if(CommonFn::isMongoId($_id)){
+            $criteria = new EMongoCriteria();
+            $criteria->_id('==', $_id);
+            $model = self::model()->find($criteria);
+            return $model;
+        }else{
+            return false;
+        }
+    }
+
+    public function getCollectionName () {
+        return 'stock';
+    }
+
+    public function parseRow($row, $output = array()) {
+        $newRow = array();
+        $newRow['id'] = (string)$row['_id'];
+        $newRow['mid'] = (string)$row['mid'];
+        $newRow['mname'] = CommonFn::get_val_if_isset($row, 'mname', '');
+        $newRow['user'] = CommonFn::get_val_if_isset($row, 'user', '');
+        $newRow['username'] = CommonFn::get_val_if_isset($row, 'username', '');
+        $newRow['time'] = date('Y-m-d H:i:s', intval(CommonFn::get_val_if_isset($row, 'time', 0)));
+        $newRow['operate'] = intval(CommonFn::get_val_if_isset($row,'operate',1));
+        $newRow['operate_str'] = CommonFn::get_val_if_isset($row,'operate_str', '');
+        $newRow['num'] = intval(CommonFn::get_val_if_isset($row, 'num', 0));
+        $newRow['tot_price'] = CommonFn::get_val_if_isset($row,'tot_price', 0);
+        $newRow['lastStock'] = intval(CommonFn::get_val_if_isset($row, 'lastStock', 0));
+        $newRow['newStock'] = intval(CommonFn::get_val_if_isset($row, 'newStock', 0));
+        $newRow['remarks'] = CommonFn::get_val_if_isset($row,'remarks', '');
+        
+        $newRow['object'] = CommonFn::get_val_if_isset($row, 'object', '');
+        $newRow['objectName'] = CommonFn::get_val_if_isset($row, 'objectName', '');
+
+        $newRow['station'] = isset($row['station']) ? (string)$row['station'] : 'noStation';
+        $newRow['stationName'] = CommonFn::get_val_if_isset($row, 'stationName', '');
+
+        $newRow['action_user'] = CommonFn::get_val_if_isset($row, 'action_user', '');
+        $newRow['action_time'] = CommonFn::get_val_if_isset($row, 'action_time', '');
+        $newRow['action_log'] = CommonFn::get_val_if_isset($row, 'action_log', '');
+
+        return $this->output($newRow, $output);
+    }
+}
+
+?>

+ 846 - 0
www/protected/views/material/index.php

@@ -0,0 +1,846 @@
+<style>
+    .f_label {width: 90px;}
+    .accordion-body {padding: 0;}
+</style>
+<div id="main">
+<div region="west" border="false" id="west_panel">
+    <table id="dg_content"></table>
+    <div id="tb_content">
+        <div class="tb_line">
+            <input id="ss" placeholder="搜索物资" class="material_selector" style="width: 120px;"/>
+            <span class="tb_label">库存状态: </span>
+            <input id="filter_status" />
+            <span class="tb_label">启用状态: </span>
+            <input id="filter_enable" />
+            <a href="#" class='easyui-linkbutton' iconCls="icon-add" plain="true" onclick="add_content();return false;">新增</a>
+            <div class="right">
+                <a href="#" class='easyui-linkbutton' iconCls="icon-search" plain="true" onclick="search_content();return false;">查询</a>
+            </div>
+        </div>
+    </div>
+</div>
+<div region="center" border="false">
+<div class="easyui-layout detail_layout">
+<div data-options="region:'center'" class="detail_center">
+<div class="detail_main">
+<!-- start content_form -->
+<form id="content_form" method="post">
+<ul>
+<li class="f_item">
+    <div class="box">
+        <div class="f_label">
+            <span>ID: </span>
+        </div>
+        <div class="box_flex f_content" onclick="getId();">
+            <input type="hidden" name="id" id="material_id" value='' />
+            <span id="id_str"></span>
+        </div>
+    </div>
+</li>
+<li class="f_item">
+    <div class="box">
+        <div class="f_label">
+            <span>名字: </span>
+        </div>
+        <div class="box_flex f_content">
+            <input type="text" name="name" style="width: 250px;"/>
+        </div>
+    </div>
+</li>
+<li class="f_item">
+    <div class="box">
+        <div class="f_label">
+            <span>单价: </span>
+        </div>
+        <div class="box_flex f_content">
+            <input type="text" name="price" style="width: 250px;"/>
+        </div>
+    </div>
+</li>
+<li class="f_item">
+    <div class="box">
+        <div class="f_label">
+            <span>当前库存: </span>
+        </div>
+        <div class="box_flex f_content">
+            <input type="text" name="stock" class="easyui-numberspinner" data-options="editable:true" style="width: 250px;" />
+            <!-- <input type="text" name="stock" style="width: 250px;" disabled="true" /> -->
+        </div>
+    </div>
+</li>
+    <li class="f_item">
+        <div class="box">
+            <div class="f_label">
+                <span>库存警戒线: </span>
+            </div>
+            <div class="box_flex f_content">
+                <input type="text" name="stockWarnLine" class="easyui-numberspinner" data-options="editable:true" style="width: 250px;"/>
+            </div>
+        </div>
+    </li>
+    <li class="f_item">
+        <div class="box">
+            <div class="f_label">
+                <span>库存状态: </span>
+            </div>
+            <div class="box_flex f_content">
+                <input type="text" name="status_str" style="width: 250px;" disabled="true"/>
+            </div>
+        </div>
+    </li>
+    <li class="f_item">
+        <div class="box">
+            <div class="f_label">
+                <span>单位:</span>
+            </div>
+            <div class="box_flex f_content">
+                <input class="editType" name="unit"/>
+            </div>
+        </div>
+    </li>
+    <li class="f_item">
+        <div class="box">
+            <div class="f_label">
+                <span>是否启用:</span>
+            </div>
+            <div class="box_flex f_content">
+                <input id="setEnable" name="enable" />
+            </div>
+        </div>
+    </li>
+    <li class="f_item">
+        <div class="box">
+            <div class="f_label">
+                <span>备注:</span>
+            </div>
+            <div class="box_flex f_content">
+                <textarea name="material_remarks" style="width: 250px; height: 120px;"></textarea>
+            </div>
+        </div>
+    </li>
+<li class="f_item">
+    <div class="box">
+        <div class="f_label">
+        </div>
+        <div class="box_flex f_content">
+            <span id="action_info" style="color:green;"></span>
+        </div>
+    </div>
+</li>
+</ul>
+</form>
+<!-- end content_form -->
+</div>
+
+<div data-options="region:'south'" class="detail_south">
+    <div class="detail_toolbar">
+        <a href="#" class="easyui-linkbutton set_button" iconCls="icon-save" onclick="save_content();return false;">保存</a>
+        <a href="#" class='easyui-linkbutton' iconCls="icon-add" onclick="set_stock();return false;">入库</a>
+        <a href="#" class="easyui-linkbutton" iconCls="icon-remove" onclick="receive();return false;">出库</a>
+    </div>
+</div>
+
+</div>
+</div>
+</div>
+</div>
+<div style="display: none;">
+    <div id="add_dialog" style="padding: 15px 0;">
+        <form id="add_form" method="post">
+            <ul>
+                <li class="f_item">
+                    <div class="box">
+                        <div class="f_label">
+                            <span>名字: </span>
+                        </div>
+                        <div class="box_flex f_content">
+                            <input type="text" name="name" style="width: 250px;"/>
+                        </div>
+                    </div>
+                </li>
+            <li class="f_item">
+                <div class="box">
+                    <div class="f_label">
+                        <span>单位: </span>
+                    </div>
+                    <div class="box_flex f_content" id="unit_type_add">
+                        <input class="editType" name="unit" />
+                    </div>
+                </div>
+            </li>
+            <li class="f_item">
+                <div class="box">
+                    <div class="f_label">
+                        <span>单价: </span>
+                    </div>
+                    <div class="box_flex f_content">
+                        <input type="text" name="price" style="width: 250px;"/>
+                    </div>
+                </div>
+            </li>
+            <li class="f_item">
+                <div class="box">
+                    <div class="f_label">
+                        <span>初始库存: </span>
+                    </div>
+                    <div class="box_flex f_content">
+                        <input type="text" name="stock" class="easyui-numberspinner" data-options="editable:true" style="width: 250px;"/>
+                    </div>
+                </div>
+            </li>
+            <li class="f_item">
+                <div class="box">
+                    <div class="f_label">
+                        <span>库存警戒线: </span>
+                    </div>
+                    <div class="box_flex f_content">
+                        <input type="text" name="stockWarnLine" class="easyui-numberspinner" data-options="editable:true" style="width: 250px;"/>
+                    </div>
+                </div>
+            </li>
+            <li class="f_item">
+                <div class="box">
+                    <div class="f_label">
+                        <span>备注: </span>
+                    </div>
+                    <div class="box_flex f_content">
+                        <textarea name="remarks" style="width: 250px; height: 80px;"></textarea>
+                    </div>
+                </div>
+            </li>
+            </ul>
+        </form>
+    </div>
+</div>
+<!-- 入库表单 -->
+<div style="display: none;">
+    <div id="stock_dialog" style="padding: 15px 0;">
+        <form id="stock_form" method="post">
+            <ul>
+                <li class="f_item">
+                    <div class="box">
+                        <div class="f_label">
+                            <span>ID: </span>
+                        </div>
+                        <div class="box_flex f_content">
+                            <span type="text" class="m_id   "></span>
+                            <input type="hidden" name="mid" class="mid  " />
+                        </div>
+                    </div>
+                </li>
+                <li class="f_item">
+                    <div class="box">
+                        <div class="f_label">
+                            <span>名字: </span>
+                        </div>
+                        <div class="box_flex f_content">
+                            <span ></span>
+                            <input type="text" name="name" id="mname" style="width: 250px;" disabled="true"/>
+                        </div>
+                    </div>
+                </li>
+            <li class="f_item">
+                <div class="box">
+                    <div class="f_label">
+                        <span>单位: </span>
+                    </div>
+                    <div class="box_flex f_content" id="unit_type_add">
+                        <input class="editType" name="unit" disabled="true"/>
+                    </div>
+                </div>
+            </li>
+            <li class="f_item">
+                <div class="box">
+                    <div class="f_label">
+                        <span>单价: </span>
+                    </div>
+                    <div class="box_flex f_content">
+                        <input type="text" name="price" style="width: 250px;" disabled="true"/>
+                    </div>
+                </div>
+            </li>
+            <li class="f_item">
+                <div class="box">
+                    <div class="f_label">
+                        <span>初始库存: </span>
+                    </div>
+                    <div class="box_flex f_content">
+                        <input type="text" name="stock" style="width: 250px;" disabled="true"/>
+                    </div>
+                </div>
+            </li>
+            <li class="f_item">
+                <div class="box">
+                    <div class="f_label">
+                        <span>数量: </span>
+                    </div>
+                    <div class="box_flex f_content">
+                        <input type="text" name="num" class="easyui-numberspinner" data-options="editable:true" style="width: 250px;"/>
+                    </div>
+                </div>
+            </li>
+            <li class="f_item">
+                <div class="box">
+                    <div class="f_label">
+                        <span>成本: </span>
+                    </div>
+                    <div class="box_flex f_content">
+                        <input type="text" name="tot_price" style="width: 250px;" placeholder="留空则系统自动计算" />
+                    </div>
+                </div>
+            </li>
+            <div id="receive_content"></div>
+            <li class="f_item">
+                <div class="box">
+                    <div class="f_label">
+                        <span>备注: </span>
+                    </div>
+                    <div class="box_flex f_content">
+                        <textarea name="remarks" style="width: 250px; height: 80px;"></textarea>
+                    </div>
+                </div>
+            </li>
+            </ul>
+        </form>
+    </div>
+</div>
+<!-- 出库表单 -->
+<div style="display: none;">
+    <div id="receive_dialog" style="padding: 15px 0;">
+        <form id="receive_form" method="post">
+            <ul>
+                <li class="f_item">
+                    <div class="box">
+                        <div class="f_label">
+                            <span>ID: </span>
+                        </div>
+                        <div class="box_flex f_content">
+                            <span type="text" class="m_id"></span>
+                            <input type="hidden" name="mid" class="mid" />
+                        </div>
+                    </div>
+                </li>
+                <li class="f_item">
+                    <div class="box">
+                        <div class="f_label">
+                            <span>名字: </span>
+                        </div>
+                        <div class="box_flex f_content">
+                            <span ></span>
+                            <input type="text" name="name" id="mname" style="width: 250px;" disabled="true"/>
+                        </div>
+                    </div>
+                </li>
+            <li class="f_item">
+                <div class="box">
+                    <div class="f_label">
+                        <span>单位: </span>
+                    </div>
+                    <div class="box_flex f_content" id="unit_type_add">
+                        <input class="editType" name="unit" disabled="true"/>
+                    </div>
+                </div>
+            </li>
+            <li class="f_item">
+                <div class="box">
+                    <div class="f_label">
+                        <span>单价: </span>
+                    </div>
+                    <div class="box_flex f_content">
+                        <input type="text" name="price" style="width: 250px;" disabled="true"/>
+                    </div>
+                </div>
+            </li>
+            <li class="f_item">
+                <div class="box">
+                    <div class="f_label">
+                        <span>初始库存: </span>
+                    </div>
+                    <div class="box_flex f_content">
+                        <input type="text" name="stock" style="width: 250px;" disabled="true"/>
+                    </div>
+                </div>
+            </li>
+            <li class="f_item">
+                <div class="box">
+                    <div class="f_label">
+                        <span>数量: </span>
+                    </div>
+                    <div class="box_flex f_content">
+                        <input type="text" name="num" class="easyui-numberspinner" data-options="editable:true" style="width: 250px;"/>
+                    </div>
+                </div>
+            </li>
+            <li class="f_item">
+                <div class="box">
+                    <div class="f_label">
+                        <span>选择对象: </span>
+                    </div>
+                    <div class="box_flex f_content">
+                        <input type="text" name="object" class="user_selector" style="width: 250px;"/>
+                    </div>
+                </div>
+            </li>
+            <li class="f_item">
+                <div class="box">
+                    <div class="f_label">
+                        <span>选择服务点: </span>
+                    </div>
+                    <div class="box_flex f_content">
+                        <input type="text" name="station" id="station" style="width: 250px;"/>
+                    </div>
+                </div>
+            </li>
+            <div id="receive_content"></div>
+            <li class="f_item">
+                <div class="box">
+                    <div class="f_label">
+                        <span>备注: </span>
+                    </div>
+                    <div class="box_flex f_content">
+                        <textarea name="remarks" style="width: 250px; height: 80px;"></textarea>
+                    </div>
+                </div>
+            </li>
+            </ul>
+            <input type="hidden" name="operate" value="0" />
+        </form>
+    </div>
+</div>
+<!-- 引入用户选择插件 -->
+<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.js"></script>
+<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.css" />
+<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/selector.js"></script>
+<!-- 用户选择插件引入结束 -->
+<script type="text/javascript">
+var jq_dg_content = $('#dg_content');
+var w_width = $(window).width();
+var w_height = $(window).height();
+var jq_content_form = $('#content_form');
+var jq_add_form = $('#add_form');
+var jq_filter_status = $('#filter_status');
+var jq_filter_enable = $('#filter_enable');
+var jq_add_dialog = $('#add_dialog');
+var jq_stock_dialog = $('#stock_dialog');
+var jq_stock_form = $('#stock_form');
+var jq_ss = $('#ss');
+var jq_receive_form = $('#receive_form');
+var jq_receive_dialog = $('#receive_dialog')
+
+var status_data = <?php echo json_encode($status); ?>;
+var type_data = <?php echo json_encode($type); ?>;
+var enable_data = <?php echo json_encode($enable); ?>;
+var station_data = <?php echo json_encode($station); ?>;
+
+var jq_setType = $('.editType');
+var jq_setEnable =$("#setEnable");
+var jq_setStation = $('#station');
+var module_router = site_root + '/index.php?r=material';
+var jq_action_info = $('#action_info');
+
+$(function(){
+    var p_width = parseInt(w_width / 2);
+    if (p_width < 520){
+        p_width = 520;
+    }
+    var d_width = p_width - 10;
+    $('#west_panel').css({width : p_width});
+    $('#main').css({width: w_width - 25, height: w_height - 18}).layout();
+
+    jq_setType.combobox({
+        editable: false,
+        data: type_data
+    });
+
+    jq_setEnable.combobox({
+        editable: false,
+        data: enable_data
+    });
+
+    jq_setStation.combobox({
+        editable: false,
+        data: station_data
+    });
+
+    // jq_ss.searchbox({
+    //     width: 150,
+    //     searcher:function(value){
+    //         search_content();
+    //     },
+    //     prompt: '请输入关键字'
+    // });
+
+    jq_filter_status.combobox({
+        width: 100,
+        data: status_data,
+        editable: false,
+        onSelect: function(){
+            search_content();
+        }
+    });
+
+    jq_filter_enable.combobox({
+        width: 100,
+        data: enable_data,
+        editable: false,
+        onSelect: function(){
+            search_content();
+        }
+    });
+
+    // 设置默认值
+    jq_filter_enable.combobox('setValue', 1);
+
+    jq_add_dialog.dialog({
+        title: '新建',
+        width: 500,
+        height: 500,
+        closed: true,
+        modal: true,
+        buttons:[{
+            text: '确认',
+            iconCls: 'icon-ok',
+            handler: function(){
+                $.messager.progress();
+                jq_add_form.submit();
+            }
+        },{
+            text: '取消',
+            iconCls: 'icon-cancel',
+            handler: function(){
+                jq_add_dialog.dialog('close');
+            }
+        }],
+        onOpen:function(){
+            jq_add_form.form('clear');
+            jq_add_form.form('load', {});
+        }
+    });
+
+    jq_stock_dialog.dialog({
+        title: '入库操作',
+        width: 500,
+        height: 500,
+        closed: true,
+        modal: true,
+        buttons:[{
+            text: '确认',
+            iconCls: 'icon-ok',
+            handler: function(){
+                $.messager.progress();
+                jq_stock_form.submit();
+            }
+        },{
+            text: '取消',
+            iconCls: 'icon-cancel',
+            handler: function(){
+                jq_stock_dialog.dialog('close');
+            }
+        }],
+        onOpen:function(){
+            // jq_stock_form.form('clear');
+            jq_stock_form.form('load', {});
+        }
+    });
+
+    jq_receive_dialog.dialog({
+        title: '出库操作',
+        width: 500,
+        height: 500,
+        closed: true,
+        modal: true,
+        buttons:[{
+            text: '确认',
+            iconCls: 'icon-ok',
+            handler: function(){
+                $.messager.progress();
+                jq_receive_form.submit();
+            }
+        },{
+            text: '取消',
+            iconCls: 'icon-cancel',
+            handler: function(){
+                jq_receive_dialog.dialog('close');
+            }
+        }],
+        onOpen:function(){
+            jq_receive_form.form('load', {});
+        }
+    });
+
+    jq_dg_content.datagrid({
+        url: module_router + '/list',
+        title: '物资列表',
+        width: d_width,
+        height: w_height - 18,
+        fitColumns: true,
+        autoRowHeight: true,
+        striped: true,
+        toolbar: '#tb_content',
+        singleSelect: true,
+        selectOnCheck: false,
+        checkOnSelect: false,
+        pagination: true,
+        pageList: [20, 30, 50],
+        pageSize: 20,
+        nowrap: false,
+        idField: 'id',
+        sortName: 'status',
+        sortOrder: 'asc',
+        queryParams: get_param_obj(),
+        frozenColumns:[],
+        columns:[[
+            {field:'id', title:'id', hidden:true},
+            {field:'name', title:'物资名称', width:35},
+            {field:'unit_str', title:'单位', width:20},
+            {field:'price', title:'单价(元)', width:20, sortable: true},
+            {field:'stock', title:'库存', width:20, sortable: true},
+            {field:'stockWarnLine', title:'警戒线', width:20},
+            {field:'addTime', title:'添加时间', width:40, hidden:true},
+            {field:'status_str', title:'库存状态', width:20},
+            {field:'status', title:'status', hidden:true},
+            {field:'enable_str', title:'启用', width:20},
+            {field:'enable', title:'enable', hidden: true},
+            {field:'material_remarks', title:'备注', hidden: true}
+        ]],
+
+        queryParams: {enable: 1},
+
+        rowStyler: function (index, row) {
+            if (row.status == 0) {
+                return 'background-color: red';
+            } else if (row.status == 1) {
+                return 'background-color: orange';
+            }
+        },
+
+        onSelect: function(index, row){
+
+            var data = $.extend({}, row);
+            jq_content_form.form('load', data);
+            jq_stock_form.form('load', data);
+            jq_receive_form.form('load', data);
+
+            $('#admins_edit_info').html('');
+
+            if (data['action_user'] != ''){
+                jq_action_info.html('信息已被编辑: ' + data['action_user'] + ' ' + data['action_time']);
+            } else {
+                jq_action_info.html('');
+            }
+
+            $("#on_loading").show();
+            $('#id_str').html(data.id);
+        },
+
+        onLoadSuccess: function(){
+            $(this).datagrid('clearChecked');
+
+            jq_content_form.form('clear');
+            jq_add_form.form('clear');
+            jq_receive_form.form('clear');
+            jq_stock_form.form('clear');
+
+            $('#id_str').html('');
+            jq_action_info.html('');
+
+            jq_dg_content.datagrid('clearSelections');
+        }
+    });
+
+    // 修改物资
+    jq_content_form.form({
+        url: module_router + '/edit',
+        onSubmit: function(param){
+            if ($('#material_id').val() == ""){
+                return false;
+            }
+            var isValid = $(this).form('validate');
+            if (!isValid){
+                $.messager.progress('close');
+            }
+            return isValid;
+        },
+        success: function(res){
+            $.messager.progress('close');
+            var res = JSON.parse(res);
+
+            if (res.success){
+                jq_dg_content.datagrid('reload');
+            }
+            if(res.success){
+                $.messager.show({
+                    title: '提示',
+                    msg: '保存成功',
+                    timeout: 3500,
+                    showType: 'slide'
+                });
+            }else{
+                $.messager.show({
+                    title: '提示',
+                    msg: res.message,
+                    timeout: 3500,
+                    showType: 'slide'
+                });
+            }
+        }
+    });
+
+    // 添加物资
+    jq_add_form.form({
+        url: module_router + '/edit',
+        onSubmit: function(param){
+            var isValid = $(this).form('validate');
+            if (!isValid){
+                $.messager.progress('close');
+            }
+            return isValid;
+        },
+        success: function(res){
+            $.messager.progress('close');
+            var res = JSON.parse(res);
+            if (res.success){
+                $.messager.show({
+                    title: '提示',
+                    msg: '添加成功',
+                    timeout: 3500,
+                    showType: 'slide'
+                });
+                jq_add_dialog.dialog('close');
+                jq_dg_content.datagrid('reload');
+            } else {
+                $.messager.show({
+                    title: '提示',
+                    msg: res.message,
+                    timeout: 3500,
+                    showType: 'slide'
+                });
+            }
+
+        }
+    });
+
+    // 出入库操作
+    jq_stock_form.form({
+        url: module_router + '/stock',
+        onSubmit: function(param){
+            var isValid = $(this).form('validate');
+            if (!isValid){
+                $.messager.progress('close');
+            }
+            return isValid;
+        },
+        success: function(res){
+            $.messager.progress('close');
+            var res = JSON.parse(res);
+            if (res.success){
+                $.messager.show({
+                    title: '提示',
+                    msg: '出入库操作成功',
+                    timeout: 3500,
+                    showType: 'slide'
+                });
+                jq_stock_dialog.dialog('close');
+                jq_stock_form.form('clear');
+                jq_dg_content.datagrid('reload');
+            } else {
+                $.messager.show({
+                    title: '提示',
+                    msg: res.message,
+                    timeout: 3500,
+                    showType: 'slide'
+                });
+            }
+
+        }
+    });
+
+    // 出库操作
+    jq_receive_form.form({
+        url: module_router + '/stock',
+        onSubmit: function(param){
+            var isValid = $(this).form('validate');
+            if (!isValid){
+                $.messager.progress('close');
+            }
+            return isValid;
+        },
+        success: function(res){
+            $.messager.progress('close');
+            var res = JSON.parse(res);
+            if (res.success){
+                $.messager.show({
+                    title: '提示',
+                    msg: '出入库操作成功',
+                    timeout: 3500,
+                    showType: 'slide'
+                });
+                jq_receive_dialog.dialog('close');
+                jq_receive_form.form('clear');
+                jq_dg_content.datagrid('reload');
+            } else {
+                $.messager.show({
+                    title: '提示',
+                    msg: res.message,
+                    timeout: 3500,
+                    showType: 'slide'
+                });
+            }
+
+        }
+    });
+
+});
+
+function save_content(){
+    if ($('#material_id').val() == ""){
+        return false;
+    }
+
+    $.messager.progress();
+    jq_content_form.submit();
+}
+
+function add_content(){
+    jq_add_dialog.dialog('open');
+}
+
+function set_stock () {
+    var mid = $('#id_str').html();
+
+    $('.mid').val(mid);
+    $('.m_id').html(mid);
+
+    jq_stock_dialog.dialog('open');
+}
+
+function receive () {
+    var mid = $('#id_str').html();
+
+    $('.mid').val(mid);
+    $('.m_id').html(mid);
+
+    jq_receive_dialog.dialog('open');
+}
+
+function search_content () {
+    var filter_status = jq_filter_status.combobox('getValue');
+    var filter_enable = jq_filter_enable.combobox('getValue');
+    var search = jq_ss.val();
+
+    jq_dg_content.datagrid({
+        pageNum: 1,
+        queryParams: {search: search, status: filter_status, enable: filter_enable}
+    });
+}
+
+function calPrice () {
+    var num = $('#num').val();
+    var price = $('price').val();
+
+    //alert(num);
+    //alert(price);
+    // alert(num * price);
+}
+
+</script>

+ 400 - 0
www/protected/views/stock/index.php

@@ -0,0 +1,400 @@
+<style>
+    .f_label {width: 90px;}
+    .accordion-body {padding: 0;}
+</style>
+<div id="main">
+<div region="west" border="false" id="west_panel">
+    <table id="dg_content"></table>
+    <div id="tb_content">
+        <div class="tb_line">
+            <p>
+                <input class="material_selector" id="material" name="material" placeholder="物资名" style="width: 100px;"/>
+                <input class="user_selector" id="user" placeholder="目标用户" value="<?php echo $fromStockView ? $objectName : ''; ?>" style="width: 100px;" />
+                <!-- <input class="station_selector" id="station" placeholder="服务点" value="<?php echo $fromStockView ? $stationName : ''; ?>" style="width: 100px;" /> -->
+                <input type="text" name="station" id="station" style="width: 100px;">
+                <span class="tb_label">操作: </span>
+                <input id="filter_operate" />
+            </p>
+            <div class="right">
+                <a href="#" class='easyui-linkbutton' iconCls="icon-search" plain="true" onclick="search_content();return false;">查询</a>
+            </div>
+            <p>
+                <span class="tb_label">开始时间</span>
+                <input type="text" id="date_start" />
+                <span class="tb_label">结束时间</span>
+                <input type="text" id="date_end" />
+            </p>
+        </div>
+    </div>
+</div>
+<div region="center" border="false">
+<div class="easyui-layout detail_layout">
+<div data-options="region:'center'" class="detail_center">
+<div class="detail_main">
+<!-- start content_form -->
+<form id="content_form" method="post">
+<ul>
+<li class="f_item">
+    <div class="box">
+        <div class="f_label">
+            <span>ID: </span>
+        </div>
+        <div class="box_flex f_content" onclick="getId();">
+            <input type="hidden" name="id" id="sid" value='' />
+            <span id="id_str"></span>
+        </div>
+    </div>
+</li>
+<li class="f_item">
+    <div class="box">
+        <div class="f_label">
+            <span>物资: </span>
+        </div>
+        <div class="box_flex f_content">
+            <input type="text" name="mname" style="width: 250px;" disabled="true"/>
+        </div>
+    </div>
+</li>
+<li class="f_item">
+    <div class="box">
+        <div class="f_label">
+            <span>用户: </span>
+        </div>
+        <div class="box_flex f_content">
+            <input type="text" name="username" style="width: 250px;" disabled="true"/>
+        </div>
+    </div>
+</li>
+<li class="f_item">
+    <div class="box">
+        <div class="f_label">
+            <span>时间: </span>
+        </div>
+        <div class="box_flex f_content">
+            <input type="text" name="time" style="width: 250px;" disabled="true" />
+        </div>
+    </div>
+</li>
+    <li class="f_item">
+        <div class="box">
+            <div class="f_label">
+                <span>操作: </span>
+            </div>
+            <div class="box_flex f_content">
+                <input type="text" name="operate_str" style="width: 250px;" disabled="true"/>
+            </div>
+        </div>
+    </li>
+    <li class="f_item">
+        <div class="box">
+            <div class="f_label">
+                <span>对象: </span>
+            </div>
+            <div class="box_flex f_content">
+                <input type="text" class="user_selector" name="objectName" style="width: 250px;"/>
+            </div>
+        </div>
+    </li>
+    <li class="f_item">
+        <div class="box">
+            <div class="f_label">
+                <span>服务点: </span>
+            </div>
+            <div class="box_flex f_content">
+                <input type="text" id="setStation" name="station" style="width: 250px;"/>
+            </div>
+        </div>
+    </li>
+    <li class="f_item">
+        <div class="box">
+            <div class="f_label">
+                <span>数量: </span>
+            </div>
+            <div class="box_flex f_content">
+                <input type="text" id="num_content" name="num" style="width: 250px;" disabled="true"/>
+            </div>
+        </div>
+    </li>
+    <li class="f_item">
+        <div class="box">
+            <div class="f_label">
+                <span>前库存: </span>
+            </div>
+            <div class="box_flex f_content">
+                <input type="text" id="lastStock_content" name="lastStock" style="width: 250px;" disabled="true"/>
+            </div>
+        </div>
+    </li>
+    <li class="f_item">
+        <div class="box">
+            <div class="f_label">
+                <span>新库存:</span>
+            </div>
+            <div class="box_flex f_content">
+                <input type="text" id="newStock_content" name="newStock" style="width: 250px;" disabled="true" />
+            </div>
+        </div>
+    </li>
+    <!-- <li class="f_item">
+        <div class="box">
+            <div class="f_label">
+                <span>其他操作:</span>
+            </div>
+            <div class="box_flex f_content">
+                <a href="#" onclick="showChangeStock();return false;">修改出入库数量及库存</a>
+            </div>
+        </div>
+    </li> -->
+    <li class="f_item">
+        <div class="box">
+            <div class="f_label">
+                <span>备注:</span>
+            </div>
+            <div class="box_flex f_content">
+                <textarea name="remarks" style="width: 250px;height: 120px;"></textarea>
+            </div>
+        </div>
+    </li>
+<li class="f_item">
+    <div class="box">
+        <div class="f_label">
+        </div>
+        <div class="box_flex f_content">
+            <span id="action_info" style="color:green;"></span>
+        </div>
+    </div>
+</li>
+</ul>
+</form>
+<!-- end content_form -->
+</div>
+
+<div data-options="region:'south'" class="detail_south">
+    <div class="detail_toolbar">
+        <a href="#" class="easyui-linkbutton set_button" iconCls="icon-save" onclick="save_content();return false;">保存</a>
+
+    </div>
+</div>
+
+</div>
+</div>
+</div>
+</div>
+<!-- 引入自动填充选择插件 -->
+<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.js"></script>
+<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.css" />
+<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/selector.js"></script>
+<!-- 用户选择插件引入结束 -->
+<script type="text/javascript">
+var jq_dg_content = $('#dg_content');
+var temp = new Date();
+var today = temp.getFullYear() + '-' + (temp.getMonth() + 1) + '-' + temp.getDate();
+var w_width = $(window).width();
+var w_height = $(window).height();
+var jq_content_form = $('#content_form');
+var jq_filter_operate = $('#filter_operate');
+
+var operate_data = <?php echo json_encode($operate); ?>;
+var station_data = <?php echo json_encode($station); ?>;
+
+var jq_setType = $('.editType');
+var jq_setEnable =$("#setEnable");
+var module_router = site_root + '/index.php?r=stock';
+var jq_action_info = $('#action_info');
+var jq_station = $('#station');
+var jq_setStation = $('#setStation');
+
+var jq_date_start = $('#date_start');
+var jq_date_end = $('#date_end');
+
+// var showChangeNum = 0;
+
+$(function(){
+    var p_width = parseInt(w_width / 2);
+    if (p_width < 520){
+        p_width = 520;
+    }
+    var d_width = p_width - 10;
+    $('#west_panel').css({width : p_width});
+    $('#main').css({width: w_width - 25, height: w_height - 18}).layout();
+
+    jq_filter_operate.combobox({
+        width: 100,
+        data: operate_data,
+        editable: false,
+        onSelect: function(){
+            search_content();
+        }
+    });
+
+    jq_station.combobox({
+        width: 100,
+        data: station_data,
+        editable: false,
+        onSelect : function () {
+            search_content();
+        }
+    });
+
+    jq_date_start.datebox({});
+
+    jq_date_end.datebox({});
+
+    jq_setStation.combobox({
+        width    : 250,
+        editable : false,
+        data     : (function () {
+            var station_data_temp = new Array();
+            $.extend(station_data_temp, station_data);
+            station_data_temp.shift();
+            station_data_temp.pop();
+
+            return station_data_temp;
+        })()
+    });
+
+    jq_dg_content.datagrid({
+        url: module_router + '/list',
+        title: '库存操作记录',
+        width: d_width,
+        height: w_height - 18,
+        fitColumns: true,
+        autoRowHeight: true,
+        striped: true,
+        toolbar: '#tb_content',
+        singleSelect: true,
+        selectOnCheck: false,
+        checkOnSelect: false,
+        pagination: true,
+        pageList: [20, 30, 50],
+        pageSize: 20,
+        nowrap: false,
+        idField: 'id',
+        sortName: 'time',
+        sortOrder: 'desc',
+        queryParams: get_param_obj(),
+        frozenColumns:[[]],
+        columns:[[
+            {field:'id', title:'id', hidden:true},
+            {field:'mname', title:'名称',width:30},
+            {field:'username', title:'用户', width:30},
+            {field:'operate_str', title:'操作', width:20},
+            {field:'objectName', title:'对象', width:30},
+            {field:'stationName', title:'服务点', width:30},
+            {field:'num', title:'数量', width:20, sortable: true},
+            {field:'tot_price', title:'总价', width:30, sortable: true},
+            {field:'lastStock', title:'前库存', width:20},
+            {field:'newStock', title:'现库存', width:20},
+            {field:'time', title:'操作时间', width:30, sortable: true},
+        ]],
+
+        queryParams: {
+            date_start : jq_date_start.datebox('getValue'),
+            date_end : jq_date_end.datebox('getValue'),
+            s_user : $('#user').val(),
+            station : $('#station').combobox('getValue')
+        },
+
+        onSelect: function(index, row){
+            var data = $.extend({}, row);
+            jq_content_form.form('load', data);
+
+            // showChangeNum = 0;
+            // $('#num_content').attr('disabled', 'true');
+
+            $('#admins_edit_info').html('');
+
+            if (data['action_user'] != ''){
+                jq_action_info.html('信息已被编辑: ' + data['action_user'] + ' ' + data['action_time']);
+            } else {
+                jq_action_info.html('');
+            }
+
+            $("#on_loading").show();
+            $('#id_str').html(data.id);
+        },
+
+        onLoadSuccess: function(){
+            $(this).datagrid('clearChecked');
+
+            jq_content_form.form('clear');
+            $('#id_str').html('');
+            jq_action_info.html('');
+
+            jq_dg_content.datagrid('clearSelections');
+        }
+    });
+
+    // 修改库存操作记录
+    jq_content_form.form({
+        url: module_router + '/edit',
+        onSubmit: function(param){
+            var isValid = $(this).form('validate');
+            if (!isValid){
+                $.messager.progress('close');
+            }
+            return isValid;
+        },
+        success: function(res){
+            $.messager.progress('close');
+            var res = JSON.parse(res);
+
+            if (res.success){
+                jq_dg_content.datagrid('reload');
+            }
+            if(res.success){
+                $.messager.show({
+                    title: '提示',
+                    msg: '保存成功',
+                    timeout: 3500,
+                    showType: 'slide'
+                });
+            }else{
+                $.messager.show({
+                    title: '提示',
+                    msg: res.message,
+                    timeout: 3500,
+                    showType: 'slide'
+                });
+            }
+        }
+    });
+
+});
+
+function save_content(){
+    if ($('#sid').val() == ""){
+        alert('ID is empty');
+        return false;
+    }
+
+    $.messager.progress();
+    jq_content_form.submit();
+}
+
+function search_content () {
+    var filter_operate = jq_filter_operate.combobox('getValue');
+    var s_mname = $('#material').val();
+    var s_user = $('#user').val();
+    var station = jq_station.combobox('getValue');
+    var date_start = jq_date_start.datebox('getValue');
+    var date_end = jq_date_end.datebox('getValue');
+
+    jq_dg_content.datagrid({
+        pageNum: 1,
+        queryParams: {
+            s_mname: s_mname,
+            s_user: s_user,
+            station: station,
+            operate: filter_operate,
+            date_start: date_start,
+            date_end: date_end
+        }
+    });
+}
+
+// function showChangeStock () {
+//     $('#num_content').removeAttr('disabled');
+//     showChangeNum = 1;
+// }
+</script>

+ 255 - 0
www/protected/views/stockViewStation/all.php

@@ -0,0 +1,255 @@
+<style>
+    .f_label {width: 90px;}
+    .accordion-body {padding: 0;}
+    .options {
+        display: inline-block;
+        border: 1px solid #e5e5e5;
+        background: #fff;
+        color: #000;
+        padding: 3px 6px;
+        text-decoration: none;
+    }
+</style>
+<div id="main">
+<div region="west" border="false" id="west_panel" style="width: 530px;">
+    <table id="dg_content"></table>
+    <div id="tb_content">
+        <div class="tb_line">
+            <p>
+                <span class="tb_label">服务点</span>
+                <input id="station" name="station_data" />
+            </p>
+            <p>
+                <span class="tb_label">开始</span>
+                <input type="text" id="date_start" value="<?php echo date('Y-m-d', $date_start); ?>" style="width: 100px;"/>
+                <span class="tb_label">结束</span>
+                <input type="text" id="date_end" value="<?php echo date('Y-m-d', strtotime('-1 day', $date_end)); ?>" style="width: 100px;"/>
+                <a href="#" class='easyui-linkbutton' iconCls="icon-search" plain="true" onclick="search_content();return false;">查询</a>
+            </p>
+        </div>
+    </div>
+</div>
+<div region="center" title="统计图表">
+<div class="easyui-layout detail_layout">
+<div data-options="region:'center'" class="detail_center">
+<div class="detail_main">
+    <div data-options="region:'center'" class="detail_center">
+        <div class="detail_main">
+            <!-- <input type="hidden" name="id" id="material_id" value='' /> -->
+            <form id="search_by_time" method="post" action="/index.php?r=stockViewStation/all">
+                <div>
+                    <p>
+                        <input type="text" name="date_start" id="date_start_search" value="<?php echo date('Y-m-d', $date_start); ?>"/>
+                        <input type="text" name="date_end" id="date_end_search" value="<?php echo date('Y-m-d', strtotime('-1 day', $date_end)); ?>"/>
+                        <input type="submit" value="搜索" />
+                    </p>
+                    <p>
+                        <a class="options" href="/index.php?r=stockViewStation/index">最近一周</a>
+                        <a class="options" href="/index.php?r=stockViewStation/findByWeeks">最近一月</a>
+                        <a class="options" href="/index.php?r=stockViewStation/findByMonths">半年数据</a>
+                    </p>
+                </div>
+            </form>
+            <form id="content_form" method="post">
+                <div id="main_station" style="height:450px;width:900px"></div>
+            </form>
+        </div>
+    </div>
+</div>
+</div>
+
+</div>
+</div>
+</div>
+<!-- 引入自动填充选择插件 -->
+<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.js"></script>
+<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/css/jquery.coolautosuggest.css" />
+<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/selector.js"></script>
+<!-- 用户选择插件引入结束 -->
+<!-- 引入echarts插件 -->
+<script src="http://echarts.baidu.com/build/dist/echarts.js"></script>
+<!-- 引入结束 -->
+<script type="text/javascript">
+var jq_dg_content = $('#dg_content');
+var temp = new Date();
+var today = temp.getFullYear() + '-' + (temp.getMonth() + 1) + '-' + temp.getDate();
+var w_width = $(window).width();
+var w_height = $(window).height();
+var jq_content_form = $('#content_form');
+var jq_filter_station = $('#station');
+
+var module_router = site_root + '/index.php?r=stockViewStation';
+
+var jq_date_start = $('#date_start');
+var jq_date_end = $('#date_end');
+
+var jq_date_start_search = $('#date_start_search');
+var jq_date_end_search = $('#date_end_search');
+
+var station_data = <?php echo json_encode($station_data); ?>;
+
+$(function(){
+    var p_width = parseInt(w_width / 2);
+    if (p_width < 520){
+        p_width = 520;
+    }
+
+    jq_date_start.datebox({});
+
+    jq_date_end.datebox({});
+
+    jq_date_start_search.datebox({});
+
+    jq_date_end_search.datebox({});
+
+    jq_filter_station.combobox({
+        width: 100,
+        data: station_data,
+        editable: false,
+        onSelect: function () {
+            search_content();
+        }
+    });
+
+    $('#main').css({width: w_width - 25, height: w_height - 18}).layout();
+
+    jq_dg_content.datagrid({
+        url: module_router + '/list',
+        title: '库存操作记录',
+        width: 520,
+        height: w_height - 18,
+        fitColumns: true,
+        autoRowHeight: true,
+        striped: true,
+        toolbar: '#tb_content',
+        singleSelect: true,
+        selectOnCheck: false,
+        checkOnSelect: false,
+        pagination: true,
+        pageList: [20, 30, 50],
+        pageSize: 20,
+        nowrap: false,
+        idField: 'station',
+        sortName: 'price_count',
+        sortOrder: 'desc',
+        frozenColumns:[],
+        queryParams: $.extend(
+            get_param_obj(),
+            {
+                date_start : jq_date_start.datebox('getValue'),
+                date_end : jq_date_end.datebox('getValue')
+            }
+        ),
+        columns:[[
+            {field:'id', title:'id', hidden:true},
+            {field:'stationName', title:'服务点',width:30},
+            {field:'operate_count', title:'领取次数', width:20},
+            {field:'price_count', title:'总价格', width:30},
+            {field:'station', title:'操作', width:30,
+                formatter: function (value, row, index) {
+                   return '<a href="javascript:;" onclick="parent.load_url(\'<?php echo Yii::app()->request->baseUrl; ?>/index.php?r=stock&station='+row['station']+'\');">详情</a>';
+                }
+            }
+        ]],
+
+        onSelect: function(index, row){
+
+            var data = $.extend({}, row);
+            
+            $('#on_loading').show();
+
+            jq_content_form.form('reset');
+        },
+    });
+});
+
+function search_content () {
+    var stationName = jq_filter_station.combobox('getValue');
+    var date_start = jq_date_start.datebox('getValue');
+    var date_end = jq_date_end.datebox('getValue');
+
+    jq_dg_content.datagrid({
+        pageNum: 1,
+        queryParams: {
+            stationName: stationName,
+            date_start: date_start,
+            date_end: date_end
+        }
+    });
+}
+</script>
+<!-- start echarts -->
+<script type="text/javascript">
+require.config({
+    paths : {
+        echarts: 'http://echarts.baidu.com/build/dist'
+    }
+});
+
+require(
+    [
+        'echarts',
+        'echarts/chart/pie',
+        'echarts/chart/funnel'
+    ],
+    function (ec) {
+        var material_chart = ec.init(document.getElementById('main_station'));
+
+        option = {
+            title : {
+                text: '<?php echo $date_range; ?>领用物资总价分布',
+                subtext: '',
+                x:'center'
+            },
+            tooltip : {
+                trigger: 'item',
+                formatter: "{a} <br/>{b} : {c} ({d}%)"
+            },
+            legend: {
+                orient : 'vertical',
+                y : 'bottom',
+                x : 'left',
+                data:[<?php echo $stationNames; ?>]
+            },
+            toolbox: {
+                show : true,
+                feature : {
+                    mark : {show: true},
+                    dataView : {show: true, readOnly: false},
+                    magicType : {
+                        show: true, 
+                        type: ['pie', 'funnel'],
+                        option: {
+                            funnel: {
+                                x: '25%',
+                                width: '50%',
+                                funnelAlign: 'left',
+                                max: 1548
+                            }
+                        }
+                    },
+                    restore : {show: true},
+                    saveAsImage : {show: true}
+                }
+            },
+            calculable : true,
+            series : [
+                {
+                    name:'服务点',
+                    type:'pie',
+                    radius : '55%',
+                    center: ['50%', '60%'],
+                    data:[
+                    <?php foreach ($price_count_arr as $key => $value) { ?>
+                        {
+                            value:<?php echo $value; ?>,
+                            name:"<?php echo $key; ?>"
+                        },
+                    <?php } ?>
+                    ]
+                }
+            ]
+        };material_chart.setOption(option);
+    }
+);
+</script>

+ 285 - 0
www/protected/views/stockViewStation/findByMonths.php

@@ -0,0 +1,285 @@
+<style>
+    .f_label {width: 90px;}
+    .accordion-body {padding: 0;}
+    .options {
+        display: inline-block;
+        border: 1px solid #e5e5e5;
+        background: #fff;
+        color: #000;
+        padding: 3px 6px;
+        text-decoration: none;
+    }
+</style>
+<div id="main">
+<div region="west" border="false" id="west_panel" style="width: 430px;">
+    <table id="dg_content"></table>
+    <div id="tb_content">
+        <div class="tb_line">
+            <p>
+                <span class="tb_label">服务点</span>
+                <input id="station" name="station_data" />
+            </p>
+            <p>
+                <span class="tb_label">开始</span>
+                <input type="text" id="date_start" value="<?php echo date('Y-m-d', strtotime('-6 month' ,time())); ?>" style="width: 100px;"/>
+                <span class="tb_label">结束</span>
+                <input type="text" id="date_end" value="<?php echo date('Y-m-d', time()); ?>" style="width: 100px;"/>
+                <a href="#" class='easyui-linkbutton' iconCls="icon-search" plain="true" onclick="search_content();return false;">查询</a>
+            </p>
+        </div>
+    </div>
+</div>
+<div region="center" title="统计图表">
+<div class="easyui-layout detail_layout">
+<div data-options="region:'center'" class="detail_center">
+<div class="detail_main">
+    <div data-options="region:'center'" class="detail_center">
+        <div class="detail_main">
+            <form id="content_form" method="post">
+                <p>
+                    <a class="options" href="/index.php?r=stockViewStation/all">总体概览</a>
+                    <span id="days"><a href="/index.php?r=stockViewStation/index" class="options">最近一周</a></span>
+                    <span id="weeks"><a href="/index.php?r=stockViewStation/findByWeeks" class="options">最近一月</a></span>
+                </p>
+            </form>
+            <div id="main_station" style="height:600px;width:900px"></div>
+        </div>
+    </div>
+</div>
+</div>
+
+</div>
+</div>
+</div>
+
+<!-- 引入自动填充选择插件 -->
+<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.js"></script>
+<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.css" />
+<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/selector.js"></script>
+<!-- 用户选择插件引入结束 -->
+<!-- 引入echarts插件 -->
+<script src="http://echarts.baidu.com/build/dist/echarts.js"></script>
+<!-- 引入结束 -->
+<script type="text/javascript">
+// 载入echarts配置
+require.config({
+    paths : {
+        echarts: 'http://echarts.baidu.com/build/dist'
+    }
+});
+
+var jq_dg_content = $('#dg_content');
+var temp = new Date();
+var today = temp.getFullYear() + '-' + (temp.getMonth() + 1) + '-' + temp.getDate();
+var w_width = $(window).width();
+var w_height = $(window).height();
+var jq_content_form = $('#content_form');
+var jq_filter_station = $('#station');
+
+var module_router = site_root + '/index.php?r=stockViewStation';
+
+var jq_date_start = $('#date_start');
+var jq_date_end = $('#date_end');
+
+var station_data = <?php echo json_encode($station_data); ?>;
+
+$(function(){
+    var p_width = parseInt(w_width / 2);
+    if (p_width < 520){
+        p_width = 520;
+    }
+
+    jq_date_start.datebox({});
+
+    jq_date_end.datebox({});
+
+    jq_filter_station.combobox({
+        width: 100,
+        data: station_data,
+        editable: false,
+        onSelect: function () {
+            search_content();
+        }
+    });
+
+    $('#main').css({width: w_width - 25, height: w_height - 18}).layout();
+
+    jq_dg_content.datagrid({
+        url: module_router + '/list',
+        title: '服务点物资领用统计',
+        width: 420,
+        height: w_height - 18,
+        fitColumns: true,
+        autoRowHeight: true,
+        striped: true,
+        toolbar: '#tb_content',
+        singleSelect: true,
+        selectOnCheck: false,
+        checkOnSelect: false,
+        pagination: true,
+        pageList: [20, 30, 50],
+        pageSize: 20,
+        nowrap: false,
+        idField: 'station',
+        sortName: 'price_count',
+        sortOrder: 'desc',
+        queryParams: $.extend(
+            get_param_obj(),
+            {
+                date_start : jq_date_start.datebox('getValue'),
+                date_end : jq_date_end.datebox('getValue'),
+                merge_data_days : 1
+            }
+        ),
+        frozenColumns:[],
+        columns:[[
+            {field:'stationName', title:'服务点',width:30},
+            {field:'operate_count', title:'领取次数', width:20},
+            {field:'price_count', title:'总价格', width:30},
+            {field:'station', title:'操作', width:30,
+                formatter: function (value, row, index) {
+                   // return '<a href="/index.php?r=stock/index&objectName='+row.objectName+'">详情</a>'
+                   return '<a href="javascript:;" onclick="parent.load_url(\'<?php echo Yii::app()->request->baseUrl; ?>/index.php?r=stockViewStation&station='+row['station']+'\');">详情</a>';
+                }
+            }
+        ]],
+
+        onSelect: function(index, row){
+
+            var data = $.extend({}, row);
+            $('#on_loading').show();
+            jq_content_form.form('load', data);
+            var data = row['data'];
+
+            $('#weeks').html('<a class="options" href="/index.php?r=stockViewStation/findByWeeks&station='+row['station']+'">最近一月</a>');
+            $('#days').html('<a class="options" href="/index.php?r=stockViewStation/index&station='+row['station']+'">最近一周</a>');
+
+            require(
+                [
+                    'echarts',
+                    'echarts/chart/line',
+                    'echarts/chart/bar'
+                ],
+                function (ec) {
+                    var material_chart = ec.init(document.getElementById('main_station'));
+
+                    var option = {
+                        title : {
+                            text: row.stationName+'\n'+data.month_range+'物资领取情况',
+                            subtext: ''
+                        },
+                        tooltip : {
+                            trigger: 'axis'
+                        },
+                        legend: {
+                            data:['领取总价']
+                        },
+                        toolbox: {
+                            show : true,
+                            feature : {
+                                mark : {show: true},
+                                dataView : {show: true, readOnly: false},
+                                magicType : {show: true, type: ['line', 'bar']},
+                                restore : {show: true},
+                                saveAsImage : {show: true}
+                            }
+                        },
+                        calculable : true,
+                        xAxis : [
+                            {
+                                type : 'category',
+                                data : data.month_arr
+                            }
+                        ],
+                        yAxis : [
+                            {
+                                type : 'value'
+                            }
+                        ],
+                        series : [
+                            {
+                                name:'领取总价',
+                                type:'line',
+                                data:data.price_count
+                            }
+                        ]
+                    };
+                    material_chart.setOption(option);
+                }
+            );
+        },
+    });
+});
+
+function search_content () {
+    var stationName = jq_filter_station.combobox('getValue');
+    var date_start = jq_date_start.datebox('getValue');
+    var date_end = jq_date_end.datebox('getValue');
+
+    jq_dg_content.datagrid({
+        pageNum: 1,
+        queryParams: {
+            stationName: stationName,
+            date_start: date_start,
+            date_end: date_end,
+            merge_data_months : 1
+        }
+    });
+}
+</script>
+<!-- start echarts -->
+<script type="text/javascript">
+require(
+    [
+        'echarts',
+        'echarts/chart/line',
+        'echarts/chart/bar'
+    ],
+    function (ec) {
+        var material_chart = ec.init(document.getElementById('main_station'));
+
+        var option = {
+            title : {
+                text: '<?php echo $month_range.'\n'.$stationName; ?>物资领取情况',
+                subtext: ''
+            },
+            tooltip : {
+                trigger: 'axis'
+            },
+            legend: {
+                data:['领取总价']
+            },
+            toolbox: {
+                show : true,
+                feature : {
+                    mark : {show: true},
+                    dataView : {show: true, readOnly: false},
+                    magicType : {show: true, type: ['line', 'bar']},
+                    restore : {show: true},
+                    saveAsImage : {show: true}
+                }
+            },
+            calculable : true,
+            xAxis : [
+                {
+                    type : 'category',
+                    data : [<?php echo $month; ?>]
+                }
+            ],
+            yAxis : [
+                {
+                    type : 'value'
+                }
+            ],
+            series : [
+                {
+                    name:'领取总价',
+                    type:'line',
+                    data:[<?php echo $price; ?>],
+                }
+            ]
+        };
+        material_chart.setOption(option);
+        }
+);
+</script>

+ 284 - 0
www/protected/views/stockViewStation/findByWeeks.php

@@ -0,0 +1,284 @@
+<style>
+    .f_label {width: 90px;}
+    .accordion-body {padding: 0;}
+    .options {
+        display: inline-block;
+        border: 1px solid #e5e5e5;
+        background: #fff;
+        color: #000;
+        padding: 3px 6px;
+        text-decoration: none;
+    }
+</style>
+<div id="main">
+<div region="west" border="false" id="west_panel" style="width: 430px;">
+    <table id="dg_content"></table>
+    <div id="tb_content">
+        <div class="tb_line">
+            <p>
+                <span class="tb_label">服务点</span>
+                <input id="station" name="station_data" />
+            </p>
+            <p>
+                <span class="tb_label">开始</span>
+                <input type="text" id="date_start" value="<?php echo date('Y-m-d', strtotime('-1 month' ,time())); ?>" style="width: 100px;"/>
+                <span class="tb_label">结束</span>
+                <input type="text" id="date_end" value="<?php echo date('Y-m-d', time()); ?>" style="width: 100px;"/>
+                <a href="#" class='easyui-linkbutton' iconCls="icon-search" plain="true" onclick="search_content();return false;">查询</a>
+            </p>
+        </div>
+    </div>
+</div>
+<div region="center" title="统计图表">
+<div class="easyui-layout detail_layout">
+<div data-options="region:'center'" class="detail_center">
+<div class="detail_main">
+    <div data-options="region:'center'" class="detail_center">
+        <div class="detail_main">
+            <form id="content_form" method="post">
+                <p>
+                    <a class="options" href="#" onclick="window.location.href='/index.php?r=stockViewStation/all';">总体概览</a>
+                    <span id="days"><a href="/index.php?r=stockViewStation/index" class="options">最近一周</a></span>
+                    <span id="months"><a href="/index.php?r=stockViewStation/findByMonths" class="options">最近半年</a></span>
+                </p>
+            </form>
+            <div id="main_station" style="height:600px;width:900px"></div>
+        </div>
+    </div>
+</div>
+</div>
+</div>
+</div>
+</div>
+
+<!-- 引入自动填充选择插件 -->
+<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.js"></script>
+<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.css" />
+<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/selector.js"></script>
+<!-- 用户选择插件引入结束 -->
+<!-- 引入echarts插件 -->
+<script src="http://echarts.baidu.com/build/dist/echarts.js"></script>
+<!-- 引入结束 -->
+<script type="text/javascript">
+// 载入echarts配置
+require.config({
+    paths : {
+        echarts: 'http://echarts.baidu.com/build/dist'
+    }
+});
+
+var jq_dg_content = $('#dg_content');
+var temp = new Date();
+var today = temp.getFullYear() + '-' + (temp.getMonth() + 1) + '-' + temp.getDate();
+var w_width = $(window).width();
+var w_height = $(window).height();
+var jq_content_form = $('#content_form');
+var jq_filter_station = $('#station');
+var station_data = <?php echo json_encode($station_data); ?>
+
+var module_router = site_root + '/index.php?r=stockViewStation';
+
+var jq_date_start = $('#date_start');
+var jq_date_end = $('#date_end');
+
+$(function(){
+    var p_width = parseInt(w_width / 2);
+    if (p_width < 520){
+        p_width = 520;
+    }
+
+    jq_date_start.datebox({});
+
+    jq_date_end.datebox({});
+
+    jq_filter_station.combobox({
+        width: 100,
+        data: station_data,
+        editable: false,
+        onSelect: function () {
+            search_content();
+        }
+    });
+
+    $('#main').css({width: w_width - 25, height: w_height - 18}).layout();
+
+    jq_dg_content.datagrid({
+        url: module_router + '/list',
+        title: '服务点物资领用统计',
+        width: 420,
+        height: w_height - 18,
+        fitColumns: true,
+        autoRowHeight: true,
+        striped: true,
+        toolbar: '#tb_content',
+        singleSelect: true,
+        selectOnCheck: false,
+        checkOnSelect: false,
+        pagination: true,
+        pageList: [20, 30, 50],
+        pageSize: 20,
+        nowrap: false,
+        idField: 'station',
+        sortName: 'price_count',
+        sortOrder: 'desc',
+        queryParams: $.extend(
+            get_param_obj(),
+            {
+                date_start : jq_date_start.datebox('getValue'),
+                date_end : jq_date_end.datebox('getValue'),
+                merge_data_days : 1
+            }
+        ),
+        frozenColumns:[],
+        columns:[[
+            {field:'stationName', title:'服务点',width:30},
+            {field:'operate_count', title:'领取次数', width:20},
+            {field:'price_count', title:'总价格', width:30},
+            {field:'station', title:'操作', width:30,
+                formatter: function (value, row, index) {
+                   // return '<a href="/index.php?r=stock/index&objectName='+row.objectName+'">详情</a>'
+                   return '<a href="javascript:;" onclick="parent.load_url(\'<?php echo Yii::app()->request->baseUrl; ?>/index.php?r=stockViewStation&station='+row['station']+'\');">详情</a>';
+                }
+            }
+        ]],
+
+        onSelect: function(index, row){
+
+            var data = $.extend({}, row);
+            $('#on_loading').show();
+            jq_content_form.form('load', data);
+            var data = row['data'];
+
+            $('#days').html('<a class="options" href="/index.php?r=stockViewStation/index&station='+row['station']+'">最近一周</a>');
+            $('#months').html('<a class="options" href="/index.php?r=stockViewStation/findByMonths&station='+row['station']+'">最近半年</a>');
+            $('#weeks').html('<a class="options" href="/index.php?r=stockViewStation/findByWeeks&station='+row['station']+'">最近一月</a>');
+
+            require(
+                [
+                    'echarts',
+                    'echarts/chart/line',
+                    'echarts/chart/bar'
+                ],
+                function (ec) {
+                    var material_chart = ec.init(document.getElementById('main_station'));
+
+                    var option = {
+                        title : {
+                            text: row.stationName+'\n'+data.date_range+'物资领取情况',
+                            subtext: ''
+                        },
+                        tooltip : {
+                            trigger: 'axis'
+                        },
+                        legend: {
+                            data:['领取总价']
+                        },
+                        toolbox: {
+                            show : true,
+                            feature : {
+                                mark : {show: true},
+                                dataView : {show: true, readOnly: false},
+                                magicType : {show: true, type: ['line', 'bar']},
+                                restore : {show: true},
+                                saveAsImage : {show: true}
+                            }
+                        },
+                        calculable : true,
+                        xAxis : [
+                            {
+                                type : 'category',
+                                data : data.week_arr
+                            }
+                        ],
+                        yAxis : [
+                            {
+                                type : 'value'
+                            }
+                        ],
+                        series : [
+                            {
+                                name:'领取总价',
+                                type:'line',
+                                data:data.price_count
+                            }
+                        ]
+                    };
+                    material_chart.setOption(option);
+                }
+            );
+        },
+    });
+});
+
+function search_content () {
+    var stationName = jq_filter_station.combobox('getValue');
+    var date_start = jq_date_start.datebox('getValue');
+    var date_end = jq_date_end.datebox('getValue');
+
+    jq_dg_content.datagrid({
+        pageNum: 1,
+        queryParams: {
+            stationName: stationName,
+            date_start: date_start,
+            date_end: date_end,
+            merge_data_weeks : 1
+        }
+    });
+}
+</script>
+<!-- start echarts -->
+<script type="text/javascript">
+require(
+    [
+        'echarts',
+        'echarts/chart/line',
+        'echarts/chart/bar'
+    ],
+    function (ec) {
+        var material_chart = ec.init(document.getElementById('main_station'));
+
+        var option = {
+            title : {
+                text: '<?php echo $date_range.'\n'.$stationName; ?>物资领取情况',
+                subtext: ''
+            },
+            tooltip : {
+                trigger: 'axis'
+            },
+            legend: {
+                data:['领取总价']
+            },
+            toolbox: {
+                show : true,
+                feature : {
+                    mark : {show: true},
+                    dataView : {show: true, readOnly: false},
+                    magicType : {show: true, type: ['line', 'bar']},
+                    restore : {show: true},
+                    saveAsImage : {show: true}
+                }
+            },
+            calculable : true,
+            xAxis : [
+                {
+                    type : 'category',
+                    data : [<?php echo $weeks; ?>]
+                }
+            ],
+            yAxis : [
+                {
+                    type : 'value'
+                }
+            ],
+            series : [
+                {
+                    name:'领取总价',
+                    type:'line',
+                    data:[<?php echo $price; ?>],
+                }
+            ]
+        };
+        material_chart.setOption(option);
+        }
+);
+</script>

+ 287 - 0
www/protected/views/stockViewStation/index.php

@@ -0,0 +1,287 @@
+<style>
+    .f_label {width: 90px;}
+    .accordion-body {padding: 0;}
+    .options {
+        display: inline-block;
+        border: 1px solid #e5e5e5;
+        background: #fff;
+        color: #000;
+        padding: 3px 6px;
+        text-decoration: none;
+    }
+</style>
+<div id="main">
+<div region="west" border="false" id="west_panel" style="width: 430px;">
+    <table id="dg_content"></table>
+    <div id="tb_content">
+        <div class="tb_line">
+            <p>
+                <span class="tb_label">服务点</span>
+                <!-- <input class="station_selector" id="user" placeholder="服务点" style="width: 150px;" /> -->
+                <input id="station" name="station_data" />
+            </p>
+            <p>
+                <span class="tb_label">开始</span>
+                <input type="text" id="date_start" value="<?php echo date('Y-m-d', strtotime('-6 day', time())); ?>" style="width: 100px;"/>
+                <span class="tb_label">结束</span>
+                <input type="text" id="date_end" value="<?php echo date('Y-m-d', time()); ?>" style="width: 100px;"/>
+                <a href="#" class='easyui-linkbutton' iconCls="icon-search" plain="true" onclick="search_content();return false;">查询</a>
+            </p>
+        </div>
+    </div>
+</div>
+<div region="center" title="统计图表">
+<div class="easyui-layout detail_layout">
+<div data-options="region:'center'" class="detail_center">
+<div class="detail_main">
+    <div data-options="region:'center'" class="detail_center">
+        <div class="detail_main">
+            <!-- <input type="hidden" name="id" id="material_id" value='' /> -->
+            <form id="content_form" method="post">
+                <p>
+                    <a class="options" href="#" onclick="window.location.href='/index.php?r=stockViewStation/all';">总体概览</a>
+                    <span id="weeks"><a href="/index.php?r=stockViewStation/findByWeeks" class="options">最近一月</a></span>
+                    <span id="months"><a href="/index.php?r=stockViewStation/findByMonths" class="options">最近半年</a></span>
+                    <span id="months"></span>
+                    <span id="weeks"></span>
+                </p>
+            </form>
+            <div id="main_station" style="height:600px;width:900px"></div>
+        </div>
+    </div>
+</div>
+</div>
+
+</div>
+</div>
+</div>
+
+<!-- 引入自动填充选择插件 -->
+<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.js"></script>
+<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.css" />
+<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/selector.js"></script>
+<!-- 用户选择插件引入结束 -->
+<!-- 引入echarts插件 -->
+<script src="http://echarts.baidu.com/build/dist/echarts.js"></script>
+<!-- 引入结束 -->
+<script type="text/javascript">
+// 载入echarts配置
+require.config({
+    paths : {
+        echarts: 'http://echarts.baidu.com/build/dist'
+    }
+});
+
+var jq_dg_content = $('#dg_content');
+var temp = new Date();
+var today = temp.getFullYear() + '-' + (temp.getMonth() + 1) + '-' + temp.getDate();
+var w_width = $(window).width();
+var w_height = $(window).height();
+var jq_content_form = $('#content_form');
+var jq_filter_station = $('#station');
+
+var module_router = site_root + '/index.php?r=stockViewStation';
+
+var jq_date_start = $('#date_start');
+var jq_date_end = $('#date_end');
+
+var station_data = <?php echo json_encode($station_data); ?>;
+
+$(function(){
+    var p_width = parseInt(w_width / 2);
+    if (p_width < 520){
+        p_width = 520;
+    }
+
+    jq_date_start.datebox({});
+
+    jq_date_end.datebox({});
+
+    jq_filter_station.combobox({
+        width: 100,
+        data: station_data,
+        editable: false,
+        onSelect: function () {
+            search_content();
+        }
+    });
+
+    $('#main').css({width: w_width - 25, height: w_height - 18}).layout();
+
+    jq_dg_content.datagrid({
+        url: module_router + '/list',
+        title: '服务点物资领用统计',
+        width: 420,
+        height: w_height - 18,
+        fitColumns: true,
+        autoRowHeight: true,
+        striped: true,
+        toolbar: '#tb_content',
+        singleSelect: true,
+        selectOnCheck: false,
+        checkOnSelect: false,
+        pagination: true,
+        pageList: [20, 30, 50],
+        pageSize: 20,
+        nowrap: false,
+        idField: 'station',
+        sortName: 'price_count',
+        sortOrder: 'desc',
+        queryParams: $.extend(
+            get_param_obj(),
+            {
+                date_start : jq_date_start.datebox('getValue'),
+                date_end : jq_date_end.datebox('getValue'),
+                merge_data_days : 1
+            }
+        ),
+        frozenColumns:[],
+        columns:[[
+            {field:'stationName', title:'服务点',width:30},
+            {field:'operate_count', title:'领取次数', width:20},
+            {field:'price_count', title:'总价格', width:30},
+            {field:'station', title:'操作', width:30,
+                formatter: function (value, row, index) {
+                   // return '<a href="/index.php?r=stock/index&objectName='+row.objectName+'">详情</a>'
+                   return '<a href="javascript:;" onclick="parent.load_url(\'<?php echo Yii::app()->request->baseUrl; ?>/index.php?r=stock&station='+row['station']+'\');">详情</a>';
+                }
+            }
+        ]],
+
+        onSelect: function(index, row){
+
+            var data = $.extend({}, row);
+            $('#on_loading').show();
+            jq_content_form.form('load', data);
+            var data = row['data'];
+
+            $('#months').html('<a class="options" href="/index.php?r=stockViewStation/findByMonths&station='+row['station']+'">最近半年</a>');
+            $('#weeks').html('<a class="options" href="/index.php?r=stockViewStation/findByWeeks&station='+row['station']+'">最近一月</a>');
+
+            require(
+                [
+                    'echarts',
+                    'echarts/chart/line',
+                    'echarts/chart/bar'
+                ],
+                function (ec) {
+                    var material_chart = ec.init(document.getElementById('main_station'));
+
+                    var option = {
+                        title : {
+                            text: row.stationName+'\n'+data.date_range+'物资领取情况',
+                            subtext: ''
+                        },
+                        tooltip : {
+                            trigger: 'axis'
+                        },
+                        legend: {
+                            data:['领取总价']
+                        },
+                        toolbox: {
+                            show : true,
+                            feature : {
+                                mark : {show: true},
+                                dataView : {show: true, readOnly: false},
+                                magicType : {show: true, type: ['line', 'bar']},
+                                restore : {show: true},
+                                saveAsImage : {show: true}
+                            }
+                        },
+                        calculable : true,
+                        xAxis : [
+                            {
+                                type : 'category',
+                                data : data.date_arr
+                            }
+                        ],
+                        yAxis : [
+                            {
+                                type : 'value'
+                            }
+                        ],
+                        series : [
+                            {
+                                name:'领取总价',
+                                type:'line',
+                                data:data.price_count
+                            }
+                        ]
+                    };
+                    material_chart.setOption(option);
+                }
+            );
+        },
+    });
+});
+
+function search_content () {
+    var stationName = jq_filter_station.combobox('getValue');
+    var date_start = jq_date_start.datebox('getValue');
+    var date_end = jq_date_end.datebox('getValue');
+
+    jq_dg_content.datagrid({
+        pageNum: 1,
+        queryParams: {
+            stationName: stationName,
+            date_start: date_start,
+            date_end: date_end,
+            merge_data_days : 1
+        }
+    });
+}
+</script>
+<script type="text/javascript">
+require(
+    [
+        'echarts',
+        'echarts/chart/line',
+        'echarts/chart/bar'
+    ],
+    function (ec) {
+        var material_chart = ec.init(document.getElementById('main_station'));
+        var option = {
+            title : {
+                text: '<?php echo $stationName ?>'+'\n'+'<?php echo $date_range; ?>'+'物资领取情况',
+                subtext: ''
+            },
+            tooltip : {
+                trigger: 'axis'
+            },
+            legend: {
+                data:['领取总价']
+            },
+            toolbox: {
+                show : true,
+                feature : {
+                    mark : {show: true},
+                    dataView : {show: true, readOnly: false},
+                    magicType : {show: true, type: ['line', 'bar']},
+                    restore : {show: true},
+                    saveAsImage : {show: true}
+                }
+            },
+            calculable : true,
+            xAxis : [
+                {
+                    type : 'category',
+                    data : [<?php echo $date_str; ?>]
+                }
+            ],
+            yAxis : [
+                {
+                    type : 'value'
+                }
+            ],
+            series : [
+                {
+                    name:'领取总价',
+                    type:'line',
+                    data:[<?php echo $price_count; ?>]
+                }
+            ]
+        };
+        material_chart.setOption(option);
+    }
+);
+</script>

+ 238 - 0
www/protected/views/stockViewUser/all.php

@@ -0,0 +1,238 @@
+<style>
+    .f_label {width: 90px;}
+    .accordion-body {padding: 0;}
+    .options {
+        display: inline-block;
+        border: 1px solid #e5e5e5;
+        background: #fff;
+        color: #000;
+        padding: 3px 6px;
+        text-decoration: none;
+    }
+</style>
+<div id="main">
+<div region="west" border="false" id="west_panel" style="width: 430px;">
+    <table id="dg_content"></table>
+    <div id="tb_content">
+        <div class="tb_line">
+            <p>
+                <span class="tb_label">目标用户</span>
+                <input class="user_selector" id="user" placeholder="目标用户" style="width: 150px;" />
+            </p>
+            <p>
+                <span class="tb_label">开始</span>
+                <input type="text" id="date_start" value="<?php echo date('Y-m-d', $date_start); ?>" style="width: 100px;"/>
+                <span class="tb_label">结束</span>
+                <input type="text" id="date_end" value="<?php echo date('Y-m-d', strtotime('-1 day', $date_end)); ?>" style="width: 100px;"/>
+                <a href="#" class='easyui-linkbutton' iconCls="icon-search" plain="true" onclick="search_content();return false;">查询</a>
+            </p>
+        </div>
+    </div>
+</div>
+<div region="center" title="统计图表">
+<div class="easyui-layout detail_layout">
+<div data-options="region:'center'" class="detail_center">
+<div class="detail_main">
+    <div data-options="region:'center'" class="detail_center">
+        <div class="detail_main">
+            <form id="search_by_time" method="post" action="/index.php?r=stockViewUser/all">
+                    <p>
+                        <input type="text" name="date_start" id="date_start_search" value="<?php echo date('Y-m-d', $date_start); ?>"/>
+                        <input type="text" name="date_end" id="date_end_search" value="<?php echo date('Y-m-d', strtotime('-1 day', $date_end)); ?>"/>
+                        <input type="submit" value="搜索" />
+                    </p>
+                    <p>
+                        <span><a href="/index.php?r=stockViewUser/index" class="options">最近一周</a></span>
+                        <span><a href="/index.php?r=stockViewUser/findByWeeks" class="options">最近一月</a></span>
+                        <span><a href="/index.php?r=stockViewUser/findByMonths" class="options">最近半年</a></span>
+                    </p>
+            </form>
+            <div id="main_station" style="height:450px;width:900px"></div>
+        </div>
+    </div>
+</div>
+</div>
+
+</div>
+</div>
+</div>
+<!-- 引入自动填充选择插件 -->
+<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.js"></script>
+<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.css" />
+<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/selector.js"></script>
+<!-- 用户选择插件引入结束 -->
+<!-- 引入echarts插件 -->
+<script src="http://echarts.baidu.com/build/dist/echarts.js"></script>
+<!-- 引入结束 -->
+<script type="text/javascript">
+var jq_dg_content = $('#dg_content');
+var temp = new Date();
+var today = temp.getFullYear() + '-' + (temp.getMonth() + 1) + '-' + temp.getDate();
+var w_width = $(window).width();
+var w_height = $(window).height();
+var jq_content_form = $('#content_form');
+
+var module_router = site_root + '/index.php?r=stockViewUser';
+
+var jq_date_start = $('#date_start');
+var jq_date_end = $('#date_end');
+
+var jq_date_start_search = $('#date_start_search');
+var jq_date_end_search = $('#date_end_search');
+
+$(function(){
+    var p_width = parseInt(w_width / 2);
+    if (p_width < 520){
+        p_width = 520;
+    }
+
+    jq_date_start.datebox({});
+
+    jq_date_end.datebox({});
+
+    jq_date_start_search.datebox({});
+
+    jq_date_end_search.datebox({});
+
+    $('#main').css({width: w_width - 25, height: w_height - 18}).layout();
+
+    jq_dg_content.datagrid({
+        url: module_router + '/list',
+        title: '用户物资领用统计',
+        width: 420,
+        height: w_height - 18,
+        fitColumns: true,
+        autoRowHeight: true,
+        striped: true,
+        toolbar: '#tb_content',
+        singleSelect: true,
+        selectOnCheck: false,
+        checkOnSelect: false,
+        pagination: true,
+        pageList: [20, 30, 50],
+        pageSize: 20,
+        nowrap: false,
+        idField: 'object',
+        sortName: 'price_count',
+        sortOrder: 'desc',
+        queryParams: $.extend(
+            get_param_obj(),
+            {
+                date_start : jq_date_start.datebox('getValue'),
+                date_end : jq_date_end.datebox('getValue'),
+                merge_data_days : 1
+            }
+        ),
+        frozenColumns:[],
+        columns:[[
+            {field:'objectName', title:'用户',width:30},
+            {field:'operate_count', title:'领取次数', width:20},
+            {field:'price_count', title:'总价格', width:30},
+            {field:'object', title:'操作', width:30,
+                formatter: function (value, row, index) {
+                   var formatString = '<a href="javascript:;" onclick="parent.load_url(\'<?php echo Yii::app()->request->baseUrl; ?>/index.php?r=stockViewUser&object='+row['object']+'\');">图表</a>';
+                   formatString += '&nbsp<a href="javascript:;" onclick="parent.load_url(\'<?php echo Yii::app()->request->baseUrl; ?>/index.php?r=stock&s_user='+row['objectName']+'\');">详情</a>';
+                   return formatString;
+                }
+            }
+        ]],
+
+        onSelect: function(index, row){
+
+            var data = $.extend({}, row);
+
+            jq_content_form.form('reset');
+        },
+    });
+});
+
+function search_content () {
+    var s_user = $('#user').val();
+    var date_start = jq_date_start.datebox('getValue');
+    var date_end = jq_date_end.datebox('getValue');
+
+    jq_dg_content.datagrid({
+        pageNum: 1,
+        queryParams: {
+            s_user: s_user,
+            date_start: date_start,
+            date_end: date_end
+        }
+    });
+}
+</script>
+<!-- start echarts -->
+<script type="text/javascript">
+require.config({
+    paths : {
+        echarts: 'http://echarts.baidu.com/build/dist'
+    }
+});
+
+require(
+    [
+        'echarts',
+        'echarts/chart/pie',
+        'echarts/chart/funnel'
+    ],
+    function (ec) {
+        var material_chart = ec.init(document.getElementById('main_station'));
+
+        option = {
+            title : {
+                text: '<?php echo $date_range; ?>领用物资总价分布',
+                subtext: '',
+                x:'center'
+            },
+            tooltip : {
+                trigger: 'item',
+                formatter: "{a} <br/>{b} : {c} ({d}%)"
+            },
+            legend: {
+                orient : 'vertical',
+                y : 'bottom',
+                x : 'left',
+                data:[<?php echo $objectNames; ?>]
+            },
+            toolbox: {
+                show : true,
+                feature : {
+                    mark : {show: true},
+                    dataView : {show: true, readOnly: false},
+                    magicType : {
+                        show: true, 
+                        type: ['pie', 'funnel'],
+                        option: {
+                            funnel: {
+                                x: '25%',
+                                width: '50%',
+                                funnelAlign: 'left',
+                                max: 1548
+                            }
+                        }
+                    },
+                    restore : {show: true},
+                    saveAsImage : {show: true}
+                }
+            },
+            calculable : true,
+            series : [
+                {
+                    name:'目标用户',
+                    type:'pie',
+                    radius : '55%',
+                    center: ['50%', '60%'],
+                    data:[
+                    <?php foreach ($price_count_arr as $key => $value) { ?>
+                        {
+                            value:<?php echo $value; ?>,
+                            name:"<?php echo $key; ?>"
+                        },
+                    <?php } ?>
+                    ]
+                }
+            ]
+        };material_chart.setOption(option);
+    }
+);
+</script>

+ 274 - 0
www/protected/views/stockViewUser/findByMonths.php

@@ -0,0 +1,274 @@
+<style>
+    .f_label {width: 90px;}
+    .accordion-body {padding: 0;}
+    .options {
+        display: inline-block;
+        border: 1px solid #e5e5e5;
+        background: #fff;
+        color: #000;
+        padding: 3px 6px;
+        text-decoration: none;
+    }
+</style>
+<div id="main">
+<div region="west" border="false" id="west_panel" style="width: 430px;">
+    <table id="dg_content"></table>
+    <div id="tb_content">
+        <div class="tb_line">
+            <p>
+                <span class="tb_label">目标用户</span>
+                <input class="user_selector" id="user" placeholder="目标用户" style="width: 150px;" />
+            </p>
+            <p>
+                <span class="tb_label">开始</span>
+                <input type="text" id="date_start" value="<?php echo date('Y-m-d', strtotime('-6 month' ,time())); ?>" style="width: 100px;"/>
+                <span class="tb_label">结束</span>
+                <input type="text" id="date_end" value="<?php echo date('Y-m-d', time()); ?>" style="width: 100px;"/>
+                <a href="#" class='easyui-linkbutton' iconCls="icon-search" plain="true" onclick="search_content();return false;">查询</a>
+            </p>
+        </div>
+    </div>
+</div>
+<div region="center" title="统计图表">
+<div class="easyui-layout detail_layout">
+<div data-options="region:'center'" class="detail_center">
+<div class="detail_main">
+    <div data-options="region:'center'" class="detail_center">
+        <div class="detail_main">
+            <form id="content_form" method="post">
+                <p>
+                    <a class="options" href="/index.php?r=stockViewUser/all">总体概览</a>
+                    <span id="days"><a href="/index.php?r=stockViewUser/index" class="options">最近一周</a></span>
+                    <span id="weeks"><a href="/index.php?r=stockViewUser/findByWeeks" class="options">最近一月</a></span>
+                </p>
+            </form>
+            <div id="main_station" style="height:600px;width:900px"></div>
+        </div>
+    </div>
+</div>
+</div>
+
+</div>
+</div>
+</div>
+
+<!-- 引入自动填充选择插件 -->
+<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.js"></script>
+<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.css" />
+<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/selector.js"></script>
+<!-- 用户选择插件引入结束 -->
+<!-- 引入echarts插件 -->
+<script src="http://echarts.baidu.com/build/dist/echarts.js"></script>
+<!-- 引入结束 -->
+<script type="text/javascript">
+// 载入echarts配置
+require.config({
+    paths : {
+        echarts: 'http://echarts.baidu.com/build/dist'
+    }
+});
+
+var jq_dg_content = $('#dg_content');
+var temp = new Date();
+var today = temp.getFullYear() + '-' + (temp.getMonth() + 1) + '-' + temp.getDate();
+var w_width = $(window).width();
+var w_height = $(window).height();
+var jq_content_form = $('#content_form');
+
+var module_router = site_root + '/index.php?r=stockViewUser';
+
+var jq_date_start = $('#date_start');
+var jq_date_end = $('#date_end');
+
+$(function(){
+    var p_width = parseInt(w_width / 2);
+    if (p_width < 520){
+        p_width = 520;
+    }
+
+    jq_date_start.datebox({});
+
+    jq_date_end.datebox({});
+
+    $('#main').css({width: w_width - 25, height: w_height - 18}).layout();
+
+    jq_dg_content.datagrid({
+        url: module_router + '/list',
+        title: '用户物资领用统计',
+        width: 420,
+        height: w_height - 18,
+        fitColumns: true,
+        autoRowHeight: true,
+        striped: true,
+        toolbar: '#tb_content',
+        singleSelect: true,
+        selectOnCheck: false,
+        checkOnSelect: false,
+        pagination: true,
+        pageList: [20, 30, 50],
+        pageSize: 20,
+        nowrap: false,
+        idField: 'object',
+        sortName: 'price_count',
+        sortOrder: 'desc',
+        queryParams: $.extend(
+            get_param_obj(),
+            {
+                date_start : jq_date_start.datebox('getValue'),
+                date_end : jq_date_end.datebox('getValue'),
+                merge_data_days : 1
+            }
+        ),
+        frozenColumns:[],
+        columns:[[
+            {field:'objectName', title:'用户',width:30},
+            {field:'operate_count', title:'领取次数', width:20},
+            {field:'price_count', title:'总价格', width:30},
+            {field:'object', title:'操作', width:30,
+                formatter: function (value, row, index) {
+                   var formatString = '<a href="javascript:;" onclick="parent.load_url(\'<?php echo Yii::app()->request->baseUrl; ?>/index.php?r=stockViewUser&object='+row['object']+'\');">图表</a>';
+                   formatString += '&nbsp<a href="javascript:;" onclick="parent.load_url(\'<?php echo Yii::app()->request->baseUrl; ?>/index.php?r=stock&s_user='+row['objectName']+'\');">详情</a>';
+                   return formatString;
+                }
+            }
+        ]],
+
+        onSelect: function(index, row){
+
+            var data = $.extend({}, row);
+            $('#on_loading').show();
+            jq_content_form.form('load', data);
+            var data = row['data'];
+
+            $('#weeks').html('<a class="options" href="/index.php?r=stockViewUser/findByWeeks&object='+row['object']+'">最近一月</a>');
+            $('#days').html('<a class="options" href="/index.php?r=stockViewUser/index&object='+row['object']+'">最近一周</a>');
+
+            require(
+                [
+                    'echarts',
+                    'echarts/chart/line',
+                    'echarts/chart/bar'
+                ],
+                function (ec) {
+                    var material_chart = ec.init(document.getElementById('main_station'));
+
+                    var option = {
+                        title : {
+                            text: row.objectName+'\n'+data.month_range+'物资领取情况',
+                            subtext: ''
+                        },
+                        tooltip : {
+                            trigger: 'axis'
+                        },
+                        legend: {
+                            data:['领取总价']
+                        },
+                        toolbox: {
+                            show : true,
+                            feature : {
+                                mark : {show: true},
+                                dataView : {show: true, readOnly: false},
+                                magicType : {show: true, type: ['line', 'bar']},
+                                restore : {show: true},
+                                saveAsImage : {show: true}
+                            }
+                        },
+                        calculable : true,
+                        xAxis : [
+                            {
+                                type : 'category',
+                                data : data.month_arr
+                            }
+                        ],
+                        yAxis : [
+                            {
+                                type : 'value'
+                            }
+                        ],
+                        series : [
+                            {
+                                name:'领取总价',
+                                type:'line',
+                                data:data.price_count
+                            }
+                        ]
+                    };
+                    material_chart.setOption(option);
+                }
+            );
+        },
+    });
+});
+
+function search_content () {
+    var s_user = $('#user').val();
+    var date_start = jq_date_start.datebox('getValue');
+    var date_end = jq_date_end.datebox('getValue');
+
+    jq_dg_content.datagrid({
+        pageNum: 1,
+        queryParams: {
+            s_user: s_user,
+            date_start: date_start,
+            date_end: date_end,
+            merge_data_months : 1
+        }
+    });
+}
+</script>
+<!-- start echarts -->
+<script type="text/javascript">
+require(
+    [
+        'echarts',
+        'echarts/chart/line',
+        'echarts/chart/bar'
+    ],
+    function (ec) {
+        var material_chart = ec.init(document.getElementById('main_station'));
+
+        var option = {
+            title : {
+                text: '<?php echo $month_range.'\n'.$objectName; ?>物资领取情况',
+                subtext: ''
+            },
+            tooltip : {
+                trigger: 'axis'
+            },
+            legend: {
+                data:['领取总价']
+            },
+            toolbox: {
+                show : true,
+                feature : {
+                    mark : {show: true},
+                    dataView : {show: true, readOnly: false},
+                    magicType : {show: true, type: ['line', 'bar']},
+                    restore : {show: true},
+                    saveAsImage : {show: true}
+                }
+            },
+            calculable : true,
+            xAxis : [
+                {
+                    type : 'category',
+                    data : [<?php echo $month; ?>]
+                }
+            ],
+            yAxis : [
+                {
+                    type : 'value'
+                }
+            ],
+            series : [
+                {
+                    name:'领取总价',
+                    type:'line',
+                    data:[<?php echo $price; ?>],
+                }
+            ]
+        };
+        material_chart.setOption(option);
+        }
+);
+</script>

+ 274 - 0
www/protected/views/stockViewUser/findByWeeks.php

@@ -0,0 +1,274 @@
+<style>
+    .f_label {width: 90px;}
+    .accordion-body {padding: 0;}
+    .options {
+        display: inline-block;
+        border: 1px solid #e5e5e5;
+        background: #fff;
+        color: #000;
+        padding: 3px 6px;
+        text-decoration: none;
+    }
+</style>
+<div id="main">
+<div region="west" border="false" id="west_panel" style="width: 430px;">
+    <table id="dg_content"></table>
+    <div id="tb_content">
+        <div class="tb_line">
+            <p>
+                <span class="tb_label">目标用户</span>
+                <input class="user_selector" id="user" placeholder="目标用户" style="width: 150px;" />
+            </p>
+            <p>
+                <span class="tb_label">开始</span>
+                <input type="text" id="date_start" value="<?php echo date('Y-m-d', strtotime('-1 month' ,time())); ?>" style="width: 100px;"/>
+                <span class="tb_label">结束</span>
+                <input type="text" id="date_end" value="<?php echo date('Y-m-d', time()); ?>" style="width: 100px;"/>
+                <a href="#" class='easyui-linkbutton' iconCls="icon-search" plain="true" onclick="search_content();return false;">查询</a>
+            </p>
+        </div>
+    </div>
+</div>
+<div region="center" title="统计图表">
+<div class="easyui-layout detail_layout">
+<div data-options="region:'center'" class="detail_center">
+<div class="detail_main">
+    <div data-options="region:'center'" class="detail_center">
+        <div class="detail_main">
+            <form id="content_form" method="post">
+                <p>
+                    <a class="options" href="#" onclick="window.location.href='/index.php?r=stockViewUser/all';">总体概览</a>
+                    <span id="days"><a href="/index.php?r=stockViewUser/index" class="options">最近一周</a></span>
+                    <span id="months"><a href="/index.php?r=stockViewUser/findByMonths" class="options">最近半年</a></span>
+                </p>
+            </form>
+            <div id="main_station" style="height:600px;width:900px"></div>
+        </div>
+    </div>
+</div>
+</div>
+</div>
+</div>
+</div>
+
+<!-- 引入自动填充选择插件 -->
+<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.js"></script>
+<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.css" />
+<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/selector.js"></script>
+<!-- 用户选择插件引入结束 -->
+<!-- 引入echarts插件 -->
+<script src="http://echarts.baidu.com/build/dist/echarts.js"></script>
+<!-- 引入结束 -->
+<script type="text/javascript">
+// 载入echarts配置
+require.config({
+    paths : {
+        echarts: 'http://echarts.baidu.com/build/dist'
+    }
+});
+
+var jq_dg_content = $('#dg_content');
+var temp = new Date();
+var today = temp.getFullYear() + '-' + (temp.getMonth() + 1) + '-' + temp.getDate();
+var w_width = $(window).width();
+var w_height = $(window).height();
+var jq_content_form = $('#content_form');
+
+var module_router = site_root + '/index.php?r=stockViewUser';
+
+var jq_date_start = $('#date_start');
+var jq_date_end = $('#date_end');
+
+$(function(){
+    var p_width = parseInt(w_width / 2);
+    if (p_width < 520){
+        p_width = 520;
+    }
+
+    jq_date_start.datebox({});
+
+    jq_date_end.datebox({});
+
+    $('#main').css({width: w_width - 25, height: w_height - 18}).layout();
+
+    jq_dg_content.datagrid({
+        url: module_router + '/list',
+        title: '用户物资领用统计',
+        width: 420,
+        height: w_height - 18,
+        fitColumns: true,
+        autoRowHeight: true,
+        striped: true,
+        toolbar: '#tb_content',
+        singleSelect: true,
+        selectOnCheck: false,
+        checkOnSelect: false,
+        pagination: true,
+        pageList: [20, 30, 50],
+        pageSize: 20,
+        nowrap: false,
+        idField: 'object',
+        sortName: 'price_count',
+        sortOrder: 'desc',
+        queryParams: $.extend(
+            get_param_obj(),
+            {
+                date_start : jq_date_start.datebox('getValue'),
+                date_end : jq_date_end.datebox('getValue'),
+                merge_data_days : 1
+            }
+        ),
+        frozenColumns:[],
+        columns:[[
+            {field:'objectName', title:'用户',width:30},
+            {field:'operate_count', title:'领取次数', width:20},
+            {field:'price_count', title:'总价格', width:30},
+            {field:'object', title:'操作', width:30,
+                formatter: function (value, row, index) {
+                   var formatString = '<a href="javascript:;" onclick="parent.load_url(\'<?php echo Yii::app()->request->baseUrl; ?>/index.php?r=stockViewUser&object='+row['object']+'\');">图表</a>';
+                   formatString += '&nbsp<a href="javascript:;" onclick="parent.load_url(\'<?php echo Yii::app()->request->baseUrl; ?>/index.php?r=stock&s_user='+row['objectName']+'\');">详情</a>';
+                   return formatString;
+                }
+            }
+        ]],
+
+        onSelect: function(index, row){
+
+            var data = $.extend({}, row);
+            $('#on_loading').show();
+            jq_content_form.form('load', data);
+            var data = row['data'];
+
+            $('#days').html('<a class="options" href="/index.php?r=stockViewUser/index&object='+row['object']+'">最近一周</a>');
+            $('#months').html('<a class="options" href="/index.php?r=stockViewUser/findByMonths&object='+row['object']+'">最近半年</a>');
+            $('#weeks').html('<a class="options" href="/index.php?r=stockViewUser/findByWeeks&object='+row['object']+'">最近一月</a>');
+
+            require(
+                [
+                    'echarts',
+                    'echarts/chart/line',
+                    'echarts/chart/bar'
+                ],
+                function (ec) {
+                    var material_chart = ec.init(document.getElementById('main_station'));
+
+                    var option = {
+                        title : {
+                            text: row.objectName+'\n'+data.date_range+'物资领取情况',
+                            subtext: ''
+                        },
+                        tooltip : {
+                            trigger: 'axis'
+                        },
+                        legend: {
+                            data:['领取总价']
+                        },
+                        toolbox: {
+                            show : true,
+                            feature : {
+                                mark : {show: true},
+                                dataView : {show: true, readOnly: false},
+                                magicType : {show: true, type: ['line', 'bar']},
+                                restore : {show: true},
+                                saveAsImage : {show: true}
+                            }
+                        },
+                        calculable : true,
+                        xAxis : [
+                            {
+                                type : 'category',
+                                data : data.week_arr
+                            }
+                        ],
+                        yAxis : [
+                            {
+                                type : 'value'
+                            }
+                        ],
+                        series : [
+                            {
+                                name:'领取总价',
+                                type:'line',
+                                data:data.price_count
+                            }
+                        ]
+                    };
+                    material_chart.setOption(option);
+                }
+            );
+        },
+    });
+});
+
+function search_content () {
+    var s_user = $('#user').val();
+    var date_start = jq_date_start.datebox('getValue');
+    var date_end = jq_date_end.datebox('getValue');
+
+    jq_dg_content.datagrid({
+        pageNum: 1,
+        queryParams: {
+            s_user: s_user,
+            date_start: date_start,
+            date_end: date_end,
+            merge_data_weeks : 1
+        }
+    });
+}
+</script>
+<!-- start echarts -->
+<script type="text/javascript">
+require(
+    [
+        'echarts',
+        'echarts/chart/line',
+        'echarts/chart/bar'
+    ],
+    function (ec) {
+        var material_chart = ec.init(document.getElementById('main_station'));
+
+        var option = {
+            title : {
+                text: '<?php echo $date_range.'\n'.$objectName; ?>物资领取情况',
+                subtext: ''
+            },
+            tooltip : {
+                trigger: 'axis'
+            },
+            legend: {
+                data:['领取总价']
+            },
+            toolbox: {
+                show : true,
+                feature : {
+                    mark : {show: true},
+                    dataView : {show: true, readOnly: false},
+                    magicType : {show: true, type: ['line', 'bar']},
+                    restore : {show: true},
+                    saveAsImage : {show: true}
+                }
+            },
+            calculable : true,
+            xAxis : [
+                {
+                    type : 'category',
+                    data : [<?php echo $weeks; ?>]
+                }
+            ],
+            yAxis : [
+                {
+                    type : 'value'
+                }
+            ],
+            series : [
+                {
+                    name:'领取总价',
+                    type:'line',
+                    data:[<?php echo $price; ?>],
+                }
+            ]
+        };
+        material_chart.setOption(option);
+        }
+);
+</script>

+ 276 - 0
www/protected/views/stockViewUser/index.php

@@ -0,0 +1,276 @@
+<style>
+    .f_label {width: 90px;}
+    .accordion-body {padding: 0;}
+    .options {
+        display: inline-block;
+        border: 1px solid #e5e5e5;
+        background: #fff;
+        color: #000;
+        padding: 3px 6px;
+        text-decoration: none;
+    }
+</style>
+<div id="main">
+<div region="west" border="false" id="west_panel" style="width: 430px;">
+    <table id="dg_content"></table>
+    <div id="tb_content">
+        <div class="tb_line">
+            <p>
+                <span class="tb_label">目标用户</span>
+                <input class="user_selector" id="user" placeholder="目标用户" style="width: 150px;" />
+            </p>
+            <p>
+                <span class="tb_label">开始</span>
+                <input type="text" id="date_start" value="<?php echo date('Y-m-d', strtotime('-6 day', time())); ?>" style="width: 100px;"/>
+                <span class="tb_label">结束</span>
+                <input type="text" id="date_end" value="<?php echo date('Y-m-d', time()); ?>" style="width: 100px;"/>
+                <a href="#" class='easyui-linkbutton' iconCls="icon-search" plain="true" onclick="search_content();return false;">查询</a>
+            </p>
+        </div>
+    </div>
+</div>
+<div region="center" title="统计图表">
+<div class="easyui-layout detail_layout">
+<div data-options="region:'center'" class="detail_center">
+<div class="detail_main">
+    <div data-options="region:'center'" class="detail_center">
+        <div class="detail_main">
+            <!-- <input type="hidden" name="id" id="material_id" value='' /> -->
+            <form id="content_form" method="post">
+                <p>
+                    <input type="hidden" name="object" id="object">
+                    <a class="options" href="#" onclick="window.location.href='/index.php?r=stockViewUser/all';">总体概览</a>
+                    <span id="weeks"><a href="/index.php?r=stockViewUser/findByWeeks" class="options">最近一月</a></span>
+                    <span id="months"><a href="/index.php?r=stockViewUser/findByMonths" class="options">最近半年</a></span>
+                    <span id="months"></span>
+                    <span id="weeks"></span>
+                </p>
+            </form>
+            <div id="main_station" style="height:600px;width:900px"></div>
+        </div>
+    </div>
+</div>
+</div>
+
+</div>
+</div>
+</div>
+
+<!-- 引入自动填充选择插件 -->
+<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.js"></script>
+<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.css" />
+<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/selector.js"></script>
+<!-- 用户选择插件引入结束 -->
+<!-- 引入echarts插件 -->
+<script src="http://echarts.baidu.com/build/dist/echarts.js"></script>
+<!-- 引入结束 -->
+<script type="text/javascript">
+// 载入echarts配置
+require.config({
+    paths : {
+        echarts: 'http://echarts.baidu.com/build/dist'
+    }
+});
+
+var jq_dg_content = $('#dg_content');
+var temp = new Date();
+var today = temp.getFullYear() + '-' + (temp.getMonth() + 1) + '-' + temp.getDate();
+var w_width = $(window).width();
+var w_height = $(window).height();
+var jq_content_form = $('#content_form');
+
+var module_router = site_root + '/index.php?r=stockViewUser';
+
+var jq_date_start = $('#date_start');
+var jq_date_end = $('#date_end');
+
+$(function(){
+    var p_width = parseInt(w_width / 2);
+    if (p_width < 520){
+        p_width = 520;
+    }
+
+    jq_date_start.datebox({});
+
+    jq_date_end.datebox({});
+
+    $('#main').css({width: w_width - 25, height: w_height - 18}).layout();
+
+    jq_dg_content.datagrid({
+        url: module_router + '/list',
+        title: '用户物资领用统计',
+        width: 420,
+        height: w_height - 18,
+        fitColumns: true,
+        autoRowHeight: true,
+        striped: true,
+        toolbar: '#tb_content',
+        singleSelect: true,
+        selectOnCheck: false,
+        checkOnSelect: false,
+        pagination: true,
+        pageList: [20, 30, 50],
+        pageSize: 20,
+        nowrap: false,
+        idField: 'object',
+        sortName: 'price_count',
+        sortOrder: 'desc',
+        queryParams: $.extend(
+            get_param_obj(),
+            {
+                date_start : jq_date_start.datebox('getValue'),
+                date_end : jq_date_end.datebox('getValue'),
+                merge_data_days : 1
+            }
+        ),
+        frozenColumns:[],
+        columns:[[
+            {field:'objectName', title:'用户',width:30},
+            {field:'operate_count', title:'领取次数', width:20},
+            {field:'price_count', title:'总价格', width:30},
+            {field:'object', title:'操作', width:30,
+                formatter: function (value, row, index) {
+                   var formatString = '<a href="javascript:;" onclick="parent.load_url(\'<?php echo Yii::app()->request->baseUrl; ?>/index.php?r=stockViewUser&object='+row['object']+'\');">图表</a>';
+                   formatString += '&nbsp<a href="javascript:;" onclick="parent.load_url(\'<?php echo Yii::app()->request->baseUrl; ?>/index.php?r=stock&s_user='+row['objectName']+'\');">详情</a>';
+                   return formatString;
+                }
+            }
+        ]],
+
+        onSelect: function(index, row){
+
+            var data = $.extend({}, row);
+            $('#on_loading').show();
+            jq_content_form.form('load', data);
+            var data = row['data'];
+
+            $('#months').html('<a class="options" href="/index.php?r=stockViewUser/findByMonths&object='+row['object']+'">最近半年</a>');
+            $('#weeks').html('<a class="options" href="/index.php?r=stockViewUser/findByWeeks&object='+row['object']+'">最近一月</a>');
+
+            require(
+                [
+                    'echarts',
+                    'echarts/chart/line',
+                    'echarts/chart/bar'
+                ],
+                function (ec) {
+                    var material_chart = ec.init(document.getElementById('main_station'));
+
+                    var option = {
+                        title : {
+                            text: row.objectName+'\n'+data.date_range+'物资领取情况',
+                            subtext: ''
+                        },
+                        tooltip : {
+                            trigger: 'axis'
+                        },
+                        legend: {
+                            data:['领取总价']
+                        },
+                        toolbox: {
+                            show : true,
+                            feature : {
+                                mark : {show: true},
+                                dataView : {show: true, readOnly: false},
+                                magicType : {show: true, type: ['line', 'bar']},
+                                restore : {show: true},
+                                saveAsImage : {show: true}
+                            }
+                        },
+                        calculable : true,
+                        xAxis : [
+                            {
+                                type : 'category',
+                                data : data.date_arr
+                            }
+                        ],
+                        yAxis : [
+                            {
+                                type : 'value'
+                            }
+                        ],
+                        series : [
+                            {
+                                name:'领取总价',
+                                type:'line',
+                                data:data.price_count
+                            }
+                        ]
+                    };
+                    material_chart.setOption(option);
+                }
+            );
+        },
+    });
+});
+
+function search_content () {
+    var s_user = $('#user').val();
+    var date_start = jq_date_start.datebox('getValue');
+    var date_end = jq_date_end.datebox('getValue');
+
+    jq_dg_content.datagrid({
+        pageNum: 1,
+        queryParams: {
+            s_user: s_user,
+            date_start: date_start,
+            date_end: date_end,
+            merge_data_days : 1
+        }
+    });
+}
+</script>
+<script type="text/javascript">
+require(
+    [
+        'echarts',
+        'echarts/chart/line',
+        'echarts/chart/bar'
+    ],
+    function (ec) {
+        var material_chart = ec.init(document.getElementById('main_station'));
+        var option = {
+            title : {
+                text: '<?php echo $objectName ?>'+'\n'+'<?php echo $date_range; ?>'+'物资领取情况',
+                subtext: ''
+            },
+            tooltip : {
+                trigger: 'axis'
+            },
+            legend: {
+                data:['领取总价']
+            },
+            toolbox: {
+                show : true,
+                feature : {
+                    mark : {show: true},
+                    dataView : {show: true, readOnly: false},
+                    magicType : {show: true, type: ['line', 'bar']},
+                    restore : {show: true},
+                    saveAsImage : {show: true}
+                }
+            },
+            calculable : true,
+            xAxis : [
+                {
+                    type : 'category',
+                    data : [<?php echo $date_str; ?>]
+                }
+            ],
+            yAxis : [
+                {
+                    type : 'value'
+                }
+            ],
+            series : [
+                {
+                    name:'领取总价',
+                    type:'line',
+                    data:[<?php echo $price_count; ?>]
+                }
+            ]
+        };
+        material_chart.setOption(option);
+    }
+);
+</script>