app); $user = $purchase_model->uuid(); $this->user = $user; } /** * @Title ("用户信息") * @Method ("get") * @Returned("merchant.head_img",desc="商家头像") * @Returned("merchant.name",desc="商家名称") * @Returned("merchant.full_address",desc="详细地址") * @Returned("merchant.contact_name",desc="联系人") * @Returned("merchant.contact_phone",desc="联系电话") * @Returned("merchant.intro",desc="商家简介") * @Returned("merchant.imgs_videos",desc="图片及视频") * @Returned("merchant.business_img",desc="营业执照") * @Returned("merchant.longitude",desc="经度") * @Returned("merchant.latitude",desc="纬度") */ public function user_info(){ $user_info = $this->user; $user_info['merchant']=DataMerchants::getByAdmin($user_info['id']); $this->success('用户信息',$user_info); } /** * @Title ("意见反馈") * @Method ("post") * @Param ("title",desc="反馈标题") * @Param ("content",desc="反馈内容") * @Param ("image",desc="图片") * @Param ("phone",desc="联系方式") * @return void */ public function feedback(){ $data = $this->_vali([ 'title.require'=>'反馈标题不能为空', 'content.require'=>'反馈内容不能为空', 'image.default'=>'', 'phone.require'=>'联系方式不能为空' ]); $feedback_data= [ 'admin_id'=>$this->user->id, 'title'=>$data['title'], 'content'=>$data['content'], 'image'=>$data['image'], 'phone'=>$data['phone'], 'status'=>1, 'create_time'=>date('Y-m-d H:i:s') ]; ShopFeedback::mk()->insert($feedback_data); $this->success('意见反馈已提交'); } /** * @Title ("反馈意见列表") * @Method ("get") * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function feedback_list(){ $admin_id = $this->user->id; $list = ShopFeedback::mk()->where('admin_id',$admin_id)->where('is_del',1)->select(); $this->success('反馈意见列表',$list); } /** * @Title ("删除意见") * @Method ("post") * @Param ("feedback_id",desc="删除意见数据id") * @return void */ public function del_feedback(){ $data = $this->_vali( [ 'feedback_id.require'=>"参数不能为空", ] ); $admin_id =$this->user->id; ShopFeedback::mk()->where('id',$data['feedback_id'])->where('admin_id',$admin_id)->delete(); $this->success('反馈记录已删除'); } /** * @Title ("编辑意见信息") * @Method ("post") * @Param ("feedback_id",desc="编辑意见数据id") * @Param ("title",desc="反馈标题") * @Param ("content",desc="反馈内容") * @Param ("image",desc="图片") * @Param ("phone",desc="联系方式") * @return void */ public function save_feedback(){ $data = $this->_vali( [ 'feedback_id.require'=>"参数不能为空", 'title.require'=>'反馈标题不能为空', 'content.require'=>'反馈内容不能为空', 'image.default'=>'', 'phone.require'=>'联系方式不能为空' ] ); $feedback_data=[ 'title'=>$data['title'], 'content'=>$data['content'], 'image'=>$data['image'], 'phone'=>$data['phone'], 'status'=>1, 'create_time'=>date('Y-m-d H:i:s') ]; $admin_id =$this->user->id; ShopFeedback::mk()->where('id',$data['feedback_id'])->where('admin_id',$admin_id)->save($feedback_data); $this->success('反馈记录已删除'); } /** * @Title ("添加用户银行卡") * @Method("post") * @Param ("bank",desc="银行名称") * @Param ("number",desc="银行卡号") * @Param ("address",desc="开户行") * @Param ("real_name",desc="持卡人真是姓名") * @return void */ public function bank_add(){ $admin_id = $this->user->id; $data = $this->_vali([ 'bank.require'=>'银行名称不能空', 'number.require'=>'银行卡号不能为空', 'address.require'=>'开户行信息不能为空', 'real_name.require'=>'持卡人姓名不能为空' ]); $bank_data = [ 'admin_id'=>$admin_id, 'bank'=>$data['bank'], 'number'=>$data['number'], 'address'=>$data['address'], 'real_name'=>$data['real_name'] ]; SystemUserBank::mk()->insertGetId($bank_data); $this->success('银行卡添加成功'); } /** * @Title ("我的银行卡列表") * @Method ("get") * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function user_bank(){ $admin_id = $this->user->id; $query = SystemUserBank::mQuery(); $list = $query->where('admin_id',$admin_id)->order('id desc')->page(true, false, false, 10); $this->success('银行卡列表',$list); } /** * @Title ("银行卡解绑") * @Method ("post") * @Param ("bank_id",desc="银行卡id") * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function bank_del(){ $admin_id = $this->user->id; $data = $this->_vali( ['bank_id.require'=>'请选择解绑银行'] ); $is_have = SystemUserBank::mk()->where(['admin_id'=>$admin_id,'id'=>$data['bank_id']])->find(); if(empty($is_have)){ $this->error('解绑信息错误'); } SystemUserBank::mk()->where(['admin_id'=>$admin_id,'id'=>$data['bank_id']])->delete(); $this->success('银行卡已解绑'); } /** * @Title ("修改用户信息") * @Method ("post") * @Param ("headimg",desc="用户头像") * @Param ("nickname",desc="用户昵称") * @Param ("sex",desc="性别1男2女") * @return void */ public function user_edit(){ $admin_id= $this->user->id; $data = input(); $user_data = []; if(isset($data['headimg'])){ $user_data['headimg']=$data['headimg']; } if(isset($data['nickname'])){ $user_data['nickname']=$data['nickname']; } if(isset($data['sex'])){ $user_data['sex']=$data['sex']; } SystemUser::mk()->where('id',$admin_id)->save($user_data); $this->success('个人信息修改完成!'); } /** * @Title ("邮箱绑定") * @Method ("post") * @Param ("mailbox",desc="邮箱") * @return void */ public function user_mailbox(){ $admin_id = $this->user->id; $data = $this->_vali( ['mailbox.require'=>'邮箱不能为空!'] ); SystemUser::mk()->where('id',$admin_id)->save(['contact_mail'=>$data['mailbox']]); $this->success('邮箱绑定成功'); } /** * @Title ("修改密码") * @Method ("post") * @Param ("old_password",desc="原始密码") * @Param ("new_password",desc="新密码") * @Param ("again_new_password",desc="确认新密码") * @return void */ public function user_password(){ $admin_id= $this->user->id; $data = $this->_vali( [ 'old_password.require'=>'原始密码不能为空', 'new_password.require'=>'新密码不能为空', 'again_new_password.require'=>'新密码不能为空' ] ); if($this->user->password!=md5($data['old_password'])){ $this->error('原始密码不正确'); } if($data['new_password'] != $data['again_new_password']){ $this->error('新密码不一致'); } $token=rand('00000','99999'); SystemUser::mk()->where('id',$admin_id)->save(['password'=>md5($data['new_password']),'token'=>$token]); $this->success('密码重置成功请重新登录!'); } /** * @Title ("商家提现申请") * @Method ("post") * @Param ("bank_number",desc="提现卡号") * @Param ("money",desc="提现金额") * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function user_withdrawal(){ $admin_id= $this->user->id; $data = $this->_vali( [ 'bank_number.require'=>'提现卡号不能为空', 'money.require'=>'提现金额不能为空' ] ); if($data['money']<1){ $this->error('提现金额不能小于'.'1'); } if($data['money']>$this->user->money){ $this->error('余额不足'); } $bank_info = SystemUserBank::mk()->where(['admin_id'=>$admin_id,'number'=>$data['bank_number']])->find(); if(!$bank_info){ $this->error('提现账号有问题'); } $charges = $data['money']*0.1; $withdrawal_data = [ 'admin_id'=>$admin_id, 'real_name'=>$bank_info['real_name'], 'bank'=>$bank_info['bank'], 'number'=>$bank_info['number'], 'address'=>$bank_info['address'], 'money'=>$data['money'], 'before'=>$this->user->money, 'after'=>$this->user->money-$data['money'], 'charges'=>$charges, 'amount'=>$data['money']-$charges, 'create_time'=>date('Y-m-d H:i:s'), 'status'=>1 ]; $amount_data=[ 'admin_id'=>$admin_id, 'before'=>$this->user->money, 'after'=>$this->user->money-$data['money'], 'type'=>2, 'amount'=>$data['money'], 'form'=>'账户提现', 'create_time'=>date('Y-m-d H:i:s') ]; SystemUserWithdrawal::mk()->insertGetId($withdrawal_data); SystemUserAmount::mk()->insert($amount_data); SystemUser::mk()->where('id',$admin_id)->save(['money'=>$amount_data['after']]); $this->success('提现申请已提交,等待打款'); } /** * @Title ("余额记录") * @Method ("get") * @return void */ public function user_amount(){ $admin_id = $this->user->id; $query = SystemUserAmount::mQuery(); $list = $query->where('admin_id',$admin_id)->order('id desc')->page(true, false, false, 10); $list['money'] = $this->user->money; $list['bank_nunm']=SystemUserBank::mk()->where('admin_id',$admin_id)->count(); $list['service']=10; $this->success('余额记录明细',$list); } /** * @Title ("添加发货地址") * @Method ("post") * @Param ("name",desc="名称") * @Param ("phone",desc="联系方式") * @Param ("province",desc="省名称") * @Param ("city",desc="市名称") * @Param ("area",desc="区县名称") * @Param ("address",desc="详细地址") * @return void */ public function add_address(){ $admin_id = $this->user->id; $data = $this->_vali( [ 'name.require'=>'名称不能为空', 'phone.require'=>'联系方式不能为空', 'province.require'=>'省名称不能为空', 'city.require'=>'城市名称不能为空', 'area.require'=>'区县名称不能为空', 'address.require'=>'详细地址不能为空' ] ); $address_data = [ 'admin_id'=>$admin_id, 'name'=>$data['name'], 'phone'=>$data['phone'], 'province'=>$data['province'], 'city'=>$data['city'], 'area'=>$data['area'], 'address'=>$data['address'], ]; SystemUserAddress::mk()->insertGetId($address_data); $this->success('发货地址添加成功'); } /** * @Title ("发货地址列表") * @Method ("get") * @return void */ public function address_list() { $admin_id = $this->user->id; $query = SystemUserAddress::mQuery(); $list = $query->where('admin_id', $admin_id) ->order('id desc')->page(true, false, false, 10); $this->success('发货地址列表', $list); } /** * @Title ("编辑发货地址") * @Method ("post") * @Param ("address_id",desc="地址id") * @Param ("name",desc="名称") * @Param ("phone",desc="联系方式") * @Param ("province",desc="省名称") * @Param ("city",desc="市名称") * @Param ("area",desc="区县名称") * @Param ("address",desc="详细地址") * @return void */ public function address_edit(){ $admin_id = $this->user->id; $data = $this->_vali( [ 'address_id.require'=>'发货地址id', 'name.require'=>'名称不能为空', 'phone.require'=>'联系方式不能为空', 'province.require'=>'省名称不能为空', 'city.require'=>'城市名称不能为空', 'area.require'=>'区县名称不能为空', 'address.require'=>'详细地址不能为空' ] ); $address_data = [ 'admin_id'=>$admin_id, 'name'=>$data['name'], 'phone'=>$data['phone'], 'province'=>$data['province'], 'city'=>$data['city'], 'area'=>$data['area'], 'address'=>$data['address'], ]; SystemUserAddress::mk()->where('id',$data['address_id'])->save($address_data); $this->success('发货地址编辑成功'); } /** * @Title ("删除发货地址") * @Method ("post") * @Param ("address_id",desc="地址id") * @return void */ public function address_del(){ $admin_id = $this->user->id; $data = $this->_vali( [ 'address_id.require'=>'发货地址id', ] ); SystemUserAddress::mk()->where('id',$data['address_id'])->delete(); $this->success('删除成功'); } /** * @Title("编辑商家信息") * @Method("post") * @Param("head_img",desc="头像") * @Param("contact_name",desc="联系人") * @Param("contact_phone",desc="联系电话") * @Param("intro",desc="商家简介") * @Param("imgs_videos",desc="图片及视频,英文逗号隔开") */ public function edit(Request $request){ $data=$this->_vali([ 'contact_name.require'=>'请填写必填项', 'contact_name.max:30'=>'联系人过长', 'contact_phone.require'=>'请填写必填项', 'contact_phone.mobile'=>'联系电话有误', 'intro.require'=>'请填写必填项', 'intro.max:500'=>'简介最多500字符', 'imgs_videos.require'=>'请填写必填项', 'head_img.url'=>'头像必须是链接', ]); if(empty($data['head_img'])){ unset($data['head_img']); } $merchant=DataMerchants::getByAdmin($this->user['id']); $merchant->save($data); $this->success('更新成功'); } /** * @title("消息列表") */ public function message_list(){ $data = $this->_vali([ 'type.require'=>'参数缺失', ]); $messagelist = SystemUserMessage::mk() ->where('type',$data['type']) ->where('status',1) ->where('deleted',0) ->where('uuid',$this->user['id']) ->withoutField('deleted,status') ->order('id desc') ->paginate()->toArray(); foreach ($messagelist['data'] as &$v){ $v['is_read'] = SystemUserMessageRead::mk()->where('uuid',$this->user['id'])->where('message_id',$v['id'])->count() ? 1 : 0; } $this->success('成功',$messagelist); } /** * @Title ("消息详情") * @Method ("post") * @Param ("id") */ public function message_details(){ $data = $this->_vali([ 'id.require'=>'参数缺失', ]); $messagedetails = SystemUserMessage::mk() ->where('id',$data['id']) ->where('status',1) ->where('deleted',0) ->findOrEmpty(); SystemUserMessageRead::mk()->where('uuid',$this->user['id'])->where('message_id',$data['id'])->count() ? : SystemUserMessageRead::mk()->insert(['message_id'=>$data['id'],'uuid'=>$this->user['id']]); $this->success('成功',$messagedetails); } /** * @Title("消息未读数量") * @Method("post") * @Returned("notice_count",desc="系统消息未读数量") * @Returned("order_count",desc="订单通知未读数量") */ public function messagenoread(){ $userid = $this->user['id']; $notice = SystemUserMessage::mk() ->where('type','1') ->where('status',1) ->where('deleted',0) ->where('uuid',$userid) ->column('id'); $order = SystemUserMessage::mk() ->where('type','2') ->where('status',1) ->where('deleted',0) ->where('uuid',$userid) ->column('id'); $notice_read_count = SystemUserMessageRead::mk()->where('uuid',$userid)->whereIn('message_id',$notice)->count(); $order_read_count = SystemUserMessageRead::mk()->where('uuid',$userid)->whereIn('message_id',$order)->count(); $array = [ 'message_count'=>count($notice)-$notice_read_count, 'order_count'=>count($order)-$order_read_count ]; $this->success('成功',$array); } /** * @Title("账号注销") * @Method("post") * */ public function cancellation(){ if (SystemUser::mk()->where('id',$this->user['id'])->update(['status'=>0])){ $this->success('注销成功'); } $this->error('注销失败'); } }