123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722 |
- <?php
- class ROrderController extends AdminController{
- public function actionIndex()
- {
- $status_option = ROrder::$status_option;
- $status = CommonFn::getComboboxData($status_option, 100, true, 100);
- $channel_option = ROrder::$channel_option;
- $channels = CommonFn::getComboboxData($channel_option, 100, true, 100);
- // 服务信息
- $criteria_main = new EMongoCriteria();
- $criteria_main->status('==', 1);
- $cursor_main = Product::model()->findAll($criteria_main);
- $rows_main = CommonFn::getRowsFromCursor($cursor_main);
- $main_row = array();
- foreach($rows_main as $row){
- $ids = (string)$row['_id'];
- $main_row[$ids] = array('name' =>$row['name']);
- }
- $main_products = CommonFn::getComboboxData($main_row, 100, true, 100);
- // 服务点信息
- $criteria_station = new EMongoCriteria();
- $cursor = Station::model()->findAll($criteria_station);
- $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 = CommonFn::getComboboxData($station_data, 'all', true, 'all');
- // 订单类型
- $type_data = Yii::app()->params['o2o_service'];
- $type = CommonFn::getComboboxData($type_data, 100, true, 100);
- $this->render('index', array(
- 'status' => $status,
- 'main_products'=> $main_products,
- 'channels' => $channels,
- 'station' => $station,
- 'type' => $type
- ));
- }
- public function actionList(){
- $filter_status = intval(Yii::app()->request->getParam('status', 100));
- $search = Yii::app()->request->getParam('search', '');
- $id = Yii::app()->request->getParam('id', '');
- $date_start_order = Yii::app()->request->getParam('date_start_order');
- $date_end_order = Yii::app()->request->getParam('date_end_order');
- $date_start_book= Yii::app()->request->getParam('date_start_book');
- $date_end_book = Yii::app()->request->getParam('date_end_book');
- $type = Yii::app()->request->getParam('type', 100);
- $have_pay = Yii::app()->request->getParam('have_pay', 0);
- $channel = Yii::app()->request->getParam('channel', 100);
- //$station = Yii::app()->request->getParam('station', 'all');
- $params = CommonFn::getPageParams();
- $criteria = new EMongoCriteria($params);
- if ($filter_status != 100){
- $criteria->status('==', $filter_status);
- }
- if ($id != ''){
- $order_id = new MongoId($id);
- $criteria->_id('==', $order_id);
- }
- if ($channel != 100){
- $criteria->channel('==', $channel);
- }
- if ($type != 100) {
- $criteria->type = $type;
- }
- if ($search != ''){
- if(CommonFn::isMongoId($search)){
- //$criteria->_id('==', new MongoId($search));
- $criteria->addCond('_id','or',new MongoId($search));
- $criteria->addCond('user','or',new MongoId($search));
- }
- else if(preg_match('/\d{8,11}/', $search)){
- $criteria->addCond('address.mobile','==',$search);
- if($have_pay){
- $criteria->addCond('status','>',0);
- }
- }else if(strlen($search) == 27){
- $criteria->charge_id('==', $search);
- }else{
- $criteria->addCond('address.name','==',$search);
- }
- }
- // 下单时间处理
- if (!empty($date_start_order) && !empty($date_end_order)) {
- // 开始时间处理
- $timestamp_start_order = strtotime($date_start_order);
- // 结束时间处理,需通过strototime()增加一天
- $timestamp_end_order = strtotime('+1 day', strtotime($date_end_order));
- $criteria->order_time('>=', $timestamp_start_order);
- $criteria->order_time('<=', $timestamp_end_order);
- }
- // 预约时间处理
- if (!empty($date_start_book) && !empty($date_end_book)) {
- // 开始时间处理
- $timestamp_start_book = strtotime($date_start_book);
- // 结束时间处理,需通过strototime()增加一天
- $timestamp_end_book = strtotime('+1 day', strtotime($date_end_book));
- $criteria->booking_time('>=', $timestamp_start_book);
- $criteria->booking_time('<=', $timestamp_end_book);
- }
- // 服务站处理
- // if ($station != 'all') {
- // $criteria->station = new MongoId($station);
- //}
- $cursor = ROrder::model()->findAll($criteria);
- $total = $cursor->count();
- $rows = CommonFn::getRowsFromCursor($cursor);
- $parsedRows = ROrder::model()->parse($rows);
- echo CommonFn::composeDatagridData($parsedRows, $total);
- }
- public function actionEdit(){
- $id = Yii::app()->request->getParam('id', '');
- $status = intval(Yii::app()->request->getParam('status',1));
- $counts = intval(Yii::app()->request->getParam('count',1));
- $booking_time = intval(Yii::app()->request->getParam('booking_time', time()));
- $deal_time = intval(Yii::app()->request->getParam('deal_time', time()));
- $remark = Yii::app()->request->getParam('remark', '');
- $tech_money = Yii::app()->request->getParam('tech_money','');//保洁师车费
- //$station = Yii::app()->request->getParam('station_id', '');
- $technician_ids = array();
- $technician_names = array();
- $technicians = array();
- $nums = Yii::app()->request->getParam('tech_nums');
- for($i=0;$i<=$nums;$i++) {
- if(Yii::app()->request->getParam('extra_add_info_'.$i)) {
- $technician_ids[] = Yii::app()->request->getParam('extra_add_info_id_'.$i);
- $technician_names[] = Yii::app()->request->getParam('extra_add_info_'.$i);
- }
- }
- if(!$counts){
- CommonFn::requestAjax(false, '购买数量错误');
- }
- // 保洁师信息检查
- // 根据ID直接查询保洁师信息(优先使用联想功能)
- if (isset($technician_ids)) {
- foreach($technician_ids as $key => $technician_id){
- $technician_obj = TechInfo::get($technician_id);
- if ($technician_obj) {
- $technicians[$key]['technician_id'] = $technician_obj->_id;
- $technicians[$key]['technician_name'] = $technician_obj->name;
- } else {
- CommonFn::requestAjax(false, '保洁师不存在');
- break;
- }
- }
- // ID为0时根据输入框信息查询
- } else if (isset($technician_names)) {
- $criteria = new EMongoCriteria();
- foreach($technician_names as $key => $technician_name) {
- $criteria->name = $technician_name;
- $technician_obj = TechInfo::model()->find($criteria);
- if ($technician_obj) {
- $technicians[$key]['technician_id'] = $technician_obj->_id;
- $technicians[$key]['technician_name'] = $technician_obj->name;
- } else {
- CommonFn::requestAjax(false, '保洁师不存在');
- break;
- }
- }
- } else {
- $technician_obj = null;
- //$technician_id = 0;
- // $technician_name = '';
- foreach($technicians as $key => $value) {
- $technicians[$key]['$technician_id'] = 0;
- $technicians[$key]['$technician_name'] = 0;
- }
- }
- //var_dump($technicians);exit;
- if($status == 100){
- CommonFn::requestAjax(false, '必须指定状态!');
- }
- $criteria = new EMongoCriteria();
- $criteria->_id = new MongoId($id);
- $order = ROrder::model()->find($criteria);
- // if($order->status == -1 || $order->status == -2){
- // CommonFn::requestAjax(false, '已取消,已退款订单不支持更改');
- // }
- // 获取用户信息,修改用户订单统计
- // 2015-11-16
- $user_id = $order->user;
- if (!empty($user_id)) {
- $user = RUser::get($user_id);
- } else {
- $user = '';
- }
- if (empty($order)){
- CommonFn::requestAjax(false, '订单不存在');
- }
- $flag = 0;
- //精佰退单接口 状态为申请退款并且是精佰的订单
- if ($order->status == -3 && $order->channel == 'jingbai') {
- //确认申请退款状态变更成已退款订单 为退单订单
- $res = '';
- $criteria = new EMongoCriteria();
- $criteria->OrderNo('==',$order->OrderNo);
- $criteria->status('==',-3);
- $orders = ROrder::model()->findAll($criteria);
- $orderId = '';
- $fin_price = 0.0;
- foreach ($orders as $value) {
- $orderId .= (string)$value->_id.',';
- $fin_price =$fin_price+ $value->final_price*0.5;
- }
- $fin_price = round($fin_price,2)*100;
- $orderId = rtrim(trim($orderId),',');
- if ($status == -2) {
- if ($remark == '1') {//退单 全额
- //已出发 已上门 订单
- $res = self::feedbackOrder(1, $order->OrderNo, $orderId, $fin_price);
- } else {//退单 不退钱
- $res = self::feedbackOrder(1, $order->OrderNo, $orderId, 0);
- }
- $flag = 1;
- } else if($status == 2 ){//不退单
- $res = self::feedbackOrder(0,$order->OrderNo,$orderId,0);
- $flag = 1;
- }
- if( $order->booking_time != $booking_time){
- self::feedbackOrderRemaker(0,$order->OrderNo,$orderId,0,$order->booking_time);
- }
- if ($flag && $res){
- foreach ($orders as $value) {
- $value->status = $status;
- $value->save();
- }
- }
- }
- if(($order->status!=-1||$order->status!=-2)&&($status==-1||$status==-2)){
- foreach ($order->coupons as $user_coupon) {
- $user_coupon = UserCoupon::get($user_coupon);
- $user_coupon->status = 1;
- $user_coupon->update(array('status'),true);
- }
- }
- if($order->status!=-2 && $status == -2) {
- $order->refund_time = time();
- $order_info = $order->parseRow($order);
- $month = date('m', $order_info['booking_time']);
- $day = date('d', $order_info['booking_time']);
- $address = $order_info['address']['poi']['name'] . $order_info['address']['detail'];
- CommonSMS::send('order_retrieve', array('month' => $month, 'day' => $day, 'address' => $address, 'mobile' => $order_info['address']['mobile']));
- // 申请退款处理完成后通知保洁师
- foreach ($technician_ids as $key => $technician_id) {
- $technician_obj = TechInfo::get($technician_id);
- if ($technician_obj && $technician_obj->weixin_userid) {
- $url_prefix = ENVIRONMENT == 'product' ? 'http://api.yiguanjia.me' : 'http://apitest.yiguanjia.me';
- $wechat = O2oApp::getWechatActive();
- $wechat_data = array(
- 'touser' => $technician_obj->weixin_userid,
- 'msgtype' => 'news',
- 'agentid' => '1',
- 'news' => array(
- 'articles' => array(
- array(
- 'title' => '壹管家提示-订单退款完成',
- 'description' => $technician_obj->name . '你好!用户于' . date('m月d日H:i', $order->apply_refund_time) . '申请退款的订单已处理完成。',
- //'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_id,
- 'url' => $url_prefix . '/index.php?r=o2o/myOrder/index'
- ),
- ),
- ),
- );
- if (!empty($order->append_orders)) {
- $count = count($order->append_orders);
- $wechat_data['news']['articles'][0]['description'] .= "\n\n本订单包含" . $count . "个追加订单,请注意查看。";
- }
- $wechat->sendMessage($wechat_data);
- }
- }
-
- }
- //取消订单
- if($order->status!=-1 && $status == -1){
- // 已完成订单不能取消
- if ($order->status == 6) {
- CommonFn::requestAjax(false, '已完成订单不可取消');
- }
- $order->cancel_time = time();
- $order_info = $order->parseRow($order);
- }
- //确认接单
- if($order->status!=3 && $status == 3){
- $order_info = $order->parseRow($order);
- }
- //订单完成后执行
- if($order->status!=6 && $status == 6 ){
- $order->finish_time = time();
- $order_info = $order->parseRow($order);
- /*$result = Service::factory('ScoreService')->changeScore((string)$order->user,intval($order->final_price),'下单奖爪币');
- if($result){
- $z_message = new ZMessage();
- $from_user = Yii::app()->params['sys_user'];
- $message_data = array(
- 'from_user' => $from_user,
- 'to_user' => (string)$order->user,
- 'content' => '您成功下单,获得了'.intval($order->final_price).'个爪币的奖励。',
- 'pics' => array(),
- 'voice' => array(),
- 'video'=> array()
- );
- $z_message->addMessage($message_data);
- CommonSMS::send('final_order',array('name' =>$order_info['address']['name'],'num' =>intval($order->final_price),'mobile'=>$order_info['address']['mobile']));
- }*/
- // 保洁师订单统计处理
- foreach($technician_ids as $key => $technician_id) {
- $technician_obj = TechInfo::get($technician_id);
- if ($technician_obj) {
- $tech_order_count = $technician_obj->order_count + 1;
- $technician_obj->order_count = $tech_order_count;
- $technician_obj->save();
- }
- }
- }
- $order->status = $status;
- $order->booking_time = $booking_time;
- $order->deal_time = $deal_time;
- $order->remark = $remark;
- $order->counts = $counts;
- $order->tech_money = $tech_money;//保洁师车费录入
- //$order->station = new MongoId($station);
- // 是否通知保洁师
- $toTech = !empty($order->technicians)? true : false;
- //$order->technician = $technician_id;
- //$order->technician_name = $technician_name;
- $order->technicians = $technicians;
- //var_dump($order);exit;
- //判断是否为实惠或金百订单
- if($order->channel == 'shihui'){
- if ($status == 1) {//已支付
- $res = self::UpdateStatus((string)$order->_id, 5);
- $flag = 1;
- } else if($status ==3){//已接单
- $res = self::UpdateStatus((string)$order->_id, 15);
- $flag = 1;
- }else if($status ==6){//服务完成
- $res = self::UpdateStatus((string)$order->_id, 20);
- $flag = 1;
- }else if($status ==-1){//取消订单
- $res = self::DelOrder((string)$order->_id);
- $flag = 1;
- }
- }else if($order->channel == 'jingbai'){
- if($status ==3){//已接单
- $res = self::UpdateStatusForJingBai($order->OrderNo,(string)$order->_id, $status,$order->remark);
- $flag = 1;
- }else if($status ==6){//服务完成
- $res = self::UpdateStatusForJingBai($order->OrderNo,(string)$order->_id, $status,$order->remark);
- $flag = 1;
- }
- }
- if($flag){
- if (!$res) {
- CommonFn::requestAjax(false,'修改失败res='.$res.',flag='.$flag);
- }
- }
- $arr_order = array('tech_money','cancel_time','refund_time','finish_time','status','booking_time','deal_time','remark', 'station', 'technicians');
- $success = $order->save(true,$arr_order);
- $char = false;
- // 通知保洁师
- if (in_array($status, array(1,2,3,4,5)) && $toTech && $success) {
- foreach($technician_ids as $key => $technician_id) {
- $technician_obj = TechInfo::get($technician_id);
- if ($technician_obj && $technician_obj->weixin_userid) {
- $url_prefix = ENVIRONMENT == 'product' ? 'http://api.yiguanjia.me' : 'http://apitest.yiguanjia.me';
- $wechat = O2oApp::getWechatActive();
- $wechat_data = array(
- 'touser' => $technician_obj->weixin_userid,
- 'msgtype' => 'news',
- 'agentid' => 1,
- 'news' => array(
- 'articles' => array(
- array(
- 'title' => '壹管家提示-新订单',
- 'description' => $technician_obj->name . '你好!刚刚有一个新的订单被分配给你,请点击查看。',
- //'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_id,
- 'url' => $url_prefix . '/index.php?r=o2o/myOrder/index'
- ),
- ),
- ),
- );
- $char = $wechat->sendMessage($wechat_data);
- }
- }
- }
- CommonFn::requestAjax($success, '微信'.$char, array());
- }
- // 根据手机号 获取对应用户的地址信息
- public function actionGetUserInfo(){
- $mobile = Yii::app()->request->getParam('mobile', '');
- $length = strlen($mobile);
- if ($length < 11) {
- $result[] = array(
- 'id' => 0,
- 'data' => '',
- 'description' => '请继续输入',
- 'content' => array()
- );
- echo json_encode($result);exit;
- }
- // $mobile_regex = new MongoRegex($mobile);
- $criteria = new EMongoCriteria();
- $criteria->sort('order_time', EMongoCriteria::SORT_DESC);
- $criteria->addCond('address.mobile', '==', $mobile);
- $cursor = ROrder::model()->findAll($criteria);
- $rows = CommonFn::getRowsFromCursor($cursor);
- if (empty($rows)) {
- $result[] = array(
- 'id' => 0,
- 'data' => '',
- 'description' => '没有匹配信息',
- 'content' => array()
- );
- echo json_encode($result);exit;
- }
- $result = array();
- $details = array();
- $index = 0;
- foreach($rows as $row){
- // 加入根据detail筛选,避免产生重复信息
- if (in_array($row['address']['detail'], $details)) continue;
- $details[] = $row['address']['detail'];
- $pio = isset($row['address']['poi']['name'])?$row['address']['poi']['name']:'';
- // 坐标获取(根据不同的来源)
- if ($row['channel'] == 'dianping') {
- $latitude = $row['address']['position']['lat'];
- $longitude = $row['address']['position']['lng'];
- } else {
- $latitude = isset($row['address']['position']['1'])?$row['address']['position']['1']:'';
- $longitude = isset($row['address']['position']['0'])?$row['address']['position']['0']:'';
- }
- // poi获取
- $poi_name = isset($row['address']['poi']['name']) ? $row['address']['poi']['name'] : '';
- $poi_uid = isset($row['address']['poi']['uid']) ? $row['address']['poi']['uid'] : '';
- $result[] = array(
- 'id' => $index,
- 'data' => $row['address']['mobile'],
- 'description' => $row['address']['province'].' '.$row['address']['city'].' '.$row['address']['area'].' '.$pio.$row['address']['detail'],
- 'content' => array(
- 'name' => $row['address']['name'],
- 'latitude' => $latitude,
- 'longitude' => $longitude,
- 'province' => $row['address']['province'],
- 'city' => $row['address']['city'],
- 'area' => $row['address']['area'],
- 'detail' => $row['address']['detail'],
- 'poi_name' => $poi_name,
- 'poi_uid' => $poi_uid,
- 'memo' => $row['memo']
- )
- );
- $index++;
- }
- echo json_encode($result);exit;
- }
- public function actionAdd () {
- // ------ 必须传入的数值 ------
- // --------- 订单信息 ---------
- $channel = Yii::app()->request->getParam('channel', '');
- $booking_time = Yii::app()->request->getParam('booking_time_add', '');
- $order_time = Yii::app()->request->getParam('order_time_add', '');
- $main_products = Yii::app()->request->getParam('main_products', '');
- $price = floatval(Yii::app()->request->getParam('price', 0));
- $final_price = floatval(Yii::app()->request->getParam('final_price', 0));
- $status = Yii::app()->request->getParam('status', -3);
- $station = Yii::app()->request->getParam('station', '57db39709f5160bb048b456a');
- // --------- 地址信息 ---------
- $mobile = Yii::app()->request->getParam('mobile', 0);
- $latitude = Yii::app()->request->getParam('latitude', 0);
- $longitude = Yii::app()->request->getParam('longitude', 0);
- $province = Yii::app()->request->getParam('province', '');
- $city = Yii::app()->request->getParam('city', '');
- $area = Yii::app()->request->getParam('area', '');
- $poi_name = Yii::app()->request->getParam('poi_name', '');
- $detail = Yii::app()->request->getParam('detail', '');
- $counts = intval(Yii::app()->request->getParam('counts', 1));
- $counts = $counts?$counts:1;
- $extra = Yii::app()->request->getParam('extra','[]');
- $extra = json_decode($extra);
- // 数据完整性检查
- // 2015-11-02 因存在赠送订单,删除金额的数据检查 : $price == 0 || $final_price == 0 ||
- // 2015-11-16 取消服务点录入,删除服务点数据检查 : || empty($station)
- $flag = empty($channel) || empty($booking_time) || empty($order_time);
- $flag = $flag || $status == -3;
- $flag = $flag || $mobile == 0 || $latitude == 0 || $longitude == 0;
- $flag = $flag || empty($province) || empty($city) || empty($area) || empty($poi_name) || empty($detail);
- if ($flag) {
- CommonFn::requestAjax(false, '请检查数据完整性', array());
- exit;
- }
- //if($channel == 'wz_app' || $channel == 'wx_pub'){
- //CommonFn::requestAjax(false, '不能录入渠道为壹管家微信||壹管家APP的订单', array());
- //exit;
- //}
- // 时间处理
- $booking_time = strtotime($booking_time);
- $order_time = strtotime($order_time);
- // ------ 可以留空的数值 ------
- $box = Yii::app()->request->getParam('box', array());
- $coupons = Yii::app()->request->getParam('coupons', array());
- $memo = Yii::app()->request->getParam('memo', '');
- $remark = Yii::app()->request->getParam('remark', '');
- $precedence = Yii::app()->request->getParam('precedence', 0);
- $have_comment = Yii::app()->request->getParam('have_comment', 0);
- $name = Yii::app()->request->getParam('name', '');
- $type = Yii::app()->request->getParam('type', 0);
- $user = Yii::app()->request->getParam('user', '');
- $poi_uid = Yii::app()->request->getParam('poi_uid', '');
- // 用户名的判断
- $channel_option = ROrder::$channel_option;
- $name = empty($name) ? $channel_option[$channel]['name'].'用户' : $name;
- // 支付渠道
- $pay_channel = $channel;
- // 服务数据整合
- $products[] = array(
- 'product' => new MongoId($main_products),
- 'count' => 1,
- 'extra' =>$extra
- );
- if (!empty($box)) {
- foreach ($box as $key => $value) {
- $products[] = array(
- 'product' => new MongoId($value),
- 'count' => 1,
- 'extra' =>$extra
- );
- }
- }
- // 地址数据整合
- $address = array(
- 'province' => $province,
- 'city' => $city,
- 'area' => $area,
- 'detail' => $detail,
- 'mobile' => $mobile,
- 'position' => array(
- // 'lat' => (float)$latitude,
- // 'lng' => (float)$longitude,
- 0 => (float)$longitude,
- 1 => (float)$latitude
- ),
- 'poi' => array(
- 'name' => $poi_name,
- 'uid' => $poi_uid
- ),
- 'name' => $name
- );
- // 订单类型判断
- if ($type == 0) {
- $criteria = new EMongoCriteria();
- $criteria->_id = new MongoId($main_products);
- $cursor = Product::model()->find($criteria);
- $type = $cursor->type;
- }
- $rOrder = new ROrder();
- $rOrder->channel = $channel;
- $rOrder->booking_time = intval($booking_time);
- $rOrder->order_time = intval($order_time);
- $rOrder->products = $products;
- $rOrder->price = floatval($price);
- $rOrder->final_price = floatval($final_price);
- $rOrder->precedence = intval($precedence);
- $rOrder->counts = $counts;
- $rOrder->coupons = $coupons;
- $rOrder->user = $user;
- $rOrder->status = intval($status);
- $rOrder->memo = $memo;
- $rOrder->remark = $remark;
- $rOrder->type = strval($type); // 数据库内使用string类型
- $rOrder->have_comment = intval($have_comment);
- $rOrder->station = new MongoId($station);
- $rOrder->address = $address;
- $rOrder->pay_channel = $pay_channel;
- $addROrder_arr = array('channel', 'booking_time', 'order_time', 'price','products', 'final_price', 'counts','precedence', 'coupons', 'user', 'status', 'memo', 'remark', 'type', 'have_comment', 'station', 'address', 'pay_channel');
- $success = $rOrder->save(true, $addROrder_arr);
- CommonFn::requestAjax($success, '', array());
- }
- /**
- * 请求申请退款订单接口
- */
- public function actionCheckRefundOrder() {
- $criteria = new EMongoCriteria();
- $criteria->status('==', -3);
- $cursor = ROrder::model()->findAll($criteria);
- $count = $cursor->count();
- if ($count > 0) {
- $data = array('code' => 1, 'count' => $count);
- } else {
- $data = array('code' => 0, 'count' => $count);
- }
- $list = new ARedisList('append_order_list');
- if($list->getCount() > 0){
- $key = $list->shift();
- $list->unshift($key);
- $data['procession_append_order_id'] = $key;
- $data['code'] = 2;
- }
- echo json_encode($data);
- }
- public function actionCancelProcess() {
- $orderid = Yii::app()->request->getParam('orderid','');
- $list = new ARedisList('append_order_list');
- $key = $list->shift();
- }
- /**
- * 重新选择保洁师接口
- */
- public function actionResetTech() {
- $id = Yii::app()->request->getParam('id', '');
- $nums = Yii::app()->request->getParam('nums', '');
- $technicians = array();
- $technician_ids = array();
- $technician_names = array();
- for($i=1;$i<=$nums;$i++) {
- if(Yii::app()->request->getParam('reset_extra_add_info_'.$i)) {
- $technician_ids[] = Yii::app()->request->getParam('reset_extra_add_info_id_'.$i);
- $technician_names[] = Yii::app()->request->getParam('reset_extra_add_info_'.$i);
- }
- }
- // 保洁师信息检查
- // 根据ID直接查询保洁师信息(优先使用联想功能)
- $technician_objs = array();
- foreach($technician_ids as $key => $technician_id) {
- if ($technician_id != 0) {
- $technician_obj = TechInfo::get($technician_id);
- if ($technician_obj) {
- $technicians[$key]['technician_id'] = $technician_obj->_id;
- $technicians[$key]['technician_name'] = $technician_obj->name;
- } else {
- CommonFn::requestAjax(false, '保洁师不存在');
- }
- // ID为0时根据输入框信息查询
- } else {
- foreach ($technician_names as $key => $technician_name)
- if ($technician_name != '') {
- $criteria = new EMongoCriteria();
- $criteria->name = $technician_name;
- $technician_obj = TechInfo::model()->find($criteria);
- if ($technician_obj) {
- $technicians[$key]['technician_id'] = $technician_obj->_id;
- $technicians[$key]['technician_name'] = $technician_obj->name;
- } else {
- CommonFn::requestAjax(false, '保洁师不存在');
- }
- } else {
- CommonFn::requestAjax(false, '保洁师姓名不能为空');
- }
- }
- $technician_objs[] = $technician_obj;
- }
- $orderid = new MongoId($id);
- $order = ROrder::model()->get($orderid);
- $toTech = isset($order->technicians) ? true : false;
- $fromTechs = $technician_names;
- //$order->technician = $technician_id;
- //$order->technician_name = $technician_name;
- $order->technicians = $technicians;
- $success = $order->save(true, array('technicians'));
- if ($toTech && $success) {
- foreach ($technician_objs as $technician_obj) {
- // 发送给被分配保洁师
- $wechat = O2oApp::getWechatActive();
- $url_prefix = ENVIRONMENT == 'product' ? 'http://api.yiguanjia.me' : 'http://apitest.yiguanjia.me';
- if (!empty($technician_obj->weixin_userid)) {
- $wechat_data = array(
- 'touser' => $technician_obj->weixin_userid,
- 'msgtype' => 'news',
- 'agentid' => '1',
- 'news' => array(
- 'articles' => array(
- array(
- 'title' => '壹管家提示-新订单',
- 'description' => $technician_obj->name . '你好!刚刚有一个新的订单被分配给你,请点击查看。',
- //'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_obj->_id,
- 'url' => $url_prefix . '/index.php?r=o2o/myOrder/index'
- ),
- ),
- ),
- );
- $wechat->sendMessage($wechat_data);
- }
- }
- // 发送给原保洁师
- foreach ($fromTechs as $fromTech) {
- $fromTechObj = TechInfo::get($fromTech);
- if (!empty($fromTechObj) && !empty($fromTechObj->weixin_userid)) {
- $wechat_data = array(
- 'touser' => $fromTechObj->weixin_userid,
- 'msgtype' => 'news',
- 'agentid' => '1',
- 'news' => array(
- 'articles' => array(
- array(
- 'title' => '壹管家提示-订单已被重新分配',
- 'description' => $fromTechObj->name . '你好!预定时间在' . date('m月d日H:i', $order->booking_time) . '的订单已被分配给其他保洁师。',
- 'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_obj->_id,
- ),
- ),
- ),
- );
- $wechat->sendMessage($wechat_data);
- }
- }
- }
- CommonFn::requestAjax($success, '', array());
- }
- /*public function actionDelOrder(){
- $delOrder = array('5826a4c89f5160d1048b52bf');
- $total = 0;
- foreach($delOrder as $value){
- $order = ROrder::model()->get(new MongoId($value));
- if($order->delete()){
- $total += 1;
- }
- }
- echo $total;
- }*/
- //取消订单
- public function DelOrder($orderId){
- $data['key'] = Yii::app()->params['shKey'];
- $data['version'] = '1.0';
- $data['serviceType'] = (int)26;
- $data['orderId'] = $orderId;//'57fde8059f5160c4048b4aeb';
- ksort($data);
- $str = '';
- $dat = '';
- foreach ($data as $key => $value) {
- $str .= $key.'='.$value.'&';
- $dat .= $key.'='.urlencode($value).'&';
- }
- $str = rtrim(trim($str),'&');
- $str .= $str.Yii::app()->params['shMd5Key'];
- $data['sign'] = strtoupper(md5($str));
- $dat .= 'sign='.urlencode($data['sign']);//构建post 参数
- $url = 'http://test2.app.hiwemeet.com/v2/openpf/home/order/thirdOrder/cancel'; //调用接口的平台服务地址
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
- curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
- $result = curl_exec($ch);
- curl_close($ch);
- $res = json_decode($result,true);
- var_dump($res);
- if ($res['code']){
- return true;
- } else {
- return false;
- }
- }
- //更新订单状态
- public function UpdateStatus($orderId,$status){
- $data['key'] = Yii::app()->params['shKey'];
- $data['version'] = '1.0';
- $data['serviceType'] = (int)26;
- $data['orderId'] = (string)$orderId;
- $data['status'] = $status;
- ksort($data);
- $str = '';
- $dat = '';
- foreach ($data as $key => $value) {
- $str .= $key.'='.$value.'&';
- $dat .= $key.'='.urlencode($value).'&';
- }
- $str = rtrim(trim($str),'&');
- $str .= $str.Yii::app()->params['shMd5Key'];
- $data['sign'] = strtoupper(md5($str));
- $dat .= 'sign='.urlencode($data['sign']);//构建post 参数
- $url = 'http://test2.app.hiwemeet.com/v2/openpf/home/order/thirdOrder/update'; //调用接口的平台服务地址
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
- curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
- $result = curl_exec($ch);
- curl_close($ch);
- $res = json_decode($result,true);
- if ($res['code']){
- return true;
- } else {
- return false;
- }
- }
- //更新订单状态
- /**
- * @param $orderId => order->orderNo
- * @param $status "00" 为创建订单,"01"为服务派单,"02"为服务完成
- * @param $HouseKeepingId 巾帼园自己的订单号 对应order->_id
- * @param $remark 订单备注
- * Sign 计算方法:OrderId+ StatusCode+ Remark+ HouseKeepingId+ Time+KEY 然后计算md5 值 KEY为巾帼园的key值
- * @return bool
- */
- public function UpdateStatusForJingBai($orderId,$HouseKeepingId,$status,$remark){
- $key = Yii::app()->params['JingBai'];
- $data['OrderId'] = $orderId;
- $data['HouseKeepingId'] = $HouseKeepingId;
- $data['Remark'] = $remark;
- if ($status == 3){//已接单
- $data['StatusCode'] = '01';
- } else if($status == 6){//已完成
- $data['StatusCode'] = '02';
- }
- $data['Time'] = date('Y-m-d H:i:s');
- $data['Sign'] = md5($data['OrderId'].$data['StatusCode'].$data['Remark'].$data['HouseKeepingId'].$data['Time'].$key);
- $dat = '';
- foreach ($data as $key => $value) {
- $dat .= $key.'='.urlencode($value).'&';
- }
- $dat = rtrim(trim($dat),'&');
- if (ENVIRONMENT == 'product'){
- $url = 'http://139.196.47.211:9230/ServiceController/SetHouseKeepingStatus'; //正式服调用接口的平台服务地址
- } else {
- $url = 'http://139.196.47.211:9030/ServiceController/SetHouseKeepingStatus'; //调用接口的平台服务地址
- }
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
- curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
- $result = curl_exec($ch);
- curl_close($ch);
- $res = json_decode($result,true);
- if ($res['ReturnCode'] == '00'){
- return true;
- } else {
- return false;
- }
- }
- //不退单, 但是需要修改信息
- public function feedbackOrderRemaker($isCancel,$orderId,$orderNo,$money=0,$remark=null){
- $key = Yii::app()->params['JingBai'];
- $data['IsCancel'] = $isCancel;
- $data['OrderId'] = $orderId;
- $data['OrderNo'] = $orderNo;
- $data['Type'] = 'OrderRemark';
- $data['Remark'] = '修改预约时间'.date('Y-m-d H:i:s',$remark);
- $data['Sign'] = md5($orderId.$orderNo.$data['Remark'].$key);
- $dat = '';
- foreach ($data as $key => $value) {
- $dat .= $key.'='.urlencode($value).'&';
- }
- $dat = rtrim(trim($dat),'&');
- if (ENVIRONMENT == 'product'){
- $url = 'http://139.196.47.211:9230/ServiceController/HouseKeepingFeedback'; //正式服调用接口的平台服务地址
- } else {
- //$url = 'http://123.206.28.63:9030/ServiceController/HouseKeepingFeedback'; //测试服调用接口的平台服务地址
- $url = 'http://139.196.47.211:9030/ServiceController/HouseKeepingFeedback'; //调用接口的平台服务地址
- }
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
- curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
- $result = curl_exec($ch);
- curl_close($ch);
- $res = json_decode($result,true);
- if ($res['ReturnCode'] == '00'){
- return true;
- } else {
- return false;
- }
- }
- //退单反馈信息接口
- /**
- * @param $isCanel 是否退单 1退单 0 不退单
- * @param $orderId 精佰订单Id 对应 巾帼园 OrderNo
- * @param $orderNo 巾帼园订单id 对应 巾帼园_id
- * @param $money 若退单巾帼园需要收多少钱,单位为分,不退单可不传
- * @param null $remark 退单状态备注包含修改信息,无修改此字段可不传
- * @return bool
- */
- public function feedbackOrder($isCancel,$orderId,$orderNo,$money=0)
- {
- $key = Yii::app()->params['JingBai'];
- $data['IsCancel'] = $isCancel;
- $data['OrderId'] = $orderId;
- $data['OrderNo'] = $orderNo;
- if(!$isCancel){//不退单
- $data['Type'] = 'CancleOrder';
- $data['Money'] = $money;
- $data['Sign'] = md5($isCancel.$orderId.$orderNo.$money.$key);
- }
- else {
- $data['Type'] = 'CancleOrder';
- $data['Money'] = $money;
- $data['Sign'] = md5($isCancel.$orderId.$orderNo.$money.$key);
- }
- $dat = '';
- foreach ($data as $key => $value) {
- $dat .= $key.'='.urlencode($value).'&';
- }
- $dat = rtrim(trim($dat),'&');
- if (ENVIRONMENT == 'product'){
- $url = 'http://139.196.47.211:9230/ServiceController/HouseKeepingFeedback'; //正式服调用接口的平台服务地址
- } else {
- //$url = 'http://123.206.28.63:9030/ServiceController/HouseKeepingFeedback'; //测试服调用接口的平台服务地址
- $url = 'http://139.196.47.211:9030/ServiceController/HouseKeepingFeedback'; //调用接口的平台服务地址
- }
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
- curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
- $result = curl_exec($ch);
- curl_close($ch);
- $res = json_decode($result,true);
- if ($res['ReturnCode'] == '00'){
- return true;
- } else {
- return false;
- }
- }
- public function actionOutputExcel(){
- $export =Yii::app()->request->getParam('export','execute_order');
- $export_type = Yii::app()->request->getParam('export_type','');
- if($export == 'execute_order'){
- $endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
- if($export_type == 'day'){
- $name=date('Y-m-d').'日订单执行汇总'; //生成的Excel文件文件名
- $beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
- } else if($export_type == 'week') {
- $name=date('Y-m-d').'周订单执行汇总'; //生成的Excel文件文件名
- $beginYesterday=mktime(0,0,0,date('m'),date('d')-6,date('Y'));
- } else if($export_type == 'month') {
- $name=date('Y-m-d').'月订单执行汇总'; //生成的Excel文件文件名
- $beginYesterday=mktime(0,0,0,date('m')-1,1,date('Y'));
- $endYesterday=mktime(0,0,0,date('m'),1,date('Y'))-1;
- } else if($export_type == 'year'){
- $name=date('Y-m-d').'年订单执行汇总'; //生成的Excel文件文件名
- $beginYesterday=mktime(0,0,0,1,1,2016);
- $endYesterday=mktime(0,0,0,12,1,2017);
- }
- } else {
- $beginYesterday=mktime(0,0,0,date('m')-1,1,date('Y'));
- $endYesterday=mktime(0,0,0,date('m'),1,date('Y'))-1;
- if($export =='tech') {
- $name=date('Y-m-d').'月保洁师营收'; //生成的Excel文件文件名
- } else {
- $name=date('Y-m-d').'月订单明细汇总'; //生成的Excel文件文件名
- }
- }
- $criteria = new EMongoCriteria();
- $criteria->booking_time('>=',$beginYesterday);//开始时间
- $criteria->booking_time('<=',$endYesterday);//结束时间
- $criteria->status('==',6);
- $data = ROrder::model()->findAll($criteria);
- $rows = CommonFn::getRowsFromCursor($data);
- $data = ROrder::model()->parse($rows);
- $res=Service::factory('ExcelToArrayService')->push($data,$name,$export);
- echo "导出成功";
- }
- //导入文件
- public function actionLoad()
- {
- $excelFile = '/var/www/1.xlsx';//获取文件名
- //这里就是导入PHPExcel包了,要用的时候就加这么两句,方便吧
- Yii::$enableIncludePath = false;
- Yii::import('application.extensions.PHPExcel.PHPExcel', 1);
- $phpexcel = new PHPExcel;
- //$excelReader = PHPExcel_IOFactory::createReader('Excel5');
- $excelReader = PHPExcel_IOFactory::createReader('Excel2007');
- $phpexcel = $excelReader->load($excelFile)->getSheet(0);//载入文件并获取第一个sheet
- $total_line = $phpexcel->getHighestRow();
- $total_column = $phpexcel->getHighestColumn();
- for ($row = 2; $row <= $total_line; $row++) {
- $data = array();
- for ($column = 'A'; $column <= $total_column; $column++) {
- $data[] = trim($phpexcel->getCell($column . $row)->getValue());
- }
- var_dump($data);
- echo '<br/>';
- }
- }
- /**
- * 根据服务类型导出一个月的订单折线图
- *
- */
- public function actionExportLineChartForOneMonth()
- {
- Yii::$enableIncludePath = false;
- Yii::import('ext.phpexcel.PHPExcel', 1);
- $objPHPExcel = new PHPExcel();
- $objSheet = $objPHPExcel->getActiveSheet();
- $criteria = new EMongoCriteria();
- $criteria->status('==',1);
- $product = Product::model()->parse(CommonFn::getRowsFromCursor(Product::model()->findAll($criteria)));
- $data = array();
- $data[0][0] = '';
- $days = date("t",mktime(0,0,0,date('m')-1,1,date('Y')));//获取上一个月总天数
- foreach ($product as $key => $value){
- $data[0][$key+1] = $value['type_str'];
- /**
- * 根据获取的产品类型,进行分类,将每一天相同服务类型的总订单存储到数组中,
- */
- for($i=1;$i<=$days;$i++){
- $order_criteria = new EMongoCriteria();
- $order_criteria->type('==',$value['type']);
- $start_time = mktime(0,0,0,date('m')-1,$i,date('Y'));
- $end_time = mktime(23,59,59,date('m')-1,$i,date('Y'));
- $order_criteria->booking_time('>=',$start_time);
- $order_criteria->booking_time('<=',$end_time);
- $orders = ROrder::model()->findAll($order_criteria);
- $data[$i][0] = date('m-d',$start_time);
- //$data[$i][$key+1] = count($orders) == 0?1:count($orders)+1;
- $data[$i][$key+1] = count($orders) == 0?'0':count($orders);
- }
- }
- $objSheet->fromArray($data);
- //图表
- $labels = array(
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$B$1',null,1),//1
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$C$1',null,1),//2
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$D$1',null,1),//3
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$E$1',null,1),//4
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$F$1',null,1),//5
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$G$1',null,1),//6
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$H$1',null,1),//7
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$I$1',null,1),//8
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$J$1',null,1),//9
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$K$1',null,1),//10
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$L$1',null,1),//11
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$M$1',null,1),//12
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$N$1',null,1),//13
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$O$1',null,1),//14
- );
- $xLabels = array(
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$A$2:$A$'.($days+1),null,14),//取x轴刻度
- );
- $datas = array(
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$B$2:$B$'.($days+1),null,14),//1
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$C$2:$C$'.($days+1),null,14),//2
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$D$2:$D$'.($days+1),null,14),//3
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$E$2:$E$'.($days+1),null,14),//4
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$F$2:$F$'.($days+1),null,14),//5
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$G$2:$G$'.($days+1),null,14),//6
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$H$2:$H$'.($days+1),null,14),//7
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$I$2:$I$'.($days+1),null,14),//8
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$J$2:$J$'.($days+1),null,14),//9
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$K$2:$K$'.($days+1),null,14),//10
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$L$2:$L$'.($days+1),null,14),//11
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$M$2:$M$'.($days+1),null,14),//12
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$N$2:$N$'.($days+1),null,14),//13
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$O$2:$O$'.($days+1),null,14),//14
- );
- $series = array(
- new PHPExcel_Chart_DataSeries(
- PHPExcel_Chart_DataSeries::TYPE_LINECHART,
- PHPExcel_Chart_DataSeries::GROUPING_STANDARD,
- range(0, count($datas)-1),
- $labels,
- $xLabels,
- $datas
- )
- ); //图表框架
- $layout=new PHPExcel_Chart_Layout();
- $layout->setShowVal(true);
- $areas = new PHPExcel_Chart_PlotArea(null,$series);
- $legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_BOTTOM,$layout,false);
- $title = new PHPExcel_Chart_Title("订单数角度对比(月)折线图");
- $ytitle = new PHPExcel_Chart_Title("订单数");
- $chart = new PHPExcel_Chart('line_chart',$title,$legend,$areas,true,false,null,$ytitle);
- $chart->setTopLeftPosition("A1")->setBottomRightPosition("P31"); //图表位置
- $objSheet->addChart($chart);
- $excel = 'Excel2007';
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,$excel);
- $objWriter->setIncludeCharts(true); //图表必须
- // $objWriter->save($dir.'/export.xls'); //生成excel文件
- CommonFn::browser_export($excel,date('m')."月份订单数角度对比(月)折线图.xlsx"); //浏览器输出
- CommonFn::SaveViaTempFile($objWriter);
- }
- /**
- * 根据服务类型导出一个周/月的订单柱形图 同比 三周的数据 横轴为服务项目
- *
- */
- public function actionExportColumChartForOneMonth()
- {
- Yii::$enableIncludePath = false;
- Yii::import('ext.phpexcel.PHPExcel', 1);
- $week = Yii::app()->request->getParam('week','1');
- $objPHPExcel = new PHPExcel();
- $objSheet = $objPHPExcel->getActiveSheet();
- $criteria = new EMongoCriteria();
- $criteria->status('==',1);
- $product = Product::model()->parse(CommonFn::getRowsFromCursor(Product::model()->findAll($criteria)));
- $data = array();
- $total = count($product)+1;
- $data[0][0] = '';
- if($week){
- $days = 7;
- foreach ($product as $key => $value) {
- $data[$key + 1][0] = $value['name'];
- /**
- * 根据获取的产品类型,进行分类,将每一周相同服务类型的总订单存储到数组中,
- */
- for ($i=0;$i<=2;$i++){
- $order_criteria = new EMongoCriteria();
- $order_criteria->type('==', $value['type']);
- //1 7 8 14 15 21
- $start_time = mktime(23, 59, 59, date('m'), date('d')-(7*$i+1), date('Y'));
- $end_time = mktime(0, 0, 0, date('m'), date('d')-(($i+1)*7), date('Y'));
- $order_criteria->booking_time('<=', $start_time);
- $order_criteria->booking_time('>=', $end_time);
- $orders = ROrder::model()->findAll($order_criteria);
- $data[0][$i+1] = date('m-d', $start_time);
- $data[$key+1][$i+1] = count($orders) == 0?1:count($orders)+1;
- $data[$key+1][$i + 1] = count($orders) == 0 ? '0' : count($orders);
- }
- /* for ($i = 1; $i <= $days; $i++) {
- $order_criteria = new EMongoCriteria();
- $order_criteria->type('==', $value['type']);
- $start_time = mktime(0, 0, 0, date('m'), date('d')-$i, date('Y'));
- $end_time = mktime(23, 59, 59, date('m'), date('d')-$i, date('Y'));
- $order_criteria->booking_time('>=', $start_time);
- $order_criteria->booking_time('<=', $end_time);
- $orders = ROrder::model()->findAll($order_criteria);
- $data[$i][0] = date('m-d', $start_time);
- $data[$i][$key+1] = count($orders) == 0?1:count($orders)+1;
- $data[$i][$key + 1] = count($orders) == 0 ? '0' : count($orders);
- }*/
- }
- $name = '同比数据分析(周)柱形图.xlsx';
- } else {
- $days = date("t",mktime(0,0,0,date('m')-1,1,date('Y')));//获取上一个月总天数
- foreach ($product as $key => $value){
- $data[0][$key+1] = $value['type_str'];
- /**
- * 根据获取的产品类型,进行分类,将每一天相同服务类型的总订单存储到数组中,
- */
- for($i=1;$i<=$days;$i++){
- $order_criteria = new EMongoCriteria();
- $order_criteria->type('==',$value['type']);
- $start_time = mktime(0,0,0,date('m')-1,$i,date('Y'));
- $end_time = mktime(23,59,59,date('m')-1,$i,date('Y'));
- $order_criteria->booking_time('>=',$start_time);
- $order_criteria->booking_time('<=',$end_time);
- $orders = ROrder::model()->findAll($order_criteria);
- $data[$i][0] = date('m-d',$start_time);
- //$data[$i][$key+1] = count($orders) == 0?1:count($orders)+1;
- $data[$i][$key+1] = count($orders) == 0?'0':count($orders);
- }
- }
- $name = '同比数据分析(月)柱形图.xlsx';
- }
- $objSheet->fromArray($data);
- //图表
- $labels = array(
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$B$1',null,1),//1
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$C$1',null,1),//2
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$D$1',null,1),//3
- );
- $xLabels = array(
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$A$2:$A$'.$total,null,$total),//取x轴刻度
- );
- $datas = array(
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$B$2:$B$'.$total,null,$total),//1
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$C$2:$C$'.$total,null,$total),//2
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$D$2:$D$'.$total,null,$total),//3
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$E$2:$E$'.$total,null,$total),//4
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$F$2:$F$'.$total,null,$total),//5
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$G$2:$G$'.$total,null,$total),//6
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$H$2:$H$'.$total,null,$total),//7
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$I$2:$I$'.$total,null,$total),//8
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$J$2:$J$'.$total,null,$total),//9
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$K$2:$K$'.$total,null,$total),//10
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$L$2:$L$'.$total,null,$total),//11
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$M$2:$M$'.$total,null,$total),//12
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$N$2:$N$'.$total,null,$total),//13
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$O$2:$O$'.$total,null,$total),//14
- );
- /*if($week){
- $labels = array(
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$B$1',null,1),//1
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$C$1',null,1),//2
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$D$1',null,1),//3
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$E$1',null,1),//4
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$F$1',null,1),//5
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$G$1',null,1),//6
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$H$1',null,1),//7
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$I$1',null,1),//8
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$J$1',null,1),//9
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$K$1',null,1),//10
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$L$1',null,1),//11
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$M$1',null,1),//12
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$N$1',null,1),//13
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$O$1',null,1),//14
- );
- $xLabels = array(
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$A$2:$A$8',null,7),//取x轴刻度
- );
- $datas = array(
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$B$2:$B$8',null,7),//1
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$C$2:$C$8',null,7),//2
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$D$2:$D$8',null,7),//3
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$E$2:$E$8',null,7),//4
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$F$2:$F$8',null,7),//5
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$G$2:$G$8',null,7),//6
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$H$2:$H$8',null,7),//7
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$I$2:$I$8',null,7),//8
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$J$2:$J$8',null,7),//9
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$K$2:$K$8',null,7),//10
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$L$2:$L$8',null,7),//11
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$M$2:$M$8',null,7),//12
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$N$2:$N$8',null,7),//13
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$O$2:$O$8',null,7),//14
- );
- } else {
- $labels = array(
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$B$1',null,1),//1
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$C$1',null,1),//2
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$D$1',null,1),//3
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$E$1',null,1),//4
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$F$1',null,1),//5
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$G$1',null,1),//6
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$H$1',null,1),//7
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$I$1',null,1),//8
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$J$1',null,1),//9
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$K$1',null,1),//10
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$L$1',null,1),//11
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$M$1',null,1),//12
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$N$1',null,1),//13
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$O$1',null,1),//14
- );
- $xLabels = array(
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$A$2:$A$'.($days+1),null,14),//取x轴刻度
- );
- $datas = array(
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$B$2:$B$'.($days+1),null,14),//1
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$C$2:$C$'.($days+1),null,14),//2
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$D$2:$D$'.($days+1),null,14),//3
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$E$2:$E$'.($days+1),null,14),//4
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$F$2:$F$'.($days+1),null,14),//5
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$G$2:$G$'.($days+1),null,14),//6
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$H$2:$H$'.($days+1),null,14),//7
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$I$2:$I$'.($days+1),null,14),//8
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$J$2:$J$'.($days+1),null,14),//9
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$K$2:$K$'.($days+1),null,14),//10
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$L$2:$L$'.($days+1),null,14),//11
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$M$2:$M$'.($days+1),null,14),//12
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$N$2:$N$'.($days+1),null,14),//13
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$O$2:$O$'.($days+1),null,14),//14
- );
- }*/
- $series = array(
- new PHPExcel_Chart_DataSeries(
- PHPExcel_Chart_DataSeries::TYPE_BARCHART,
- PHPExcel_Chart_DataSeries::GROUPING_STANDARD,
- range(0, count($labels)-1),
- $labels,
- $xLabels,
- $datas
- )
- ); //图表框架
- $layout=new PHPExcel_Chart_Layout();
- $layout->setShowVal(true);
- $areas = new PHPExcel_Chart_PlotArea(null,$series);
- $legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT,$layout,false);
- $title = new PHPExcel_Chart_Title("同比数据分析");
- $ytitle = new PHPExcel_Chart_Title("订单数");
- $chart = new PHPExcel_Chart('line_chart',$title,$legend,$areas,true,false,null,$ytitle);
- $chart->setTopLeftPosition("A1")->setBottomRightPosition("AI30"); //图表位置
- $objSheet->addChart($chart);
- $excel = 'Excel2007';
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,$excel);
- $objWriter->setIncludeCharts(true); //图表必须
- // $objWriter->save($dir.'/export.xls'); //生成excel文件
- CommonFn::browser_export($excel,date('m').$name); //浏览器输出
- CommonFn::SaveViaTempFile($objWriter);
- }
- /**
- * 根据支付方式导出一个周/月的订单柱形图
- */
- public function actionExportColumChartForOneMonthByChannel()
- {
- Yii::$enableIncludePath = false;
- Yii::import('ext.phpexcel.PHPExcel', 1);
- $week = Yii::app()->request->getParam('week','');
- $objPHPExcel = new PHPExcel();
- $objSheet = $objPHPExcel->getActiveSheet();
- $criteria = new EMongoCriteria();
- $channel = ROrder::$channel_option;
- $data = array();
- $data[0][0] = '';
- $k =1;
- if($week){
- $days = 7;
- foreach ($channel as $key => $value) {
- $data[0][$k] = $value['name'];
- /**
- * 根据获取的产品类型,进行分类,将每一天相同服务类型的总订单存储到数组中,
- */
- for ($i = 1; $i <= $days; $i++) {
- $order_criteria = new EMongoCriteria();
- $order_criteria->channel('==',$key);
- $start_time = mktime(0, 0, 0, date('m'), date('d')-$i, date('Y'));
- $end_time = mktime(23, 59, 59, date('m'), date('d')-$i, date('Y'));
- $order_criteria->booking_time('>=', $start_time);
- $order_criteria->booking_time('<=', $end_time);
- $orders = ROrder::model()->findAll($order_criteria);
- $data[$i][0] = date('m-d', $start_time);
- //$data[$i][$key+1] = count($orders) == 0?1:count($orders)+1;
- $data[$i][$k] = count($orders) == 0 ? '0' : count($orders);
- }
- $k ++;
- }
- $name = "支付方式分析(周)柱形图.xlsx";
- } else {
- $days = date("t",mktime(0,0,0,date('m')-1,1,date('Y')));//获取上一个月总天数
- foreach ($channel as $key => $value){
- $data[0][$k] = $value['name'];
- /**
- * 根据获取的支付类型,进行分类,将每一天相同服务类型的总订单存储到数组中,
- */
- for($i=1;$i<=$days;$i++){
- $order_criteria = new EMongoCriteria();
- $order_criteria->channel('==',$key);
- $start_time = mktime(0,0,0,date('m')-1,$i,date('Y'));
- $end_time = mktime(23,59,59,date('m')-1,$i,date('Y'));
- $order_criteria->booking_time('>=',$start_time);
- $order_criteria->booking_time('<=',$end_time);
- $orders = ROrder::model()->findAll($order_criteria);
- $data[$i][0] = date('m-d',$start_time);
- //$data[$i][$key+1] = count($orders) == 0?1:count($orders)+1;
- $data[$i][$k] = count($orders) == 0?'0':count($orders);
- }
- $k++;
- }
- $name = "支付方式分析(月)柱形图.xlsx";
- }
- $objSheet->fromArray($data);
- //图表
- $labels = array(
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$B$1',null,1),//1
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$C$1',null,1),//2
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$D$1',null,1),//3
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$E$1',null,1),//4
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$F$1',null,1),//5
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$G$1',null,1),//6
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$H$1',null,1),//7
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$I$1',null,1),//8
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$J$1',null,1),//9
- );
- $xLabels = array(
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$A$2:$A$'.($days+1),null,9),//取x轴刻度
- );
- $datas = array(
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$B$2:$B$'.($days+1),null,9),//1
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$C$2:$C$'.($days+1),null,9),//2
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$D$2:$D$'.($days+1),null,9),//3
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$E$2:$E$'.($days+1),null,9),//4
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$F$2:$F$'.($days+1),null,9),//5
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$G$2:$G$'.($days+1),null,9),//6
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$H$2:$H$'.($days+1),null,9),//7
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$I$2:$I$'.($days+1),null,9),//8
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$J$2:$J$'.($days+1),null,9),//9
- );
- /*if($week){
- $labels = array(
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$B$1',null,1),//1
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$C$1',null,1),//2
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$D$1',null,1),//3
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$E$1',null,1),//4
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$F$1',null,1),//5
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$G$1',null,1),//6
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$H$1',null,1),//7
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$I$1',null,1),//8
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$J$1',null,1),//9
- );
- $xLabels = array(
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$A$2:$A$8',null,9),//取x轴刻度
- );
- $datas = array(
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$B$2:$B$8',null,9),//1
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$C$2:$C$8',null,9),//2
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$D$2:$D$8',null,9),//3
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$E$2:$E$8',null,9),//4
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$F$2:$F$8',null,9),//5
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$G$2:$G$8',null,9),//6
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$H$2:$H$8',null,9),//7
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$I$2:$I$8',null,9),//8
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$J$2:$J$8',null,9),//9
- );
- $name = "支付方式分析(周)柱形图.xlsx";
- } else {
- $labels = array(
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$B$1',null,1),//1
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$C$1',null,1),//2
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$D$1',null,1),//3
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$E$1',null,1),//4
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$F$1',null,1),//5
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$G$1',null,1),//6
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$H$1',null,1),//7
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$I$1',null,1),//8
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$J$1',null,1),//9
- );
- $xLabels = array(
- new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$A$2:$A$'.($days+1),null,9),//取x轴刻度
- );
- $datas = array(
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$B$2:$B$'.($days+1),null,9),//1
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$C$2:$C$'.($days+1),null,9),//2
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$D$2:$D$'.($days+1),null,9),//3
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$E$2:$E$'.($days+1),null,9),//4
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$F$2:$F$'.($days+1),null,9),//5
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$G$2:$G$'.($days+1),null,9),//6
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$H$2:$H$'.($days+1),null,9),//7
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$I$2:$I$'.($days+1),null,9),//8
- new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$J$2:$J$'.($days+1),null,9),//9
- );
- $name = "支付方式分析(月)柱形图.xlsx";
- }*/
- $series = array(
- new PHPExcel_Chart_DataSeries(
- PHPExcel_Chart_DataSeries::TYPE_BARCHART,
- PHPExcel_Chart_DataSeries::GROUPING_STANDARD,
- range(0, count($datas)-1),
- $labels,
- $xLabels,
- $datas
- )
- ); //图表框架
- $layout=new PHPExcel_Chart_Layout();
- $layout->setShowVal(true);
- $areas = new PHPExcel_Chart_PlotArea(null,$series);
- $legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT,$layout,false);
- $title = new PHPExcel_Chart_Title("支付方式分析");
- $ytitle = new PHPExcel_Chart_Title("订单数");
- $chart = new PHPExcel_Chart('line_chart',$title,$legend,$areas,true,false,null,$ytitle);
- $chart->setTopLeftPosition("A1")->setBottomRightPosition("P31"); //图表位置
- $objSheet->addChart($chart);
- $excel = 'Excel2007';
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,$excel);
- $objWriter->setIncludeCharts(true); //图表必须
- // $objWriter->save($dir.'/export.xls'); //生成excel文件
- CommonFn::browser_export($excel,date('m').$name); //浏览器输出
- CommonFn::SaveViaTempFile($objWriter);
- }
- public function actionTest(){
- $arr = array(
- array('', '一班', '二班', '三班','四班'),
- array('不及格', 20, 30, 40,67),
- array('良好', 30, 50, 55,67),
- array('优秀', 15, 17, 20,67)
- );
- Yii::$enableIncludePath = false;
- Yii::import('ext.phpexcel.PHPExcel', 1);
- $objPHPExcel = new PHPExcel();
- $objSheet = $objPHPExcel->getActiveSheet();
- $criteria = new EMongoCriteria();
- $criteria->status('==',1);
- $name = '同比数据分析(月)柱形图.xlsx';
- $objSheet->fromArray($arr);
- //图表
- $labels = array(
- new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', null, 1),//一班
- new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', null, 1),//二班
- new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', null, 1),//三班
- new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$E$1', null, 1),//三班
- );
- $xLabels = array(
- new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$4', null, 3),
- );
- $datas = array(
- new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$4', null, 4),//取一班的数据
- new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$4', null, 4),//取二班的数据
- new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$4', null, 4),//取三班的数据
- new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$E$2:$E$4', null, 4),//取三班的数据
- );
- $series = array(
- new PHPExcel_Chart_DataSeries(
- PHPExcel_Chart_DataSeries::TYPE_BARCHART,
- PHPExcel_Chart_DataSeries::GROUPING_STANDARD,
- range(0, count($labels)-1),
- $labels,
- $xLabels,
- $datas
- )
- ); //图表框架
- $layout=new PHPExcel_Chart_Layout();
- $layout->setShowVal(true);
- $areas = new PHPExcel_Chart_PlotArea(null,$series);
- $legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT,$layout,false);
- $title = new PHPExcel_Chart_Title("同比数据分析");
- $ytitle = new PHPExcel_Chart_Title("订单数");
- $chart = new PHPExcel_Chart('line_chart',$title,$legend,$areas,true,false,null,$ytitle);
- $chart->setTopLeftPosition("A1")->setBottomRightPosition("P31"); //图表位置
- $objSheet->addChart($chart);
- $excel = 'Excel2007';
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,$excel);
- $objWriter->setIncludeCharts(true); //图表必须
- // $objWriter->save($dir.'/export.xls'); //生成excel文件
- CommonFn::browser_export($excel,date('m').$name); //浏览器输出
- CommonFn::SaveViaTempFile($objWriter);
- }
- }
|