ConfirmController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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/wozhua/webshell/SyncCodeOnline.sh");
  129. echo 'success';
  130. }elseif(ENVIRONMENT == 'develop'){
  131. exec("/data/wozhua/webshell/SyncCodeDev.sh");
  132. echo 'success';
  133. }else{
  134. exec("/data/wozhua/webshell/SyncCode.sh");
  135. echo 'success';
  136. }
  137. }
  138. public function actionSyncDealCode(){
  139. echo ENVIRONMENT."\n";
  140. if(ENVIRONMENT == 'product'){
  141. exec("/data/wozhua/webshell/SyncDealCodeOnline.sh");
  142. echo 'success';
  143. }else{
  144. exec("/data/wozhua/webshell/SyncDealCode.sh");
  145. echo 'success';
  146. }
  147. }
  148. public function actionSyncFrontCode(){
  149. echo ENVIRONMENT."\n";
  150. if(ENVIRONMENT == 'product'){
  151. exec("/data/wozhua/webshell/SyncFrontCodeOnline.sh");
  152. echo 'success';
  153. }else{
  154. exec("/data/wozhua/webshell/SyncFrontCode.sh");
  155. echo 'success';
  156. }
  157. }
  158. public function actionConvVideo(){
  159. $input_data = json_decode(file_get_contents("php://input"), true);
  160. file_put_contents('/data/qiniulog.json',var_export($input_data,true),FILE_APPEND);
  161. $id = $input_data['id'];
  162. if($id){
  163. $cache = new ARedisCache();
  164. $topic_id = $cache->get($id);
  165. $topic = Topic::get(new MongoId($topic_id));
  166. $qiniu_config = Yii::app()->params['qiniuConfig'];
  167. if($topic && isset($topic->video)){
  168. $key = str_replace('http://'.$qiniu_config['video'].'.qiniudn.com/','',$topic->video['url']);
  169. $new_key = 'af'.$key;
  170. $topic->video['url'] = 'http://'.$qiniu_config['video'].'.qiniudn.com/'.$new_key;
  171. $topic->update(array('video'),true);
  172. }
  173. }
  174. }
  175. public function actionUserFollow(){
  176. $path = Yii::getPathOfAlias('application');
  177. require_once($path."/vendors/weixin/wechat.class.php");
  178. $wxConfig = Yii::app()->params['wxConfig'];
  179. $options = array(
  180. 'token'=>'kkzH33eWEuP383uuKuQ366uKPwwzpE37', //填写你设定的key
  181. 'encodingaeskey'=>'2MACh0Ww6nDHDtH4pHEwgfRnCnctGVtNA0Bumvw5nkA', //填写加密用的EncodingAESKey
  182. 'appid'=>$wxConfig['appId'], //填写高级调用功能的app id
  183. 'appsecret'=>$wxConfig['appSecret'], //填写高级调用功能的密钥
  184. );
  185. $weObj = new Wechat($options);
  186. $weObj->valid();
  187. $menu = $weObj->getMenu();
  188. $newmenu = array(
  189. "button"=>
  190. array(
  191. array('type'=>'view','name'=>'上门服务','url'=>'http://www.wozhua.mobi/o2o/web/index'),
  192. array('type'=>'view','name'=>'下载APP','url'=>'http://t.cn/R2DKttW'),
  193. array('type'=>'click','name'=>'握爪过年','key'=>'WOZHUA_STAR'),
  194. )
  195. );
  196. $result = $weObj->createMenu($newmenu);
  197. $data = $weObj->getRev()->getRevData();
  198. if(isset($data['FromUserName']) && !empty($data['FromUserName'])){
  199. if($data['Event'] == 'subscribe'){
  200. // @file_put_contents('/data/subscribe.log',$data['FromUserName'].'--'.$data['Event']."\n",FILE_APPEND);
  201. $criteria = new EMongoCriteria();
  202. $criteria->wx_pub_openid('==',$data['FromUserName']);
  203. $user = RUser::model()->find($criteria);
  204. if($user){
  205. $user->wx_have_follow = 1;
  206. $user->update(array('wx_have_follow'),true);
  207. }else{
  208. // @file_put_contents('/data/subscribe_error.log',$data['FromUserName'].'--'.$data['Event']."\n",FILE_APPEND);
  209. }
  210. }elseif($data['Event']=='unsubscribe'){
  211. // @file_put_contents('/data/subscribe.log',$data['FromUserName'].'--'.$data['Event']."\n",FILE_APPEND);
  212. $criteria = new EMongoCriteria();
  213. $criteria->wx_pub_openid('==',$data['FromUserName']);
  214. $user = RUser::model()->find($criteria);
  215. if($user){
  216. $user->wx_have_follow = 0;
  217. $user->update(array('wx_have_follow'),true);
  218. }else{
  219. // @file_put_contents('/data/subscribe_error.log',$data['FromUserName'].'--'.$data['Event']."\n",FILE_APPEND);
  220. }
  221. }elseif($data['Event']=='CLICK' && $data['EventKey']=='WOZHUA_STAR'){
  222. $criteria = new EMongoCriteria();
  223. $criteria->wx_pub_openid('==',$data['FromUserName']);
  224. $user = RUser::model()->find($criteria);
  225. if($user && $user->wx_have_follow != 1){
  226. $user->wx_have_follow = 1;
  227. $user->update(array('wx_have_follow'),true);
  228. }
  229. $weObj->text("晒萌宠照,赢Apple watch,参与活动请点击:http://t.cn/RbgjgPK")->reply();
  230. }
  231. if(time() - $data['CreateTime'] < 2 && $data['Event'] == 'subscribe'){
  232. $weObj->text("晒萌宠照,赢Apple watch,参与活动请点击:http://t.cn/RbgjgPK")->reply();
  233. }
  234. }
  235. }
  236. }