123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <?php
- class RUserController extends AdminController{
- public function actionIndex()
- {
- $this->render('index');
- }
- public function actionList(){
- $search = Yii::app()->request->getParam('search', '');
- $id = Yii::app()->request->getParam('id', '');
- $params = CommonFn::getPageParams();
- if(isset($params['sort']) && isset($params['sort']['register_time'])){
- $params['sort'] = array('_id' => $params['sort']['register_time']);
- }
- $criteria = new EMongoCriteria($params);
- if ($id != ''){
- $user_id = new MongoId($id);
- $criteria->_id('==', $user_id);
- }
- if ($search != '' && !CommonFn::isMongoId($search) && !CommonFn::isDeviceId($search)){
- $criteria->user_name('or', new MongoRegex('/' . $search . '/'));
- if (CommonFn::isMongoId($search)){
- $criteria->_id('or', new MongoId($search));
- }
- }
- if (CommonFn::isMongoId($search)) {
- $criteria = new EMongoCriteria();
- $criteria->_id('==', new MongoId($search));
- }
- $cursor = RUser::model()->findAll($criteria);
- $total = $cursor->count();
- $rows = CommonFn::getRowsFromCursor($cursor);
- $parsedRows = RUser::model()->parse($rows);
- echo CommonFn::composeDatagridData($parsedRows, $total);
- }
- public function actionUpdate(){
- $id = Yii::app()->request->getParam('id', '');
- if(!$id){
- CommonFn::requestAjax(false, "缺少必须参数");
- }
- $criteria = new EMongoCriteria();
- $criteria->_id = new MongoId($id);
- $user = RUser::model()->find($criteria);
- //$keys = array('status','certify_status','is_fake_user','city_info');
- //$success = $user->save(true, $keys, true);
- CommonFn::requestAjax($success, $message, array());
- }
- public function actionGetCoupons(){
- $user_id = Yii::app()->getRequest()->getParam("user_id");
- $UserCoupon = new UserCoupon();
- $criteria = new EMongoCriteria();
- $criteria->user('==',new MongoId($user_id));
- $current_time = time();
- $criteria->end_time('>=',$current_time);
- $criteria->status('==',1);
- $coupons = UserCoupon::model()->findAll($criteria);
- $coupon_list = array();
- foreach ($coupons as $value) {
- $coupon = Coupon::get($value->coupon);
- if($coupon->status!=1){
- continue;
- }
- $coupon = $UserCoupon->parseRow($value,array('id','start_time','end_time','start_time_str','end_time_str','coupon'));
- $coupon['unuseable_reason'] = '可使用';
- $coupon_list[] = $coupon;
- }
- $criteria = new EMongoCriteria();
- $criteria->user('==',new MongoId($user_id));
- $criteria->status('==',-1);
- $coupons = UserCoupon::model()->findAll($criteria);
- foreach ($coupons as $value) {
- $coupon = $UserCoupon->parseRow($value,array('id','start_time','end_time','start_time_str','end_time_str','coupon'));
- $coupon['unuseable_reason'] = '已使用';
- $coupon_list[] = $coupon;
- }
- $criteria = new EMongoCriteria();
- $criteria->user('==',new MongoId($user_id));
- $current_time = time();
- $criteria->end_time('<',$current_time);
- $coupons = UserCoupon::model()->findAll($criteria);
- foreach ($coupons as $value) {
- $coupon = $UserCoupon->parseRow($value,array('id','start_time','end_time','start_time_str','end_time_str','coupon'));
- $coupon['unuseable_reason'] = '已过期';
- $coupon_list[] = $coupon;
- }
- foreach ($coupon_list as $key => $value) {
- $coupon_list[$key]['name'] = $value['coupon']['name'];
- $coupon_list[$key]['value'] = $value['coupon']['value'];
- $coupon_list[$key]['min_price'] = $value['coupon']['min_price'];
- $coupon_list[$key]['type_str'] = $value['coupon']['type_str'];
- }
- $total = count($coupon_list);
- $data = $coupon_list;
- echo CommonFn::composeDatagridData($data, $total);
- }
- /**
- * 后台发送优惠券
- * zhouxuchen 2015-11-23
- */
- // public function actionSendCoupon() {
- // $user_id = Yii::app()->request->getParam('user_id', '');
- // $coupon_id = Yii::app()->request->getParam('coupon_id', '');
- // $start_time = Yii::app()->request->getParam('start_time', '');
- // $end_time = Yii::app()->request->getParam('end_time', '');
- // $need_sms = intval(Yii::app()->request->getParam('need_sms', '0'));
- // $need_zpush = intval(Yii::app()->request->getParam('need_zpush', '0'));
- // $copy = Yii::app()->request->getParam('copy', '');
- // $mongo = new MongoClient(DB_CONNETC);
- // $db = $mongo->wozhua_o2o;
- // $coll = 'admin_send_coupon_log';
- // $collection = $db->selectCollection($coll);
- // $admin = Yii::app()->user;
- // $admin_id = $admin->id;
- // $user_id = new MongoId($user_id);
- // $coupon_id = new MongoId($coupon_id);
- // $time = time();
- // $user = RUser::get($user_id);
- // // 开始与结束时间处理
- // $start_time = empty($start_time) ? $time : strtotime($start_time);
- // $end_time = empty($end_time) ? strtotime('+30 day', $start_time) : strtotime($end_time);
- // // 插入user_coupons表
- // $flag_user_coupon = Service::factory('CouponService')->giveCoupon($user_id, $coupon_id, $start_time, $end_time);
- // if (!$flag_user_coupon) {
- // CommonFn::requestAjax($flag_user_coupon, '发放优惠券失败', array());
- // }
- // // 插入admin_send_coupon_log表
- // $data = array(
- // 'admin_id' => $admin_id,
- // 'user_id' => $user_id,
- // 'coupon_id' => $coupon_id,
- // 'time' => $time
- // );
- // $flag_send_log = $collection->insert($data);
- // if ($flag_send_log['err'] != null) {
- // CommonFn::requestAjax($flag_user_coupon, '优惠券已发放,日志记录失败', array());
- // }
- // // 推送私信
- // // 前端表单已注释,该段代码会跳过
- // if ($need_zpush) {
- // $android_data = array();
- // $time_str = CommonFn::sgmdate('Y年n月d日', time(), 1);
- // $android_data['title'] = '系统通知';
- // $android_data['content'] = $copy.'<a href="http://www.wozhua.mobi/index.php?r=o2o/web/index&need_header=0">点击这里</a>预约';
- // $android_data['custom'] = array(
- // 'type' => 'user_status',
- // 'data' => array(
- // 'status' => 1,
- // 'user_id' => (string)$user_id,
- // 'time' => time(),
- // 'time_str' => $time_str,
- // ),
- // );
- // $android_data['account'] = (string)$user_id;
- // $ios_data = array();
- // $ios_data['alert'] = '系统通知:'.'恭喜你获得一张壹管家上门券';
- // $ios_data['account'] = (string)$user_id;
- // $ios_data['custom'] = array(
- // 't' => 'a',
- // 'v' => 1
- // );
- // $z_push = new ZPush();
- // $z_push->PushSingleAccount($android_data, $ios_data);
- // }
- // // 发送短信
- // // 前端表单已注释,该段代码会跳过
- // if ($need_sms) {
- // if ($user->mobile != '') {
- // Service::factory('SendSMSService')->send_sms($copy, $user->mobile);
- // } else if (!empty($user->shop_address) && isset($user->shop_address[0]['mobile'])) {
- // $mobile = $user->shop_address[0]['mobile'];
- // Service::factory('SendSMSService')->send_sms($copy, $mobile);
- // } else {
- // $criteria = new EMongoCriteria();
- // //$criteria->channel('==', 'wz_app');
- // $criteria->user('==', $user_id);
- // $criteria->sort('order_time', EMongoCriteria::SORT_DESC);
- // $cursor = ROrder::model()->findAll($criteria);
- // if ($cursor->count() == 0) {
- // CommonFn::requestAjax(false, '优惠券已发放,因用户未填手机号,短信发送失败');
- // } else {
- // foreach ($cursor as $key => $row) {
- // $address = $row->address;
- // $mobile = $address['mobile'];
- // break;
- // }
- // Service::factory('SendSMSService')->send_sms($copy, $mobile);
- // }
- // }
- // }
- // CommonFn::requestAjax(true, '优惠券已成功发放');
- // }
- }
|