ROrderController.php 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722
  1. <?php
  2. class ROrderController extends AdminController{
  3. public function actionIndex()
  4. {
  5. $status_option = ROrder::$status_option;
  6. $status = CommonFn::getComboboxData($status_option, 100, true, 100);
  7. $channel_option = ROrder::$channel_option;
  8. $channels = CommonFn::getComboboxData($channel_option, 100, true, 100);
  9. // 服务信息
  10. $criteria_main = new EMongoCriteria();
  11. $criteria_main->status('==', 1);
  12. $cursor_main = Product::model()->findAll($criteria_main);
  13. $rows_main = CommonFn::getRowsFromCursor($cursor_main);
  14. $main_row = array();
  15. foreach($rows_main as $row){
  16. $ids = (string)$row['_id'];
  17. $main_row[$ids] = array('name' =>$row['name']);
  18. }
  19. $main_products = CommonFn::getComboboxData($main_row, 100, true, 100);
  20. // 服务点信息
  21. $criteria_station = new EMongoCriteria();
  22. $cursor = Station::model()->findAll($criteria_station);
  23. $rows = CommonFn::getRowsFromCursor($cursor);
  24. $parsedRows = Station::model()->parse($rows);
  25. $station_data = array();
  26. foreach ($parsedRows as $key => $v) {
  27. $station_data = array_merge($station_data, array($v['id'] => array('name' => $v['name'])));
  28. }
  29. $station = CommonFn::getComboboxData($station_data, 'all', true, 'all');
  30. // 订单类型
  31. $type_data = Yii::app()->params['o2o_service'];
  32. $type = CommonFn::getComboboxData($type_data, 100, true, 100);
  33. $this->render('index', array(
  34. 'status' => $status,
  35. 'main_products'=> $main_products,
  36. 'channels' => $channels,
  37. 'station' => $station,
  38. 'type' => $type
  39. ));
  40. }
  41. public function actionList(){
  42. $filter_status = intval(Yii::app()->request->getParam('status', 100));
  43. $search = Yii::app()->request->getParam('search', '');
  44. $id = Yii::app()->request->getParam('id', '');
  45. $date_start_order = Yii::app()->request->getParam('date_start_order');
  46. $date_end_order = Yii::app()->request->getParam('date_end_order');
  47. $date_start_book= Yii::app()->request->getParam('date_start_book');
  48. $date_end_book = Yii::app()->request->getParam('date_end_book');
  49. $type = Yii::app()->request->getParam('type', 100);
  50. $have_pay = Yii::app()->request->getParam('have_pay', 0);
  51. $channel = Yii::app()->request->getParam('channel', 100);
  52. //$station = Yii::app()->request->getParam('station', 'all');
  53. $params = CommonFn::getPageParams();
  54. $criteria = new EMongoCriteria($params);
  55. if ($filter_status != 100){
  56. $criteria->status('==', $filter_status);
  57. }
  58. if ($id != ''){
  59. $order_id = new MongoId($id);
  60. $criteria->_id('==', $order_id);
  61. }
  62. if ($channel != 100){
  63. $criteria->channel('==', $channel);
  64. }
  65. if ($type != 100) {
  66. $criteria->type = $type;
  67. }
  68. if ($search != ''){
  69. if(CommonFn::isMongoId($search)){
  70. //$criteria->_id('==', new MongoId($search));
  71. $criteria->addCond('_id','or',new MongoId($search));
  72. $criteria->addCond('user','or',new MongoId($search));
  73. }
  74. else if(preg_match('/\d{8,11}/', $search)){
  75. $criteria->addCond('address.mobile','==',$search);
  76. if($have_pay){
  77. $criteria->addCond('status','>',0);
  78. }
  79. }else if(strlen($search) == 27){
  80. $criteria->charge_id('==', $search);
  81. }else{
  82. $criteria->addCond('address.name','==',$search);
  83. }
  84. }
  85. // 下单时间处理
  86. if (!empty($date_start_order) && !empty($date_end_order)) {
  87. // 开始时间处理
  88. $timestamp_start_order = strtotime($date_start_order);
  89. // 结束时间处理,需通过strototime()增加一天
  90. $timestamp_end_order = strtotime('+1 day', strtotime($date_end_order));
  91. $criteria->order_time('>=', $timestamp_start_order);
  92. $criteria->order_time('<=', $timestamp_end_order);
  93. }
  94. // 预约时间处理
  95. if (!empty($date_start_book) && !empty($date_end_book)) {
  96. // 开始时间处理
  97. $timestamp_start_book = strtotime($date_start_book);
  98. // 结束时间处理,需通过strototime()增加一天
  99. $timestamp_end_book = strtotime('+1 day', strtotime($date_end_book));
  100. $criteria->booking_time('>=', $timestamp_start_book);
  101. $criteria->booking_time('<=', $timestamp_end_book);
  102. }
  103. // 服务站处理
  104. // if ($station != 'all') {
  105. // $criteria->station = new MongoId($station);
  106. //}
  107. $cursor = ROrder::model()->findAll($criteria);
  108. $total = $cursor->count();
  109. $rows = CommonFn::getRowsFromCursor($cursor);
  110. $parsedRows = ROrder::model()->parse($rows);
  111. echo CommonFn::composeDatagridData($parsedRows, $total);
  112. }
  113. public function actionEdit(){
  114. $id = Yii::app()->request->getParam('id', '');
  115. $status = intval(Yii::app()->request->getParam('status',1));
  116. $counts = intval(Yii::app()->request->getParam('count',1));
  117. $booking_time = intval(Yii::app()->request->getParam('booking_time', time()));
  118. $deal_time = intval(Yii::app()->request->getParam('deal_time', time()));
  119. $remark = Yii::app()->request->getParam('remark', '');
  120. $tech_money = Yii::app()->request->getParam('tech_money','');//保洁师车费
  121. //$station = Yii::app()->request->getParam('station_id', '');
  122. $technician_ids = array();
  123. $technician_names = array();
  124. $technicians = array();
  125. $nums = Yii::app()->request->getParam('tech_nums');
  126. for($i=0;$i<=$nums;$i++) {
  127. if(Yii::app()->request->getParam('extra_add_info_'.$i)) {
  128. $technician_ids[] = Yii::app()->request->getParam('extra_add_info_id_'.$i);
  129. $technician_names[] = Yii::app()->request->getParam('extra_add_info_'.$i);
  130. }
  131. }
  132. if(!$counts){
  133. CommonFn::requestAjax(false, '购买数量错误');
  134. }
  135. // 保洁师信息检查
  136. // 根据ID直接查询保洁师信息(优先使用联想功能)
  137. if (isset($technician_ids)) {
  138. foreach($technician_ids as $key => $technician_id){
  139. $technician_obj = TechInfo::get($technician_id);
  140. if ($technician_obj) {
  141. $technicians[$key]['technician_id'] = $technician_obj->_id;
  142. $technicians[$key]['technician_name'] = $technician_obj->name;
  143. } else {
  144. CommonFn::requestAjax(false, '保洁师不存在');
  145. break;
  146. }
  147. }
  148. // ID为0时根据输入框信息查询
  149. } else if (isset($technician_names)) {
  150. $criteria = new EMongoCriteria();
  151. foreach($technician_names as $key => $technician_name) {
  152. $criteria->name = $technician_name;
  153. $technician_obj = TechInfo::model()->find($criteria);
  154. if ($technician_obj) {
  155. $technicians[$key]['technician_id'] = $technician_obj->_id;
  156. $technicians[$key]['technician_name'] = $technician_obj->name;
  157. } else {
  158. CommonFn::requestAjax(false, '保洁师不存在');
  159. break;
  160. }
  161. }
  162. } else {
  163. $technician_obj = null;
  164. //$technician_id = 0;
  165. // $technician_name = '';
  166. foreach($technicians as $key => $value) {
  167. $technicians[$key]['$technician_id'] = 0;
  168. $technicians[$key]['$technician_name'] = 0;
  169. }
  170. }
  171. //var_dump($technicians);exit;
  172. if($status == 100){
  173. CommonFn::requestAjax(false, '必须指定状态!');
  174. }
  175. $criteria = new EMongoCriteria();
  176. $criteria->_id = new MongoId($id);
  177. $order = ROrder::model()->find($criteria);
  178. // if($order->status == -1 || $order->status == -2){
  179. // CommonFn::requestAjax(false, '已取消,已退款订单不支持更改');
  180. // }
  181. // 获取用户信息,修改用户订单统计
  182. // 2015-11-16
  183. $user_id = $order->user;
  184. if (!empty($user_id)) {
  185. $user = RUser::get($user_id);
  186. } else {
  187. $user = '';
  188. }
  189. if (empty($order)){
  190. CommonFn::requestAjax(false, '订单不存在');
  191. }
  192. $flag = 0;
  193. //精佰退单接口 状态为申请退款并且是精佰的订单
  194. if ($order->status == -3 && $order->channel == 'jingbai') {
  195. //确认申请退款状态变更成已退款订单 为退单订单
  196. $res = '';
  197. $criteria = new EMongoCriteria();
  198. $criteria->OrderNo('==',$order->OrderNo);
  199. $criteria->status('==',-3);
  200. $orders = ROrder::model()->findAll($criteria);
  201. $orderId = '';
  202. $fin_price = 0.0;
  203. foreach ($orders as $value) {
  204. $orderId .= (string)$value->_id.',';
  205. $fin_price =$fin_price+ $value->final_price*0.5;
  206. }
  207. $fin_price = round($fin_price,2)*100;
  208. $orderId = rtrim(trim($orderId),',');
  209. if ($status == -2) {
  210. if ($remark == '1') {//退单 全额
  211. //已出发 已上门 订单
  212. $res = self::feedbackOrder(1, $order->OrderNo, $orderId, $fin_price);
  213. } else {//退单 不退钱
  214. $res = self::feedbackOrder(1, $order->OrderNo, $orderId, 0);
  215. }
  216. $flag = 1;
  217. } else if($status == 2 ){//不退单
  218. $res = self::feedbackOrder(0,$order->OrderNo,$orderId,0);
  219. $flag = 1;
  220. }
  221. if( $order->booking_time != $booking_time){
  222. self::feedbackOrderRemaker(0,$order->OrderNo,$orderId,0,$order->booking_time);
  223. }
  224. if ($flag && $res){
  225. foreach ($orders as $value) {
  226. $value->status = $status;
  227. $value->save();
  228. }
  229. }
  230. }
  231. if(($order->status!=-1||$order->status!=-2)&&($status==-1||$status==-2)){
  232. foreach ($order->coupons as $user_coupon) {
  233. $user_coupon = UserCoupon::get($user_coupon);
  234. $user_coupon->status = 1;
  235. $user_coupon->update(array('status'),true);
  236. }
  237. }
  238. if($order->status!=-2 && $status == -2) {
  239. $order->refund_time = time();
  240. $order_info = $order->parseRow($order);
  241. $month = date('m', $order_info['booking_time']);
  242. $day = date('d', $order_info['booking_time']);
  243. $address = $order_info['address']['poi']['name'] . $order_info['address']['detail'];
  244. CommonSMS::send('order_retrieve', array('month' => $month, 'day' => $day, 'address' => $address, 'mobile' => $order_info['address']['mobile']));
  245. // 申请退款处理完成后通知保洁师
  246. foreach ($technician_ids as $key => $technician_id) {
  247. $technician_obj = TechInfo::get($technician_id);
  248. if ($technician_obj && $technician_obj->weixin_userid) {
  249. $url_prefix = ENVIRONMENT == 'product' ? 'http://api.yiguanjia.me' : 'http://apitest.yiguanjia.me';
  250. $wechat = O2oApp::getWechatActive();
  251. $wechat_data = array(
  252. 'touser' => $technician_obj->weixin_userid,
  253. 'msgtype' => 'news',
  254. 'agentid' => '1',
  255. 'news' => array(
  256. 'articles' => array(
  257. array(
  258. 'title' => '壹管家提示-订单退款完成',
  259. 'description' => $technician_obj->name . '你好!用户于' . date('m月d日H:i', $order->apply_refund_time) . '申请退款的订单已处理完成。',
  260. //'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_id,
  261. 'url' => $url_prefix . '/index.php?r=o2o/myOrder/index'
  262. ),
  263. ),
  264. ),
  265. );
  266. if (!empty($order->append_orders)) {
  267. $count = count($order->append_orders);
  268. $wechat_data['news']['articles'][0]['description'] .= "\n\n本订单包含" . $count . "个追加订单,请注意查看。";
  269. }
  270. $wechat->sendMessage($wechat_data);
  271. }
  272. }
  273. }
  274. //取消订单
  275. if($order->status!=-1 && $status == -1){
  276. // 已完成订单不能取消
  277. if ($order->status == 6) {
  278. CommonFn::requestAjax(false, '已完成订单不可取消');
  279. }
  280. $order->cancel_time = time();
  281. $order_info = $order->parseRow($order);
  282. }
  283. //确认接单
  284. if($order->status!=3 && $status == 3){
  285. $order_info = $order->parseRow($order);
  286. }
  287. //订单完成后执行
  288. if($order->status!=6 && $status == 6 ){
  289. $order->finish_time = time();
  290. $order_info = $order->parseRow($order);
  291. /*$result = Service::factory('ScoreService')->changeScore((string)$order->user,intval($order->final_price),'下单奖爪币');
  292. if($result){
  293. $z_message = new ZMessage();
  294. $from_user = Yii::app()->params['sys_user'];
  295. $message_data = array(
  296. 'from_user' => $from_user,
  297. 'to_user' => (string)$order->user,
  298. 'content' => '您成功下单,获得了'.intval($order->final_price).'个爪币的奖励。',
  299. 'pics' => array(),
  300. 'voice' => array(),
  301. 'video'=> array()
  302. );
  303. $z_message->addMessage($message_data);
  304. CommonSMS::send('final_order',array('name' =>$order_info['address']['name'],'num' =>intval($order->final_price),'mobile'=>$order_info['address']['mobile']));
  305. }*/
  306. // 保洁师订单统计处理
  307. foreach($technician_ids as $key => $technician_id) {
  308. $technician_obj = TechInfo::get($technician_id);
  309. if ($technician_obj) {
  310. $tech_order_count = $technician_obj->order_count + 1;
  311. $technician_obj->order_count = $tech_order_count;
  312. $technician_obj->save();
  313. }
  314. }
  315. }
  316. $order->status = $status;
  317. $order->booking_time = $booking_time;
  318. $order->deal_time = $deal_time;
  319. $order->remark = $remark;
  320. $order->counts = $counts;
  321. $order->tech_money = $tech_money;//保洁师车费录入
  322. //$order->station = new MongoId($station);
  323. // 是否通知保洁师
  324. $toTech = !empty($order->technicians)? true : false;
  325. //$order->technician = $technician_id;
  326. //$order->technician_name = $technician_name;
  327. $order->technicians = $technicians;
  328. //var_dump($order);exit;
  329. //判断是否为实惠或金百订单
  330. if($order->channel == 'shihui'){
  331. if ($status == 1) {//已支付
  332. $res = self::UpdateStatus((string)$order->_id, 5);
  333. $flag = 1;
  334. } else if($status ==3){//已接单
  335. $res = self::UpdateStatus((string)$order->_id, 15);
  336. $flag = 1;
  337. }else if($status ==6){//服务完成
  338. $res = self::UpdateStatus((string)$order->_id, 20);
  339. $flag = 1;
  340. }else if($status ==-1){//取消订单
  341. $res = self::DelOrder((string)$order->_id);
  342. $flag = 1;
  343. }
  344. }else if($order->channel == 'jingbai'){
  345. if($status ==3){//已接单
  346. $res = self::UpdateStatusForJingBai($order->OrderNo,(string)$order->_id, $status,$order->remark);
  347. $flag = 1;
  348. }else if($status ==6){//服务完成
  349. $res = self::UpdateStatusForJingBai($order->OrderNo,(string)$order->_id, $status,$order->remark);
  350. $flag = 1;
  351. }
  352. }
  353. if($flag){
  354. if (!$res) {
  355. CommonFn::requestAjax(false,'修改失败res='.$res.',flag='.$flag);
  356. }
  357. }
  358. $arr_order = array('tech_money','cancel_time','refund_time','finish_time','status','booking_time','deal_time','remark', 'station', 'technicians');
  359. $success = $order->save(true,$arr_order);
  360. $char = false;
  361. // 通知保洁师
  362. if (in_array($status, array(1,2,3,4,5)) && $toTech && $success) {
  363. foreach($technician_ids as $key => $technician_id) {
  364. $technician_obj = TechInfo::get($technician_id);
  365. if ($technician_obj && $technician_obj->weixin_userid) {
  366. $url_prefix = ENVIRONMENT == 'product' ? 'http://api.yiguanjia.me' : 'http://apitest.yiguanjia.me';
  367. $wechat = O2oApp::getWechatActive();
  368. $wechat_data = array(
  369. 'touser' => $technician_obj->weixin_userid,
  370. 'msgtype' => 'news',
  371. 'agentid' => 1,
  372. 'news' => array(
  373. 'articles' => array(
  374. array(
  375. 'title' => '壹管家提示-新订单',
  376. 'description' => $technician_obj->name . '你好!刚刚有一个新的订单被分配给你,请点击查看。',
  377. //'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_id,
  378. 'url' => $url_prefix . '/index.php?r=o2o/myOrder/index'
  379. ),
  380. ),
  381. ),
  382. );
  383. $char = $wechat->sendMessage($wechat_data);
  384. }
  385. }
  386. }
  387. CommonFn::requestAjax($success, '微信'.$char, array());
  388. }
  389. // 根据手机号 获取对应用户的地址信息
  390. public function actionGetUserInfo(){
  391. $mobile = Yii::app()->request->getParam('mobile', '');
  392. $length = strlen($mobile);
  393. if ($length < 11) {
  394. $result[] = array(
  395. 'id' => 0,
  396. 'data' => '',
  397. 'description' => '请继续输入',
  398. 'content' => array()
  399. );
  400. echo json_encode($result);exit;
  401. }
  402. // $mobile_regex = new MongoRegex($mobile);
  403. $criteria = new EMongoCriteria();
  404. $criteria->sort('order_time', EMongoCriteria::SORT_DESC);
  405. $criteria->addCond('address.mobile', '==', $mobile);
  406. $cursor = ROrder::model()->findAll($criteria);
  407. $rows = CommonFn::getRowsFromCursor($cursor);
  408. if (empty($rows)) {
  409. $result[] = array(
  410. 'id' => 0,
  411. 'data' => '',
  412. 'description' => '没有匹配信息',
  413. 'content' => array()
  414. );
  415. echo json_encode($result);exit;
  416. }
  417. $result = array();
  418. $details = array();
  419. $index = 0;
  420. foreach($rows as $row){
  421. // 加入根据detail筛选,避免产生重复信息
  422. if (in_array($row['address']['detail'], $details)) continue;
  423. $details[] = $row['address']['detail'];
  424. $pio = isset($row['address']['poi']['name'])?$row['address']['poi']['name']:'';
  425. // 坐标获取(根据不同的来源)
  426. if ($row['channel'] == 'dianping') {
  427. $latitude = $row['address']['position']['lat'];
  428. $longitude = $row['address']['position']['lng'];
  429. } else {
  430. $latitude = isset($row['address']['position']['1'])?$row['address']['position']['1']:'';
  431. $longitude = isset($row['address']['position']['0'])?$row['address']['position']['0']:'';
  432. }
  433. // poi获取
  434. $poi_name = isset($row['address']['poi']['name']) ? $row['address']['poi']['name'] : '';
  435. $poi_uid = isset($row['address']['poi']['uid']) ? $row['address']['poi']['uid'] : '';
  436. $result[] = array(
  437. 'id' => $index,
  438. 'data' => $row['address']['mobile'],
  439. 'description' => $row['address']['province'].' '.$row['address']['city'].' '.$row['address']['area'].' '.$pio.$row['address']['detail'],
  440. 'content' => array(
  441. 'name' => $row['address']['name'],
  442. 'latitude' => $latitude,
  443. 'longitude' => $longitude,
  444. 'province' => $row['address']['province'],
  445. 'city' => $row['address']['city'],
  446. 'area' => $row['address']['area'],
  447. 'detail' => $row['address']['detail'],
  448. 'poi_name' => $poi_name,
  449. 'poi_uid' => $poi_uid,
  450. 'memo' => $row['memo']
  451. )
  452. );
  453. $index++;
  454. }
  455. echo json_encode($result);exit;
  456. }
  457. public function actionAdd () {
  458. // ------ 必须传入的数值 ------
  459. // --------- 订单信息 ---------
  460. $channel = Yii::app()->request->getParam('channel', '');
  461. $booking_time = Yii::app()->request->getParam('booking_time_add', '');
  462. $order_time = Yii::app()->request->getParam('order_time_add', '');
  463. $main_products = Yii::app()->request->getParam('main_products', '');
  464. $price = floatval(Yii::app()->request->getParam('price', 0));
  465. $final_price = floatval(Yii::app()->request->getParam('final_price', 0));
  466. $status = Yii::app()->request->getParam('status', -3);
  467. $station = Yii::app()->request->getParam('station', '57db39709f5160bb048b456a');
  468. // --------- 地址信息 ---------
  469. $mobile = Yii::app()->request->getParam('mobile', 0);
  470. $latitude = Yii::app()->request->getParam('latitude', 0);
  471. $longitude = Yii::app()->request->getParam('longitude', 0);
  472. $province = Yii::app()->request->getParam('province', '');
  473. $city = Yii::app()->request->getParam('city', '');
  474. $area = Yii::app()->request->getParam('area', '');
  475. $poi_name = Yii::app()->request->getParam('poi_name', '');
  476. $detail = Yii::app()->request->getParam('detail', '');
  477. $counts = intval(Yii::app()->request->getParam('counts', 1));
  478. $counts = $counts?$counts:1;
  479. $extra = Yii::app()->request->getParam('extra','[]');
  480. $extra = json_decode($extra);
  481. // 数据完整性检查
  482. // 2015-11-02 因存在赠送订单,删除金额的数据检查 : $price == 0 || $final_price == 0 ||
  483. // 2015-11-16 取消服务点录入,删除服务点数据检查 : || empty($station)
  484. $flag = empty($channel) || empty($booking_time) || empty($order_time);
  485. $flag = $flag || $status == -3;
  486. $flag = $flag || $mobile == 0 || $latitude == 0 || $longitude == 0;
  487. $flag = $flag || empty($province) || empty($city) || empty($area) || empty($poi_name) || empty($detail);
  488. if ($flag) {
  489. CommonFn::requestAjax(false, '请检查数据完整性', array());
  490. exit;
  491. }
  492. //if($channel == 'wz_app' || $channel == 'wx_pub'){
  493. //CommonFn::requestAjax(false, '不能录入渠道为壹管家微信||壹管家APP的订单', array());
  494. //exit;
  495. //}
  496. // 时间处理
  497. $booking_time = strtotime($booking_time);
  498. $order_time = strtotime($order_time);
  499. // ------ 可以留空的数值 ------
  500. $box = Yii::app()->request->getParam('box', array());
  501. $coupons = Yii::app()->request->getParam('coupons', array());
  502. $memo = Yii::app()->request->getParam('memo', '');
  503. $remark = Yii::app()->request->getParam('remark', '');
  504. $precedence = Yii::app()->request->getParam('precedence', 0);
  505. $have_comment = Yii::app()->request->getParam('have_comment', 0);
  506. $name = Yii::app()->request->getParam('name', '');
  507. $type = Yii::app()->request->getParam('type', 0);
  508. $user = Yii::app()->request->getParam('user', '');
  509. $poi_uid = Yii::app()->request->getParam('poi_uid', '');
  510. // 用户名的判断
  511. $channel_option = ROrder::$channel_option;
  512. $name = empty($name) ? $channel_option[$channel]['name'].'用户' : $name;
  513. // 支付渠道
  514. $pay_channel = $channel;
  515. // 服务数据整合
  516. $products[] = array(
  517. 'product' => new MongoId($main_products),
  518. 'count' => 1,
  519. 'extra' =>$extra
  520. );
  521. if (!empty($box)) {
  522. foreach ($box as $key => $value) {
  523. $products[] = array(
  524. 'product' => new MongoId($value),
  525. 'count' => 1,
  526. 'extra' =>$extra
  527. );
  528. }
  529. }
  530. // 地址数据整合
  531. $address = array(
  532. 'province' => $province,
  533. 'city' => $city,
  534. 'area' => $area,
  535. 'detail' => $detail,
  536. 'mobile' => $mobile,
  537. 'position' => array(
  538. // 'lat' => (float)$latitude,
  539. // 'lng' => (float)$longitude,
  540. 0 => (float)$longitude,
  541. 1 => (float)$latitude
  542. ),
  543. 'poi' => array(
  544. 'name' => $poi_name,
  545. 'uid' => $poi_uid
  546. ),
  547. 'name' => $name
  548. );
  549. // 订单类型判断
  550. if ($type == 0) {
  551. $criteria = new EMongoCriteria();
  552. $criteria->_id = new MongoId($main_products);
  553. $cursor = Product::model()->find($criteria);
  554. $type = $cursor->type;
  555. }
  556. $rOrder = new ROrder();
  557. $rOrder->channel = $channel;
  558. $rOrder->booking_time = intval($booking_time);
  559. $rOrder->order_time = intval($order_time);
  560. $rOrder->products = $products;
  561. $rOrder->price = floatval($price);
  562. $rOrder->final_price = floatval($final_price);
  563. $rOrder->precedence = intval($precedence);
  564. $rOrder->counts = $counts;
  565. $rOrder->coupons = $coupons;
  566. $rOrder->user = $user;
  567. $rOrder->status = intval($status);
  568. $rOrder->memo = $memo;
  569. $rOrder->remark = $remark;
  570. $rOrder->type = strval($type); // 数据库内使用string类型
  571. $rOrder->have_comment = intval($have_comment);
  572. $rOrder->station = new MongoId($station);
  573. $rOrder->address = $address;
  574. $rOrder->pay_channel = $pay_channel;
  575. $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');
  576. $success = $rOrder->save(true, $addROrder_arr);
  577. CommonFn::requestAjax($success, '', array());
  578. }
  579. /**
  580. * 请求申请退款订单接口
  581. */
  582. public function actionCheckRefundOrder() {
  583. $criteria = new EMongoCriteria();
  584. $criteria->status('==', -3);
  585. $cursor = ROrder::model()->findAll($criteria);
  586. $count = $cursor->count();
  587. if ($count > 0) {
  588. $data = array('code' => 1, 'count' => $count);
  589. } else {
  590. $data = array('code' => 0, 'count' => $count);
  591. }
  592. $list = new ARedisList('append_order_list');
  593. if($list->getCount() > 0){
  594. $key = $list->shift();
  595. $list->unshift($key);
  596. $data['procession_append_order_id'] = $key;
  597. $data['code'] = 2;
  598. }
  599. echo json_encode($data);
  600. }
  601. public function actionCancelProcess() {
  602. $orderid = Yii::app()->request->getParam('orderid','');
  603. $list = new ARedisList('append_order_list');
  604. $key = $list->shift();
  605. }
  606. /**
  607. * 重新选择保洁师接口
  608. */
  609. public function actionResetTech() {
  610. $id = Yii::app()->request->getParam('id', '');
  611. $nums = Yii::app()->request->getParam('nums', '');
  612. $technicians = array();
  613. $technician_ids = array();
  614. $technician_names = array();
  615. for($i=1;$i<=$nums;$i++) {
  616. if(Yii::app()->request->getParam('reset_extra_add_info_'.$i)) {
  617. $technician_ids[] = Yii::app()->request->getParam('reset_extra_add_info_id_'.$i);
  618. $technician_names[] = Yii::app()->request->getParam('reset_extra_add_info_'.$i);
  619. }
  620. }
  621. // 保洁师信息检查
  622. // 根据ID直接查询保洁师信息(优先使用联想功能)
  623. $technician_objs = array();
  624. foreach($technician_ids as $key => $technician_id) {
  625. if ($technician_id != 0) {
  626. $technician_obj = TechInfo::get($technician_id);
  627. if ($technician_obj) {
  628. $technicians[$key]['technician_id'] = $technician_obj->_id;
  629. $technicians[$key]['technician_name'] = $technician_obj->name;
  630. } else {
  631. CommonFn::requestAjax(false, '保洁师不存在');
  632. }
  633. // ID为0时根据输入框信息查询
  634. } else {
  635. foreach ($technician_names as $key => $technician_name)
  636. if ($technician_name != '') {
  637. $criteria = new EMongoCriteria();
  638. $criteria->name = $technician_name;
  639. $technician_obj = TechInfo::model()->find($criteria);
  640. if ($technician_obj) {
  641. $technicians[$key]['technician_id'] = $technician_obj->_id;
  642. $technicians[$key]['technician_name'] = $technician_obj->name;
  643. } else {
  644. CommonFn::requestAjax(false, '保洁师不存在');
  645. }
  646. } else {
  647. CommonFn::requestAjax(false, '保洁师姓名不能为空');
  648. }
  649. }
  650. $technician_objs[] = $technician_obj;
  651. }
  652. $orderid = new MongoId($id);
  653. $order = ROrder::model()->get($orderid);
  654. $toTech = isset($order->technicians) ? true : false;
  655. $fromTechs = $technician_names;
  656. //$order->technician = $technician_id;
  657. //$order->technician_name = $technician_name;
  658. $order->technicians = $technicians;
  659. $success = $order->save(true, array('technicians'));
  660. if ($toTech && $success) {
  661. foreach ($technician_objs as $technician_obj) {
  662. // 发送给被分配保洁师
  663. $wechat = O2oApp::getWechatActive();
  664. $url_prefix = ENVIRONMENT == 'product' ? 'http://api.yiguanjia.me' : 'http://apitest.yiguanjia.me';
  665. if (!empty($technician_obj->weixin_userid)) {
  666. $wechat_data = array(
  667. 'touser' => $technician_obj->weixin_userid,
  668. 'msgtype' => 'news',
  669. 'agentid' => '1',
  670. 'news' => array(
  671. 'articles' => array(
  672. array(
  673. 'title' => '壹管家提示-新订单',
  674. 'description' => $technician_obj->name . '你好!刚刚有一个新的订单被分配给你,请点击查看。',
  675. //'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_obj->_id,
  676. 'url' => $url_prefix . '/index.php?r=o2o/myOrder/index'
  677. ),
  678. ),
  679. ),
  680. );
  681. $wechat->sendMessage($wechat_data);
  682. }
  683. }
  684. // 发送给原保洁师
  685. foreach ($fromTechs as $fromTech) {
  686. $fromTechObj = TechInfo::get($fromTech);
  687. if (!empty($fromTechObj) && !empty($fromTechObj->weixin_userid)) {
  688. $wechat_data = array(
  689. 'touser' => $fromTechObj->weixin_userid,
  690. 'msgtype' => 'news',
  691. 'agentid' => '1',
  692. 'news' => array(
  693. 'articles' => array(
  694. array(
  695. 'title' => '壹管家提示-订单已被重新分配',
  696. 'description' => $fromTechObj->name . '你好!预定时间在' . date('m月d日H:i', $order->booking_time) . '的订单已被分配给其他保洁师。',
  697. 'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_obj->_id,
  698. ),
  699. ),
  700. ),
  701. );
  702. $wechat->sendMessage($wechat_data);
  703. }
  704. }
  705. }
  706. CommonFn::requestAjax($success, '', array());
  707. }
  708. /*public function actionDelOrder(){
  709. $delOrder = array('5826a4c89f5160d1048b52bf');
  710. $total = 0;
  711. foreach($delOrder as $value){
  712. $order = ROrder::model()->get(new MongoId($value));
  713. if($order->delete()){
  714. $total += 1;
  715. }
  716. }
  717. echo $total;
  718. }*/
  719. //取消订单
  720. public function DelOrder($orderId){
  721. $data['key'] = Yii::app()->params['shKey'];
  722. $data['version'] = '1.0';
  723. $data['serviceType'] = (int)26;
  724. $data['orderId'] = $orderId;//'57fde8059f5160c4048b4aeb';
  725. ksort($data);
  726. $str = '';
  727. $dat = '';
  728. foreach ($data as $key => $value) {
  729. $str .= $key.'='.$value.'&';
  730. $dat .= $key.'='.urlencode($value).'&';
  731. }
  732. $str = rtrim(trim($str),'&');
  733. $str .= $str.Yii::app()->params['shMd5Key'];
  734. $data['sign'] = strtoupper(md5($str));
  735. $dat .= 'sign='.urlencode($data['sign']);//构建post 参数
  736. $url = 'http://test2.app.hiwemeet.com/v2/openpf/home/order/thirdOrder/cancel'; //调用接口的平台服务地址
  737. $ch = curl_init();
  738. curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
  739. curl_setopt($ch, CURLOPT_URL, $url);
  740. curl_setopt($ch, CURLOPT_POST, 1);
  741. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  742. curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
  743. $result = curl_exec($ch);
  744. curl_close($ch);
  745. $res = json_decode($result,true);
  746. var_dump($res);
  747. if ($res['code']){
  748. return true;
  749. } else {
  750. return false;
  751. }
  752. }
  753. //更新订单状态
  754. public function UpdateStatus($orderId,$status){
  755. $data['key'] = Yii::app()->params['shKey'];
  756. $data['version'] = '1.0';
  757. $data['serviceType'] = (int)26;
  758. $data['orderId'] = (string)$orderId;
  759. $data['status'] = $status;
  760. ksort($data);
  761. $str = '';
  762. $dat = '';
  763. foreach ($data as $key => $value) {
  764. $str .= $key.'='.$value.'&';
  765. $dat .= $key.'='.urlencode($value).'&';
  766. }
  767. $str = rtrim(trim($str),'&');
  768. $str .= $str.Yii::app()->params['shMd5Key'];
  769. $data['sign'] = strtoupper(md5($str));
  770. $dat .= 'sign='.urlencode($data['sign']);//构建post 参数
  771. $url = 'http://test2.app.hiwemeet.com/v2/openpf/home/order/thirdOrder/update'; //调用接口的平台服务地址
  772. $ch = curl_init();
  773. curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
  774. curl_setopt($ch, CURLOPT_URL, $url);
  775. curl_setopt($ch, CURLOPT_POST, 1);
  776. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  777. curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
  778. $result = curl_exec($ch);
  779. curl_close($ch);
  780. $res = json_decode($result,true);
  781. if ($res['code']){
  782. return true;
  783. } else {
  784. return false;
  785. }
  786. }
  787. //更新订单状态
  788. /**
  789. * @param $orderId => order->orderNo
  790. * @param $status "00" 为创建订单,"01"为服务派单,"02"为服务完成
  791. * @param $HouseKeepingId 巾帼园自己的订单号 对应order->_id
  792. * @param $remark 订单备注
  793. * Sign 计算方法:OrderId+ StatusCode+ Remark+ HouseKeepingId+ Time+KEY 然后计算md5 值 KEY为巾帼园的key值
  794. * @return bool
  795. */
  796. public function UpdateStatusForJingBai($orderId,$HouseKeepingId,$status,$remark){
  797. $key = Yii::app()->params['JingBai'];
  798. $data['OrderId'] = $orderId;
  799. $data['HouseKeepingId'] = $HouseKeepingId;
  800. $data['Remark'] = $remark;
  801. if ($status == 3){//已接单
  802. $data['StatusCode'] = '01';
  803. } else if($status == 6){//已完成
  804. $data['StatusCode'] = '02';
  805. }
  806. $data['Time'] = date('Y-m-d H:i:s');
  807. $data['Sign'] = md5($data['OrderId'].$data['StatusCode'].$data['Remark'].$data['HouseKeepingId'].$data['Time'].$key);
  808. $dat = '';
  809. foreach ($data as $key => $value) {
  810. $dat .= $key.'='.urlencode($value).'&';
  811. }
  812. $dat = rtrim(trim($dat),'&');
  813. if (ENVIRONMENT == 'product'){
  814. $url = 'http://139.196.47.211:9230/ServiceController/SetHouseKeepingStatus'; //正式服调用接口的平台服务地址
  815. } else {
  816. $url = 'http://139.196.47.211:9030/ServiceController/SetHouseKeepingStatus'; //调用接口的平台服务地址
  817. }
  818. $ch = curl_init();
  819. curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
  820. curl_setopt($ch, CURLOPT_URL, $url);
  821. curl_setopt($ch, CURLOPT_POST, 1);
  822. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  823. curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
  824. $result = curl_exec($ch);
  825. curl_close($ch);
  826. $res = json_decode($result,true);
  827. if ($res['ReturnCode'] == '00'){
  828. return true;
  829. } else {
  830. return false;
  831. }
  832. }
  833. //不退单, 但是需要修改信息
  834. public function feedbackOrderRemaker($isCancel,$orderId,$orderNo,$money=0,$remark=null){
  835. $key = Yii::app()->params['JingBai'];
  836. $data['IsCancel'] = $isCancel;
  837. $data['OrderId'] = $orderId;
  838. $data['OrderNo'] = $orderNo;
  839. $data['Type'] = 'OrderRemark';
  840. $data['Remark'] = '修改预约时间'.date('Y-m-d H:i:s',$remark);
  841. $data['Sign'] = md5($orderId.$orderNo.$data['Remark'].$key);
  842. $dat = '';
  843. foreach ($data as $key => $value) {
  844. $dat .= $key.'='.urlencode($value).'&';
  845. }
  846. $dat = rtrim(trim($dat),'&');
  847. if (ENVIRONMENT == 'product'){
  848. $url = 'http://139.196.47.211:9230/ServiceController/HouseKeepingFeedback'; //正式服调用接口的平台服务地址
  849. } else {
  850. //$url = 'http://123.206.28.63:9030/ServiceController/HouseKeepingFeedback'; //测试服调用接口的平台服务地址
  851. $url = 'http://139.196.47.211:9030/ServiceController/HouseKeepingFeedback'; //调用接口的平台服务地址
  852. }
  853. $ch = curl_init();
  854. curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
  855. curl_setopt($ch, CURLOPT_URL, $url);
  856. curl_setopt($ch, CURLOPT_POST, 1);
  857. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  858. curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
  859. $result = curl_exec($ch);
  860. curl_close($ch);
  861. $res = json_decode($result,true);
  862. if ($res['ReturnCode'] == '00'){
  863. return true;
  864. } else {
  865. return false;
  866. }
  867. }
  868. //退单反馈信息接口
  869. /**
  870. * @param $isCanel 是否退单 1退单 0 不退单
  871. * @param $orderId 精佰订单Id 对应 巾帼园 OrderNo
  872. * @param $orderNo 巾帼园订单id 对应 巾帼园_id
  873. * @param $money 若退单巾帼园需要收多少钱,单位为分,不退单可不传
  874. * @param null $remark 退单状态备注包含修改信息,无修改此字段可不传
  875. * @return bool
  876. */
  877. public function feedbackOrder($isCancel,$orderId,$orderNo,$money=0)
  878. {
  879. $key = Yii::app()->params['JingBai'];
  880. $data['IsCancel'] = $isCancel;
  881. $data['OrderId'] = $orderId;
  882. $data['OrderNo'] = $orderNo;
  883. if(!$isCancel){//不退单
  884. $data['Type'] = 'CancleOrder';
  885. $data['Money'] = $money;
  886. $data['Sign'] = md5($isCancel.$orderId.$orderNo.$money.$key);
  887. }
  888. else {
  889. $data['Type'] = 'CancleOrder';
  890. $data['Money'] = $money;
  891. $data['Sign'] = md5($isCancel.$orderId.$orderNo.$money.$key);
  892. }
  893. $dat = '';
  894. foreach ($data as $key => $value) {
  895. $dat .= $key.'='.urlencode($value).'&';
  896. }
  897. $dat = rtrim(trim($dat),'&');
  898. if (ENVIRONMENT == 'product'){
  899. $url = 'http://139.196.47.211:9230/ServiceController/HouseKeepingFeedback'; //正式服调用接口的平台服务地址
  900. } else {
  901. //$url = 'http://123.206.28.63:9030/ServiceController/HouseKeepingFeedback'; //测试服调用接口的平台服务地址
  902. $url = 'http://139.196.47.211:9030/ServiceController/HouseKeepingFeedback'; //调用接口的平台服务地址
  903. }
  904. $ch = curl_init();
  905. curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
  906. curl_setopt($ch, CURLOPT_URL, $url);
  907. curl_setopt($ch, CURLOPT_POST, 1);
  908. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  909. curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
  910. $result = curl_exec($ch);
  911. curl_close($ch);
  912. $res = json_decode($result,true);
  913. if ($res['ReturnCode'] == '00'){
  914. return true;
  915. } else {
  916. return false;
  917. }
  918. }
  919. public function actionOutputExcel(){
  920. $export =Yii::app()->request->getParam('export','execute_order');
  921. $export_type = Yii::app()->request->getParam('export_type','');
  922. if($export == 'execute_order'){
  923. $endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
  924. if($export_type == 'day'){
  925. $name=date('Y-m-d').'日订单执行汇总'; //生成的Excel文件文件名
  926. $beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
  927. } else if($export_type == 'week') {
  928. $name=date('Y-m-d').'周订单执行汇总'; //生成的Excel文件文件名
  929. $beginYesterday=mktime(0,0,0,date('m'),date('d')-6,date('Y'));
  930. } else if($export_type == 'month') {
  931. $name=date('Y-m-d').'月订单执行汇总'; //生成的Excel文件文件名
  932. $beginYesterday=mktime(0,0,0,date('m')-1,1,date('Y'));
  933. $endYesterday=mktime(0,0,0,date('m'),1,date('Y'))-1;
  934. } else if($export_type == 'year'){
  935. $name=date('Y-m-d').'年订单执行汇总'; //生成的Excel文件文件名
  936. $beginYesterday=mktime(0,0,0,1,1,2016);
  937. $endYesterday=mktime(0,0,0,12,1,2017);
  938. }
  939. } else {
  940. $beginYesterday=mktime(0,0,0,date('m')-1,1,date('Y'));
  941. $endYesterday=mktime(0,0,0,date('m'),1,date('Y'))-1;
  942. if($export =='tech') {
  943. $name=date('Y-m-d').'月保洁师营收'; //生成的Excel文件文件名
  944. } else {
  945. $name=date('Y-m-d').'月订单明细汇总'; //生成的Excel文件文件名
  946. }
  947. }
  948. $criteria = new EMongoCriteria();
  949. $criteria->booking_time('>=',$beginYesterday);//开始时间
  950. $criteria->booking_time('<=',$endYesterday);//结束时间
  951. $criteria->status('==',6);
  952. $data = ROrder::model()->findAll($criteria);
  953. $rows = CommonFn::getRowsFromCursor($data);
  954. $data = ROrder::model()->parse($rows);
  955. $res=Service::factory('ExcelToArrayService')->push($data,$name,$export);
  956. echo "导出成功";
  957. }
  958. //导入文件
  959. public function actionLoad()
  960. {
  961. $excelFile = '/var/www/1.xlsx';//获取文件名
  962. //这里就是导入PHPExcel包了,要用的时候就加这么两句,方便吧
  963. Yii::$enableIncludePath = false;
  964. Yii::import('application.extensions.PHPExcel.PHPExcel', 1);
  965. $phpexcel = new PHPExcel;
  966. //$excelReader = PHPExcel_IOFactory::createReader('Excel5');
  967. $excelReader = PHPExcel_IOFactory::createReader('Excel2007');
  968. $phpexcel = $excelReader->load($excelFile)->getSheet(0);//载入文件并获取第一个sheet
  969. $total_line = $phpexcel->getHighestRow();
  970. $total_column = $phpexcel->getHighestColumn();
  971. for ($row = 2; $row <= $total_line; $row++) {
  972. $data = array();
  973. for ($column = 'A'; $column <= $total_column; $column++) {
  974. $data[] = trim($phpexcel->getCell($column . $row)->getValue());
  975. }
  976. var_dump($data);
  977. echo '<br/>';
  978. }
  979. }
  980. /**
  981. * 根据服务类型导出一个月的订单折线图
  982. *
  983. */
  984. public function actionExportLineChartForOneMonth()
  985. {
  986. Yii::$enableIncludePath = false;
  987. Yii::import('ext.phpexcel.PHPExcel', 1);
  988. $objPHPExcel = new PHPExcel();
  989. $objSheet = $objPHPExcel->getActiveSheet();
  990. $criteria = new EMongoCriteria();
  991. $criteria->status('==',1);
  992. $product = Product::model()->parse(CommonFn::getRowsFromCursor(Product::model()->findAll($criteria)));
  993. $data = array();
  994. $data[0][0] = '';
  995. $days = date("t",mktime(0,0,0,date('m')-1,1,date('Y')));//获取上一个月总天数
  996. foreach ($product as $key => $value){
  997. $data[0][$key+1] = $value['type_str'];
  998. /**
  999. * 根据获取的产品类型,进行分类,将每一天相同服务类型的总订单存储到数组中,
  1000. */
  1001. for($i=1;$i<=$days;$i++){
  1002. $order_criteria = new EMongoCriteria();
  1003. $order_criteria->type('==',$value['type']);
  1004. $start_time = mktime(0,0,0,date('m')-1,$i,date('Y'));
  1005. $end_time = mktime(23,59,59,date('m')-1,$i,date('Y'));
  1006. $order_criteria->booking_time('>=',$start_time);
  1007. $order_criteria->booking_time('<=',$end_time);
  1008. $orders = ROrder::model()->findAll($order_criteria);
  1009. $data[$i][0] = date('m-d',$start_time);
  1010. //$data[$i][$key+1] = count($orders) == 0?1:count($orders)+1;
  1011. $data[$i][$key+1] = count($orders) == 0?'0':count($orders);
  1012. }
  1013. }
  1014. $objSheet->fromArray($data);
  1015. //图表
  1016. $labels = array(
  1017. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$B$1',null,1),//1
  1018. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$C$1',null,1),//2
  1019. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$D$1',null,1),//3
  1020. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$E$1',null,1),//4
  1021. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$F$1',null,1),//5
  1022. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$G$1',null,1),//6
  1023. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$H$1',null,1),//7
  1024. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$I$1',null,1),//8
  1025. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$J$1',null,1),//9
  1026. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$K$1',null,1),//10
  1027. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$L$1',null,1),//11
  1028. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$M$1',null,1),//12
  1029. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$N$1',null,1),//13
  1030. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$O$1',null,1),//14
  1031. );
  1032. $xLabels = array(
  1033. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$A$2:$A$'.($days+1),null,14),//取x轴刻度
  1034. );
  1035. $datas = array(
  1036. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$B$2:$B$'.($days+1),null,14),//1
  1037. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$C$2:$C$'.($days+1),null,14),//2
  1038. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$D$2:$D$'.($days+1),null,14),//3
  1039. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$E$2:$E$'.($days+1),null,14),//4
  1040. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$F$2:$F$'.($days+1),null,14),//5
  1041. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$G$2:$G$'.($days+1),null,14),//6
  1042. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$H$2:$H$'.($days+1),null,14),//7
  1043. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$I$2:$I$'.($days+1),null,14),//8
  1044. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$J$2:$J$'.($days+1),null,14),//9
  1045. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$K$2:$K$'.($days+1),null,14),//10
  1046. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$L$2:$L$'.($days+1),null,14),//11
  1047. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$M$2:$M$'.($days+1),null,14),//12
  1048. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$N$2:$N$'.($days+1),null,14),//13
  1049. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$O$2:$O$'.($days+1),null,14),//14
  1050. );
  1051. $series = array(
  1052. new PHPExcel_Chart_DataSeries(
  1053. PHPExcel_Chart_DataSeries::TYPE_LINECHART,
  1054. PHPExcel_Chart_DataSeries::GROUPING_STANDARD,
  1055. range(0, count($datas)-1),
  1056. $labels,
  1057. $xLabels,
  1058. $datas
  1059. )
  1060. ); //图表框架
  1061. $layout=new PHPExcel_Chart_Layout();
  1062. $layout->setShowVal(true);
  1063. $areas = new PHPExcel_Chart_PlotArea(null,$series);
  1064. $legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_BOTTOM,$layout,false);
  1065. $title = new PHPExcel_Chart_Title("订单数角度对比(月)折线图");
  1066. $ytitle = new PHPExcel_Chart_Title("订单数");
  1067. $chart = new PHPExcel_Chart('line_chart',$title,$legend,$areas,true,false,null,$ytitle);
  1068. $chart->setTopLeftPosition("A1")->setBottomRightPosition("P31"); //图表位置
  1069. $objSheet->addChart($chart);
  1070. $excel = 'Excel2007';
  1071. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,$excel);
  1072. $objWriter->setIncludeCharts(true); //图表必须
  1073. // $objWriter->save($dir.'/export.xls'); //生成excel文件
  1074. CommonFn::browser_export($excel,date('m')."月份订单数角度对比(月)折线图.xlsx"); //浏览器输出
  1075. CommonFn::SaveViaTempFile($objWriter);
  1076. }
  1077. /**
  1078. * 根据服务类型导出一个周/月的订单柱形图 同比 三周的数据 横轴为服务项目
  1079. *
  1080. */
  1081. public function actionExportColumChartForOneMonth()
  1082. {
  1083. Yii::$enableIncludePath = false;
  1084. Yii::import('ext.phpexcel.PHPExcel', 1);
  1085. $week = Yii::app()->request->getParam('week','1');
  1086. $objPHPExcel = new PHPExcel();
  1087. $objSheet = $objPHPExcel->getActiveSheet();
  1088. $criteria = new EMongoCriteria();
  1089. $criteria->status('==',1);
  1090. $product = Product::model()->parse(CommonFn::getRowsFromCursor(Product::model()->findAll($criteria)));
  1091. $data = array();
  1092. $total = count($product)+1;
  1093. $data[0][0] = '';
  1094. if($week){
  1095. $days = 7;
  1096. foreach ($product as $key => $value) {
  1097. $data[$key + 1][0] = $value['name'];
  1098. /**
  1099. * 根据获取的产品类型,进行分类,将每一周相同服务类型的总订单存储到数组中,
  1100. */
  1101. for ($i=0;$i<=2;$i++){
  1102. $order_criteria = new EMongoCriteria();
  1103. $order_criteria->type('==', $value['type']);
  1104. //1 7 8 14 15 21
  1105. $start_time = mktime(23, 59, 59, date('m'), date('d')-(7*$i+1), date('Y'));
  1106. $end_time = mktime(0, 0, 0, date('m'), date('d')-(($i+1)*7), date('Y'));
  1107. $order_criteria->booking_time('<=', $start_time);
  1108. $order_criteria->booking_time('>=', $end_time);
  1109. $orders = ROrder::model()->findAll($order_criteria);
  1110. $data[0][$i+1] = date('m-d', $start_time);
  1111. $data[$key+1][$i+1] = count($orders) == 0?1:count($orders)+1;
  1112. $data[$key+1][$i + 1] = count($orders) == 0 ? '0' : count($orders);
  1113. }
  1114. /* for ($i = 1; $i <= $days; $i++) {
  1115. $order_criteria = new EMongoCriteria();
  1116. $order_criteria->type('==', $value['type']);
  1117. $start_time = mktime(0, 0, 0, date('m'), date('d')-$i, date('Y'));
  1118. $end_time = mktime(23, 59, 59, date('m'), date('d')-$i, date('Y'));
  1119. $order_criteria->booking_time('>=', $start_time);
  1120. $order_criteria->booking_time('<=', $end_time);
  1121. $orders = ROrder::model()->findAll($order_criteria);
  1122. $data[$i][0] = date('m-d', $start_time);
  1123. $data[$i][$key+1] = count($orders) == 0?1:count($orders)+1;
  1124. $data[$i][$key + 1] = count($orders) == 0 ? '0' : count($orders);
  1125. }*/
  1126. }
  1127. $name = '同比数据分析(周)柱形图.xlsx';
  1128. } else {
  1129. $days = date("t",mktime(0,0,0,date('m')-1,1,date('Y')));//获取上一个月总天数
  1130. foreach ($product as $key => $value){
  1131. $data[0][$key+1] = $value['type_str'];
  1132. /**
  1133. * 根据获取的产品类型,进行分类,将每一天相同服务类型的总订单存储到数组中,
  1134. */
  1135. for($i=1;$i<=$days;$i++){
  1136. $order_criteria = new EMongoCriteria();
  1137. $order_criteria->type('==',$value['type']);
  1138. $start_time = mktime(0,0,0,date('m')-1,$i,date('Y'));
  1139. $end_time = mktime(23,59,59,date('m')-1,$i,date('Y'));
  1140. $order_criteria->booking_time('>=',$start_time);
  1141. $order_criteria->booking_time('<=',$end_time);
  1142. $orders = ROrder::model()->findAll($order_criteria);
  1143. $data[$i][0] = date('m-d',$start_time);
  1144. //$data[$i][$key+1] = count($orders) == 0?1:count($orders)+1;
  1145. $data[$i][$key+1] = count($orders) == 0?'0':count($orders);
  1146. }
  1147. }
  1148. $name = '同比数据分析(月)柱形图.xlsx';
  1149. }
  1150. $objSheet->fromArray($data);
  1151. //图表
  1152. $labels = array(
  1153. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$B$1',null,1),//1
  1154. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$C$1',null,1),//2
  1155. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$D$1',null,1),//3
  1156. );
  1157. $xLabels = array(
  1158. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$A$2:$A$'.$total,null,$total),//取x轴刻度
  1159. );
  1160. $datas = array(
  1161. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$B$2:$B$'.$total,null,$total),//1
  1162. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$C$2:$C$'.$total,null,$total),//2
  1163. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$D$2:$D$'.$total,null,$total),//3
  1164. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$E$2:$E$'.$total,null,$total),//4
  1165. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$F$2:$F$'.$total,null,$total),//5
  1166. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$G$2:$G$'.$total,null,$total),//6
  1167. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$H$2:$H$'.$total,null,$total),//7
  1168. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$I$2:$I$'.$total,null,$total),//8
  1169. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$J$2:$J$'.$total,null,$total),//9
  1170. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$K$2:$K$'.$total,null,$total),//10
  1171. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$L$2:$L$'.$total,null,$total),//11
  1172. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$M$2:$M$'.$total,null,$total),//12
  1173. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$N$2:$N$'.$total,null,$total),//13
  1174. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$O$2:$O$'.$total,null,$total),//14
  1175. );
  1176. /*if($week){
  1177. $labels = array(
  1178. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$B$1',null,1),//1
  1179. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$C$1',null,1),//2
  1180. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$D$1',null,1),//3
  1181. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$E$1',null,1),//4
  1182. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$F$1',null,1),//5
  1183. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$G$1',null,1),//6
  1184. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$H$1',null,1),//7
  1185. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$I$1',null,1),//8
  1186. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$J$1',null,1),//9
  1187. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$K$1',null,1),//10
  1188. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$L$1',null,1),//11
  1189. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$M$1',null,1),//12
  1190. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$N$1',null,1),//13
  1191. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$O$1',null,1),//14
  1192. );
  1193. $xLabels = array(
  1194. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$A$2:$A$8',null,7),//取x轴刻度
  1195. );
  1196. $datas = array(
  1197. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$B$2:$B$8',null,7),//1
  1198. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$C$2:$C$8',null,7),//2
  1199. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$D$2:$D$8',null,7),//3
  1200. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$E$2:$E$8',null,7),//4
  1201. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$F$2:$F$8',null,7),//5
  1202. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$G$2:$G$8',null,7),//6
  1203. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$H$2:$H$8',null,7),//7
  1204. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$I$2:$I$8',null,7),//8
  1205. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$J$2:$J$8',null,7),//9
  1206. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$K$2:$K$8',null,7),//10
  1207. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$L$2:$L$8',null,7),//11
  1208. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$M$2:$M$8',null,7),//12
  1209. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$N$2:$N$8',null,7),//13
  1210. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$O$2:$O$8',null,7),//14
  1211. );
  1212. } else {
  1213. $labels = array(
  1214. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$B$1',null,1),//1
  1215. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$C$1',null,1),//2
  1216. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$D$1',null,1),//3
  1217. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$E$1',null,1),//4
  1218. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$F$1',null,1),//5
  1219. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$G$1',null,1),//6
  1220. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$H$1',null,1),//7
  1221. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$I$1',null,1),//8
  1222. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$J$1',null,1),//9
  1223. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$K$1',null,1),//10
  1224. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$L$1',null,1),//11
  1225. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$M$1',null,1),//12
  1226. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$N$1',null,1),//13
  1227. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$O$1',null,1),//14
  1228. );
  1229. $xLabels = array(
  1230. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$A$2:$A$'.($days+1),null,14),//取x轴刻度
  1231. );
  1232. $datas = array(
  1233. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$B$2:$B$'.($days+1),null,14),//1
  1234. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$C$2:$C$'.($days+1),null,14),//2
  1235. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$D$2:$D$'.($days+1),null,14),//3
  1236. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$E$2:$E$'.($days+1),null,14),//4
  1237. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$F$2:$F$'.($days+1),null,14),//5
  1238. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$G$2:$G$'.($days+1),null,14),//6
  1239. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$H$2:$H$'.($days+1),null,14),//7
  1240. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$I$2:$I$'.($days+1),null,14),//8
  1241. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$J$2:$J$'.($days+1),null,14),//9
  1242. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$K$2:$K$'.($days+1),null,14),//10
  1243. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$L$2:$L$'.($days+1),null,14),//11
  1244. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$M$2:$M$'.($days+1),null,14),//12
  1245. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$N$2:$N$'.($days+1),null,14),//13
  1246. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$O$2:$O$'.($days+1),null,14),//14
  1247. );
  1248. }*/
  1249. $series = array(
  1250. new PHPExcel_Chart_DataSeries(
  1251. PHPExcel_Chart_DataSeries::TYPE_BARCHART,
  1252. PHPExcel_Chart_DataSeries::GROUPING_STANDARD,
  1253. range(0, count($labels)-1),
  1254. $labels,
  1255. $xLabels,
  1256. $datas
  1257. )
  1258. ); //图表框架
  1259. $layout=new PHPExcel_Chart_Layout();
  1260. $layout->setShowVal(true);
  1261. $areas = new PHPExcel_Chart_PlotArea(null,$series);
  1262. $legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT,$layout,false);
  1263. $title = new PHPExcel_Chart_Title("同比数据分析");
  1264. $ytitle = new PHPExcel_Chart_Title("订单数");
  1265. $chart = new PHPExcel_Chart('line_chart',$title,$legend,$areas,true,false,null,$ytitle);
  1266. $chart->setTopLeftPosition("A1")->setBottomRightPosition("AI30"); //图表位置
  1267. $objSheet->addChart($chart);
  1268. $excel = 'Excel2007';
  1269. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,$excel);
  1270. $objWriter->setIncludeCharts(true); //图表必须
  1271. // $objWriter->save($dir.'/export.xls'); //生成excel文件
  1272. CommonFn::browser_export($excel,date('m').$name); //浏览器输出
  1273. CommonFn::SaveViaTempFile($objWriter);
  1274. }
  1275. /**
  1276. * 根据支付方式导出一个周/月的订单柱形图
  1277. */
  1278. public function actionExportColumChartForOneMonthByChannel()
  1279. {
  1280. Yii::$enableIncludePath = false;
  1281. Yii::import('ext.phpexcel.PHPExcel', 1);
  1282. $week = Yii::app()->request->getParam('week','');
  1283. $objPHPExcel = new PHPExcel();
  1284. $objSheet = $objPHPExcel->getActiveSheet();
  1285. $criteria = new EMongoCriteria();
  1286. $channel = ROrder::$channel_option;
  1287. $data = array();
  1288. $data[0][0] = '';
  1289. $k =1;
  1290. if($week){
  1291. $days = 7;
  1292. foreach ($channel as $key => $value) {
  1293. $data[0][$k] = $value['name'];
  1294. /**
  1295. * 根据获取的产品类型,进行分类,将每一天相同服务类型的总订单存储到数组中,
  1296. */
  1297. for ($i = 1; $i <= $days; $i++) {
  1298. $order_criteria = new EMongoCriteria();
  1299. $order_criteria->channel('==',$key);
  1300. $start_time = mktime(0, 0, 0, date('m'), date('d')-$i, date('Y'));
  1301. $end_time = mktime(23, 59, 59, date('m'), date('d')-$i, date('Y'));
  1302. $order_criteria->booking_time('>=', $start_time);
  1303. $order_criteria->booking_time('<=', $end_time);
  1304. $orders = ROrder::model()->findAll($order_criteria);
  1305. $data[$i][0] = date('m-d', $start_time);
  1306. //$data[$i][$key+1] = count($orders) == 0?1:count($orders)+1;
  1307. $data[$i][$k] = count($orders) == 0 ? '0' : count($orders);
  1308. }
  1309. $k ++;
  1310. }
  1311. $name = "支付方式分析(周)柱形图.xlsx";
  1312. } else {
  1313. $days = date("t",mktime(0,0,0,date('m')-1,1,date('Y')));//获取上一个月总天数
  1314. foreach ($channel as $key => $value){
  1315. $data[0][$k] = $value['name'];
  1316. /**
  1317. * 根据获取的支付类型,进行分类,将每一天相同服务类型的总订单存储到数组中,
  1318. */
  1319. for($i=1;$i<=$days;$i++){
  1320. $order_criteria = new EMongoCriteria();
  1321. $order_criteria->channel('==',$key);
  1322. $start_time = mktime(0,0,0,date('m')-1,$i,date('Y'));
  1323. $end_time = mktime(23,59,59,date('m')-1,$i,date('Y'));
  1324. $order_criteria->booking_time('>=',$start_time);
  1325. $order_criteria->booking_time('<=',$end_time);
  1326. $orders = ROrder::model()->findAll($order_criteria);
  1327. $data[$i][0] = date('m-d',$start_time);
  1328. //$data[$i][$key+1] = count($orders) == 0?1:count($orders)+1;
  1329. $data[$i][$k] = count($orders) == 0?'0':count($orders);
  1330. }
  1331. $k++;
  1332. }
  1333. $name = "支付方式分析(月)柱形图.xlsx";
  1334. }
  1335. $objSheet->fromArray($data);
  1336. //图表
  1337. $labels = array(
  1338. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$B$1',null,1),//1
  1339. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$C$1',null,1),//2
  1340. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$D$1',null,1),//3
  1341. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$E$1',null,1),//4
  1342. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$F$1',null,1),//5
  1343. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$G$1',null,1),//6
  1344. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$H$1',null,1),//7
  1345. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$I$1',null,1),//8
  1346. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$J$1',null,1),//9
  1347. );
  1348. $xLabels = array(
  1349. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$A$2:$A$'.($days+1),null,9),//取x轴刻度
  1350. );
  1351. $datas = array(
  1352. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$B$2:$B$'.($days+1),null,9),//1
  1353. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$C$2:$C$'.($days+1),null,9),//2
  1354. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$D$2:$D$'.($days+1),null,9),//3
  1355. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$E$2:$E$'.($days+1),null,9),//4
  1356. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$F$2:$F$'.($days+1),null,9),//5
  1357. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$G$2:$G$'.($days+1),null,9),//6
  1358. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$H$2:$H$'.($days+1),null,9),//7
  1359. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$I$2:$I$'.($days+1),null,9),//8
  1360. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$J$2:$J$'.($days+1),null,9),//9
  1361. );
  1362. /*if($week){
  1363. $labels = array(
  1364. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$B$1',null,1),//1
  1365. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$C$1',null,1),//2
  1366. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$D$1',null,1),//3
  1367. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$E$1',null,1),//4
  1368. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$F$1',null,1),//5
  1369. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$G$1',null,1),//6
  1370. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$H$1',null,1),//7
  1371. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$I$1',null,1),//8
  1372. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$J$1',null,1),//9
  1373. );
  1374. $xLabels = array(
  1375. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$A$2:$A$8',null,9),//取x轴刻度
  1376. );
  1377. $datas = array(
  1378. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$B$2:$B$8',null,9),//1
  1379. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$C$2:$C$8',null,9),//2
  1380. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$D$2:$D$8',null,9),//3
  1381. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$E$2:$E$8',null,9),//4
  1382. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$F$2:$F$8',null,9),//5
  1383. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$G$2:$G$8',null,9),//6
  1384. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$H$2:$H$8',null,9),//7
  1385. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$I$2:$I$8',null,9),//8
  1386. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$J$2:$J$8',null,9),//9
  1387. );
  1388. $name = "支付方式分析(周)柱形图.xlsx";
  1389. } else {
  1390. $labels = array(
  1391. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$B$1',null,1),//1
  1392. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$C$1',null,1),//2
  1393. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$D$1',null,1),//3
  1394. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$E$1',null,1),//4
  1395. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$F$1',null,1),//5
  1396. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$G$1',null,1),//6
  1397. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$H$1',null,1),//7
  1398. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$I$1',null,1),//8
  1399. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$J$1',null,1),//9
  1400. );
  1401. $xLabels = array(
  1402. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$A$2:$A$'.($days+1),null,9),//取x轴刻度
  1403. );
  1404. $datas = array(
  1405. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$B$2:$B$'.($days+1),null,9),//1
  1406. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$C$2:$C$'.($days+1),null,9),//2
  1407. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$D$2:$D$'.($days+1),null,9),//3
  1408. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$E$2:$E$'.($days+1),null,9),//4
  1409. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$F$2:$F$'.($days+1),null,9),//5
  1410. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$G$2:$G$'.($days+1),null,9),//6
  1411. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$H$2:$H$'.($days+1),null,9),//7
  1412. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$I$2:$I$'.($days+1),null,9),//8
  1413. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$J$2:$J$'.($days+1),null,9),//9
  1414. );
  1415. $name = "支付方式分析(月)柱形图.xlsx";
  1416. }*/
  1417. $series = array(
  1418. new PHPExcel_Chart_DataSeries(
  1419. PHPExcel_Chart_DataSeries::TYPE_BARCHART,
  1420. PHPExcel_Chart_DataSeries::GROUPING_STANDARD,
  1421. range(0, count($datas)-1),
  1422. $labels,
  1423. $xLabels,
  1424. $datas
  1425. )
  1426. ); //图表框架
  1427. $layout=new PHPExcel_Chart_Layout();
  1428. $layout->setShowVal(true);
  1429. $areas = new PHPExcel_Chart_PlotArea(null,$series);
  1430. $legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT,$layout,false);
  1431. $title = new PHPExcel_Chart_Title("支付方式分析");
  1432. $ytitle = new PHPExcel_Chart_Title("订单数");
  1433. $chart = new PHPExcel_Chart('line_chart',$title,$legend,$areas,true,false,null,$ytitle);
  1434. $chart->setTopLeftPosition("A1")->setBottomRightPosition("P31"); //图表位置
  1435. $objSheet->addChart($chart);
  1436. $excel = 'Excel2007';
  1437. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,$excel);
  1438. $objWriter->setIncludeCharts(true); //图表必须
  1439. // $objWriter->save($dir.'/export.xls'); //生成excel文件
  1440. CommonFn::browser_export($excel,date('m').$name); //浏览器输出
  1441. CommonFn::SaveViaTempFile($objWriter);
  1442. }
  1443. public function actionTest(){
  1444. $arr = array(
  1445. array('', '一班', '二班', '三班','四班'),
  1446. array('不及格', 20, 30, 40,67),
  1447. array('良好', 30, 50, 55,67),
  1448. array('优秀', 15, 17, 20,67)
  1449. );
  1450. Yii::$enableIncludePath = false;
  1451. Yii::import('ext.phpexcel.PHPExcel', 1);
  1452. $objPHPExcel = new PHPExcel();
  1453. $objSheet = $objPHPExcel->getActiveSheet();
  1454. $criteria = new EMongoCriteria();
  1455. $criteria->status('==',1);
  1456. $name = '同比数据分析(月)柱形图.xlsx';
  1457. $objSheet->fromArray($arr);
  1458. //图表
  1459. $labels = array(
  1460. new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', null, 1),//一班
  1461. new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', null, 1),//二班
  1462. new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', null, 1),//三班
  1463. new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$E$1', null, 1),//三班
  1464. );
  1465. $xLabels = array(
  1466. new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$4', null, 3),
  1467. );
  1468. $datas = array(
  1469. new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$4', null, 4),//取一班的数据
  1470. new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$4', null, 4),//取二班的数据
  1471. new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$4', null, 4),//取三班的数据
  1472. new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$E$2:$E$4', null, 4),//取三班的数据
  1473. );
  1474. $series = array(
  1475. new PHPExcel_Chart_DataSeries(
  1476. PHPExcel_Chart_DataSeries::TYPE_BARCHART,
  1477. PHPExcel_Chart_DataSeries::GROUPING_STANDARD,
  1478. range(0, count($labels)-1),
  1479. $labels,
  1480. $xLabels,
  1481. $datas
  1482. )
  1483. ); //图表框架
  1484. $layout=new PHPExcel_Chart_Layout();
  1485. $layout->setShowVal(true);
  1486. $areas = new PHPExcel_Chart_PlotArea(null,$series);
  1487. $legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT,$layout,false);
  1488. $title = new PHPExcel_Chart_Title("同比数据分析");
  1489. $ytitle = new PHPExcel_Chart_Title("订单数");
  1490. $chart = new PHPExcel_Chart('line_chart',$title,$legend,$areas,true,false,null,$ytitle);
  1491. $chart->setTopLeftPosition("A1")->setBottomRightPosition("P31"); //图表位置
  1492. $objSheet->addChart($chart);
  1493. $excel = 'Excel2007';
  1494. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,$excel);
  1495. $objWriter->setIncludeCharts(true); //图表必须
  1496. // $objWriter->save($dir.'/export.xls'); //生成excel文件
  1497. CommonFn::browser_export($excel,date('m').$name); //浏览器输出
  1498. CommonFn::SaveViaTempFile($objWriter);
  1499. }
  1500. }