作者 杨育虎

ok

... ... @@ -21,4 +21,4 @@ aaw6YoV7JeJfUrfSAglOrAcgT8V8IZG2vMjlb6vbTH3lfsBW6YDEawftwslq2R9v
Xm0MDE0B9fvOTXxLj65NcYDgSeUhQWGMax+KE8i+S06cOxxgKEOhKBGXxmaPO6A+
LNOfLdnKoMrlQMQTrPENHQ9f6kbSONEVLLiBHakl5oDC0RQP9TYARDeb7WPf8s9F
iWHg+A==
-----END CERTIFICATE-----
\ No newline at end of file
-----END CERTIFICATE-----
... ...
... ... @@ -25,4 +25,4 @@ apJE0U8uSmNn23+Lq5STPVguafe2LFTGJZ65E2SKmQKBgQDvULYFweG6kZr2OfJf
gaueydQvMge7VtkPSKCejrLa26MLnTIzuiJg+40EVrf9PaLWHIPNegp58V9N5X45
w1AYj1HvOsEqkw8CBkc99NedwEaMrG4UNECEbf7wtL4t83KZD3wUnq5czVhKukLV
SsuJ63wrxSypFa2fPURZaMJtEA==
-----END PRIVATE KEY-----
\ No newline at end of file
-----END PRIVATE KEY-----
... ...
<?php
return array (
0 =>
array (
'name' => 'wechat',
'title' => '微信',
'type' => 'array',
'content' =>
array (
),
'value' =>
array (
'appid' => 'wxf06ef1898e5e6d55',
'app_id' => 'wxf06ef1898e5e6d55',
'app_secret' => 'afdf55fd5d385f0f0900c6b350576310',
'miniapp_id' => 'wxf06ef1898e5e6d55',
'mch_id' => '1591095591',
'key' => 'iqEyMLJMfBzOyJYwEAZGrGXqOIxWp176',
'notify_url' => '/addons/epay/api/notifyx/type/wechat',
'cert_client' => '/epay/certs/apiclient_cert.pem',
'cert_key' => '/epay/certs/apiclient_key.pem',
'log' => '1',
),
'rule' => '',
'msg' => '',
'tip' => '微信参数配置',
'ok' => '',
'extend' => '',
),
1 =>
array (
'name' => 'alipay',
'title' => '支付宝',
'type' => 'array',
'content' =>
array (
),
'value' =>
array (
'app_id' => '',
'notify_url' => '/addons/epay/api/notifyx/type/alipay',
'return_url' => '/addons/epay/api/returnx/type/alipay',
'ali_public_key' => '',
'private_key' => '',
'log' => 1,
),
'rule' => 'required',
'msg' => '',
'tip' => '支付宝参数配置',
'ok' => '',
'extend' => '',
),
2 =>
array (
'name' => '__tips__',
'title' => '温馨提示',
'type' => 'array',
'content' =>
array (
),
'value' => '请注意微信支付证书路径位于/addons/epay/certs目录下,请替换成你自己的证书<br>appid:APP的appid<br>app_id:公众号的appid<br>app_secret:公众号的secret<br>miniapp_id:小程序ID<br>mch_id:微信商户ID<br>key:微信商户支付的密钥',
'rule' => '',
'msg' => '',
'tip' => '微信参数配置',
'ok' => '',
'extend' => '',
),
);
<?php
return array (
0 =>
array (
'name' => 'wechat',
'title' => '微信',
'type' => 'array',
'content' =>
array (
),
'value' =>
array (
'appid' => 'wxf06ef1898e5e6d55',
'app_id' => 'wxf06ef1898e5e6d55',
'app_secret' => 'afdf55fd5d385f0f0900c6b350576310',
'miniapp_id' => 'wxf06ef1898e5e6d55',
'mch_id' => '1591095591',
'key' => 'iqEyMLJMfBzOyJYwEAZGrGXqOIxWp176',
'notify_url' => '/addons/epay/api/notifyx/type/wechat',
'cert_client' => '/epay/certs/apiclient_cert.pem',
'cert_key' => '/epay/certs/apiclient_key.pem',
'log' => '1',
),
'rule' => '',
'msg' => '',
'tip' => '微信参数配置',
'ok' => '',
'extend' => '',
),
1 =>
array (
'name' => 'alipay',
'title' => '支付宝',
'type' => 'array',
'content' =>
array (
),
'value' =>
array (
'app_id' => '',
'notify_url' => '/addons/epay/api/notifyx/type/alipay',
'return_url' => '/addons/epay/api/returnx/type/alipay',
'ali_public_key' => '',
'private_key' => '',
'log' => 1,
),
'rule' => 'required',
'msg' => '',
'tip' => '支付宝参数配置',
'ok' => '',
'extend' => '',
),
2 =>
array (
'name' => '__tips__',
'title' => '温馨提示',
'type' => 'array',
'content' =>
array (
),
'value' => '请注意微信支付证书路径位于/addons/epay/certs目录下,请替换成你自己的证书<br>appid:APP的appid<br>app_id:公众号的appid<br>app_secret:公众号的secret<br>miniapp_id:小程序ID<br>mch_id:微信商户ID<br>key:微信商户支付的密钥',
'rule' => '',
'msg' => '',
'tip' => '微信参数配置',
'ok' => '',
'extend' => '',
),
);
... ...
<?php
/*
* (c) overtrue <i@overtrue.me>
*
* Modified By yansongda <me@yansongda.cn>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Yansongda\Pay\Traits;
use GuzzleHttp\Client;
use Psr\Http\Message\ResponseInterface;
trait HasHttpRequest
{
/**
* Make a get request.
*
* @param string $endpoint
* @param array $query
* @param array $headers
*
* @return array
*/
protected function get($endpoint, $query = [], $headers = [])
{
return $this->request('get', $endpoint, [
'headers' => $headers,
'query' => $query,
]);
}
/**
* Make a post request.
*
* @param string $endpoint
* @param mixed $params
* @param array $options
*
* @return string
*/
protected function post($endpoint, $params = [], ...$options)
{
$options = isset($options[0]) ? $options[0] : [];
if (!is_array($params)) {
$options['body'] = $params;
} else {
$options['form_params'] = $params;
}
return $this->request('post', $endpoint, $options);
}
/**
* Make a http request.
*
* @param string $method
* @param string $endpoint
* @param array $options http://docs.guzzlephp.org/en/latest/request-options.html
*
* @return array
*/
protected function request($method, $endpoint, $options = [])
{
return $this->unwrapResponse($this->getHttpClient($this->getBaseOptions())->{$method}($endpoint, $options));
}
/**
* Return base Guzzle options.
*
* @return array
*/
protected function getBaseOptions()
{
$options = [
'base_uri' => method_exists($this, 'getBaseUri') ? $this->getBaseUri() : '',
'timeout' => property_exists($this, 'timeout') ? $this->timeout : 5.0,
];
return $options;
}
/**
* Return http client.
*
* @param array $options
*
* @return \GuzzleHttp\Client
*/
protected function getHttpClient(array $options = [])
{
return new Client($options);
}
/**
* Convert response contents to json.
*
* @param \Psr\Http\Message\ResponseInterface $response
*
* @return array
*/
protected function unwrapResponse(ResponseInterface $response)
{
$contentType = $response->getHeaderLine('Content-Type');
$contents = $response->getBody()->getContents();
if (false !== stripos($contentType, 'json') || stripos($contentType, 'javascript')) {
return json_decode($contents, true);
} elseif (false !== stripos($contentType, 'xml')) {
return $contents;
// return json_decode(json_encode(simplexml_load_string($contents, 'SimpleXMLElement', LIBXML_NOCDATA), JSON_UNESCAPED_UNICODE), true);
}
return $contents;
}
}
<?php
/*
* (c) overtrue <i@overtrue.me>
*
* Modified By yansongda <me@yansongda.cn>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Yansongda\Pay\Traits;
use GuzzleHttp\Client;
use Psr\Http\Message\ResponseInterface;
trait HasHttpRequest
{
/**
* Make a get request.
*
* @param string $endpoint
* @param array $query
* @param array $headers
*
* @return array
*/
protected function get($endpoint, $query = [], $headers = [])
{
return $this->request('get', $endpoint, [
'headers' => $headers,
'query' => $query,
]);
}
/**
* Make a post request.
*
* @param string $endpoint
* @param mixed $params
* @param array $options
*
* @return string
*/
protected function post($endpoint, $params = [], ...$options)
{
$options = isset($options[0]) ? $options[0] : [];
if (!is_array($params)) {
$options['body'] = $params;
} else {
$options['form_params'] = $params;
}
return $this->request('post', $endpoint, $options);
}
/**
* Make a http request.
*
* @param string $method
* @param string $endpoint
* @param array $options http://docs.guzzlephp.org/en/latest/request-options.html
*
* @return array
*/
protected function request($method, $endpoint, $options = [])
{
return $this->unwrapResponse($this->getHttpClient($this->getBaseOptions())->{$method}($endpoint, $options));
}
/**
* Return base Guzzle options.
*
* @return array
*/
protected function getBaseOptions()
{
$options = [
'base_uri' => method_exists($this, 'getBaseUri') ? $this->getBaseUri() : '',
'timeout' => property_exists($this, 'timeout') ? $this->timeout : 5.0,
];
return $options;
}
/**
* Return http client.
*
* @param array $options
*
* @return \GuzzleHttp\Client
*/
protected function getHttpClient(array $options = [])
{
return new Client($options);
}
/**
* Convert response contents to json.
*
* @param \Psr\Http\Message\ResponseInterface $response
*
* @return array
*/
protected function unwrapResponse(ResponseInterface $response)
{
$contentType = $response->getHeaderLine('Content-Type');
$contents = $response->getBody()->getContents();
if (false !== stripos($contentType, 'json') || stripos($contentType, 'javascript')) {
return json_decode($contents, true);
} elseif (false !== stripos($contentType, 'xml')) {
return $contents;
// return json_decode(json_encode(simplexml_load_string($contents, 'SimpleXMLElement', LIBXML_NOCDATA), JSON_UNESCAPED_UNICODE), true);
}
return $contents;
}
}
... ...
... ... @@ -3,9 +3,6 @@
function handleOrder($orderInfo) {
try {
if(!is_array($orderInfo)) {
return false;
}
$orderInfo['other'] = json_decode($orderInfo['other'], true);
if($orderInfo['type'] == 1) { // 打赏
... ... @@ -43,18 +40,22 @@ function handleOrder($orderInfo) {
if($studentInfo['vip_endtime']) {
if($studentInfo['vip_level'] == $orderInfo['other']['vip_level']) {
$vipEndTime = bcadd($studentInfo['vip_endtime'], bcmul($orderInfo['other']['keep'], bcmul(3600, 24, 0), 0), 0);
if($studentInfo['vip_endtime'] >= time()) {
$vipEndTime = bcadd($studentInfo['vip_endtime'], bcmul($orderInfo['other']['keep'], bcmul(3600, 24, 0), 0), 0);
} else {
$vipEndTime = bcadd(bcmul($orderInfo['other']['keep'], bcmul(3600, 24, 0), 0), time(), 0);
}
} else {
$vipEndTime = bcmul($orderInfo['other']['keep'], bcmul(3600, 24, 0), 0);
$vipEndTime = bcadd(bcmul($orderInfo['other']['keep'], bcmul(3600, 24, 0), 0), time(), 0);
}
} else {
$vipEndTime = bcmul($orderInfo['other']['keep'], bcmul(3600, 24, 0), 0);
$vipEndTime = bcadd(bcmul($orderInfo['other']['keep'], bcmul(3600, 24, 0), 0), time(), 0);
}
$updateData = [
'vip_level' => $orderInfo['other']['vip_level'],
'vip_endtime' => $vipEndTime,
];
$res = $student->updateOne($studentInfo['id'], $updateData);
$res = $student->updateOne($studentInfo['user_id'], $updateData);
if(!$res) {
return false;
}
... ...
... ... @@ -17,6 +17,7 @@ use fast\Http;
use fast\Random;
use think\Config;
use think\Db;
use think\Log;
/**
* 公共接口
... ... @@ -192,7 +193,7 @@ class Common extends Api
if(!$orderInfo) {
Db::rollback();
} else {
if($orderInfo['status'] == 3) {
if($orderInfo['status'] != 1) {
Db::rollback();
} else {
$res = $order->updateOne($orderInfo['id'], ['status' => 3, 'updatetime' => time()]);
... ...
<?php
namespace app\api\controller;
use app\common\controller\Api;
use app\api\model\Mes as MesModel;
use app\api\model\Student;
use think\Log;
/**
* 消息相关
*/
class Mes extends Api
{
// 无需登录的接口,*表示全部
protected $noNeedLogin = [''];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
/**
* 发一条消息给学长
* @ApiTitle (发一条消息给学长)
* @ApiSummary (发一条消息给学长)
* @ApiMethod (POST)
* @ApiHeaders (name="token", type="string", required=true, description="请求的Token")
* @ApiParams (name="userb_id", type="integer", required=true, description="学长用户ID")
* @ApiParams (name="des_content", type="string", required=true, description="内容")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 0,
"msg": "消息不能是空的哦",
"time": "1586397638",
"data": null
})
*/
public function sendMes()
{
$useraId = $this->auth->id;
$userbId = $this->request->param('userb_id', 0, 'int');
$desContent = $this->request->param('des_content', '', 'string');
if(!$userbId) {
$this->error('您的操作有误');
}
if($userbId == $useraId) {
$this->error('不能发消息给自己哦');
}
if(!$desContent) {
$this->error('消息不能是空的哦');
}
if(mb_strlen($desContent) > 200) {
$this->error('消息最多200哦');
}
$insertData = [
'usera_id' => $useraId,
'userb_id' => $userbId,
'createtime' => time(),
'updatetime' => time(),
'des_content' => $desContent
];
$mes = new MesModel();
$res = $mes->addOne($insertData);
if(!$res) {
$this->error('留言失败了,请您重试一下');
}
$this->success('留言成功了');
}
/**
* 获取我的所有的留言列表
* @ApiTitle (获取我的所有的留言列表)
* @ApiSummary (获取我的所有的留言列表)
* @ApiMethod (GET)
* @ApiHeaders (name="token", type="string", required=true, description="请求的Token")
* @ApiParams (name="page", type="integer", required=true, description="")
* @ApiParams (name="size", type="integer", required=true, description="")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1586503795",
"data": [
{
"id": 3,
"usera_id": 1,
"userb_id": 3,
"createtime": "2020-04-09",
"updatetime": 1586413562,
"des_content": "1",
"readtime": null(用于判断是否已读),
"deletetime": null
},
{
"id": 2,
"usera_id": 1,
"userb_id": 2,
"createtime": "2020-04-09",
"updatetime": 1586413562,
"des_content": "1",
"readtime": null,
"deletetime": null,
"head_image": "www.a.jpg"
}
]
})
*/
public function getMyMes()
{
$userId = $this->auth->id;
$page = $this->request->param('page', 1, 'int');
$size = $this->request->param('size', 10, 'int');
$mes = new MesModel();
$mesList = $mes->listByUserId($userId, $page, $size);
$student = new Student();
$newMes = [];
foreach ($mesList as $k => $v) {
$mesInfo = $mes->infoOne($v['usera_id'], $v['userb_id']);
$mesInfo['createtime'] = date('Y-m-d', $mesInfo['createtime']);
if($v['usera_id'] != $userId) {
$studentInfo = $student->infoByUserIdCanShow($v['usera_id']);
}
if($v['userb_id'] != $userId) {
$studentInfo = $student->infoByUserIdCanShow($v['userb_id']);
}
if(isset($studentInfo)) {
$mesInfo['head_image'] = $studentInfo['head_image'];
$mesInfo['nickname'] = $studentInfo['nickname'];
} else {
$mesInfo['head_image'] = '';
$mesInfo['nickname'] = '';
}
$newMes[] = $mesInfo;
}
$this->success('', $newMes);
}
/**
* 已读消息
* @ApiTitle (已读消息)
* @ApiSummary (已读消息)
* @ApiMethod (POST)
* @ApiHeaders (name="token", type="string", required=true, description="请求的Token")
* @ApiParams (name="usera_id", type="integer", required=true, description="发消息的人的ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ()
*/
public function isReadMes()
{
$userId = $this->auth->id;
$useraId = $this->request->param('usera_id', 0, 'int');
if(!$useraId) {
$this->error('您的操作有误');
}
if($userId == $useraId) {
$this->error('您的操作有误');
}
$mes = new MesModel();
$where['usera_id'] = ['=', $useraId];
$where['userb_id'] = ['=', $userId];
$updateData = [
'readtime' => time()
];
$res = $mes->updateByWhere($where, $updateData);
if(!$res) {
$this->error('已读失败');
}
$this->success('已读成功');
}
/**
* 获取对话框详细内容
* @ApiTitle (获取对话框详细内容)
* @ApiSummary (获取对话框详细内容)
* @ApiMethod (GET)
* @ApiHeaders (name="token", type="string", required=true, description="请求的Token")
* @ApiParams (name="page", type="integer", required=true, description="")
* @ApiParams (name="size", type="integer", required=true, description="")
* @ApiParams (name="userb_id", type="integer", required=true, description="对话的用户的ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1587697350",
"data": [
{
"id": 2,
"usera_id": 1,
"userb_id": 2,
"createtime": "2020-04-09",
"updatetime": 1586413562,
"des_content": "1",
"readtime": null,
"deletetime": null,
"head_image": "/uploads/20200413/39270b1276af4c6af020cc85eb80fb29.jpg",
"nickname": "我是高中生"
}
]
})
*/
public function getMesDetail()
{
$userId = $this->auth->id;
$page = $this->request->param('page', 1, 'int');
$size = $this->request->param('size', 10, 'int');
$userbId = $this->request->param('userb_id', 0, 'string');
if(!$userbId) {
$this->error('');
}
$limit = ($page-1)*$size;
$mes = new MesModel();
$sql = "select * from fa_mes where (usera_id = $userId and userb_id = $userbId) or (usera_id = $userbId and userb_id = $userId) order by createtime desc limit $limit, $size";
$mesList = $mes->listBySql($sql);
$student = new Student();
$newMes = [];
foreach ($mesList as $k => $v) {
$mesInfo = $mes->infoOne($v['usera_id'], $v['userb_id']);
$mesInfo['createtime'] = date('Y-m-d', $mesInfo['createtime']);
if($v['usera_id'] != $userId) {
$studentInfo = $student->infoByUserIdCanShow($v['usera_id']);
}
if($v['userb_id'] != $userId) {
$studentInfo = $student->infoByUserIdCanShow($v['userb_id']);
}
if(isset($studentInfo)) {
$mesInfo['head_image'] = $studentInfo['head_image'];
$mesInfo['nickname'] = $studentInfo['nickname'];
} else {
$mesInfo['head_image'] = '';
$mesInfo['nickname'] = '';
}
$newMes[] = $mesInfo;
}
$this->success('', $newMes);
}
<?php
namespace app\api\controller;
use app\common\controller\Api;
use app\api\model\Mes as MesModel;
use app\api\model\Student;
use think\Log;
/**
* 消息相关
*/
class Mes extends Api
{
// 无需登录的接口,*表示全部
protected $noNeedLogin = ['getMyMes'];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
/**
* 发一条消息给学长
* @ApiTitle (发一条消息给学长)
* @ApiSummary (发一条消息给学长)
* @ApiMethod (POST)
* @ApiHeaders (name="token", type="string", required=true, description="请求的Token")
* @ApiParams (name="userb_id", type="integer", required=true, description="学长用户ID")
* @ApiParams (name="des_content", type="string", required=true, description="内容")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 0,
"msg": "消息不能是空的哦",
"time": "1586397638",
"data": null
})
*/
public function sendMes()
{
$useraId = $this->auth->id;
$userbId = $this->request->param('userb_id', 0, 'int');
$desContent = $this->request->param('des_content', '', 'string');
if(!$userbId) {
$this->error('您的操作有误');
}
if($userbId == $useraId) {
$this->error('不能发消息给自己哦');
}
if(!$desContent) {
$this->error('消息不能是空的哦');
}
if(mb_strlen($desContent) > 200) {
$this->error('消息最多200哦');
}
$insertData = [
'usera_id' => $useraId,
'userb_id' => $userbId,
'createtime' => time(),
'updatetime' => time(),
'des_content' => $desContent
];
$mes = new MesModel();
$res = $mes->addOne($insertData);
if(!$res) {
$this->error('留言失败了,请您重试一下');
}
$this->success('留言成功了');
}
/**
* 获取我的所有的留言列表
* @ApiTitle (获取我的所有的留言列表)
* @ApiSummary (获取我的所有的留言列表)
* @ApiMethod (GET)
* @ApiHeaders (name="token", type="string", required=true, description="请求的Token")
* @ApiParams (name="page", type="integer", required=true, description="")
* @ApiParams (name="size", type="integer", required=true, description="")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1586503795",
"data": [
{
"id": 3,
"usera_id": 1,
"userb_id": 3,
"createtime": "2020-04-09",
"updatetime": 1586413562,
"des_content": "1",
"readtime": null(用于判断是否已读),
"deletetime": null
},
{
"id": 2,
"usera_id": 1,
"userb_id": 2,
"createtime": "2020-04-09",
"updatetime": 1586413562,
"des_content": "1",
"readtime": null,
"deletetime": null,
"head_image": "www.a.jpg"
}
]
})
*/
public function getMyMes()
{
$userId = $this->auth->id;
$userId = 12;
$page = $this->request->param('page', 1, 'int');
$size = $this->request->param('size', 10, 'int');
$mes = new MesModel();
$mesList = $mes->listByUserId($userId, $page, $size);
$student = new Student();
$userData = [];
$newMes = [];
foreach ($mesList as $k => $v) {
$users = [$v['usera_id'], $v['userb_id']];
sort($users);
if(!in_array($users, $userData)) {
$userData[] = $users;
} else {
continue;
}
$mesInfo = $mes->infoOne($v['usera_id'], $v['userb_id']);
$mesInfo['createtime'] = date('Y-m-d', $mesInfo['createtime']);
if($v['usera_id'] != $userId) {
$studentInfo = $student->infoByUserIdCanShow($v['usera_id']);
}
if($v['userb_id'] != $userId) {
$studentInfo = $student->infoByUserIdCanShow($v['userb_id']);
}
if(isset($studentInfo)) {
$mesInfo['head_image'] = $studentInfo['head_image'];
$mesInfo['nickname'] = $studentInfo['nickname'];
} else {
$mesInfo['head_image'] = '';
$mesInfo['nickname'] = '';
}
$newMes[] = $mesInfo;
}
$this->success('', $newMes);
}
/**
* 已读消息
* @ApiTitle (已读消息)
* @ApiSummary (已读消息)
* @ApiMethod (POST)
* @ApiHeaders (name="token", type="string", required=true, description="请求的Token")
* @ApiParams (name="usera_id", type="integer", required=true, description="发消息的人的ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ()
*/
public function isReadMes()
{
$userId = $this->auth->id;
$useraId = $this->request->param('usera_id', 0, 'int');
if(!$useraId) {
$this->error('您的操作有误');
}
if($userId == $useraId) {
$this->error('您的操作有误');
}
$mes = new MesModel();
$where['usera_id'] = ['=', $useraId];
$where['userb_id'] = ['=', $userId];
$updateData = [
'readtime' => time()
];
$res = $mes->updateByWhere($where, $updateData);
if(!$res) {
$this->error('已读失败');
}
$this->success('已读成功');
}
/**
* 获取对话框详细内容
* @ApiTitle (获取对话框详细内容)
* @ApiSummary (获取对话框详细内容)
* @ApiMethod (GET)
* @ApiHeaders (name="token", type="string", required=true, description="请求的Token")
* @ApiParams (name="page", type="integer", required=true, description="")
* @ApiParams (name="size", type="integer", required=true, description="")
* @ApiParams (name="userb_id", type="integer", required=true, description="对话的用户的ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1587697350",
"data": [
{
"id": 2,
"usera_id": 1,
"userb_id": 2,
"createtime": "2020-04-09",
"updatetime": 1586413562,
"des_content": "1",
"readtime": null,
"deletetime": null,
"head_image": "/uploads/20200413/39270b1276af4c6af020cc85eb80fb29.jpg",
"nickname": "我是高中生"
}
]
})
*/
public function getMesDetail()
{
$userId = $this->auth->id;
$page = $this->request->param('page', 1, 'int');
$size = $this->request->param('size', 10, 'int');
$userbId = $this->request->param('userb_id', 0, 'int');
if(!$userbId) {
$this->error('');
}
$limit = ($page-1)*$size;
$mes = new MesModel();
$sql = "select * from fa_mes where (usera_id = $userId and userb_id = $userbId) or (usera_id = $userbId and userb_id = $userId) order by createtime desc limit $limit, $size";
$mesList = $mes->listBySql($sql);
if($mesList) {
$mesList = array_reverse($mesList);
}
$student = new Student();
$studentInfo = $student->infoByUserIdCanShow($userbId);
$userInfo = $student->infoByUserId($userId);
foreach ($mesList as $k => $v) {
$mesList[$k]['createtime'] = date('Y-m-d', $v['createtime']);
if($studentInfo) {
$mesList[$k]['userb_head_image'] = $this->qiNiu.$studentInfo['head_image'];
$mesList[$k]['userb_nickname'] = $studentInfo['nickname'];
} else {
$mesList[$k]['userb_head_image'] = '';
$mesList[$k]['userb_nickname'] = '';
}
$mesList[$k]['usera_head_image'] = $this->qiNiu.$userInfo['head_image'];
$mesList[$k]['usera_nickname'] = $userInfo['nickname'];
}
$this->success('', $mesList);
}
}
\ No newline at end of file
... ...
... ... @@ -312,9 +312,12 @@ class Student extends Api
$studentInfo['college_name'] = '';
}
$endYear = date("Y-m-d", strtotime($studentInfo['endtime']));
$endYear = date("Y-m-d", $studentInfo['endtime']);
$studentInfo['end_year'] = $endYear;
$startYear = date("Y-m-d", $studentInfo['starttime']);
$studentInfo['start_year'] = $startYear;
$school = new School();
$schoolInfo = $school->infoById($studentInfo['school_id']);
if($schoolInfo) {
... ...
... ... @@ -39,7 +39,7 @@ class Thank extends Api
$userId = $this->auth->id;
$money = $this->request->param('money', 0, 'int');
if(!$money || $money <= 0) {
if(!$money || $money <= 0 || (!is_float($money) && !is_numeric($money))) {
$this->error('您的操作有误');
}
... ... @@ -55,6 +55,8 @@ class Thank extends Api
$this->error('您提交的内容有误');
}
$openid = $thirdInfo['openid'];
$amount = $money;
$amount = 0.01;
$order = new Order();
$out_trade_no = date("YmdHis", time()) . mt_rand(100000, 999999);
... ... @@ -62,10 +64,10 @@ class Thank extends Api
'createtime' => time(),
'updatetime' => time(),
'order_id' => $out_trade_no,
'money' => $money,
'money' => $amount,
'type' => 1,
'status' => 1,
'other' => json_encode(['user_id' => $userbId, 'money' => $money]),
'other' => json_encode(['user_id' => $userbId, 'money' => $amount]),
'user_id' => $userId
];
$res = $order->addOne($insertData);
... ... @@ -79,7 +81,6 @@ class Thank extends Api
//其他
$type = 'wechat';
$method = 'miniapp';
$amount = $money;
//回调链接
$notifyurl = 'http://school.t.brotop.cn/api/Common/payNotify';
... ...
<?php
namespace app\api\controller;
use app\api\model\College;
use app\api\model\Graduated;
use app\api\model\LikeUniversity;
use app\api\model\School;
use app\api\model\Student;
use app\api\model\Subject;
use app\api\model\University as UniversityModel;
use app\api\model\UniversityLevel;
use app\api\model\Up;
use app\common\controller\Api;
use think\Log;
/**
* 大学相关
*/
class University extends Api
{
// 无需登录的接口,*表示全部
protected $noNeedLogin = ['getAllUp', 'getUniversityLevel', 'getUniversityList', 'getGraduated', 'getCollege'];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
/**
* 获取大学的学院
* @ApiTitle (获取大学的学院)
* @ApiSummary (获取大学的学院)
* @ApiMethod (GET)
* @ApiParams (name="university_id", type="integer", required=true, description="大学ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "获取大学的学院成功",
"time": "1586846504",
"data": [
{
"id": 1,
"university_id": 1,
"name": "计算机",
"des_image": "www.qiniu.com/uploads/20200413/39270b1276af4c6af020cc85eb80fb29.jpg",
"weigh": 0,
"createtime": 1586768521,
"updatetime": 1586768484,
"show_switch": 1,
"deletetime": null
}
]
})
*/
public function getCollege()
{
$universityId = $this->request->param('university_id', '', 'int');
if(!$universityId) {
$this->error('您的提交有误');
}
$college = new College();
$collegeList = $college->listByUniversityId($universityId);
foreach ($collegeList as $k => $v) {
$collegeList[$k]['des_image'] = $this->qiNiu.$v['des_image'];
}
$this->success('获取大学的学院成功', $collegeList);
}
/**
* 获取所有的专业
* @ApiTitle (获取所有的专业)
* @ApiSummary (获取所有的专业)
* @ApiMethod (GET)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "获取专业成功",
"time": "1586313439",
"data": [
{
"id": 1,
"show_switch": 1,
"name": "软件工程",
"createtime": 0,
"updatetime": 0,
"weigh": 0,
"deletetime": null
}
]
})
*/
public function getGraduated()
{
$graduated = new Graduated();
$graduatedList = $graduated->listAll();
$this->success('获取所有的专业成功', $graduatedList);
}
/**
* 获取关注的学校
* @ApiTitle (获取关注的学校)
* @ApiSummary (获取关注的学校)
* @ApiMethod (GET)
* @ApiHeaders (name="token", type="string", required=true, description="请求的Token")
* @ApiParams (name="page", type="integer", required=true, description="页码")
* @ApiParams (name="size", type="integer", required=true, description="分页数:默认10")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "获取关注的学校成功",
"time": "1586846652",
"data": [
{
"id": 1,
"user_id": 1,
"university_id": 1,
"createtime": 1586768302,
"updatetime": 1586767790,
"deletetime": null,
"name": "北京大学",
"des_content": "1",
"des_image": "www.qiniu.com/uploads/20200413/39270b1276af4c6af020cc85eb80fb29.jpg",
"url": "www.beijing.com",
"wechat": "北京大学官方公众号",
"show_switch": 1,
"icon_image": "www.qiniu.com/assets/img/qrcode.png",
"weigh": 0,
"province_id": 11,
"city_id": 1101,
"level_id": 2
}
]
})
*/
public function getMyLikeUniversity()
{
$userId = $this->auth->id;
$page = $this->request->param('page', 1, 'int');
$size = $this->request->param('size', 10, 'int');
$likeUniversity = new LikeUniversity();
$likeUniversityList = $likeUniversity->listByUserId($userId, $page, $size);
foreach ($likeUniversityList as $k => $v) {
$likeUniversityList[$k]['des_image'] = $this->qiNiu.$v['des_image'];
$likeUniversityList[$k]['icon_image'] = $this->qiNiu.$v['icon_image'];
}
$this->success('获取关注的学校成功', $likeUniversityList);
}
/**
* 关注/取关大学
* @ApiTitle (关注/取关大学)
* @ApiSummary (关注/取关大学)
* @ApiMethod (POST)
* @ApiHeaders (name="token", type="string", required=true, description="请求的Token")
* @ApiParams (name="university_id", type="integer", required=true, description="大学ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ()
*/
public function likeUniversity()
{
$userId = $this->auth->id;
$universityId = $this->request->param('university_id', 0, 'int');
if(!$universityId) {
$this->error('您的操作有误');
}
$likeUniversity = new LikeUniversity();
$likeUniversityInfo = $likeUniversity->infoById($userId, $universityId);
if($likeUniversityInfo) {
if($likeUniversity->updateOne($likeUniversityInfo['id'], ['deletetime' => time()])) {
$this->success('取关大学成功');
} else {
$this->error('取关大学失败');
}
} else {
$insertData = [
'user_id' => $userId,
'university_id' => $universityId,
'createtime' => time(),
'updatetime' => time(),
];
if($likeUniversity->addOne($insertData)) {
$this->success('关注大学成功');
} else {
$this->error('关注大学失败');
}
}
}
/**
* 获取大学列表(搜索)
* @ApiTitle (获取大学列表(搜索))
* @ApiSummary (获取大学列表(搜索))
* @ApiMethod (GET)
* @ApiParams (name="page", type="integer", required=true, description="页码")
* @ApiParams (name="size", type="integer", required=true, description="分页数:默认10")
* @ApiParams (name="word", type="string", required=false, description="关键词")
* @ApiParams (name="level_id", type="integer", required=false, description="排名ID")
* @ApiParams (name="province_id", type="integer", required=false, description="省ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "获取大学列表成功",
"time": "1586846824",
"data": [
{
"id": 2,
"name": "天津大学",
"des_content": "1",
"des_image": "www.qiniu.com/uploads/20200413/39270b1276af4c6af020cc85eb80fb29.jpg",
"updatetime": 1586768302,
"createtime": 1586768302,
"url": "www.tianjin.com",
"wechat": "天津大学官方公众号",
"show_switch": 1,
"icon_image": "www.qiniu.com/assets/img/qrcode.png",
"weigh": 2,
"province_id": 12,
"city_id": 1201,
"deletetime": null,
"level_id": 3
}
]
})
*/
public function getUniversityList()
{
$page = $this->request->param('page', 1, 'int');
$size = $this->request->param('size', 10, 'int');
$word = $this->request->param('word', '', 'string');
if(mb_strlen($word) > 255) {
$this->error('您的提交有误');
}
$levelId = $this->request->param('level_id', 0, 'int');
$provinceId = $this->request->param('province_id', 0, 'int');
$where['show_switch'] = ['=', 1];
if($levelId) {
$where['level_id'] = ['=', $levelId];
}
if($provinceId) {
$where['province_id'] = ['=', $provinceId];
}
if($word) {
$where['name'] = ['like', '%'.$word.'%'];
}
$university = new UniversityModel();
$universityList = $university->listByWhere($page, $size, $where);
foreach ($universityList as $k => $v) {
$universityList[$k]['des_image'] = $this->qiNiu.$v['des_image'];
$universityList[$k]['icon_image'] = $this->qiNiu.$v['icon_image'];
}
$this->success('获取大学列表成功', $universityList);
}
/**
* 获取大学的详细信息
* @ApiTitle (获取大学的详细信息)
* @ApiSummary (获取大学的详细信息)
* @ApiMethod (GET)
* @ApiParams (name="university_id", type="integer", required=true, description="大学ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "获取大学的详细信息成功",
"time": "1586846977",
"data": {
"id": 1,
"name": "北京大学",
"des_content": "1",
"des_image": "www.qiniu.com/uploads/20200413/39270b1276af4c6af020cc85eb80fb29.jpg",
"updatetime": 1586767790,
"createtime": 1586768302,
"url": "www.beijing.com",
"wechat": "北京大学官方公众号",
"show_switch": 1,
"icon_image": "www.qiniu.com/assets/img/qrcode.png",
"weigh": 0,
"province_id": 11,
"city_id": 1101,
"deletetime": null,
"level_id": 2,
"same_school_total_num": 1,
"same_city_total_num": 1,
"same_province_total_num": 1,
"college_list": [
{
"id": 1,
"university_id": 1,
"name": "计算机",
"des_image": "www.qiniu.com/uploads/20200413/39270b1276af4c6af020cc85eb80fb29.jpg",
"weigh": 0,
"createtime": 1586768521,
"updatetime": 1586768484,
"show_switch": 1,
"deletetime": null
}
]
}
})
*/
public function getUniversityInfo()
{
$userId = $this->auth->id;
$universityId = $this->request->param('university_id', 0, 'int');
if(!$universityId) {
Log::write('1', 'debug');
$this->error('您的提交有误');
}
// 获取大学数据
$university = new UniversityModel();
$universityInfo = $university->infoById($universityId);
if(!$universityInfo) {
Log::write('2', 'debug');
$this->error('您的提交有误');
}
// 获取学长数量
$student = new Student();
$studentInfo = $student->infoByUserIdCanShow($userId);
if(!$studentInfo) {
Log::write('3', 'debug');
$this->error('您的提交有误');
}
$sameSchoolTotalNum = $student->countByUniversityIdAndSchoolId($universityId, $studentInfo['school_id']);
$universityInfo['same_school_total_num'] = $sameSchoolTotalNum;
$school = new School();
$schoolInfo = $school->infoById($studentInfo['school_id']);
$schoolIds = $school->listByCityId($schoolInfo['city_id']);
$sameCityTotalNum = $student->countByUniversityIdAndSchoolIds($universityId, $schoolIds);
$universityInfo['same_city_total_num'] = $sameCityTotalNum;
$schoolIds = $school->listByProvinceId($schoolInfo['province_id']);
$sameProvinceTotalNum = $student->countByUniversityIdAndSchoolIds($universityId, $schoolIds);
$universityInfo['same_province_total_num'] = $sameProvinceTotalNum;
// 图片地址
$universityInfo['des_image'] = $this->qiNiu.$universityInfo['des_image'];
$universityInfo['icon_image'] = $this->qiNiu.$universityInfo['icon_image'];
// 获取学院
$college = new College();
$collegeList = $college->listByUniversityId($universityId);
foreach ($collegeList as $k => $v) {
$collegeList[$k]['des_image'] = $this->qiNiu.$v['des_image'];
}
$universityInfo['college_list'] = $collegeList;
$likeUniversity = new LikeUniversity();
$likeUniversityInfo = $likeUniversity->infoById($userId, $universityId);
$universityInfo['is_like'] = $likeUniversityInfo ? 1 : 0;
$this->success('获取大学的详细信息成功', $universityInfo);
}
/**
* 获取大学级别985/211等
* @ApiTitle (获取大学级别985/211等)
* @ApiSummary (获取大学级别985/211等)
* @ApiMethod (GET)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "获取大学级别985/211等成功",
"time": "1586413893",
"data": [
{
"id": 1,
"name": "1",
"weigh": 1,
"show_switch": 1,
"createtime": 0,
"updatetime": 0,
"deletetime": null
}
]
})
*/
public function getUniversityLevel()
{
$universityLevel = new UniversityLevel();
$universityLevelList = $universityLevel->listAll();
$this->success('获取大学级别985/211等成功', $universityLevelList);
}
/**
* 获取所有的升学方式
* @ApiTitle (获取所有的升学方式)
* @ApiSummary (获取所有的升学方式)
* @ApiMethod (GET)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "获取所有的升学方式成功",
"time": "1586420526",
"data": [
{
"id": 1,
"name": "裸分",
"weigh": 0,
"createtime": 0,
"updatetime": 0,
"show_switch": 1,
"deletetime": null
}
]
})
*/
public function getAllUp()
{
$up = new Up();
$upList = $up->listAll();
$this->success('获取所有的升学方式成功', $upList);
}
/**
* 获取选考科目
* @ApiTitle (获取选考科目)
* @ApiSummary (获取选考科目)
* @ApiMethod (GET)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn (获取选考科目)
*/
public function listSubject()
{
$subject = new Subject();
$subjectList = $subject->listAll();
$this->success('获取选考科目', $subjectList);
}
}
<?php
namespace app\api\controller;
use app\api\model\College;
use app\api\model\Graduated;
use app\api\model\LikeUniversity;
use app\api\model\School;
use app\api\model\Student;
use app\api\model\Subject;
use app\api\model\University as UniversityModel;
use app\api\model\UniversityLevel;
use app\api\model\Up;
use app\common\controller\Api;
use think\Log;
/**
* 大学相关
*/
class University extends Api
{
// 无需登录的接口,*表示全部
protected $noNeedLogin = ['getAllUp', 'getUniversityLevel', 'getUniversityList', 'getGraduated', 'getCollege'];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
/**
* 获取大学的学院
* @ApiTitle (获取大学的学院)
* @ApiSummary (获取大学的学院)
* @ApiMethod (GET)
* @ApiParams (name="university_id", type="integer", required=true, description="大学ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "获取大学的学院成功",
"time": "1586846504",
"data": [
{
"id": 1,
"university_id": 1,
"name": "计算机",
"des_image": "www.qiniu.com/uploads/20200413/39270b1276af4c6af020cc85eb80fb29.jpg",
"weigh": 0,
"createtime": 1586768521,
"updatetime": 1586768484,
"show_switch": 1,
"deletetime": null
}
]
})
*/
public function getCollege()
{
$universityId = $this->request->param('university_id', '', 'int');
if(!$universityId) {
$this->error('您的提交有误');
}
$college = new College();
$collegeList = $college->listByUniversityId($universityId);
foreach ($collegeList as $k => $v) {
$collegeList[$k]['des_image'] = $this->qiNiu.$v['des_image'];
}
$this->success('获取大学的学院成功', $collegeList);
}
/**
* 获取所有的专业
* @ApiTitle (获取所有的专业)
* @ApiSummary (获取所有的专业)
* @ApiMethod (GET)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "获取专业成功",
"time": "1586313439",
"data": [
{
"id": 1,
"show_switch": 1,
"name": "软件工程",
"createtime": 0,
"updatetime": 0,
"weigh": 0,
"deletetime": null
}
]
})
*/
public function getGraduated()
{
$graduated = new Graduated();
$graduatedList = $graduated->listAll();
$this->success('获取所有的专业成功', $graduatedList);
}
/**
* 获取关注的学校
* @ApiTitle (获取关注的学校)
* @ApiSummary (获取关注的学校)
* @ApiMethod (GET)
* @ApiHeaders (name="token", type="string", required=true, description="请求的Token")
* @ApiParams (name="page", type="integer", required=true, description="页码")
* @ApiParams (name="size", type="integer", required=true, description="分页数:默认10")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "获取关注的学校成功",
"time": "1586846652",
"data": [
{
"id": 1,
"user_id": 1,
"university_id": 1,
"createtime": 1586768302,
"updatetime": 1586767790,
"deletetime": null,
"name": "北京大学",
"des_content": "1",
"des_image": "www.qiniu.com/uploads/20200413/39270b1276af4c6af020cc85eb80fb29.jpg",
"url": "www.beijing.com",
"wechat": "北京大学官方公众号",
"show_switch": 1,
"icon_image": "www.qiniu.com/assets/img/qrcode.png",
"weigh": 0,
"province_id": 11,
"city_id": 1101,
"level_id": 2
}
]
})
*/
public function getMyLikeUniversity()
{
$userId = $this->auth->id;
$page = $this->request->param('page', 1, 'int');
$size = $this->request->param('size', 10, 'int');
$likeUniversity = new LikeUniversity();
$likeUniversityList = $likeUniversity->listByUserId($userId, $page, $size);
foreach ($likeUniversityList as $k => $v) {
$likeUniversityList[$k]['des_image'] = $this->qiNiu.$v['des_image'];
$likeUniversityList[$k]['icon_image'] = $this->qiNiu.$v['icon_image'];
}
$this->success('获取关注的学校成功', $likeUniversityList);
}
/**
* 关注/取关大学
* @ApiTitle (关注/取关大学)
* @ApiSummary (关注/取关大学)
* @ApiMethod (POST)
* @ApiHeaders (name="token", type="string", required=true, description="请求的Token")
* @ApiParams (name="university_id", type="integer", required=true, description="大学ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ()
*/
public function likeUniversity()
{
$userId = $this->auth->id;
$universityId = $this->request->param('university_id', 0, 'int');
if(!$universityId) {
$this->error('您的操作有误');
}
$likeUniversity = new LikeUniversity();
$likeUniversityInfo = $likeUniversity->infoById($userId, $universityId);
if($likeUniversityInfo) {
if($likeUniversity->updateOne($likeUniversityInfo['id'], ['deletetime' => time()])) {
$this->success('取关大学成功');
} else {
$this->error('取关大学失败');
}
} else {
$insertData = [
'user_id' => $userId,
'university_id' => $universityId,
'createtime' => time(),
'updatetime' => time(),
];
if($likeUniversity->addOne($insertData)) {
$this->success('关注大学成功');
} else {
$this->error('关注大学失败');
}
}
}
/**
* 获取大学列表(搜索)
* @ApiTitle (获取大学列表(搜索))
* @ApiSummary (获取大学列表(搜索))
* @ApiMethod (GET)
* @ApiParams (name="page", type="integer", required=true, description="页码")
* @ApiParams (name="size", type="integer", required=true, description="分页数:默认10")
* @ApiParams (name="word", type="string", required=false, description="关键词")
* @ApiParams (name="level_id", type="integer", required=false, description="排名ID")
* @ApiParams (name="province_id", type="integer", required=false, description="省ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "获取大学列表成功",
"time": "1586846824",
"data": [
{
"id": 2,
"name": "天津大学",
"des_content": "1",
"des_image": "www.qiniu.com/uploads/20200413/39270b1276af4c6af020cc85eb80fb29.jpg",
"updatetime": 1586768302,
"createtime": 1586768302,
"url": "www.tianjin.com",
"wechat": "天津大学官方公众号",
"show_switch": 1,
"icon_image": "www.qiniu.com/assets/img/qrcode.png",
"weigh": 2,
"province_id": 12,
"city_id": 1201,
"deletetime": null,
"level_id": 3
}
]
})
*/
public function getUniversityList()
{
$page = $this->request->param('page', 1, 'int');
$size = $this->request->param('size', 10, 'int');
$word = $this->request->param('word', '', 'string');
if(mb_strlen($word) > 255) {
$this->error('您的提交有误');
}
$levelId = $this->request->param('level_id', 0, 'int');
$provinceId = $this->request->param('province_id', 0, 'int');
$where['show_switch'] = ['=', 1];
if($levelId) {
$where['level_id'] = ['=', $levelId];
}
if($provinceId) {
$where['province_id'] = ['=', $provinceId];
}
if($word) {
$where['name'] = ['like', '%'.$word.'%'];
}
$university = new UniversityModel();
$universityList = $university->listByWhere($page, $size, $where);
foreach ($universityList as $k => $v) {
$universityList[$k]['des_image'] = $this->qiNiu.$v['des_image'];
$universityList[$k]['icon_image'] = $this->qiNiu.$v['icon_image'];
}
$this->success('获取大学列表成功', $universityList);
}
/**
* 获取大学的详细信息
* @ApiTitle (获取大学的详细信息)
* @ApiSummary (获取大学的详细信息)
* @ApiMethod (GET)
* @ApiParams (name="university_id", type="integer", required=true, description="大学ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "获取大学的详细信息成功",
"time": "1586846977",
"data": {
"id": 1,
"name": "北京大学",
"des_content": "1",
"des_image": "www.qiniu.com/uploads/20200413/39270b1276af4c6af020cc85eb80fb29.jpg",
"updatetime": 1586767790,
"createtime": 1586768302,
"url": "www.beijing.com",
"wechat": "北京大学官方公众号",
"show_switch": 1,
"icon_image": "www.qiniu.com/assets/img/qrcode.png",
"weigh": 0,
"province_id": 11,
"city_id": 1101,
"deletetime": null,
"level_id": 2,
"same_school_total_num": 1,
"same_city_total_num": 1,
"same_province_total_num": 1,
"college_list": [
{
"id": 1,
"university_id": 1,
"name": "计算机",
"des_image": "www.qiniu.com/uploads/20200413/39270b1276af4c6af020cc85eb80fb29.jpg",
"weigh": 0,
"createtime": 1586768521,
"updatetime": 1586768484,
"show_switch": 1,
"deletetime": null
}
]
}
})
*/
public function getUniversityInfo()
{
$userId = $this->auth->id;
$universityId = $this->request->param('university_id', 0, 'int');
if(!$universityId) {
$this->error('您的提交有误');
}
// 获取大学数据
$university = new UniversityModel();
$universityInfo = $university->infoById($universityId);
if(!$universityInfo) {
$this->error('您的提交有误');
}
// 获取学长数量
$student = new Student();
$studentInfo = $student->infoByUserIdCanShow($userId);
if(!$studentInfo) {
$this->error('您的提交有误');
}
$sameSchoolTotalNum = $student->countByUniversityIdAndSchoolId($universityId, $studentInfo['school_id']);
$universityInfo['same_school_total_num'] = $sameSchoolTotalNum;
$school = new School();
$schoolInfo = $school->infoById($studentInfo['school_id']);
$schoolIds = $school->listByCityId($schoolInfo['city_id']);
$sameCityTotalNum = $student->countByUniversityIdAndSchoolIds($universityId, $schoolIds);
$universityInfo['same_city_total_num'] = $sameCityTotalNum;
$schoolIds = $school->listByProvinceId($schoolInfo['province_id']);
$sameProvinceTotalNum = $student->countByUniversityIdAndSchoolIds($universityId, $schoolIds);
$universityInfo['same_province_total_num'] = $sameProvinceTotalNum;
// 图片地址
$universityInfo['des_image'] = $this->qiNiu.$universityInfo['des_image'];
$universityInfo['icon_image'] = $this->qiNiu.$universityInfo['icon_image'];
// 获取学院
$college = new College();
$collegeList = $college->listByUniversityId($universityId);
foreach ($collegeList as $k => $v) {
$collegeList[$k]['des_image'] = $this->qiNiu.$v['des_image'];
}
$universityInfo['college_list'] = $collegeList;
$likeUniversity = new LikeUniversity();
$likeUniversityInfo = $likeUniversity->infoById($userId, $universityId);
$universityInfo['is_like'] = $likeUniversityInfo ? 1 : 0;
$this->success('获取大学的详细信息成功', $universityInfo);
}
/**
* 获取大学级别985/211等
* @ApiTitle (获取大学级别985/211等)
* @ApiSummary (获取大学级别985/211等)
* @ApiMethod (GET)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "获取大学级别985/211等成功",
"time": "1586413893",
"data": [
{
"id": 1,
"name": "1",
"weigh": 1,
"show_switch": 1,
"createtime": 0,
"updatetime": 0,
"deletetime": null
}
]
})
*/
public function getUniversityLevel()
{
$universityLevel = new UniversityLevel();
$universityLevelList = $universityLevel->listAll();
$this->success('获取大学级别985/211等成功', $universityLevelList);
}
/**
* 获取所有的升学方式
* @ApiTitle (获取所有的升学方式)
* @ApiSummary (获取所有的升学方式)
* @ApiMethod (GET)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "获取所有的升学方式成功",
"time": "1586420526",
"data": [
{
"id": 1,
"name": "裸分",
"weigh": 0,
"createtime": 0,
"updatetime": 0,
"show_switch": 1,
"deletetime": null
}
]
})
*/
public function getAllUp()
{
$up = new Up();
$upList = $up->listAll();
$this->success('获取所有的升学方式成功', $upList);
}
/**
* 获取选考科目
* @ApiTitle (获取选考科目)
* @ApiSummary (获取选考科目)
* @ApiMethod (GET)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn (获取选考科目)
*/
public function listSubject()
{
$subject = new Subject();
$subjectList = $subject->listAll();
$this->success('获取选考科目', $subjectList);
}
}
... ...
... ... @@ -64,13 +64,13 @@ class Vip extends Api
$vipConfig = new VipConfig();
$vipConfigList = $vipConfig->listAll();
foreach ($vipConfigList as $k => $v) {
if($studentInfo['vip_endtime'] > time() && $v['id'] == $studentInfo['vip_level']) {
$vipConfigList[$k]['vip_endtime'] = date('Y-m-d', $studentInfo['vip_endtime']);
} else {
$vipConfigList[$k]['vip_endtime'] = '';
}
foreach ($vipConfigList as $k => $v) {
if($studentInfo['vip_endtime'] > time() && $v['vip_level'] == $studentInfo['vip_level']) {
$vipConfigList[$k]['vip_endtime'] = date('Y-m-d', $studentInfo['vip_endtime']);
} else {
$vipConfigList[$k]['vip_endtime'] = '';
}
}
$this->success('获取vip卡购买的配置成功', $vipConfigList);
}
... ... @@ -110,6 +110,8 @@ class Vip extends Api
$this->error('您提交的内容有误');
}
$openid = $thirdInfo['openid'];
$amount = $vipConfigInfo['money'];
$amount = 0.01;
$order = new Order();
$out_trade_no = date("YmdHis", time()) . mt_rand(100000, 999999);
... ... @@ -117,7 +119,7 @@ class Vip extends Api
'createtime' => time(),
'updatetime' => time(),
'order_id' => $out_trade_no,
'money' => $vipConfigInfo['money'],
'money' => $amount,
'type' => 2,
'status' => 1,
'other' => json_encode(['user_id' => $userId, 'keep' => 30, 'vip_level' => $vipConfigInfo['vip_level']]),
... ... @@ -134,7 +136,6 @@ class Vip extends Api
//其他
$type = 'wechat';
$method = 'miniapp';
$amount = $vipConfigInfo['money'];
//回调链接
$notifyurl = 'http://school.t.brotop.cn/api/Common/payNotify';
... ...
<?php
namespace app\api\model;
use think\Model;
class Mes extends Model
{
protected $name = 'mes';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
// 天加一个留言
public function addOne($data)
{
return $this->insert($data);
}
// 获取一个用户的留言列表
public function listByUserId($userId, $page, $size)
{
return $this
->whereor(['usera_id' => ['=', $userId], 'userb_id' => ['=', $userId]])
->useSoftDelete($this->deleteTime)
->order('createtime desc')
->group('usera_id, userb_id')
->page($page, $size)
->select();
}
// 获取最新的一条消息
public function infoOne($useraId, $userbId)
{
return $this->where(['usera_id' => ['=', $useraId], 'userb_id' => ['=', $userbId]])->useSoftDelete($this->deleteTime)->order('createtime desc')->find();
}
// 修改为已读
public function updateByWhere($where, $data)
{
return $this->where($where)->update($data);
}
public function listBySql($sql)
{
return $this->query($sql);
}
<?php
namespace app\api\model;
use think\Model;
class Mes extends Model
{
protected $name = 'mes';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
// 天加一个留言
public function addOne($data)
{
return $this->insert($data);
}
// 获取一个用户的留言列表
public function listByUserId($userId, $page, $size)
{
return $this
->whereor(['usera_id' => ['=', $userId], 'userb_id' => ['=', $userId]])
->useSoftDelete($this->deleteTime)
->order('createtime desc')
->group('usera_id, userb_id')
->page($page, $size)
->select();
}
// 获取最新的一条消息
public function infoOne($useraId, $userbId)
{
return $this->where(("usera_id = $useraId AND userb_id = $userbId) OR (usera_id = $userbId and userb_id = $useraId"))->useSoftDelete($this->deleteTime)->order('createtime desc')->find();
}
// 修改为已读
public function updateByWhere($where, $data)
{
return $this->where($where)->update($data);
}
public function listBySql($sql)
{
return $this->query($sql);
}
}
\ No newline at end of file
... ...
<?php
namespace app\api\model;
use think\Model;
class Order extends Model
{
protected $name = 'order';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
// 添加一个订单
public function addOne($data)
{
return $this->insert($data);
}
// 根据条件查询订单
public function listByWhere($where)
{
return $this->where($where)->useSoftDelete($this->deleteTime)->select();
}
// 获取并锁定一个订单
public function infoAndLockById($id)
{
return $this->where(['id' => ['=', $id]])->useSoftDelete($this->deleteTime)->find();
}
// 修改一个订单
public function updateOne($id, $data)
{
return $this->where(['id' => ['=', $id]])->update($data);
}
<?php
namespace app\api\model;
use think\Model;
class Order extends Model
{
protected $name = 'order';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
// 添加一个订单
public function addOne($data)
{
return $this->insert($data);
}
// 根据条件查询订单
public function listByWhere($where)
{
return $this->where($where)->useSoftDelete($this->deleteTime)->select();
}
// 获取并锁定一个订单
public function infoAndLockById($id)
{
return $this->where(['order_id' => ['=', $id]])->useSoftDelete($this->deleteTime)->find();
}
// 修改一个订单
public function updateOne($id, $data)
{
return $this->where(['id' => ['=', $id]])->update($data);
}
}
\ No newline at end of file
... ...
... ... @@ -36,7 +36,7 @@ class Student extends Model
public function infoByUserIdCanShow($userId)
{
return $this
->where(['user_id' => ['=', $userId], 'show_switch' => ['=', 1]])
->where(['user_id' => ['=', $userId]])
->useSoftDelete($this->deleteTime)
->find();
}
... ...
... ... @@ -42,16 +42,18 @@ class PayToUser extends Command{
$third = new Third();
$userMoneyLog = new UserMoneyLog();
// try {
try {
foreach ($withdrawLogList as $v) {
$thirdInfo = $third->getOneByUserId($v['user_id']);
$order = [
'partner_trade_no' => $v['order_id'],
'openid' => $thirdInfo['openid'],
'check_name' => 'NO_CHECK',
'amount' => bcmul($v['money'], 100, 0),
'amount' => bcmul($v['money'], 10000, 0),
'desc' => '提现到零钱',
'appid' => 'wxf06ef1898e5e6d55',
'mchid' => '1591095591',
'mch_appid' => 'wxf06ef1898e5e6d55',
'nonce_str' => uniqid(),
];
$res = $pay->driver('wechat')->gateway('transfer')->pay($order);
if(isset($res['return_code']) && ($res['return_code'] == 'SUCCESS') && isset($res['result_code']) && ($res['result_code'] == 'SUCCESS')) {
... ... @@ -113,9 +115,8 @@ class PayToUser extends Command{
}
}
}
// } catch (\Exception $e) {
// Log::write($e, '错误');
// }
} catch (\Exception $e) {
Log::write($e, '错误');
}
}
}
\ No newline at end of file
... ...