OrderController.php 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  1. <?php
  2. /**
  3. * OrderController o2o下单相关接口
  4. */
  5. class OrderController extends O2oBaseController{
  6. public function actionAdd(){
  7. $user_id = Yii::app()->getRequest()->getParam("user_id");
  8. $products = json_decode(Yii::app()->getRequest()->getParam("products","[]"),true);
  9. $memo = Yii::app()->getRequest()->getParam("memo","");
  10. $booking_time = Yii::app()->getRequest()->getParam("booking_time",'');
  11. $precedence = intval(Yii::app()->getRequest()->getParam("precedence",0));
  12. $coupons = json_decode(Yii::app()->getRequest()->getParam("coupons","[]"),true);
  13. $address_id = Yii::app()->getRequest()->getParam("address_id");
  14. $tech_id = Yii::app()->getRequest()->getParam("tech_id");
  15. $station = Yii::app()->getRequest()->getParam("station");
  16. $order_channel = Yii::app()->getRequest()->getParam("order_channel");
  17. $counts = Yii::app()->request->getParam('counts', 1);
  18. $extra = json_decode(Yii::app()->getRequest()->getParam("extra","[]"),true);
  19. $balance = floatval(Yii::app()->getRequest()->getParam("balance",0));//余额支付的金额
  20. //CommonFn::requestAjax(false,'系统升级中,暂时不能下单');
  21. if(!$precedence){
  22. $booking_check = strtotime($booking_time);
  23. $verity_check = $booking_check - time();
  24. //if($verity_check < 13800){
  25. //CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  26. //}
  27. }
  28. //活动暂用 start 判断用户是否购买过 test //583247cca84ea01d428b46a1 master// 58324b7e9f5160a4048b5758
  29. $doubleEleventId = '58324b7e9f5160a4048b5758';
  30. //$flag_book = 0;
  31. /*
  32. if($products[0]['product_id'] == $doubleEleventId) {
  33. $criteria_user = new EMongoCriteria();
  34. $criteria_user->user('==', new MongoId($user_id));
  35. $criteria_user->addCond('products.product', '==', new MongoId($doubleEleventId));//双十一产品id
  36. //$criteria_user->addCond('status','==',1);
  37. $order = ROrder::model()->findAll($criteria_user);
  38. $o = CommonFn::getRowsFromCursor($order);
  39. foreach ($o as $value) {
  40. if ($value['status'] == 0 || $value['status'] == -1) {
  41. $t = ROrder::model()->get(new MongoId($value['_id']));
  42. $t->delete();
  43. } else {
  44. CommonFn::requestAjax(false, '对不起,日常保洁两小时体验只能购买一单,你已经抢购过');
  45. }
  46. }
  47. /* //取出双十一活动暂用
  48. $criteria_time = new EMongoCriteria();
  49. $criteria_time->addCond('products.product', '==', new MongoId($doubleEleventId));
  50. $cursor_time = ROrder::model()->findAll($criteria_time);
  51. $rows = array();
  52. if(!empty($cursor_time)) {
  53. $rows = CommonFn::getRowsFromCursor($cursor_time);
  54. }
  55. $y = date("Y");
  56. $m = date("m");
  57. $d = date("d");
  58. $day_start = mktime(0, 0, 0, $m, $d, $y);
  59. $day_end = mktime(23, 59, 59, $m, $d, $y);
  60. $total = 0;
  61. if ($rows) {
  62. foreach ($rows as $orders) {
  63. //判断订单是否达到111单
  64. if ($total >= 111) {
  65. CommonFn::requestAjax(false, '今天的双11订单已经抢购光了');
  66. }
  67. //判断是否是当天订单
  68. if ($orders['order_time'] >= $day_start && $orders['order_time'] <= $day_end) {
  69. $total += 1;
  70. }
  71. }
  72. }
  73. //$flag_book = 1;
  74. }
  75. */
  76. //end //取出双十一活动暂用
  77. if(!$user_id||!$products||!$address_id){
  78. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  79. }
  80. $user_obj = CommonFn::apigetObJ($user_id,'ZUser',CommonFn::getMessage('user','id_not_exist'),array(),201);
  81. if($balance){
  82. if($user_obj->balance < $balance){
  83. CommonFn::requestAjax(false,'余额不足哦');
  84. }
  85. }
  86. $address_list = $user_obj->shop_address?$user_obj->shop_address:array();
  87. $address = array();
  88. foreach ($address_list as $value) {
  89. if($address_id == $value['address_id']){
  90. $address = $value;
  91. }
  92. }
  93. if(!$address){
  94. file_put_contents('/data/erroraddressc.log',var_export($address,true),FILE_APPEND);
  95. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','address_false'));
  96. }else{
  97. if($station){
  98. $station = Station::get(new MongoId($station));
  99. if(!$station){
  100. file_put_contents('/data/erroraddressa.log',var_export($address,true),FILE_APPEND);
  101. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','address_cannot_service'));
  102. }
  103. $divide_station = $station->_id;
  104. }else{
  105. file_put_contents('/data/erroraddressb.log',var_export($address,true),FILE_APPEND);
  106. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','address_cannot_service'));
  107. }
  108. $o2o_address['name'] = $address['name'];
  109. $o2o_address['mobile'] = $address['mobile'];
  110. $o2o_address['province'] = $address['address']['province'];
  111. $o2o_address['city'] = $address['address']['city'];
  112. $o2o_address['area'] = $address['address']['area'];
  113. $o2o_address['detail'] = $address['address']['detail'];
  114. $o2o_address['position'] = isset($address['position'])?$address['position']:array(0,0);
  115. $o2o_address['poi'] = isset($address['address']['poi'])?$address['address']['poi']:array();
  116. }
  117. $product_list = array();
  118. $price = 0.0;
  119. $service_type = 0;
  120. foreach ($products as $product) {
  121. if(isset($product['product_id']) && $product['count'] >= 1){
  122. $product_temp = array();
  123. $product_obj = Product::get(new MongoId($product['product_id']));
  124. if($product_obj){
  125. $price += ($product_obj->price*$product['count']);
  126. $price += $extra[0]['price']*$product['count'];
  127. $product_temp['product'] = $product_obj->_id;
  128. $product_temp['count'] = $product['count'];
  129. $product_temp['extra'] = $extra[0];
  130. $product_list[] = $product_temp;
  131. if($product_obj->is_extra == 0){
  132. $service_type = $product_obj->type;
  133. }
  134. }else{
  135. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','product_not_exist'));
  136. }
  137. }else{
  138. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','product_illegal'));
  139. }
  140. }
  141. if($precedence){
  142. $price += 40;
  143. }
  144. $final_price = $price;
  145. $used_coupon = array();
  146. foreach ($coupons as $coupon){
  147. $user_coupon = UserCoupon::get(new MongoId($coupon));
  148. $current_time = time();
  149. if($user_coupon && (string)$user_coupon->user == $user_id && $user_coupon->start_time < $current_time && $user_coupon->end_time > $current_time && $user_coupon->status == 1){
  150. $coupon = Coupon::get($user_coupon->coupon);
  151. //判断优惠券可用时间
  152. $weekend_check = (date('w',strtotime($booking_time))==0 || date('w',strtotime($booking_time))==6)?1:0;
  153. $booking_hour = date('H',strtotime($booking_time));
  154. if($weekend_check){
  155. if($coupon->workday_limit==1){
  156. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','coupon_unuseable').'1');
  157. }
  158. }else{
  159. if($coupon->workday_limit==2){
  160. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','coupon_unuseable').'2');
  161. }
  162. }
  163. if($coupon->time_limit_start && $coupon->time_limit_end && ($coupon->time_limit_start > $booking_hour || $coupon->time_limit_end < $booking_hour)){
  164. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','coupon_unuseable').'3');
  165. }
  166. $new_user_coupons = Yii::app()->params['new_user_coupons'];
  167. if(($coupon->type == 0 || $coupon->type == $service_type ) && $coupon->status==1 && $coupon->min_price <= $final_price){
  168. $final_price = $final_price-$coupon->value>=0?$final_price-$coupon->value:0;
  169. $used_coupon[] = $user_coupon->_id;
  170. $user_coupon->status = -1;
  171. $user_coupon->use_time = time();
  172. $user_coupon->update(array('status','use_time'),true);
  173. }else{
  174. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','coupon_unuseable').'4');
  175. }
  176. }else{
  177. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','coupon_unuseable').'5');
  178. }
  179. }
  180. $order = new ROrder();
  181. $order->order_time = time();
  182. $order->booking_time = strtotime($booking_time);
  183. $order->products = $product_list;
  184. $order->precedence = $precedence;
  185. $order->price = $price;
  186. $order->channel = $order_channel;
  187. $order->counts = $counts;
  188. $order->final_price = $final_price;
  189. $order->pay_price = $order->final_price-$balance;
  190. $order->address = $o2o_address;
  191. $order->memo = $memo;
  192. $order->station = $divide_station;
  193. $order->coupons = $used_coupon;
  194. if(isset($user_coupon->coupon)){
  195. $order->coupon_type = $user_coupon->coupon;
  196. }
  197. if($order->pay_price == 0){
  198. $user_obj->balance = $user_obj->balance-$balance;
  199. $user_obj->save();
  200. $balance_log = new BalanceLog();
  201. $balance_log->time = time();
  202. $balance_log->user = $user_obj->_id;
  203. $balance_log->memo = '微信下订单';
  204. $balance_log->type = 'order';
  205. $balance_log->amount = $balance;
  206. $balance_log->save(true);
  207. if($order->final_price>0){
  208. $order->pay_channel = 'balance';
  209. }
  210. $order->status = 1;
  211. //start 长期订暂用
  212. /*if($order->status == 1 ) {
  213. if($products[0]['product_id'] == '5835423fa84ea0ac7a8b4568') {
  214. $u_id = new MongoId($user_id);
  215. $start_time = date_create("2016-11-11")->format('U');//发放优惠券可用开始时间 2016.11.14
  216. $end_time = date_create("2016-12-15")->format('U'); //发放优惠券过期时间 17天
  217. if ($extra[0]['type'] == "3张(2小时/人)"){
  218. for( $i=0;$i<3;$i++) {
  219. Service::factory('CouponService')->giveCoupon($u_id, new MongoId("5835527fa84ea02e758b45b7"), $start_time, $end_time);//发放代金券
  220. }
  221. } else if ($extra[0]['type'] == "3张(3小时/人)"){
  222. for( $i=0;$i<3;$i++) {
  223. Service::factory('CouponService')->giveCoupon($u_id, new MongoId("58356a2aa84ea03b018b46bb"), $start_time, $end_time);//发放代金券
  224. }
  225. } elseif ($extra[0]['type'] == "6张(2小时/人)"){
  226. for( $i=0;$i<6;$i++) {
  227. Service::factory('CouponService')->giveCoupon($u_id, new MongoId("5835527fa84ea02e758b45b7"), $start_time, $end_time);//发放代金券
  228. }
  229. } else{
  230. for( $i=0;$i<6;$i++) {
  231. Service::factory('CouponService')->giveCoupon($u_id, new MongoId("58356a2aa84ea03b018b46bb"), $start_time, $end_time);//发放代金券
  232. }
  233. }
  234. }
  235. }*/
  236. //end暂用
  237. //修改订单状态
  238. CommonFn::sendOrderSms($order,(string)$order->_id);
  239. }else{
  240. $order->status = 0;
  241. }
  242. $order->user = $user_obj->_id;
  243. $order->type = $service_type;
  244. //$order->technician = intval($tech_id);
  245. if($order->save()){
  246. $data = ROrder::model()->parseRow($order);
  247. /*foreach ($products as $product) {
  248. if(isset($product['product_id']) && $product['count'] >= 1){
  249. $product_obj = Product::get(new MongoId($product['product_id']));
  250. if($product_obj){
  251. $product_obj->sale_count+=$product['count'];
  252. $product_obj->update(array('sale_count'),true);
  253. }
  254. }
  255. }*/
  256. CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$data);
  257. }
  258. }
  259. public function actionList(){
  260. $user_id = Yii::app()->getRequest()->getParam("user_id");
  261. $type = Yii::app()->getRequest()->getParam("type");
  262. $order_type = Yii::app()->getRequest()->getParam("order_type");
  263. if(!$order_type){
  264. $order_type = $type;
  265. }
  266. $user_obj = CommonFn::apigetObJ($user_id,"ZUser",CommonFn::getMessage('user','id_not_exist'),201);
  267. $page = intval(Yii::app()->getRequest()->getParam("page",1));
  268. $pagesize = Yii::app()->params['ROrderListPageSize'];
  269. if($order_type == 1 ){
  270. $conditions = array(
  271. 'user'=>array('==',$user_obj->_id),
  272. 'status'=>array('notin',array(-3,-2,-1,6,7))
  273. );
  274. }elseif ($order_type == 2) {
  275. $conditions = array(
  276. 'user'=>array('==',$user_obj->_id),
  277. 'status'=>array('in',array(-3,-2,-1,7))
  278. );
  279. }elseif($order_type == 3){
  280. $conditions = array(
  281. 'user'=>array('==',$user_obj->_id),
  282. 'status'=>array('==',6)
  283. );
  284. }else{
  285. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  286. }
  287. $order = array(
  288. 'booking_time'=>'desc'
  289. );
  290. $model = new ROrder();
  291. $pagedata = CommonFn::getPagedata($model,$page,$pagesize,$conditions,$order);
  292. $order_list = $pagedata['res'];
  293. foreach ($order_list as $key => $value) {
  294. $order_list[$key] = $model->output($value);
  295. }
  296. $data = array_values($order_list);
  297. CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$data,200,array('sum_count' => $pagedata['sum_count'],'sum_page'=>$pagedata['sum_page'],'page_size'=>$pagedata['page_size'],'current_page'=>$pagedata['current_page']));
  298. }
  299. public function actionPay(){
  300. $user_id = Yii::app()->getRequest()->getParam("user_id");
  301. $pay_channel = Yii::app()->getRequest()->getParam("pay_channel");
  302. $order_id = Yii::app()->getRequest()->getParam("order_id");
  303. if(!$user_id || !$pay_channel || !$order_id || !CommonFn::isMongoId($order_id)){
  304. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  305. }
  306. $user_obj = RUser::get(new MongoId($user_id));
  307. $order = ROrder::get(new MongoId($order_id));
  308. if(!$order || !$user_obj){
  309. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  310. }
  311. if($order && (string)$order->user != $user_id){
  312. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  313. }
  314. if($order->charge_id){
  315. CommonFn::requestAjax(false,'此订单已支付过',array('have_pay'=>1));
  316. }
  317. foreach ($order->products as $value) {
  318. if(isset($value['product'])){
  319. $product = Product::get($value['product']);
  320. }
  321. if($product){
  322. break;
  323. }
  324. }
  325. if(isset($product)&&$product){
  326. $str = isset(Yii::app()->params['o2o_service'][$product->type]['name'])?Yii::app()->params['o2o_service'][$product->type]['name']:'';
  327. }
  328. $str = isset($str)&&$str?$str:'上门';
  329. $amount = ceil($order->pay_price*1000)/10;
  330. $result = Service::factory('PayService')->Pay($pay_channel,$amount,(string)$order->_id,$str,$str,$user_obj->wx_pub_openid);
  331. if($result === false){
  332. CommonFn::requestAjax(false,'支付遇到点问题了,请稍候再试');
  333. }else{
  334. // 支付成功后用户有效订单数增加
  335. if (isset($user_obj->order_count)) {
  336. $user_obj->order_count += 1;
  337. //支付成功 判断是否是长期定 start
  338. /*if($order->products[0]['product'] == '5835423fa84ea0ac7a8b4568') {
  339. $u_id = new MongoId($user_id);
  340. $start_time = date_create("2016-11-11")->format('U');//发放优惠券可用开始时间 2016.11.14
  341. $end_time = date_create("2016-12-15")->format('U'); //发放优惠券过期时间 17天
  342. if ($order->products[0]['extra']['type']['type'] == "3张(2小时/人)"){
  343. for( $i=0;$i<3;$i++) {
  344. Service::factory('CouponService')->giveCoupon($u_id, new MongoId("5835527fa84ea02e758b45b7"), $start_time, $end_time);//发放代金券
  345. }
  346. } else if ($order->products[0]['extra']['type']['type'] == "3张(3小时/人)"){
  347. for( $i=0;$i<3;$i++) {
  348. Service::factory('CouponService')->giveCoupon($u_id, new MongoId("58356a2aa84ea03b018b46bb"), $start_time, $end_time);//发放代金券
  349. }
  350. } elseif ($order->products[0]['extra']['type']['type'] == "6张(2小时/人)"){
  351. for( $i=0;$i<6;$i++) {
  352. Service::factory('CouponService')->giveCoupon($u_id, new MongoId("5835527fa84ea02e758b45b7"), $start_time, $end_time);//发放代金券
  353. }
  354. } else{
  355. for( $i=0;$i<6;$i++) {
  356. Service::factory('CouponService')->giveCoupon($u_id, new MongoId("58356a2aa84ea03b018b46bb"), $start_time, $end_time);//发放代金券
  357. }
  358. }
  359. }*/
  360. // 长期定end
  361. } else {
  362. $user_obj->order_count = 1;
  363. }
  364. //支付成功
  365. $user_obj->save();
  366. CommonFn::requestAjax(true,'success',json_decode($result),200,array('booking_time'=>$order->booking_time));
  367. }
  368. }
  369. public function actionDel(){
  370. $user_id = Yii::app()->getRequest()->getParam("user_id");
  371. $order_id = Yii::app()->getRequest()->getParam("order_id");
  372. if(!$user_id || !$order_id || !CommonFn::isMongoId($order_id)){
  373. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  374. }
  375. $user_obj = RUser::get(new MongoId($user_id));
  376. $order = ROrder::get(new MongoId($order_id));
  377. $status = -1;
  378. if(!$order || !$user_obj){
  379. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  380. }
  381. if($order && (string)$order->user != $user_id){
  382. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  383. }
  384. if($order->status != 0){
  385. CommonFn::requestAjax(false,'此订单暂不支持取消');
  386. }
  387. if( $order->status!=-1 && $order->status!=-2 ){
  388. foreach ($order->coupons as $user_coupon) {
  389. $user_coupon = UserCoupon::get($user_coupon);
  390. $user_coupon->status = 1;
  391. $user_coupon->update(array('status'),true);
  392. }
  393. }
  394. $order->status = $status;
  395. $arr_order = array('status');
  396. $success = $order->update($arr_order,true);
  397. if($success){
  398. $order_info = $order->parseRow($order);
  399. }
  400. CommonFn::requestAjax($success, '');
  401. }
  402. public function actionUsableCoupon(){
  403. $user_id = Yii::app()->getRequest()->getParam("user_id");
  404. $get_all = Yii::app()->getRequest()->getParam("get_all");
  405. $type = Yii::app()->getRequest()->getParam("type");
  406. $extra = json_decode(Yii::app()->getRequest()->getParam("extra","[]"),true);
  407. $booking_time = Yii::app()->getRequest()->getParam("booking_time");
  408. if($booking_time){
  409. $booking_time = strtotime($booking_time);
  410. $weekend_check = (date('w',$booking_time)==0||date('w',$booking_time)==6)?1:0;
  411. $booking_hour = date('H',$booking_time);
  412. }
  413. $device_id = Yii::app()->getRequest()->getParam("device_id",'');
  414. $products = json_decode(Yii::app()->getRequest()->getParam("products",'[]'),true);
  415. if(!CommonFn::isMongoId($user_id)){
  416. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  417. }
  418. $UserCoupon = new UserCoupon();
  419. if($get_all){
  420. $criteria = new EMongoCriteria();
  421. $criteria->user('==',new MongoId($user_id));
  422. $current_time = time();
  423. $criteria->end_time('>=',$current_time);
  424. $criteria->status('==',1);
  425. $coupons = UserCoupon::model()->findAll($criteria);
  426. $coupon_list = array();
  427. $coupon_list['useable_coupons'] = array();
  428. foreach ($coupons as $value) {
  429. $coupon = Coupon::get($value->coupon);
  430. if($coupon->status!=1){
  431. continue;
  432. }
  433. $coupon_list['useable_coupons'][] = $UserCoupon->parseRow($value,array('id','start_time','end_time','start_time_str','end_time_str','coupon'));
  434. }
  435. if(count($coupon_list['useable_coupons']) <= 15){
  436. $criteria = new EMongoCriteria();
  437. $criteria->user('==',new MongoId($user_id));
  438. $criteria->status('==',-1);
  439. $coupons = UserCoupon::model()->findAll($criteria);
  440. $coupon_list['used_coupons'] = array();
  441. foreach ($coupons as $value) {
  442. $coupon = $UserCoupon->parseRow($value,array('id','start_time','end_time','start_time_str','end_time_str','coupon'));
  443. $coupon['unuseable_reason'] = '已使用';
  444. $coupon_list['used_coupons'][] = $coupon;
  445. }
  446. $criteria = new EMongoCriteria();
  447. $criteria->user('==',new MongoId($user_id));
  448. $current_time = time();
  449. $criteria->end_time('<',$current_time);
  450. $coupons = UserCoupon::model()->findAll($criteria);
  451. $coupon_list['overtime_coupons'] = array();
  452. foreach ($coupons as $value) {
  453. $coupon = $UserCoupon->parseRow($value,array('id','start_time','end_time','start_time_str','end_time_str','coupon'));
  454. $coupon['unuseable_reason'] = '已过期';
  455. $coupon_list['overtime_coupons'][] = $coupon;
  456. }
  457. }else{
  458. $coupon_list['used_coupons'] = array();
  459. $coupon_list['overtime_coupons'] = array();
  460. }
  461. CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$coupon_list);
  462. }
  463. $price = 0;
  464. if($products){
  465. foreach ($products as $product) {
  466. if(isset($product['product_id']) && $product['count'] >= 1){
  467. $product_temp = array();
  468. $product_obj = Product::get(new MongoId($product['product_id']));
  469. if($product_obj){
  470. $price += ($product_obj->price*$product['count']);
  471. $price += $extra[0]['price']*$product['count'];
  472. }else{
  473. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','product_not_exist'));
  474. }
  475. }else{
  476. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','product_illegal'));
  477. }
  478. }
  479. }
  480. $criteria = new EMongoCriteria();
  481. $criteria->user('==',new MongoId($user_id));
  482. $current_time = time();
  483. $criteria->start_time('<=',$current_time);
  484. $criteria->end_time('>=',$current_time);
  485. $criteria->status('==',1);
  486. $coupons = UserCoupon::model()->findAll($criteria);
  487. $coupon_list = array();
  488. $unuseable_coupons = array();
  489. foreach ($coupons as $value) {
  490. $coupon = Coupon::get($value->coupon);
  491. if($coupon->status!=1){
  492. continue;
  493. }
  494. if($coupon->min_price>$price || ($type && $coupon->type != $type && $coupon->type != 0)){
  495. continue;
  496. }
  497. if($booking_time){
  498. if($weekend_check){
  499. if($coupon->workday_limit==1){
  500. $unuseable_coupons[] = $UserCoupon->parseRow($value,array('id','start_time','end_time','start_time_str','end_time_str','coupon'));
  501. continue;
  502. }
  503. }else{
  504. if($coupon->workday_limit==2){
  505. $unuseable_coupons[] = $UserCoupon->parseRow($value,array('id','start_time','end_time','start_time_str','end_time_str','coupon'));
  506. continue;
  507. }
  508. }
  509. if($coupon->time_limit_start && $coupon->time_limit_end && ($coupon->time_limit_start > $booking_hour || $coupon->time_limit_end < $booking_hour)){
  510. $unuseable_coupons[] = $UserCoupon->parseRow($value,array('id','start_time','end_time','start_time_str','end_time_str','coupon'));
  511. continue;
  512. }
  513. }
  514. $coupon_list[] = $UserCoupon->parseRow($value,array('id','start_time','end_time','start_time_str','end_time_str','coupon'));
  515. }
  516. CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$coupon_list,200,array('unuseable_coupons' => $unuseable_coupons));
  517. }
  518. public function actionCheckAddress(){
  519. $user_id = Yii::app()->getRequest()->getParam("user_id");
  520. $address_id = Yii::app()->getRequest()->getParam("address_id");
  521. $user_obj = CommonFn::apigetObJ($user_id,'ZUser',CommonFn::getMessage('user','id_not_exist'),array(),201);
  522. $address_list = $user_obj->shop_address?$user_obj->shop_address:array();
  523. $address = array();
  524. foreach ($address_list as $value) {
  525. if($address_id == $value['address_id']){
  526. $address = $value;
  527. }
  528. }
  529. if(!$address){
  530. file_put_contents('/data/erroraddress_user.log',var_export($user_id,true),FILE_APPEND);
  531. CommonFn::requestAjax(false,CommonFn::getMessage('shop','address_false'));
  532. }else{
  533. if(isset($address['address']['province']) && ($address['address']['province'] == '上海市' || $address['address']['province'] == '')){
  534. CommonFn::requestAjax(true,'success',array('station' => '57db39709f5160bb048b456a'));
  535. }else{
  536. file_put_contents('/data/erroraddress.log',var_export($address,true),FILE_APPEND);
  537. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','address_cannot_service'));
  538. }
  539. }
  540. }
  541. public function actionAppend(){
  542. $user_id = Yii::app()->getRequest()->getParam("user_id");
  543. $order_id = Yii::app()->getRequest()->getParam("order_id");
  544. $products = json_decode(Yii::app()->getRequest()->getParam("products","[]"),true);
  545. if(!$user_id || !$products || !$order_id || !CommonFn::isMongoId($order_id) || !CommonFn::isMongoId($user_id)){
  546. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  547. }
  548. $user_obj = RUser::get(new MongoId($user_id));
  549. $order = ROrder::get(new MongoId($order_id));
  550. if(!$order || !$user_obj){
  551. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  552. }
  553. if($order && (string)$order->user != $user_id){
  554. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  555. }
  556. $product_list = array();
  557. $price = 0;
  558. foreach ($products as $product) {
  559. if(isset($product['product_id']) && $product['count'] >= 1){
  560. $product_temp = array();
  561. $product_obj = Product::get(new MongoId($product['product_id']));
  562. if($product_obj){
  563. $price += ($product_obj->price*$product['count']);
  564. $product_temp['product'] = $product_obj->_id;
  565. $product_temp['count'] = $product['count'];
  566. $product_list[] = $product_temp;
  567. if($product_obj->is_extra != 1){
  568. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','product_illegal'));
  569. }
  570. }else{
  571. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','product_not_exist'));
  572. }
  573. }else{
  574. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','product_illegal'));
  575. }
  576. }
  577. $append_product = new AppendOrder();
  578. $append_product->order = $order->_id;
  579. $append_product->products = $product_list;
  580. $append_product->price = $price;
  581. $append_product->append_time = time();
  582. $success = $append_product->save();
  583. if($success){
  584. $order->append_orders[] = $append_product->_id;
  585. $order->update(array('append_orders'),true);
  586. $list = new ARedisList('append_order_list');
  587. $list->push((string)$order->_id);
  588. $append_info = $append_product->parseRow($append_product);
  589. CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$append_info);
  590. }
  591. CommonFn::requestAjax($success, '');
  592. }
  593. public function actionAppendPay(){
  594. $user_id = Yii::app()->getRequest()->getParam("user_id");
  595. $pay_channel = Yii::app()->getRequest()->getParam("pay_channel");
  596. $order_id = Yii::app()->getRequest()->getParam("order_id");
  597. $append_id = Yii::app()->getRequest()->getParam("append_id");
  598. if(!$user_id || !$pay_channel || !$order_id || !$append_id || !CommonFn::isMongoId($append_id)){
  599. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  600. }
  601. $user_obj = RUser::get(new MongoId($user_id));
  602. $order = ROrder::get(new MongoId($order_id));
  603. $append_product = AppendOrder::get(new MongoId($append_id));
  604. if(!$order || !$user_obj){
  605. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  606. }
  607. if($order && (string)$order->user != $user_id){
  608. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  609. }
  610. if($append_product->status == 1){
  611. CommonFn::requestAjax(false,'此订单已支付过',array('have_pay'=>1));
  612. }
  613. $str = '附加服务';
  614. $amount = ceil($append_product->price*1000)/10;
  615. $result = Service::factory('PayService')->Pay($pay_channel,$amount,(string)$append_product->_id,$str,$str,$user_obj->wx_pub_openid);
  616. if($result === false){
  617. CommonFn::requestAjax(false,'支付遇到点问题了,请稍候再试');
  618. }else{
  619. // 追加订单并付款后通知保洁师
  620. if (!empty($order->technician)) {
  621. $techObj = TechInfo::get($order->technician);
  622. if (!empty($techObj) && !empty($techObj->weixin_userid)) {
  623. $wechat = O2oApp::getWechatActive();
  624. $url_prefix = ENVIRONMENT == 'product' ? 'http:// api.yiguanjia.me' : 'http:// apitest.yiguanjia.me';
  625. $wechat_data = array(
  626. 'touser' => $techObj->weixin_userid,
  627. 'msgtype' => 'news',
  628. 'agentid' => '24',
  629. 'news' => array(
  630. 'articles' => array(
  631. array(
  632. 'title' => '壹管家提示-新的追加订单',
  633. 'description' => $techObj->name.'你好!预定时间在'.date('m月d日H:i', $order->booking_time).'的订单刚刚被用户追加了新的服务,请点击查看。',
  634. 'url' => $url_prefix.'/index.php?r=o2o/myOrder/info&order='.(string)$order->_id.'&user='.$order->technician,
  635. ),
  636. ),
  637. ),
  638. );
  639. $wechat->sendMessage($wechat_data);
  640. }
  641. }
  642. CommonFn::requestAjax(true,'success',json_decode($result));
  643. }
  644. }
  645. public function actionRetrieve(){
  646. $user_id = Yii::app()->getRequest()->getParam("user_id");
  647. $order_id = Yii::app()->getRequest()->getParam("order_id");
  648. if(!$user_id || !$order_id ){
  649. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  650. }
  651. $user_obj = RUser::get(new MongoId($user_id));
  652. $order = ROrder::get(new MongoId($order_id));
  653. if(!$order || !$user_obj){
  654. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  655. }
  656. if($order && (string)$order->user != $user_id){
  657. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  658. }
  659. if($order->status != 1){
  660. CommonFn::requestAjax(false,'此订单不可申请退款');
  661. }
  662. $order->status = -3;
  663. $order->apply_refund_time = time();
  664. if($order->update(array('status','apply_refund_time'),true)){
  665. // 发送通知给保洁师
  666. if (!empty($order->technician)) {
  667. $techObj = TechInfo::get($order->technician);
  668. if (!empty($techObj) && !empty($techObj->weixin_userid)) {
  669. $wechat = O2oApp::getWechatActive();
  670. $url_prefix = ENVIRONMENT == 'product' ? 'http:// api.yiguanjia.me' : 'http:// apitest.yiguanjia.me';
  671. $wechat_data = array(
  672. 'touser' => $techObj->weixin_userid,
  673. 'msgtype' => 'news',
  674. 'agentid' => '24',
  675. 'news' => array(
  676. 'articles' => array(
  677. array(
  678. 'title' => '壹管家提示-申请退款',
  679. 'description' => $techObj->name.'你好!预定时间在'.date('m月d日H:i', $order->booking_time).'的订单刚刚已被用户申请退款,请点击查看。',
  680. 'url' => $url_prefix.'/index.php?r=o2o/myOrder/info&order='.$order_id.'&user='.$order->technician,
  681. ),
  682. ),
  683. ),
  684. );
  685. $wechat->sendMessage($wechat_data);
  686. }
  687. }
  688. CommonFn::requestAjax(true,'申请退款成功,请等待确认');
  689. }else{
  690. CommonFn::requestAjax(false,'请稍后再试');
  691. }
  692. }
  693. public function actionConfirmComplete(){
  694. $user_id = Yii::app()->getRequest()->getParam("user_id");
  695. $order_id = Yii::app()->getRequest()->getParam("order_id");
  696. if(!$user_id || !$order_id ){
  697. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  698. }
  699. $user_obj = RUser::get(new MongoId($user_id));
  700. $order = ROrder::get(new MongoId($order_id));
  701. if(!$order || !$user_obj){
  702. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  703. }
  704. if($order && (string)$order->user != $user_id){
  705. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  706. }
  707. if(!in_array($order->status, array(1,2,3,4,5))){
  708. CommonFn::requestAjax(false,'此订单不支持修改状态');
  709. }
  710. $order->status = 6;
  711. $order->finish_time = time();
  712. $success = $order->update(array('finish_time','status'),true);
  713. if($success ){
  714. // 保洁师订单统计
  715. if (isset($order->technicians)) {
  716. foreach($order->technicians as $technician){
  717. $tech_obj = TechInfo::get($technician['technician_id']);
  718. if ($tech_obj) {
  719. $order_count = $tech_obj->order_count + 1;
  720. $tech_obj->order_count = $order_count;
  721. }
  722. }
  723. }
  724. CommonFn::requestAjax(true,'订单已完成,期待您的下次预约');
  725. }else{
  726. CommonFn::requestAjax(false,'请稍后再试');
  727. }
  728. }
  729. public function actionDetail(){
  730. $user_id = Yii::app()->getRequest()->getParam("user_id");
  731. $order_id = Yii::app()->getRequest()->getParam("order_id");
  732. if(!$user_id || !$order_id || !CommonFn::isMongoId($order_id) || !CommonFn::isMongoId($user_id)){
  733. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  734. }
  735. $user_obj = RUser::get(new MongoId($user_id));
  736. $order = ROrder::get(new MongoId($order_id));
  737. if(!$order || !$user_obj){
  738. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  739. }
  740. if($order && (string)$order->user != $user_id){
  741. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  742. }
  743. $order_info = $order->parseRow($order);
  744. CommonFn::requestAjax(true,'',$order_info);
  745. }
  746. //选择保洁师
  747. public function actionSelectTech(){
  748. $booking_time = Yii::app()->getRequest()->getParam("booking_time");
  749. $service_type = json_decode(Yii::app()->getRequest()->getParam("service_type","[]"),true);
  750. $user_id = Yii::app()->getRequest()->getParam("user_id");
  751. $address_id = Yii::app()->getRequest()->getParam("address_id");
  752. $user_obj = CommonFn::apigetObJ($user_id,'ZUser',CommonFn::getMessage('user','id_not_exist'),array(),201);
  753. $address_list = $user_obj->shop_address?$user_obj->shop_address:array();
  754. $address = array();
  755. foreach ($address_list as $value) {
  756. if($address_id == $value['address_id']){
  757. $address = $value;
  758. }
  759. }
  760. if(strtotime($booking_time) < time()){
  761. CommonFn::requestAjax(false,'此时间段不可预约');
  762. }
  763. if(!$address){
  764. CommonFn::requestAjax(false,CommonFn::getMessage('shop','address_false'));
  765. }
  766. if(!isset($address['position'][0])||$address['position'][0]==0||is_int($address['position'][0])){
  767. $address_res = CommonFn::simple_http('http://api.map.baidu.com/geocoder/v2/?ak=B349f0b32ef6e78b2e678f45cb9fddaf&address='.$address['address']['area'].$address['address']['detail'].'&city='.$address['address']['city'].'&output=json');
  768. $address_info = json_decode($address_res,true);
  769. $position = $address_info['result']['location'];
  770. $detail_res = CommonFn::simple_http('http://api.map.baidu.com/geocoder/v2/?ak=B349f0b32ef6e78b2e678f45cb9fddaf&location='.$position['lat'].','.$position['lng'].'&output=json&pois=1');
  771. $detail_info = json_decode($detail_res,true);
  772. $business = explode(',',$detail_info['result']['business']);
  773. }else{
  774. $detail_res = CommonFn::simple_http('http://api.map.baidu.com/geocoder/v2/?ak=B349f0b32ef6e78b2e678f45cb9fddaf&location='.$address['position'][1].','.$address['position'][0].'&output=json&pois=1');
  775. $detail_info = json_decode($detail_res,true);
  776. $business = explode(',',$detail_info['result']['business']);
  777. }
  778. $user_model = new TechInfo();
  779. $criteria = new EMongoCriteria();
  780. $criteria->service_type('all', $service_type);
  781. if( !in_array(9, $service_type) && !in_array(10, $service_type)){
  782. foreach ($business as $value) {
  783. $criteria->addCond('business','or',$value);
  784. }
  785. }
  786. $criteria->status('==', 1);
  787. $cursor = $user_model->findAll($criteria);
  788. //获取满足服务类型保洁师列表
  789. $match_service_tech_list = array();
  790. $tech_list = array();
  791. foreach ($cursor as $key => $value) {
  792. $match_service_tech_list[] = $value->_id;
  793. $tech_list[$value->_id] = $value;
  794. }
  795. $parse_time = strtotime(date('Y-m-d H:00',strtotime($booking_time)));
  796. $FreeTimeRecord = FreeTimeRecord::get($parse_time);
  797. // $last_parse_time = strtotime(date('Y-m-d H:00',strtotime($booking_time)))-3600;
  798. // $LastFreeTimeRecord = FreeTimeRecord::get($last_parse_time);
  799. // $next_parse_time = strtotime(date('Y-m-d H:00',strtotime($booking_time)))-3600;
  800. // $NextFreeTimeRecord = FreeTimeRecord::get($next_parse_time);
  801. //获取此时段空闲保洁师列表
  802. $free_tech_list = array();
  803. // $last_free_tech_list = array();
  804. // $next_free_tech_list = array();
  805. if($FreeTimeRecord){
  806. $free_tech_list = $FreeTimeRecord->free_technician;
  807. }
  808. // if($LastFreeTimeRecord){
  809. // $last_free_tech_list = $LastFreeTimeRecord->free_technician;
  810. // }
  811. // if($NextFreeTimeRecord){
  812. // $next_free_tech_list = $NextFreeTimeRecord->free_technician;
  813. // }
  814. //空闲且满足服务能力保洁师,推荐用户选择
  815. $recommend_tech = array_intersect($match_service_tech_list,$free_tech_list);
  816. $can_select_tech = array();
  817. foreach ($recommend_tech as $key => $value) {
  818. $tech = $tech_list[$value];
  819. unset($tech_list[$value]);
  820. $tmp['id'] = $tech->_id;
  821. $tmp['name'] = $tech->name;
  822. $tmp['desc'] = $tech->desc;
  823. $tmp['service_type'] = $tech->service_type;
  824. $tmp['avatar'] = $tech->avatar;
  825. $tmp['favourable_count'] = $tech->favourable_count;
  826. $can_select_tech[] = $tmp;
  827. }
  828. //满足服务能力,但此时段不空闲,展示给用户此保洁师下个空闲时段
  829. $service_match_tech = array();
  830. foreach ($tech_list as $key => $value) {
  831. $tmp['id'] = $value->_id;
  832. $tmp['name'] = $value->name;
  833. $tmp['desc'] = $value->desc;
  834. $tmp['service_type'] = $value->service_type;
  835. $tmp['avatar'] = $value->avatar;
  836. $tmp['favourable_count'] = $value->favourable_count;
  837. $criteria = new EMongoCriteria();
  838. $criteria->free_technician('==', $tmp['id']);
  839. $criteria->_id('>',time());
  840. $criteria->limit(1);
  841. $criteria->sort('_id', EMongoCriteria::SORT_ASC);
  842. if(FreeTimeRecord::model()->count($criteria)){
  843. $free_time = FreeTimeRecord::model()->findAll($criteria);
  844. foreach ($free_time as $next_free_time) {
  845. $tmp['next_free_time'] = FreeTimeRecord::parseFreeTime($next_free_time->_id);
  846. break;
  847. }
  848. }else{
  849. continue;
  850. }
  851. $service_match_tech[] = $tmp;
  852. }
  853. $data['can_select_tech'] = $can_select_tech;
  854. $data['service_match_tech'] = $service_match_tech;
  855. CommonFn::requestAjax(true,'',$data);
  856. }
  857. /**
  858. * 获取评价列表接口
  859. */
  860. public function actionTechComment() {
  861. $page = intval(Yii::app()->getRequest()->getParam("page",1));
  862. //$tech_id = intval(Yii::app()->getRequest()->getParam("tech_id"));
  863. $pagesize = Yii::app()->params['O2oCommentListPageSize'];
  864. if(!$tech_id){
  865. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  866. }
  867. $conditions = array(
  868. //'technician'=>array('==',$tech_id),
  869. 'status'=>array('==',1),
  870. );
  871. $order = array(
  872. 'time' => 'desc'
  873. );
  874. $model = new Comment();
  875. $pagedata = CommonFn::getPagedata($model,$page,$pagesize,$conditions,$order);
  876. $data['comments'] = $pagedata['res'];
  877. CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$data,200,array('sum_count' => $pagedata['sum_count'],'sum_page'=>$pagedata['sum_page'],'page_size'=>$pagedata['page_size'],'current_page'=>$pagedata['current_page']));
  878. }
  879. public function actionGetUserTotalOrder(){
  880. $start_time = Yii::app()->request->getParam('start_time','');
  881. $end_time = Yii::app()->request->getParam('end_time','');
  882. $user_id = Yii::app()->request->getParam('user_id','');
  883. if(empty($user_id)){
  884. $data['errorCode'] = '01';
  885. $data['errorMessage'] ='请传入user_id';
  886. echo json_encode($data);exit;
  887. }
  888. $criteria = new EMongoCriteria();
  889. $criteria->booking_time('>=', strtotime($start_time));
  890. $criteria->booking_time('<', strtotime($end_time));
  891. $criteria->status('==',6);
  892. $criteria->addCond('user','==',new MongoId($user_id));
  893. $cursor = ROrder::model()->findAll($criteria);
  894. $total = 0;
  895. $rows = CommonFn::getRowsFromCursor($cursor);
  896. foreach ($rows as $key => $value) {
  897. $total += $value['final_price'];
  898. }
  899. $parsedRows = ROrder::model()->parse($rows);
  900. $data['result'] = $parsedRows;
  901. $data['total'] = $total;
  902. echo CommonFn::requestAjax(true,$data);
  903. time();
  904. }
  905. public function actionDelete(){
  906. $ids = array(
  907. "594b79209f5160a6048b64d5",
  908. "594b78439f5160af048b6670",
  909. "594b78009f5160b6048b6627",
  910. "594b77c19f5160a6048b64cc",
  911. "594b765d9f5160b3048b6c52",
  912. "594b765c9f5160ab048b653c",
  913. "594b765c9f5160a5048b68b1",
  914. "594b765b9f5160b9048b687d",
  915. "594b765a9f5160cd048b69ff",
  916. "594b76599f5160bc048b672c",
  917. "594b76579f5160cc048b6a43",
  918. "594b76579f5160c0048b66e7",
  919. "594b76559f5160d2048b67be",
  920. "594b76549f5160bb048b650e",
  921. "594b76539f5160cb048b8946",
  922. "594b764f9f5160b2048b6844",
  923. "594b764d9f5160c3048b6616",
  924. "594b756e9f5160c6048b665f",
  925. "594b75489f5160a5048b68ab",
  926. "594b751e9f5160a1048b7916",
  927. "594b74d09f5160b6048b661d",
  928. "594b74c89f5160be048b6639",
  929. "594b74c19f5160b7048b694a",
  930. "594b74b69f5160c7048b6976",
  931. "594b73789f5160d3048b636c",
  932. "594a23779f5160c0048b66d6",
  933. "594a22779f5160b2048b6837"
  934. );
  935. $i = 0;
  936. foreach ($ids as $id) {
  937. $order = ROrder::get(new MongoId($id));
  938. $result = $order->delete();
  939. if($result){
  940. $i++;
  941. }
  942. }
  943. echo $i;
  944. }
  945. }