From 2ef90f9403ca446ef315536008125dc792301d64 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 1 Jun 2024 13:32:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E4=BB=A3=E7=A0=81(=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=9B=B8=E5=85=B3,=E5=95=86=E5=93=81=E5=88=86?= =?UTF-8?q?=E7=B1=BB)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/LoginController.php | 8 +- .../controller/goods/GoodsclassController.php | 29 +++++ app/api/controller/user/AddressController.php | 99 ++++++++++++++++ app/api/controller/user/UserController.php | 2 +- .../user/UserFeedbackController.php | 34 ++++++ app/api/lists/goods/GoodsclassLists.php | 102 +++++++++++++++++ app/api/lists/user/UserAddressList.php | 63 +++++++++++ app/api/lists/user/UserFeedbackLists.php | 64 +++++++++++ app/api/logic/user/AddressLogic.php | 106 ++++++++++++++++++ app/api/logic/user/UserFeedbackLogic.php | 38 +++++++ app/api/logic/user/UserLogic.php | 59 ++++++++++ app/api/validate/PayValidate.php | 54 +++++++++ app/api/validate/UserAddressValidate.php | 93 +++++++++++++++ app/common/model/goods/Goodsclass.php | 29 +++++ app/common/model/merchant/Merchant.php | 27 +++++ app/common/model/user/UserAddress.php | 22 ++++ 16 files changed, 824 insertions(+), 5 deletions(-) create mode 100644 app/api/controller/goods/GoodsclassController.php create mode 100644 app/api/controller/user/AddressController.php create mode 100644 app/api/controller/user/UserFeedbackController.php create mode 100644 app/api/lists/goods/GoodsclassLists.php create mode 100644 app/api/lists/user/UserAddressList.php create mode 100644 app/api/lists/user/UserFeedbackLists.php create mode 100644 app/api/logic/user/AddressLogic.php create mode 100644 app/api/logic/user/UserFeedbackLogic.php create mode 100644 app/api/logic/user/UserLogic.php create mode 100644 app/api/validate/PayValidate.php create mode 100644 app/api/validate/UserAddressValidate.php create mode 100644 app/common/model/goods/Goodsclass.php create mode 100644 app/common/model/merchant/Merchant.php create mode 100644 app/common/model/user/UserAddress.php diff --git a/app/api/controller/LoginController.php b/app/api/controller/LoginController.php index 0fdf52c37..129650aba 100644 --- a/app/api/controller/LoginController.php +++ b/app/api/controller/LoginController.php @@ -3,7 +3,7 @@ namespace app\api\controller; use app\api\logic\LoginLogic; -use app\api\validate\{LoginAccountValidate, RegisterValidate, WebScanLoginValidate, WechatLoginValidate}; +use app\api\validate\{LoginAccountValidate, WechatLoginValidate}; use app\common\model\user\UserAuth; class LoginController extends BaseApiController @@ -35,7 +35,7 @@ class LoginController extends BaseApiController /** * @notes 小程序-登录接口 - * @return \think\response\Json + * @return * @author 段誉 * @date 2022/9/20 19:48 */ @@ -52,7 +52,7 @@ class LoginController extends BaseApiController /** * @notes 小程序绑定微信 - * @return \think\response\Json + * @return * @author 段誉 * @date 2022/9/20 19:48 */ @@ -69,7 +69,7 @@ class LoginController extends BaseApiController /** * @notes 更新用户头像昵称 - * @return \think\response\Json + * @return * @author 段誉 * @date 2023/2/22 11:15 */ diff --git a/app/api/controller/goods/GoodsclassController.php b/app/api/controller/goods/GoodsclassController.php new file mode 100644 index 000000000..51b8af4e3 --- /dev/null +++ b/app/api/controller/goods/GoodsclassController.php @@ -0,0 +1,29 @@ +dataLists(new GoodsclassLists()); + } + + +} \ No newline at end of file diff --git a/app/api/controller/user/AddressController.php b/app/api/controller/user/AddressController.php new file mode 100644 index 000000000..6069d496f --- /dev/null +++ b/app/api/controller/user/AddressController.php @@ -0,0 +1,99 @@ +dataLists(new UserAddressList()); + } + /** + * @notes 添加地址 + * @return \think\response\Json + * @author likeadmin + * @date 2024/4/24 10:37 + */ + public function create() + { + $params = (new UserAddressValidate())->post()->goCheck('add'); + $params['uid'] = $this->request->userId; + $res=AddressLogic::add($params); + if(AddressLogic::hasError()){ + return $this->fail(AddressLogic::getError()); + }else{ + return $this->success('添加成功'); + } + } + /** + * 商户给用户添加地址 + */ + public function merchant_create() + { + $params = $this->request->post(); + if($params['order_id'] && $params['order_id']!=0){ + $uid=Cashierclass::where('id',$params['order_id'])->value('uid'); + if(!$uid || $uid<=0){ + return $this->fail('订单不存在'); + } + } + $params['uid'] = $uid; + $res=AddressLogic::add($params); + if(AddressLogic::hasError()){ + return $this->fail(AddressLogic::getError()); + }else{ +// Cashierclass::where('id',$params['order_id'])->update(['address_id'=>$res,'real_name'=>$params['real_name'],'user_phone'=>$params['phone'],'user_address'=>$params['detail']]); + return $this->success('添加成功'); + } + } + /** + * @notes 编辑地址 + * @return \think\response\Json + * @author likeadmin + * @date 2024/4/24 10:37 + */ + public function edit() + { + $params = (new UserAddressValidate())->post()->goCheck('edit'); + $params['uid'] = $this->request->userId; + if(AddressLogic::edit($params)){ + return $this->success('编辑成功'); + }else{ + return $this->fail(AddressLogic::getError()); + } + } + + + /** + * @notes 删除地址 + * @return \think\response\Json + * @author likeadmin + * @date 2024/4/24 10:37 + */ + public function delete() + { + $params = (new UserAddressValidate())->post()->goCheck('delete'); + if(AddressLogic::delete($params)){ + return $this->success('删除成功'); + }else{ + return $this->fail(AddressLogic::getError()); + } + } + + /** + * @notes 获取地址详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/4/24 10:37 + */ + public function detail() + { + $params = (new UserAddressValidate())->goCheck('detail'); + return $this->success('获取成功',AddressLogic::detail($params)); + } +} diff --git a/app/api/controller/user/UserController.php b/app/api/controller/user/UserController.php index 6fc92c844..055c9bd6b 100644 --- a/app/api/controller/user/UserController.php +++ b/app/api/controller/user/UserController.php @@ -19,7 +19,7 @@ class UserController extends BaseApiController /** * @notes 获取小程序手机号 - * @return \think\response\Json + * @return * @author 段誉 * @date 2022/9/21 16:46 */ diff --git a/app/api/controller/user/UserFeedbackController.php b/app/api/controller/user/UserFeedbackController.php new file mode 100644 index 000000000..e65ecabd4 --- /dev/null +++ b/app/api/controller/user/UserFeedbackController.php @@ -0,0 +1,34 @@ +dataLists(new UserFeedbackLists()); + } + + + public function add() + { + $params = (new UserFeedbackValidate())->post()->goCheck('add'); + $result = UserFeedbackLogic::add($params,$this->request->userInfo['user_id']); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(UserFeedbackLogic::getError()); + } + } \ No newline at end of file diff --git a/app/api/lists/goods/GoodsclassLists.php b/app/api/lists/goods/GoodsclassLists.php new file mode 100644 index 000000000..d2c84d36e --- /dev/null +++ b/app/api/lists/goods/GoodsclassLists.php @@ -0,0 +1,102 @@ + ['pid', 'name', 'data', 'pic', 'sort'], + ]; + } + + + /** + * @notes 获取商品分类列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/04/23 10:27 + */ + public function lists(): array + { + $pid=Request()->get('pid',0); + if($pid==0){ + $lists = Goodsclass::where($this->searchWhere) + ->where('pid', 0) + ->where('children','<>',null) + ->field(['id', 'pid', 'name', 'data', 'pic', 'sort']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['sort' => 'desc','id' => 'desc']) + ->select()->toArray(); + }else{ + $three=Request()->get('three',0); + if($three==0){ + $where[]=['children','<>','']; + $this->where=$where; + } + $lists = Goodsclass::where($this->searchWhere) + ->where($this->where) + ->field(['id', 'pid', 'name', 'data', 'pic', 'sort']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['sort' => 'desc','id' => 'desc']) + ->select()->toArray(); + } + // ->each(function ($item) { + // $a = Goodsclass::where('pid', $item['id'])->field(['id', 'pid', 'name', 'data', 'pic', 'sort'])->select(); + // $item['children'] = $a; + // foreach ($a as $k => &$v) { + // $b = Goodsclass::where('pid', $v['id'])->field(['id', 'pid', 'name', 'data', 'pic', 'sort'])->select(); + // $v['children'] = $b; + // } + // })->toArray(); + return $lists; + // return linear_to_tree($lists, 'children'); + + } + + + /** + * @notes 获取商品分类数量 + * @return int + * @author likeadmin + * @date 2024/04/23 10:27 + */ + public function count(): int + { + $pid=Request()->get('pid',0); + if($pid==0){ + return Goodsclass::where($this->searchWhere)->where('pid', 0) + ->where('children','<>',null) + ->count(); + }else{ + return Goodsclass::where($this->searchWhere) + ->where($this->where) + ->count(); + } + + } + +} \ No newline at end of file diff --git a/app/api/lists/user/UserAddressList.php b/app/api/lists/user/UserAddressList.php new file mode 100644 index 000000000..b6bacad2c --- /dev/null +++ b/app/api/lists/user/UserAddressList.php @@ -0,0 +1,63 @@ +request->userId; + if(!$user_id) return []; + return UserAddress::where($this->searchWhere)->where('uid',$user_id) + ->field('address_id,real_name,detail,phone,is_default') + ->limit($this->limitOffset, $this->limitLength) + ->order(['address_id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取地址数量 + * @return int + * @date 2024/04/27 11:26 + */ + public function count(): int + { + $user_id=$this->request->userId; + return UserAddress::where($this->searchWhere)->where('uid',$user_id)->count(); + } + +} \ No newline at end of file diff --git a/app/api/lists/user/UserFeedbackLists.php b/app/api/lists/user/UserFeedbackLists.php new file mode 100644 index 000000000..7d841d1a4 --- /dev/null +++ b/app/api/lists/user/UserFeedbackLists.php @@ -0,0 +1,64 @@ + ['uid'], + '%like%' => ['name', 'contact'], + ]; + } + + + /** + * @notes 获取用户反馈表列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/05/13 16:56 + */ + public function lists(): array + { + $uid = $this->request->userInfo['user_id']; + return UserFeedback::where($this->searchWhere)->where('uid',$uid) + ->field(['id', 'uid', 'content', 'images', 'name', 'contact','create_time']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($data){ + $user = User::field('nickname')->where('id',$data['uid'])->findOrEmpty(); + $data['user_name'] = !$user->isEmpty() ? $user['nickname'] : ''; + }) + ->toArray(); + } + + + /** + * @notes 获取用户反馈表数量 + * @return int + * @author likeadmin + * @date 2024/05/13 16:56 + */ + public function count(): int + { + return UserFeedback::where($this->searchWhere)->count(); + } + + } \ No newline at end of file diff --git a/app/api/logic/user/AddressLogic.php b/app/api/logic/user/AddressLogic.php new file mode 100644 index 000000000..a1efca0c1 --- /dev/null +++ b/app/api/logic/user/AddressLogic.php @@ -0,0 +1,106 @@ +update(['is_default'=>0]); + }else{ + $params['is_default']=1; + } + $id=UserAddress::insertGetId([ + 'uid' => $params['uid'], + 'real_name' => $params['real_name'], + 'phone' => $params['phone'], + 'detail' => $params['detail'], + 'is_default' => $params['is_default'], + ]); + Db::commit(); + return $id; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑地址表 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/04/24 10:37 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + if($params['is_default']==1){ + UserAddress::where('uid',$params['uid'])->update(['is_default'=>0]); + } + $data = [ + 'real_name' => $params['real_name'], + 'phone' => $params['phone'], + 'detail' => $params['detail'], + 'is_default' => $params['is_default'], + ]; + UserAddress::where('uid', $params['uid'])->where('address_id', $params['address_id'])->update($data); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除地址表 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/04/24 10:37 + */ + public static function delete(array $params): bool + { + return UserAddress::destroy($params['address_id']); + } + + + /** + * @notes 获取购物车表详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/04/24 10:37 + */ + public static function detail($params): array + { + return UserAddress::field('address_id,real_name,phone,detail,is_default')->findOrEmpty($params['address_id'])->toArray(); + } +} diff --git a/app/api/logic/user/UserFeedbackLogic.php b/app/api/logic/user/UserFeedbackLogic.php new file mode 100644 index 000000000..42cba90e6 --- /dev/null +++ b/app/api/logic/user/UserFeedbackLogic.php @@ -0,0 +1,38 @@ + $uid, + 'content' => $params['content'], + 'images' => $params['images'] ? json_encode($params['images']) : null, + 'name' => $params['name'], + 'contact' => $params['contact'], + 'create_time' => time(), + ]); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + } \ No newline at end of file diff --git a/app/api/logic/user/UserLogic.php b/app/api/logic/user/UserLogic.php new file mode 100644 index 000000000..939903a38 --- /dev/null +++ b/app/api/logic/user/UserLogic.php @@ -0,0 +1,59 @@ +getUserPhoneNumber($params['code']); + $phoneNumber = $response['phone_info']['purePhoneNumber'] ?? ''; + if (empty($phoneNumber)) { + throw new \Exception('获取手机号码失败'); + } + + $user = User::where([ + ['mobile', '=', $phoneNumber], + ['id', '<>', $params['user_id']] + ])->findOrEmpty(); + + if (!$user->isEmpty()) { + throw new \Exception('手机号已被其他账号绑定'); + } + + // 绑定手机号 + User::update([ + 'id' => $params['user_id'], + 'mobile' => $phoneNumber + ]); + + return true; + } catch (\Exception $e) { + self::setError($e->getMessage()); + return false; + } + } + + +} \ No newline at end of file diff --git a/app/api/validate/PayValidate.php b/app/api/validate/PayValidate.php new file mode 100644 index 000000000..87d2c4068 --- /dev/null +++ b/app/api/validate/PayValidate.php @@ -0,0 +1,54 @@ + 'require', + 'pay_way' => 'require|in:' . PayEnum::BALANCE_PAY . ',' . PayEnum::WECHAT_PAY . ',' . PayEnum::ALIPAY, + 'order_id' => 'require' + ]; + + + protected $message = [ + 'from.require' => '参数缺失', + 'pay_way.require' => '支付方式参数缺失', + 'pay_way.in' => '支付方式参数错误', + 'order_id.require' => '订单参数缺失' + ]; + + + /** + * @notes 支付方式场景 + * @return PayValidate + * @author 段誉 + * @date 2023/2/24 17:43 + */ + public function scenePayway() + { + return $this->only(['from', 'order_id']); + } + + + /** + * @notes 支付状态 + * @return PayValidate + * @author 段誉 + * @date 2023/3/1 16:17 + */ + public function sceneStatus() + { + return $this->only(['from', 'order_id']); + } + + + +} \ No newline at end of file diff --git a/app/api/validate/UserAddressValidate.php b/app/api/validate/UserAddressValidate.php new file mode 100644 index 000000000..30a1360b6 --- /dev/null +++ b/app/api/validate/UserAddressValidate.php @@ -0,0 +1,93 @@ + 'require', + 'phone' => 'require', + 'detail' => 'require', + 'address_id' => 'require', + "is_default"=>"require|in:0,1" + + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + + 'real_name' => '收货人姓名', + 'phone' => '收货人电话', + 'detail' => '收货人详细地址', + 'address_id' => '地址id', + "is_default"=>"默认地址" + + ]; + + + /** + * @notes 添加场景 + * @return UserAddressValidate + * @author likeadmin + * @date 2024/04/28 17:28 + */ + public function sceneAdd() + { + return $this->only(['real_name','phone','detail']); + } + + + /** + * @notes 编辑场景 + * @return UserAddressValidate + * @author likeadmin + * @date 2024/04/28 17:28 + */ + public function sceneEdit() + { + return $this->only(['real_name','phone','detail','address_id']); + } + + + /** + * @notes 删除场景 + * @return UserAddressValidate + * @author likeadmin + * @date 2024/04/28 17:28 + */ + public function sceneDelete() + { + return $this->only(['address_id']); + } + + + /** + * @notes 详情场景 + * @return UserAddressValidate + * @author likeadmin + * @date 2024/04/28 17:28 + */ + public function sceneDetail() + { + return $this->only(['address_id']); + } + +} \ No newline at end of file diff --git a/app/common/model/goods/Goodsclass.php b/app/common/model/goods/Goodsclass.php new file mode 100644 index 000000000..271298308 --- /dev/null +++ b/app/common/model/goods/Goodsclass.php @@ -0,0 +1,29 @@ +hasOne(User::class,'id','uid')->bind(['mer_real_name'=>'real_name']); + } +} \ No newline at end of file diff --git a/app/common/model/user/UserAddress.php b/app/common/model/user/UserAddress.php new file mode 100644 index 000000000..db3119db1 --- /dev/null +++ b/app/common/model/user/UserAddress.php @@ -0,0 +1,22 @@ +