215 lines
7.7 KiB
PHP
215 lines
7.7 KiB
PHP
<?php
|
||
header("Access-Control-Allow-Origin: *");
|
||
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, PATCH, DELETE");
|
||
header("Access-Control-Allow-Headers: Content-Type, Authorization, Content-Length, X-Requested-With");
|
||
header("Access-Control-Allow-Credentials: true");
|
||
header("Content-Type: text/html; charset=utf-8");
|
||
|
||
/**
|
||
* 用户积分接口
|
||
*/
|
||
use phprs\util\Verify;
|
||
use phprs\util\exceptions\Forbidden;
|
||
use phprs\util\Logger;
|
||
use phprs\util\exceptions\NotFound;
|
||
use phprs\ezsql\Sql;
|
||
use phprs\util\exceptions\BadRequest;
|
||
|
||
require_once 'apiBase.php';
|
||
/**
|
||
*
|
||
* 用户积分接口
|
||
* @path("/jifen")
|
||
*/
|
||
class Jifen extends apiBase{
|
||
/**
|
||
* 更新用户积分(错误代码:13000-13050)
|
||
* @route({"POST","/update"})
|
||
* @param({"appid","$._POST.appid"}) 所属应用
|
||
* @param({"devkey","$._POST.devkey"}) 开发者Key
|
||
* @param({"sid","$._POST.sid"}) 临时会员ID
|
||
* @param({"scode","$._POST.scode"}) 客户端票据
|
||
* @param({"jifencount","$._POST.jifencount"}) 变更积分数量
|
||
* @param({"content","$._POST.content"}) 操作说明
|
||
* @throws({"phprs\util\exceptions\Forbidden","res", "403 Forbidden",{"error":"Forbidden"}}) cookie不可用
|
||
*/
|
||
public function jifenUpdate($appid='', $devkey='',$sid='',$scode='',$jifencount='',$content='') {
|
||
// 验证公共参数是否合法
|
||
parent::init($appid,$devkey,$sid,$scode);
|
||
$verify_result = parent::verify();
|
||
|
||
if( is_error_api($verify_result) ){
|
||
return json_encode($verify_result,JSON_UNESCAPED_UNICODE);
|
||
}
|
||
|
||
$result = array();
|
||
|
||
if ( !is_numeric($jifencount) ) {
|
||
$result["error"] = "1";
|
||
$result["error_code"] = 13000;
|
||
$result["msg"] = "请正确传入变更积分的数量";
|
||
return json_encode($result,JSON_UNESCAPED_UNICODE);
|
||
}
|
||
|
||
$old_jifen = $this->userInfo["market_jifen"];
|
||
if( empty($old_jifen) || !is_numeric($old_jifen) ){
|
||
$old_jifen = 0;
|
||
$this->userInfo["market_jifen"] = 0;
|
||
}
|
||
|
||
$old_jifen = $old_jifen + $jifencount;
|
||
$this->userInfo["market_jifen"] = $old_jifen;
|
||
if( $old_jifen<0 ){
|
||
$old_jifen = 0;
|
||
$this->userInfo["market_jifen"] = 0;
|
||
}
|
||
|
||
$updateSql = Sql::update('syweb_users');
|
||
$updateSql->set("market_jifen",$old_jifen);
|
||
$condition = array();
|
||
$conditionStr = "";
|
||
|
||
if( empty($conditionStr) ){
|
||
$conditionStr = " id= ".$this->userInfo["id"];
|
||
}else{
|
||
$conditionStr .= " and id= ".$this->userInfo["id"];
|
||
}
|
||
if(!empty($conditionStr)){
|
||
$updateSql->where($conditionStr);
|
||
}
|
||
|
||
$pdo = $this->db;
|
||
$pdo->beginTransaction();
|
||
$updateCount = $updateSql->exec($pdo);
|
||
$pdo->commit();
|
||
|
||
// 假如是聚开心授权的话,还需要同步修改聚开心那边
|
||
if( $this->userInfo["auth_type"]==2 ) {
|
||
$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"] = 13001;
|
||
$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/SetIntegral.ashx";
|
||
$url .= "?spid=".$spid;
|
||
$url .= "&accessToken=".$accessToken;
|
||
$act = 1;
|
||
if( $jifencount<0 ) {
|
||
$jifencount = -$jifencount;
|
||
$act = 2;
|
||
}
|
||
$url .= "&point=".$jifencount;
|
||
$url .= "&act=".$act;
|
||
$url .= "&content=".$content;
|
||
|
||
$sign = "accessToken=".$accessToken."&act=".$act."&content=".$content."&point=".$jifencount."&spid=".$spid."&secret=ecd10d48daf3138b88727bc65ca3e0bd";
|
||
$sign = md5($sign);
|
||
$url .= "&sign=".$sign;
|
||
|
||
$response = ihttp_get($url);
|
||
if( empty($response) ) {
|
||
$result["error"] = "1";
|
||
$result["error_code"] = 13001;
|
||
$result["msg"] = "获取授权信息错误,登录失败!";
|
||
return json_encode($result,JSON_UNESCAPED_UNICODE);
|
||
}
|
||
$response = @json_decode($response['content'], true);
|
||
|
||
$retCode = $response["RetCode"];
|
||
if( $retCode==1 ) {
|
||
$result["error"] = '1';
|
||
$result["error_code"] = 13002;
|
||
$result["msg"] = "同步聚开心积分错误,错误消息为:" + $response["RetMsg"];
|
||
return json_encode($result,JSON_UNESCAPED_UNICODE);
|
||
}
|
||
|
||
$jkxUserList = Sql::select('a.*')
|
||
->from('syweb_users_jkx a')
|
||
->where('a.uid=?',$this->userInfo["id"])
|
||
->get($this->db ,null);
|
||
if( empty($jkxUserList) || count($jkxUserList)<=0 ) {
|
||
$result["error"] = '1';
|
||
$result["error_code"] = 13003;
|
||
$result["msg"] = "子账户无效";
|
||
return json_encode($result,JSON_UNESCAPED_UNICODE);
|
||
}
|
||
$jkxUserInfo = $jkxUserList[0];
|
||
|
||
$updateSql = Sql::update('syweb_users_jkx');
|
||
if( $act==1 ) {
|
||
$updateSql->set("integral",$jkxUserInfo["integral"] + $jifencount);
|
||
} else {
|
||
$updateSql->set("integral",$jkxUserInfo["integral"] - $jifencount);
|
||
}
|
||
$conditionStr = " id= ".$jkxUserInfo["id"];
|
||
$updateSql->where($conditionStr);
|
||
|
||
$pdo = $this->db;
|
||
$pdo->beginTransaction();
|
||
$updateSql->exec($pdo);
|
||
$pdo->commit();
|
||
}
|
||
|
||
$result["error"] = '0';
|
||
$result["message"] = '积分修改成功。';
|
||
return json_encode($result,JSON_UNESCAPED_UNICODE);
|
||
}
|
||
|
||
/**
|
||
* 查询用户积分余额(错误代码:11051-11100)
|
||
* @route({"POST","/"})
|
||
* @param({"appid","$._POST.appid"}) 应用appid
|
||
* @param({"devkey","$._POST.devkey"}) 开发者key
|
||
* @param({"sid","$._POST.sid"}) 服务器返回的sid
|
||
* @param({"scode","$._POST.scode"}) 客户端生成的scode
|
||
* @throws({"phprs\util\exceptions\Forbidden","res", "403 Forbidden",{"error":"Forbidden"}}) cookie不可用
|
||
*/
|
||
public function queryUserJifen($appid="",$devkey="",$sid="",$scode="") {
|
||
// 验证公共参数是否合法
|
||
parent::init($appid,$devkey,$sid,$scode);
|
||
$verify_result = parent::verify();
|
||
|
||
if( !is_error_api($verify_result) ){
|
||
$result = array();
|
||
|
||
$jifen_count = $this->userInfo['jifen_account'];
|
||
if( !empty($jifen_count) && is_numeric($jifen_count) ){
|
||
$result["error"] = "0";
|
||
$result["jifen_count"] = $jifen_count;
|
||
return json_encode($result,JSON_UNESCAPED_UNICODE);
|
||
} else {
|
||
$result["error"] = "0";
|
||
$result["jifen_count"] = 0;
|
||
return json_encode($result,JSON_UNESCAPED_UNICODE);
|
||
}
|
||
}else{
|
||
return json_encode($verify_result,JSON_UNESCAPED_UNICODE);
|
||
}
|
||
}
|
||
|
||
/** @inject("ioc_factory") */
|
||
private $factory;
|
||
/**
|
||
* @property({"default":"@db"})
|
||
* @var PDO
|
||
*/
|
||
public $db;
|
||
// 此处删除了代码
|
||
} |