添加后台代理代码

This commit is contained in:
2026-03-15 01:27:05 +08:00
parent 11f9ac4dc1
commit ea08c9366a
5254 changed files with 721042 additions and 0 deletions

View File

@@ -0,0 +1,368 @@
<?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("/wcaddress")
*/
class WholeCountryAddress extends apiBase{
/**
* 根据上级地区Code查询下级地区列表
* @route({"POST","/"})
* @param({"appid","$._POST.appid"}) 应用appid
* @param({"devkey","$._POST.devkey"}) 开发者key
* @param({"parentcode","$._POST.parentcode"}) 地区指定代码parentcode
* @throws({"phprs\util\exceptions\Forbidden","res", "403 Forbidden",{"error":"Forbidden"}}) cookie不可用
* @return("body")
*/
public function getAddressListByParentCode($appid = "",$devkey="",$parentcode="{=NULL=}"){
$result = array();
if( empty($appid) ){
$result["error"] = '1';
$result["error_code"] = 10001; // 请传入APPID参数
return json_encode($result,JSON_UNESCAPED_UNICODE);
}
$appInfo = Sql::select('syweb_app.*')
->from('syweb_app')
->where('syweb_app.appid=?', $appid)
->get($this->db ,null);
if( empty($appInfo) || count($appInfo)<=0 ){
$result["error"] = '1';
$result["error_code"] = 10002; // 指定的应用不存在
return json_encode($result,JSON_UNESCAPED_UNICODE);
}
if( empty($devkey) ){
$result["error"] = '1';
$result["error_code"] = 10003; // 请传入DevKey参数
return json_encode($result,JSON_UNESCAPED_UNICODE);
}
if ( $parentcode=='{=NULL=}' ) {
$result[0]["error"] = "1";
$result[0]["error_code"] = 10006; // 请传入地区父ID
return json_encode($result,JSON_UNESCAPED_UNICODE);
}
$res = Sql::select('a.*')
->from('syweb_whole_country_address a')
->where('a.address_parent_code=?', $parentcode)
->get($this->db ,null);
if( !empty($res) && count($res)>0 ){
$result[0]["error"] = "0";
$result[0]["data"] = $res;
return json_encode($result,JSON_UNESCAPED_UNICODE);
}else{
$result[0]["error"] = "0";
$result[0]["data"] = array();
return json_encode($result,JSON_UNESCAPED_UNICODE);
}
}
/**
* 根据数据存储会员收货地址(错误代码12701-12750)
* @route({"POST","/save"})
* @param({"appid","$._POST.appid"}) 应用appid
* @param({"devkey","$._POST.devkey"}) 开发者key
* @param({"sid","$._POST.sid"}) 服务器返回的sid
* @param({"scode","$._POST.scode"}) 客户端生成的Scode
* @param({"id","$._POST.id"}) 收货地址系统编号
* @param({"province_code","$._POST.province_code"}) 省份地区编号
* @param({"city_code","$._POST.city_code"}) 城市编号
* @param({"country_code","$._POST.country_code"}) 县区编号
* @param({"street_code","$._POST.street_code"}) 街道编号
* @param({"address_detail","$._POST.address_detail"}) 详细地址
* @param({"realname","$._POST.realname"}) 收货人真实姓名
* @param({"tel","$._POST.tel"}) 收货人电话
* @param({"lng","$._POST.lng"}) 客户收货地址所在经度
* @param({"lat","$._POST.lat"}) 客户收货地址所在纬度
* @param({"isdefault","$._POST.isdefault"}) 是否设置为默认收货地址
* @throws({"phprs\util\exceptions\Forbidden","res", "403 Forbidden",{"error":"Forbidden"}}) cookie不可用
* @return("body")
*/
public function postUserAddress($appid='',$devkey='',$sid="",$scode="",$id="",$province_code="",$city_code="",$country_code="",$street_code="",$address_detail='',$realname='',$tel='',$lng='',$lat='',$isdefault=''){
// 验证公共参数是否合法
parent::init($appid,$devkey,$sid,$scode);
$verify_result = parent::verify();
if( !is_error_api($verify_result) ){
if ( !empty($isdefault) && $isdefault=="1" ) {
$isdefault = 1;
}else{
$isdefault = 0;
}
if( !empty($id) && is_numeric($id) ){
$updateSql = Sql::update('syweb_users_address');
$updateSql->set("province_code",$province_code);// 省份地区Code
$updateSql->set("city_code",$city_code);// 城市地区Code
$updateSql->set("country_code",$country_code);// 县区Code
$updateSql->set("street_code",$street_code);// 街道Code
$updateSql->set("address_detail",$address_detail);// 详细地址
$updateSql->set("realname",$realname);// 收货人姓名
$updateSql->set("tel",$tel);// 收货人联系电话
$updateSql->set("lng",$lng);// 经度
$updateSql->set("lat",$lat);// 纬度
$updateSql->where(" `id` = ".$id);
$pdo = $this->db;
$pdo->beginTransaction();
$updateCount = $updateSql->exec($pdo);
if( $isdefault==1 ){
// 修改会员默认收货地址 begin
$setDefaultAddressSql = Sql::update('syweb_users');
$setDefaultAddressSql->set("address_id",$id);
$setDefaultAddressSql->where(" `id` = ".$this->userInfo['id']);
$setDefaultAddressSql->exec($pdo);
// 修改会员默认收货地址 end
}
$pdo->commit();
$result["error"] = '0';
$result["message"] = '收货地址修改成功。';
return json_encode($result,JSON_UNESCAPED_UNICODE);
} else {
$insertData = array();
$insertData['uid'] = $this->userInfo['id'];// 会员用户ID
$insertData['business_id'] = $this->businessInfo["id"];// 商户ID
$insertData['province_code'] = $province_code;// 省份地区Code
$insertData['city_code'] = $city_code;// 城市地区Code
$insertData['country_code'] = $country_code;// 县区Code
$insertData['street_code'] = $street_code;// 街道Code
$insertData['address_detail'] = $address_detail;// 详细地址
$insertData['realname'] = $realname;// 收货人姓名
$insertData['tel'] = $tel;// 收货人联系电话
$insertData['lng'] = $lng;// 经度
$insertData['lat'] = $lat;// 纬度
$insertData['createtime'] = TIMESTAMP;
$pdo = $this->db;
$pdo->beginTransaction();
$addressId = Sql::insertInto('syweb_users_address')->values($insertData)->exec($pdo)->lastInsertId();
if( $isdefault==1 ){
// 修改会员默认收货地址 begin
$setDefaultAddressSql = Sql::update('syweb_users');
$setDefaultAddressSql->set("address_id",$addressId);
$setDefaultAddressSql->where(" `id` = ".$this->userInfo['id']);
$setDefaultAddressSql->exec($pdo);
// 修改会员默认收货地址 end
}
$pdo->commit();
if ( !empty($addressId) ) {
$result["error"] = '0';
$result["id"] = $addressId;
$result["message"] = '收货地址存储成功。';
return json_encode($result,JSON_UNESCAPED_UNICODE);
}else{
$result["status"] = '1';
$result["error_code"] = 12701; // 用户收货地址存储失败
$result["msg"] = "用户收货地址存储失败";
return json_encode($result,JSON_UNESCAPED_UNICODE);
}
}
}else{
return json_encode($verify_result,JSON_UNESCAPED_UNICODE);
}
}
/**
* 查询当前登录会员的收货地址列表(错误代码12751-12800)
* @route({"POST","/list"})
* @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 queryUserAddressList($appid='',$devkey='',$sid='',$scode='') {
// 验证公共参数是否合法
parent::init($appid,$devkey,$sid,$scode);
$verify_result = parent::verify();
if( !is_error_api($verify_result) ){
$result = array();
$fields = "a.id,a.province_code,(select address_name from syweb_whole_country_address where address_code=a.province_code) as province_name,a.city_code,(select address_name from syweb_whole_country_address where address_code=a.city_code) as city_name,a.country_code,(select address_name from syweb_whole_country_address where address_code=a.country_code) as country_name,a.street_code,(select address_name from syweb_whole_country_address where address_code=a.street_code) as street_name,a.address_detail,a.realname,a.tel,a.lng,a.lat,a.createtime";
$addressList = Sql::select($fields)
->from('syweb_users_address a')
->where('a.business_id=? and a.uid=?', $this->businessInfo['id'],$this->userInfo['id'])
->get($this->db ,null);
if(!empty($addressList) && count($addressList)>0){
foreach ($addressList as $key => &$row) {
if( $row['id']==$this->userInfo['address_id'] ){
$row['isdefault'] = 1;
}else{
$row['isdefault'] = 0;
}
}
$result["error"] = "0";
$result["data"] = $addressList;
return json_encode($result,JSON_UNESCAPED_UNICODE);
} else {
$result["error"] = '0';
$result["data"] = array();
return json_encode($result,JSON_UNESCAPED_UNICODE);
}
}else{
return json_encode($verify_result,JSON_UNESCAPED_UNICODE);
}
}
/**
* 根据收货地址的ID查询收货地址详细信息(错误代码12801-12850)
* @route({"POST","/info"})
* @param({"appid","$._POST.appid"}) 应用appid
* @param({"devkey","$._POST.devkey"}) 开发者key
* @param({"sid","$._POST.sid"}) 服务器返回的sid
* @param({"scode","$._POST.scode"}) 客户端生成的scode
* @param({"id","$._POST.id"}) 收货地址ID
* @throws({"phprs\util\exceptions\Forbidden","res", "403 Forbidden",{"error":"Forbidden"}}) cookie不可用
*/
public function queryUserAddressInfo($appid='',$devkey='',$sid='',$scode='',$id='') {
// 验证公共参数是否合法
parent::init($appid,$devkey,$sid,$scode);
$verify_result = parent::verify();
if( !is_error_api($verify_result) ){
$result = array();
if(empty($id) || !is_numeric($id)){
$result["error"] = "1";
$result["error_code"] = 12801; // 请传入地址ID
$result["msg"] = "请传入地址ID";
return json_encode($result,JSON_UNESCAPED_UNICODE);
}
$fields = "a.id,a.province_code,(select address_name from syweb_whole_country_address where address_code=a.province_code) as province_name,a.city_code,(select address_name from syweb_whole_country_address where address_code=a.city_code) as city_name,a.country_code,(select address_name from syweb_whole_country_address where address_code=a.country_code) as country_name,a.street_code,(select address_name from syweb_whole_country_address where address_code=a.street_code) as street_name,a.address_detail,a.realname,a.tel,a.lng,a.lat,a.createtime";
$addressInfo = Sql::select($fields)
->from('syweb_users_address a')
->where('a.business_id=? and a.uid=? and a.id=?', $this->businessInfo['id'],$this->userInfo['id'],$id)
->get($this->db ,null);
if(!empty($addressInfo) && count($addressInfo)>0){
if( $addressInfo[0]['id']==$this->userInfo['address_id'] ){
$addressInfo[0]['isdefault'] = 1;
}else{
$addressInfo[0]['isdefault'] = 0;
}
$result["error"] = "0";
$result["data"] = $addressInfo[0];
return json_encode($result,JSON_UNESCAPED_UNICODE);
} else {
$result["error"] = '0';
$result["data"] = array();
return json_encode($result,JSON_UNESCAPED_UNICODE);
}
}else{
return json_encode($verify_result,JSON_UNESCAPED_UNICODE);
}
}
/**
* 获取用户默认收货地址(错误代码12851-12900)
* @route({"POST","/defaddr"})
* @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 queryUserDefaultAddressDefault($appid='',$devkey='',$sid='',$scode='') {
// 验证公共参数是否合法
parent::init($appid,$devkey,$sid,$scode);
$verify_result = parent::verify();
if( !is_error_api($verify_result) ){
$result = array();
$defaultAddressId = $this->userInfo['address_id'];
if( !empty($defaultAddressId) && is_numeric($defaultAddressId) ){
$fields = "a.id,a.province_code,(select address_name from syweb_whole_country_address where address_code=a.province_code) as province_name,a.city_code,(select address_name from syweb_whole_country_address where address_code=a.city_code) as city_name,a.country_code,(select address_name from syweb_whole_country_address where address_code=a.country_code) as country_name,a.street_code,(select address_name from syweb_whole_country_address where address_code=a.street_code) as street_name,a.address_detail,a.realname,a.tel,a.lng,a.lat,a.createtime";
$addressInfo = Sql::select($fields)
->from('syweb_users_address a')
->where('a.business_id=? and a.uid=? and a.id=?', $this->businessInfo['id'],$this->userInfo['id'],$defaultAddressId)
->get($this->db ,null);
if(!empty($addressInfo) && count($addressInfo)>0){
$result[0]["error"] = "0";
$result[0]["data"] = $addressInfo[0];
return json_encode($result,JSON_UNESCAPED_UNICODE);
} else {
$result["error"] = '0';
$result["data"] = array();
return json_encode($result,JSON_UNESCAPED_UNICODE);
}
} else {
$result["error"] = '1';
$result["error_code"] = 12851; // 没有设置默认地址
$result["msg"] = "没有设置默认地址";
return json_encode($result,JSON_UNESCAPED_UNICODE);
}
}else{
return json_encode($verify_result,JSON_UNESCAPED_UNICODE);
}
}
/**
* 根据条件删除收货地址(错误代码12901-12950)
* @route({"POST","/delete"})
* @param({"appid","$._POST.appid"}) 应用appid
* @param({"devkey","$._POST.devkey"}) 开发者key
* @param({"sid","$._POST.sid"}) 服务器返回的sid
* @param({"scode","$._POST.scode"}) 客户端生成的scode
* @param({"id","$._POST.id"}) 收货地址系统编号
* @throws({"phprs\util\exceptions\Forbidden","res", "403 Forbidden",{"error":"Forbidden"}}) cookie不可用
* @return("body")
*/
public function postDelData($appid='',$devkey='',$sid='',$scode='',$id=''){
// 验证公共参数是否合法
parent::init($appid,$devkey,$sid,$scode);
$verify_result = parent::verify();
if( !is_error_api($verify_result) ){
$result = array();
if( empty($id) || !is_numeric($id) ){
$result["error"] = "1";
$result["error_code"] = 12901; // 请传入收货地址编号
$result["msg"] = "请传入收货地址编号";
return json_encode($result,JSON_UNESCAPED_UNICODE);
}
$condition .= " `id` = ".$id;
$pdo = $this->db;
$pdo->beginTransaction();
$delResult = Sql::deleteFrom('syweb_users_address')->where($condition)->exec($this->db);
$this->db->commit();
$result["error"] = "0";
$result["message"] = "删除收货地址成功!";
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;
// 此处删除了代码
}