ROrderController.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  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. $count = 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_id = intval(Yii::app()->request->getParam('technician', 0));
  122. $technician_name = Yii::app()->request->getParam('technician_name', '');
  123. if(!$count){
  124. CommonFn::requestAjax(false, '购买数量错误');
  125. }
  126. // 保洁师信息检查
  127. // 根据ID直接查询保洁师信息(优先使用联想功能)
  128. if ($technician_id != 0) {
  129. $technician_obj = TechInfo::get($technician_id);
  130. if ($technician_obj) {
  131. $technicians_id = $technician_obj->_id;
  132. $technician_name = $technician_obj->name;
  133. } else {
  134. CommonFn::requestAjax(false, '保洁师不存在');
  135. }
  136. // ID为0时根据输入框信息查询
  137. } else if ($technician_name != '') {
  138. $criteria = new EMongoCriteria();
  139. $criteria->name = $technician_name;
  140. $technician_obj = TechInfo::model()->find($criteria);
  141. if ($technician_obj) {
  142. $technician_id = $technician_obj->_id;
  143. $technician_name = $technician_obj->name;
  144. } else {
  145. CommonFn::requestAjax(false, '保洁师不存在');
  146. }
  147. } else {
  148. $technician_obj = null;
  149. $technician_id = 0;
  150. $technician_name = '';
  151. }
  152. if($status == 100){
  153. CommonFn::requestAjax(false, '必须指定状态!');
  154. }
  155. $criteria = new EMongoCriteria();
  156. $criteria->_id = new MongoId($id);
  157. $order = ROrder::model()->find($criteria);
  158. // if($order->status == -1 || $order->status == -2){
  159. // CommonFn::requestAjax(false, '已取消,已退款订单不支持更改');
  160. // }
  161. // 获取用户信息,修改用户订单统计
  162. // zhouxuchen 2015-11-16
  163. $user_id = $order->user;
  164. if (!empty($user_id)) {
  165. $user = RUser::get($user_id);
  166. } else {
  167. $user = '';
  168. }
  169. if (empty($order)){
  170. CommonFn::requestAjax(false, '订单不存在');
  171. }
  172. if(($order->status!=-1||$order->status!=-2)&&($status==-1||$status==-2)){
  173. foreach ($order->coupons as $user_coupon) {
  174. $user_coupon = UserCoupon::get($user_coupon);
  175. $user_coupon->status = 1;
  176. $user_coupon->update(array('status'),true);
  177. }
  178. }
  179. if($order->status!=-2 && $status == -2){
  180. $order->refund_time = time();
  181. $order_info = $order->parseRow($order);
  182. $month = date('m',$order_info['booking_time']);
  183. $day = date('d',$order_info['booking_time']);
  184. $address = $order_info['address']['poi']['name'].$order_info['address']['detail'];
  185. CommonSMS::send('order_retrieve',array('month'=>$month,'day'=>$day,'address'=>$address,'mobile'=>$order_info['address']['mobile']));
  186. // 申请退款处理完成后通知保洁师
  187. if ($technician_obj && $technician_obj->weixin_userid) {
  188. $url_prefix = ENVIRONMENT == 'product' ? 'http://api.wozhua.mobi' : 'http://apitest.wozhua.mobi';
  189. $wechat = O2oApp::getWechatActive();
  190. $wechat_data = array(
  191. 'touser' => $technician_obj->weixin_userid,
  192. 'msgtype' => 'news',
  193. 'agentid' => '24',
  194. 'news' => array(
  195. 'articles' => array(
  196. array(
  197. 'title' => '壹管家提示-订单退款完成',
  198. 'description' => $technician_obj->name.'你好!用户于'.date('m月d日H:i', $order->apply_refund_time).'申请退款的订单已处理完成。',
  199. 'url' => $url_prefix.'/index.php?r=o2o/myOrder/info&order='.$id.'&user='.$technician_id,
  200. ),
  201. ),
  202. ),
  203. );
  204. if (!empty($order->append_orders)) {
  205. $count = count($order->append_orders);
  206. $wechat_data['news']['articles'][0]['description'] .= "\n\n本订单包含".$count."个追加订单,请注意查看。";
  207. }
  208. $wechat->sendMessage($wechat_data);
  209. }
  210. // if (!empty($order->append_orders)) {
  211. // $wechat_data = array(
  212. // 'touser' => $technician_obj->userid,
  213. // 'msgtype' => 'news',
  214. // 'agentid' => '24',
  215. // 'news' => array(
  216. // 'articles' => array(
  217. // array(
  218. // 'title' => '壹管家提示-追加订单退款完成',
  219. // 'description' => $technician_obj->name.'你好!用户于'.date('m月d日H:i', $order->apply_refund_time).'申请退款的追加订单已处理完成,请点击下方条目查看详情。',
  220. // ),
  221. // ),
  222. // ),
  223. // );
  224. // foreach ($order->append_orders as $key => $value) {
  225. // $wechat_data['news']['articles'][] = array(
  226. // 'description' => '追加订单' . ($key + 1),
  227. // 'url' => 'http://api.wozhua.mobi/index.php?r=o2o/myOrder/info&order='.$id.'&user='.$technician_id,
  228. // );
  229. // }
  230. // }
  231. }
  232. //取消订单
  233. if($order->status!=-1 && $status == -1){
  234. // 已完成订单不能取消
  235. if ($order->status == 6) {
  236. CommonFn::requestAjax(false, '已完成订单不可取消');
  237. }
  238. $order->cancel_time = time();
  239. $order_info = $order->parseRow($order);
  240. }
  241. //确认接单
  242. if($order->status!=3 && $status == 3){
  243. $order_info = $order->parseRow($order);
  244. }
  245. //订单完成后执行
  246. if($order->status!=6 && $status == 6 ){
  247. $order->finish_time = time();
  248. $order_info = $order->parseRow($order);
  249. /*$result = Service::factory('ScoreService')->changeScore((string)$order->user,intval($order->final_price),'下单奖爪币');
  250. if($result){
  251. $z_message = new ZMessage();
  252. $from_user = Yii::app()->params['sys_user'];
  253. $message_data = array(
  254. 'from_user' => $from_user,
  255. 'to_user' => (string)$order->user,
  256. 'content' => '您成功下单,获得了'.intval($order->final_price).'个爪币的奖励。',
  257. 'pics' => array(),
  258. 'voice' => array(),
  259. 'video'=> array()
  260. );
  261. $z_message->addMessage($message_data);
  262. CommonSMS::send('final_order',array('name' =>$order_info['address']['name'],'num' =>intval($order->final_price),'mobile'=>$order_info['address']['mobile']));
  263. }*/
  264. // 保洁师订单统计处理
  265. if ($technician_obj) {
  266. $tech_order_count = $technician_obj->order_count + 1;
  267. $technician_obj->order_count = $tech_order_count;
  268. $technician_obj->save();
  269. }
  270. }
  271. $order->status = $status;
  272. $order->booking_time = $booking_time;
  273. $order->deal_time = $deal_time;
  274. $order->remark = $remark;
  275. $order->count = $count;
  276. //$order->station = new MongoId($station);
  277. // 是否通知保洁师
  278. $toTech = $order->technician != $technician_id ? true : false;
  279. $order->technician = $technician_id;
  280. $order->technician_name = $technician_name;
  281. $arr_order = array('cancel_time','refund_time','finish_time','status','count','booking_time','deal_time','remark', 'station', 'technician', 'technician_name');
  282. $success = $order->save(true,$arr_order);
  283. // 通知保洁师
  284. if (in_array($status, array(1,2,3,4,5)) && $toTech && $success) {
  285. // if ($toTech) {
  286. if ($technician_obj && $technician_obj->weixin_userid) {
  287. $url_prefix = ENVIRONMENT == 'product' ? 'http://api.wozhua.mobi' : 'http://apitest.wozhua.mobi';
  288. $wechat = O2oApp::getWechatActive();
  289. $wechat_data = array(
  290. 'touser' => $technician_obj->weixin_userid,
  291. 'msgtype' => 'news',
  292. 'agentid' => '24',
  293. 'news' => array(
  294. 'articles' => array(
  295. array(
  296. 'title' => '壹管家提示-新订单',
  297. 'description' => $technician_obj->name.'你好!刚刚有一个新的订单被分配给你,请点击查看。',
  298. 'url' => $url_prefix.'/index.php?r=o2o/myOrder/info&order='.$id.'&user='.$technician_id,
  299. ),
  300. ),
  301. ),
  302. );
  303. $wechat->sendMessage($wechat_data);
  304. }
  305. }
  306. CommonFn::requestAjax($success, '', array());
  307. }
  308. // 根据手机号 获取对应用户的地址信息
  309. public function actionGetUserInfo(){
  310. $mobile = Yii::app()->request->getParam('mobile', '');
  311. $length = strlen($mobile);
  312. if ($length < 11) {
  313. $result[] = array(
  314. 'id' => 0,
  315. 'data' => '',
  316. 'description' => '请继续输入',
  317. 'content' => array()
  318. );
  319. echo json_encode($result);exit;
  320. }
  321. // $mobile_regex = new MongoRegex($mobile);
  322. $criteria = new EMongoCriteria();
  323. $criteria->sort('order_time', EMongoCriteria::SORT_DESC);
  324. $criteria->addCond('address.mobile', '==', $mobile);
  325. $cursor = ROrder::model()->findAll($criteria);
  326. $rows = CommonFn::getRowsFromCursor($cursor);
  327. if (empty($rows)) {
  328. $result[] = array(
  329. 'id' => 0,
  330. 'data' => '',
  331. 'description' => '没有匹配信息',
  332. 'content' => array()
  333. );
  334. echo json_encode($result);exit;
  335. }
  336. $result = array();
  337. $details = array();
  338. $index = 0;
  339. foreach($rows as $row){
  340. // 加入根据detail筛选,避免产生重复信息
  341. if (in_array($row['address']['detail'], $details)) continue;
  342. $details[] = $row['address']['detail'];
  343. $pio = isset($row['address']['poi']['name'])?$row['address']['poi']['name']:'';
  344. // 坐标获取(根据不同的来源)
  345. if ($row['channel'] == 'dianping') {
  346. $latitude = $row['address']['position']['lat'];
  347. $longitude = $row['address']['position']['lng'];
  348. } else {
  349. $latitude = isset($row['address']['position']['1'])?$row['address']['position']['1']:'';
  350. $longitude = isset($row['address']['position']['0'])?$row['address']['position']['0']:'';
  351. }
  352. // poi获取
  353. $poi_name = isset($row['address']['poi']['name']) ? $row['address']['poi']['name'] : '';
  354. $poi_uid = isset($row['address']['poi']['uid']) ? $row['address']['poi']['uid'] : '';
  355. $result[] = array(
  356. 'id' => $index,
  357. 'data' => $row['address']['mobile'],
  358. 'description' => $row['address']['province'].' '.$row['address']['city'].' '.$row['address']['area'].' '.$pio.$row['address']['detail'],
  359. 'content' => array(
  360. 'name' => $row['address']['name'],
  361. 'latitude' => $latitude,
  362. 'longitude' => $longitude,
  363. 'province' => $row['address']['province'],
  364. 'city' => $row['address']['city'],
  365. 'area' => $row['address']['area'],
  366. 'detail' => $row['address']['detail'],
  367. 'poi_name' => $poi_name,
  368. 'poi_uid' => $poi_uid,
  369. 'memo' => $row['memo']
  370. )
  371. );
  372. $index++;
  373. }
  374. echo json_encode($result);exit;
  375. /*$map = new MongoCode('
  376. function(){
  377. emit(this.address.name,this.address);
  378. }
  379. ');
  380. $reduce = new MongoCode('
  381. function(key,values){
  382. var ret={age:key,names:values[0]};
  383. return ret;
  384. }
  385. ');
  386. $query = array('address.mobile' => array('=' => $mobile));
  387. $instance = Message::model()->getDb();
  388. $cmd = $instance->command(array(
  389. 'mapreduce' => 'orders',
  390. 'map' => $map,
  391. 'reduce' => $reduce,
  392. 'query' => $query,
  393. 'out' => array('merge' => 'admin_message')
  394. ));*/
  395. /**
  396. * note time : 2015-10-16
  397. * noted by : zhouxuchen
  398. */
  399. /*$mongo = new MongoClient(DB_CONNETC);
  400. $pipeline = array(
  401. array(
  402. '$match' => array(
  403. '_id' => array('address.mobile' => $mobile)
  404. ),
  405. '$group' => array(
  406. 'mobile' => array('state' => '$state' ),
  407. 'user' => array('$first' => '$pop' )
  408. )
  409. )
  410. );
  411. $out = $mongo->wozhua_o2o->orders->aggregate($pipeline);
  412. var_dump($out);exit;*/
  413. }
  414. public function actionAdd () {
  415. // ------ 必须传入的数值 ------
  416. // --------- 订单信息 ---------
  417. $channel = Yii::app()->request->getParam('channel', '');
  418. $booking_time = Yii::app()->request->getParam('booking_time_add', '');
  419. $order_time = Yii::app()->request->getParam('order_time_add', '');
  420. $main_products = Yii::app()->request->getParam('main_products', '');
  421. $price = Yii::app()->request->getParam('price', 0);
  422. $final_price = Yii::app()->request->getParam('final_price', 0);
  423. $status = Yii::app()->request->getParam('status', -3);
  424. $station = Yii::app()->request->getParam('station', '57db39709f5160bb048b456a');
  425. // --------- 地址信息 ---------
  426. $mobile = Yii::app()->request->getParam('mobile', 0);
  427. $latitude = Yii::app()->request->getParam('latitude', 0);
  428. $longitude = Yii::app()->request->getParam('longitude', 0);
  429. $province = Yii::app()->request->getParam('province', '');
  430. $city = Yii::app()->request->getParam('city', '');
  431. $area = Yii::app()->request->getParam('area', '');
  432. $poi_name = Yii::app()->request->getParam('poi_name', '');
  433. $detail = Yii::app()->request->getParam('detail', '');
  434. $extra = Yii::app()->request->getParam('extra',array());
  435. $extra = json_decode($extra);
  436. // 数据完整性检查
  437. // 2015-11-02 因存在赠送订单,删除金额的数据检查 : $price == 0 || $final_price == 0 ||
  438. // 2015-11-16 取消服务点录入,删除服务点数据检查 : || empty($station)
  439. $flag = empty($channel) || empty($booking_time) || empty($order_time);
  440. $flag = $flag || $status == -3;
  441. $flag = $flag || $mobile == 0 || $latitude == 0 || $longitude == 0;
  442. $flag = $flag || empty($province) || empty($city) || empty($area) || empty($poi_name) || empty($detail);
  443. if ($flag) {
  444. CommonFn::requestAjax(false, '请检查数据完整性', array());
  445. exit;
  446. }
  447. //if($channel == 'wz_app' || $channel == 'wx_pub'){
  448. //CommonFn::requestAjax(false, '不能录入渠道为壹管家微信||壹管家APP的订单', array());
  449. //exit;
  450. //}
  451. // 时间处理
  452. $booking_time = strtotime($booking_time);
  453. $order_time = strtotime($order_time);
  454. // ------ 可以留空的数值 ------
  455. $box = Yii::app()->request->getParam('box', array());
  456. $coupons = Yii::app()->request->getParam('coupons', array());
  457. $memo = Yii::app()->request->getParam('memo', '');
  458. $remark = Yii::app()->request->getParam('remark', '');
  459. $precedence = Yii::app()->request->getParam('precedence', 0);
  460. $have_comment = Yii::app()->request->getParam('have_comment', 0);
  461. $name = Yii::app()->request->getParam('name', '');
  462. $type = Yii::app()->request->getParam('type', 0);
  463. $user = Yii::app()->request->getParam('user', '');
  464. $poi_uid = Yii::app()->request->getParam('poi_uid', '');
  465. // 用户名的判断
  466. $channel_option = ROrder::$channel_option;
  467. $name = empty($name) ? $channel_option[$channel]['name'].'用户' : $name;
  468. // 支付渠道
  469. $pay_channel = $channel;
  470. // 服务数据整合
  471. $products[] = array(
  472. 'product' => new MongoId($main_products),
  473. 'count' => 1,
  474. 'extra' =>$extra
  475. );
  476. if (!empty($box)) {
  477. foreach ($box as $key => $value) {
  478. $products[] = array(
  479. 'product' => new MongoId($value),
  480. 'count' => 1,
  481. 'extra' =>$extra
  482. );
  483. }
  484. }
  485. // 地址数据整合
  486. $address = array(
  487. 'province' => $province,
  488. 'city' => $city,
  489. 'area' => $area,
  490. 'detail' => $detail,
  491. 'mobile' => $mobile,
  492. 'position' => array(
  493. // 'lat' => (float)$latitude,
  494. // 'lng' => (float)$longitude,
  495. 0 => (float)$longitude,
  496. 1 => (float)$latitude
  497. ),
  498. 'poi' => array(
  499. 'name' => $poi_name,
  500. 'uid' => $poi_uid
  501. ),
  502. 'name' => $name
  503. );
  504. // 订单类型判断
  505. if ($type == 0) {
  506. $criteria = new EMongoCriteria();
  507. $criteria->_id = new MongoId($main_products);
  508. $cursor = Product::model()->find($criteria);
  509. $type = $cursor->type;
  510. }
  511. $rOrder = new ROrder();
  512. $rOrder->channel = $channel;
  513. $rOrder->booking_time = intval($booking_time);
  514. $rOrder->order_time = intval($order_time);
  515. $rOrder->products = $products;
  516. $rOrder->price = intval($price);
  517. $rOrder->final_price = intval($final_price);
  518. //$rOrder->precedence = intval($precedence);
  519. $rOrder->coupons = $coupons;
  520. $rOrder->user = $user;
  521. $rOrder->status = intval($status);
  522. $rOrder->memo = $memo;
  523. $rOrder->remark = $remark;
  524. $rOrder->type = strval($type); // 数据库内使用string类型
  525. $rOrder->have_comment = intval($have_comment);
  526. $rOrder->station = new MongoId($station);
  527. $rOrder->address = $address;
  528. $rOrder->pay_channel = $pay_channel;
  529. $addROrder_arr = array('channel', 'booking_time', 'order_time', 'price','products', 'final_price', 'precedence', 'coupons', 'user', 'status', 'memo', 'remark', 'type', 'have_comment', 'station', 'address', 'pay_channel');
  530. $success = $rOrder->save(true, $addROrder_arr);
  531. CommonFn::requestAjax($success, '', array());
  532. }
  533. /**
  534. * 请求申请退款订单接口
  535. */
  536. public function actionCheckRefundOrder() {
  537. $criteria = new EMongoCriteria();
  538. $criteria->status('==', -3);
  539. $cursor = ROrder::model()->findAll($criteria);
  540. $count = $cursor->count();
  541. if ($count > 0) {
  542. $data = array('code' => 1, 'count' => $count);
  543. } else {
  544. $data = array('code' => 0, 'count' => $count);
  545. }
  546. $list = new ARedisList('append_order_list');
  547. if($list->getCount() > 0){
  548. $key = $list->shift();
  549. $list->unshift($key);
  550. $data['procession_append_order_id'] = $key;
  551. $data['code'] = 2;
  552. }
  553. echo json_encode($data);
  554. }
  555. public function actionCancelProcess() {
  556. $orderid = Yii::app()->request->getParam('orderid','');
  557. $list = new ARedisList('append_order_list');
  558. $key = $list->shift();
  559. }
  560. /**
  561. * 重新选择保洁师接口
  562. */
  563. public function actionResetTech() {
  564. $id = Yii::app()->request->getParam('id', '');
  565. $technician_id = intval(Yii::app()->request->getParam('reset_technician', 0));
  566. $technician_name = Yii::app()->request->getParam('reset_technician_name', '');
  567. // 保洁师信息检查
  568. // 根据ID直接查询保洁师信息(优先使用联想功能)
  569. if ($technician_id != 0) {
  570. $technician_obj = TechInfo::get($technician_id);
  571. if ($technician_obj) {
  572. $technician_id = $technician_obj->_id;
  573. $technician_name = $technician_obj->name;
  574. } else {
  575. CommonFn::requestAjax(false, '保洁师不存在');
  576. }
  577. // ID为0时根据输入框信息查询
  578. } else if ($technician_name != '') {
  579. $criteria = new EMongoCriteria();
  580. $criteria->name = $technician_name;
  581. $technician_obj = TechInfo::model()->find($criteria);
  582. if ($technician_obj) {
  583. $technician_id = $technician_obj->_id;
  584. $technician_name = $technician_obj->name;
  585. } else {
  586. CommonFn::requestAjax(false, '保洁师不存在');
  587. }
  588. } else {
  589. CommonFn::requestAjax(false, '保洁师姓名不能为空');
  590. }
  591. $orderid = new MongoId($id);
  592. $order = ROrder::model()->get($orderid);
  593. $toTech = $order->technician != $technician_id ? true : false;
  594. $fromTech = $order->technician;
  595. $order->technician = $technician_id;
  596. $order->technician_name = $technician_name;
  597. $success = $order->save(true, array('technician', 'technician_name'));
  598. if ($toTech && $success) {
  599. // 发送给被分配保洁师
  600. $wechat = O2oApp::getWechatActive();
  601. $url_prefix = ENVIRONMENT == 'product' ? 'http://api.wozhua.mobi' : 'http://apitest.wozhua.mobi';
  602. if (!empty($technician_obj->weixin_userid)) {
  603. $wechat_data = array(
  604. 'touser' => $technician_obj->weixin_userid,
  605. 'msgtype' => 'news',
  606. 'agentid' => '24',
  607. 'news' => array(
  608. 'articles' => array(
  609. array(
  610. 'title' => '壹管家提示-新订单',
  611. 'description' => $technician_obj->name.'你好!刚刚有一个新的订单被分配给你,请点击查看。',
  612. 'url' => $url_prefix.'/index.php?r=o2o/myOrder/info&order='.$id.'&user='.$technician_id,
  613. ),
  614. ),
  615. ),
  616. );
  617. $wechat->sendMessage($wechat_data);
  618. }
  619. // 发送给原保洁师
  620. $fromTechObj = TechInfo::get($fromTech);
  621. if (!empty($fromTechObj) && !empty($fromTechObj->weixin_userid)) {
  622. $wechat_data = array(
  623. 'touser' => $fromTechObj->weixin_userid,
  624. 'msgtype' => 'news',
  625. 'agentid' => '24',
  626. 'news' => array(
  627. 'articles' => array(
  628. array(
  629. 'title' => '壹管家提示-订单已被重新分配',
  630. 'description' => $fromTechObj->name.'你好!预定时间在'.date('m月d日H:i', $order->booking_time).'的订单已被分配给其他保洁师。',
  631. 'url' => $url_prefix.'/index.php?r=o2o/myOrder/info&order='.$id.'&user='.$technician_id,
  632. ),
  633. ),
  634. ),
  635. );
  636. $wechat->sendMessage($wechat_data);
  637. }
  638. }
  639. CommonFn::requestAjax($success, '', array());
  640. }
  641. }