123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473 |
- <?php
- namespace app\data\controller\api\business;
- use app\data\controller\api\Auth;
- use app\data\model\DataMerchants;
- use app\data\model\ShopFeedback;
- use app\data\model\SystemUserAddress;
- use app\data\model\SystemUserAmount;
- use app\data\model\SystemUserBank;
- use app\data\model\SystemUserWithdrawal;
- use think\admin\Controller;
- use hg\apidoc\annotation\Title;
- use hg\apidoc\annotation\Method;
- use hg\apidoc\annotation\Param;
- use hg\apidoc\annotation\Returned;
- use think\admin\model\SystemUser;
- use think\Request;
- /**
- * 商家个人中心
- */
- class User extends Auth
- {
- /**
- * 控制器初始化
- */
- protected function initialize()
- {
- $purchase_model = new Common($this->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)->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="性别")
- * @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="新密码")
- * @return void
- */
- public function user_password(){
- $admin_id= $this->user->id;
- $data = $this->_vali(
- [
- 'old_password.require'=>'原始密码不能为空',
- 'new_password.require'=>'新密码不能为空'
- ]
- );
- if($this->user->password!=md5($data['old_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('提现账号有问题');
- }
- $withdrawal_data = [
- 'admin_id'=>$admin_id,
- 'real_name'=>$data['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'=>10,
- 'amount'=>$data['money']-10,
- 'create_time'=>date('Y-m-d H:i:s'),
- 'status'=>1
- ];
- SystemUserWithdrawal::mk()->insertGetId($withdrawal_data);
- $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();
- $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('更新成功');
- }
- }
|