ProductController.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. /**
  3. * ProductController o2o商品相关接口
  4. *
  5. * @author leeon<leeon_on@qq.com>
  6. *
  7. */
  8. class ProductController extends O2oBaseController{
  9. public function actionList(){
  10. $page = intval(Yii::app()->getRequest()->getParam("page",1));
  11. $user_id = Yii::app()->getRequest()->getParam("user_id");
  12. $holiday = explode(',',Service::factory('VariableService')->getVariable('forbidden_order_date'));
  13. //新手礼包判断
  14. if($user_id){
  15. $cache = new ARedisCache();
  16. $key = 'new_user_coupons_check'.$user_id;
  17. $new_user_coupons_check = $cache->get($key);
  18. if(!$new_user_coupons_check){
  19. if(CommonFn::isMongoId($user_id)){
  20. $user_id = new MongoId($user_id);
  21. $criteria = new EMongoCriteria();
  22. $criteria->user('==',$user_id);
  23. $coupons = UserCoupon::model()->count($criteria);
  24. if($coupons<3){
  25. //新手礼包
  26. $coupon_ids = Yii::app()->params['new_user_coupon_ids'];
  27. $start_time = time();
  28. $end_time = $start_time + 2592000;
  29. foreach ($coupon_ids as $coupon_id) {
  30. $coupon_id = new MongoId($coupon_id);
  31. @Service::factory('CouponService')->giveCoupon($user_id,$coupon_id,$start_time,$end_time);
  32. }
  33. }else{
  34. $key = 'new_user_coupons_check'.$user_id;
  35. $cache->set($key,1,604800);
  36. }
  37. }else{
  38. $key = 'new_user_coupons_check'.$user_id;
  39. $cache->set($key,1,604800);
  40. }
  41. }
  42. }
  43. $type = Yii::app()->getRequest()->getParam("type");
  44. $pagesize = Yii::app()->params['O2oProductListPageSize'];
  45. if($type){
  46. $conditions = array(
  47. 'status'=>array('==',1),
  48. 'type'=>array('==',$type),
  49. 'is_extra'=>array('==',0),
  50. );
  51. }else{
  52. $conditions = array(
  53. 'status'=>array('==',1),
  54. 'is_extra'=>array('==',0),
  55. );
  56. }
  57. $order = array(
  58. 'order'=>'desc',
  59. );
  60. $model = new Product();
  61. $pagedata = CommonFn::getPagedata($model,$page,$pagesize,$conditions,$order);
  62. $data['products'] = $pagedata['res'];
  63. $criteria = new EMongoCriteria();
  64. $criteria->status('==',1);
  65. if($type){
  66. $criteria->type('==',$type);
  67. }
  68. $criteria->is_extra('==',1);
  69. $extra_products = $model->findAll($criteria);
  70. $extra_products = CommonFn::getRows($extra_products);
  71. $extra_products = $model->parse($extra_products);
  72. $data['extra_products'] = $extra_products;
  73. CommonFn::requestAjax(true,'true',$data,200,array('sum_count' => $pagedata['sum_count'],'sum_page'=>$pagedata['sum_page'],'page_size'=>$pagedata['page_size'],'current_page'=>$pagedata['current_page'],'holiday' => $holiday));
  74. }
  75. public function actionCommentList(){
  76. $page = intval(Yii::app()->getRequest()->getParam("page",1));
  77. $user_id = Yii::app()->getRequest()->getParam("user_id");
  78. $type = Yii::app()->getRequest()->getParam("type");
  79. $pagesize = Yii::app()->params['O2oCommentListPageSize'];
  80. if($type){
  81. $conditions = array(
  82. 'status'=>array('==',1),
  83. 'type'=>array('==',intval($type)),
  84. );
  85. }else{
  86. $conditions = array(
  87. 'status'=>array('==',1),
  88. );
  89. }
  90. $order = array(
  91. 'weight'=>'desc',
  92. 'time' => 'desc'
  93. );
  94. $model = new Comment();
  95. $pagedata = CommonFn::getPagedata($model,$page,$pagesize,$conditions,$order);
  96. $data['comments'] = $pagedata['res'];
  97. 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']));
  98. }
  99. public function actionComment(){
  100. $user_id = Yii::app()->getRequest()->getParam("user_id");
  101. $order_id = Yii::app()->getRequest()->getParam("order_id");
  102. $content = Yii::app()->getRequest()->getParam("content");
  103. $pics = json_decode(Yii::app()->request->getParam('pics'),true);
  104. $score = intval(Yii::app()->getRequest()->getParam("score"));
  105. if(!$score || !$order_id || !$content || !$user_id || !CommonFn::isMongoId($user_id) || !CommonFn::isMongoId($order_id)){
  106. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  107. }
  108. if(mb_strlen(trim($content),'utf-8')<10){
  109. CommonFn::requestAjax(false,'评价最少十个字哦~~');
  110. }
  111. if($score>5 || $score<0){
  112. $score = 5;
  113. }
  114. $user = RUser::get(new MongoId($user_id));
  115. $order = ROrder::get(new MongoId($order_id));
  116. if(!$user || !$order || $order->user != $user->_id){
  117. CommonFn::requestAjax(false,CommonFn::getMessage('message','operation_not_permission'));
  118. }
  119. if(isset($order->have_comment) && $order->have_comment == 1){
  120. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','haved_comment'));
  121. }
  122. $type = 0;
  123. if(!isset($order->type) || $order->type == 0){
  124. foreach ($order->products as $product) {
  125. $product_obj = Product::get($product['product']);
  126. $type = $product_obj->type;
  127. break;
  128. }
  129. } else {
  130. $type = $order->type;
  131. }
  132. $comment = new Comment();
  133. $comment->content = $content;
  134. $comment->user = $user->_id;
  135. $comment->type = intval($type);
  136. $comment->order = $order->_id;
  137. $comment->pics = $pics;
  138. $comment->score = $score;
  139. $comment->time = time();
  140. // 保洁师信息处理
  141. // zhouxuchen 2015-12-11
  142. $technician = empty($order->technician) ? 0 : $order->technician;
  143. $comment->technician = $technician;
  144. if($comment->save()){
  145. $order->have_comment = 1;
  146. $order->update(array('have_comment'),true);
  147. $data = $comment->parseRow($comment);
  148. $start_time = time();
  149. $end_time = strtotime(date('Y-m-d',$start_time+1209600));
  150. $coupon_ids[] = '56c5914fa84ea0874f8d3820';
  151. $coupon_ids[] = '56c591b1a84ea0dd4e8d411e';
  152. $coupon_ids[] = '56c591e5a84ea04d238cc67b';
  153. $coupon_ids[] = '56c5921ca84ea0b3268bd949';
  154. Service::factory('CouponService')->giveCoupon($order->user,new MongoId($coupon_ids[mt_rand(0,3)]),$start_time,$end_time);
  155. // 保洁师操作
  156. if ($technician) {
  157. $technicianObj = TechInfo::get($technician);
  158. if ($technicianObj && $technicianObj->weixin_userid) {
  159. $url_prefix = ENVIRONMENT == 'product' ? 'http://api.wozhua.mobi' : 'http://apitest.wozhua.mobi';
  160. $wechat = O2oApp::getWechatObj();
  161. $wechat_data = array(
  162. 'touser' => $technicianObj->weixin_userid,
  163. 'msgtype' => 'news',
  164. 'agentid' => '24',
  165. 'news' => array(
  166. 'articles' => array(
  167. array(
  168. 'title' => '壹管家提示-新评价',
  169. 'description' => $technicianObj->name.'你好!你刚刚在壹管家O2O服务上收到了一条评分为'.$score.'分的订单评价,请点击查看。',
  170. 'url' => $url_prefix.'/index.php?r=o2o/myComment/info&order='.$order_id.'&user='.$technician,
  171. ),
  172. ),
  173. ),
  174. );
  175. $wechat->sendMessage($wechat_data);
  176. }
  177. // 好评数统计
  178. if ($score == 5) {
  179. $favourable_count = $technicianObj->favourable_count + 1;
  180. $technicianObj->favourable_count = $favourable_count;
  181. $technicianObj->save();
  182. }
  183. }
  184. CommonFn::requestAjax(true,CommonFn::getMessage('o2o','comment_success'),$data);
  185. }else{
  186. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','comment_failt'));
  187. }
  188. }
  189. public function actionQuestion(){
  190. $user_id = Yii::app()->getRequest()->getParam("user_id");
  191. $content = Yii::app()->getRequest()->getParam("content");
  192. $type = Yii::app()->getRequest()->getParam("type");
  193. if(!$type || !$content || !$user_id || !CommonFn::isMongoId($user_id)){
  194. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  195. }
  196. $user = RUser::get(new MongoId($user_id));
  197. if(!$user){
  198. CommonFn::requestAjax(false,CommonFn::getMessage('message','operation_not_permission'));
  199. }
  200. $question = new Question();
  201. $question->content = $content;
  202. $question->user = $user->_id;
  203. $question->type = isset($type)?intval($type):0;
  204. $question->time = time();
  205. if($question->save()){
  206. $data = $question->parseRow($question);
  207. CommonFn::requestAjax(true,CommonFn::getMessage('o2o','comment_success'),$data);
  208. }else{
  209. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','comment_failt'));
  210. }
  211. }
  212. }