ROrderController.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  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. $flag = 0;
  192. //精佰退单接口 状态为申请退款并且是精佰的订单
  193. if ($order->status == -3 && $order->channel == 'jingbai') {
  194. //确认申请退款状态变更成已退款订单 为退单订单
  195. $criteria = new EMongoCriteria();
  196. $criteria->OrderNo('==',$order->OrderNo);
  197. $orders = ROrder::model()->findAll($criteria);
  198. $orderId = '';
  199. $fin_price = 0;
  200. foreach ($orders as $value) {
  201. $orderId .= $value->_id.',';
  202. $fin_price += $order->final_price*0.5;
  203. }
  204. $orderId = rtrim(trim($orderId),',');
  205. if ($status == -2){
  206. if ($remark == '1'){
  207. //已出发 已上门 订单
  208. $res = self::feedbackOrder(1,$order->OrderNo,$orderId,number_format($fin_price,2));
  209. } else {
  210. $res = self::feedbackOrder(1,$order->OrderNo,$orderId,0);
  211. }
  212. $flag = 1;
  213. } else if($status == 2 &&$order->booking_time != $booking_time){
  214. //2 确认申请退款状态变更成已处理 为修改订单 此时修改订单预约时间
  215. $res = self::feedbackOrder(0,$order->OrderNo,$orderId,0,$order->booking_time);
  216. $flag = 1;
  217. } else if($status == 2 &&$order->booking_time == $booking_time){//不退单 没有修改
  218. $res = self::feedbackOrder(0,$order->OrderNo,$orderId,0);
  219. $flag = 1;
  220. }
  221. var_dump($res);exit;
  222. if ($flag && $res){
  223. foreach ($orders as $value) {
  224. $value->status = $status;
  225. }
  226. }
  227. }
  228. if(($order->status!=-1||$order->status!=-2)&&($status==-1||$status==-2)){
  229. foreach ($order->coupons as $user_coupon) {
  230. $user_coupon = UserCoupon::get($user_coupon);
  231. $user_coupon->status = 1;
  232. $user_coupon->update(array('status'),true);
  233. }
  234. }
  235. if($order->status!=-2 && $status == -2) {
  236. $order->refund_time = time();
  237. $order_info = $order->parseRow($order);
  238. $month = date('m', $order_info['booking_time']);
  239. $day = date('d', $order_info['booking_time']);
  240. $address = $order_info['address']['poi']['name'] . $order_info['address']['detail'];
  241. CommonSMS::send('order_retrieve', array('month' => $month, 'day' => $day, 'address' => $address, 'mobile' => $order_info['address']['mobile']));
  242. // 申请退款处理完成后通知保洁师
  243. foreach ($technician_ids as $key => $technician_id) {
  244. $technician_obj = TechInfo::get($technician_id);
  245. if ($technician_obj && $technician_obj->weixin_userid) {
  246. $url_prefix = ENVIRONMENT == 'product' ? 'http://api.yiguanjia.me' : 'http://apitest.yiguanjia.me';
  247. $wechat = O2oApp::getWechatActive();
  248. $wechat_data = array(
  249. 'touser' => $technician_obj->weixin_userid,
  250. 'msgtype' => 'news',
  251. 'agentid' => '1',
  252. 'news' => array(
  253. 'articles' => array(
  254. array(
  255. 'title' => '壹管家提示-订单退款完成',
  256. 'description' => $technician_obj->name . '你好!用户于' . date('m月d日H:i', $order->apply_refund_time) . '申请退款的订单已处理完成。',
  257. //'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_id,
  258. 'url' => $url_prefix . '/index.php?r=o2o/myOrder/index'
  259. ),
  260. ),
  261. ),
  262. );
  263. if (!empty($order->append_orders)) {
  264. $count = count($order->append_orders);
  265. $wechat_data['news']['articles'][0]['description'] .= "\n\n本订单包含" . $count . "个追加订单,请注意查看。";
  266. }
  267. $wechat->sendMessage($wechat_data);
  268. }
  269. }
  270. }
  271. //取消订单
  272. if($order->status!=-1 && $status == -1){
  273. // 已完成订单不能取消
  274. if ($order->status == 6) {
  275. CommonFn::requestAjax(false, '已完成订单不可取消');
  276. }
  277. $order->cancel_time = time();
  278. $order_info = $order->parseRow($order);
  279. }
  280. //确认接单
  281. if($order->status!=3 && $status == 3){
  282. $order_info = $order->parseRow($order);
  283. }
  284. //订单完成后执行
  285. if($order->status!=6 && $status == 6 ){
  286. $order->finish_time = time();
  287. $order_info = $order->parseRow($order);
  288. /*$result = Service::factory('ScoreService')->changeScore((string)$order->user,intval($order->final_price),'下单奖爪币');
  289. if($result){
  290. $z_message = new ZMessage();
  291. $from_user = Yii::app()->params['sys_user'];
  292. $message_data = array(
  293. 'from_user' => $from_user,
  294. 'to_user' => (string)$order->user,
  295. 'content' => '您成功下单,获得了'.intval($order->final_price).'个爪币的奖励。',
  296. 'pics' => array(),
  297. 'voice' => array(),
  298. 'video'=> array()
  299. );
  300. $z_message->addMessage($message_data);
  301. CommonSMS::send('final_order',array('name' =>$order_info['address']['name'],'num' =>intval($order->final_price),'mobile'=>$order_info['address']['mobile']));
  302. }*/
  303. // 保洁师订单统计处理
  304. foreach($technician_ids as $key => $technician_id) {
  305. $technician_obj = TechInfo::get($technician_id);
  306. if ($technician_obj) {
  307. $tech_order_count = $technician_obj->order_count + 1;
  308. $technician_obj->order_count = $tech_order_count;
  309. $technician_obj->save();
  310. }
  311. }
  312. }
  313. $order->status = $status;
  314. $order->booking_time = $booking_time;
  315. $order->deal_time = $deal_time;
  316. $order->remark = $remark;
  317. $order->counts = $counts;
  318. //$order->station = new MongoId($station);
  319. // 是否通知保洁师
  320. $toTech = !empty($order->technicians)? true : false;
  321. //$order->technician = $technician_id;
  322. //$order->technician_name = $technician_name;
  323. $order->technicians = $technicians;
  324. //var_dump($order);exit;
  325. //判断是否为实惠或金百订单
  326. if($order->channel == 'shihui'){
  327. if ($status == 1) {//已支付
  328. $res = self::UpdateStatus((string)$order->_id, 5);
  329. $flag = 1;
  330. } else if($status ==3){//已接单
  331. $res = self::UpdateStatus((string)$order->_id, 15);
  332. $flag = 1;
  333. }else if($status ==6){//服务完成
  334. $res = self::UpdateStatus((string)$order->_id, 20);
  335. $flag = 1;
  336. }else if($status ==-1){//取消订单
  337. $res = self::DelOrder((string)$order->_id);
  338. $flag = 1;
  339. }
  340. }else if($order->channel == 'jingbai'){
  341. if($status ==3){//已接单
  342. $res = self::UpdateStatusForJingBai($order->OrderNo,(string)$order->_id, $status,$order->remark);
  343. $flag = 1;
  344. }else if($status ==6){//服务完成
  345. $res = self::UpdateStatusForJingBai($order->OrderNo,(string)$order->_id, $status,$order->remark);
  346. $flag = 1;
  347. }
  348. }
  349. if($flag){
  350. if (!$res) {
  351. CommonFn::requestAjax(false,'修改失败');
  352. }
  353. }
  354. $arr_order = array('cancel_time','refund_time','finish_time','status','booking_time','deal_time','remark', 'station', 'technicians');
  355. $success = $order->save(true,$arr_order);
  356. $char = false;
  357. // 通知保洁师
  358. if (in_array($status, array(1,2,3,4,5)) && $toTech && $success) {
  359. foreach($technician_ids as $key => $technician_id) {
  360. $technician_obj = TechInfo::get($technician_id);
  361. if ($technician_obj && $technician_obj->weixin_userid) {
  362. $url_prefix = ENVIRONMENT == 'product' ? 'http://api.yiguanjia.me' : 'http://apitest.yiguanjia.me';
  363. $wechat = O2oApp::getWechatActive();
  364. $wechat_data = array(
  365. 'touser' => $technician_obj->weixin_userid,
  366. 'msgtype' => 'news',
  367. 'agentid' => 1,
  368. 'news' => array(
  369. 'articles' => array(
  370. array(
  371. 'title' => '壹管家提示-新订单',
  372. 'description' => $technician_obj->name . '你好!刚刚有一个新的订单被分配给你,请点击查看。',
  373. //'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_id,
  374. 'url' => $url_prefix . '/index.php?r=o2o/myOrder/index'
  375. ),
  376. ),
  377. ),
  378. );
  379. $char = $wechat->sendMessage($wechat_data);
  380. }
  381. }
  382. }
  383. CommonFn::requestAjax($success, '微信'.$char, array());
  384. }
  385. // 根据手机号 获取对应用户的地址信息
  386. public function actionGetUserInfo(){
  387. $mobile = Yii::app()->request->getParam('mobile', '');
  388. $length = strlen($mobile);
  389. if ($length < 11) {
  390. $result[] = array(
  391. 'id' => 0,
  392. 'data' => '',
  393. 'description' => '请继续输入',
  394. 'content' => array()
  395. );
  396. echo json_encode($result);exit;
  397. }
  398. // $mobile_regex = new MongoRegex($mobile);
  399. $criteria = new EMongoCriteria();
  400. $criteria->sort('order_time', EMongoCriteria::SORT_DESC);
  401. $criteria->addCond('address.mobile', '==', $mobile);
  402. $cursor = ROrder::model()->findAll($criteria);
  403. $rows = CommonFn::getRowsFromCursor($cursor);
  404. if (empty($rows)) {
  405. $result[] = array(
  406. 'id' => 0,
  407. 'data' => '',
  408. 'description' => '没有匹配信息',
  409. 'content' => array()
  410. );
  411. echo json_encode($result);exit;
  412. }
  413. $result = array();
  414. $details = array();
  415. $index = 0;
  416. foreach($rows as $row){
  417. // 加入根据detail筛选,避免产生重复信息
  418. if (in_array($row['address']['detail'], $details)) continue;
  419. $details[] = $row['address']['detail'];
  420. $pio = isset($row['address']['poi']['name'])?$row['address']['poi']['name']:'';
  421. // 坐标获取(根据不同的来源)
  422. if ($row['channel'] == 'dianping') {
  423. $latitude = $row['address']['position']['lat'];
  424. $longitude = $row['address']['position']['lng'];
  425. } else {
  426. $latitude = isset($row['address']['position']['1'])?$row['address']['position']['1']:'';
  427. $longitude = isset($row['address']['position']['0'])?$row['address']['position']['0']:'';
  428. }
  429. // poi获取
  430. $poi_name = isset($row['address']['poi']['name']) ? $row['address']['poi']['name'] : '';
  431. $poi_uid = isset($row['address']['poi']['uid']) ? $row['address']['poi']['uid'] : '';
  432. $result[] = array(
  433. 'id' => $index,
  434. 'data' => $row['address']['mobile'],
  435. 'description' => $row['address']['province'].' '.$row['address']['city'].' '.$row['address']['area'].' '.$pio.$row['address']['detail'],
  436. 'content' => array(
  437. 'name' => $row['address']['name'],
  438. 'latitude' => $latitude,
  439. 'longitude' => $longitude,
  440. 'province' => $row['address']['province'],
  441. 'city' => $row['address']['city'],
  442. 'area' => $row['address']['area'],
  443. 'detail' => $row['address']['detail'],
  444. 'poi_name' => $poi_name,
  445. 'poi_uid' => $poi_uid,
  446. 'memo' => $row['memo']
  447. )
  448. );
  449. $index++;
  450. }
  451. echo json_encode($result);exit;
  452. }
  453. public function actionAdd () {
  454. // ------ 必须传入的数值 ------
  455. // --------- 订单信息 ---------
  456. $channel = Yii::app()->request->getParam('channel', '');
  457. $booking_time = Yii::app()->request->getParam('booking_time_add', '');
  458. $order_time = Yii::app()->request->getParam('order_time_add', '');
  459. $main_products = Yii::app()->request->getParam('main_products', '');
  460. $price = floatval(Yii::app()->request->getParam('price', 0));
  461. $final_price = floatval(Yii::app()->request->getParam('final_price', 0));
  462. $status = Yii::app()->request->getParam('status', -3);
  463. $station = Yii::app()->request->getParam('station', '57db39709f5160bb048b456a');
  464. // --------- 地址信息 ---------
  465. $mobile = Yii::app()->request->getParam('mobile', 0);
  466. $latitude = Yii::app()->request->getParam('latitude', 0);
  467. $longitude = Yii::app()->request->getParam('longitude', 0);
  468. $province = Yii::app()->request->getParam('province', '');
  469. $city = Yii::app()->request->getParam('city', '');
  470. $area = Yii::app()->request->getParam('area', '');
  471. $poi_name = Yii::app()->request->getParam('poi_name', '');
  472. $detail = Yii::app()->request->getParam('detail', '');
  473. $counts = intval(Yii::app()->request->getParam('counts', 1));
  474. $counts = $counts?$counts:1;
  475. $extra = Yii::app()->request->getParam('extra','[]');
  476. $extra = json_decode($extra);
  477. // 数据完整性检查
  478. // 2015-11-02 因存在赠送订单,删除金额的数据检查 : $price == 0 || $final_price == 0 ||
  479. // 2015-11-16 取消服务点录入,删除服务点数据检查 : || empty($station)
  480. $flag = empty($channel) || empty($booking_time) || empty($order_time);
  481. $flag = $flag || $status == -3;
  482. $flag = $flag || $mobile == 0 || $latitude == 0 || $longitude == 0;
  483. $flag = $flag || empty($province) || empty($city) || empty($area) || empty($poi_name) || empty($detail);
  484. if ($flag) {
  485. CommonFn::requestAjax(false, '请检查数据完整性', array());
  486. exit;
  487. }
  488. //if($channel == 'wz_app' || $channel == 'wx_pub'){
  489. //CommonFn::requestAjax(false, '不能录入渠道为壹管家微信||壹管家APP的订单', array());
  490. //exit;
  491. //}
  492. // 时间处理
  493. $booking_time = strtotime($booking_time);
  494. $order_time = strtotime($order_time);
  495. // ------ 可以留空的数值 ------
  496. $box = Yii::app()->request->getParam('box', array());
  497. $coupons = Yii::app()->request->getParam('coupons', array());
  498. $memo = Yii::app()->request->getParam('memo', '');
  499. $remark = Yii::app()->request->getParam('remark', '');
  500. $precedence = Yii::app()->request->getParam('precedence', 0);
  501. $have_comment = Yii::app()->request->getParam('have_comment', 0);
  502. $name = Yii::app()->request->getParam('name', '');
  503. $type = Yii::app()->request->getParam('type', 0);
  504. $user = Yii::app()->request->getParam('user', '');
  505. $poi_uid = Yii::app()->request->getParam('poi_uid', '');
  506. // 用户名的判断
  507. $channel_option = ROrder::$channel_option;
  508. $name = empty($name) ? $channel_option[$channel]['name'].'用户' : $name;
  509. // 支付渠道
  510. $pay_channel = $channel;
  511. // 服务数据整合
  512. $products[] = array(
  513. 'product' => new MongoId($main_products),
  514. 'count' => 1,
  515. 'extra' =>$extra
  516. );
  517. if (!empty($box)) {
  518. foreach ($box as $key => $value) {
  519. $products[] = array(
  520. 'product' => new MongoId($value),
  521. 'count' => 1,
  522. 'extra' =>$extra
  523. );
  524. }
  525. }
  526. // 地址数据整合
  527. $address = array(
  528. 'province' => $province,
  529. 'city' => $city,
  530. 'area' => $area,
  531. 'detail' => $detail,
  532. 'mobile' => $mobile,
  533. 'position' => array(
  534. // 'lat' => (float)$latitude,
  535. // 'lng' => (float)$longitude,
  536. 0 => (float)$longitude,
  537. 1 => (float)$latitude
  538. ),
  539. 'poi' => array(
  540. 'name' => $poi_name,
  541. 'uid' => $poi_uid
  542. ),
  543. 'name' => $name
  544. );
  545. // 订单类型判断
  546. if ($type == 0) {
  547. $criteria = new EMongoCriteria();
  548. $criteria->_id = new MongoId($main_products);
  549. $cursor = Product::model()->find($criteria);
  550. $type = $cursor->type;
  551. }
  552. $rOrder = new ROrder();
  553. $rOrder->channel = $channel;
  554. $rOrder->booking_time = intval($booking_time);
  555. $rOrder->order_time = intval($order_time);
  556. $rOrder->products = $products;
  557. $rOrder->price = floatval($price);
  558. $rOrder->final_price = floatval($final_price);
  559. $rOrder->precedence = intval($precedence);
  560. $rOrder->counts = $counts;
  561. $rOrder->coupons = $coupons;
  562. $rOrder->user = $user;
  563. $rOrder->status = intval($status);
  564. $rOrder->memo = $memo;
  565. $rOrder->remark = $remark;
  566. $rOrder->type = strval($type); // 数据库内使用string类型
  567. $rOrder->have_comment = intval($have_comment);
  568. $rOrder->station = new MongoId($station);
  569. $rOrder->address = $address;
  570. $rOrder->pay_channel = $pay_channel;
  571. $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');
  572. $success = $rOrder->save(true, $addROrder_arr);
  573. CommonFn::requestAjax($success, '', array());
  574. }
  575. /**
  576. * 请求申请退款订单接口
  577. */
  578. public function actionCheckRefundOrder() {
  579. $criteria = new EMongoCriteria();
  580. $criteria->status('==', -3);
  581. $cursor = ROrder::model()->findAll($criteria);
  582. $count = $cursor->count();
  583. if ($count > 0) {
  584. $data = array('code' => 1, 'count' => $count);
  585. } else {
  586. $data = array('code' => 0, 'count' => $count);
  587. }
  588. $list = new ARedisList('append_order_list');
  589. if($list->getCount() > 0){
  590. $key = $list->shift();
  591. $list->unshift($key);
  592. $data['procession_append_order_id'] = $key;
  593. $data['code'] = 2;
  594. }
  595. echo json_encode($data);
  596. }
  597. public function actionCancelProcess() {
  598. $orderid = Yii::app()->request->getParam('orderid','');
  599. $list = new ARedisList('append_order_list');
  600. $key = $list->shift();
  601. }
  602. /**
  603. * 重新选择保洁师接口
  604. */
  605. public function actionResetTech() {
  606. $id = Yii::app()->request->getParam('id', '');
  607. $nums = Yii::app()->request->getParam('nums', '');
  608. $technicians = array();
  609. $technician_ids = array();
  610. $technician_names = array();
  611. for($i=1;$i<=$nums;$i++) {
  612. if(Yii::app()->request->getParam('reset_extra_add_info_'.$i)) {
  613. $technician_ids[] = Yii::app()->request->getParam('reset_extra_add_info_id_'.$i);
  614. $technician_names[] = Yii::app()->request->getParam('reset_extra_add_info_'.$i);
  615. }
  616. }
  617. // 保洁师信息检查
  618. // 根据ID直接查询保洁师信息(优先使用联想功能)
  619. $technician_objs = array();
  620. foreach($technician_ids as $key => $technician_id) {
  621. if ($technician_id != 0) {
  622. $technician_obj = TechInfo::get($technician_id);
  623. if ($technician_obj) {
  624. $technicians[$key]['technician_id'] = $technician_obj->_id;
  625. $technicians[$key]['technician_name'] = $technician_obj->name;
  626. } else {
  627. CommonFn::requestAjax(false, '保洁师不存在');
  628. }
  629. // ID为0时根据输入框信息查询
  630. } else {
  631. foreach ($technician_names as $key => $technician_name)
  632. if ($technician_name != '') {
  633. $criteria = new EMongoCriteria();
  634. $criteria->name = $technician_name;
  635. $technician_obj = TechInfo::model()->find($criteria);
  636. if ($technician_obj) {
  637. $technicians[$key]['technician_id'] = $technician_obj->_id;
  638. $technicians[$key]['technician_name'] = $technician_obj->name;
  639. } else {
  640. CommonFn::requestAjax(false, '保洁师不存在');
  641. }
  642. } else {
  643. CommonFn::requestAjax(false, '保洁师姓名不能为空');
  644. }
  645. }
  646. $technician_objs[] = $technician_obj;
  647. }
  648. $orderid = new MongoId($id);
  649. $order = ROrder::model()->get($orderid);
  650. $toTech = isset($order->technicians) ? true : false;
  651. $fromTechs = $technician_names;
  652. //$order->technician = $technician_id;
  653. //$order->technician_name = $technician_name;
  654. $order->technicians = $technicians;
  655. $success = $order->save(true, array('technicians'));
  656. if ($toTech && $success) {
  657. foreach ($technician_objs as $technician_obj) {
  658. // 发送给被分配保洁师
  659. $wechat = O2oApp::getWechatActive();
  660. $url_prefix = ENVIRONMENT == 'product' ? 'http://api.yiguanjia.me' : 'http://apitest.yiguanjia.me';
  661. if (!empty($technician_obj->weixin_userid)) {
  662. $wechat_data = array(
  663. 'touser' => $technician_obj->weixin_userid,
  664. 'msgtype' => 'news',
  665. 'agentid' => '1',
  666. 'news' => array(
  667. 'articles' => array(
  668. array(
  669. 'title' => '壹管家提示-新订单',
  670. 'description' => $technician_obj->name . '你好!刚刚有一个新的订单被分配给你,请点击查看。',
  671. //'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_obj->_id,
  672. 'url' => $url_prefix . '/index.php?r=o2o/myOrder/index'
  673. ),
  674. ),
  675. ),
  676. );
  677. $wechat->sendMessage($wechat_data);
  678. }
  679. }
  680. // 发送给原保洁师
  681. foreach ($fromTechs as $fromTech) {
  682. $fromTechObj = TechInfo::get($fromTech);
  683. if (!empty($fromTechObj) && !empty($fromTechObj->weixin_userid)) {
  684. $wechat_data = array(
  685. 'touser' => $fromTechObj->weixin_userid,
  686. 'msgtype' => 'news',
  687. 'agentid' => '1',
  688. 'news' => array(
  689. 'articles' => array(
  690. array(
  691. 'title' => '壹管家提示-订单已被重新分配',
  692. 'description' => $fromTechObj->name . '你好!预定时间在' . date('m月d日H:i', $order->booking_time) . '的订单已被分配给其他保洁师。',
  693. 'url' => $url_prefix . '/index.php?r=o2o/myOrder/info&order=' . $id . '&user=' . $technician_obj->_id,
  694. ),
  695. ),
  696. ),
  697. );
  698. $wechat->sendMessage($wechat_data);
  699. }
  700. }
  701. }
  702. CommonFn::requestAjax($success, '', array());
  703. }
  704. /*public function actionDelOrder(){
  705. $delOrder = array('5826a4c89f5160d1048b52bf');
  706. $total = 0;
  707. foreach($delOrder as $value){
  708. $order = ROrder::model()->get(new MongoId($value));
  709. if($order->delete()){
  710. $total += 1;
  711. }
  712. }
  713. echo $total;
  714. }*/
  715. //取消订单
  716. public function DelOrder($orderId){
  717. $data['key'] = Yii::app()->params['shKey'];
  718. $data['version'] = '1.0';
  719. $data['serviceType'] = (int)26;
  720. $data['orderId'] = $orderId;//'57fde8059f5160c4048b4aeb';
  721. ksort($data);
  722. $str = '';
  723. $dat = '';
  724. foreach ($data as $key => $value) {
  725. $str .= $key.'='.$value.'&';
  726. $dat .= $key.'='.urlencode($value).'&';
  727. }
  728. $str = rtrim(trim($str),'&');
  729. $str .= $str.Yii::app()->params['shMd5Key'];
  730. $data['sign'] = strtoupper(md5($str));
  731. $dat .= 'sign='.urlencode($data['sign']);//构建post 参数
  732. $url = 'http://test2.app.hiwemeet.com/v2/openpf/home/order/thirdOrder/cancel'; //调用接口的平台服务地址
  733. $ch = curl_init();
  734. curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
  735. curl_setopt($ch, CURLOPT_URL, $url);
  736. curl_setopt($ch, CURLOPT_POST, 1);
  737. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  738. curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
  739. $result = curl_exec($ch);
  740. curl_close($ch);
  741. $res = json_decode($result,true);
  742. var_dump($res);
  743. if ($res['code']){
  744. return true;
  745. } else {
  746. return false;
  747. }
  748. }
  749. //更新订单状态
  750. public function UpdateStatus($orderId,$status){
  751. $data['key'] = Yii::app()->params['shKey'];
  752. $data['version'] = '1.0';
  753. $data['serviceType'] = (int)26;
  754. $data['orderId'] = (string)$orderId;
  755. $data['status'] = $status;
  756. ksort($data);
  757. $str = '';
  758. $dat = '';
  759. foreach ($data as $key => $value) {
  760. $str .= $key.'='.$value.'&';
  761. $dat .= $key.'='.urlencode($value).'&';
  762. }
  763. $str = rtrim(trim($str),'&');
  764. $str .= $str.Yii::app()->params['shMd5Key'];
  765. $data['sign'] = strtoupper(md5($str));
  766. $dat .= 'sign='.urlencode($data['sign']);//构建post 参数
  767. $url = 'http://test2.app.hiwemeet.com/v2/openpf/home/order/thirdOrder/update'; //调用接口的平台服务地址
  768. $ch = curl_init();
  769. curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
  770. curl_setopt($ch, CURLOPT_URL, $url);
  771. curl_setopt($ch, CURLOPT_POST, 1);
  772. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  773. curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
  774. $result = curl_exec($ch);
  775. curl_close($ch);
  776. $res = json_decode($result,true);
  777. if ($res['code']){
  778. return true;
  779. } else {
  780. return false;
  781. }
  782. }
  783. //更新订单状态
  784. /**
  785. * @param $orderId => order->orderNo
  786. * @param $status "00" 为创建订单,"01"为服务派单,"02"为服务完成
  787. * @param $HouseKeepingId 巾帼园自己的订单号 对应order->_id
  788. * @param $remark 订单备注
  789. * Sign 计算方法:OrderId+ StatusCode+ Remark+ HouseKeepingId+ Time+KEY 然后计算md5 值 KEY为巾帼园的key值
  790. * @return bool
  791. */
  792. public function UpdateStatusForJingBai($orderId,$HouseKeepingId,$status,$remark){
  793. $key = Yii::app()->params['JingBai'];
  794. $data['OrderId'] = $orderId;
  795. $data['HouseKeepingId'] = $HouseKeepingId;
  796. $data['Remark'] = $remark;
  797. if ($status == 3){//已接单
  798. $data['StatusCode'] = '01';
  799. } else if($status == 6){//已完成
  800. $data['StatusCode'] = '02';
  801. }
  802. $data['Time'] = date('Y-m-d H:i:s');
  803. $data['Sign'] = md5($data['OrderId'].$data['StatusCode'].$data['Remark'].$data['HouseKeepingId'].$data['Time'].$key);
  804. $dat = '';
  805. foreach ($data as $key => $value) {
  806. $dat .= $key.'='.urlencode($value).'&';
  807. }
  808. $dat = rtrim(trim($dat),'&');
  809. $url = 'http://139.196.47.211:9030/ServiceController/SetHouseKeepingStatus'; //调用接口的平台服务地址
  810. $ch = curl_init();
  811. curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
  812. curl_setopt($ch, CURLOPT_URL, $url);
  813. curl_setopt($ch, CURLOPT_POST, 1);
  814. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  815. curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
  816. $result = curl_exec($ch);
  817. curl_close($ch);
  818. $res = json_decode($result,true);
  819. if ($res['ReturnCode'] == '00'){
  820. return true;
  821. } else {
  822. return false;
  823. }
  824. }
  825. //退单反馈信息接口
  826. /**
  827. * @param $isCanel 是否退单 1退单 0 不退单
  828. * @param $orderId 精佰订单Id 对应 巾帼园 OrderNo
  829. * @param $orderNo 巾帼园订单id 对应 巾帼园_id
  830. * @param $money 若退单巾帼园需要收多少钱,单位为分,不退单可不传
  831. * @param null $remark 退单状态备注包含修改信息,无修改此字段可不传
  832. * @return bool
  833. */
  834. public function feedbackOrder($isCancel,$orderId,$orderNo,$money=0,$remark=null)
  835. {
  836. $key = Yii::app()->params['JingBai'];
  837. $data['IsCancel'] = $isCancel;
  838. $data['OrderId'] = $orderId;
  839. $data['OrderNo'] = $orderNo;
  840. //不退单, 但是需要修改信息
  841. if(!$isCancel && !empty($remark)){
  842. $data['Type'] = 'OrderRemark';
  843. $data['Remark'] = '修改预约时间'.date('Y-m-d H:i:s',$remark);
  844. $data['Sign'] = md5($orderId.$orderNo.$data['Remark'].$key);
  845. }else if(!$isCancel && empty($remark)){//不退单 没有修改信息
  846. $data['Type'] = 'CancleOrder';
  847. $data['Money'] = $money;
  848. $data['Sign'] = md5($isCancel.$orderId.$orderNo.$money.$key);
  849. }
  850. else {
  851. $data['Type'] = 'CancleOrder';
  852. $data['Money'] = $money;
  853. $data['Sign'] = md5($isCancel.$orderId.$orderNo.$money.$key);
  854. }
  855. $dat = '';
  856. foreach ($data as $key => $value) {
  857. $dat .= $key.'='.urlencode($value).'&';
  858. }
  859. var_dump($data);
  860. $dat = rtrim(trim($dat),'&');
  861. //$url = 'http://139.196.47.211:9030/ServiceController/ HouseKeepingFeedback'; //调用接口的平台服务地址
  862. $url = 'http://123.206.28.63:9030/ServiceController/HouseKeepingFeedback'; //调用接口的平台服务地址
  863. $ch = curl_init();
  864. curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
  865. curl_setopt($ch, CURLOPT_URL, $url);
  866. curl_setopt($ch, CURLOPT_POST, 1);
  867. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  868. curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
  869. $result = curl_exec($ch);
  870. curl_close($ch);
  871. $res = json_decode($result,true);
  872. var_dump($res['ReturnCode']);
  873. if ($res['ReturnCode'] == '00'){
  874. return true;
  875. } else {
  876. return false;
  877. }
  878. }
  879. public function actionOutputExcel(){
  880. $data = ROrder::model()->findAll(); //
  881. $rows = CommonFn::getRowsFromCursor($data);
  882. $data = ROrder::model()->parse($rows);
  883. $name='OrderList'; //生成的Excel文件文件名
  884. $res=Service::factory('ExcelToArrayService')->push($data,$name);
  885. echo "导出成功";
  886. }
  887. }