...
|
...
|
@@ -18,7 +18,7 @@ use think\Validate; |
|
|
*/
|
|
|
class User extends Api
|
|
|
{
|
|
|
protected $noNeedLogin = ['third','joinUs','developLogin','notice'];
|
|
|
protected $noNeedLogin = ['third', 'joinUs', 'developLogin', 'notice'];
|
|
|
protected $noNeedRight = '*';
|
|
|
|
|
|
public function _initialize()
|
...
|
...
|
@@ -48,12 +48,12 @@ class User extends Api |
|
|
{
|
|
|
$data = [];
|
|
|
$data['nickname'] = $this->auth->nickname;
|
|
|
$data['avatar'] = cdnurl($this->auth->avatar,true);
|
|
|
$data['avatar'] = cdnurl($this->auth->avatar, true);
|
|
|
$data['mobile'] = $this->auth->mobile;
|
|
|
$data['pay'] = Db::name('litestore_order')->where('user_id',$this->auth->id)->where('pay_status','10')->count();
|
|
|
$data['wait_send'] = Db::name('litestore_order')->where('user_id',$this->auth->id)->where('freight_status','10')->count();
|
|
|
$data['wait_collect'] = Db::name('litestore_order')->where('user_id',$this->auth->id)->where('receipt_status','10')->count();
|
|
|
$data['wait_comment'] = Db::name('litestore_order')->where('user_id',$this->auth->id)->where('receipt_status','20')->count();
|
|
|
$data['pay'] = Db::name('litestore_order')->where('user_id', $this->auth->id)->where('pay_status', '10')->count();
|
|
|
$data['wait_send'] = Db::name('litestore_order')->where('user_id', $this->auth->id)->where('freight_status', '10')->count();
|
|
|
$data['wait_collect'] = Db::name('litestore_order')->where('user_id', $this->auth->id)->where('receipt_status', '10')->count();
|
|
|
$data['wait_comment'] = Db::name('litestore_order')->where('user_id', $this->auth->id)->where('receipt_status', '20')->count();
|
|
|
$this->success('会员中心', ['welcome' => $data]);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -100,7 +100,7 @@ class User extends Api |
|
|
$nickname = $this->request->post('nickname');
|
|
|
$avatar = $this->request->post('avatar');
|
|
|
$invite_id = $this->request->post('invite_id');
|
|
|
if (!$code || !$nickname || !$avatar){
|
|
|
if (!$code || !$nickname || !$avatar) {
|
|
|
$this->error('后台所需参数缺失请完善参数');
|
|
|
}
|
|
|
$param = [];
|
...
|
...
|
@@ -108,40 +108,40 @@ class User extends Api |
|
|
$param['grant_type'] = 'authorization_code';
|
|
|
$param['secret'] = Config::get('site.secret');
|
|
|
$param['appid'] = Config::get('site.appid');
|
|
|
$wxapi = Http::get('https://api.weixin.qq.com/sns/jscode2session',$param);//请求openid
|
|
|
$wxapi = json_decode($wxapi,true);
|
|
|
if (isset($wxapi['errcode'])){
|
|
|
$wxapi = Http::get('https://api.weixin.qq.com/sns/jscode2session', $param);//请求openid
|
|
|
$wxapi = json_decode($wxapi, true);
|
|
|
if (isset($wxapi['errcode'])) {
|
|
|
$this->error($wxapi['errmsg']);
|
|
|
}
|
|
|
$third = new \app\api\model\Third();
|
|
|
$userid = $third->where('openid',$wxapi['openid'])->value('user_id');
|
|
|
if ($userid){
|
|
|
$this->auth->direct($userid,$invite_id);
|
|
|
$third->isUpdate()->save(['session_key'=>$wxapi['session_key']],['user_id'=>$userid]);
|
|
|
$this->success('登录成功',['token'=>$this->auth->getToken(),'user_type'=>$this->auth->user_type]);
|
|
|
}else{
|
|
|
if ($invite_id > 0){
|
|
|
$userid = $this->auth->register($nickname,'','','',['avatar'=>$avatar,'invite_user_id'=>$invite_id,'invite_time'=>time()]);
|
|
|
}else{
|
|
|
$userid = $this->auth->register($nickname,'','','',['avatar'=>$avatar]);
|
|
|
}
|
|
|
if ($userid){
|
|
|
$third->isUpdate(false)->save(['openid'=>$wxapi['openid'],'user_id'=>$userid,'session_key'=>$wxapi['session_key']]);
|
|
|
$userid = $third->where('openid', $wxapi['openid'])->value('user_id');
|
|
|
if ($userid) {
|
|
|
$this->auth->direct($userid, $invite_id);
|
|
|
$third->isUpdate()->save(['session_key' => $wxapi['session_key']], ['user_id' => $userid]);
|
|
|
$this->success('登录成功', ['token' => $this->auth->getToken(), 'user_type' => $this->auth->user_type]);
|
|
|
} else {
|
|
|
if ($invite_id > 0) {
|
|
|
$userid = $this->auth->register($nickname, '', '', '', ['avatar' => $avatar, 'invite_user_id' => $invite_id, 'invite_time' => time()]);
|
|
|
} else {
|
|
|
$userid = $this->auth->register($nickname, '', '', '', ['avatar' => $avatar]);
|
|
|
}
|
|
|
if ($userid) {
|
|
|
$third->isUpdate(false)->save(['openid' => $wxapi['openid'], 'user_id' => $userid, 'session_key' => $wxapi['session_key']]);
|
|
|
// 注册送优惠券
|
|
|
$coupon = Db::name('coupon')->where('id',3)->find();
|
|
|
$coupon = Db::name('coupon')->where('id', 3)->find();
|
|
|
$time = time();
|
|
|
if($coupon['register_send_switch'] == '1' && $time >= $coupon['register_send_starttime'] && $time <= $coupon['register_send_endtime']){
|
|
|
if ($coupon['register_send_switch'] == '1' && $time >= $coupon['register_send_starttime'] && $time <= $coupon['register_send_endtime']) {
|
|
|
UserCoupon::create([
|
|
|
'user_id' => $userid,
|
|
|
'coupon_id' => $coupon['id'],
|
|
|
'name' => $coupon['name'],
|
|
|
'price' => $coupon['price'],
|
|
|
'full_price' => $coupon['full_price'],
|
|
|
'endtime' => $time+$coupon['days']*86400
|
|
|
'endtime' => $time + $coupon['days'] * 86400,
|
|
|
]);
|
|
|
}
|
|
|
$this->success('登录成功',['token'=>$this->auth->getToken(),'user_type'=>$this->auth->user_type]);
|
|
|
}else{
|
|
|
$this->success('登录成功', ['token' => $this->auth->getToken(), 'user_type' => $this->auth->user_type]);
|
|
|
} else {
|
|
|
$this->error('注册失败');
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -177,7 +177,7 @@ class User extends Api |
|
|
}
|
|
|
// 获取session_key
|
|
|
$user = $this->auth->getUser();
|
|
|
$third = \app\api\model\Third::where('user_id',$user['id'])->field('session_key')->find();
|
|
|
$third = \app\api\model\Third::where('user_id', $user['id'])->field('session_key')->find();
|
|
|
empty($third) && $this->error('请先登录');
|
|
|
// 获取小程序配置
|
|
|
$app = Factory::miniProgram([
|
...
|
...
|
@@ -188,7 +188,7 @@ class User extends Api |
|
|
// 更新手机号
|
|
|
$user->mobile = $res['purePhoneNumber'];
|
|
|
$user->save();
|
|
|
$this->success('授权成功',['mobile' => $res['purePhoneNumber']]);
|
|
|
$this->success('授权成功', ['mobile' => $res['purePhoneNumber']]);
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -220,12 +220,12 @@ class User extends Api |
|
|
$model = new UserCoupon();
|
|
|
|
|
|
// 更新已过期状态
|
|
|
$model->where('status','0')->where('user_id',$this->auth->id)->where('endtime','<',time())->update(['status'=>'2']);
|
|
|
$model->where('status', '0')->where('user_id', $this->auth->id)->where('endtime', '<', time())->update(['status' => '2']);
|
|
|
|
|
|
$type = $this->request->post('type');
|
|
|
if (!in_array($type,[0,1,2])) $this->error('type参数不合法');
|
|
|
$list = $model->where('status',$type)->where('user_id',$this->auth->id)->select();
|
|
|
$this->success('用户优惠券列表',$list);
|
|
|
if (!in_array($type, [0, 1, 2])) $this->error('type参数不合法');
|
|
|
$list = $model->where('status', $type)->where('user_id', $this->auth->id)->select();
|
|
|
$this->success('用户优惠券列表', $list);
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -255,8 +255,8 @@ class User extends Api |
|
|
public function userAddressList()
|
|
|
{
|
|
|
$model = new UserAddress();
|
|
|
$list = $model->where('user_id',$this->auth->id)->order('normal_status','desc')->select();
|
|
|
$this->success('用户地址列表',$list);
|
|
|
$list = $model->where('user_id', $this->auth->id)->order('normal_status', 'desc')->select();
|
|
|
$this->success('用户地址列表', $list);
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -319,7 +319,7 @@ class User extends Api |
|
|
$validate->message($msg);
|
|
|
if (!$validate->check($data)) $this->error($validate->getError());
|
|
|
$model = new UserAddress();
|
|
|
if ($type == 1){
|
|
|
if ($type == 1) {
|
|
|
$data = [
|
|
|
'mobile' => $mobile,
|
|
|
'normal_status' => $normal,
|
...
|
...
|
@@ -329,10 +329,10 @@ class User extends Api |
|
|
'address' => $address,
|
|
|
'address_detail' => $address_detail,
|
|
|
];
|
|
|
if ($normal == 1) $model->isUpdate()->save(['normal_status'=>'0'],['user_id'=>$this->auth->id]);
|
|
|
$model->isUpdate()->save($data,['id'=>$id]);
|
|
|
}else{
|
|
|
$model->where('id',$id)->delete();
|
|
|
if ($normal == 1) $model->isUpdate()->save(['normal_status' => '0'], ['user_id' => $this->auth->id]);
|
|
|
$model->isUpdate()->save($data, ['id' => $id]);
|
|
|
} else {
|
|
|
$model->where('id', $id)->delete();
|
|
|
}
|
|
|
$this->success('SUCCESS');
|
|
|
}
|
...
|
...
|
@@ -402,7 +402,7 @@ class User extends Api |
|
|
'address' => $address,
|
|
|
'address_detail' => $address_detail,
|
|
|
];
|
|
|
if ($normal == 1) $model->isUpdate()->save(['normal_status'=>'0'],['user_id'=>$this->auth->id]);
|
|
|
if ($normal == 1) $model->isUpdate()->save(['normal_status' => '0'], ['user_id' => $this->auth->id]);
|
|
|
$model->isUpdate(false)->save($data);
|
|
|
|
|
|
$this->success('SUCCESS');
|
...
|
...
|
@@ -472,8 +472,8 @@ class User extends Api |
|
|
if (!$validate->check($data)) $this->error($validate->getError());
|
|
|
|
|
|
// 禁止连点
|
|
|
!empty(cache('joinus_'.$username)) && $this->error('操作频繁,请稍后再试');
|
|
|
cache('joinus_'.$username,'123',5);
|
|
|
!empty(cache('joinus_' . $username)) && $this->error('操作频繁,请稍后再试');
|
|
|
cache('joinus_' . $username, '123', 5);
|
|
|
|
|
|
$data['createtime'] = time();
|
|
|
Db::name('join_us')->insert($data);
|
...
|
...
|
@@ -512,9 +512,9 @@ class User extends Api |
|
|
$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'=>$this->auth->rider,'mobile'=>Config::get('site.work_mobile')]);
|
|
|
->order('id', 'desc')
|
|
|
->paginate(15, false, ['page' => $page]);
|
|
|
$this->success('SUCCESS', ['list' => $list, 'rider_status' => $this->auth->rider, 'mobile' => Config::get('site.work_mobile')]);
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -537,13 +537,13 @@ class User extends Api |
|
|
$mobile = $this->request->post('mobile');
|
|
|
if (!$cotent) $this->error('请填写意见描述');
|
|
|
if (mb_strlen($cotent) > 100) $this->error('请将意见描述控制在100字以内');
|
|
|
if (!$mobile || !preg_match('/^1\d{10}$/',$mobile)) $this->error('请正确填写联系方式');
|
|
|
if (!$mobile || !preg_match('/^1\d{10}$/', $mobile)) $this->error('请正确填写联系方式');
|
|
|
$data = [
|
|
|
'user_id' => $this->auth->id,
|
|
|
'cotent' => $cotent,
|
|
|
'images' => $images,
|
|
|
'mobile' => $mobile,
|
|
|
'createtime' => time()
|
|
|
'createtime' => time(),
|
|
|
];
|
|
|
Db::name('opinion')->insert($data);
|
|
|
$this->success('SUCCESS');
|
...
|
...
|
@@ -561,7 +561,7 @@ class User extends Api |
|
|
*/
|
|
|
public function riderApply()
|
|
|
{
|
|
|
if (in_array($this->auth->rider,[1,2])){
|
|
|
if (in_array($this->auth->rider, [1, 2])) {
|
|
|
$this->error('您已申请,不可重复申请');
|
|
|
}
|
|
|
$user = $this->auth->getUser();
|
...
|
...
|
@@ -597,19 +597,19 @@ class User extends Api |
|
|
public function inviteReward()
|
|
|
{
|
|
|
$model = new \app\api\model\User();
|
|
|
$coupon = Db::name('coupon')->where('id',1)->field('price,full_price,endtime')->find();
|
|
|
$coupon['endtime'] = date('Y年m月d日',$coupon['endtime']);
|
|
|
$coupon = Db::name('coupon')->where('id', 1)->field('price,full_price,endtime')->find();
|
|
|
$coupon['endtime'] = date('Y年m月d日', $coupon['endtime']);
|
|
|
$coupon['rule'] = Config::get('site.invite_rule');
|
|
|
$coupon['user_list'] = $model
|
|
|
->where('invite_user_id',$this->auth->id)
|
|
|
->where('invite_status','1')
|
|
|
->where('invite_user_id', $this->auth->id)
|
|
|
->where('invite_status', '1')
|
|
|
->limit(3)
|
|
|
->select();
|
|
|
foreach ($coupon['user_list'] as $key => $value){
|
|
|
foreach ($coupon['user_list'] as $key => $value) {
|
|
|
$value->visible(['nickname']);
|
|
|
}
|
|
|
$coupon['invite_id'] = $this->auth->id;
|
|
|
$this->success('邀请有奖',$coupon);
|
|
|
$this->success('邀请有奖', $coupon);
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -640,15 +640,15 @@ class User extends Api |
|
|
*/
|
|
|
public function taxList()
|
|
|
{
|
|
|
$page = $this->request->post('page',1);
|
|
|
$page = $this->request->post('page', 1);
|
|
|
$model = new Tax();
|
|
|
$list = $model
|
|
|
->where('user_id',$this->auth->id)
|
|
|
->where('del_status','normal')
|
|
|
->where('user_id', $this->auth->id)
|
|
|
->where('del_status', 'normal')
|
|
|
->field('id,company_name,username,type,price,tax_time')
|
|
|
->order('id','desc')
|
|
|
->paginate(5,false,['page'=>$page]);
|
|
|
$this->success('发票管理列表',$list);
|
|
|
->order('id', 'desc')
|
|
|
->paginate(5, false, ['page' => $page]);
|
|
|
$this->success('发票管理列表', $list);
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -686,7 +686,7 @@ class User extends Api |
|
|
$eamil = $this->request->post('eamil');
|
|
|
$order_no = $this->request->post('order_no');
|
|
|
//校验数据
|
|
|
if (!in_array($type,[1,2])) $this->error('type参数不合法');
|
|
|
if (!in_array($type, [1, 2])) $this->error('type参数不合法');
|
|
|
$data = [
|
|
|
'mobile' => $mobile,
|
|
|
'eamil' => $eamil,
|
...
|
...
|
@@ -702,9 +702,9 @@ class User extends Api |
|
|
'eamil' => '电子邮箱格式不正确',
|
|
|
'order_no' => '请输入订单编号',
|
|
|
];
|
|
|
$validate = new \think\Validate($rule,$msg);
|
|
|
$validate = new \think\Validate($rule, $msg);
|
|
|
if (!$validate->check($data)) $this->error($validate->getError());
|
|
|
if ($type == 2){
|
|
|
if ($type == 2) {
|
|
|
$data = [
|
|
|
'company_name' => $company_name,
|
|
|
'company_mobile' => $company_mobile,
|
...
|
...
|
@@ -726,9 +726,9 @@ class User extends Api |
|
|
'company_address' => '请填写公司地址',
|
|
|
'bank' => '请填写开户银行',
|
|
|
];
|
|
|
$validate = new \think\Validate($rule,$msg);
|
|
|
$validate = new \think\Validate($rule, $msg);
|
|
|
if (!$validate->check($data)) $this->error($validate->getError());
|
|
|
}else{
|
|
|
} else {
|
|
|
$data = [
|
|
|
'username' => $username,
|
|
|
];
|
...
|
...
|
@@ -738,12 +738,12 @@ class User extends Api |
|
|
$msg = [
|
|
|
'username' => '请填写个人/非企业单位名称',
|
|
|
];
|
|
|
$validate = new \think\Validate($rule,$msg);
|
|
|
$validate = new \think\Validate($rule, $msg);
|
|
|
if (!$validate->check($data)) $this->error($validate->getError());
|
|
|
}
|
|
|
//校验订单编号
|
|
|
$orderModel = new \app\api\model\Order();
|
|
|
$order = $orderModel::get(['order_no'=>$order_no]);
|
|
|
$order = $orderModel::get(['order_no' => $order_no]);
|
|
|
if (!$order) $this->error('订单编号不存在');
|
|
|
if ($order['user_id'] != $this->auth->id) $this->error('当前用户无权使用此订单编号');
|
|
|
// 插入数据
|
...
|
...
|
@@ -783,12 +783,12 @@ class User extends Api |
|
|
{
|
|
|
$ids = $this->request->post('ids');
|
|
|
//校验数据
|
|
|
$ids = explode(',',$ids);
|
|
|
foreach ($ids as $key => $value){
|
|
|
$ids = explode(',', $ids);
|
|
|
foreach ($ids as $key => $value) {
|
|
|
if (!is_numeric($value)) $this->error('ids参数不合法');
|
|
|
}
|
|
|
$model = new Tax();
|
|
|
$model->isUpdate()->save(['del_status' => 'hidden'],['id' => ['in',$ids]]);
|
|
|
$model->isUpdate()->save(['del_status' => 'hidden'], ['id' => ['in', $ids]]);
|
|
|
$this->success('SUCCESS');
|
|
|
}
|
|
|
|
...
|
...
|
@@ -799,7 +799,7 @@ class User extends Api |
|
|
*/
|
|
|
public function developLogin()
|
|
|
{
|
|
|
$account = $this->request->post('account');
|
|
|
$account = $this->request->param('account');
|
|
|
if (!$account) {
|
|
|
$this->error(__('Invalid parameters'));
|
|
|
}
|
...
|
...
|
@@ -821,14 +821,15 @@ class User extends Api |
|
|
* 测试
|
|
|
* @ApiInternal
|
|
|
*/
|
|
|
public function notice(){
|
|
|
public function notice()
|
|
|
{
|
|
|
$client = new Client();
|
|
|
$response = $client->request('POST', request()->domain().":2121/", [
|
|
|
$response = $client->request('POST', request()->domain() . ":2121/", [
|
|
|
'form_params' => [
|
|
|
'type' => 'publish',
|
|
|
'content' => '这个是推送的测试数据',
|
|
|
'to' => '',
|
|
|
]
|
|
|
],
|
|
|
]);
|
|
|
halt($response->getBody()->getContents());
|
|
|
}
|
...
|
...
|
|