RUserController.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. class RUserController extends AdminController{
  3. public function actionIndex()
  4. {
  5. $this->render('index');
  6. }
  7. public function actionList(){
  8. $search = Yii::app()->request->getParam('search', '');
  9. $id = Yii::app()->request->getParam('id', '');
  10. $params = CommonFn::getPageParams();
  11. if(isset($params['sort']) && isset($params['sort']['register_time'])){
  12. $params['sort'] = array('_id' => $params['sort']['register_time']);
  13. }
  14. $criteria = new EMongoCriteria($params);
  15. if ($id != ''){
  16. $user_id = new MongoId($id);
  17. $criteria->_id('==', $user_id);
  18. }
  19. if ($search != '' && !CommonFn::isMongoId($search) && !CommonFn::isDeviceId($search)){
  20. $criteria->user_name('or', new MongoRegex('/' . $search . '/'));
  21. if (CommonFn::isMongoId($search)){
  22. $criteria->_id('or', new MongoId($search));
  23. }
  24. }
  25. if (CommonFn::isMongoId($search)) {
  26. $criteria = new EMongoCriteria();
  27. $criteria->_id('==', new MongoId($search));
  28. }
  29. $cursor = RUser::model()->findAll($criteria);
  30. $total = $cursor->count();
  31. $rows = CommonFn::getRowsFromCursor($cursor);
  32. $parsedRows = RUser::model()->parse($rows);
  33. echo CommonFn::composeDatagridData($parsedRows, $total);
  34. }
  35. public function actionUpdate(){
  36. $id = Yii::app()->request->getParam('id', '');
  37. if(!$id){
  38. CommonFn::requestAjax(false, "缺少必须参数");
  39. }
  40. $criteria = new EMongoCriteria();
  41. $criteria->_id = new MongoId($id);
  42. $user = RUser::model()->find($criteria);
  43. //$keys = array('status','certify_status','is_fake_user','city_info');
  44. //$success = $user->save(true, $keys, true);
  45. CommonFn::requestAjax($success, $message, array());
  46. }
  47. public function actionGetCoupons(){
  48. $user_id = Yii::app()->getRequest()->getParam("user_id");
  49. $UserCoupon = new UserCoupon();
  50. $criteria = new EMongoCriteria();
  51. $criteria->user('==',new MongoId($user_id));
  52. $current_time = time();
  53. $criteria->end_time('>=',$current_time);
  54. $criteria->status('==',1);
  55. $coupons = UserCoupon::model()->findAll($criteria);
  56. $coupon_list = array();
  57. foreach ($coupons as $value) {
  58. $coupon = Coupon::get($value->coupon);
  59. if($coupon->status!=1){
  60. continue;
  61. }
  62. $coupon = $UserCoupon->parseRow($value,array('id','start_time','end_time','start_time_str','end_time_str','coupon'));
  63. $coupon['unuseable_reason'] = '可使用';
  64. $coupon_list[] = $coupon;
  65. }
  66. $criteria = new EMongoCriteria();
  67. $criteria->user('==',new MongoId($user_id));
  68. $criteria->status('==',-1);
  69. $coupons = UserCoupon::model()->findAll($criteria);
  70. foreach ($coupons as $value) {
  71. $coupon = $UserCoupon->parseRow($value,array('id','start_time','end_time','start_time_str','end_time_str','coupon'));
  72. $coupon['unuseable_reason'] = '已使用';
  73. $coupon_list[] = $coupon;
  74. }
  75. $criteria = new EMongoCriteria();
  76. $criteria->user('==',new MongoId($user_id));
  77. $current_time = time();
  78. $criteria->end_time('<',$current_time);
  79. $coupons = UserCoupon::model()->findAll($criteria);
  80. foreach ($coupons as $value) {
  81. $coupon = $UserCoupon->parseRow($value,array('id','start_time','end_time','start_time_str','end_time_str','coupon'));
  82. $coupon['unuseable_reason'] = '已过期';
  83. $coupon_list[] = $coupon;
  84. }
  85. foreach ($coupon_list as $key => $value) {
  86. $coupon_list[$key]['name'] = $value['coupon']['name'];
  87. $coupon_list[$key]['value'] = $value['coupon']['value'];
  88. $coupon_list[$key]['min_price'] = $value['coupon']['min_price'];
  89. $coupon_list[$key]['type_str'] = $value['coupon']['type_str'];
  90. }
  91. $total = count($coupon_list);
  92. $data = $coupon_list;
  93. echo CommonFn::composeDatagridData($data, $total);
  94. }
  95. /**
  96. * 后台发送优惠券
  97. * zhouxuchen 2015-11-23
  98. */
  99. // public function actionSendCoupon() {
  100. // $user_id = Yii::app()->request->getParam('user_id', '');
  101. // $coupon_id = Yii::app()->request->getParam('coupon_id', '');
  102. // $start_time = Yii::app()->request->getParam('start_time', '');
  103. // $end_time = Yii::app()->request->getParam('end_time', '');
  104. // $need_sms = intval(Yii::app()->request->getParam('need_sms', '0'));
  105. // $need_zpush = intval(Yii::app()->request->getParam('need_zpush', '0'));
  106. // $copy = Yii::app()->request->getParam('copy', '');
  107. // $mongo = new MongoClient(DB_CONNETC);
  108. // $db = $mongo->wozhua_o2o;
  109. // $coll = 'admin_send_coupon_log';
  110. // $collection = $db->selectCollection($coll);
  111. // $admin = Yii::app()->user;
  112. // $admin_id = $admin->id;
  113. // $user_id = new MongoId($user_id);
  114. // $coupon_id = new MongoId($coupon_id);
  115. // $time = time();
  116. // $user = RUser::get($user_id);
  117. // // 开始与结束时间处理
  118. // $start_time = empty($start_time) ? $time : strtotime($start_time);
  119. // $end_time = empty($end_time) ? strtotime('+30 day', $start_time) : strtotime($end_time);
  120. // // 插入user_coupons表
  121. // $flag_user_coupon = Service::factory('CouponService')->giveCoupon($user_id, $coupon_id, $start_time, $end_time);
  122. // if (!$flag_user_coupon) {
  123. // CommonFn::requestAjax($flag_user_coupon, '发放优惠券失败', array());
  124. // }
  125. // // 插入admin_send_coupon_log表
  126. // $data = array(
  127. // 'admin_id' => $admin_id,
  128. // 'user_id' => $user_id,
  129. // 'coupon_id' => $coupon_id,
  130. // 'time' => $time
  131. // );
  132. // $flag_send_log = $collection->insert($data);
  133. // if ($flag_send_log['err'] != null) {
  134. // CommonFn::requestAjax($flag_user_coupon, '优惠券已发放,日志记录失败', array());
  135. // }
  136. // // 推送私信
  137. // // 前端表单已注释,该段代码会跳过
  138. // if ($need_zpush) {
  139. // $android_data = array();
  140. // $time_str = CommonFn::sgmdate('Y年n月d日', time(), 1);
  141. // $android_data['title'] = '系统通知';
  142. // $android_data['content'] = $copy.'<a href="http://www.wozhua.mobi/index.php?r=o2o/web/index&need_header=0">点击这里</a>预约';
  143. // $android_data['custom'] = array(
  144. // 'type' => 'user_status',
  145. // 'data' => array(
  146. // 'status' => 1,
  147. // 'user_id' => (string)$user_id,
  148. // 'time' => time(),
  149. // 'time_str' => $time_str,
  150. // ),
  151. // );
  152. // $android_data['account'] = (string)$user_id;
  153. // $ios_data = array();
  154. // $ios_data['alert'] = '系统通知:'.'恭喜你获得一张壹管家上门券';
  155. // $ios_data['account'] = (string)$user_id;
  156. // $ios_data['custom'] = array(
  157. // 't' => 'a',
  158. // 'v' => 1
  159. // );
  160. // $z_push = new ZPush();
  161. // $z_push->PushSingleAccount($android_data, $ios_data);
  162. // }
  163. // // 发送短信
  164. // // 前端表单已注释,该段代码会跳过
  165. // if ($need_sms) {
  166. // if ($user->mobile != '') {
  167. // Service::factory('SendSMSService')->send_sms($copy, $user->mobile);
  168. // } else if (!empty($user->shop_address) && isset($user->shop_address[0]['mobile'])) {
  169. // $mobile = $user->shop_address[0]['mobile'];
  170. // Service::factory('SendSMSService')->send_sms($copy, $mobile);
  171. // } else {
  172. // $criteria = new EMongoCriteria();
  173. // //$criteria->channel('==', 'wz_app');
  174. // $criteria->user('==', $user_id);
  175. // $criteria->sort('order_time', EMongoCriteria::SORT_DESC);
  176. // $cursor = ROrder::model()->findAll($criteria);
  177. // if ($cursor->count() == 0) {
  178. // CommonFn::requestAjax(false, '优惠券已发放,因用户未填手机号,短信发送失败');
  179. // } else {
  180. // foreach ($cursor as $key => $row) {
  181. // $address = $row->address;
  182. // $mobile = $address['mobile'];
  183. // break;
  184. // }
  185. // Service::factory('SendSMSService')->send_sms($copy, $mobile);
  186. // }
  187. // }
  188. // }
  189. // CommonFn::requestAjax(true, '优惠券已成功发放');
  190. // }
  191. }