ROrderController.php 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  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.club' : 'http://apitest.yiguanjia.club';
  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.club' : 'http://apitest.yiguanjia.club';
  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.club' : 'http://apitest.yiguanjia.club';
  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. $criteria->channel('==','jingbai');
  953. $data = ROrder::model()->findAll($criteria);
  954. $rows = CommonFn::getRowsFromCursor($data);
  955. $data = ROrder::model()->parse($rows);
  956. $res=Service::factory('ExcelToArrayService')->push($data,$name,$export);
  957. echo "导出成功";
  958. }
  959. //导入文件
  960. public function actionLoad()
  961. {
  962. $excelFile = '/var/www/1.xlsx';//获取文件名
  963. //这里就是导入PHPExcel包了,要用的时候就加这么两句,方便吧
  964. Yii::$enableIncludePath = false;
  965. Yii::import('application.extensions.PHPExcel.PHPExcel', 1);
  966. $phpexcel = new PHPExcel;
  967. //$excelReader = PHPExcel_IOFactory::createReader('Excel5');
  968. $excelReader = PHPExcel_IOFactory::createReader('Excel2007');
  969. $phpexcel = $excelReader->load($excelFile)->getSheet(0);//载入文件并获取第一个sheet
  970. $total_line = $phpexcel->getHighestRow();
  971. $total_column = $phpexcel->getHighestColumn();
  972. for ($row = 2; $row <= $total_line; $row++) {
  973. $data = array();
  974. for ($column = 'A'; $column <= $total_column; $column++) {
  975. $data[] = trim($phpexcel->getCell($column . $row)->getValue());
  976. }
  977. var_dump($data);
  978. echo '<br/>';
  979. }
  980. }
  981. /**
  982. * 根据服务类型导出一个月的订单折线图
  983. *
  984. */
  985. public function actionExportLineChartForOneMonth()
  986. {
  987. Yii::$enableIncludePath = false;
  988. Yii::import('ext.phpexcel.PHPExcel', 1);
  989. $objPHPExcel = new PHPExcel();
  990. $objSheet = $objPHPExcel->getActiveSheet();
  991. $criteria = new EMongoCriteria();
  992. $criteria->status('==',1);
  993. $product = Product::model()->parse(CommonFn::getRowsFromCursor(Product::model()->findAll($criteria)));
  994. $data = array();
  995. $data[0][0] = '';
  996. $days = date("t",mktime(0,0,0,date('m')-1,1,date('Y')));//获取上一个月总天数
  997. foreach ($product as $key => $value){
  998. $data[0][$key+1] = $value['type_str'];
  999. /**
  1000. * 根据获取的产品类型,进行分类,将每一天相同服务类型的总订单存储到数组中,
  1001. */
  1002. for($i=1;$i<=$days;$i++){
  1003. $order_criteria = new EMongoCriteria();
  1004. $order_criteria->type('==',$value['type']);
  1005. $start_time = mktime(0,0,0,date('m')-1,$i,date('Y'));
  1006. $end_time = mktime(23,59,59,date('m')-1,$i,date('Y'));
  1007. $order_criteria->booking_time('>=',$start_time);
  1008. $order_criteria->booking_time('<=',$end_time);
  1009. $orders = ROrder::model()->findAll($order_criteria);
  1010. $data[$i][0] = date('m-d',$start_time);
  1011. //$data[$i][$key+1] = count($orders) == 0?1:count($orders)+1;
  1012. $data[$i][$key+1] = count($orders) == 0?'0':count($orders);
  1013. }
  1014. }
  1015. $objSheet->fromArray($data);
  1016. //图表
  1017. $labels = array(
  1018. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$B$1',null,1),//1
  1019. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$C$1',null,1),//2
  1020. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$D$1',null,1),//3
  1021. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$E$1',null,1),//4
  1022. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$F$1',null,1),//5
  1023. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$G$1',null,1),//6
  1024. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$H$1',null,1),//7
  1025. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$I$1',null,1),//8
  1026. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$J$1',null,1),//9
  1027. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$K$1',null,1),//10
  1028. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$L$1',null,1),//11
  1029. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$M$1',null,1),//12
  1030. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$N$1',null,1),//13
  1031. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$O$1',null,1),//14
  1032. );
  1033. $xLabels = array(
  1034. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$A$2:$A$'.($days+1),null,14),//取x轴刻度
  1035. );
  1036. $datas = array(
  1037. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$B$2:$B$'.($days+1),null,14),//1
  1038. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$C$2:$C$'.($days+1),null,14),//2
  1039. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$D$2:$D$'.($days+1),null,14),//3
  1040. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$E$2:$E$'.($days+1),null,14),//4
  1041. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$F$2:$F$'.($days+1),null,14),//5
  1042. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$G$2:$G$'.($days+1),null,14),//6
  1043. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$H$2:$H$'.($days+1),null,14),//7
  1044. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$I$2:$I$'.($days+1),null,14),//8
  1045. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$J$2:$J$'.($days+1),null,14),//9
  1046. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$K$2:$K$'.($days+1),null,14),//10
  1047. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$L$2:$L$'.($days+1),null,14),//11
  1048. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$M$2:$M$'.($days+1),null,14),//12
  1049. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$N$2:$N$'.($days+1),null,14),//13
  1050. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$O$2:$O$'.($days+1),null,14),//14
  1051. );
  1052. $series = array(
  1053. new PHPExcel_Chart_DataSeries(
  1054. PHPExcel_Chart_DataSeries::TYPE_LINECHART,
  1055. PHPExcel_Chart_DataSeries::GROUPING_STANDARD,
  1056. range(0, count($datas)-1),
  1057. $labels,
  1058. $xLabels,
  1059. $datas
  1060. )
  1061. ); //图表框架
  1062. $layout=new PHPExcel_Chart_Layout();
  1063. $layout->setShowVal(true);
  1064. $areas = new PHPExcel_Chart_PlotArea(null,$series);
  1065. $legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_BOTTOM,$layout,false);
  1066. $title = new PHPExcel_Chart_Title("订单数角度对比(月)折线图");
  1067. $ytitle = new PHPExcel_Chart_Title("订单数");
  1068. $chart = new PHPExcel_Chart('line_chart',$title,$legend,$areas,true,false,null,$ytitle);
  1069. $chart->setTopLeftPosition("A1")->setBottomRightPosition("P31"); //图表位置
  1070. $objSheet->addChart($chart);
  1071. $excel = 'Excel2007';
  1072. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,$excel);
  1073. $objWriter->setIncludeCharts(true); //图表必须
  1074. // $objWriter->save($dir.'/export.xls'); //生成excel文件
  1075. CommonFn::browser_export($excel,date('m')."月份订单数角度对比(月)折线图.xlsx"); //浏览器输出
  1076. CommonFn::SaveViaTempFile($objWriter);
  1077. }
  1078. /**
  1079. * 根据服务类型导出一个周/月的订单柱形图 同比 三周的数据 横轴为服务项目
  1080. *
  1081. */
  1082. public function actionExportColumChartForOneMonth()
  1083. {
  1084. Yii::$enableIncludePath = false;
  1085. Yii::import('ext.phpexcel.PHPExcel', 1);
  1086. $week = Yii::app()->request->getParam('week','1');
  1087. $objPHPExcel = new PHPExcel();
  1088. $objSheet = $objPHPExcel->getActiveSheet();
  1089. $criteria = new EMongoCriteria();
  1090. $criteria->status('==',1);
  1091. $product = Product::model()->parse(CommonFn::getRowsFromCursor(Product::model()->findAll($criteria)));
  1092. $data = array();
  1093. $total = count($product)+1;
  1094. $data[0][0] = '';
  1095. if($week){
  1096. $days = 7;
  1097. foreach ($product as $key => $value) {
  1098. $data[$key + 1][0] = $value['name'];
  1099. /**
  1100. * 根据获取的产品类型,进行分类,将每一周相同服务类型的总订单存储到数组中,
  1101. */
  1102. for ($i=0;$i<=2;$i++){
  1103. $order_criteria = new EMongoCriteria();
  1104. $order_criteria->type('==', $value['type']);
  1105. //1 7 8 14 15 21
  1106. $start_time = mktime(23, 59, 59, date('m'), date('d')-(7*$i+1), date('Y'));
  1107. $end_time = mktime(0, 0, 0, date('m'), date('d')-(($i+1)*7), date('Y'));
  1108. $order_criteria->booking_time('<=', $start_time);
  1109. $order_criteria->booking_time('>=', $end_time);
  1110. $orders = ROrder::model()->findAll($order_criteria);
  1111. $data[0][$i+1] = date('m-d', $start_time);
  1112. $data[$key+1][$i+1] = count($orders) == 0?1:count($orders)+1;
  1113. $data[$key+1][$i + 1] = count($orders) == 0 ? '0' : count($orders);
  1114. }
  1115. /* for ($i = 1; $i <= $days; $i++) {
  1116. $order_criteria = new EMongoCriteria();
  1117. $order_criteria->type('==', $value['type']);
  1118. $start_time = mktime(0, 0, 0, date('m'), date('d')-$i, date('Y'));
  1119. $end_time = mktime(23, 59, 59, date('m'), date('d')-$i, date('Y'));
  1120. $order_criteria->booking_time('>=', $start_time);
  1121. $order_criteria->booking_time('<=', $end_time);
  1122. $orders = ROrder::model()->findAll($order_criteria);
  1123. $data[$i][0] = date('m-d', $start_time);
  1124. $data[$i][$key+1] = count($orders) == 0?1:count($orders)+1;
  1125. $data[$i][$key + 1] = count($orders) == 0 ? '0' : count($orders);
  1126. }*/
  1127. }
  1128. $name = '同比数据分析(周)柱形图.xlsx';
  1129. } else {
  1130. $days = date("t",mktime(0,0,0,date('m')-1,1,date('Y')));//获取上一个月总天数
  1131. foreach ($product as $key => $value){
  1132. $data[0][$key+1] = $value['type_str'];
  1133. /**
  1134. * 根据获取的产品类型,进行分类,将每一天相同服务类型的总订单存储到数组中,
  1135. */
  1136. for($i=1;$i<=$days;$i++){
  1137. $order_criteria = new EMongoCriteria();
  1138. $order_criteria->type('==',$value['type']);
  1139. $start_time = mktime(0,0,0,date('m')-1,$i,date('Y'));
  1140. $end_time = mktime(23,59,59,date('m')-1,$i,date('Y'));
  1141. $order_criteria->booking_time('>=',$start_time);
  1142. $order_criteria->booking_time('<=',$end_time);
  1143. $orders = ROrder::model()->findAll($order_criteria);
  1144. $data[$i][0] = date('m-d',$start_time);
  1145. //$data[$i][$key+1] = count($orders) == 0?1:count($orders)+1;
  1146. $data[$i][$key+1] = count($orders) == 0?'0':count($orders);
  1147. }
  1148. }
  1149. $name = '同比数据分析(月)柱形图.xlsx';
  1150. }
  1151. $objSheet->fromArray($data);
  1152. //图表
  1153. $labels = array(
  1154. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$B$1',null,1),//1
  1155. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$C$1',null,1),//2
  1156. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$D$1',null,1),//3
  1157. );
  1158. $xLabels = array(
  1159. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$A$2:$A$'.$total,null,$total),//取x轴刻度
  1160. );
  1161. $datas = array(
  1162. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$B$2:$B$'.$total,null,$total),//1
  1163. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$C$2:$C$'.$total,null,$total),//2
  1164. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$D$2:$D$'.$total,null,$total),//3
  1165. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$E$2:$E$'.$total,null,$total),//4
  1166. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$F$2:$F$'.$total,null,$total),//5
  1167. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$G$2:$G$'.$total,null,$total),//6
  1168. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$H$2:$H$'.$total,null,$total),//7
  1169. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$I$2:$I$'.$total,null,$total),//8
  1170. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$J$2:$J$'.$total,null,$total),//9
  1171. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$K$2:$K$'.$total,null,$total),//10
  1172. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$L$2:$L$'.$total,null,$total),//11
  1173. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$M$2:$M$'.$total,null,$total),//12
  1174. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$N$2:$N$'.$total,null,$total),//13
  1175. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$O$2:$O$'.$total,null,$total),//14
  1176. );
  1177. /*if($week){
  1178. $labels = array(
  1179. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$B$1',null,1),//1
  1180. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$C$1',null,1),//2
  1181. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$D$1',null,1),//3
  1182. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$E$1',null,1),//4
  1183. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$F$1',null,1),//5
  1184. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$G$1',null,1),//6
  1185. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$H$1',null,1),//7
  1186. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$I$1',null,1),//8
  1187. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$J$1',null,1),//9
  1188. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$K$1',null,1),//10
  1189. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$L$1',null,1),//11
  1190. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$M$1',null,1),//12
  1191. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$N$1',null,1),//13
  1192. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$O$1',null,1),//14
  1193. );
  1194. $xLabels = array(
  1195. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$A$2:$A$8',null,7),//取x轴刻度
  1196. );
  1197. $datas = array(
  1198. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$B$2:$B$8',null,7),//1
  1199. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$C$2:$C$8',null,7),//2
  1200. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$D$2:$D$8',null,7),//3
  1201. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$E$2:$E$8',null,7),//4
  1202. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$F$2:$F$8',null,7),//5
  1203. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$G$2:$G$8',null,7),//6
  1204. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$H$2:$H$8',null,7),//7
  1205. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$I$2:$I$8',null,7),//8
  1206. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$J$2:$J$8',null,7),//9
  1207. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$K$2:$K$8',null,7),//10
  1208. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$L$2:$L$8',null,7),//11
  1209. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$M$2:$M$8',null,7),//12
  1210. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$N$2:$N$8',null,7),//13
  1211. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$O$2:$O$8',null,7),//14
  1212. );
  1213. } else {
  1214. $labels = array(
  1215. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$B$1',null,1),//1
  1216. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$C$1',null,1),//2
  1217. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$D$1',null,1),//3
  1218. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$E$1',null,1),//4
  1219. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$F$1',null,1),//5
  1220. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$G$1',null,1),//6
  1221. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$H$1',null,1),//7
  1222. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$I$1',null,1),//8
  1223. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$J$1',null,1),//9
  1224. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$K$1',null,1),//10
  1225. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$L$1',null,1),//11
  1226. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$M$1',null,1),//12
  1227. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$N$1',null,1),//13
  1228. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$O$1',null,1),//14
  1229. );
  1230. $xLabels = array(
  1231. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$A$2:$A$'.($days+1),null,14),//取x轴刻度
  1232. );
  1233. $datas = array(
  1234. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$B$2:$B$'.($days+1),null,14),//1
  1235. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$C$2:$C$'.($days+1),null,14),//2
  1236. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$D$2:$D$'.($days+1),null,14),//3
  1237. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$E$2:$E$'.($days+1),null,14),//4
  1238. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$F$2:$F$'.($days+1),null,14),//5
  1239. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$G$2:$G$'.($days+1),null,14),//6
  1240. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$H$2:$H$'.($days+1),null,14),//7
  1241. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$I$2:$I$'.($days+1),null,14),//8
  1242. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$J$2:$J$'.($days+1),null,14),//9
  1243. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$K$2:$K$'.($days+1),null,14),//10
  1244. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$L$2:$L$'.($days+1),null,14),//11
  1245. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$M$2:$M$'.($days+1),null,14),//12
  1246. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$N$2:$N$'.($days+1),null,14),//13
  1247. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$O$2:$O$'.($days+1),null,14),//14
  1248. );
  1249. }*/
  1250. $series = array(
  1251. new PHPExcel_Chart_DataSeries(
  1252. PHPExcel_Chart_DataSeries::TYPE_BARCHART,
  1253. PHPExcel_Chart_DataSeries::GROUPING_STANDARD,
  1254. range(0, count($labels)-1),
  1255. $labels,
  1256. $xLabels,
  1257. $datas
  1258. )
  1259. ); //图表框架
  1260. $layout=new PHPExcel_Chart_Layout();
  1261. $layout->setShowVal(true);
  1262. $areas = new PHPExcel_Chart_PlotArea(null,$series);
  1263. $legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT,$layout,false);
  1264. $title = new PHPExcel_Chart_Title("同比数据分析");
  1265. $ytitle = new PHPExcel_Chart_Title("订单数");
  1266. $chart = new PHPExcel_Chart('line_chart',$title,$legend,$areas,true,false,null,$ytitle);
  1267. $chart->setTopLeftPosition("A1")->setBottomRightPosition("AI30"); //图表位置
  1268. $objSheet->addChart($chart);
  1269. $excel = 'Excel2007';
  1270. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,$excel);
  1271. $objWriter->setIncludeCharts(true); //图表必须
  1272. // $objWriter->save($dir.'/export.xls'); //生成excel文件
  1273. CommonFn::browser_export($excel,date('m').$name); //浏览器输出
  1274. CommonFn::SaveViaTempFile($objWriter);
  1275. }
  1276. /**
  1277. * 根据支付方式导出一个周/月的订单柱形图
  1278. */
  1279. public function actionExportColumChartForOneMonthByChannel()
  1280. {
  1281. Yii::$enableIncludePath = false;
  1282. Yii::import('ext.phpexcel.PHPExcel', 1);
  1283. $week = Yii::app()->request->getParam('week','');
  1284. $objPHPExcel = new PHPExcel();
  1285. $objSheet = $objPHPExcel->getActiveSheet();
  1286. $criteria = new EMongoCriteria();
  1287. $channel = ROrder::$channel_option;
  1288. $data = array();
  1289. $data[0][0] = '';
  1290. $k =1;
  1291. if($week){
  1292. $days = 7;
  1293. foreach ($channel as $key => $value) {
  1294. $data[0][$k] = $value['name'];
  1295. /**
  1296. * 根据获取的产品类型,进行分类,将每一天相同服务类型的总订单存储到数组中,
  1297. */
  1298. for ($i = 1; $i <= $days; $i++) {
  1299. $order_criteria = new EMongoCriteria();
  1300. $order_criteria->channel('==',$key);
  1301. $start_time = mktime(0, 0, 0, date('m'), date('d')-$i, date('Y'));
  1302. $end_time = mktime(23, 59, 59, date('m'), date('d')-$i, date('Y'));
  1303. $order_criteria->booking_time('>=', $start_time);
  1304. $order_criteria->booking_time('<=', $end_time);
  1305. $orders = ROrder::model()->findAll($order_criteria);
  1306. $data[$i][0] = date('m-d', $start_time);
  1307. //$data[$i][$key+1] = count($orders) == 0?1:count($orders)+1;
  1308. $data[$i][$k] = count($orders) == 0 ? '0' : count($orders);
  1309. }
  1310. $k ++;
  1311. }
  1312. $name = "支付方式分析(周)柱形图.xlsx";
  1313. } else {
  1314. $days = date("t",mktime(0,0,0,date('m')-1,1,date('Y')));//获取上一个月总天数
  1315. foreach ($channel as $key => $value){
  1316. $data[0][$k] = $value['name'];
  1317. /**
  1318. * 根据获取的支付类型,进行分类,将每一天相同服务类型的总订单存储到数组中,
  1319. */
  1320. for($i=1;$i<=$days;$i++){
  1321. $order_criteria = new EMongoCriteria();
  1322. $order_criteria->channel('==',$key);
  1323. $start_time = mktime(0,0,0,date('m')-1,$i,date('Y'));
  1324. $end_time = mktime(23,59,59,date('m')-1,$i,date('Y'));
  1325. $order_criteria->booking_time('>=',$start_time);
  1326. $order_criteria->booking_time('<=',$end_time);
  1327. $orders = ROrder::model()->findAll($order_criteria);
  1328. $data[$i][0] = date('m-d',$start_time);
  1329. //$data[$i][$key+1] = count($orders) == 0?1:count($orders)+1;
  1330. $data[$i][$k] = count($orders) == 0?'0':count($orders);
  1331. }
  1332. $k++;
  1333. }
  1334. $name = "支付方式分析(月)柱形图.xlsx";
  1335. }
  1336. $objSheet->fromArray($data);
  1337. //图表
  1338. $labels = array(
  1339. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$B$1',null,1),//1
  1340. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$C$1',null,1),//2
  1341. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$D$1',null,1),//3
  1342. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$E$1',null,1),//4
  1343. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$F$1',null,1),//5
  1344. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$G$1',null,1),//6
  1345. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$H$1',null,1),//7
  1346. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$I$1',null,1),//8
  1347. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$J$1',null,1),//9
  1348. );
  1349. $xLabels = array(
  1350. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$A$2:$A$'.($days+1),null,9),//取x轴刻度
  1351. );
  1352. $datas = array(
  1353. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$B$2:$B$'.($days+1),null,9),//1
  1354. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$C$2:$C$'.($days+1),null,9),//2
  1355. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$D$2:$D$'.($days+1),null,9),//3
  1356. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$E$2:$E$'.($days+1),null,9),//4
  1357. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$F$2:$F$'.($days+1),null,9),//5
  1358. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$G$2:$G$'.($days+1),null,9),//6
  1359. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$H$2:$H$'.($days+1),null,9),//7
  1360. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$I$2:$I$'.($days+1),null,9),//8
  1361. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$J$2:$J$'.($days+1),null,9),//9
  1362. );
  1363. /*if($week){
  1364. $labels = array(
  1365. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$B$1',null,1),//1
  1366. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$C$1',null,1),//2
  1367. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$D$1',null,1),//3
  1368. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$E$1',null,1),//4
  1369. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$F$1',null,1),//5
  1370. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$G$1',null,1),//6
  1371. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$H$1',null,1),//7
  1372. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$I$1',null,1),//8
  1373. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$J$1',null,1),//9
  1374. );
  1375. $xLabels = array(
  1376. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$A$2:$A$8',null,9),//取x轴刻度
  1377. );
  1378. $datas = array(
  1379. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$B$2:$B$8',null,9),//1
  1380. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$C$2:$C$8',null,9),//2
  1381. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$D$2:$D$8',null,9),//3
  1382. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$E$2:$E$8',null,9),//4
  1383. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$F$2:$F$8',null,9),//5
  1384. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$G$2:$G$8',null,9),//6
  1385. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$H$2:$H$8',null,9),//7
  1386. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$I$2:$I$8',null,9),//8
  1387. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$J$2:$J$8',null,9),//9
  1388. );
  1389. $name = "支付方式分析(周)柱形图.xlsx";
  1390. } else {
  1391. $labels = array(
  1392. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$B$1',null,1),//1
  1393. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$C$1',null,1),//2
  1394. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$D$1',null,1),//3
  1395. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$E$1',null,1),//4
  1396. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$F$1',null,1),//5
  1397. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$G$1',null,1),//6
  1398. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$H$1',null,1),//7
  1399. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$I$1',null,1),//8
  1400. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$J$1',null,1),//9
  1401. );
  1402. $xLabels = array(
  1403. new PHPExcel_Chart_DataSeriesValues('String','Worksheet!$A$2:$A$'.($days+1),null,9),//取x轴刻度
  1404. );
  1405. $datas = array(
  1406. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$B$2:$B$'.($days+1),null,9),//1
  1407. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$C$2:$C$'.($days+1),null,9),//2
  1408. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$D$2:$D$'.($days+1),null,9),//3
  1409. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$E$2:$E$'.($days+1),null,9),//4
  1410. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$F$2:$F$'.($days+1),null,9),//5
  1411. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$G$2:$G$'.($days+1),null,9),//6
  1412. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$H$2:$H$'.($days+1),null,9),//7
  1413. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$I$2:$I$'.($days+1),null,9),//8
  1414. new PHPExcel_Chart_DataSeriesValues('Number','Worksheet!$J$2:$J$'.($days+1),null,9),//9
  1415. );
  1416. $name = "支付方式分析(月)柱形图.xlsx";
  1417. }*/
  1418. $series = array(
  1419. new PHPExcel_Chart_DataSeries(
  1420. PHPExcel_Chart_DataSeries::TYPE_BARCHART,
  1421. PHPExcel_Chart_DataSeries::GROUPING_STANDARD,
  1422. range(0, count($datas)-1),
  1423. $labels,
  1424. $xLabels,
  1425. $datas
  1426. )
  1427. ); //图表框架
  1428. $layout=new PHPExcel_Chart_Layout();
  1429. $layout->setShowVal(true);
  1430. $areas = new PHPExcel_Chart_PlotArea(null,$series);
  1431. $legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT,$layout,false);
  1432. $title = new PHPExcel_Chart_Title("支付方式分析");
  1433. $ytitle = new PHPExcel_Chart_Title("订单数");
  1434. $chart = new PHPExcel_Chart('line_chart',$title,$legend,$areas,true,false,null,$ytitle);
  1435. $chart->setTopLeftPosition("A1")->setBottomRightPosition("P31"); //图表位置
  1436. $objSheet->addChart($chart);
  1437. $excel = 'Excel2007';
  1438. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,$excel);
  1439. $objWriter->setIncludeCharts(true); //图表必须
  1440. // $objWriter->save($dir.'/export.xls'); //生成excel文件
  1441. CommonFn::browser_export($excel,date('m').$name); //浏览器输出
  1442. CommonFn::SaveViaTempFile($objWriter);
  1443. }
  1444. public function actionTest(){
  1445. $arr = array(
  1446. array('', '一班', '二班', '三班','四班'),
  1447. array('不及格', 20, 30, 40,67),
  1448. array('良好', 30, 50, 55,67),
  1449. array('优秀', 15, 17, 20,67)
  1450. );
  1451. Yii::$enableIncludePath = false;
  1452. Yii::import('ext.phpexcel.PHPExcel', 1);
  1453. $objPHPExcel = new PHPExcel();
  1454. $objSheet = $objPHPExcel->getActiveSheet();
  1455. $criteria = new EMongoCriteria();
  1456. $criteria->status('==',1);
  1457. $name = '同比数据分析(月)柱形图.xlsx';
  1458. $objSheet->fromArray($arr);
  1459. //图表
  1460. $labels = array(
  1461. new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', null, 1),//一班
  1462. new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', null, 1),//二班
  1463. new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', null, 1),//三班
  1464. new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$E$1', null, 1),//三班
  1465. );
  1466. $xLabels = array(
  1467. new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$4', null, 3),
  1468. );
  1469. $datas = array(
  1470. new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$4', null, 4),//取一班的数据
  1471. new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$4', null, 4),//取二班的数据
  1472. new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$4', null, 4),//取三班的数据
  1473. new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$E$2:$E$4', null, 4),//取三班的数据
  1474. );
  1475. $series = array(
  1476. new PHPExcel_Chart_DataSeries(
  1477. PHPExcel_Chart_DataSeries::TYPE_BARCHART,
  1478. PHPExcel_Chart_DataSeries::GROUPING_STANDARD,
  1479. range(0, count($labels)-1),
  1480. $labels,
  1481. $xLabels,
  1482. $datas
  1483. )
  1484. ); //图表框架
  1485. $layout=new PHPExcel_Chart_Layout();
  1486. $layout->setShowVal(true);
  1487. $areas = new PHPExcel_Chart_PlotArea(null,$series);
  1488. $legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT,$layout,false);
  1489. $title = new PHPExcel_Chart_Title("同比数据分析");
  1490. $ytitle = new PHPExcel_Chart_Title("订单数");
  1491. $chart = new PHPExcel_Chart('line_chart',$title,$legend,$areas,true,false,null,$ytitle);
  1492. $chart->setTopLeftPosition("A1")->setBottomRightPosition("P31"); //图表位置
  1493. $objSheet->addChart($chart);
  1494. $excel = 'Excel2007';
  1495. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,$excel);
  1496. $objWriter->setIncludeCharts(true); //图表必须
  1497. // $objWriter->save($dir.'/export.xls'); //生成excel文件
  1498. CommonFn::browser_export($excel,date('m').$name); //浏览器输出
  1499. CommonFn::SaveViaTempFile($objWriter);
  1500. }
  1501. }