ConfirmController.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. class ConfirmController extends CController{
  3. public $layout="none";
  4. public function actionPaySuccess(){
  5. $input_data = json_decode(file_get_contents("php://input"), true);
  6. $input_data = $input_data['data']['object'];
  7. if($input_data['object'] == 'charge'&& $input_data['paid']==true){
  8. if($input_data['subject'] == '附加服务'){
  9. $a_order = AppendOrder::get(new MongoId($input_data['order_no']));
  10. if($a_order && $a_order->status == 0){
  11. $a_order->charge_id = $input_data['id'];
  12. $a_order->pay_channel = $input_data['channel'];
  13. $a_order->status = 1;
  14. if($a_order->update(array('charge_id','pay_channel','status'),true)){
  15. echo 'success';
  16. die();
  17. }
  18. }
  19. echo 'fail';
  20. die();
  21. }
  22. if ($input_data['subject'] == '带我回家-支付') {
  23. $deal_order = DealOrder::get(new MongoId($input_data['order_no']));
  24. if ($deal_order && $deal_order->status == 0) {
  25. // 订单修改
  26. $deal_order->chargeid = $input_data['id'];
  27. $deal_order->pay_channel = $input_data['channel'];
  28. $deal_order->pay_time = time();
  29. $deal_order->status = 1;
  30. // 宠物修改
  31. $pet = DealPet::get($deal_order->pet);
  32. $pet->status = 3;
  33. // 商家订单增加
  34. $kennel = Kennel::get($deal_order->kennel);
  35. $kennel->order_count += 1;
  36. $kennel->save();
  37. if ($deal_order->save() && $pet->save()) {
  38. echo 'success';
  39. die;
  40. }
  41. }
  42. echo 'fail';
  43. die;
  44. }
  45. if ($input_data['subject'] == '带我回家-首款支付') {
  46. $deal_earnest_order = DealChildOrder::get(new MongoId($input_data['order_no']));
  47. if ($deal_earnest_order && $deal_earnest_order->status == 0) {
  48. $deal_earnest_order->chargeid = $input_data['id'];
  49. $deal_earnest_order->pay_channel = $input_data['channel'];
  50. $deal_earnest_order->pay_time = time();
  51. $deal_earnest_order->status = 1;
  52. // 后续操作在DealChildOrder::afterSave()中
  53. if ($deal_earnest_order->save()) {
  54. echo 'success';
  55. die;
  56. }
  57. }
  58. echo 'fail';
  59. die;
  60. }
  61. if ($input_data['subject'] == '带我回家-尾款支付') {
  62. $deal_final_order = DealChildOrder::get(new MongoId($input_data['order_no']));
  63. if ($deal_final_order && $deal_final_order->status == 0) {
  64. $deal_final_order->chargeid = $input_data['id'];
  65. $deal_final_order->pay_channel = $input_data['channel'];
  66. $deal_final_order->pay_time = time();
  67. $deal_final_order->status = 1;
  68. // 后续操作在DealChildOrder::afterSave()中
  69. if ($deal_final_order->save()) {
  70. echo 'success';
  71. die;
  72. }
  73. }
  74. echo 'fail';
  75. die;
  76. }
  77. //TODO update database
  78. $order = ROrder::get(new MongoId($input_data['order_no']));
  79. if(!$order || $order->status == -1){
  80. echo 'fail';
  81. die();
  82. }
  83. $order->charge_id = $input_data['id'];
  84. $order->pay_channel = $input_data['channel'];
  85. $order->status = 1;
  86. if($order->update(array('charge_id','pay_channel','status'),true)){
  87. $list = new ARedisList('o2o_after_pay_success');
  88. $list->push(json_encode($input_data));
  89. echo 'success';
  90. die();
  91. }else{
  92. echo 'fail';
  93. die();
  94. }
  95. }elseif($input_data['object'] == 'refund'&& $input_data['succeed']==true){
  96. //TODO update database
  97. echo 'success';
  98. die();
  99. }else{
  100. echo 'fail';
  101. die();
  102. }
  103. }
  104. public function actionCheckMobile(){
  105. $mobile = Yii::app()->getRequest()->getParam("mobile",'');
  106. if($mobile && preg_match("/\d{11}/",$mobile)){
  107. $criteria = new EMongoCriteria();
  108. $criteria->mobile('==',$mobile);
  109. $user = Mobile::model()->find($criteria);
  110. if($user){
  111. echo 'fail';
  112. }else{
  113. $userAr = new Mobile();
  114. $userAr->mobile = $mobile;
  115. if($userAr->save()){
  116. echo 'success';
  117. }else{
  118. echo 'fail';
  119. }
  120. }
  121. }else{
  122. echo 'fail';
  123. }
  124. }
  125. public function actionSyncCode(){
  126. echo ENVIRONMENT."\n";
  127. if(ENVIRONMENT == 'product'){
  128. exec("/data/php/webshell/SyncCodeOnline.sh");
  129. echo 'success';
  130. }elseif(ENVIRONMENT == 'develop'){
  131. exec("/data/php/webshell/SyncCodeDev.sh");
  132. echo 'success';
  133. }else{
  134. exec("/data/php/webshell/SyncCode.sh");
  135. echo 'success';
  136. }
  137. }
  138. public function actionConvVideo(){
  139. $input_data = json_decode(file_get_contents("php://input"), true);
  140. file_put_contents('/data/qiniulog.json',var_export($input_data,true),FILE_APPEND);
  141. $id = $input_data['id'];
  142. if($id){
  143. $cache = new ARedisCache();
  144. $topic_id = $cache->get($id);
  145. $topic = Topic::get(new MongoId($topic_id));
  146. $qiniu_config = Yii::app()->params['qiniuConfig'];
  147. if($topic && isset($topic->video)){
  148. $key = str_replace('http://'.$qiniu_config['video'].'.qiniudn.com/','',$topic->video['url']);
  149. $new_key = 'af'.$key;
  150. $topic->video['url'] = 'http://'.$qiniu_config['video'].'.qiniudn.com/'.$new_key;
  151. $topic->update(array('video'),true);
  152. }
  153. }
  154. }
  155. public function actionUserFollow(){
  156. $path = Yii::getPathOfAlias('application');
  157. require_once($path."/vendors/weixin/wechat.class.php");
  158. $wxConfig = Yii::app()->params['wxConfig'];
  159. $options = array(
  160. 'token'=>'kkzH33eWEuP383uuKuQ366uKPwwzpE37', //填写你设定的key
  161. 'encodingaeskey'=>'2MACh0Ww6nDHDtH4pHEwgfRnCnctGVtNA0Bumvw5nkA', //填写加密用的EncodingAESKey
  162. 'appid'=>$wxConfig['appId'], //填写高级调用功能的app id
  163. 'appsecret'=>$wxConfig['appSecret'], //填写高级调用功能的密钥
  164. );
  165. $weObj = new Wechat($options);
  166. $weObj->valid();
  167. $menu = $weObj->getMenu();
  168. $newmenu = array(
  169. "button"=>
  170. array(
  171. array('type'=>'view','name'=>'上门服务','url'=>'http://www.wozhua.mobi/o2o/web/index'),
  172. array('type'=>'view','name'=>'下载APP','url'=>'http://t.cn/R2DKttW'),
  173. array('type'=>'click','name'=>'壹管家过年','key'=>'WOZHUA_STAR'),
  174. )
  175. );
  176. $result = $weObj->createMenu($newmenu);
  177. $data = $weObj->getRev()->getRevData();
  178. if(isset($data['FromUserName']) && !empty($data['FromUserName'])){
  179. if($data['Event'] == 'subscribe'){
  180. // @file_put_contents('/data/subscribe.log',$data['FromUserName'].'--'.$data['Event']."\n",FILE_APPEND);
  181. $criteria = new EMongoCriteria();
  182. $criteria->wx_pub_openid('==',$data['FromUserName']);
  183. $user = RUser::model()->find($criteria);
  184. if($user){
  185. $user->wx_have_follow = 1;
  186. $user->update(array('wx_have_follow'),true);
  187. }else{
  188. // @file_put_contents('/data/subscribe_error.log',$data['FromUserName'].'--'.$data['Event']."\n",FILE_APPEND);
  189. }
  190. }elseif($data['Event']=='unsubscribe'){
  191. // @file_put_contents('/data/subscribe.log',$data['FromUserName'].'--'.$data['Event']."\n",FILE_APPEND);
  192. $criteria = new EMongoCriteria();
  193. $criteria->wx_pub_openid('==',$data['FromUserName']);
  194. $user = RUser::model()->find($criteria);
  195. if($user){
  196. $user->wx_have_follow = 0;
  197. $user->update(array('wx_have_follow'),true);
  198. }else{
  199. // @file_put_contents('/data/subscribe_error.log',$data['FromUserName'].'--'.$data['Event']."\n",FILE_APPEND);
  200. }
  201. }elseif($data['Event']=='CLICK' && $data['EventKey']=='WOZHUA_STAR'){
  202. $criteria = new EMongoCriteria();
  203. $criteria->wx_pub_openid('==',$data['FromUserName']);
  204. $user = RUser::model()->find($criteria);
  205. if($user && $user->wx_have_follow != 1){
  206. $user->wx_have_follow = 1;
  207. $user->update(array('wx_have_follow'),true);
  208. }
  209. $weObj->text("晒萌宠照,赢Apple watch,参与活动请点击:http://t.cn/RbgjgPK")->reply();
  210. }
  211. if(time() - $data['CreateTime'] < 2 && $data['Event'] == 'subscribe'){
  212. $weObj->text("晒萌宠照,赢Apple watch,参与活动请点击:http://t.cn/RbgjgPK")->reply();
  213. }
  214. }
  215. }
  216. }