作者 李忠强

更新

... ... @@ -16,7 +16,7 @@ use think\Hook;
*/
class Common extends Api
{
protected $noNeedLogin = ['init'];
protected $noNeedLogin = ['init','userAgreement','privacyAgreement'];
protected $noNeedRight = '*';
/**
... ... @@ -127,4 +127,32 @@ class Common extends Api
}
}
/**
* @ApiTitle (用户协议)
* @ApiMethod (POST)
* @ApiReturn ({
'code':'1',
'msg':'用户协议'
'data':'富文本'
})
*/
public function userAgreement()
{
$this->success('用户协议', Config::get('site.user_agreement'));
}
/**
* @ApiTitle (隐私协议)
* @ApiMethod (POST)
* @ApiReturn ({
'code':'1',
'msg':'隐私协议'
'data':'富文本'
})
*/
public function privacyAgreement()
{
$this->success('隐私协议', Config::get('site.privacy_agreement'));
}
}
... ...
... ... @@ -8,6 +8,9 @@ use app\api\model\GoodsSpec;
use app\api\model\SpecValue;
use app\common\controller\Api;
/**
* 订单页面
*/
class Order extends Api
{
protected $noNeedLogin = ['*'];
... ...
... ... @@ -2,21 +2,20 @@
namespace app\api\controller;
use app\api\model\UserAddress;
use app\api\model\UserCoupon;
use app\common\controller\Api;
use app\common\library\Ems;
use app\common\library\Sms;
use fast\Http;
use fast\Random;
use think\Config;
use think\Db;
use think\Validate;
/**
* 会员接口
* 我的页面
*/
class User extends Api
{
protected $noNeedLogin = ['third'];
protected $noNeedLogin = ['*'];
// protected $noNeedLogin = ['third'];
protected $noNeedRight = '*';
public function _initialize()
... ... @@ -126,30 +125,288 @@ class User extends Api
}
/**
* @ApiTitle (用户协议)
* @ApiTitle (用户优惠券)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="type", type="integer", required=true, description="0未使用1已使用2已过期")
* @ApiReturn ({
'code':'1',
'msg':'用户协议'
'data':'富文本'
'msg':'返回成功'
"data": [
{
"id": 1,
"user_id": 1,
"coupon_id": 1,
"name": "手动阀手动阀",
"price": "1.00", 优惠券金额
"full_price": "10.00", 满减金额
"createtime": 111122244,
"endtime": 1641869388,
"status": "0",
"endtime_text": "2022年01月11日到期"
}
]
})
*/
public function userCoupon()
{
$type = $this->request->post('type');
if (!in_array($type,[0,1,2])) $this->error('type参数不合法');
$model = new UserCoupon();
$list = $model->where('status',$type)->where('user_id',$this->auth->id)->select();
$this->success('用户优惠券列表',$list);
}
/**
* @ApiTitle (用户地址列表)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
"data": [
{
"id": 1,
"user_id": 1,
"username": "1", 收件人
"address": "阿松大", 地址
"address_detail": "阿松大", 详细地址
"normal_status": "0", 0不默认1默认
"lng": null, 经度
"lat": null, 纬度
"createtime": null,
"mobile_hide": "135****9988" 电话号码
"mobile": "13549059988" 电话号码
}
]
})
*/
public function userAddressList()
{
$model = new UserAddress();
$list = $model->where('user_id',1)->order('normal_status','desc')->select();
$this->success('用户地址列表',$list);
}
/**
* @ApiTitle (用户修改(删除)地址)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=id, type=integer, required=true, description="地址id")
* @ApiParams (name=type, type=integer, required=true, description="1修改2删除")
* @ApiParams (name=username, type=string, required=false, description="收件人")
* @ApiParams (name=mobile, type=string, required=flase, description="手机号")
* @ApiParams (name=address, type=string, required=false, description="地址")
* @ApiParams (name=address_detail, type=string, required=false, description="详细地址")
* @ApiParams (name=normal, type=integer, required=false, description="默认状态 0不默认或1默认")
* @ApiParams (name=lat, type=float, required=false, description="纬度")
* @ApiParams (name=lng, type=float, required=false, description="经度")
* @ApiReturn ({
'code':'1',
'msg':'SUCCESS'
"data":
})
*/
public function userAddressEdit()
{
$id = $this->request->post('id');
$type = $this->request->post('type');
$username = $this->request->post('username');
$mobile = $this->request->post('mobile');
$address = $this->request->post('address');
$address_detail = $this->request->post('address_detail');
$normal = $this->request->post('normal');
$lat = $this->request->post('lat');
$lng = $this->request->post('lng');
$data = [
'type' => $type,
'mobile' => $mobile,
'id' => $id,
'normal' => $normal,
'lat' => $lat,
'lng' => $lng,
];
$rule = [
'type' => 'require|in:1,2',
'mobile' => 'regex:^1\d{10}$',
'id' => 'require|integer',
'normal' => 'in:0,1',
'lat' => 'float',
'lng' => 'float',
];
$msg = [
'type' => 'type参数不合法',
'mobile' => '电话号码格式不正确',
'id' => '地址id不合法',
'normal' => '默认状态参数不合法',
'lat' => '纬度请为浮点数格式',
'lng' => '经度请为浮点数格式',
];
$validate = new \think\Validate();
$validate->rule($rule);
$validate->message($msg);
if (!$validate->check($data)) $this->error($validate->getError());
$model = new UserAddress();
if ($type == 1){
$data = [
'mobile' => $mobile,
'normal_status' => $normal,
'lat' => $lat,
'lng' => $lng,
'username' => $username,
'address' => $address,
'address_detail' => $address_detail,
];
$model->where('id',$id)->isUpdate()->save($data,['id'=>$id]);
}else{
$model->where('id',$id)->delete();
}
$this->success('SUCCESS');
}
/**
* @ApiTitle (加入我们)
* @ApiMethod (POST)
* @ApiParams (name=work, type=string, required=true, description="从事行业")
* @ApiParams (name=years, type=string, required=true, description="从业时间")
* @ApiParams (name=username, type=string, required=true, description="姓名")
* @ApiParams (name=mobile, type=string, required=true, description="手机号")
* @ApiParams (name=money, type=string, required=true, description="预计可投入资金")
* @ApiParams (name=team, type=integer, required=true, description="团队拥有0没有1有")
* @ApiParams (name=city, type=string, required=true, description="意向城市")
* @ApiParams (name=content, type=string, required=true, description="自身优势")
* @ApiReturn ({
'code':'1',
'msg':'SUCCESS'
"data":
})
*/
public function joinUs()
{
$work = $this->request->post('work');
$years = $this->request->post('years');
$username = $this->request->post('username');
$mobile = $this->request->post('mobile');
$money = $this->request->post('money');
$team = $this->request->post('team');
$city = $this->request->post('city');
$content = $this->request->post('content');
$data = [
'work' => $work,
'mobile' => $mobile,
'username' => $username,
'years' => $years,
'money' => $money,
'team' => $team,
'city' => $city,
'content' => $content,
];
$rule = [
'work' => 'require',
'mobile' => 'require|regex:^1\d{10}$',
'years' => 'require',
'username' => 'require',
'money' => 'require',
'team' => 'require|in:0,1',
'city' => 'require',
'content' => 'require|max:100',
];
$msg = [
'work' => '请填写从事行业',
'mobile' => '请正确填写电话号码',
'years' => '请填写从业时间',
'username' => '请输入姓名',
'money' => '请输入可投入资金',
'team' => '请选择是否拥有团队',
'city' => '请填写意向城市',
'content' => '请填写描述控制在100字以内',
];
$validate = new \think\Validate();
$validate->rule($rule);
$validate->message($msg);
if (!$validate->check($data)) $this->error($validate->getError());
$data['createtime'] = time();
Db::name('join_us')->insert($data);
$this->success('SUCCESS');
}
/**
* @ApiTitle (帮助反馈列表)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="token")
* @ApiParams (name=page, type=integer, required=true, description="页数")
* @ApiReturn ({
'code':'1',
'msg':'SUCCESS'
"data":
"list": {
"total": 1,
"per_page": 15,
"current_page": 1,
"last_page": 1,
"data": [
{
"id": 1,
"title": "123", 标题
"content": "啊实打实大苏打", 内容
}
]
},
"rider_status": 0 申请骑手状态:0=无,1=申请中,2=成功,3=拒绝
})
*/
public function userAgreement()
public function helpsList()
{
$this->success('用户协议', Config::get('site.user_agreement'));
$page = $this->request->post('page');
if (!is_numeric($page)) $this->error('页数参数不合法');
$list = Db::name('helps')
->order('id','desc')
->paginate(15,false,['page'=>$page]);
$this->success('SUCCESS',['list'=>$list,'rider_status'=>0]);
}
/**
* @ApiTitle (隐私协议)
* @ApiTitle (申请成为骑手)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="token")
* @ApiReturn ({
'code':'1',
'msg':'隐私协议'
'data':'富文本'
'msg':'SUCCESS'
"data":
})
*/
public function privacyAgreement()
public function riderApply()
{
$this->success('隐私协议', Config::get('site.privacy_agreement'));
if ($this->auth->rider > 0){
$this->error('您已申请,不可重复申请');
}
$user = $this->auth->getUser();
$user->rider = '1';
$user->save();
$this->success('SUCCESS');
}
/**
* @ApiTitle (邀请有奖)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="token")
* @ApiReturn ({
'code':'1',
'msg':'SUCCESS'
"data":
})
*/
public function inviteReward()
{
if ($this->auth->rider > 0){
$this->error('您已申请,不可重复申请');
}
$user = $this->auth->getUser();
$user->rider = '1';
$user->save();
$this->success('SUCCESS');
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class UserAddress extends Model
{
protected $createTime = 'createtime';
protected $updateTime = '';
protected $append = [
'mobile_hide'
];
public function getMobileHideAttr($value,$data)
{
$value = !empty($data['mobile'])?str_replace(substr($data['mobile'],3,4),'****',$data['mobile']):'';
return $value;
}
}
\ No newline at end of file
... ...
<?php
namespace app\api\model;
use think\Model;
class UserCoupon extends Model
{
protected $append = [
'endtime_text'
];
public function getEndtimeTextAttr($value,$data)
{
$value = !empty($data['endtime'])?date('Y年m月d日到期'):'';
return $value;
}
}
\ No newline at end of file
... ...