ROrderController.php 41 KB

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