<?php
/**
 * 江南智慧社区模块微站定义
 *
 * @author Min晓天
 * @url http://bbs.we7.cc/
 */
defined('IN_IA') or exit('Access Denied');
include('model.php');
require_once IA_ROOT . '/addons/evzg_express/inc/core/KdApi.php';
require_once IA_ROOT . '/addons/evzg_express/inc/core/bdy/AipOcr.php';
class Evzg_expressModuleSite extends WeModuleSite {

    public function __call($name, $arguments){
       global $_GPC;
      $isMobile = stripos($name, 'doMobile') === 0;
      $isWeb = stripos($name, 'doWeb') === 0;
      if($isMobile||$isWeb){
          $dir = IA_ROOT . '/addons/' . $this->modulename . '/inc/';

          if($isWeb) {

              $do = strtolower(substr($name, 5));
              $sys = substr($do, 0, 4);
              if ($sys == 'mweb')
              {
                  $do = substr($do, 4);
                  $dir .= 'mweb/';
                  require $dir .'__init.php';;
              }else{
                  $dir .= 'web/';
              }
          }

          if($isMobile) {
              $op = $_GPC['_op'];
              load()->func('file');
              load()->func('tpl');
              load()->model('mc');
              $do = strtolower(substr($name, 8));
			  $sys = substr($do, 0, 2);
			  if ($sys == 'mw')
			  {
				$do = substr($do, 4);
				$dir .= 'mweb/';
				require $dir .'__init.php';
			 }else if ($sys == 'dy') {
				$do = substr($do, 2);
				$dir .= 'mobile/delivery/';

			}else{
			     $dir .= 'mobile/';
			 }
			 if(!empty($op)){
			    $dir.=$op.'/';
			 }
			 require $dir .'__init.php';
          }
			$fun = $do;
			$file = $dir . $fun . '.inc.php';

			if (file_exists($file))
			{
			    require $file;
			    exit();
			}$file = $dir . $fun . '.inc.php';
			if(file_exists($file)) {
				require $file;
				exit;
			} else {
				$dir = str_replace("addons", "framework/builtin", $dir);
				$file = $dir . $fun . '.inc.php';
				if(file_exists($file)) {
					require $file;
					exit;
				}
			}
		}
		trigger_error("访问的方法 {$name} 不存在.", E_USER_WARNING);
		return null;

  }
  public function payResult($params){
      //一些业务代码
      //根据参数params中的result来判断支付是否成功
      if ($params['result'] == 'success' && $params['from'] == 'notify') {
          if(strripos($params['tid'],'y')!==false){
              $id=explode("y",$params['tid']);
              pdo_update("evzg_express_expressorder",array('paystatus'=>'1','status'=>2,'paytime'=>time()),array('id'=>$id[1]));
              printEvg($id[1]);
          }elseif (strripos($params['tid'],'trend')!==false){
              $id=explode("trend_",$params['tid']);
              pdo_update("evzg_express_trends",array('paystatus'=>'1','status'=>1,'paytime'=>time()),array('id'=>$id[1]));
              trendExpre($id);
          }elseif (strripos($params['tid'],'sms')!==false){
              mload()->model('sms');
              $id=explode("sms",$params['tid']);
              pdo_update("evzg_express_sms_order",array('status'=>1,'paytime'=>time()),array('id'=>$id[1]));
              sms_order_paystaus($id);
              //trendExpre($id);
          }


      }
      //因为支付完成通知有两种方式 notify，return,notify为后台通知,return为前台通知，需要给用户展示提示信息
      //return做为通知是不稳定的，用户很可能直接关闭页面，所以状态变更以notify为准
      //如果消息是用户直接返回（非通知），则提示一个付款成功
      //如果是JS版的支付此处的跳转则没有意义
      if ($params['from'] == 'return') {
          if ($params['result'] == 'success') {
              if(strripos($params['tid'],'y')!==false){
                  message('支付成功！', $this->createMobileUrl("userorder"), 'success');
              }elseif (strripos($params['tid'],'trend')!==false){
                 message('支付成功！', $this->createMobileUrl("trends"), 'success');
              }elseif (strripos($params['tid'],'sms')!==false){
                  message('支付成功！', $this->createMobileUrl("my"), 'success');
              }else{
                  message('支付成功！', $this->createMobileUrl("index"), 'success');
              }

          } else {
              message('支付失败！', $this->createMobileUrl("index"), 'error');
          }
      }
  }
}