123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- <?php
- class ConfirmController extends CController{
- public $layout="none";
- public function actionPaySuccess(){
- $input_data = json_decode(file_get_contents("php://input"), true);
- $input_data = $input_data['data']['object'];
- if($input_data['object'] == 'charge'&& $input_data['paid']==true){
- if($input_data['subject'] == '附加服务'){
- $a_order = AppendOrder::get(new MongoId($input_data['order_no']));
- if($a_order && $a_order->status == 0){
- $a_order->charge_id = $input_data['id'];
- $a_order->pay_channel = $input_data['channel'];
- $a_order->status = 1;
- if($a_order->update(array('charge_id','pay_channel','status'),true)){
- echo 'success';
- die();
- }
- }
- echo 'fail';
- die();
- }
- if ($input_data['subject'] == '带我回家-支付') {
- $deal_order = DealOrder::get(new MongoId($input_data['order_no']));
- if ($deal_order && $deal_order->status == 0) {
- // 订单修改
- $deal_order->chargeid = $input_data['id'];
- $deal_order->pay_channel = $input_data['channel'];
- $deal_order->pay_time = time();
- $deal_order->status = 1;
- // 宠物修改
- $pet = DealPet::get($deal_order->pet);
- $pet->status = 3;
- // 商家订单增加
- $kennel = Kennel::get($deal_order->kennel);
- $kennel->order_count += 1;
- $kennel->save();
- if ($deal_order->save() && $pet->save()) {
- echo 'success';
- die;
- }
- }
- echo 'fail';
- die;
- }
- if ($input_data['subject'] == '带我回家-首款支付') {
- $deal_earnest_order = DealChildOrder::get(new MongoId($input_data['order_no']));
- if ($deal_earnest_order && $deal_earnest_order->status == 0) {
- $deal_earnest_order->chargeid = $input_data['id'];
- $deal_earnest_order->pay_channel = $input_data['channel'];
- $deal_earnest_order->pay_time = time();
- $deal_earnest_order->status = 1;
- // 后续操作在DealChildOrder::afterSave()中
- if ($deal_earnest_order->save()) {
- echo 'success';
- die;
- }
- }
- echo 'fail';
- die;
- }
- if ($input_data['subject'] == '带我回家-尾款支付') {
- $deal_final_order = DealChildOrder::get(new MongoId($input_data['order_no']));
- if ($deal_final_order && $deal_final_order->status == 0) {
- $deal_final_order->chargeid = $input_data['id'];
- $deal_final_order->pay_channel = $input_data['channel'];
- $deal_final_order->pay_time = time();
- $deal_final_order->status = 1;
- // 后续操作在DealChildOrder::afterSave()中
- if ($deal_final_order->save()) {
- echo 'success';
- die;
- }
- }
- echo 'fail';
- die;
- }
- //TODO update database
- $order = ROrder::get(new MongoId($input_data['order_no']));
- if(!$order || $order->status == -1){
- echo 'fail';
- die();
- }
- $order->charge_id = $input_data['id'];
- $order->pay_channel = $input_data['channel'];
- $order->status = 1;
- if($order->update(array('charge_id','pay_channel','status'),true)){
- $list = new ARedisList('o2o_after_pay_success');
- $list->push(json_encode($input_data));
- echo 'success';
- die();
- }else{
- echo 'fail';
- die();
- }
- }elseif($input_data['object'] == 'refund'&& $input_data['succeed']==true){
- //TODO update database
- echo 'success';
- die();
- }else{
- echo 'fail';
- die();
- }
- }
- public function actionCheckMobile(){
- $mobile = Yii::app()->getRequest()->getParam("mobile",'');
- if($mobile && preg_match("/\d{11}/",$mobile)){
- $criteria = new EMongoCriteria();
- $criteria->mobile('==',$mobile);
- $user = Mobile::model()->find($criteria);
- if($user){
- echo 'fail';
- }else{
- $userAr = new Mobile();
- $userAr->mobile = $mobile;
- if($userAr->save()){
- echo 'success';
- }else{
- echo 'fail';
- }
- }
- }else{
- echo 'fail';
- }
- }
- public function actionSyncCode(){
- echo ENVIRONMENT."\n";
- if(ENVIRONMENT == 'product'){
- exec("/data/php/webshell/SyncCodeOnline.sh");
- echo 'success';
- }elseif(ENVIRONMENT == 'develop'){
- exec("/data/php/webshell/SyncCodeDev.sh");
- echo 'success';
- }else{
- exec("/data/php/webshell/SyncCode.sh");
- echo 'success';
- }
- }
- public function actionConvVideo(){
- $input_data = json_decode(file_get_contents("php://input"), true);
- file_put_contents('/data/qiniulog.json',var_export($input_data,true),FILE_APPEND);
- $id = $input_data['id'];
- if($id){
- $cache = new ARedisCache();
- $topic_id = $cache->get($id);
- $topic = Topic::get(new MongoId($topic_id));
- $qiniu_config = Yii::app()->params['qiniuConfig'];
- if($topic && isset($topic->video)){
- $key = str_replace('http://'.$qiniu_config['video'].'.qiniudn.com/','',$topic->video['url']);
- $new_key = 'af'.$key;
- $topic->video['url'] = 'http://'.$qiniu_config['video'].'.qiniudn.com/'.$new_key;
- $topic->update(array('video'),true);
- }
- }
- }
- public function actionUserFollow(){
- $path = Yii::getPathOfAlias('application');
- require_once($path."/vendors/weixin/wechat.class.php");
- $wxConfig = Yii::app()->params['wxConfig'];
- $options = array(
- 'token'=>'kkzH33eWEuP383uuKuQ366uKPwwzpE37', //填写你设定的key
- 'encodingaeskey'=>'2MACh0Ww6nDHDtH4pHEwgfRnCnctGVtNA0Bumvw5nkA', //填写加密用的EncodingAESKey
- 'appid'=>$wxConfig['appId'], //填写高级调用功能的app id
- 'appsecret'=>$wxConfig['appSecret'], //填写高级调用功能的密钥
- );
- $weObj = new Wechat($options);
- $weObj->valid();
- $menu = $weObj->getMenu();
- $newmenu = array(
- "button"=>
- array(
- array('type'=>'view','name'=>'上门服务','url'=>'http://www.wozhua.mobi/o2o/web/index'),
- array('type'=>'view','name'=>'下载APP','url'=>'http://t.cn/R2DKttW'),
- array('type'=>'click','name'=>'壹管家过年','key'=>'WOZHUA_STAR'),
- )
- );
- $result = $weObj->createMenu($newmenu);
- $data = $weObj->getRev()->getRevData();
- if(isset($data['FromUserName']) && !empty($data['FromUserName'])){
- if($data['Event'] == 'subscribe'){
- // @file_put_contents('/data/subscribe.log',$data['FromUserName'].'--'.$data['Event']."\n",FILE_APPEND);
- $criteria = new EMongoCriteria();
- $criteria->wx_pub_openid('==',$data['FromUserName']);
- $user = RUser::model()->find($criteria);
- if($user){
- $user->wx_have_follow = 1;
- $user->update(array('wx_have_follow'),true);
- }else{
- // @file_put_contents('/data/subscribe_error.log',$data['FromUserName'].'--'.$data['Event']."\n",FILE_APPEND);
- }
- }elseif($data['Event']=='unsubscribe'){
- // @file_put_contents('/data/subscribe.log',$data['FromUserName'].'--'.$data['Event']."\n",FILE_APPEND);
- $criteria = new EMongoCriteria();
- $criteria->wx_pub_openid('==',$data['FromUserName']);
- $user = RUser::model()->find($criteria);
- if($user){
- $user->wx_have_follow = 0;
- $user->update(array('wx_have_follow'),true);
- }else{
- // @file_put_contents('/data/subscribe_error.log',$data['FromUserName'].'--'.$data['Event']."\n",FILE_APPEND);
- }
- }elseif($data['Event']=='CLICK' && $data['EventKey']=='WOZHUA_STAR'){
- $criteria = new EMongoCriteria();
- $criteria->wx_pub_openid('==',$data['FromUserName']);
- $user = RUser::model()->find($criteria);
- if($user && $user->wx_have_follow != 1){
- $user->wx_have_follow = 1;
- $user->update(array('wx_have_follow'),true);
- }
- $weObj->text("晒萌宠照,赢Apple watch,参与活动请点击:http://t.cn/RbgjgPK")->reply();
- }
- if(time() - $data['CreateTime'] < 2 && $data['Event'] == 'subscribe'){
- $weObj->text("晒萌宠照,赢Apple watch,参与活动请点击:http://t.cn/RbgjgPK")->reply();
- }
- }
- }
- }
|