ROrderController.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  1. <?php
  2. class ROrderController extends AdminController{
  3. public function actionIndex()
  4. {
  5. $status_option = ROrder::$status_option;
  6. $status = CommonFn::getComboboxData($status_option, 100, true, 100);
  7. $channel_option = ROrder::$channel_option;
  8. $channels = CommonFn::getComboboxData($channel_option, 100, true, 100);
  9. // 服务信息
  10. $criteria_main = new EMongoCriteria();
  11. $criteria_main->status('==', 1);
  12. $cursor_main = Product::model()->findAll($criteria_main);
  13. $rows_main = CommonFn::getRowsFromCursor($cursor_main);
  14. $main_row = array();
  15. foreach($rows_main as $row){
  16. $ids = (string)$row['_id'];
  17. $main_row[$ids] = array('name' =>$row['name']);
  18. }
  19. $main_products = CommonFn::getComboboxData($main_row, 100, true, 100);
  20. // 服务点信息
  21. $criteria_station = new EMongoCriteria();
  22. $cursor = Station::model()->findAll($criteria_station);
  23. $rows = CommonFn::getRowsFromCursor($cursor);
  24. $parsedRows = Station::model()->parse($rows);
  25. $station_data = array();
  26. foreach ($parsedRows as $key => $v) {
  27. $station_data = array_merge($station_data, array($v['id'] => array('name' => $v['name'])));
  28. }
  29. $station = CommonFn::getComboboxData($station_data, 'all', true, 'all');
  30. // 订单类型
  31. $type_data = Yii::app()->params['o2o_service'];
  32. $type = CommonFn::getComboboxData($type_data, 100, true, 100);
  33. $this->render('index', array(
  34. 'status' => $status,
  35. 'main_products'=> $main_products,
  36. 'channels' => $channels,
  37. 'station' => $station,
  38. 'type' => $type
  39. ));
  40. }
  41. public function actionList(){
  42. $filter_status = intval(Yii::app()->request->getParam('status', 100));
  43. $search = Yii::app()->request->getParam('search', '');
  44. $id = Yii::app()->request->getParam('id', '');
  45. $date_start_order = Yii::app()->request->getParam('date_start_order');
  46. $date_end_order = Yii::app()->request->getParam('date_end_order');
  47. $date_start_book= Yii::app()->request->getParam('date_start_book');
  48. $date_end_book = Yii::app()->request->getParam('date_end_book');
  49. $type = Yii::app()->request->getParam('type', 100);
  50. $have_pay = Yii::app()->request->getParam('have_pay', 0);
  51. $channel = Yii::app()->request->getParam('channel', 100);
  52. //$station = Yii::app()->request->getParam('station', 'all');
  53. $params = CommonFn::getPageParams();
  54. $criteria = new EMongoCriteria($params);
  55. if ($filter_status != 100){
  56. $criteria->status('==', $filter_status);
  57. }
  58. if ($id != ''){
  59. $order_id = new MongoId($id);
  60. $criteria->_id('==', $order_id);
  61. }
  62. if ($channel != 100){
  63. $criteria->channel('==', $channel);
  64. }
  65. if ($type != 100) {
  66. $criteria->type = $type;
  67. }
  68. if ($search != ''){
  69. if(CommonFn::isMongoId($search)){
  70. //$criteria->_id('==', new MongoId($search));
  71. $criteria->addCond('_id','or',new MongoId($search));
  72. $criteria->addCond('user','or',new MongoId($search));
  73. }
  74. else if(preg_match('/\d{8,11}/', $search)){
  75. $criteria->addCond('address.mobile','==',$search);
  76. if($have_pay){
  77. $criteria->addCond('status','>',0);
  78. }
  79. }else if(strlen($search) == 27){
  80. $criteria->charge_id('==', $search);
  81. }else{
  82. $criteria->addCond('address.name','==',$search);
  83. }
  84. }
  85. // 下单时间处理
  86. if (!empty($date_start_order) && !empty($date_end_order)) {
  87. // 开始时间处理
  88. $timestamp_start_order = strtotime($date_start_order);
  89. // 结束时间处理,需通过strototime()增加一天
  90. $timestamp_end_order = strtotime('+1 day', strtotime($date_end_order));
  91. $criteria->order_time('>=', $timestamp_start_order);
  92. $criteria->order_time('<=', $timestamp_end_order);
  93. }
  94. // 预约时间处理
  95. if (!empty($date_start_book) && !empty($date_end_book)) {
  96. // 开始时间处理
  97. $timestamp_start_book = strtotime($date_start_book);
  98. // 结束时间处理,需通过strototime()增加一天
  99. $timestamp_end_book = strtotime('+1 day', strtotime($date_end_book));
  100. $criteria->booking_time('>=', $timestamp_start_book);
  101. $criteria->booking_time('<=', $timestamp_end_book);
  102. }
  103. // 服务站处理
  104. // if ($station != 'all') {
  105. // $criteria->station = new MongoId($station);
  106. //}
  107. $cursor = ROrder::model()->findAll($criteria);
  108. $total = $cursor->count();
  109. $rows = CommonFn::getRowsFromCursor($cursor);
  110. $parsedRows = ROrder::model()->parse($rows);
  111. echo CommonFn::composeDatagridData($parsedRows, $total);
  112. }
  113. public function actionEdit(){
  114. $id = Yii::app()->request->getParam('id', '');
  115. $status = intval(Yii::app()->request->getParam('status',1));
  116. $counts = intval(Yii::app()->request->getParam('count',1));
  117. $booking_time = intval(Yii::app()->request->getParam('booking_time', time()));
  118. $deal_time = intval(Yii::app()->request->getParam('deal_time', time()));
  119. $remark = Yii::app()->request->getParam('remark', '');
  120. //$station = Yii::app()->request->getParam('station_id', '');
  121. $technician_ids = array();
  122. $technician_names = array();
  123. $technicians = array();
  124. $nums = Yii::app()->request->getParam('tech_nums');
  125. for($i=0;$i<=$nums;$i++) {
  126. if(Yii::app()->request->getParam('extra_add_info_'.$i)) {
  127. $technician_ids[] = Yii::app()->request->getParam('extra_add_info_id_'.$i);
  128. $technician_names[] = Yii::app()->request->getParam('extra_add_info_'.$i);
  129. }
  130. }
  131. if(!$counts){
  132. CommonFn::requestAjax(false, '购买数量错误');
  133. }
  134. // 保洁师信息检查
  135. // 根据ID直接查询保洁师信息(优先使用联想功能)
  136. if (isset($technician_ids)) {
  137. foreach($technician_ids as $key => $technician_id){
  138. $technician_obj = TechInfo::get($technician_id);
  139. if ($technician_obj) {
  140. $technicians[$key]['technician_id'] = $technician_obj->_id;
  141. $technicians[$key]['technician_name'] = $technician_obj->name;
  142. } else {
  143. CommonFn::requestAjax(false, '保洁师不存在');
  144. break;
  145. }
  146. }
  147. // ID为0时根据输入框信息查询
  148. } else if (isset($technician_names)) {
  149. $criteria = new EMongoCriteria();
  150. foreach($technician_names as $key => $technician_name) {
  151. $criteria->name = $technician_name;
  152. $technician_obj = TechInfo::model()->find($criteria);
  153. if ($technician_obj) {
  154. $technicians[$key]['technician_id'] = $technician_obj->_id;
  155. $technicians[$key]['technician_name'] = $technician_obj->name;
  156. } else {
  157. CommonFn::requestAjax(false, '保洁师不存在');
  158. break;
  159. }
  160. }
  161. } else {
  162. $technician_obj = null;
  163. //$technician_id = 0;
  164. // $technician_name = '';
  165. foreach($technicians as $key => $value) {
  166. $technicians[$key]['$technician_id'] = 0;
  167. $technicians[$key]['$technician_name'] = 0;
  168. }
  169. }
  170. //var_dump($technicians);exit;
  171. if($status == 100){
  172. CommonFn::requestAjax(false, '必须指定状态!');
  173. }
  174. $criteria = new EMongoCriteria();
  175. $criteria->_id = new MongoId($id);
  176. $order = ROrder::model()->find($criteria);
  177. // if($order->status == -1 || $order->status == -2){
  178. // CommonFn::requestAjax(false, '已取消,已退款订单不支持更改');
  179. // }
  180. // 获取用户信息,修改用户订单统计
  181. // 2015-11-16
  182. $user_id = $order->user;
  183. if (!empty($user_id)) {
  184. $user = RUser::get($user_id);
  185. } else {
  186. $user = '';
  187. }
  188. if (empty($order)){
  189. CommonFn::requestAjax(false, '订单不存在');
  190. }
  191. if(($order->status!=-1||$order->status!=-2)&&($status==-1||$status==-2)){
  192. foreach ($order->coupons as $user_coupon) {
  193. $user_coupon = UserCoupon::get($user_coupon);
  194. $user_coupon->status = 1;
  195. $user_coupon->update(array('status'),true);
  196. }
  197. }
  198. if($order->status!=-2 && $status == -2) {
  199. $order->refund_time = time();
  200. $order_info = $order->parseRow($order);
  201. $month = date('m', $order_info['booking_time']);
  202. $day = date('d', $order_info['booking_time']);
  203. $address = $order_info['address']['poi']['name'] . $order_info['address']['detail'];
  204. CommonSMS::send('order_retrieve', array('month' => $month, 'day' => $day, 'address' => $address, 'mobile' => $order_info['address']['mobile']));
  205. // 申请退款处理完成后通知保洁师
  206. foreach ($technician_ids as $key => $technician_id) {
  207. $technician_obj = TechInfo::get($technician_id);
  208. if ($technician_obj && $technician_obj->weixin_userid) {
  209. $url_prefix = ENVIRONMENT == 'product' ? 'http://api.yiguanjia.me' : 'http://apitest.yiguanjia.me';
  210. $wechat = O2oApp::getWechatActive();
  211. $wechat_data = array(
  212. 'touser' => $technician_obj->weixin_userid,
  213. 'msgtype' => 'news',
  214. 'agentid' => '1',
  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. //'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_id,
  221. 'url' => $url_prefix . '/index.php?r=o2o/myOrder/index'
  222. ),
  223. ),
  224. ),
  225. );
  226. if (!empty($order->append_orders)) {
  227. $count = count($order->append_orders);
  228. $wechat_data['news']['articles'][0]['description'] .= "\n\n本订单包含" . $count . "个追加订单,请注意查看。";
  229. }
  230. $wechat->sendMessage($wechat_data);
  231. }
  232. }
  233. }
  234. //取消订单
  235. if($order->status!=-1 && $status == -1){
  236. // 已完成订单不能取消
  237. if ($order->status == 6) {
  238. CommonFn::requestAjax(false, '已完成订单不可取消');
  239. }
  240. $order->cancel_time = time();
  241. $order_info = $order->parseRow($order);
  242. }
  243. //确认接单
  244. if($order->status!=3 && $status == 3){
  245. $order_info = $order->parseRow($order);
  246. }
  247. //订单完成后执行
  248. if($order->status!=6 && $status == 6 ){
  249. $order->finish_time = time();
  250. $order_info = $order->parseRow($order);
  251. /*$result = Service::factory('ScoreService')->changeScore((string)$order->user,intval($order->final_price),'下单奖爪币');
  252. if($result){
  253. $z_message = new ZMessage();
  254. $from_user = Yii::app()->params['sys_user'];
  255. $message_data = array(
  256. 'from_user' => $from_user,
  257. 'to_user' => (string)$order->user,
  258. 'content' => '您成功下单,获得了'.intval($order->final_price).'个爪币的奖励。',
  259. 'pics' => array(),
  260. 'voice' => array(),
  261. 'video'=> array()
  262. );
  263. $z_message->addMessage($message_data);
  264. CommonSMS::send('final_order',array('name' =>$order_info['address']['name'],'num' =>intval($order->final_price),'mobile'=>$order_info['address']['mobile']));
  265. }*/
  266. // 保洁师订单统计处理
  267. foreach($technician_ids as $key => $technician_id) {
  268. $technician_obj = TechInfo::get($technician_id);
  269. if ($technician_obj) {
  270. $tech_order_count = $technician_obj->order_count + 1;
  271. $technician_obj->order_count = $tech_order_count;
  272. $technician_obj->save();
  273. }
  274. }
  275. }
  276. $order->status = $status;
  277. $order->booking_time = $booking_time;
  278. $order->deal_time = $deal_time;
  279. $order->remark = $remark;
  280. $order->counts = $counts;
  281. //$order->station = new MongoId($station);
  282. // 是否通知保洁师
  283. $toTech = !empty($order->technicians)? true : false;
  284. //$order->technician = $technician_id;
  285. //$order->technician_name = $technician_name;
  286. $order->technicians = $technicians;
  287. //var_dump($order);exit;
  288. //判断是否为实惠或金百订单
  289. if($order->channel == 'shihui'){
  290. if ($status == 1) {//已支付
  291. $res = self::UpdateStatus((string)$order->_id, 5);
  292. } else if($status ==3){//已接单
  293. $res = self::UpdateStatus((string)$order->_id, 15);
  294. }else if($status ==6){//服务完成
  295. $res = self::UpdateStatus((string)$order->_id, 20);
  296. }else if($status ==-1){//取消订单
  297. $res = self::DelOrder((string)$order->_id);
  298. }
  299. }else if($order->channel == 'jingbai'){
  300. if ($status == 1) {//已支付
  301. $res = self::UpdateStatus((string)$order->_id, 5);
  302. } else if($status ==3){//已接单
  303. $res = self::UpdateStatus((string)$order->_id, 15);
  304. }else if($status ==6){//服务完成
  305. $res = self::UpdateStatus((string)$order->_id, 20);
  306. }else if($status ==-1){//取消订单
  307. $res = self::DelOrder((string)$order->_id);
  308. }
  309. }
  310. if (!$res) {
  311. CommonFn::requestAjax(false,'修改失败');
  312. }
  313. //
  314. $arr_order = array('cancel_time','refund_time','finish_time','status','booking_time','deal_time','remark', 'station', 'technicians');
  315. $success = $order->save(true,$arr_order);
  316. $char = false;
  317. // 通知保洁师
  318. if (in_array($status, array(1,2,3,4,5)) && $toTech && $success) {
  319. foreach($technician_ids as $key => $technician_id) {
  320. $technician_obj = TechInfo::get($technician_id);
  321. if ($technician_obj && $technician_obj->weixin_userid) {
  322. $url_prefix = ENVIRONMENT == 'product' ? 'http://api.yiguanjia.me' : 'http://apitest.yiguanjia.me';
  323. $wechat = O2oApp::getWechatActive();
  324. $wechat_data = array(
  325. 'touser' => $technician_obj->weixin_userid,
  326. 'msgtype' => 'news',
  327. 'agentid' => 1,
  328. 'news' => array(
  329. 'articles' => array(
  330. array(
  331. 'title' => '壹管家提示-新订单',
  332. 'description' => $technician_obj->name . '你好!刚刚有一个新的订单被分配给你,请点击查看。',
  333. //'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_id,
  334. 'url' => $url_prefix . '/index.php?r=o2o/myOrder/index'
  335. ),
  336. ),
  337. ),
  338. );
  339. $char = $wechat->sendMessage($wechat_data);
  340. }
  341. }
  342. }
  343. CommonFn::requestAjax($success, '微信'.$char, array());
  344. }
  345. // 根据手机号 获取对应用户的地址信息
  346. public function actionGetUserInfo(){
  347. $mobile = Yii::app()->request->getParam('mobile', '');
  348. $length = strlen($mobile);
  349. if ($length < 11) {
  350. $result[] = array(
  351. 'id' => 0,
  352. 'data' => '',
  353. 'description' => '请继续输入',
  354. 'content' => array()
  355. );
  356. echo json_encode($result);exit;
  357. }
  358. // $mobile_regex = new MongoRegex($mobile);
  359. $criteria = new EMongoCriteria();
  360. $criteria->sort('order_time', EMongoCriteria::SORT_DESC);
  361. $criteria->addCond('address.mobile', '==', $mobile);
  362. $cursor = ROrder::model()->findAll($criteria);
  363. $rows = CommonFn::getRowsFromCursor($cursor);
  364. if (empty($rows)) {
  365. $result[] = array(
  366. 'id' => 0,
  367. 'data' => '',
  368. 'description' => '没有匹配信息',
  369. 'content' => array()
  370. );
  371. echo json_encode($result);exit;
  372. }
  373. $result = array();
  374. $details = array();
  375. $index = 0;
  376. foreach($rows as $row){
  377. // 加入根据detail筛选,避免产生重复信息
  378. if (in_array($row['address']['detail'], $details)) continue;
  379. $details[] = $row['address']['detail'];
  380. $pio = isset($row['address']['poi']['name'])?$row['address']['poi']['name']:'';
  381. // 坐标获取(根据不同的来源)
  382. if ($row['channel'] == 'dianping') {
  383. $latitude = $row['address']['position']['lat'];
  384. $longitude = $row['address']['position']['lng'];
  385. } else {
  386. $latitude = isset($row['address']['position']['1'])?$row['address']['position']['1']:'';
  387. $longitude = isset($row['address']['position']['0'])?$row['address']['position']['0']:'';
  388. }
  389. // poi获取
  390. $poi_name = isset($row['address']['poi']['name']) ? $row['address']['poi']['name'] : '';
  391. $poi_uid = isset($row['address']['poi']['uid']) ? $row['address']['poi']['uid'] : '';
  392. $result[] = array(
  393. 'id' => $index,
  394. 'data' => $row['address']['mobile'],
  395. 'description' => $row['address']['province'].' '.$row['address']['city'].' '.$row['address']['area'].' '.$pio.$row['address']['detail'],
  396. 'content' => array(
  397. 'name' => $row['address']['name'],
  398. 'latitude' => $latitude,
  399. 'longitude' => $longitude,
  400. 'province' => $row['address']['province'],
  401. 'city' => $row['address']['city'],
  402. 'area' => $row['address']['area'],
  403. 'detail' => $row['address']['detail'],
  404. 'poi_name' => $poi_name,
  405. 'poi_uid' => $poi_uid,
  406. 'memo' => $row['memo']
  407. )
  408. );
  409. $index++;
  410. }
  411. echo json_encode($result);exit;
  412. }
  413. public function actionAdd () {
  414. // ------ 必须传入的数值 ------
  415. // --------- 订单信息 ---------
  416. $channel = Yii::app()->request->getParam('channel', '');
  417. $booking_time = Yii::app()->request->getParam('booking_time_add', '');
  418. $order_time = Yii::app()->request->getParam('order_time_add', '');
  419. $main_products = Yii::app()->request->getParam('main_products', '');
  420. $price = floatval(Yii::app()->request->getParam('price', 0));
  421. $final_price = floatval(Yii::app()->request->getParam('final_price', 0));
  422. $status = Yii::app()->request->getParam('status', -3);
  423. $station = Yii::app()->request->getParam('station', '57db39709f5160bb048b456a');
  424. // --------- 地址信息 ---------
  425. $mobile = Yii::app()->request->getParam('mobile', 0);
  426. $latitude = Yii::app()->request->getParam('latitude', 0);
  427. $longitude = Yii::app()->request->getParam('longitude', 0);
  428. $province = Yii::app()->request->getParam('province', '');
  429. $city = Yii::app()->request->getParam('city', '');
  430. $area = Yii::app()->request->getParam('area', '');
  431. $poi_name = Yii::app()->request->getParam('poi_name', '');
  432. $detail = Yii::app()->request->getParam('detail', '');
  433. $counts = intval(Yii::app()->request->getParam('counts', 1));
  434. $counts = $counts?$counts:1;
  435. $extra = Yii::app()->request->getParam('extra','[]');
  436. $extra = json_decode($extra);
  437. // 数据完整性检查
  438. // 2015-11-02 因存在赠送订单,删除金额的数据检查 : $price == 0 || $final_price == 0 ||
  439. // 2015-11-16 取消服务点录入,删除服务点数据检查 : || empty($station)
  440. $flag = empty($channel) || empty($booking_time) || empty($order_time);
  441. $flag = $flag || $status == -3;
  442. $flag = $flag || $mobile == 0 || $latitude == 0 || $longitude == 0;
  443. $flag = $flag || empty($province) || empty($city) || empty($area) || empty($poi_name) || empty($detail);
  444. if ($flag) {
  445. CommonFn::requestAjax(false, '请检查数据完整性', array());
  446. exit;
  447. }
  448. //if($channel == 'wz_app' || $channel == 'wx_pub'){
  449. //CommonFn::requestAjax(false, '不能录入渠道为壹管家微信||壹管家APP的订单', array());
  450. //exit;
  451. //}
  452. // 时间处理
  453. $booking_time = strtotime($booking_time);
  454. $order_time = strtotime($order_time);
  455. // ------ 可以留空的数值 ------
  456. $box = Yii::app()->request->getParam('box', array());
  457. $coupons = Yii::app()->request->getParam('coupons', array());
  458. $memo = Yii::app()->request->getParam('memo', '');
  459. $remark = Yii::app()->request->getParam('remark', '');
  460. $precedence = Yii::app()->request->getParam('precedence', 0);
  461. $have_comment = Yii::app()->request->getParam('have_comment', 0);
  462. $name = Yii::app()->request->getParam('name', '');
  463. $type = Yii::app()->request->getParam('type', 0);
  464. $user = Yii::app()->request->getParam('user', '');
  465. $poi_uid = Yii::app()->request->getParam('poi_uid', '');
  466. // 用户名的判断
  467. $channel_option = ROrder::$channel_option;
  468. $name = empty($name) ? $channel_option[$channel]['name'].'用户' : $name;
  469. // 支付渠道
  470. $pay_channel = $channel;
  471. // 服务数据整合
  472. $products[] = array(
  473. 'product' => new MongoId($main_products),
  474. 'count' => 1,
  475. 'extra' =>$extra
  476. );
  477. if (!empty($box)) {
  478. foreach ($box as $key => $value) {
  479. $products[] = array(
  480. 'product' => new MongoId($value),
  481. 'count' => 1,
  482. 'extra' =>$extra
  483. );
  484. }
  485. }
  486. // 地址数据整合
  487. $address = array(
  488. 'province' => $province,
  489. 'city' => $city,
  490. 'area' => $area,
  491. 'detail' => $detail,
  492. 'mobile' => $mobile,
  493. 'position' => array(
  494. // 'lat' => (float)$latitude,
  495. // 'lng' => (float)$longitude,
  496. 0 => (float)$longitude,
  497. 1 => (float)$latitude
  498. ),
  499. 'poi' => array(
  500. 'name' => $poi_name,
  501. 'uid' => $poi_uid
  502. ),
  503. 'name' => $name
  504. );
  505. // 订单类型判断
  506. if ($type == 0) {
  507. $criteria = new EMongoCriteria();
  508. $criteria->_id = new MongoId($main_products);
  509. $cursor = Product::model()->find($criteria);
  510. $type = $cursor->type;
  511. }
  512. $rOrder = new ROrder();
  513. $rOrder->channel = $channel;
  514. $rOrder->booking_time = intval($booking_time);
  515. $rOrder->order_time = intval($order_time);
  516. $rOrder->products = $products;
  517. $rOrder->price = floatval($price);
  518. $rOrder->final_price = floatval($final_price);
  519. $rOrder->precedence = intval($precedence);
  520. $rOrder->counts = $counts;
  521. $rOrder->coupons = $coupons;
  522. $rOrder->user = $user;
  523. $rOrder->status = intval($status);
  524. $rOrder->memo = $memo;
  525. $rOrder->remark = $remark;
  526. $rOrder->type = strval($type); // 数据库内使用string类型
  527. $rOrder->have_comment = intval($have_comment);
  528. $rOrder->station = new MongoId($station);
  529. $rOrder->address = $address;
  530. $rOrder->pay_channel = $pay_channel;
  531. $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');
  532. $success = $rOrder->save(true, $addROrder_arr);
  533. CommonFn::requestAjax($success, '', array());
  534. }
  535. /**
  536. * 请求申请退款订单接口
  537. */
  538. public function actionCheckRefundOrder() {
  539. $criteria = new EMongoCriteria();
  540. $criteria->status('==', -3);
  541. $cursor = ROrder::model()->findAll($criteria);
  542. $count = $cursor->count();
  543. if ($count > 0) {
  544. $data = array('code' => 1, 'count' => $count);
  545. } else {
  546. $data = array('code' => 0, 'count' => $count);
  547. }
  548. $list = new ARedisList('append_order_list');
  549. if($list->getCount() > 0){
  550. $key = $list->shift();
  551. $list->unshift($key);
  552. $data['procession_append_order_id'] = $key;
  553. $data['code'] = 2;
  554. }
  555. echo json_encode($data);
  556. }
  557. public function actionCancelProcess() {
  558. $orderid = Yii::app()->request->getParam('orderid','');
  559. $list = new ARedisList('append_order_list');
  560. $key = $list->shift();
  561. }
  562. /**
  563. * 重新选择保洁师接口
  564. */
  565. public function actionResetTech() {
  566. $id = Yii::app()->request->getParam('id', '');
  567. $nums = Yii::app()->request->getParam('nums', '');
  568. $technicians = array();
  569. $technician_ids = array();
  570. $technician_names = array();
  571. for($i=1;$i<=$nums;$i++) {
  572. if(Yii::app()->request->getParam('reset_extra_add_info_'.$i)) {
  573. $technician_ids[] = Yii::app()->request->getParam('reset_extra_add_info_id_'.$i);
  574. $technician_names[] = Yii::app()->request->getParam('reset_extra_add_info_'.$i);
  575. }
  576. }
  577. // 保洁师信息检查
  578. // 根据ID直接查询保洁师信息(优先使用联想功能)
  579. $technician_objs = array();
  580. foreach($technician_ids as $key => $technician_id) {
  581. if ($technician_id != 0) {
  582. $technician_obj = TechInfo::get($technician_id);
  583. if ($technician_obj) {
  584. $technicians[$key]['technician_id'] = $technician_obj->_id;
  585. $technicians[$key]['technician_name'] = $technician_obj->name;
  586. } else {
  587. CommonFn::requestAjax(false, '保洁师不存在');
  588. }
  589. // ID为0时根据输入框信息查询
  590. } else {
  591. foreach ($technician_names as $key => $technician_name)
  592. if ($technician_name != '') {
  593. $criteria = new EMongoCriteria();
  594. $criteria->name = $technician_name;
  595. $technician_obj = TechInfo::model()->find($criteria);
  596. if ($technician_obj) {
  597. $technicians[$key]['technician_id'] = $technician_obj->_id;
  598. $technicians[$key]['technician_name'] = $technician_obj->name;
  599. } else {
  600. CommonFn::requestAjax(false, '保洁师不存在');
  601. }
  602. } else {
  603. CommonFn::requestAjax(false, '保洁师姓名不能为空');
  604. }
  605. }
  606. $technician_objs[] = $technician_obj;
  607. }
  608. $orderid = new MongoId($id);
  609. $order = ROrder::model()->get($orderid);
  610. $toTech = isset($order->technicians) ? true : false;
  611. $fromTechs = $technician_names;
  612. //$order->technician = $technician_id;
  613. //$order->technician_name = $technician_name;
  614. $order->technicians = $technicians;
  615. $success = $order->save(true, array('technicians'));
  616. if ($toTech && $success) {
  617. foreach ($technician_objs as $technician_obj) {
  618. // 发送给被分配保洁师
  619. $wechat = O2oApp::getWechatActive();
  620. $url_prefix = ENVIRONMENT == 'product' ? 'http://api.yiguanjia.me' : 'http://apitest.yiguanjia.me';
  621. if (!empty($technician_obj->weixin_userid)) {
  622. $wechat_data = array(
  623. 'touser' => $technician_obj->weixin_userid,
  624. 'msgtype' => 'news',
  625. 'agentid' => '1',
  626. 'news' => array(
  627. 'articles' => array(
  628. array(
  629. 'title' => '壹管家提示-新订单',
  630. 'description' => $technician_obj->name . '你好!刚刚有一个新的订单被分配给你,请点击查看。',
  631. //'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_obj->_id,
  632. 'url' => $url_prefix . '/index.php?r=o2o/myOrder/index'
  633. ),
  634. ),
  635. ),
  636. );
  637. $wechat->sendMessage($wechat_data);
  638. }
  639. }
  640. // 发送给原保洁师
  641. foreach ($fromTechs as $fromTech) {
  642. $fromTechObj = TechInfo::get($fromTech);
  643. if (!empty($fromTechObj) && !empty($fromTechObj->weixin_userid)) {
  644. $wechat_data = array(
  645. 'touser' => $fromTechObj->weixin_userid,
  646. 'msgtype' => 'news',
  647. 'agentid' => '1',
  648. 'news' => array(
  649. 'articles' => array(
  650. array(
  651. 'title' => '壹管家提示-订单已被重新分配',
  652. 'description' => $fromTechObj->name . '你好!预定时间在' . date('m月d日H:i', $order->booking_time) . '的订单已被分配给其他保洁师。',
  653. 'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_obj->_id,
  654. ),
  655. ),
  656. ),
  657. );
  658. $wechat->sendMessage($wechat_data);
  659. }
  660. }
  661. }
  662. CommonFn::requestAjax($success, '', array());
  663. }
  664. /*public function actionDelOrder(){
  665. $delOrder = array('5826a4c89f5160d1048b52bf');
  666. $total = 0;
  667. foreach($delOrder as $value){
  668. $order = ROrder::model()->get(new MongoId($value));
  669. if($order->delete()){
  670. $total += 1;
  671. }
  672. }
  673. echo $total;
  674. }*/
  675. //取消订单
  676. public function DelOrder($orderId){
  677. $data['key'] = Yii::app()->params['shKey'];
  678. $data['version'] = '1.0';
  679. $data['serviceType'] = (int)26;
  680. $data['orderId'] = $orderId;//'57fde8059f5160c4048b4aeb';
  681. ksort($data);
  682. $str = '';
  683. $dat = '';
  684. foreach ($data as $key => $value) {
  685. $str .= $key.'='.$value.'&';
  686. $dat .= $key.'='.urlencode($value).'&';
  687. }
  688. $str = rtrim(trim($str),'&');
  689. $str .= $str.Yii::app()->params['shMd5Key'];
  690. $data['sign'] = strtoupper(md5($str));
  691. $dat .= 'sign='.urlencode($data['sign']);//构建post 参数
  692. $url = 'http://test2.app.hiwemeet.com/v2/openpf/home/order/thirdOrder/cancel'; //调用接口的平台服务地址
  693. $ch = curl_init();
  694. curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
  695. curl_setopt($ch, CURLOPT_URL, $url);
  696. curl_setopt($ch, CURLOPT_POST, 1);
  697. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  698. curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
  699. $result = curl_exec($ch);
  700. curl_close($ch);
  701. $res = json_decode($result,true);
  702. var_dump($res);
  703. if ($res['code']){
  704. return true;
  705. } else {
  706. return false;
  707. }
  708. }
  709. //更新订单状态
  710. public function UpdateStatus($orderId,$status){
  711. $data['key'] = Yii::app()->params['shKey'];
  712. $data['version'] = '1.0';
  713. $data['serviceType'] = (int)26;
  714. $data['orderId'] = (string)$orderId;
  715. $data['status'] = $status;
  716. ksort($data);
  717. $str = '';
  718. $dat = '';
  719. foreach ($data as $key => $value) {
  720. $str .= $key.'='.$value.'&';
  721. $dat .= $key.'='.urlencode($value).'&';
  722. }
  723. $str = rtrim(trim($str),'&');
  724. $str .= $str.Yii::app()->params['shMd5Key'];
  725. $data['sign'] = strtoupper(md5($str));
  726. $dat .= 'sign='.urlencode($data['sign']);//构建post 参数
  727. $url = 'http://test2.app.hiwemeet.com/v2/openpf/home/order/thirdOrder/update'; //调用接口的平台服务地址
  728. $ch = curl_init();
  729. curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
  730. curl_setopt($ch, CURLOPT_URL, $url);
  731. curl_setopt($ch, CURLOPT_POST, 1);
  732. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  733. curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
  734. $result = curl_exec($ch);
  735. curl_close($ch);
  736. $res = json_decode($result,true);
  737. if ($res['code']){
  738. return true;
  739. } else {
  740. return false;
  741. }
  742. }
  743. //更新订单状态
  744. /**
  745. * @param $orderId => order->orderNo
  746. * @param $status "00" 为创建订单,"01"为服务派单,"02"为服务完成
  747. * @param $HouseKeepingId 巾帼园自己的订单号 对应order->_id
  748. * @param $remark 订单备注
  749. * @return bool
  750. */
  751. public function UpdateStatusForJingBai($orderId,$status,$HouseKeepingId,$remark){
  752. $data['key'] = Yii::app()->params['shKey'];
  753. $data['version'] = '1.0';
  754. $data['serviceType'] = (int)26;
  755. $data['orderId'] = (string)$orderId;
  756. $data['status'] = $status;
  757. ksort($data);
  758. $str = '';
  759. $dat = '';
  760. foreach ($data as $key => $value) {
  761. $str .= $key.'='.$value.'&';
  762. $dat .= $key.'='.urlencode($value).'&';
  763. }
  764. $str = rtrim(trim($str),'&');
  765. $str .= $str.Yii::app()->params['shMd5Key'];
  766. $data['sign'] = strtoupper(md5($str));
  767. $dat .= 'sign='.urlencode($data['sign']);//构建post 参数
  768. $url = 'http://test2.app.hiwemeet.com/v2/openpf/home/order/thirdOrder/update'; //调用接口的平台服务地址
  769. $ch = curl_init();
  770. curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
  771. curl_setopt($ch, CURLOPT_URL, $url);
  772. curl_setopt($ch, CURLOPT_POST, 1);
  773. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  774. curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
  775. $result = curl_exec($ch);
  776. curl_close($ch);
  777. $res = json_decode($result,true);
  778. if ($res['code']){
  779. return true;
  780. } else {
  781. return false;
  782. }
  783. }
  784. public function actionOutputExcel(){
  785. $data = ROrder::model()->findAll(); //
  786. $rows = CommonFn::getRowsFromCursor($data);
  787. $data = ROrder::model()->parse($rows);
  788. $name='OrderList'; //生成的Excel文件文件名
  789. $res=Service::factory('ExcelToArrayService')->push($data,$name);
  790. echo "导出成功";
  791. }
  792. }