123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077 |
- <?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_main = new EMongoCriteria();
- $criteria_main->status('==', 1);
- $cursor_main = Product::model()->findAll($criteria_main);
- $rows_main = CommonFn::getRowsFromCursor($cursor_main);
- $main_row = array();
- foreach($rows_main as $row){
- $ids = (string)$row['_id'];
- $main_row[$ids] = array('name' =>$row['name']);
- }
- $main_products = CommonFn::getComboboxData($main_row, 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,
- 'main_products'=> $main_products,
- '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));
- $counts = intval(Yii::app()->request->getParam('count',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_ids = array();
- $technician_names = array();
- $technicians = array();
- $nums = Yii::app()->request->getParam('tech_nums');
- for($i=0;$i<=$nums;$i++) {
- if(Yii::app()->request->getParam('extra_add_info_'.$i)) {
- $technician_ids[] = Yii::app()->request->getParam('extra_add_info_id_'.$i);
- $technician_names[] = Yii::app()->request->getParam('extra_add_info_'.$i);
- }
- }
- if(!$counts){
- CommonFn::requestAjax(false, '购买数量错误');
- }
- // 保洁师信息检查
- // 根据ID直接查询保洁师信息(优先使用联想功能)
- if (isset($technician_ids)) {
- foreach($technician_ids as $key => $technician_id){
- $technician_obj = TechInfo::get($technician_id);
- if ($technician_obj) {
- $technicians[$key]['technician_id'] = $technician_obj->_id;
- $technicians[$key]['technician_name'] = $technician_obj->name;
- } else {
- CommonFn::requestAjax(false, '保洁师不存在');
- break;
- }
- }
- // ID为0时根据输入框信息查询
- } else if (isset($technician_names)) {
- $criteria = new EMongoCriteria();
- foreach($technician_names as $key => $technician_name) {
- $criteria->name = $technician_name;
- $technician_obj = TechInfo::model()->find($criteria);
- if ($technician_obj) {
- $technicians[$key]['technician_id'] = $technician_obj->_id;
- $technicians[$key]['technician_name'] = $technician_obj->name;
- } else {
- CommonFn::requestAjax(false, '保洁师不存在');
- break;
- }
- }
- } else {
- $technician_obj = null;
- //$technician_id = 0;
- // $technician_name = '';
- foreach($technicians as $key => $value) {
- $technicians[$key]['$technician_id'] = 0;
- $technicians[$key]['$technician_name'] = 0;
- }
- }
- //var_dump($technicians);exit;
- 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, '已取消,已退款订单不支持更改');
- // }
- // 获取用户信息,修改用户订单统计
- // 2015-11-16
- $user_id = $order->user;
- if (!empty($user_id)) {
- $user = RUser::get($user_id);
- } else {
- $user = '';
- }
- if (empty($order)){
- CommonFn::requestAjax(false, '订单不存在');
- }
- $flag = 0;
- //精佰退单接口 状态为申请退款并且是精佰的订单
- if ($order->status == -3 && $order->channel == 'jingbai') {
- //确认申请退款状态变更成已退款订单 为退单订单
- $res = '';
- $criteria = new EMongoCriteria();
- $criteria->OrderNo('==',$order->OrderNo);
- $criteria->status('==',-3);
- $orders = ROrder::model()->findAll($criteria);
- $orderId = '';
- $fin_price = 0.0;
- foreach ($orders as $value) {
- $orderId .= (string)$value->_id.',';
- $fin_price =$fin_price+ $value->final_price*0.5;
- }
- $fin_price = round($fin_price,2)*100;
- $orderId = rtrim(trim($orderId),',');
- if ($status == -2) {
- if ($remark == '1') {//退单 全额
- //已出发 已上门 订单
- $res = self::feedbackOrder(1, $order->OrderNo, $orderId, $fin_price);
- } else {//退单 不退钱
- $res = self::feedbackOrder(1, $order->OrderNo, $orderId, 0);
- }
- $flag = 1;
- } else if($status == 2 ){//不退单
- $res = self::feedbackOrder(0,$order->OrderNo,$orderId,0);
- $flag = 1;
- }
- if( $order->booking_time != $booking_time){
- self::feedbackOrderRemaker(0,$order->OrderNo,$orderId,0,$order->booking_time);
- }
- if ($flag && $res){
- foreach ($orders as $value) {
- $value->status = $status;
- $value->save();
- }
- }
- }
- 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']));
- // 申请退款处理完成后通知保洁师
- foreach ($technician_ids as $key => $technician_id) {
- $technician_obj = TechInfo::get($technician_id);
- if ($technician_obj && $technician_obj->weixin_userid) {
- $url_prefix = ENVIRONMENT == 'product' ? 'http://api.yiguanjia.me' : 'http://apitest.yiguanjia.me';
- $wechat = O2oApp::getWechatActive();
- $wechat_data = array(
- 'touser' => $technician_obj->weixin_userid,
- 'msgtype' => 'news',
- 'agentid' => '1',
- '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,
- 'url' => $url_prefix . '/index.php?r=o2o/myOrder/index'
- ),
- ),
- ),
- );
- if (!empty($order->append_orders)) {
- $count = count($order->append_orders);
- $wechat_data['news']['articles'][0]['description'] .= "\n\n本订单包含" . $count . "个追加订单,请注意查看。";
- }
- $wechat->sendMessage($wechat_data);
- }
- }
-
- }
- //取消订单
- if($order->status!=-1 && $status == -1){
- // 已完成订单不能取消
- if ($order->status == 6) {
- CommonFn::requestAjax(false, '已完成订单不可取消');
- }
- $order->cancel_time = time();
- $order_info = $order->parseRow($order);
- }
- //确认接单
- if($order->status!=3 && $status == 3){
- $order_info = $order->parseRow($order);
- }
- //订单完成后执行
- if($order->status!=6 && $status == 6 ){
- $order->finish_time = time();
- $order_info = $order->parseRow($order);
- /*$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']));
- }*/
- // 保洁师订单统计处理
- foreach($technician_ids as $key => $technician_id) {
- $technician_obj = TechInfo::get($technician_id);
- if ($technician_obj) {
- $tech_order_count = $technician_obj->order_count + 1;
- $technician_obj->order_count = $tech_order_count;
- $technician_obj->save();
- }
- }
- }
- $order->status = $status;
- $order->booking_time = $booking_time;
- $order->deal_time = $deal_time;
- $order->remark = $remark;
- $order->counts = $counts;
- //$order->station = new MongoId($station);
- // 是否通知保洁师
- $toTech = !empty($order->technicians)? true : false;
- //$order->technician = $technician_id;
- //$order->technician_name = $technician_name;
- $order->technicians = $technicians;
- //var_dump($order);exit;
- //判断是否为实惠或金百订单
- if($order->channel == 'shihui'){
- if ($status == 1) {//已支付
- $res = self::UpdateStatus((string)$order->_id, 5);
- $flag = 1;
- } else if($status ==3){//已接单
- $res = self::UpdateStatus((string)$order->_id, 15);
- $flag = 1;
- }else if($status ==6){//服务完成
- $res = self::UpdateStatus((string)$order->_id, 20);
- $flag = 1;
- }else if($status ==-1){//取消订单
- $res = self::DelOrder((string)$order->_id);
- $flag = 1;
- }
- }else if($order->channel == 'jingbai'){
- if($status ==3){//已接单
- $res = self::UpdateStatusForJingBai($order->OrderNo,(string)$order->_id, $status,$order->remark);
- $flag = 1;
- }else if($status ==6){//服务完成
- $res = self::UpdateStatusForJingBai($order->OrderNo,(string)$order->_id, $status,$order->remark);
- $flag = 1;
- }
- }
- if($flag){
- if (!$res) {
- CommonFn::requestAjax(false,'修改失败res='.$res.',flag='.$flag);
- }
- }
- $arr_order = array('cancel_time','refund_time','finish_time','status','booking_time','deal_time','remark', 'station', 'technicians');
- $success = $order->save(true,$arr_order);
- $char = false;
- // 通知保洁师
- if (in_array($status, array(1,2,3,4,5)) && $toTech && $success) {
- foreach($technician_ids as $key => $technician_id) {
- $technician_obj = TechInfo::get($technician_id);
- if ($technician_obj && $technician_obj->weixin_userid) {
- $url_prefix = ENVIRONMENT == 'product' ? 'http://api.yiguanjia.me' : 'http://apitest.yiguanjia.me';
- $wechat = O2oApp::getWechatActive();
- $wechat_data = array(
- 'touser' => $technician_obj->weixin_userid,
- 'msgtype' => 'news',
- 'agentid' => 1,
- 'news' => array(
- 'articles' => array(
- array(
- 'title' => '壹管家提示-新订单',
- 'description' => $technician_obj->name . '你好!刚刚有一个新的订单被分配给你,请点击查看。',
- //'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_id,
- 'url' => $url_prefix . '/index.php?r=o2o/myOrder/index'
- ),
- ),
- ),
- );
- $char = $wechat->sendMessage($wechat_data);
- }
- }
- }
- CommonFn::requestAjax($success, '微信'.$char, array());
- }
- // 根据手机号 获取对应用户的地址信息
- 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;
- }
- 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', '');
- $main_products = Yii::app()->request->getParam('main_products', '');
- $price = floatval(Yii::app()->request->getParam('price', 0));
- $final_price = floatval(Yii::app()->request->getParam('final_price', 0));
- $status = Yii::app()->request->getParam('status', -3);
- $station = Yii::app()->request->getParam('station', '57db39709f5160bb048b456a');
- // --------- 地址信息 ---------
- $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', '');
- $counts = intval(Yii::app()->request->getParam('counts', 1));
- $counts = $counts?$counts:1;
- $extra = Yii::app()->request->getParam('extra','[]');
- $extra = json_decode($extra);
- // 数据完整性检查
- // 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;
- // 服务数据整合
- $products[] = array(
- 'product' => new MongoId($main_products),
- 'count' => 1,
- 'extra' =>$extra
- );
- if (!empty($box)) {
- foreach ($box as $key => $value) {
- $products[] = array(
- 'product' => new MongoId($value),
- 'count' => 1,
- 'extra' =>$extra
- );
- }
- }
- // 地址数据整合
- $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->products = $products;
- $rOrder->price = floatval($price);
- $rOrder->final_price = floatval($final_price);
- $rOrder->precedence = intval($precedence);
- $rOrder->counts = $counts;
- $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','products', 'final_price', 'counts','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', '');
- $nums = Yii::app()->request->getParam('nums', '');
- $technicians = array();
- $technician_ids = array();
- $technician_names = array();
- for($i=1;$i<=$nums;$i++) {
- if(Yii::app()->request->getParam('reset_extra_add_info_'.$i)) {
- $technician_ids[] = Yii::app()->request->getParam('reset_extra_add_info_id_'.$i);
- $technician_names[] = Yii::app()->request->getParam('reset_extra_add_info_'.$i);
- }
- }
- // 保洁师信息检查
- // 根据ID直接查询保洁师信息(优先使用联想功能)
- $technician_objs = array();
- foreach($technician_ids as $key => $technician_id) {
- if ($technician_id != 0) {
- $technician_obj = TechInfo::get($technician_id);
- if ($technician_obj) {
- $technicians[$key]['technician_id'] = $technician_obj->_id;
- $technicians[$key]['technician_name'] = $technician_obj->name;
- } else {
- CommonFn::requestAjax(false, '保洁师不存在');
- }
- // ID为0时根据输入框信息查询
- } else {
- foreach ($technician_names as $key => $technician_name)
- if ($technician_name != '') {
- $criteria = new EMongoCriteria();
- $criteria->name = $technician_name;
- $technician_obj = TechInfo::model()->find($criteria);
- if ($technician_obj) {
- $technicians[$key]['technician_id'] = $technician_obj->_id;
- $technicians[$key]['technician_name'] = $technician_obj->name;
- } else {
- CommonFn::requestAjax(false, '保洁师不存在');
- }
- } else {
- CommonFn::requestAjax(false, '保洁师姓名不能为空');
- }
- }
- $technician_objs[] = $technician_obj;
- }
- $orderid = new MongoId($id);
- $order = ROrder::model()->get($orderid);
- $toTech = isset($order->technicians) ? true : false;
- $fromTechs = $technician_names;
- //$order->technician = $technician_id;
- //$order->technician_name = $technician_name;
- $order->technicians = $technicians;
- $success = $order->save(true, array('technicians'));
- if ($toTech && $success) {
- foreach ($technician_objs as $technician_obj) {
- // 发送给被分配保洁师
- $wechat = O2oApp::getWechatActive();
- $url_prefix = ENVIRONMENT == 'product' ? 'http://api.yiguanjia.me' : 'http://apitest.yiguanjia.me';
- if (!empty($technician_obj->weixin_userid)) {
- $wechat_data = array(
- 'touser' => $technician_obj->weixin_userid,
- 'msgtype' => 'news',
- 'agentid' => '1',
- 'news' => array(
- 'articles' => array(
- array(
- 'title' => '壹管家提示-新订单',
- 'description' => $technician_obj->name . '你好!刚刚有一个新的订单被分配给你,请点击查看。',
- //'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_obj->_id,
- 'url' => $url_prefix . '/index.php?r=o2o/myOrder/index'
- ),
- ),
- ),
- );
- $wechat->sendMessage($wechat_data);
- }
- }
- // 发送给原保洁师
- foreach ($fromTechs as $fromTech) {
- $fromTechObj = TechInfo::get($fromTech);
- if (!empty($fromTechObj) && !empty($fromTechObj->weixin_userid)) {
- $wechat_data = array(
- 'touser' => $fromTechObj->weixin_userid,
- 'msgtype' => 'news',
- 'agentid' => '1',
- '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_obj->_id,
- ),
- ),
- ),
- );
- $wechat->sendMessage($wechat_data);
- }
- }
- }
- CommonFn::requestAjax($success, '', array());
- }
- /*public function actionDelOrder(){
- $delOrder = array('5826a4c89f5160d1048b52bf');
- $total = 0;
- foreach($delOrder as $value){
- $order = ROrder::model()->get(new MongoId($value));
- if($order->delete()){
- $total += 1;
- }
- }
- echo $total;
- }*/
- //取消订单
- public function DelOrder($orderId){
- $data['key'] = Yii::app()->params['shKey'];
- $data['version'] = '1.0';
- $data['serviceType'] = (int)26;
- $data['orderId'] = $orderId;//'57fde8059f5160c4048b4aeb';
- ksort($data);
- $str = '';
- $dat = '';
- foreach ($data as $key => $value) {
- $str .= $key.'='.$value.'&';
- $dat .= $key.'='.urlencode($value).'&';
- }
- $str = rtrim(trim($str),'&');
- $str .= $str.Yii::app()->params['shMd5Key'];
- $data['sign'] = strtoupper(md5($str));
- $dat .= 'sign='.urlencode($data['sign']);//构建post 参数
- $url = 'http://test2.app.hiwemeet.com/v2/openpf/home/order/thirdOrder/cancel'; //调用接口的平台服务地址
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
- curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
- $result = curl_exec($ch);
- curl_close($ch);
- $res = json_decode($result,true);
- var_dump($res);
- if ($res['code']){
- return true;
- } else {
- return false;
- }
- }
- //更新订单状态
- public function UpdateStatus($orderId,$status){
- $data['key'] = Yii::app()->params['shKey'];
- $data['version'] = '1.0';
- $data['serviceType'] = (int)26;
- $data['orderId'] = (string)$orderId;
- $data['status'] = $status;
- ksort($data);
- $str = '';
- $dat = '';
- foreach ($data as $key => $value) {
- $str .= $key.'='.$value.'&';
- $dat .= $key.'='.urlencode($value).'&';
- }
- $str = rtrim(trim($str),'&');
- $str .= $str.Yii::app()->params['shMd5Key'];
- $data['sign'] = strtoupper(md5($str));
- $dat .= 'sign='.urlencode($data['sign']);//构建post 参数
- $url = 'http://test2.app.hiwemeet.com/v2/openpf/home/order/thirdOrder/update'; //调用接口的平台服务地址
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
- curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
- $result = curl_exec($ch);
- curl_close($ch);
- $res = json_decode($result,true);
- if ($res['code']){
- return true;
- } else {
- return false;
- }
- }
- //更新订单状态
- /**
- * @param $orderId => order->orderNo
- * @param $status "00" 为创建订单,"01"为服务派单,"02"为服务完成
- * @param $HouseKeepingId 巾帼园自己的订单号 对应order->_id
- * @param $remark 订单备注
- * Sign 计算方法:OrderId+ StatusCode+ Remark+ HouseKeepingId+ Time+KEY 然后计算md5 值 KEY为巾帼园的key值
- * @return bool
- */
- public function UpdateStatusForJingBai($orderId,$HouseKeepingId,$status,$remark){
- $key = Yii::app()->params['JingBai'];
- $data['OrderId'] = $orderId;
- $data['HouseKeepingId'] = $HouseKeepingId;
- $data['Remark'] = $remark;
- if ($status == 3){//已接单
- $data['StatusCode'] = '01';
- } else if($status == 6){//已完成
- $data['StatusCode'] = '02';
- }
- $data['Time'] = date('Y-m-d H:i:s');
- $data['Sign'] = md5($data['OrderId'].$data['StatusCode'].$data['Remark'].$data['HouseKeepingId'].$data['Time'].$key);
- $dat = '';
- foreach ($data as $key => $value) {
- $dat .= $key.'='.urlencode($value).'&';
- }
- $dat = rtrim(trim($dat),'&');
- if (ENVIRONMENT == 'product'){
- $url = 'http://139.196.47.211:9230/ServiceController/SetHouseKeepingStatus'; //正式服调用接口的平台服务地址
- } else {
- $url = 'http://139.196.47.211:9030/ServiceController/SetHouseKeepingStatus'; //调用接口的平台服务地址
- }
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
- curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
- $result = curl_exec($ch);
- curl_close($ch);
- $res = json_decode($result,true);
- if ($res['ReturnCode'] == '00'){
- return true;
- } else {
- return false;
- }
- }
- //不退单, 但是需要修改信息
- public function feedbackOrderRemaker($isCancel,$orderId,$orderNo,$money=0,$remark=null){
- $key = Yii::app()->params['JingBai'];
- $data['IsCancel'] = $isCancel;
- $data['OrderId'] = $orderId;
- $data['OrderNo'] = $orderNo;
- $data['Type'] = 'OrderRemark';
- $data['Remark'] = '修改预约时间'.date('Y-m-d H:i:s',$remark);
- $data['Sign'] = md5($orderId.$orderNo.$data['Remark'].$key);
- $dat = '';
- foreach ($data as $key => $value) {
- $dat .= $key.'='.urlencode($value).'&';
- }
- $dat = rtrim(trim($dat),'&');
- if (ENVIRONMENT == 'product'){
- $url = 'http://139.196.47.211:9230/ServiceController/HouseKeepingFeedback'; //正式服调用接口的平台服务地址
- } else {
- //$url = 'http://123.206.28.63:9030/ServiceController/HouseKeepingFeedback'; //测试服调用接口的平台服务地址
- $url = 'http://139.196.47.211:9030/ServiceController/HouseKeepingFeedback'; //调用接口的平台服务地址
- }
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
- curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
- $result = curl_exec($ch);
- curl_close($ch);
- $res = json_decode($result,true);
- if ($res['ReturnCode'] == '00'){
- return true;
- } else {
- return false;
- }
- }
- //退单反馈信息接口
- /**
- * @param $isCanel 是否退单 1退单 0 不退单
- * @param $orderId 精佰订单Id 对应 巾帼园 OrderNo
- * @param $orderNo 巾帼园订单id 对应 巾帼园_id
- * @param $money 若退单巾帼园需要收多少钱,单位为分,不退单可不传
- * @param null $remark 退单状态备注包含修改信息,无修改此字段可不传
- * @return bool
- */
- public function feedbackOrder($isCancel,$orderId,$orderNo,$money=0)
- {
- $key = Yii::app()->params['JingBai'];
- $data['IsCancel'] = $isCancel;
- $data['OrderId'] = $orderId;
- $data['OrderNo'] = $orderNo;
- if(!$isCancel){//不退单
- $data['Type'] = 'CancleOrder';
- $data['Money'] = $money;
- $data['Sign'] = md5($isCancel.$orderId.$orderNo.$money.$key);
- }
- else {
- $data['Type'] = 'CancleOrder';
- $data['Money'] = $money;
- $data['Sign'] = md5($isCancel.$orderId.$orderNo.$money.$key);
- }
- $dat = '';
- foreach ($data as $key => $value) {
- $dat .= $key.'='.urlencode($value).'&';
- }
- $dat = rtrim(trim($dat),'&');
- if (ENVIRONMENT == 'product'){
- $url = 'http://139.196.47.211:9230/ServiceController/HouseKeepingFeedback'; //正式服调用接口的平台服务地址
- } else {
- //$url = 'http://123.206.28.63:9030/ServiceController/HouseKeepingFeedback'; //测试服调用接口的平台服务地址
- $url = 'http://139.196.47.211:9030/ServiceController/HouseKeepingFeedback'; //调用接口的平台服务地址
- }
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
- curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
- $result = curl_exec($ch);
- curl_close($ch);
- $res = json_decode($result,true);
- if ($res['ReturnCode'] == '00'){
- return true;
- } else {
- return false;
- }
- }
- public function actionOutputExcel(){
- $data = ROrder::model()->findAll(); //
- $rows = CommonFn::getRowsFromCursor($data);
- $data = ROrder::model()->parse($rows);
- $name='OrderList'; //生成的Excel文件文件名
- $res=Service::factory('ExcelToArrayService')->push($data,$name);
- echo "导出成功";
- }
- }
|