update(self::orderTab) ->data($arr) ->where('id')->eq($this->order_id) ->exec(); return $n == 1; } /** * @return array 拉取签名参数数组 */ public function uc_GetData2Sign() { $sid = array('callbackInfo', 'amount', 'notifyUrl', 'cpOrderId', 'accountId'); $arr = array(); foreach (get_object_vars($this) as $key => $value) { if (in_array($key, $sid)) { $arr[$key] = $value; } } return $arr; } /** * @return array 普通返回值数组 */ public function retData() { $sid = array('callbackInfo', 'amount', 'product_price', 'product_count', 'notifyUrl', 'cpOrderId'); $arr = array(); foreach (get_object_vars($this) as $key => $value) { if (in_array($key, $sid)) { $arr[$key] = $value; } } return $arr; } /** * @return array 小七手游订单结构(未签名) */ public function x7sy_retData() { $ret = array( 'extends_info_data' => $this->callbackInfo, // // 透传参数 'game_area' => $this->zoneid, 'game_guid' => $this->accountId, 'game_level' => 0, 'game_orderid' => $this->cpOrderId, 'game_price' => $this->product_price, // // 对方要求单位:元 'game_role_id' => "no", 'game_role_name' => "no", 'notify_id' => "3788", // // 如果只有一个可以设置为-1,但不可以设置为0 'subject' => $this->product_name ); return $ret; } /** * @return array 易接返回值数组 */ public function yijie_retData() { return $this->retData(); } public function __construct($arg = null) { parent::__construct($arg); if (!$this->accountId || !$this->amount || !$this->channel || !$this->product_id) { \loyalsoft\CLog::pay('参数缺失'); exit('{"err":1,"msg":"参数缺失!"}'); } if ($this->amount) { // $this->amount = number_format($this->amount, 2, '.', ''); // if ('soft' == $this->channel) { # 2018年1月15号以前固定为1分钱测试 // $this->amount = number_format(0.01, 2, '.', ''); // $this->product_price = 0.01; // } else // // if ($this->amount != loyalsoft\GameConfig::shop_getItem($this->product_id)->price) { // var_dump($this->product_id); // var_dump(loyalsoft\GameConfig::shop_getItem($this->product_id)->price); // \loyalsoft\CLog::pay('金额不符' . $this->amount . " "); // exit('{"err":1,"msg":"金额不符!"}'); // } } loyalsoft\daoInst()->insert(self::orderTab) ->data(array('order_ts' => loyalsoft\now())) ->exec(); $this->order_id = loyalsoft\daoInst()->select('last_insert_id() as id')->fetch('id'); # 订单自增id $this->cpOrderId = LoyalsoftAPPID . \date('ymdHi') . substr(sprintf("%1$06d", $this->order_id), -6); # 商户唯一id(尾部附加自增id后6位数) $this->callbackInfo .= "," . $this->cpOrderId; # 将cpOrderId追加到透传参数中 $this->notifyUrl = self::get_notify_url(); # 自动提取支付回调地址 } /** * PS. 仅限pay.php作为入口使用才行 * @return string 获取支付回调地址, */ public static function get_notify_url() { $url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER["REQUEST_URI"]; $nurl = substr($url, 0, strpos($url, "pay.php")) . "notify.php"; return $nurl; # 回调地址 } public function AntiAdditionCheck() { $uid = $this->accountId; $ageRange = $this->ageRange; $amt = $this->amount; if (isset($uid) && isset($ageRange)) { $monthTS = loyalsoft\TimeUtil::tsMonthBegin(); # 本月初起始时间戳 $dayTS = loyalsoft\TimeUtil::tsDayBegin(); # 当天起始时间戳 $monthTotal = loyalsoft\daoInst() ->select("sum(`amount`)/100 as total") # 总金额(单位:分转元) ->from("tpl_order_tab") ->where("uid")->eq($uid) # 该玩家 ->andWhere("status")->eq(1) # 成交订单 ->andWhere("order_ts")->ge($monthTS) # 本月 ->fetch('total'); if (!is_numeric($monthTotal)) { $monthTotal = 0; } $dayTotal = loyalsoft\daoInst() ->select("sum(`amount`)/100 as total") # 总金额(单位:分转元) ->from("tpl_order_tab") ->where("uid")->eq($uid) # 该玩家 ->andWhere("status")->eq(1) # 成交订单 ->andWhere("order_ts")->ge($dayTS) # 今日 ->fetch('total'); if (!is_numeric($dayTotal)) { $dayTotal = 0; } if ($ageRange < 0 || !is_numeric($ageRange)) { return \Resp::err(1, "未完成实名认证的用户暂不提供充值."); } else if ($ageRange < 8) { return \Resp::err(1, "未慢8周岁的用户暂不提供充值."); } else if ($ageRange < 16) { # 单笔/每月: 50,200 if ($amt > 50) { return \Resp::err(1, "单笔充值金额不高于50¥"); } // if (($amt + $dayTotal) > 100) { // return \Resp::err(1, "单日累计充值金额不高于100¥"); // } if (($amt + $monthTotal) > 200) { return \Resp::err(1, "当月累计充值金额不高于200¥"); } } else if ($ageRange < 18) { # 单笔/每月: 100,400 if ($amt > 100) { return \Resp::err(1, "单笔充值金额不高于100¥"); } // if (($amt + $dayTotal) > 100) { // return \Resp::err(1, "单日累计充值金额不高于100¥"); // } if (($amt + $monthTotal) > 400) { return \Resp::err(1, "当月累计充值金额不高于400¥"); } } return \Resp::ok("ok"); } return \Resp::err(-1, "参数不足"); # 其他情况 } }