作者 宋国杰
1 个管道 的构建 失败 耗费 12 秒

在家接口开发

<?php
namespace api\common\model;
use think\Model;
class GoodsModel extends Model
{
protected $name = 'goods';
public function getGoods($id){
$map['id']=$id;
$map['is_online']=1;
$info=$this->where($map)->find();
if(empty($info)){
return '';
}
$info['pic']=cmf_get_image_url($info['pic']);
//is_json($info['banner']);
$info['banner']=json_decode($info['banner']);
if (!empty($info['banner']) && is_array($info['banner'])){
foreach ($info['banner'] as $k=>$v) {
$info['banner'][$k]=cmf_get_image_url($v);
}
}else{
$info['banner']=[];
}
return $info;
}
}
\ No newline at end of file
... ...
... ... @@ -50,5 +50,38 @@ class VolunteerModel extends Model
}
/**
* 获取用户详情
* @param $userId
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getUserInfo($userId){
$map['user_id']=$userId;
$user=$this->where($map)->find();
if (empty($user)){
return;
}
$userInfo['avatar']=$user['photo'];
$userInfo['name']=$user['name'];
$userInfo['level']=$user['level'];
$userInfo['work_time']=$user['work_time'];
$userInfo['use_time']=$user['use_time']??0;
$userInfo['level_time']=$user['work_time']-$user['use_time'];
if ($user['study_time']<5){
$userInfo['status']='志愿者(待学习)';
}
if ($user['study_time']>=5 && $user['study_time']<10){
$userInfo['status']='志愿者(待实习)';
}
if ($user['study_time']<10){
$userInfo['status']='志愿者';
}
return $userInfo;
}
}
\ No newline at end of file
... ...
... ... @@ -12,14 +12,17 @@ namespace api\index\controller;
use api\common\model\ActivityNews;
use api\common\model\ClassModel;
use api\common\model\ClassQuestionModel;
use api\common\model\GoodsModel;
use api\common\model\LevelModel;
use api\common\model\NewsTypeMode;
use api\common\model\TeamModel;
use api\common\model\UserPassModel;
use api\common\model\VolunteerModel;
use api\index\model\UserModel;
use cmf\controller\RestBaseController;
use FontLib\Table\Type\name;
use think\console\output\formatter\Style;
use think\Validate;
/**
* @title 志愿者二开接口
... ... @@ -373,7 +376,7 @@ class SecondController extends RestBaseController
$Team=new TeamModel();
$info= $Team->getTeamInfo($id);
$map['user_id']=$userId;
$map['team_id']=$id;k
$map['team_id']=$id;
$apply_info=db('team_apply')->where($map)->order('id','DESC')->find();
if (empty($apply_info)){
$info['user_status']=3;
... ... @@ -383,6 +386,179 @@ class SecondController extends RestBaseController
$this->success('',$info);
}
/**
* @title 申请加入团队
* @description 申请加入团队
* @author sgj
* @url /index/second/applyTeam
* @method POST
*
*
*@header name:XX-Token require:1 default: desc:token
*
*@param name:team_id type:int require:1 other: desc:团队id
*@param name:wx_id type:int require:1 other: desc:微信号
*@param name:mobile type:int require:1 other: desc:手机号
*@param name:join_reason type:int require:1 other: desc:加入原因
* @throws
*/
public function applyTeam(){
$user_id = $this->getUserId();
$param = $this->request->param();
$validate = new Validate([
'wx_id' => 'require',
'team_id' => 'require',
'mobile' => 'require',
'join_reason' => 'require',
]);
$validate->message([
'wx_id' => '微信号不能为空',
'team_id' =>'团队id不能为空',
'mobile' => '手机号不能为空',
'join_reason' => '加入原因不能为空',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$param['create_time']=time();
$param['user_id']=$user_id;
$result=db('team_apply')->insert($param);
if ($result>0){
$this->success('操作成功');
}else{
$this->error('操作失败');
}
}
/**
* @title 我的团队
* @description 我的团队
* @author sgj
* @url /index/second/myTeam
* @method POST
*
*
*@header name:XX-Token require:1 default: desc:token
*
* @return name:团队名称
* @return pic:图片
* @return my_time:我的时间
* @return work_total_time:总时长
* @return people_num:人数
* @return city:城市
* @throws
*/
public function myTeam(){
$user_id = $this->getUserId();
/*查询到已经申请的团队*/
$map['ta.status']=1;
$map['ta.user_id']=$user_id;
$info=db('team_apply')->alias('ta')
->field('t.*')
->join('team t','t.id=ta.team_id')
->where($map)->select();
foreach ($info as $k=>$v) {
$return[$k]['pic']=cmf_get_image_url($v['pic']);
$return[$k]['name']=$v['name'];
$return[$k]['id']=$v['id'];
$return[$k]['city']=$v['city'];
$return[$k]['people_num']=$v['people_num'];
$return[$k]['work_total_time']=$v['work_total_time'];
$return[$k]['my_time']=$this->myTime($user_id,$v['id']);
}
if (!empty($return)){
$this->success('',$return);
}else{
$this->error('');
}
}
private function myTime($user_id,$team_id){
$map['user_id']=$user_id;
$map['team_id']=$team_id;
$time=db('team_work_log')->where($map)->sum('work_time');
return $time;
}
/**
* @title 志愿反馈
* @description 志愿反馈
* @author sgj
* @url /index/second/feedback
* @method POST
*
*
*@header name:XX-Token require:1 default: desc:token
*
* @return user:用户信息@
* @user avatar:头像 name:姓名 level:星级 work_time:总工时 use_time:消耗工时 level_time:剩余工时 status:状态
*
* @throws
*/
public function feedBack(){
$userId=$this->getUserId();
$userModel=new VolunteerModel();
$return['user']=$userModel->getUserInfo($userId);
$this->success('',$return);
}
/**
* @title 商品列表
* @description 商品列表
* @author sgj
* @url /index/second/goodsList
* @method POST
*
*
*@param name:page type:int require:1 other: desc:页数
*
*@header name:XX-Token require:1 default: desc:token
*
* @return data:商品信息@
* @data id pic:缩略图 work_time:消耗工时 good_name:名称 real_good:是否为实物 seal_num:销售量 num:库存量
*
* @throws
*/
public function goodsList(){
$goodModel=new GoodsModel();
$map['is_online']=1;
$goods=$goodModel->where($map)->paginate(10,true);
$list=$goods->items();
foreach ($list as $k=>$v){
$list[$k]['pic']=cmf_get_image_url($v['pic']);
$list[$k]['content']='';
}
$this->success('',$goods);
}
/**
* @title 商品详情
* @description 商品详情
* @author sgj
* @url /index/second/goodInfo
* @method POST
*
*
*@param name:id type:int require:1 other: desc:商品id
*
*@header name:XX-Token require:1 default: desc:token
*
* @return data:商品信息@
* @data content:内容详情 pic:缩略图 work_time:消耗工时 good_name:名称 real_good:是否为实物 seal_num:销售量 num:库存量
*
* @throws
*/
public function goodInfo(){
$id=input('id');
$goodModel=new GoodsModel();
$goodInfo=$goodModel->getGoods($id);
if (empty($goodInfo)){
$this->error('没有找到相应商品');
}
$this->success('',$goodInfo);
}
}
\ No newline at end of file
... ...
... ... @@ -17,4 +17,8 @@ class UserModel extends Model
$data = $this->where($where)->find();
return $data;
}
public function getUserInfo($userId){
}
}
\ No newline at end of file
... ...
ALTER TABLE `volunteer_dev`.`cmf_volunteer`
ADD COLUMN `study_time` decimal NULL COMMENT '学习时长' AFTER `refund_reason`,
ADD COLUMN `use_time` decimal NULL COMMENT '使用时长' AFTER `study_time`;
ALTER TABLE `volunteer_dev`.`cmf_volunteer`
ADD COLUMN `is_official` tinyint(4) NULL COMMENT '是否为正式志愿者' AFTER `use_time`;
\ No newline at end of file
... ...
... ... @@ -677,6 +677,31 @@ function cmf_get_image_url($file, $style = '')
}
/**
* 判断是否为json
* @param string $data
* @param bool $assoc
* @return array|bool|mixed|string
*/
function is_json($data = '', $assoc = false) {
$data = json_decode($data, $assoc);
if ($data && (is_object($data)) || (is_array($data) && !empty(current($data)))) {
return $data;
}
return false;
}
function analyJson($json_str) {
$json_str = str_replace('\\', '', $json_str);
$out_arr = array();
preg_match('/{.*}/', $json_str, $out_arr);
if (!empty($out_arr)) {
$result = json_decode($out_arr[0], TRUE);
} else {
return FALSE;
}
return $result;
}
/**
* 获取图片预览链接
* @param string $file 文件路径,相对于upload
* @param string $style 图片样式,支持各大云存储
... ...