ROrderController.php 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  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. //$station = Yii::app()->request->getParam('station_id', '');
  121. $technician_ids = array();
  122. $technician_names = array();
  123. $technicians = array();
  124. $nums = Yii::app()->request->getParam('tech_nums');
  125. for($i=0;$i<=$nums;$i++) {
  126. if(Yii::app()->request->getParam('extra_add_info_'.$i)) {
  127. $technician_ids[] = Yii::app()->request->getParam('extra_add_info_id_'.$i);
  128. $technician_names[] = Yii::app()->request->getParam('extra_add_info_'.$i);
  129. }
  130. }
  131. if(!$counts){
  132. CommonFn::requestAjax(false, '购买数量错误');
  133. }
  134. // 保洁师信息检查
  135. // 根据ID直接查询保洁师信息(优先使用联想功能)
  136. if (isset($technician_ids)) {
  137. foreach($technician_ids as $key => $technician_id){
  138. $technician_obj = TechInfo::get($technician_id);
  139. if ($technician_obj) {
  140. $technicians[$key]['technician_id'] = $technician_obj->_id;
  141. $technicians[$key]['technician_name'] = $technician_obj->name;
  142. } else {
  143. CommonFn::requestAjax(false, '保洁师不存在');
  144. break;
  145. }
  146. }
  147. // ID为0时根据输入框信息查询
  148. } else if (isset($technician_names)) {
  149. $criteria = new EMongoCriteria();
  150. foreach($technician_names as $key => $technician_name) {
  151. $criteria->name = $technician_name;
  152. $technician_obj = TechInfo::model()->find($criteria);
  153. if ($technician_obj) {
  154. $technicians[$key]['technician_id'] = $technician_obj->_id;
  155. $technicians[$key]['technician_name'] = $technician_obj->name;
  156. } else {
  157. CommonFn::requestAjax(false, '保洁师不存在');
  158. break;
  159. }
  160. }
  161. } else {
  162. $technician_obj = null;
  163. //$technician_id = 0;
  164. // $technician_name = '';
  165. foreach($technicians as $key => $value) {
  166. $technicians[$key]['$technician_id'] = 0;
  167. $technicians[$key]['$technician_name'] = 0;
  168. }
  169. }
  170. //var_dump($technicians);exit;
  171. if($status == 100){
  172. CommonFn::requestAjax(false, '必须指定状态!');
  173. }
  174. $criteria = new EMongoCriteria();
  175. $criteria->_id = new MongoId($id);
  176. $order = ROrder::model()->find($criteria);
  177. // if($order->status == -1 || $order->status == -2){
  178. // CommonFn::requestAjax(false, '已取消,已退款订单不支持更改');
  179. // }
  180. // 获取用户信息,修改用户订单统计
  181. // 2015-11-16
  182. $user_id = $order->user;
  183. if (!empty($user_id)) {
  184. $user = RUser::get($user_id);
  185. } else {
  186. $user = '';
  187. }
  188. if (empty($order)){
  189. CommonFn::requestAjax(false, '订单不存在');
  190. }
  191. $flag = 0;
  192. //精佰退单接口 状态为申请退款并且是精佰的订单
  193. if ($order->status == -3 && $order->channel == 'jingbai') {
  194. //确认申请退款状态变更成已退款订单 为退单订单
  195. $criteria = new EMongoCriteria();
  196. $criteria->OrderNo('==',$order->OrderNo);
  197. $criteria->status('==',-3);
  198. $orders = ROrder::model()->findAll($criteria);
  199. $orderId = '';
  200. $fin_price = 0.0;
  201. foreach ($orders as $value) {
  202. $orderId .= (string)$value->_id.',';
  203. $fin_price =$fin_price+ $value->final_price*0.5;
  204. }
  205. $fin_price = round($fin_price,2)*100;
  206. $orderId = rtrim(trim($orderId),',');
  207. if ($status == -2) {
  208. if ($remark == '1') {//退单 全额
  209. //已出发 已上门 订单
  210. $res = self::feedbackOrder(1, $order->OrderNo, $orderId, $fin_price);
  211. } else {//退单 不退钱
  212. $res = self::feedbackOrder(1, $order->OrderNo, $orderId, 0);
  213. }
  214. $flag = 1;
  215. } else if($status == 2 ){//不退单
  216. $res = self::feedbackOrder(0,$order->OrderNo,$orderId,0);
  217. $flag = 1;
  218. }
  219. if( $order->booking_time != $booking_time){
  220. self::feedbackOrderRemaker(0,$order->OrderNo,$orderId,0,$order->booking_time);
  221. }
  222. if ($flag && $res){
  223. foreach ($orders as $value) {
  224. $value->status = $status;
  225. $value->save();
  226. }
  227. }
  228. }
  229. if(($order->status!=-1||$order->status!=-2)&&($status==-1||$status==-2)){
  230. foreach ($order->coupons as $user_coupon) {
  231. $user_coupon = UserCoupon::get($user_coupon);
  232. $user_coupon->status = 1;
  233. $user_coupon->update(array('status'),true);
  234. }
  235. }
  236. if($order->status!=-2 && $status == -2) {
  237. $order->refund_time = time();
  238. $order_info = $order->parseRow($order);
  239. $month = date('m', $order_info['booking_time']);
  240. $day = date('d', $order_info['booking_time']);
  241. $address = $order_info['address']['poi']['name'] . $order_info['address']['detail'];
  242. CommonSMS::send('order_retrieve', array('month' => $month, 'day' => $day, 'address' => $address, 'mobile' => $order_info['address']['mobile']));
  243. // 申请退款处理完成后通知保洁师
  244. foreach ($technician_ids as $key => $technician_id) {
  245. $technician_obj = TechInfo::get($technician_id);
  246. if ($technician_obj && $technician_obj->weixin_userid) {
  247. $url_prefix = ENVIRONMENT == 'product' ? 'http://api.yiguanjia.me' : 'http://apitest.yiguanjia.me';
  248. $wechat = O2oApp::getWechatActive();
  249. $wechat_data = array(
  250. 'touser' => $technician_obj->weixin_userid,
  251. 'msgtype' => 'news',
  252. 'agentid' => '1',
  253. 'news' => array(
  254. 'articles' => array(
  255. array(
  256. 'title' => '壹管家提示-订单退款完成',
  257. 'description' => $technician_obj->name . '你好!用户于' . date('m月d日H:i', $order->apply_refund_time) . '申请退款的订单已处理完成。',
  258. //'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_id,
  259. 'url' => $url_prefix . '/index.php?r=o2o/myOrder/index'
  260. ),
  261. ),
  262. ),
  263. );
  264. if (!empty($order->append_orders)) {
  265. $count = count($order->append_orders);
  266. $wechat_data['news']['articles'][0]['description'] .= "\n\n本订单包含" . $count . "个追加订单,请注意查看。";
  267. }
  268. $wechat->sendMessage($wechat_data);
  269. }
  270. }
  271. }
  272. //取消订单
  273. if($order->status!=-1 && $status == -1){
  274. // 已完成订单不能取消
  275. if ($order->status == 6) {
  276. CommonFn::requestAjax(false, '已完成订单不可取消');
  277. }
  278. $order->cancel_time = time();
  279. $order_info = $order->parseRow($order);
  280. }
  281. //确认接单
  282. if($order->status!=3 && $status == 3){
  283. $order_info = $order->parseRow($order);
  284. }
  285. //订单完成后执行
  286. if($order->status!=6 && $status == 6 ){
  287. $order->finish_time = time();
  288. $order_info = $order->parseRow($order);
  289. /*$result = Service::factory('ScoreService')->changeScore((string)$order->user,intval($order->final_price),'下单奖爪币');
  290. if($result){
  291. $z_message = new ZMessage();
  292. $from_user = Yii::app()->params['sys_user'];
  293. $message_data = array(
  294. 'from_user' => $from_user,
  295. 'to_user' => (string)$order->user,
  296. 'content' => '您成功下单,获得了'.intval($order->final_price).'个爪币的奖励。',
  297. 'pics' => array(),
  298. 'voice' => array(),
  299. 'video'=> array()
  300. );
  301. $z_message->addMessage($message_data);
  302. CommonSMS::send('final_order',array('name' =>$order_info['address']['name'],'num' =>intval($order->final_price),'mobile'=>$order_info['address']['mobile']));
  303. }*/
  304. // 保洁师订单统计处理
  305. foreach($technician_ids as $key => $technician_id) {
  306. $technician_obj = TechInfo::get($technician_id);
  307. if ($technician_obj) {
  308. $tech_order_count = $technician_obj->order_count + 1;
  309. $technician_obj->order_count = $tech_order_count;
  310. $technician_obj->save();
  311. }
  312. }
  313. }
  314. $order->status = $status;
  315. $order->booking_time = $booking_time;
  316. $order->deal_time = $deal_time;
  317. $order->remark = $remark;
  318. $order->counts = $counts;
  319. //$order->station = new MongoId($station);
  320. // 是否通知保洁师
  321. $toTech = !empty($order->technicians)? true : false;
  322. //$order->technician = $technician_id;
  323. //$order->technician_name = $technician_name;
  324. $order->technicians = $technicians;
  325. //var_dump($order);exit;
  326. //判断是否为实惠或金百订单
  327. if($order->channel == 'shihui'){
  328. if ($status == 1) {//已支付
  329. $res = self::UpdateStatus((string)$order->_id, 5);
  330. $flag = 1;
  331. } else if($status ==3){//已接单
  332. $res = self::UpdateStatus((string)$order->_id, 15);
  333. $flag = 1;
  334. }else if($status ==6){//服务完成
  335. $res = self::UpdateStatus((string)$order->_id, 20);
  336. $flag = 1;
  337. }else if($status ==-1){//取消订单
  338. $res = self::DelOrder((string)$order->_id);
  339. $flag = 1;
  340. }
  341. }else if($order->channel == 'jingbai'){
  342. if($status ==3){//已接单
  343. $res = self::UpdateStatusForJingBai($order->OrderNo,(string)$order->_id, $status,$order->remark);
  344. $flag = 1;
  345. }else if($status ==6){//服务完成
  346. $res = self::UpdateStatusForJingBai($order->OrderNo,(string)$order->_id, $status,$order->remark);
  347. $flag = 1;
  348. }
  349. }
  350. if($flag){
  351. if (!$res) {
  352. CommonFn::requestAjax(false,'修改失败res='.$res.',flag='.$flag);
  353. }
  354. }
  355. $arr_order = array('cancel_time','refund_time','finish_time','status','booking_time','deal_time','remark', 'station', 'technicians');
  356. $success = $order->save(true,$arr_order);
  357. $char = false;
  358. // 通知保洁师
  359. if (in_array($status, array(1,2,3,4,5)) && $toTech && $success) {
  360. foreach($technician_ids as $key => $technician_id) {
  361. $technician_obj = TechInfo::get($technician_id);
  362. if ($technician_obj && $technician_obj->weixin_userid) {
  363. $url_prefix = ENVIRONMENT == 'product' ? 'http://api.yiguanjia.me' : 'http://apitest.yiguanjia.me';
  364. $wechat = O2oApp::getWechatActive();
  365. $wechat_data = array(
  366. 'touser' => $technician_obj->weixin_userid,
  367. 'msgtype' => 'news',
  368. 'agentid' => 1,
  369. 'news' => array(
  370. 'articles' => array(
  371. array(
  372. 'title' => '壹管家提示-新订单',
  373. 'description' => $technician_obj->name . '你好!刚刚有一个新的订单被分配给你,请点击查看。',
  374. //'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_id,
  375. 'url' => $url_prefix . '/index.php?r=o2o/myOrder/index'
  376. ),
  377. ),
  378. ),
  379. );
  380. $char = $wechat->sendMessage($wechat_data);
  381. }
  382. }
  383. }
  384. CommonFn::requestAjax($success, '微信'.$char, array());
  385. }
  386. // 根据手机号 获取对应用户的地址信息
  387. public function actionGetUserInfo(){
  388. $mobile = Yii::app()->request->getParam('mobile', '');
  389. $length = strlen($mobile);
  390. if ($length < 11) {
  391. $result[] = array(
  392. 'id' => 0,
  393. 'data' => '',
  394. 'description' => '请继续输入',
  395. 'content' => array()
  396. );
  397. echo json_encode($result);exit;
  398. }
  399. // $mobile_regex = new MongoRegex($mobile);
  400. $criteria = new EMongoCriteria();
  401. $criteria->sort('order_time', EMongoCriteria::SORT_DESC);
  402. $criteria->addCond('address.mobile', '==', $mobile);
  403. $cursor = ROrder::model()->findAll($criteria);
  404. $rows = CommonFn::getRowsFromCursor($cursor);
  405. if (empty($rows)) {
  406. $result[] = array(
  407. 'id' => 0,
  408. 'data' => '',
  409. 'description' => '没有匹配信息',
  410. 'content' => array()
  411. );
  412. echo json_encode($result);exit;
  413. }
  414. $result = array();
  415. $details = array();
  416. $index = 0;
  417. foreach($rows as $row){
  418. // 加入根据detail筛选,避免产生重复信息
  419. if (in_array($row['address']['detail'], $details)) continue;
  420. $details[] = $row['address']['detail'];
  421. $pio = isset($row['address']['poi']['name'])?$row['address']['poi']['name']:'';
  422. // 坐标获取(根据不同的来源)
  423. if ($row['channel'] == 'dianping') {
  424. $latitude = $row['address']['position']['lat'];
  425. $longitude = $row['address']['position']['lng'];
  426. } else {
  427. $latitude = isset($row['address']['position']['1'])?$row['address']['position']['1']:'';
  428. $longitude = isset($row['address']['position']['0'])?$row['address']['position']['0']:'';
  429. }
  430. // poi获取
  431. $poi_name = isset($row['address']['poi']['name']) ? $row['address']['poi']['name'] : '';
  432. $poi_uid = isset($row['address']['poi']['uid']) ? $row['address']['poi']['uid'] : '';
  433. $result[] = array(
  434. 'id' => $index,
  435. 'data' => $row['address']['mobile'],
  436. 'description' => $row['address']['province'].' '.$row['address']['city'].' '.$row['address']['area'].' '.$pio.$row['address']['detail'],
  437. 'content' => array(
  438. 'name' => $row['address']['name'],
  439. 'latitude' => $latitude,
  440. 'longitude' => $longitude,
  441. 'province' => $row['address']['province'],
  442. 'city' => $row['address']['city'],
  443. 'area' => $row['address']['area'],
  444. 'detail' => $row['address']['detail'],
  445. 'poi_name' => $poi_name,
  446. 'poi_uid' => $poi_uid,
  447. 'memo' => $row['memo']
  448. )
  449. );
  450. $index++;
  451. }
  452. echo json_encode($result);exit;
  453. }
  454. public function actionAdd () {
  455. // ------ 必须传入的数值 ------
  456. // --------- 订单信息 ---------
  457. $channel = Yii::app()->request->getParam('channel', '');
  458. $booking_time = Yii::app()->request->getParam('booking_time_add', '');
  459. $order_time = Yii::app()->request->getParam('order_time_add', '');
  460. $main_products = Yii::app()->request->getParam('main_products', '');
  461. $price = floatval(Yii::app()->request->getParam('price', 0));
  462. $final_price = floatval(Yii::app()->request->getParam('final_price', 0));
  463. $status = Yii::app()->request->getParam('status', -3);
  464. $station = Yii::app()->request->getParam('station', '57db39709f5160bb048b456a');
  465. // --------- 地址信息 ---------
  466. $mobile = Yii::app()->request->getParam('mobile', 0);
  467. $latitude = Yii::app()->request->getParam('latitude', 0);
  468. $longitude = Yii::app()->request->getParam('longitude', 0);
  469. $province = Yii::app()->request->getParam('province', '');
  470. $city = Yii::app()->request->getParam('city', '');
  471. $area = Yii::app()->request->getParam('area', '');
  472. $poi_name = Yii::app()->request->getParam('poi_name', '');
  473. $detail = Yii::app()->request->getParam('detail', '');
  474. $counts = intval(Yii::app()->request->getParam('counts', 1));
  475. $counts = $counts?$counts:1;
  476. $extra = Yii::app()->request->getParam('extra','[]');
  477. $extra = json_decode($extra);
  478. // 数据完整性检查
  479. // 2015-11-02 因存在赠送订单,删除金额的数据检查 : $price == 0 || $final_price == 0 ||
  480. // 2015-11-16 取消服务点录入,删除服务点数据检查 : || empty($station)
  481. $flag = empty($channel) || empty($booking_time) || empty($order_time);
  482. $flag = $flag || $status == -3;
  483. $flag = $flag || $mobile == 0 || $latitude == 0 || $longitude == 0;
  484. $flag = $flag || empty($province) || empty($city) || empty($area) || empty($poi_name) || empty($detail);
  485. if ($flag) {
  486. CommonFn::requestAjax(false, '请检查数据完整性', array());
  487. exit;
  488. }
  489. //if($channel == 'wz_app' || $channel == 'wx_pub'){
  490. //CommonFn::requestAjax(false, '不能录入渠道为壹管家微信||壹管家APP的订单', array());
  491. //exit;
  492. //}
  493. // 时间处理
  494. $booking_time = strtotime($booking_time);
  495. $order_time = strtotime($order_time);
  496. // ------ 可以留空的数值 ------
  497. $box = Yii::app()->request->getParam('box', array());
  498. $coupons = Yii::app()->request->getParam('coupons', array());
  499. $memo = Yii::app()->request->getParam('memo', '');
  500. $remark = Yii::app()->request->getParam('remark', '');
  501. $precedence = Yii::app()->request->getParam('precedence', 0);
  502. $have_comment = Yii::app()->request->getParam('have_comment', 0);
  503. $name = Yii::app()->request->getParam('name', '');
  504. $type = Yii::app()->request->getParam('type', 0);
  505. $user = Yii::app()->request->getParam('user', '');
  506. $poi_uid = Yii::app()->request->getParam('poi_uid', '');
  507. // 用户名的判断
  508. $channel_option = ROrder::$channel_option;
  509. $name = empty($name) ? $channel_option[$channel]['name'].'用户' : $name;
  510. // 支付渠道
  511. $pay_channel = $channel;
  512. // 服务数据整合
  513. $products[] = array(
  514. 'product' => new MongoId($main_products),
  515. 'count' => 1,
  516. 'extra' =>$extra
  517. );
  518. if (!empty($box)) {
  519. foreach ($box as $key => $value) {
  520. $products[] = array(
  521. 'product' => new MongoId($value),
  522. 'count' => 1,
  523. 'extra' =>$extra
  524. );
  525. }
  526. }
  527. // 地址数据整合
  528. $address = array(
  529. 'province' => $province,
  530. 'city' => $city,
  531. 'area' => $area,
  532. 'detail' => $detail,
  533. 'mobile' => $mobile,
  534. 'position' => array(
  535. // 'lat' => (float)$latitude,
  536. // 'lng' => (float)$longitude,
  537. 0 => (float)$longitude,
  538. 1 => (float)$latitude
  539. ),
  540. 'poi' => array(
  541. 'name' => $poi_name,
  542. 'uid' => $poi_uid
  543. ),
  544. 'name' => $name
  545. );
  546. // 订单类型判断
  547. if ($type == 0) {
  548. $criteria = new EMongoCriteria();
  549. $criteria->_id = new MongoId($main_products);
  550. $cursor = Product::model()->find($criteria);
  551. $type = $cursor->type;
  552. }
  553. $rOrder = new ROrder();
  554. $rOrder->channel = $channel;
  555. $rOrder->booking_time = intval($booking_time);
  556. $rOrder->order_time = intval($order_time);
  557. $rOrder->products = $products;
  558. $rOrder->price = floatval($price);
  559. $rOrder->final_price = floatval($final_price);
  560. $rOrder->precedence = intval($precedence);
  561. $rOrder->counts = $counts;
  562. $rOrder->coupons = $coupons;
  563. $rOrder->user = $user;
  564. $rOrder->status = intval($status);
  565. $rOrder->memo = $memo;
  566. $rOrder->remark = $remark;
  567. $rOrder->type = strval($type); // 数据库内使用string类型
  568. $rOrder->have_comment = intval($have_comment);
  569. $rOrder->station = new MongoId($station);
  570. $rOrder->address = $address;
  571. $rOrder->pay_channel = $pay_channel;
  572. $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');
  573. $success = $rOrder->save(true, $addROrder_arr);
  574. CommonFn::requestAjax($success, '', array());
  575. }
  576. /**
  577. * 请求申请退款订单接口
  578. */
  579. public function actionCheckRefundOrder() {
  580. $criteria = new EMongoCriteria();
  581. $criteria->status('==', -3);
  582. $cursor = ROrder::model()->findAll($criteria);
  583. $count = $cursor->count();
  584. if ($count > 0) {
  585. $data = array('code' => 1, 'count' => $count);
  586. } else {
  587. $data = array('code' => 0, 'count' => $count);
  588. }
  589. $list = new ARedisList('append_order_list');
  590. if($list->getCount() > 0){
  591. $key = $list->shift();
  592. $list->unshift($key);
  593. $data['procession_append_order_id'] = $key;
  594. $data['code'] = 2;
  595. }
  596. echo json_encode($data);
  597. }
  598. public function actionCancelProcess() {
  599. $orderid = Yii::app()->request->getParam('orderid','');
  600. $list = new ARedisList('append_order_list');
  601. $key = $list->shift();
  602. }
  603. /**
  604. * 重新选择保洁师接口
  605. */
  606. public function actionResetTech() {
  607. $id = Yii::app()->request->getParam('id', '');
  608. $nums = Yii::app()->request->getParam('nums', '');
  609. $technicians = array();
  610. $technician_ids = array();
  611. $technician_names = array();
  612. for($i=1;$i<=$nums;$i++) {
  613. if(Yii::app()->request->getParam('reset_extra_add_info_'.$i)) {
  614. $technician_ids[] = Yii::app()->request->getParam('reset_extra_add_info_id_'.$i);
  615. $technician_names[] = Yii::app()->request->getParam('reset_extra_add_info_'.$i);
  616. }
  617. }
  618. // 保洁师信息检查
  619. // 根据ID直接查询保洁师信息(优先使用联想功能)
  620. $technician_objs = array();
  621. foreach($technician_ids as $key => $technician_id) {
  622. if ($technician_id != 0) {
  623. $technician_obj = TechInfo::get($technician_id);
  624. if ($technician_obj) {
  625. $technicians[$key]['technician_id'] = $technician_obj->_id;
  626. $technicians[$key]['technician_name'] = $technician_obj->name;
  627. } else {
  628. CommonFn::requestAjax(false, '保洁师不存在');
  629. }
  630. // ID为0时根据输入框信息查询
  631. } else {
  632. foreach ($technician_names as $key => $technician_name)
  633. if ($technician_name != '') {
  634. $criteria = new EMongoCriteria();
  635. $criteria->name = $technician_name;
  636. $technician_obj = TechInfo::model()->find($criteria);
  637. if ($technician_obj) {
  638. $technicians[$key]['technician_id'] = $technician_obj->_id;
  639. $technicians[$key]['technician_name'] = $technician_obj->name;
  640. } else {
  641. CommonFn::requestAjax(false, '保洁师不存在');
  642. }
  643. } else {
  644. CommonFn::requestAjax(false, '保洁师姓名不能为空');
  645. }
  646. }
  647. $technician_objs[] = $technician_obj;
  648. }
  649. $orderid = new MongoId($id);
  650. $order = ROrder::model()->get($orderid);
  651. $toTech = isset($order->technicians) ? true : false;
  652. $fromTechs = $technician_names;
  653. //$order->technician = $technician_id;
  654. //$order->technician_name = $technician_name;
  655. $order->technicians = $technicians;
  656. $success = $order->save(true, array('technicians'));
  657. if ($toTech && $success) {
  658. foreach ($technician_objs as $technician_obj) {
  659. // 发送给被分配保洁师
  660. $wechat = O2oApp::getWechatActive();
  661. $url_prefix = ENVIRONMENT == 'product' ? 'http://api.yiguanjia.me' : 'http://apitest.yiguanjia.me';
  662. if (!empty($technician_obj->weixin_userid)) {
  663. $wechat_data = array(
  664. 'touser' => $technician_obj->weixin_userid,
  665. 'msgtype' => 'news',
  666. 'agentid' => '1',
  667. 'news' => array(
  668. 'articles' => array(
  669. array(
  670. 'title' => '壹管家提示-新订单',
  671. 'description' => $technician_obj->name . '你好!刚刚有一个新的订单被分配给你,请点击查看。',
  672. //'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_obj->_id,
  673. 'url' => $url_prefix . '/index.php?r=o2o/myOrder/index'
  674. ),
  675. ),
  676. ),
  677. );
  678. $wechat->sendMessage($wechat_data);
  679. }
  680. }
  681. // 发送给原保洁师
  682. foreach ($fromTechs as $fromTech) {
  683. $fromTechObj = TechInfo::get($fromTech);
  684. if (!empty($fromTechObj) && !empty($fromTechObj->weixin_userid)) {
  685. $wechat_data = array(
  686. 'touser' => $fromTechObj->weixin_userid,
  687. 'msgtype' => 'news',
  688. 'agentid' => '1',
  689. 'news' => array(
  690. 'articles' => array(
  691. array(
  692. 'title' => '壹管家提示-订单已被重新分配',
  693. 'description' => $fromTechObj->name . '你好!预定时间在' . date('m月d日H:i', $order->booking_time) . '的订单已被分配给其他保洁师。',
  694. 'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_obj->_id,
  695. ),
  696. ),
  697. ),
  698. );
  699. $wechat->sendMessage($wechat_data);
  700. }
  701. }
  702. }
  703. CommonFn::requestAjax($success, '', array());
  704. }
  705. /*public function actionDelOrder(){
  706. $delOrder = array('5826a4c89f5160d1048b52bf');
  707. $total = 0;
  708. foreach($delOrder as $value){
  709. $order = ROrder::model()->get(new MongoId($value));
  710. if($order->delete()){
  711. $total += 1;
  712. }
  713. }
  714. echo $total;
  715. }*/
  716. //取消订单
  717. public function DelOrder($orderId){
  718. $data['key'] = Yii::app()->params['shKey'];
  719. $data['version'] = '1.0';
  720. $data['serviceType'] = (int)26;
  721. $data['orderId'] = $orderId;//'57fde8059f5160c4048b4aeb';
  722. ksort($data);
  723. $str = '';
  724. $dat = '';
  725. foreach ($data as $key => $value) {
  726. $str .= $key.'='.$value.'&';
  727. $dat .= $key.'='.urlencode($value).'&';
  728. }
  729. $str = rtrim(trim($str),'&');
  730. $str .= $str.Yii::app()->params['shMd5Key'];
  731. $data['sign'] = strtoupper(md5($str));
  732. $dat .= 'sign='.urlencode($data['sign']);//构建post 参数
  733. $url = 'http://test2.app.hiwemeet.com/v2/openpf/home/order/thirdOrder/cancel'; //调用接口的平台服务地址
  734. $ch = curl_init();
  735. curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
  736. curl_setopt($ch, CURLOPT_URL, $url);
  737. curl_setopt($ch, CURLOPT_POST, 1);
  738. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  739. curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
  740. $result = curl_exec($ch);
  741. curl_close($ch);
  742. $res = json_decode($result,true);
  743. var_dump($res);
  744. if ($res['code']){
  745. return true;
  746. } else {
  747. return false;
  748. }
  749. }
  750. //更新订单状态
  751. public function UpdateStatus($orderId,$status){
  752. $data['key'] = Yii::app()->params['shKey'];
  753. $data['version'] = '1.0';
  754. $data['serviceType'] = (int)26;
  755. $data['orderId'] = (string)$orderId;
  756. $data['status'] = $status;
  757. ksort($data);
  758. $str = '';
  759. $dat = '';
  760. foreach ($data as $key => $value) {
  761. $str .= $key.'='.$value.'&';
  762. $dat .= $key.'='.urlencode($value).'&';
  763. }
  764. $str = rtrim(trim($str),'&');
  765. $str .= $str.Yii::app()->params['shMd5Key'];
  766. $data['sign'] = strtoupper(md5($str));
  767. $dat .= 'sign='.urlencode($data['sign']);//构建post 参数
  768. $url = 'http://test2.app.hiwemeet.com/v2/openpf/home/order/thirdOrder/update'; //调用接口的平台服务地址
  769. $ch = curl_init();
  770. curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
  771. curl_setopt($ch, CURLOPT_URL, $url);
  772. curl_setopt($ch, CURLOPT_POST, 1);
  773. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  774. curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
  775. $result = curl_exec($ch);
  776. curl_close($ch);
  777. $res = json_decode($result,true);
  778. if ($res['code']){
  779. return true;
  780. } else {
  781. return false;
  782. }
  783. }
  784. //更新订单状态
  785. /**
  786. * @param $orderId => order->orderNo
  787. * @param $status "00" 为创建订单,"01"为服务派单,"02"为服务完成
  788. * @param $HouseKeepingId 巾帼园自己的订单号 对应order->_id
  789. * @param $remark 订单备注
  790. * Sign 计算方法:OrderId+ StatusCode+ Remark+ HouseKeepingId+ Time+KEY 然后计算md5 值 KEY为巾帼园的key值
  791. * @return bool
  792. */
  793. public function UpdateStatusForJingBai($orderId,$HouseKeepingId,$status,$remark){
  794. $key = Yii::app()->params['JingBai'];
  795. $data['OrderId'] = $orderId;
  796. $data['HouseKeepingId'] = $HouseKeepingId;
  797. $data['Remark'] = $remark;
  798. if ($status == 3){//已接单
  799. $data['StatusCode'] = '01';
  800. } else if($status == 6){//已完成
  801. $data['StatusCode'] = '02';
  802. }
  803. $data['Time'] = date('Y-m-d H:i:s');
  804. $data['Sign'] = md5($data['OrderId'].$data['StatusCode'].$data['Remark'].$data['HouseKeepingId'].$data['Time'].$key);
  805. $dat = '';
  806. foreach ($data as $key => $value) {
  807. $dat .= $key.'='.urlencode($value).'&';
  808. }
  809. $dat = rtrim(trim($dat),'&');
  810. if (ENVIRONMENT == 'product'){
  811. $url = 'http://139.196.47.211:9230/ServiceController/SetHouseKeepingStatus'; //正式服调用接口的平台服务地址
  812. } else {
  813. $url = 'http://139.196.47.211:9030/ServiceController/SetHouseKeepingStatus'; //调用接口的平台服务地址
  814. }
  815. $ch = curl_init();
  816. curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
  817. curl_setopt($ch, CURLOPT_URL, $url);
  818. curl_setopt($ch, CURLOPT_POST, 1);
  819. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  820. curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
  821. $result = curl_exec($ch);
  822. curl_close($ch);
  823. $res = json_decode($result,true);
  824. if ($res['ReturnCode'] == '00'){
  825. return true;
  826. } else {
  827. return false;
  828. }
  829. }
  830. //不退单, 但是需要修改信息
  831. public function feedbackOrderRemaker($isCancel,$orderId,$orderNo,$money=0,$remark=null){
  832. $key = Yii::app()->params['JingBai'];
  833. $data['IsCancel'] = $isCancel;
  834. $data['OrderId'] = $orderId;
  835. $data['OrderNo'] = $orderNo;
  836. $data['Type'] = 'OrderRemark';
  837. $data['Remark'] = '修改预约时间'.date('Y-m-d H:i:s',$remark);
  838. $data['Sign'] = md5($orderId.$orderNo.$data['Remark'].$key);
  839. $dat = '';
  840. foreach ($data as $key => $value) {
  841. $dat .= $key.'='.urlencode($value).'&';
  842. }
  843. $dat = rtrim(trim($dat),'&');
  844. if (ENVIRONMENT == 'product'){
  845. $url = 'http://139.196.47.211:9230/ServiceController/HouseKeepingFeedback'; //正式服调用接口的平台服务地址
  846. } else {
  847. //$url = 'http://123.206.28.63:9030/ServiceController/HouseKeepingFeedback'; //测试服调用接口的平台服务地址
  848. $url = 'http://139.196.47.211:9030/ServiceController/HouseKeepingFeedback'; //调用接口的平台服务地址
  849. }
  850. $ch = curl_init();
  851. curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
  852. curl_setopt($ch, CURLOPT_URL, $url);
  853. curl_setopt($ch, CURLOPT_POST, 1);
  854. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  855. curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
  856. $result = curl_exec($ch);
  857. curl_close($ch);
  858. $res = json_decode($result,true);
  859. if ($res['ReturnCode'] == '00'){
  860. return true;
  861. } else {
  862. return false;
  863. }
  864. }
  865. //退单反馈信息接口
  866. /**
  867. * @param $isCanel 是否退单 1退单 0 不退单
  868. * @param $orderId 精佰订单Id 对应 巾帼园 OrderNo
  869. * @param $orderNo 巾帼园订单id 对应 巾帼园_id
  870. * @param $money 若退单巾帼园需要收多少钱,单位为分,不退单可不传
  871. * @param null $remark 退单状态备注包含修改信息,无修改此字段可不传
  872. * @return bool
  873. */
  874. public function feedbackOrder($isCancel,$orderId,$orderNo,$money=0)
  875. {
  876. $key = Yii::app()->params['JingBai'];
  877. $data['IsCancel'] = $isCancel;
  878. $data['OrderId'] = $orderId;
  879. $data['OrderNo'] = $orderNo;
  880. if(!$isCancel){//不退单
  881. $data['Type'] = 'CancleOrder';
  882. $data['Money'] = $money;
  883. $data['Sign'] = md5($isCancel.$orderId.$orderNo.$money.$key);
  884. }
  885. else {
  886. $data['Type'] = 'CancleOrder';
  887. $data['Money'] = $money;
  888. $data['Sign'] = md5($isCancel.$orderId.$orderNo.$money.$key);
  889. }
  890. $dat = '';
  891. foreach ($data as $key => $value) {
  892. $dat .= $key.'='.urlencode($value).'&';
  893. }
  894. $dat = rtrim(trim($dat),'&');
  895. if (ENVIRONMENT == 'product'){
  896. $url = 'http://139.196.47.211:9230/ServiceController/HouseKeepingFeedback'; //正式服调用接口的平台服务地址
  897. } else {
  898. //$url = 'http://123.206.28.63:9030/ServiceController/HouseKeepingFeedback'; //测试服调用接口的平台服务地址
  899. $url = 'http://139.196.47.211:9030/ServiceController/HouseKeepingFeedback'; //调用接口的平台服务地址
  900. }
  901. $ch = curl_init();
  902. curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
  903. curl_setopt($ch, CURLOPT_URL, $url);
  904. curl_setopt($ch, CURLOPT_POST, 1);
  905. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  906. curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
  907. $result = curl_exec($ch);
  908. curl_close($ch);
  909. $res = json_decode($result,true);
  910. if ($res['ReturnCode'] == '00'){
  911. return true;
  912. } else {
  913. return false;
  914. }
  915. }
  916. public function actionOutputExcel(){
  917. $data = ROrder::model()->findAll(); //
  918. $rows = CommonFn::getRowsFromCursor($data);
  919. $data = ROrder::model()->parse($rows);
  920. $name='OrderList'; //生成的Excel文件文件名
  921. $res=Service::factory('ExcelToArrayService')->push($data,$name);
  922. echo "导出成功";
  923. }
  924. }