ROrderController.php 30 KB

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