CommonController.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. <?php
  2. /**
  3. * 公用API
  4. */
  5. class CommonController extends ApiBaseController {
  6. public function beforeAction($action){
  7. $weixin_use = array('staticsource','getsubcity', 'getallcity');
  8. if(in_array(strtolower($action->id),$weixin_use)){
  9. return true;
  10. }
  11. return $this->verify();
  12. }
  13. public function actionDiscover(){
  14. $page = intval(Yii::app()->getRequest()->getParam("page",1));
  15. $page = $page?$page:1;
  16. $type = Yii::app()->request->getParam('type','');
  17. $user_id = Yii::app()->request->getParam('user_id','');
  18. $device_id = Yii::app()->request->getParam('device_id','');
  19. if($type == 'digest'){
  20. $city_info = json_decode(Yii::app()->request->getParam('city_info'),true);
  21. //防止city_info出现非法数据
  22. if(!isset($city_info['province'])){
  23. $city_info['province'] = '';
  24. $city_info['city'] = '';
  25. $city_info['area'] = '';
  26. }elseif(!isset($city_info['city'])){
  27. $city_info['city'] = '';
  28. $city_info['area'] = '';
  29. }elseif(!isset($city_info['area'])){
  30. $city_info['area'] = '';
  31. }
  32. $z_User = new ZUser();
  33. $user = $z_User->idExist($user_id);
  34. $z_group = new ZGroup();
  35. $res_topics = array();
  36. $actiontime = CommonFn::getFirstTime(ActionTimeRedis::TYPE_GET_INDEX,$device_id,$page);
  37. $_user = null;
  38. if($user){
  39. $_user = $user['_id'];
  40. }
  41. $picked_groups = $z_group->get_user_picked_groups($_user,$city_info,false,true);
  42. $picked_groups = $z_group->filter_special($picked_groups);
  43. $parsed_groups = array();
  44. foreach($picked_groups as $picked_group){
  45. $parsed_groups[] = new MongoId($picked_group['_id']);
  46. }
  47. $pagesize = Yii::app()->params['indexPageSize'];
  48. $conditions = array(
  49. 'group'=>array('in',$parsed_groups),
  50. 'status'=>array('==',1),
  51. 'time'=>array('<=',$actiontime)
  52. );
  53. $order = array(
  54. 'time'=>'desc',
  55. );
  56. $model = new Topic();
  57. $pagedata = CommonFn::getPagedata($model,$page,$pagesize,$conditions,$order,false,false);
  58. $topics = $pagedata['res'];
  59. foreach($topics as $topic){
  60. $_topic = $model->parseRow($topic,array('id','content','city_info','time','time_str','group','visit_count','reply_count','fav_count','like_count','user','pics','voice','video','last_post_time','last_post_time_str'));
  61. if($user){
  62. $z_like = new ZLike();
  63. $like = $z_like->getLikeByLikeObj((string)$user['_id'],$_topic['id']);
  64. if(empty($like)){
  65. $_topic['is_liked'] = false;
  66. }else{
  67. $_topic['is_liked'] = true;
  68. }
  69. }else{
  70. $_topic['is_liked'] = false;
  71. }
  72. $res_topics[] = $_topic;
  73. }
  74. CommonFn::requestAjax(true,'',$res_topics,200,array('sum_count' => $pagedata['sum_count'],'sum_page'=>$pagedata['sum_page'],'page_size'=>$pagedata['page_size'],'current_page'=>$pagedata['current_page']));
  75. }else{
  76. }
  77. }
  78. //推荐帖子
  79. public function actionIndex(){
  80. $page = intval(Yii::app()->getRequest()->getParam("page",1));
  81. $city_info = json_decode(Yii::app()->request->getParam('city_info'),true);
  82. if(empty($page)){
  83. $page = 1;
  84. }
  85. $user_id = Yii::app()->request->getParam('user_id','');
  86. $device_id = Yii::app()->request->getParam('device_id','');
  87. //防止city_info出现非法数据
  88. if(!isset($city_info['province'])){
  89. $city_info['province'] = '';
  90. $city_info['city'] = '';
  91. $city_info['area'] = '';
  92. }elseif(!isset($city_info['city'])){
  93. $city_info['city'] = '';
  94. $city_info['area'] = '';
  95. }elseif(!isset($city_info['area'])){
  96. $city_info['area'] = '';
  97. }
  98. $z_User = new ZUser();
  99. $user = $z_User->idExist($user_id);
  100. $z_group = new ZGroup();
  101. $z_topic = new ZTopic();
  102. $arr = array();
  103. $actiontime = CommonFn::getFirstTime(ActionTimeRedis::TYPE_GET_INDEX,$device_id,$page);
  104. $_user = null;
  105. if($user){
  106. $_user = $user['_id'];
  107. }
  108. $picked_groups = $z_group->get_user_picked_groups($_user,$city_info,false,true);
  109. $picked_groups = $z_group->filter_special($picked_groups);
  110. $parsed_groups = array();
  111. foreach($picked_groups as $picked_group){
  112. $parsed_groups[] = new MongoId($picked_group['_id']);
  113. }
  114. $pagesize = Yii::app()->params['indexPageSize'];
  115. $conditions = array(
  116. 'group'=>array('in',$parsed_groups),
  117. 'status'=>array('==',1),
  118. 'time'=>array('<=',$actiontime)
  119. );
  120. $order = array(
  121. 'time'=>'desc',
  122. );
  123. $model = new Topic();
  124. $pagedata = CommonFn::getPagedata($model,$page,$pagesize,$conditions,$order,false,false);
  125. $topics = $pagedata['res'];
  126. $front_topic_user = '';
  127. $last_topics = array();
  128. foreach($topics as $topic){
  129. $_topic = $model->parseRow($topic,array('id','content','city_info','time','time_str','group','visit_count','reply_count','fav_count','like_count','user','pics','voice','video','last_post_time','last_post_time_str'));
  130. if($user){
  131. $z_like = new ZLike();
  132. $like = $z_like->getLikeByLikeObj((string)$user['_id'],$_topic['id']);
  133. if(empty($like)){
  134. $_topic['is_liked'] = false;
  135. }else{
  136. $_topic['is_liked'] = true;
  137. }
  138. }else{
  139. $_topic['is_liked'] = false;
  140. }
  141. if($_topic['user']['id'] == $front_topic_user){
  142. $last_topics[] = array('type'=>'topic','item'=>$_topic);
  143. }else{
  144. $front_topic_user = $_topic['user']['id'];
  145. $arr[] = array('type'=>'topic','item'=>$_topic);
  146. }
  147. }
  148. $arr = array_merge($arr,$last_topics);
  149. CommonFn::requestAjax(true,'',$arr,200,array('sum_count' => $pagedata['sum_count'],'sum_page'=>$pagedata['sum_page'],'page_size'=>$pagedata['page_size'],'current_page'=>$pagedata['current_page']));
  150. }
  151. //首页轮播的图
  152. public function actionSlide(){
  153. $city_info = json_decode(Yii::app()->request->getParam('city_info'),true);
  154. $city_info_pro = isset($city_info['province'])?$city_info['province']:'';
  155. $criteria = new EMongoCriteria();
  156. $criteria->status('==', 1);
  157. if(CommonFn::compareVersion('2.7.2',Yii::app()->request->getParam('app_version',''))){
  158. $criteria->type('!=','subject');
  159. }
  160. $criteria->sort('order', EMongoCriteria::SORT_DESC);
  161. $cursor = Slide::model()->findAll($criteria);
  162. $rows = CommonFn::getRows($cursor);
  163. foreach ($rows as $key => $value) {
  164. if(isset($value['city_info'])&&isset($value['city_info']['province'])&&$value['city_info']['province']!=$city_info_pro&&$value['city_info']['province']!=''){
  165. unset($rows[$key]);
  166. }elseif(isset($value['end_time'])&&$value['end_time']<=time()&&$value['end_time']!==0&&!empty($value['end_time'])){
  167. unset($rows[$key]);
  168. }
  169. }
  170. $parsedRows = Slide::model()->parse($rows);
  171. $parsedRows = array_values($parsedRows);
  172. CommonFn::requestAjax(true,'',$parsedRows);
  173. }
  174. //积分规则
  175. public function actionScoreRule(){
  176. $score_rule = Yii::app()->params['score_rule'];
  177. $data = array();
  178. foreach ($score_rule as $value) {
  179. $data[] = $value;
  180. }
  181. CommonFn::requestAjax(true,'',$data);
  182. }
  183. //发帖选择圈子接口
  184. public function actionTopicGroupList(){
  185. $user_id = Yii::app()->request->getParam('user_id');
  186. if(!CommonFn::isMongoId($user_id)){
  187. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  188. }
  189. $user = RUser::get(new MongoId($user_id));
  190. if(!$user){
  191. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  192. }
  193. $follow_groups = $user->groups;
  194. $criteria = new EMongoCriteria();
  195. $criteria->can_topic('==',1);
  196. $criteria->status('==',1);
  197. $criteria->sort('order', EMongoCriteria::SORT_DESC);
  198. $cursor = Group::model()->findAll($criteria);
  199. $first_section = array();
  200. $second_section = array();
  201. foreach ($cursor as $key => $value) {
  202. if(in_array((string)$value->_id,$follow_groups)){
  203. $first_section[] = array('id'=>(string)$value->_id,'name'=>(string)$value->name,'avatar'=>$value->avatar);
  204. }elseif(!isset($value->city_info['city']) || empty($value->city_info['city']) || (isset($user->city_info['city']) && $value->city_info['city'] == $user->city_info['city'])){
  205. $second_section[] = array('id'=>(string)$value->_id,'name'=>(string)$value->name,'avatar'=>$value->avatar);
  206. }
  207. }
  208. $group_list = array_merge($first_section,$second_section);
  209. CommonFn::requestAjax(true,'success',array('group_list'=>$group_list));
  210. }
  211. //客户端手动更新
  212. public function actionUpdateApp(){
  213. $version = Yii::app()->request->getParam('app_version');
  214. $app_client_id = Yii::app()->request->getParam('app_client_id');
  215. $channel = Yii::app()->request->getParam('channel','');
  216. $network_type = Yii::app()->request->getParam('network_type','');
  217. if(empty($version)||empty($app_client_id)){
  218. CommonFn::requestAjax(false,CommonFn::getMessage('message','request_illegal'));
  219. }
  220. if($app_client_id == 2){
  221. $leatest_version = Service::factory('VariableService')->getVariable('android_new_version');
  222. }elseif($app_client_id == 1){
  223. $leatest_version = Service::factory('VariableService')->getVariable('ios_new_version');
  224. }else{
  225. CommonFn::requestAjax(false,CommonFn::getMessage('message','request_illegal'));
  226. }
  227. if($network_type == 'wifi' && CommonFn::compareVersion($leatest_version,Yii::app()->request->getParam('app_version',''))){
  228. if($app_client_id == 2){
  229. $channel_apk = Yii::app()->params['channel_apk'];
  230. if(isset($channel_apk[$channel])){
  231. $download_url = $channel_apk[$channel];
  232. }else{
  233. $download_url = $channel_apk['guanwang'];
  234. }
  235. $info = array('new_version'=>$leatest_version,'size' => '34M','download'=>$download_url,'message'=>'新爪爪出来咯,快来找我玩≧△≦');
  236. }else{
  237. $info = array('new_version'=>$leatest_version,'message'=>'新爪爪出来咯,快来找我玩≧△≦');
  238. }
  239. CommonFn::requestAjax(true,CommonFn::getMessage('message', 'have_newer'),$info);
  240. }else{
  241. CommonFn::requestAjax(false,'');
  242. }
  243. }
  244. //获取全部的城市信息
  245. public function actionGetAllCity(){
  246. $criteria = new EMongoCriteria();
  247. $criteria->sort('parent_province_id', EMongoCriteria::SORT_ASC);
  248. $criteria->sort('parent_city_id', EMongoCriteria::SORT_ASC);
  249. $cursor = CityLib::model()->findAll($criteria);
  250. $res = CommonFn::getRowsFromCursor($cursor);
  251. $province = array();
  252. $city = array();
  253. $area = array();
  254. $keyMap = array();
  255. foreach ($res as $item) {
  256. $keyMap[$item['_id']] = $item['name'];
  257. }
  258. foreach ($res as $item) {
  259. $parent = $item['parent_area_id'];
  260. $level = 4;
  261. if ($parent == 0) {
  262. $parent = $item['parent_city_id'];
  263. $level = 3;
  264. }
  265. if ($parent == 0) {
  266. $parent = $item['parent_province_id'];
  267. $level = 2;
  268. }
  269. if ($parent == 0) {
  270. $level = 1;
  271. }
  272. if ($level == 1) {
  273. $province[] = $item['name'];
  274. } else if ($level == 2) {
  275. $city[$keyMap[$item['parent_province_id']]][] = $item['name'];
  276. } else if ($level == 3) {
  277. $area[$keyMap[$item['parent_city_id']]][] = $item['name'];
  278. }
  279. }
  280. $data = array('p' => $province, 'c' => $city, 'a' => $area);
  281. CommonFn::requestAjax(true, CommonFn::getMessage('message', 'operation_success'), $data, 200);
  282. }
  283. //获取城市级联信息
  284. public function actionGetSubCity(){
  285. $address_info = json_decode(Yii::app()->request->getParam('address_info'),true);
  286. if(!isset($address_info['province']) || $address_info['province'] == '未知'){
  287. $address_info = array();
  288. }
  289. $province = array();
  290. $city = array();
  291. $area = array();
  292. $z_citylib = new ZCityLib();
  293. if(isset($address_info['province'])&&$address_info['province']){
  294. $province = $z_citylib->getSubCity(1);
  295. foreach ($province as $key => $value) {
  296. if($value['name'] == $address_info['province']){
  297. $province[$key]['is_selected'] = 1;
  298. $city = $z_citylib->getSubCity($value['city_code']);
  299. foreach ($city as $sub_key => $sub_value) {
  300. if(isset($address_info['city']) && $sub_value['name'] == $address_info['city']){
  301. $have_selected = true;
  302. $city[$sub_key]['is_selected'] = 1;
  303. $area = $z_citylib->getSubCity($sub_value['city_code']);
  304. foreach ($area as $grand_key => $grand_value) {
  305. if($grand_value['name'] == $address_info['area']){
  306. $area[$grand_key]['is_selected'] = 1;
  307. }else{
  308. $area[$grand_key]['is_selected'] = 0;
  309. }
  310. }
  311. }else{
  312. $city[$sub_key]['is_selected'] = 0;
  313. }
  314. }
  315. if(!isset($have_selected)){
  316. $city[0]['is_selected'] = 1;
  317. $area = $z_citylib->getSubCity($city[0]['city_code']);
  318. foreach ($area as $grand_key => $grand_value) {
  319. if($grand_key == 0){
  320. $area[$grand_key]['is_selected'] = 1;
  321. }else{
  322. $area[$grand_key]['is_selected'] = 0;
  323. }
  324. }
  325. }
  326. }else{
  327. $province[$key]['is_selected'] = 0;
  328. }
  329. }
  330. }else{
  331. $province = $z_citylib->getSubCity(1);
  332. foreach ($province as $key => $value) {
  333. if($value['name'] == '上海市'){
  334. $province[$key]['is_selected'] = 1;
  335. }else{
  336. $province[$key]['is_selected'] = 0;
  337. }
  338. }
  339. foreach ($province as $key => $value) {
  340. if($value['name'] == '上海市'){
  341. $city = $z_citylib->getSubCity($value['city_code']);
  342. foreach ($city as $sub_key => $sub_value) {
  343. if($sub_value['name'] == '上海市'){
  344. $city[$sub_key]['is_selected'] = 1;
  345. }else{
  346. $city[$sub_key]['is_selected'] = 0;
  347. }
  348. }
  349. $area = $z_citylib->getSubCity($city[0]['city_code']);
  350. foreach ($area as $sub_key => $sub_value) {
  351. if($sub_value['name'] == '上海市'){
  352. $area[$sub_key]['is_selected'] = 1;
  353. }else{
  354. $area[$sub_key]['is_selected'] = 0;
  355. }
  356. }
  357. }
  358. }
  359. }
  360. //容错处理,防止客户端上传错误城市
  361. if(empty($province)){
  362. $province = $z_citylib->getSubCity(1);
  363. foreach ($province as $key => $value) {
  364. if($value['name'] == '上海市'){
  365. $province[$key]['is_selected'] = 1;
  366. }else{
  367. $province[$key]['is_selected'] = 0;
  368. }
  369. }
  370. }
  371. if(empty($city)){
  372. foreach ($province as $key => $value) {
  373. if($value['is_selected'] == 1){
  374. $temp_code = $value['city_code'];
  375. }
  376. }
  377. $city = $z_citylib->getSubCity($temp_code);
  378. if(empty($city)){
  379. $temp['name'] = '';
  380. $city[] = $temp;
  381. }
  382. $city[0]['is_selected'] = 1;
  383. }
  384. if(empty($area)){
  385. foreach ($city as $key => $value) {
  386. if($value['is_selected'] == 1){
  387. $temp_code = $value['city_code'];
  388. }
  389. }
  390. $area = $z_citylib->getSubCity($temp_code);
  391. if(empty($area)){
  392. $temp['name'] = '';
  393. $area[] = $temp;
  394. }
  395. $area[0]['is_selected'] = 1;
  396. }
  397. foreach ($province as $key => $value) {
  398. unset($province[$key]['city_code']);
  399. }
  400. foreach ($city as $key => $value) {
  401. unset($city[$key]['city_code']);
  402. }
  403. foreach ($area as $key => $value) {
  404. unset($area[$key]['city_code']);
  405. }
  406. $data['provinces'] = $province;
  407. $data['citys'] = $city;
  408. $data['areas'] = $area;
  409. CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$data,200);
  410. }
  411. public function actionPay(){
  412. $pay_channel = Yii::app()->getRequest()->getParam("pay_channel");
  413. $order_id = Yii::app()->getRequest()->getParam("order_id");
  414. $callback = Yii::app()->getRequest()->getParam("callback");
  415. $amount = 1;
  416. $result = Service::factory('PayService')->Pay($pay_channel,$amount);
  417. if($callback){
  418. echo $callback."($result)";
  419. die();
  420. }
  421. echo $result;
  422. }
  423. public function actionRetrieve(){
  424. $charge_id = Yii::app()->getRequest()->getParam("charge_id");
  425. $result = Service::factory('PayService')->retrieve($charge_id);
  426. echo $result;
  427. }
  428. public function actionInit(){
  429. $cache = new ARedisCache();
  430. $key = 'data_cache_common_init';
  431. $data_cache = $cache->get($key);
  432. $data = array();
  433. if($data_cache){
  434. $data = unserialize($data_cache);
  435. }else{
  436. $host = ENVIRONMENT=='product'?'www.yiguanjia.me':'wwwtest.yiguanjia.me';
  437. $hot_keys = trim(Service::factory('VariableService')->getVariable('hot_keywords'));
  438. $hot_keys = explode("\n",$hot_keys);
  439. $criteria = new EMongoCriteria();
  440. $criteria->time('<=',time());
  441. $criteria->limit(1);
  442. $criteria->sort('time',EMongoCriteria::SORT_DESC);
  443. $r_card = RecommendCard::model()->findAll($criteria);
  444. $new_card_time = 0;
  445. foreach ($r_card as $key => $value) {
  446. $new_card_time = $value->time;
  447. break;
  448. }
  449. $subject = new Subject();
  450. $criteria = new EMongoCriteria();
  451. $criteria->is_recommend('==', 1);
  452. $criteria->sort('rank',EMongoCriteria::SORT_DESC);
  453. $criteria->status('==', 1);
  454. $criteria->limit(8);
  455. $res = $subject->findAll($criteria);
  456. $data['recommend_subject'] = array_values($subject->parse($res));
  457. $data['limit_conf'] = Yii::app()->params['limit_conf'];
  458. $data['new_user_coupons_value'] = Yii::app()->params['new_user_coupons_value']?Yii::app()->params['new_user_coupons_value']:0;
  459. $data['app_video_conf'] = Yii::app()->params['app_video_conf'];
  460. $data['new_card_time'] = $new_card_time;
  461. $data['hot_keywords'] = $hot_keys;
  462. $data['report_reason'] = Yii::app()->params['report_reason'];
  463. $data['certify_url'] = isset(Yii::app()->params['certify_url'])?Yii::app()->params['certify_url']:'';
  464. $data['tool_box_url'] = 'http://www.wozhua.mobi/webapp/pet';
  465. $data['deal_url'] = 'http://'.$host.'/o2o/web/index/deal?need_header=0';
  466. $pic_edit = Service::factory('VariableService')->getVariable('pic_edit');
  467. $data['pic_edit'] = intval($pic_edit);
  468. $data['topic_report_reason'] = Yii::app()->params['topic_report_reason'];
  469. $data['user_report_reason'] = Yii::app()->params['user_report_reason'];
  470. $data['kefu_user'] = Yii::app()->params['kefu_user'];
  471. $data['enable_clear_cache'] = 0;
  472. $updata_message = array('title'=>'有新版本发布了','content' => CommonFn::getMessage('message','have_newer'));
  473. $data['updata_message'] = $updata_message;
  474. $cache->set($key,serialize($data),300);
  475. }
  476. $close_versions = explode(',',Service::factory('VariableService')->getVariable('close_versions'));
  477. if( in_array(Yii::app()->request->getParam('app_version',''),$close_versions)){
  478. $data['foreign_link_open'] = 0;
  479. $data['lottery_open'] = 0;
  480. }else{
  481. $data['lottery_open'] = 1;
  482. $data['foreign_link_open'] = 1;
  483. }
  484. $data['enable_clear_cache'] = 1;
  485. $data['certify_type'] = Yii::app()->params['new_certify_type'];
  486. //最新版本
  487. $app_client_id = Yii::app()->request->getParam('app_client_id');
  488. $leatest_version = '';
  489. if($app_client_id == 2){
  490. $leatest_version = Service::factory('VariableService')->getVariable('android_new_version');
  491. }elseif($app_client_id == 1){
  492. $leatest_version = Service::factory('VariableService')->getVariable('ios_new_version');
  493. }
  494. $data['new_app_version'] = $leatest_version;
  495. CommonFn::requestAjax(true,'',$data);
  496. }
  497. public function actionGetUrl(){
  498. $url_id = Yii::app()->getRequest()->getParam("url_id");
  499. $data['url'] = Service::factory('VariableService')->getVariable($url_id);
  500. $success = empty($data) ? false : true;
  501. $message = $success ? '' : 'URL不存在';
  502. CommonFn::requestAjax($success, $message, $data);
  503. }
  504. public function actionReport() {
  505. $user = Yii::app()->request->getParam('user_id', '');
  506. $reason = Yii::app()->request->getParam('reason', '');
  507. $time = time();
  508. $to_user_id = Yii::app()->request->getParam('to_user_id', '');
  509. $topic_id = Yii::app()->request->getParam('topic_id', '');
  510. if ((empty($to_user_id) && empty($topic_id)) // 举报对象
  511. || empty($user) || empty($reason)) { // 举报用户和理由
  512. CommonFn::requestAjax(false, '参数不全', array());
  513. }
  514. $type = empty($to_user_id) ? 'topic' : 'user';
  515. $object = empty($to_user_id) ? $topic_id : $to_user_id;
  516. $object_id = new MongoId($object);
  517. $user_id = new MongoId($user);
  518. $reports = Report::getByUser($user_id, $object_id);
  519. if ($reports != false) {
  520. $reports->next();
  521. $report = $reports->current();
  522. if ($report->status == 0) {
  523. CommonFn::requestAjax(false, '已经举报过了哦', array());
  524. }
  525. }
  526. $report = new Report();
  527. $report->type = $type;
  528. $report->object = $object_id;
  529. $report->user = $user_id;
  530. $report->reason = $reason;
  531. $report->time = $time;
  532. $success = $report->insert();
  533. $message = $success ? '举报成功' : '举报失败';
  534. CommonFn::requestAjax($success, $message, array());
  535. }
  536. public function actionCustomeParam() {
  537. $user_id = Yii::app()->request->getParam('user_id', '');
  538. $device_id = Yii::app()->request->getParam('device_id');
  539. $data['new_user_coupons_value'] = Yii::app()->params['new_user_coupons_value']?Yii::app()->params['new_user_coupons_value']:0;
  540. if($user_id){
  541. $cache = new ARedisCache();
  542. $key = 'new_user_coupons_check'.$user_id;
  543. $new_user_coupons_check = $cache->get($key);
  544. if(!$new_user_coupons_check){
  545. if(CommonFn::isMongoId($user_id)){
  546. $user_id = new MongoId($user_id);
  547. $criteria = new EMongoCriteria();
  548. $criteria->user('==',$user_id);
  549. $coupons = UserCoupon::model()->count($criteria);
  550. if($coupons<1){
  551. $data['get_user_coupons'] = 1;
  552. }else{
  553. $data['get_user_coupons'] = 0;
  554. }
  555. }else{
  556. $data['get_user_coupons'] = 0;
  557. }
  558. }else{
  559. $data['get_user_coupons'] = 0;
  560. }
  561. }elseif ($device_id) {
  562. $cache = new ARedisCache();
  563. $key = 'new_user_coupons_check'.$device_id;
  564. $new_user_coupons_check = $cache->get($key);
  565. if(!$new_user_coupons_check){
  566. $criteria = new EMongoCriteria();
  567. $criteria->user_device_id('==',$device_id);
  568. $coupons = UserCoupon::model()->count($criteria);
  569. if($coupons<1){
  570. $data['get_user_coupons'] = 1;
  571. }else{
  572. $data['get_user_coupons'] = 0;
  573. }
  574. }
  575. }else{
  576. $data['get_user_coupons'] = 0;
  577. }
  578. CommonFn::requestAjax(true,'success', $data);
  579. }
  580. public function actionStaticSource() {
  581. $key = Yii::app()->request->getParam('key');
  582. $static = StaticSource::getByKey($key);
  583. if (!$static) {
  584. CommonFn::requestAjax(false, '资源不存在', []);
  585. } else {
  586. CommonFn::requestAjax(true, '', [
  587. 'id' => (string)$static->_id,
  588. 'key' => $static->key,
  589. 'title' => $static->title? $static->title : '',
  590. 'content' => $static->content,
  591. ]);
  592. }
  593. }
  594. }