123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845 |
- <?php
- class ROrderController extends AdminController{
- public function actionIndex()
- {
- $status_option = ROrder::$status_option;
- $status = CommonFn::getComboboxData($status_option, 100, true, 100);
- $channel_option = ROrder::$channel_option;
- $channels = CommonFn::getComboboxData($channel_option, 100, true, 100);
- // 服务点信息
- $criteria_station = new EMongoCriteria();
- $cursor = Station::model()->findAll($criteria_station);
- $rows = CommonFn::getRowsFromCursor($cursor);
- $parsedRows = Station::model()->parse($rows);
- $station_data = array();
- foreach ($parsedRows as $key => $v) {
- $station_data = array_merge($station_data, array($v['id'] => array('name' => $v['name'])));
- }
- $station = CommonFn::getComboboxData($station_data, 'all', true, 'all');
- // 订单类型
- $type_data = Yii::app()->params['o2o_service'];
- $type = CommonFn::getComboboxData($type_data, 100, true, 100);
- $this->render('index', array(
- 'status' => $status,
- 'channels' => $channels,
- 'station' => $station,
- 'type' => $type
- ));
- }
- public function actionList(){
- $filter_status = intval(Yii::app()->request->getParam('status', 100));
- $search = Yii::app()->request->getParam('search', '');
- $id = Yii::app()->request->getParam('id', '');
- $date_start_order = Yii::app()->request->getParam('date_start_order');
- $date_end_order = Yii::app()->request->getParam('date_end_order');
- $date_start_book= Yii::app()->request->getParam('date_start_book');
- $date_end_book = Yii::app()->request->getParam('date_end_book');
- $type = Yii::app()->request->getParam('type', 100);
- $have_pay = Yii::app()->request->getParam('have_pay', 0);
- $channel = Yii::app()->request->getParam('channel', 100);
- //$station = Yii::app()->request->getParam('station', 'all');
- $params = CommonFn::getPageParams();
- $criteria = new EMongoCriteria($params);
- if ($filter_status != 100){
- $criteria->status('==', $filter_status);
- }
- if ($id != ''){
- $order_id = new MongoId($id);
- $criteria->_id('==', $order_id);
- }
- if ($channel != 100){
- $criteria->channel('==', $channel);
- }
- if ($type != 100) {
- $criteria->type = $type;
- }
- if ($search != ''){
- if(CommonFn::isMongoId($search)){
- //$criteria->_id('==', new MongoId($search));
- $criteria->addCond('_id','or',new MongoId($search));
- $criteria->addCond('user','or',new MongoId($search));
- }
- else if(preg_match('/\d{8,11}/', $search)){
- $criteria->addCond('address.mobile','==',$search);
- if($have_pay){
- $criteria->addCond('status','>',0);
- }
- }else if(strlen($search) == 27){
- $criteria->charge_id('==', $search);
- }else{
- $criteria->addCond('address.name','==',$search);
- }
- }
- // 下单时间处理
- if (!empty($date_start_order) && !empty($date_end_order)) {
- // 开始时间处理
- $timestamp_start_order = strtotime($date_start_order);
- // 结束时间处理,需通过strototime()增加一天
- $timestamp_end_order = strtotime('+1 day', strtotime($date_end_order));
- $criteria->order_time('>=', $timestamp_start_order);
- $criteria->order_time('<=', $timestamp_end_order);
- }
- // 预约时间处理
- if (!empty($date_start_book) && !empty($date_end_book)) {
- // 开始时间处理
- $timestamp_start_book = strtotime($date_start_book);
- // 结束时间处理,需通过strototime()增加一天
- $timestamp_end_book = strtotime('+1 day', strtotime($date_end_book));
- $criteria->booking_time('>=', $timestamp_start_book);
- $criteria->booking_time('<=', $timestamp_end_book);
- }
- // 服务站处理
- // if ($station != 'all') {
- // $criteria->station = new MongoId($station);
- //}
- $cursor = ROrder::model()->findAll($criteria);
- $total = $cursor->count();
- $rows = CommonFn::getRowsFromCursor($cursor);
- $parsedRows = ROrder::model()->parse($rows);
- echo CommonFn::composeDatagridData($parsedRows, $total);
- }
- public function actionEdit(){
- $id = Yii::app()->request->getParam('id', '');
- $status = intval(Yii::app()->request->getParam('status',1));
- $booking_time = intval(Yii::app()->request->getParam('booking_time', time()));
- $deal_time = intval(Yii::app()->request->getParam('deal_time', time()));
- $remark = Yii::app()->request->getParam('remark', '');
- //$station = Yii::app()->request->getParam('station_id', '');
- $technician_id = intval(Yii::app()->request->getParam('technician', 0));
- $technician_name = Yii::app()->request->getParam('technician_name', '');
- // 保洁师信息检查
- // 根据ID直接查询保洁师信息(优先使用联想功能)
- if ($technician_id != 0) {
- $technician_obj = TechInfo::get($technician_id);
- if ($technician_obj) {
- $technicians_id = $technician_obj->_id;
- $technician_name = $technician_obj->name;
- } else {
- CommonFn::requestAjax(false, '保洁师不存在');
- }
- // ID为0时根据输入框信息查询
- } else if ($technician_name != '') {
- $criteria = new EMongoCriteria();
- $criteria->name = $technician_name;
- $technician_obj = TechInfo::model()->find($criteria);
- if ($technician_obj) {
- $technician_id = $technician_obj->_id;
- $technician_name = $technician_obj->name;
- } else {
- CommonFn::requestAjax(false, '保洁师不存在');
- }
- } else {
- $technician_obj = null;
- $technician_id = 0;
- $technician_name = '';
- }
- if($status == 100){
- CommonFn::requestAjax(false, '必须指定状态!');
- }
- $criteria = new EMongoCriteria();
- $criteria->_id = new MongoId($id);
- $order = ROrder::model()->find($criteria);
- // if($order->status == -1 || $order->status == -2){
- // CommonFn::requestAjax(false, '已取消,已退款订单不支持更改');
- // }
- // 获取用户信息,修改用户订单统计
- // zhouxuchen 2015-11-16
- $user_id = $order->user;
- if (!empty($user_id)) {
- $user = RUser::get($user_id);
- } else {
- $user = '';
- }
- if (empty($order)){
- CommonFn::requestAjax(false, '订单不存在');
- }
-
- if(($order->status!=-1||$order->status!=-2)&&($status==-1||$status==-2)){
- foreach ($order->coupons as $user_coupon) {
- $user_coupon = UserCoupon::get($user_coupon);
- $user_coupon->status = 1;
- $user_coupon->update(array('status'),true);
- }
- }
- if($order->status!=-2 && $status == -2){
- $order->refund_time = time();
- $order_info = $order->parseRow($order);
- $month = date('m',$order_info['booking_time']);
- $day = date('d',$order_info['booking_time']);
- $address = $order_info['address']['poi']['name'].$order_info['address']['detail'];
- CommonSMS::send('order_retrieve',array('month'=>$month,'day'=>$day,'address'=>$address,'mobile'=>$order_info['address']['mobile']));
- // 申请退款处理完成后通知保洁师
- if ($technician_obj && $technician_obj->weixin_userid) {
- $url_prefix = ENVIRONMENT == 'product' ? 'http://api.wozhua.mobi' : 'http://apitest.wozhua.mobi';
- $wechat = O2oApp::getWechatActive();
- $wechat_data = array(
- 'touser' => $technician_obj->weixin_userid,
- 'msgtype' => 'news',
- 'agentid' => '24',
- 'news' => array(
- 'articles' => array(
- array(
- 'title' => '壹管家提示-订单退款完成',
- 'description' => $technician_obj->name.'你好!用户于'.date('m月d日H:i', $order->apply_refund_time).'申请退款的订单已处理完成。',
- 'url' => $url_prefix.'/index.php?r=o2o/myOrder/info&order='.$id.'&user='.$technician_id,
- ),
- ),
- ),
- );
- if (!empty($order->append_orders)) {
- $count = count($order->append_orders);
- $wechat_data['news']['articles'][0]['description'] .= "\n\n本订单包含".$count."个追加订单,请注意查看。";
- }
- $wechat->sendMessage($wechat_data);
- }
- // if (!empty($order->append_orders)) {
- // $wechat_data = array(
- // 'touser' => $technician_obj->userid,
- // 'msgtype' => 'news',
- // 'agentid' => '24',
- // 'news' => array(
- // 'articles' => array(
- // array(
- // 'title' => '壹管家提示-追加订单退款完成',
- // 'description' => $technician_obj->name.'你好!用户于'.date('m月d日H:i', $order->apply_refund_time).'申请退款的追加订单已处理完成,请点击下方条目查看详情。',
- // ),
- // ),
- // ),
- // );
- // foreach ($order->append_orders as $key => $value) {
- // $wechat_data['news']['articles'][] = array(
- // 'description' => '追加订单' . ($key + 1),
- // 'url' => 'http://api.wozhua.mobi/index.php?r=o2o/myOrder/info&order='.$id.'&user='.$technician_id,
- // );
- // }
- // }
- }
- //修改点评订单预约时间
- if($order->channel == 'dianping' && $order->booking_time != $booking_time){
- $update_dianping = ROrder::updateOrderInfo($order->_id,array('serviceTime' => date('Y-m-d H:i:s',$booking_time)));
- if($update_dianping == false){
- CommonFn::requestAjax(false, '更新点评到家数据失败');
- }
- }
- //取消订单
- if($order->status!=-1 && $status == -1){
- // 已完成订单不能取消
- if ($order->status == 6) {
- CommonFn::requestAjax(false, '已完成订单不可取消');
- }
- $order->cancel_time = time();
- $order_info = $order->parseRow($order);
- if($order->channel == 'dianping'){
- $update_dianping = ROrder::cancelDianPingOrder($order->_id);
- if($update_dianping == false){
- CommonFn::requestAjax(false, '更新点评到家数据失败');
- }
- // 客服取消订单,用户有效订单数减少
- // zhouxuchen 2015-11-16
- if (!empty($user) && $user->order_count > 0 && $order->status > 0) {
- $user->order_count -= 1;
- $user->save();
- }
- }
- }
- //确认接单
- if($order->status!=3 && $status == 3){
- if($order->channel == 'dianping'){
- $update_dianping = ROrder::setDianPingStatus($order->_id,13);
- if($update_dianping == false){
- CommonFn::requestAjax(false, '更新点评到家数据失败');
- }
- }
- $order_info = $order->parseRow($order);
- }
- //订单完成后执行
- if($order->status!=6 && $status == 6 ){
- $order->finish_time = time();
- if($order->channel == 'dianping'){
- if($order->status == -1){
- CommonFn::requestAjax(false, '已取消大众点评订单,不可设置为已完成状态');
- }
- $update_dianping = ROrder::setDianPingStatus($order->_id,5);
- if($update_dianping == false){
- // CommonFn::requestAjax(false, '更新点评到家数据失败');
- }
- }
- $order_info = $order->parseRow($order);
- if($order->channel == 'dianping'){
- CommonSMS::send('dianping_final_order',array('mobile'=>$order_info['address']['mobile']));
- }else{
- $result = Service::factory('ScoreService')->changeScore((string)$order->user,intval($order->final_price),'下单奖爪币');
- if($result){
- $z_message = new ZMessage();
- $from_user = Yii::app()->params['sys_user'];
- $message_data = array(
- 'from_user' => $from_user,
- 'to_user' => (string)$order->user,
- 'content' => '您成功下单,获得了'.intval($order->final_price).'个爪币的奖励。',
- 'pics' => array(),
- 'voice' => array(),
- 'video'=> array()
- );
- $z_message->addMessage($message_data);
- CommonSMS::send('final_order',array('name' =>$order_info['address']['name'],'num' =>intval($order->final_price),'mobile'=>$order_info['address']['mobile']));
- }
- }
- // 保洁师订单统计处理
- if ($technician_obj) {
- $tech_order_count = $technician_obj->order_count + 1;
- $technician_obj->order_count = $tech_order_count;
- $technician_obj->save();
- }
- }
- // 葡萄订单状态处理
- if ($order->channel == 'putao' && $status != $order->status) {
- if (in_array($status, array(0, 1, 2, 7, -2))) {
- CommonFn::requestAjax(false, '该选项状态不适用于葡萄生活', array());
- }
- $update_putao = Putao::getInstance()->updateToPlatform($order->_id, $status);
- if ($update_putao['code'] == -1) {
- CommonFn::requestAjax(false, '更新葡萄生活数据失败/'.$update_putao['msg'], array());
- } else {
- $remark_info = $update_putao['msg'];
- $remark = $remark == '' ? $remark : $remark."\n";
- $remark .= $remark_info."\n".date('Y-m-d H:i:s', time());
- }
- }
- // 触宝订单状态处理
- // TODO
- if ($order->channel == 'chubao' && $status != $order->status) {
- $chubao_info = $order->third_platform_info;
- if (empty($user->name) || !isset($chubao_info['transactionId'])) {
- CommonFn::requestAjax(false, '触宝用户信息不全');
- } else {
- $userId = $user->name;
- }
- if (in_array($status, array(-1, 6))) {
- $chubao = new Chubao();
- $chubaoClient = $chubao->getClient();
- $chubaoConfig = Yii::app()->params['chubao'];
- // 服务信息
- $product_list = $order->products;
- $product_id = $product_list[0]['product'];
- $product = Product::get($product_id);
- $o2o_service = Yii::app()->params['o2o_service'];
- $shortInfo = $o2o_service[$product->type]['name'];
- // chubaoOrderPush实例化及基本设置
- $chubaoPush = $chubao->getOrderPush();
- $chubaoPush->setUserId($userId);
- $chubaoPush->setOrderId($id);
- $chubaoPush->setOrderService($chubaoConfig['service']);
- $chubaoPush->setOrderTitle('壹管家宠物');
- $chubaoPush->setOrderShortInfo('壹管家上门服务-'.$shortInfo);
- $chubaoPush->setOrderCreateTime(date('YmdHis', $order->order_time));
- $chubaoPush->setOrderFinishTime('');
- $chubaoPush->setOrderUrl($chubaoConfig['orderUrl'].'/'.$id);
- // 取消订单
- if ($status == -1) {
- // 已付款情况下申请退款
- if (in_array($order->status, array(1,2,3,4,5))) {
- $chubaoRefund = $chubao->getTradeRefund();
- $chubaoRefund->setUserId($userId);
- $chubaoRefund->setNotifyUrl($chubaoConfig['refundCallbackUrl']);
- $chubaoRefund->setTransactionId($chubao_info['transactionId']);
- $chubaoRefund->setRefundNo($id);
- $chubaoRefund->setTotalFee($order->final_price * 100);
- $chubaoRefund->setCashFee($order->final_price * 100);
- $chubaoRefund->setRefundFee($order->final_price * 100);
- $refundRes = $chubaoClient->execute($chubaoRefund);
- if ($refundRes['refundStatus'] == 'REFUND_FAIL') {
- CommonFn::requestAjax(false, '触宝订单退款失败');
- }
- }
- // 取消订单
- $chubaoPush->setOrderStatus('订单已被客服取消');
- $chubaoPush->setTradeStatus('TRADE_CLOSED');
- $pushRes = $chubaoClient->execute($chubaoPush);
- if ($pushRes['result'] == 'FAIL') {
- CommonFn::requestAjax(false, '触宝订单取消失败');
- }
- // 确认订单
- } else if ($status == 6) {
- $chubaoPush->setOrderStatus('订单已被客服确认完成');
- $chubaoPush->setTradeStatus('TRADE_FINISH');
- $pushRes = $chubaoClient->execute($chubaoPush);
- if ($pushRes['result'] == 'FAIL') {
- CommonFn::requestAjax(false, '触宝订单确认失败');
- }
- }
- }
- }
- $order->status = $status;
- $order->booking_time = $booking_time;
- $order->deal_time = $deal_time;
- $order->remark = $remark;
- //$order->station = new MongoId($station);
- // 是否通知保洁师
- $toTech = $order->technician != $technician_id ? true : false;
- $order->technician = $technician_id;
- $order->technician_name = $technician_name;
- $arr_order = array('cancel_time','refund_time','finish_time','status','booking_time','deal_time','remark', 'station', 'technician', 'technician_name');
- $success = $order->save(true,$arr_order);
- // 通知保洁师
- if (in_array($status, array(1,2,3,4,5)) && $toTech && $success) {
- // if ($toTech) {
- if ($technician_obj && $technician_obj->weixin_userid) {
- $url_prefix = ENVIRONMENT == 'product' ? 'http://api.wozhua.mobi' : 'http://apitest.wozhua.mobi';
- $wechat = O2oApp::getWechatActive();
- $wechat_data = array(
- 'touser' => $technician_obj->weixin_userid,
- 'msgtype' => 'news',
- 'agentid' => '24',
- 'news' => array(
- 'articles' => array(
- array(
- 'title' => '壹管家提示-新订单',
- 'description' => $technician_obj->name.'你好!刚刚有一个新的订单被分配给你,请点击查看。',
- 'url' => $url_prefix.'/index.php?r=o2o/myOrder/info&order='.$id.'&user='.$technician_id,
- ),
- ),
- ),
- );
- $wechat->sendMessage($wechat_data);
- }
- }
- CommonFn::requestAjax($success, '', array());
- }
- public function actionGetDianPingInfo(){
- $id = Yii::app()->request->getParam('id', '');
- $post_args = array(
- 'methodName' => 'loadOrderInfo',
- 'orderId' => $id
- );
- $sign = CommonFn::getDianPingSing($post_args);
- if($sign === false){
- return false;
- }
- $post_args['sign'] = $sign;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($ch, CURLOPT_URL, 'http://m.api.51ping.com/tohome/openapi/wozhua/');
- curl_setopt($ch, CURLOPT_POSTFIELDS,$post_args);
- $result = curl_exec($ch);
- if($result === false) {
- return false;
- }
- curl_close($ch);
- echo $result;
- die();
- }
- // 根据手机号 获取对应用户的地址信息
- public function actionGetUserInfo(){
- $mobile = Yii::app()->request->getParam('mobile', '');
- $length = strlen($mobile);
- if ($length < 11) {
- $result[] = array(
- 'id' => 0,
- 'data' => '',
- 'description' => '请继续输入',
- 'content' => array()
- );
- echo json_encode($result);exit;
- }
- // $mobile_regex = new MongoRegex($mobile);
- $criteria = new EMongoCriteria();
- $criteria->sort('order_time', EMongoCriteria::SORT_DESC);
- $criteria->addCond('address.mobile', '==', $mobile);
- $cursor = ROrder::model()->findAll($criteria);
- $rows = CommonFn::getRowsFromCursor($cursor);
- if (empty($rows)) {
- $result[] = array(
- 'id' => 0,
- 'data' => '',
- 'description' => '没有匹配信息',
- 'content' => array()
- );
- echo json_encode($result);exit;
- }
- $result = array();
- $details = array();
- $index = 0;
- foreach($rows as $row){
- // 加入根据detail筛选,避免产生重复信息
- if (in_array($row['address']['detail'], $details)) continue;
- $details[] = $row['address']['detail'];
- $pio = isset($row['address']['poi']['name'])?$row['address']['poi']['name']:'';
- // 坐标获取(根据不同的来源)
- if ($row['channel'] == 'dianping') {
- $latitude = $row['address']['position']['lat'];
- $longitude = $row['address']['position']['lng'];
- } else {
- $latitude = isset($row['address']['position']['1'])?$row['address']['position']['1']:'';
- $longitude = isset($row['address']['position']['0'])?$row['address']['position']['0']:'';
- }
- // poi获取
- $poi_name = isset($row['address']['poi']['name']) ? $row['address']['poi']['name'] : '';
- $poi_uid = isset($row['address']['poi']['uid']) ? $row['address']['poi']['uid'] : '';
- $result[] = array(
- 'id' => $index,
- 'data' => $row['address']['mobile'],
- 'description' => $row['address']['province'].' '.$row['address']['city'].' '.$row['address']['area'].' '.$pio.$row['address']['detail'],
- 'content' => array(
- 'name' => $row['address']['name'],
- 'latitude' => $latitude,
- 'longitude' => $longitude,
- 'province' => $row['address']['province'],
- 'city' => $row['address']['city'],
- 'area' => $row['address']['area'],
- 'detail' => $row['address']['detail'],
- 'poi_name' => $poi_name,
- 'poi_uid' => $poi_uid,
- 'memo' => $row['memo']
- )
- );
- $index++;
- }
- echo json_encode($result);exit;
- /*$map = new MongoCode('
- function(){
- emit(this.address.name,this.address);
- }
- ');
- $reduce = new MongoCode('
- function(key,values){
- var ret={age:key,names:values[0]};
- return ret;
- }
- ');
- $query = array('address.mobile' => array('=' => $mobile));
- $instance = Message::model()->getDb();
- $cmd = $instance->command(array(
- 'mapreduce' => 'orders',
- 'map' => $map,
- 'reduce' => $reduce,
- 'query' => $query,
- 'out' => array('merge' => 'admin_message')
- ));*/
- /**
- * note time : 2015-10-16
- * noted by : zhouxuchen
- */
- /*$mongo = new MongoClient(DB_CONNETC);
- $pipeline = array(
- array(
- '$match' => array(
- '_id' => array('address.mobile' => $mobile)
- ),
- '$group' => array(
- 'mobile' => array('state' => '$state' ),
- 'user' => array('$first' => '$pop' )
- )
- )
- );
- $out = $mongo->wozhua_o2o->orders->aggregate($pipeline);
- var_dump($out);exit;*/
- }
- public function actionAdd () {
- // ------ 必须传入的数值 ------
- // --------- 订单信息 ---------
- $channel = Yii::app()->request->getParam('channel', '');
- $booking_time = Yii::app()->request->getParam('booking_time_add', '');
- $order_time = Yii::app()->request->getParam('order_time_add', '');
- $price = Yii::app()->request->getParam('price', 0);
- $final_price = Yii::app()->request->getParam('final_price', 0);
- $status = Yii::app()->request->getParam('status', -3);
- $station = Yii::app()->request->getParam('station', '5548b05e0eb9fbc5728b51ea');
- // --------- 地址信息 ---------
- $mobile = Yii::app()->request->getParam('mobile', 0);
- $latitude = Yii::app()->request->getParam('latitude', 0);
- $longitude = Yii::app()->request->getParam('longitude', 0);
- $province = Yii::app()->request->getParam('province', '');
- $city = Yii::app()->request->getParam('city', '');
- $area = Yii::app()->request->getParam('area', '');
- $poi_name = Yii::app()->request->getParam('poi_name', '');
- $detail = Yii::app()->request->getParam('detail', '');
- // 数据完整性检查
- // 2015-11-02 因存在赠送订单,删除金额的数据检查 : $price == 0 || $final_price == 0 ||
- // 2015-11-16 取消服务点录入,删除服务点数据检查 : || empty($station)
- $flag = empty($channel) || empty($booking_time) || empty($order_time);
- $flag = $flag || $status == -3;
- $flag = $flag || $mobile == 0 || $latitude == 0 || $longitude == 0;
- $flag = $flag || empty($province) || empty($city) || empty($area) || empty($poi_name) || empty($detail);
- if ($flag) {
- CommonFn::requestAjax(false, '请检查数据完整性', array());
- exit;
- }
- //if($channel == 'wz_app' || $channel == 'wx_pub'){
- //CommonFn::requestAjax(false, '不能录入渠道为壹管家微信||壹管家APP的订单', array());
- //exit;
- //}
- // 时间处理
- $booking_time = strtotime($booking_time);
- $order_time = strtotime($order_time);
- // ------ 可以留空的数值 ------
- $box = Yii::app()->request->getParam('box', array());
- $coupons = Yii::app()->request->getParam('coupons', array());
- $memo = Yii::app()->request->getParam('memo', '');
- $remark = Yii::app()->request->getParam('remark', '');
- $precedence = Yii::app()->request->getParam('precedence', 0);
- $have_comment = Yii::app()->request->getParam('have_comment', 0);
- $name = Yii::app()->request->getParam('name', '');
- $type = Yii::app()->request->getParam('type', 0);
- $user = Yii::app()->request->getParam('user', '');
- $poi_uid = Yii::app()->request->getParam('poi_uid', '');
- // 用户名的判断
- $channel_option = ROrder::$channel_option;
- $name = empty($name) ? $channel_option[$channel]['name'].'用户' : $name;
- // 支付渠道
- $pay_channel = $channel;
- // 地址数据整合
- $address = array(
- 'province' => $province,
- 'city' => $city,
- 'area' => $area,
- 'detail' => $detail,
- 'mobile' => $mobile,
- 'position' => array(
- // 'lat' => (float)$latitude,
- // 'lng' => (float)$longitude,
- 0 => (float)$longitude,
- 1 => (float)$latitude
- ),
- 'poi' => array(
- 'name' => $poi_name,
- 'uid' => $poi_uid
- ),
- 'name' => $name
- );
- // 订单类型判断
- if ($type == 0) {
- $criteria = new EMongoCriteria();
- $criteria->_id = new MongoId($main_products);
- $cursor = Product::model()->find($criteria);
- $type = $cursor->type;
- }
- $rOrder = new ROrder();
- $rOrder->channel = $channel;
- $rOrder->booking_time = intval($booking_time);
- $rOrder->order_time = intval($order_time);
- $rOrder->price = intval($price);
- $rOrder->final_price = intval($final_price);
- $rOrder->precedence = intval($precedence);
- $rOrder->coupons = $coupons;
- $rOrder->user = $user;
- $rOrder->status = intval($status);
- $rOrder->memo = $memo;
- $rOrder->remark = $remark;
- $rOrder->type = strval($type); // 数据库内使用string类型
- $rOrder->have_comment = intval($have_comment);
- $rOrder->station = new MongoId($station);
- $rOrder->address = $address;
- $rOrder->pay_channel = $pay_channel;
- $addROrder_arr = array('channel', 'booking_time', 'order_time', 'price', 'final_price', 'precedence', 'coupons', 'user', 'status', 'memo', 'remark', 'type', 'have_comment', 'station', 'address', 'pay_channel');
- $success = $rOrder->save(true, $addROrder_arr);
- CommonFn::requestAjax($success, '', array());
- }
- /**
- * 请求申请退款订单接口
- */
- public function actionCheckRefundOrder() {
- $criteria = new EMongoCriteria();
- $criteria->status('==', -3);
- $cursor = ROrder::model()->findAll($criteria);
- $count = $cursor->count();
- if ($count > 0) {
- $data = array('code' => 1, 'count' => $count);
- } else {
- $data = array('code' => 0, 'count' => $count);
- }
- $list = new ARedisList('append_order_list');
- if($list->getCount() > 0){
- $key = $list->shift();
- $list->unshift($key);
- $data['procession_append_order_id'] = $key;
- $data['code'] = 2;
- }
-
- echo json_encode($data);
- }
- public function actionCancelProcess() {
- $orderid = Yii::app()->request->getParam('orderid','');
- $list = new ARedisList('append_order_list');
- $key = $list->shift();
- }
- /**
- * 重新选择保洁师接口
- */
- public function actionResetTech() {
- $id = Yii::app()->request->getParam('id', '');
- $technician_id = intval(Yii::app()->request->getParam('reset_technician', 0));
- $technician_name = Yii::app()->request->getParam('reset_technician_name', '');
-
- // 保洁师信息检查
- // 根据ID直接查询保洁师信息(优先使用联想功能)
- if ($technician_id != 0) {
- $technician_obj = TechInfo::get($technician_id);
- if ($technician_obj) {
- $technician_id = $technician_obj->_id;
- $technician_name = $technician_obj->name;
- } else {
- CommonFn::requestAjax(false, '保洁师不存在');
- }
- // ID为0时根据输入框信息查询
- } else if ($technician_name != '') {
- $criteria = new EMongoCriteria();
- $criteria->name = $technician_name;
- $technician_obj = TechInfo::model()->find($criteria);
- if ($technician_obj) {
- $technician_id = $technician_obj->_id;
- $technician_name = $technician_obj->name;
- } else {
- CommonFn::requestAjax(false, '保洁师不存在');
- }
- } else {
- CommonFn::requestAjax(false, '保洁师姓名不能为空');
- }
- $orderid = new MongoId($id);
- $order = ROrder::model()->get($orderid);
- $toTech = $order->technician != $technician_id ? true : false;
- $fromTech = $order->technician;
- $order->technician = $technician_id;
- $order->technician_name = $technician_name;
- $success = $order->save(true, array('technician', 'technician_name'));
- if ($toTech && $success) {
- // 发送给被分配保洁师
- $wechat = O2oApp::getWechatActive();
- $url_prefix = ENVIRONMENT == 'product' ? 'http://api.wozhua.mobi' : 'http://apitest.wozhua.mobi';
- if (!empty($technician_obj->weixin_userid)) {
- $wechat_data = array(
- 'touser' => $technician_obj->weixin_userid,
- 'msgtype' => 'news',
- 'agentid' => '24',
- 'news' => array(
- 'articles' => array(
- array(
- 'title' => '壹管家提示-新订单',
- 'description' => $technician_obj->name.'你好!刚刚有一个新的订单被分配给你,请点击查看。',
- 'url' => $url_prefix.'/index.php?r=o2o/myOrder/info&order='.$id.'&user='.$technician_id,
- ),
- ),
- ),
- );
- $wechat->sendMessage($wechat_data);
- }
- // 发送给原保洁师
- $fromTechObj = TechInfo::get($fromTech);
- if (!empty($fromTechObj) && !empty($fromTechObj->weixin_userid)) {
- $wechat_data = array(
- 'touser' => $fromTechObj->weixin_userid,
- 'msgtype' => 'news',
- 'agentid' => '24',
- 'news' => array(
- 'articles' => array(
- array(
- 'title' => '壹管家提示-订单已被重新分配',
- 'description' => $fromTechObj->name.'你好!预定时间在'.date('m月d日H:i', $order->booking_time).'的订单已被分配给其他保洁师。',
- 'url' => $url_prefix.'/index.php?r=o2o/myOrder/info&order='.$id.'&user='.$technician_id,
- ),
- ),
- ),
- );
- $wechat->sendMessage($wechat_data);
- }
- }
- CommonFn::requestAjax($success, '', array());
- }
- }
|