from('syweb_business_activity a') ->where('a.activity_key=?',$activity_key) ->get($this->db ,null); if( empty($activityList) || count($activityList)<=0 ) { $result["error"] = '1'; $result["error_code"] = 13001; $result["msg"] = "指定的活动不存在或已经下架"; return $result; } $this->activityInfo = $activityList[0]; $activityMarketList = Sql::select('a.*') ->from('syweb_business_activity_market a') ->where('a.activity_key=? and a.market_key=?',$activity_key,$market_key) ->get($this->db ,null); if( empty($activityMarketList) || count($activityMarketList)<=0 ) { $result["error"] = '1'; $result["error_code"] = 13002; $result["msg"] = "当前门店未参与该活动!"; return $result; } } /** * 获取优惠券(错误代码:12000--12050) * @route({"POST","/exchange"}) * @param({"appid","$._POST.appid"}) 所属应用 * @param({"devkey","$._POST.devkey"}) 开发者Key * @param({"sid","$._POST.sid"}) 临时会员ID * @param({"scode","$._POST.scode"}) 客户端票据 * @param({"market_key","$._POST.market_key"}) market_key * @param({"activity_key","$._POST.activity_key"}) activity_key * @param({"useprice","$._POST.useprice"}) useprice * @param({"price","$._POST.price"}) price * @param({"validDay","$._POST.validDay"}) validDay * @throws({"phprs\util\exceptions\Forbidden","res", "403 Forbidden",{"error":"Forbidden"}}) cookie不可用 */ public function exchange($appid='', $devkey='',$sid='',$scode='',$market_key='',$activity_key='',$useprice=0,$price=0,$validDay=0) { $result = array(); $P = $_POST; // 判断公共验证是否存在错误 $verify_result = $this->commonVerify($appid,$devkey,$sid,$scode,$market_key,$activity_key); if( is_error_api($verify_result) ){ return json_encode($verify_result,JSON_UNESCAPED_UNICODE); } if( $this->userInfo["auth_type"]==0 ) { $result["error"] = "1"; $result["error_code"] = 12000; $result["msg"] = "创建优惠券失败"; return json_encode($result,JSON_UNESCAPED_UNICODE); } else if( $this->userInfo["auth_type"]==1 ) { $result["error"] = "1"; $result["error_code"] = 12000; $result["msg"] = "创建优惠券失败"; return json_encode($result,JSON_UNESCAPED_UNICODE); } else if( $this->userInfo["auth_type"]==2 ) { if ( !is_numeric($useprice) ) { $result["error"] = "1"; $result["error_code"] = 12001; $result["msg"] = "满多少可用必须为数字!"; return json_encode($result,JSON_UNESCAPED_UNICODE); } if ( !is_numeric($price) ) { $result["error"] = "1"; $result["error_code"] = 12002; $result["msg"] = "减免金额必须为数字!"; return json_encode($result,JSON_UNESCAPED_UNICODE); } if ( !is_numeric($validDay) ) { $result["error"] = "1"; $result["error_code"] = 12003; $result["msg"] = "有效天数必须为数字!"; return json_encode($result,JSON_UNESCAPED_UNICODE); } $appid = "G3CI8FQF"; $appkey = "28de5f4a54cbbb62b2264ab555ff7f62"; $url = "http://www.0792it.com/partnerApi/GetSpidFromUid.ashx"; $url .= "?appid=".$appid; $url .= "&appkey=".$appkey; $url .= "&uid=".$this->userInfo["openid"]; $response = ihttp_get($url); if( empty($response) ) { $result["error"] = "1"; $result["error_code"] = 12004; $result["msg"] = "获取授权信息错误,登录失败!"; return json_encode($result,JSON_UNESCAPED_UNICODE); } $response = @json_decode($response['content'], true); $spid = $response["spid"]; $accessToken = $response["accessToken"]; // 开始获取用户信息 $url = "http://www.0792it.com/partnerApi/CreatShopCoupon.ashx"; $paramers = array(); $paramers["accessToken"] = $accessToken; $paramers["GameName"] = $this->activityInfo["activity_name"]; $paramers["s_price"] = $price; $paramers["s_useprice"] = $useprice; $paramers["Shopid"] = $this->marketInfo["jkx_market_key"]; $paramers["spid"] = $spid; $paramers["validDay"] = $validDay; $paramers["secret"] = "ecd10d48daf3138b88727bc65ca3e0bd"; $paramerStr = $this->ToUrlParams($paramers); $sign = md5($paramerStr); $paramerStr .= "&sign=".$sign; $url .= "?".$paramerStr; $response = ihttp_get($url); if( empty($response) ) { $result["error"] = "1"; $result["error_code"] = 12005; $result["msg"] = "创建优惠券失败!"; return json_encode($result,JSON_UNESCAPED_UNICODE); } $response = @json_decode($response['content'], true); $retCode = $response["RetCode"]; if( $retCode==1 || $retCode==3 || $retCode==5 ) { $result["error"] = '1'; $result["error_code"] = 12005; $result["msg"] = "创建优惠券失败,错误消息为:".$response["RetMsg"]; return json_encode($result,JSON_UNESCAPED_UNICODE); } $result["error"] = '0'; $result["msg"] = "创建优惠券成功!"; return json_encode($result,JSON_UNESCAPED_UNICODE); } } /** @inject("ioc_factory") */ private $factory; /** * @property({"default":"@db"}) * @var PDO */ public $db; // 此处删除了代码 }