发布于2022-08-03 18:12 阅读(1141) 评论(0) 点赞(13) 收藏(5)
银行卡、预约、秒杀折扣
\app\adminapi\controller\v1\application\wechat\StoreServiceInvite.php
\app\adminapi\route\app.php
\app\api\controller\v1\order\StoreOrderController.php
\app\api\controller\v1\user\UserBankController.php
\app\api\controller\v1\user\UserExtractController.php
\app\api\controller\v1\user\UserInviteController.php
\app\api\controller\v1\InviteController.php
\app\api\controller\v1\LoginController.php
\app\api\route\v1.php
\app\api\validate\user\BankValidate.php
\app\api\validate\user\InviteValidate.php
\app\api\validate\user\RegisterValidates.php
\app\dao\service\StoreServiceInviteDao.php
\app\dao\user\InviteDao.php
\app\dao\user\UserBankDao.php
\app\model\service\StoreServiceInvite.php
\app\model\user\Invite.php
\app\model\user\UserBank.php
\app\services\activity\StoreSeckillServices.php
\app\services\message\service\StoreServiceInviteServices.php
\app\services\product\product\StoreProductServices.php
\app\services\product\sku\StoreProductAttrValueServices.php
\app\services\user\InviteServices.php
\app\services\user\LoginServices.php
\app\services\user\UserBankServices.php
预约的表 eb_user_invite
eb_user 增加了一个 paypwd
eb_store_product_attr_value 表中增加了一个discount字段
eb_user_bank
phone
\app\adminapi\controller\v1\application\wechat\StoreServiceInvite.php
<?php namespace app\adminapi\controller\v1\application\wechat; use app\adminapi\controller\AuthController; use app\services\message\service\StoreServiceInviteServices; use think\facade\App; /** * 客服用户留言反馈 * Class StoreServiceFeedback * @package app\adminapi\controller\v1\application\wechat */ class StoreServiceInvite extends AuthController { /** * StoreServiceFeedback constructor. * @param App $app * @param StoreServiceFeedbackServices $services */ public function __construct(App $app, StoreServiceInviteServices $services) { parent::__construct($app); $this->services = $services; } /** * 获取留言列表 * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function index() { $where = $this->request->getMore([ ['title', ''], ['time', ''] ]); return app('json')->success($this->services->getInviteList($where)); } /** * 获取修改表单 * @param $id * @return mixed * @throws \FormBuilder\Exception\FormBuilderException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function edit($id) { if (!$id) { return app('json')->fail('缺少参数'); } return app('json')->success($this->services->editForm((int)$id)); } /** * 修改 * @param $id * @return mixed */ public function update($id) { $data = $this->request->postMore([ ['make', ''], ['status', 0], ]); if (!$id || !($invite = $this->services->get($id))) { return app('json')->fail('反馈内容不存在'); } $invite->make = $data['make']; if ($data['status']) { $invite->status = $data['status']; } $invite->save(); return app('json')->success('修改成功'); } /** * 删除反馈 * @param $id * @return mixed * @throws \Exception */ public function delete($id) { if (!$id) { return app('json')->fail('缺少参数'); } if ($this->services->delete($id)) { return app('json')->success('删除成功'); } else { return app('json')->fail('删除失败'); } } }
\app\adminapi\route\app.php
<?php // +---------------------------------------------------------------------- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ] // +---------------------------------------------------------------------- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved. // +---------------------------------------------------------------------- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 // +---------------------------------------------------------------------- // | Author: CRMEB Team <admin@crmeb.com> // +---------------------------------------------------------------------- use think\facade\Route; /** * 应用模块 相关路由 */ Route::group('app', function () { //小程序模板资源路由 Route::resource('routine', 'v1.application.routine.RoutineTemplate')->name('RoutineResource')->option(['real_name' => '小程序订阅消息']); //客服反馈接口 Route::resource('feedback', 'v1.application.wechat.StoreServiceFeedback')->only(['index', 'delete', 'update', 'edit'])->option(['real_name' => '用户反馈']); //用户预约接口 Route::resource('invite', 'v1.application.wechat.StoreServiceInvite')->only(['index', 'delete', 'update', 'edit'])->option(['real_name' => '用户预约']); //一键同步订阅消息 Route::get('routine/syncSubscribe', 'v1.application.routine.RoutineTemplate/syncSubscribe')->name('syncSubscribe')->option(['real_name' => '一键同步订阅消息']); //一键同步微信模版消息消息 Route::get('wechat/syncSubscribe', 'v1.application.wechat.WechatTemplate/syncSubscribe')->name('syncSubscribe')->option(['real_name' => '一键同步模版消息']); //修改状态 Route::put('routine/set_status/:id/:status', 'v1.application.routine.RoutineTemplate/set_status')->name('RoutineSetStatus')->option(['real_name' => '修改订阅消息状态']); //菜单值 Route::get('wechat/menu', 'v1.application.wechat.menus/index')->option(['real_name' => '微信公众号菜单列表']); //保存菜单 Route::post('wechat/menu', 'v1.application.wechat.menus/save')->option(['real_name' => '保存微信公众号菜单']); //微信模板消息资源路由 Route::resource('wechat/template', 'v1.application.wechat.WechatTemplate')->name('WechatTemplateResource')->option(['real_name' => '公众号模版消息']); //话术接口 Route::resource('wechat/speechcraft', 'v1.application.wechat.StoreServiceSpeechcraft')->option(['real_name' => '客服话术']); //话术分类接口 Route::resource('wechat/speechcraftcate', 'v1.application.wechat.StoreServiceSpeechcraftCate')->option(['real_name' => '客服话术分类']); //微信模板消息修改状态 Route::put('wechat/template/set_status/:id/:status', 'v1.application.wechat.WechatTemplate/set_status')->name('WechatTemplateSetStatus')->option(['real_name' => '修改关键字回复状态']); //关注回复 Route::get('wechat/reply', 'v1.application.wechat.Reply/reply')->option(['real_name' => '关注回复']); //获取关注回复二维码 Route::get('wechat/code_reply/:id', 'v1.application.wechat.Reply/code_reply')->option(['real_name' => '获取关注回复二维码']); //关键字回复列表 Route::get('wechat/keyword', 'v1.application.wechat.Reply/index')->option(['real_name' => '关键字回复列表']); //关键字详情 Route::get('wechat/keyword/:id', 'v1.application.wechat.Reply/read')->option(['real_name' => '关键字回复详情']); //保存关键字修改 Route::post('wechat/keyword/:id', 'v1.application.wechat.Reply/save')->option(['real_name' => '保存关键字回复']); //删除关键字 Route::delete('wechat/keyword/:id', 'v1.application.wechat.Reply/delete')->option(['real_name' => '删除关键字回复']); //修改关键字状态 Route::put('wechat/keyword/set_status/:id/:status', 'v1.application.wechat.Reply/set_status')->option(['real_name' => '修改关键字回复状态']); //图文列表 Route::get('wechat/news', 'v1.application.wechat.WechatNewsCategory/index')->option(['real_name' => '图文列表']); //详情 Route::get('wechat/news/:id', 'v1.application.wechat.WechatNewsCategory/read')->option(['real_name' => '图文详情']); //保存图文 Route::post('wechat/news', 'v1.application.wechat.WechatNewsCategory/save')->option(['real_name' => '保存图文']); //删除图文 Route::delete('wechat/news/:id', 'v1.application.wechat.WechatNewsCategory/delete')->option(['real_name' => '删除图文']); //发送图文消息 Route::post('wechat/push', 'v1.application.wechat.WechatNewsCategory/push')->option(['real_name' => '发送图文消息']); //用户行为列表 Route::get('wechat/action', 'v1.application.wechat.WechatMessage/index')->option(['real_name' => '用户行为列表']); //用户行为列表操作名称列表 Route::get('wechat/action/operate', 'v1.application.wechat.WechatMessage/operate')->option(['real_name' => '用户行为列表操作名称列表']); //客服列表 Route::get('wechat/kefu', 'v1.application.wechat.StoreService/index')->option(['real_name' => '客服列表']); //客服登录 Route::get('wechat/kefu/login/:id', 'v1.application.wechat.StoreService/keufLogin')->option(['real_name' => '客服登录']); //新增客服选择用户列表 Route::get('wechat/kefu/create', 'v1.application.wechat.StoreService/create')->option(['real_name' => '新增客服选择用户列表']); //新增客服表单 Route::get('wechat/kefu/add', 'v1.application.wechat.StoreService/add')->option(['real_name' => '添加客服表单']); //保存新建的数据 Route::post('wechat/kefu', 'v1.application.wechat.StoreService/save')->option(['real_name' => '添加客服']); //编辑客服表单 Route::get('wechat/kefu/:id/edit', 'v1.application.wechat.StoreService/edit')->option(['real_name' => '修改客服表单']); //保存编辑的数据 Route::put('wechat/kefu/:id', 'v1.application.wechat.StoreService/update')->option(['real_name' => '修改客服']); //删除 Route::delete('wechat/kefu/:id', 'v1.application.wechat.StoreService/delete')->option(['real_name' => '删除客服']); //修改状态 Route::put('wechat/kefu/set_status/:id/:status', 'v1.application.wechat.StoreService/set_status')->option(['real_name' => '修改客服状态']); //聊天记录 Route::get('wechat/kefu/record/:id', 'v1.application.wechat.StoreService/chat_user')->option(['real_name' => '聊天记录']); //查看对话 Route::get('wechat/kefu/chat_list', 'v1.application.wechat.StoreService/chat_list')->option(['real_name' => '查看对话']); //下载小程序模版页面数据 Route::get('routine/info', 'v1.application.routine.RoutineTemplate/getDownloadInfo')->option(['real_name' => '下载小程序页面数据']); //下载小程序模版 Route::post('routine/download', 'v1.application.routine.RoutineTemplate/downloadTemp')->option(['real_name' => '下载小程序模版']); })->middleware([ \app\http\middleware\AllowOriginMiddleware::class, \app\adminapi\middleware\AdminAuthTokenMiddleware::class, \app\adminapi\middleware\AdminCkeckRoleMiddleware::class, \app\adminapi\middleware\AdminLogMiddleware::class ]);
\app\api\controller\v1\order\StoreOrderController.php
<?php namespace app\api\controller\v1\order; use app\Request; use app\services\pay\PayServices; use app\services\shipping\ExpressServices; use app\services\system\admin\SystemAdminServices; use app\services\user\UserInvoiceServices; use app\services\activity\{lottery\LuckLotteryServices, StoreBargainServices, StoreCombinationServices, StorePinkServices, StoreSeckillServices }; use app\services\coupon\StoreCouponIssueServices; use app\services\order\{OtherOrderServices, StoreCartServices, StoreOrderCartInfoServices, StoreOrderComputedServices, StoreOrderCreateServices, StoreOrderEconomizeServices, StoreOrderInvoiceServices, StoreOrderRefundServices, StoreOrderServices, StoreOrderSuccessServices, StoreOrderTakeServices }; use app\services\pay\OrderPayServices; use app\services\pay\YuePayServices; use app\services\product\product\StoreProductReplyServices; use app\services\shipping\ShippingTemplatesServices; use app\services\system\attachment\SystemAttachmentServices; use app\services\system\store\SystemStoreServices; use crmeb\services\CacheService; use crmeb\services\UtilService; use think\facade\Cache; /** * 订单控制器 * Class StoreOrderController * @package app\api\controller\order */ class StoreOrderController { /** * @var StoreOrderServices */ protected $services; /** * @var int[] */ protected $getChennel = [ 'weixin' => 0, 'routine' => 1, 'weixinh5' => 2, 'pc' => 3 ]; /** * StoreOrderController constructor. * @param StoreOrderServices $services */ public function __construct(StoreOrderServices $services) { $this->services = $services; } /** * 订单确认 * @param Request $request * @return mixed */ public function confirm(Request $request, ShippingTemplatesServices $services) { if (!$services->get(1, ['id'])) { return app('json')->fail('默认模板未配置,无法下单'); } [$cartId, $new, $addressId] = $request->postMore([ 'cartId', 'new', ['addressId', 0] ], true); if (!is_string($cartId) || !$cartId) { return app('json')->fail('请提交购买的商品'); } $user = $request->user()->toArray(); return app('json')->successful($this->services->getOrderConfirmData($user, $cartId, !!$new, $addressId)); } /** * 计算订单金额 * @param Request $request * @param $key * @return mixed * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function computedOrder(Request $request, StoreOrderComputedServices $computedServices, $key) { if (!$key) return app('json')->fail('参数错误!'); $uid = $request->uid(); if ($this->services->be(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0])) return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]); list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, $shipping_type) = $request->postMore([ 'addressId', 'couponId', ['payType', 'yue'], ['useIntegral', 0], 'mark', ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['bargainId', ''], ['shipping_type', 1], ], true); $payType = strtolower($payType); $cartGroup = $this->services->getCacheOrderInfo($uid, $key); if (!$cartGroup) return app('json')->fail('订单已过期,请刷新当前页面!'); $priceGroup = $computedServices->setParamData([ 'combinationId' => $combinationId, 'pinkId' => $pinkId, 'seckill_id' => $seckill_id, 'bargainId' => $bargainId, ])->computedOrder($request->uid(), $request->user()->toArray(), $cartGroup, $addressId, $payType, !!$useIntegral, (int)$couponId, false, (int)$shipping_type); if ($priceGroup) return app('json')->status('NONE', 'ok', $priceGroup); else return app('json')->fail('计算失败'); } /** * 订单创建 * @param Request $request * @param StoreBargainServices $bargainServices * @param StorePinkServices $pinkServices * @param StoreOrderCreateServices $createServices * @param StoreSeckillServices $seckillServices * @param UserInvoiceServices $userInvoiceServices * @param StoreOrderInvoiceServices $storeOrderInvoiceServices * @param $key * @return mixed * @throws \Psr\SimpleCache\InvalidArgumentException * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function create(Request $request, StoreBargainServices $bargainServices, StorePinkServices $pinkServices, StoreOrderCreateServices $createServices, StoreSeckillServices $seckillServices, UserInvoiceServices $userInvoiceServices, StoreOrderInvoiceServices $storeOrderInvoiceServices, StoreCombinationServices $combinationServices, $key) { if (!$key) return app('json')->fail('参数错误!'); $uid = (int)$request->uid(); if ($checkOrder = $this->services->getOne(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0])) return app('json')->status('extend_order', '订单已创建,请点击查看完成支付', ['orderId' => $checkOrder['order_id'], 'key' => $key]); [$addressId, $couponId, $payType, $useIntegral, $mark, $paypwd,$combinationId, $pinkId, $seckill_id, $bargainId, $from, $shipping_type, $real_name, $phone, $storeId, $news, $invoice_id, $quitUrl, $advanceId, $virtual_type] = $request->postMore([ [['addressId', 'd'], 0], [['couponId', 'd'], 0], ['payType', ''], ['useIntegral', 0], ['mark', ''], ['paypwd', ''], [['combinationId', 'd'], 0], [['pinkId', 'd'], 0], [['seckill_id', 'd'], 0], [['bargainId', 'd'], ''], ['from', 'weixin'], [['shipping_type', 'd'], 1], ['real_name', ''], ['phone', ''], [['store_id', 'd'], 0], ['new', 0], [['invoice_id', 'd'], 0], ['quitUrl', ''], [['advanceId', 'd'], 0], ['virtual_type', 0] ], true); $payType = strtolower($payType); $cartGroup = $this->services->getCacheOrderInfo($uid, $key); if (!$cartGroup) { return app('json')->fail('订单已过期,请刷新当前页面!'); } //var_dump($paypwd); //下单前支付密码验证 if(!$paypwd){ return app('json')->fail('请填写支付密码'); }else{ $user = $request->user()->toArray(); if(md5((string)$paypwd) != $user['paypwd']){ return app('json')->fail('支付密码不正确'); } } //下单前砍价验证 if ($bargainId) { $bargainServices->checkBargainUser((int)$bargainId, $uid); } //下单前发票验证 if ($invoice_id) { $userInvoiceServices->checkInvoice((int)$invoice_id, $uid); } if ($pinkId) { $pinkId = (int)$pinkId; /** @var StorePinkServices $pinkServices */ $pinkServices = app()->make(StorePinkServices::class); if ($pinkServices->isPink($pinkId, $uid)) return app('json')->status('ORDER_EXIST', '订单生成失败,你已经在该团内不能再参加了', ['orderId' => $this->services->getStoreIdPink($pinkId, $uid)]); if ($this->services->getIsOrderPink($pinkId, $uid)) return app('json')->status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => $this->services->getStoreIdPink($pinkId, $uid)]); if (!CacheService::checkStock(md5($pinkId), 1, 3) || !CacheService::popStock(md5($pinkId), 1, 3)) { return app('json')->fail('该团人员已满'); } } if ($from != 'pc') { if (!$this->services->checkPaytype($payType)) { return app('json')->fail('暂不支持该支付方式,请刷新页面或者联系管理员'); } } else { $payType = 'pc'; } $isChannel = $this->getChennel[$from] ?? ($request->isApp() ? 0 : 1); if ($seckill_id || $combinationId || $bargainId || $advanceId) { $cartInfo = $cartGroup['cartInfo']; foreach ($cartInfo as $item) { $type = 0; if (!isset($item['product_attr_unique']) || !$item['product_attr_unique']) continue; if ($item['seckill_id']) { $type = 1; } elseif ($item['bargain_id']) { $type = 2; } elseif ($item['combination_id']) { $type = 3; } elseif ($item['advance_id']) { $type = 6; } if ($type && (!CacheService::checkStock($item['product_attr_unique'], (int)$item['cart_num'], $type) || !CacheService::popStock($item['product_attr_unique'], (int)$item['cart_num'], $type))) { return app('json')->fail('您购买的商品库存已不足' . $item['cart_num'] . $item['productInfo']['unit_name']); } } } $virtual_type = $cartGroup['cartInfo'][0]['productInfo']['virtual_type'] ?? 0; $order = $createServices->createOrder($uid, $key, $cartGroup, $request->user()->toArray(), $addressId, $payType, !!$useIntegral, $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, $isChannel, $shipping_type, $real_name, $phone, $storeId, !!$news, $advanceId, $virtual_type); if ($order === false) { if ($seckill_id || $combinationId || $advanceId || $bargainId) { foreach ($cartInfo as $item) { $value = $item['cart_info']; $type = 0; if (!isset($value['product_attr_unique']) || $value['product_attr_unique']) continue; if ($value['seckill_id']) { $type = 1; } elseif ($value['bargain_id']) { $type = 2; } elseif ($value['combination_id']) { $type = 3; } elseif ($value['advance_id']) { $type = 6; } if ($type) CacheService::setStock($value['product_attr_unique'], (int)$value['cart_num'], $type, false); } } return app('json')->fail('订单生成失败'); } $orderId = $order['order_id']; $orderInfo = $this->services->getOne(['order_id' => $orderId]); if (!$orderInfo || !isset($orderInfo['paid'])) { return app('json')->fail('支付订单不存在!'); } //创建开票数据 if ($invoice_id) { $storeOrderInvoiceServices->makeUp($uid, $orderId, (int)$invoice_id); } $orderInfo = $orderInfo->toArray(); $info = compact('orderId', 'key'); if ($orderId) { switch ($payType) { case PayServices::WEIXIN_PAY: if ($orderInfo['paid']) return app('json')->fail('支付已支付!'); //支付金额为0 if (bcsub((string)$orderInfo['pay_price'], '0', 2) <= 0) { //创建订单jspay支付 /** @var StoreOrderSuccessServices $success */ $success = app()->make(StoreOrderSuccessServices::class); $payPriceStatus = $success->zeroYuanPayment($orderInfo, $uid, PayServices::WEIXIN_PAY); if ($payPriceStatus)//0元支付成功 return app('json')->status('success', '微信支付成功', $info); else return app('json')->status('pay_error'); } else { /** @var OrderPayServices $payServices */ $payServices = app()->make(OrderPayServices::class); if (!$from && $request->isApp()) { $from = 'weixin'; } $info['jsConfig'] = $payServices->orderPay($orderInfo, $from); if ($from == 'weixinh5') { return app('json')->status('wechat_h5_pay', '订单创建成功', $info); } else { return app('json')->status('wechat_pay', '订单创建成功', $info); } } break; case PayServices::YUE_PAY: /** @var YuePayServices $yueServices */ $yueServices = app()->make(YuePayServices::class); $pay = $yueServices->yueOrderPay($orderInfo, $uid); if ($pay['status'] === true) return app('json')->status('success', '余额支付成功', $info); else { if (is_array($pay)) return app('json')->status($pay['status'], $pay['msg'], $info); else return app('json')->status('pay_error', $pay); } break; case PayServices::ALIAPY_PAY: if (!$quitUrl && ($request->isH5() || $request->isWechat())) { return app('json')->status('pay_error', '请传入支付宝支付回调URL', $info); } [$url, $param] = explode('?', $quitUrl); $quitUrl = $url . '?order_id=' . $orderInfo['order_id']; //支付金额为0 if (bcsub((string)$orderInfo['pay_price'], '0', 2) <= 0) { //创建订单jspay支付 /** @var StoreOrderSuccessServices $success */ $success = app()->make(StoreOrderSuccessServices::class); $payPriceStatus = $success->zeroYuanPayment($orderInfo, $uid, PayServices::ALIAPY_PAY); if ($payPriceStatus)//0元支付成功 return app('json')->status('success', '支付宝支付成功', $info); else return app('json')->status('pay_error'); } else { /** @var OrderPayServices $payServices */ $payServices = app()->make(OrderPayServices::class); $info['jsConfig'] = $payServices->alipayOrder($orderInfo, $quitUrl, $from == 'routine'); $payKey = md5($orderInfo['order_id']); CacheService::set($payKey, ['order_id' => $orderInfo['order_id'], 'other_pay_type' => false], 300); $info['pay_key'] = $payKey; return app('json')->status(PayServices::ALIAPY_PAY . '_pay', '订单创建成功', $info); } break; case PayServices::OFFLINE_PAY: case 'pc': return app('json')->status('success', '订单创建成功', $info); break; } } else return app('json')->fail('订单生成失败!'); } /** * 订单 再次下单 * @param Request $request * @return mixed */ public function again(Request $request, StoreCartServices $services) { list($uni) = $request->postMore([ ['uni', ''], ], true); if (!$uni) return app('json')->fail('参数错误!'); $order = $this->services->getUserOrderDetail($uni, (int)$request->uid()); if (!$order) return app('json')->fail('订单不存在!'); $order = $this->services->tidyOrder($order, true); $cateId = []; foreach ($order['cartInfo'] as $v) { if ($v['combination_id']) return app('json')->fail('拼团商品不能再来一单,请在拼团商品内自行下单!'); else if ($v['bargain_id']) return app('json')->fail('砍价商品不能再来一单,请在砍价商品内自行下单!'); else if ($v['seckill_id']) return app('json')->fail('秒杀商品不能再来一单,请在秒杀商品内自行下单!'); else if ($v['advance_id']) return app('json')->fail('预售商品不能再来一单,请在预售商品内自行下单!'); else $cateId[] = $services->setCart($request->uid(), (int)$v['product_id'], (int)$v['cart_num'], isset($v['productInfo']['attrInfo']['unique']) ? $v['productInfo']['attrInfo']['unique'] : '', '0', true); } if (!$cateId) return app('json')->fail('再来一单失败,请重新下单!'); return app('json')->successful('ok', ['cateId' => implode(',', $cateId)]); } /** * 订单支付 * @param Request $request * @return mixed */ public function pay(Request $request, StorePinkServices $services, OrderPayServices $payServices, YuePayServices $yuePayServices) { [$uni, $paytype, $from, $quitUrl] = $request->postMore([ ['uni', ''], ['paytype', 'weixin'], ['from', 'weixin'], ['quitUrl', ''] ], true); if (!$uni) return app('json')->fail('参数错误!'); $order = $this->services->getUserOrderDetail($uni, (int)$request->uid()); if (!$order) return app('json')->fail('订单不存在!'); if ($order['paid']) return app('json')->fail('该订单已支付!'); if ($order['pink_id'] && $services->isPinkStatus($order['pink_id'])) { return app('json')->fail('该订单已失效!'); } if (!Cache::get('pay_' . $order['order_id'])) { switch ($from) { case 'weixin': if (in_array($order->is_channel, [1, 2, 3])) {//0 $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id']; } break; case 'weixinh5': if (in_array($order->is_channel, [0, 1, 3])) { $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id']; } break; case 'routine': if (in_array($order->is_channel, [0, 2, 3])) { $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id']; } break; case 'pc': case 'aliapy': $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id']; break; } } $order['pay_type'] = $paytype; //重新支付选择支付方式 switch ($order['pay_type']) { case PayServices::WEIXIN_PAY: $jsConfig = $payServices->orderPay($order->toArray(), $from); if ($from == 'weixinh5') { return app('json')->status('wechat_h5_pay', ['jsConfig' => $jsConfig, 'order_id' => $order['order_id']]); } elseif ($from == 'weixin' || $from == 'routine') { return app('json')->status('wechat_pay', ['jsConfig' => $jsConfig, 'order_id' => $order['order_id']]); } elseif ($from == 'pc') { return app('json')->status('wechat_pc_pay', ['jsConfig' => $jsConfig, 'order_id' => $order['order_id']]); } break; case PayServices::ALIAPY_PAY: if (!$quitUrl && $from != 'routine') { return app('json')->fail('请传入支付宝支付回调URL'); } $isCode = $from == 'routine' || $from == 'pc'; $jsConfig = $payServices->alipayOrder($order->toArray(), $quitUrl, $isCode); if ($isCode && !($jsConfig->invalid ?? false)) $jsConfig->invalid = time() + 60; $payKey = md5($order['order_id']); CacheService::set($payKey, ['order_id' => $order['order_id'], 'other_pay_type' => false], 300); return app('json')->status(PayServices::ALIAPY_PAY . '_pay', '订单创建成功', ['jsConfig' => $jsConfig, 'order_id' => $order['order_id'], 'pay_key' => $payKey]); break; case PayServices::YUE_PAY: $pay = $yuePayServices->yueOrderPay($order->toArray(), $request->uid()); if ($pay['status'] === true) return app('json')->status('success', '余额支付成功'); else { if (is_array($pay)) return app('json')->status($pay['status'], $pay['msg']); else return app('json')->status('pay_error', $pay); } break; case PayServices::OFFLINE_PAY: if ($this->services->setOrderTypePayOffline($order['order_id'])) return app('json')->status('success', '订单创建成功'); else return app('json')->status('success', '支付失败'); break; } return app('json')->fail('支付方式错误'); } /** * 支付宝单独支付 * @param OrderPayServices $payServices * @param string $key * @param string $quitUrl * @return mixed */ public function aliPay(OrderPayServices $payServices, OtherOrderServices $services, string $key, string $quitUrl) { if (!$key || !($orderCache = CacheService::get($key))) { return app('json')->fail('该订单无法支付'); } if (!isset($orderCache['order_id'])) { return app('json')->fail('该订单无法支付'); } $payType = isset($orderCache['other_pay_type']) && $orderCache['other_pay_type'] == true; if ($payType) { $orderInfo = $services->getOne(['order_id' => $orderCache['order_id'], 'is_del' => 0, 'paid' => 0]); } else { $orderInfo = $this->services->get(['order_id' => $orderCache['order_id'], 'paid' => 0, 'is_del' => 0]); } if (!$orderInfo) { return app('json')->fail('订单支付状态有误,无法进行支付'); } if (!$quitUrl) { return app('json')->fail('请传入支付宝支付回调URL'); } $payInfo = $payServices->alipayOrder($orderInfo->toArray(), $quitUrl); return app('json')->success(['pay_content' => $payInfo]); } /** * 订单列表 * @param Request $request * @return mixed */ public function lst(Request $request) { $where = $request->getMore([ ['type', '', '', 'status'], ['search', '', '', 'real_name'], ['refund_type', '', '', 'refundTypes'] ]); $where['uid'] = $request->uid(); $where['is_del'] = 0; $where['is_system_del'] = 0; if (in_array($where['status'], [-1, -2, -3])) { $where['not_pid'] = 1; } elseif (in_array($where['status'], [0, 1, 2, 3, 4])) { $where['pid'] = 0; } $list = $this->services->getOrderApiList($where); return app('json')->successful($list); } /** * 订单详情 * @param Request $request * @param $uni * @return mixed */ public function detail(Request $request, StoreOrderEconomizeServices $services, $uni) { /** @var StoreOrderCartInfoServices $storeOrderCartInfoServices */ $storeOrderCartInfoServices = app()->make(StoreOrderCartInfoServices::class); if (!strlen(trim($uni))) return app('json')->fail('参数错误'); $order = $this->services->getUserOrderDetail($uni, (int)$request->uid(), ['split', 'invoice']); if (!$order) return app('json')->fail('订单不存在'); $order = $order->toArray(); $splitNum = []; if (isset($order['split']) && $order['split']) { foreach ($order['split'] as &$item) { $item = $this->services->tidyOrder($item, true); if ($item['_status']['_type'] == 3) { foreach ($item['cartInfo'] ?: [] as $key => $product) { $item['cartInfo'][$key]['add_time'] = isset($product['add_time']) ? date('Y-m-d H:i', (int)$product['add_time']) : '时间错误'; } } } $splitNum = $storeOrderCartInfoServices->getSplitCartNum($order['cart_id']); } //是否开启门店自提 $store_self_mention = sys_config('store_self_mention'); //关闭门店自提后 订单隐藏门店信息 if ($store_self_mention == 0) $order['shipping_type'] = 1; if ($order['verify_code']) { $verify_code = $order['verify_code']; $verify[] = substr($verify_code, 0, 4); $verify[] = substr($verify_code, 4, 4); $verify[] = substr($verify_code, 8); $order['_verify_code'] = implode(' ', $verify); } $order['add_time_y'] = date('Y-m-d', $order['add_time']); $order['add_time_h'] = date('H:i:s', $order['add_time']); $order['system_store'] = false; if ($order['store_id']) { /** @var SystemStoreServices $storeServices */ $storeServices = app()->make(SystemStoreServices::class); $order['system_store'] = $storeServices->getStoreDispose($order['store_id']); } if (($order['shipping_type'] === 2 || $order['delivery_uid'] != 0) && $order['verify_code']) { $name = $order['verify_code'] . '.jpg'; /** @var SystemAttachmentServices $attachmentServices */ $attachmentServices = app()->make(SystemAttachmentServices::class); $imageInfo = $attachmentServices->getInfo(['name' => $name]); $siteUrl = sys_config('site_url'); if (!$imageInfo) { $imageInfo = UtilService::getQRCodePath($order['verify_code'], $name); if (is_array($imageInfo)) { $attachmentServices->attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time'], 2); $url = $imageInfo['dir']; } else $url = ''; } else $url = $imageInfo['att_dir']; if (isset($imageInfo['image_type']) && $imageInfo['image_type'] == 1) $url = $siteUrl . $url; $order['code'] = $url; } $order['mapKey'] = sys_config('tengxun_map_key'); $order['yue_pay_status'] = (int)sys_config('balance_func_status') && (int)sys_config('yue_pay_status') == 1 ? (int)1 : (int)2;//余额支付 1 开启 2 关闭 $order['pay_weixin_open'] = (int)sys_config('pay_weixin_open') ?? 0;//微信支付 1 开启 0 关闭 $order['ali_pay_status'] = sys_config('ali_pay_status') ? true : false;//支付包支付 1 开启 0 关闭 $orderData = $this->services->tidyOrder($order, true, true); $vipTruePrice = 0; foreach ($orderData['cartInfo'] ?? [] as $key => $cart) { $vipTruePrice = bcadd((string)$vipTruePrice, (string)$cart['vip_sum_truePrice'], 2); if (isset($splitNum[$cart['id']])) { $orderData['cartInfo'][$key]['cart_num'] = $cart['cart_num'] - $splitNum[$cart['id']]; if ($orderData['cartInfo'][$key]['cart_num'] == 0) unset($orderData['cartInfo'][$key]); } } $orderData['cartInfo'] = array_merge($orderData['cartInfo']); $orderData['vip_true_price'] = $vipTruePrice; $economize = $services->get(['order_id' => $order['order_id']], ['postage_price', 'member_price']); if ($economize) { $orderData['postage_price'] = $economize['postage_price']; $orderData['member_price'] = $economize['member_price']; } else { $orderData['postage_price'] = 0; $orderData['member_price'] = 0; } $orderData['routine_contact_type'] = sys_config('routine_contact_type', 0); /** @var UserInvoiceServices $userInvoice */ $userInvoice = app()->make(UserInvoiceServices::class); $invoice_func = $userInvoice->invoiceFuncStatus(); $orderData['invoice_func'] = $invoice_func['invoice_func']; $orderData['special_invoice'] = $invoice_func['special_invoice']; $orderData['refund_cartInfo'] = $orderData['cartInfo']; $orderData['refund_total_num'] = $orderData['total_num']; $orderData['refund_pay_price'] = $orderData['pay_price']; $is_apply_refund = true; if (in_array($order['pid'], [0, -1])) { $cart_infos = $storeOrderCartInfoServices->getSplitCartList((int)$order['id'], 'surplus_num,cart_info'); $orderData['refund_cartInfo'] = []; $orderData['refund_total_num'] = $orderData['refund_pay_price'] = 0; if ($cart_infos) { $cart_info = []; foreach ($cart_infos as $cart) { $info = $cart['cart_info']; $info['cart_num'] = $cart['surplus_num']; $cart_info[] = $info; } $orderData['refund_cartInfo'] = $cart_info; /** @var StoreOrderComputedServices $orderComputeServices */ $orderComputeServices = app()->make(StoreOrderComputedServices::class); $orderData['refund_total_num'] = $orderComputeServices->getOrderSumPrice($cart_info, 'cart_num', false); $orderData['refund_pay_price'] = $orderComputeServices->getOrderSumPrice($cart_info, 'truePrice'); } else {//主订单已全部发货 不可申请退款 $is_apply_refund = false; } } $orderData['is_apply_refund'] = $is_apply_refund; return app('json')->successful('ok', $orderData); } /** * 退款订单详情 * @param Request $request * @param $uni * @param string $cartId * @return mixed */ public function refund_detail(Request $request, $uni, $cartId = '') { if (!strlen(trim($uni))) return app('json')->fail('参数错误'); /** @var StoreOrderCartInfoServices $storeOrderCartInfoServices */ $storeOrderCartInfoServices = app()->make(StoreOrderCartInfoServices::class); $order = $this->services->getUserOrderDetail($uni, (int)$request->uid(), ['split', 'invoice']); if (!$order) return app('json')->fail('订单不存在'); $order = $order->toArray(); $orderData = $this->services->tidyOrder($order, true, true); $splitNum = $storeOrderCartInfoServices->getSplitCartNum($order['cart_id']); foreach ($orderData['cartInfo'] ?? [] as $key => $cart) { $orderData['cartInfo'][$key]['one_postage_price'] = bcdiv($cart['postage_price'], $cart['cart_num'], 2); if ($cartId != '') { if ($cart['id'] != $cartId) { unset($orderData['cartInfo'][$key]); } else { if (isset($splitNum[$cart['id']])) { $orderData['total_num'] = $orderData['cartInfo'][$key]['cart_num'] = $cart['cart_num'] - $splitNum[$cart['id']]; $orderData['pay_price'] = bcadd(bcmul($cart['truePrice'], $orderData['total_num'], 4), bcmul($orderData['total_num'], $orderData['cartInfo'][$key]['one_postage_price'], 4), 2); } else { $orderData['total_num'] = $orderData['cartInfo'][$key]['cart_num']; $orderData['pay_price'] = bcadd(bcmul($cart['truePrice'], $cart['cart_num'], 4), $cart['postage_price'], 2); } } } else { if (isset($splitNum[$cart['id']])) { $orderData['cartInfo'][$key]['cart_num'] = $cart['cart_num'] - $splitNum[$cart['id']]; $orderData['total_num'] = $orderData['total_num'] - $splitNum[$cart['id']]; if ($orderData['cartInfo'][$key]['cart_num'] == 0) unset($orderData['cartInfo'][$key]); } } } if ($cartId == '') { $orderData['pay_price'] = bcsub($orderData['pay_price'], $this->services->sum(['pid' => $orderData['id']], 'pay_price'), 2); } $orderData['cartInfo'] = array_merge($orderData['cartInfo']); return app('json')->successful('ok', $orderData); } /** * 订单删除 * @param Request $request * @return mixed */ public function del(Request $request) { [$uni] = $request->postMore([ ['uni', ''], ], true); if (!$uni) return app('json')->fail('参数错误!'); $res = $this->services->removeOrder($uni, (int)$request->uid()); if ($res) { return app('json')->successful(); } else { return app('json')->fail('删除失败'); } } /** * 订单收货 * @param Request $request * @return mixed */ public function take(Request $request, StoreOrderTakeServices $services, StoreCouponIssueServices $issueServices) { list($uni) = $request->postMore([ ['uni', ''], ], true); if (!$uni) return app('json')->fail('参数错误!'); $order = $services->takeOrder($uni, (int)$request->uid()); if ($order) { return app('json')->successful('收货成功'); } else return app('json')->fail('收货失败'); } /** * 订单 查看物流 * @param Request $request * @param $uni * @return mixed */ public function express(Request $request, StoreOrderCartInfoServices $services, ExpressServices $expressServices, $uni, $type = '') { if (!$uni || !($order = $this->services->getUserOrderDetail($uni, $request->uid()))) return app('json')->fail('查询订单不存在!'); if ($type != 'refund' && ($order['delivery_type'] != 'express' || !$order['delivery_id'])) return app('json')->fail('该订单不存在快递单号!'); $express = $type == 'refund' ? $order['refund_express'] : $order['delivery_id']; $cacheName = $uni . $express; $orderInfo = []; $cartInfo = $services->getCartColunm(['oid' => $order['id']], 'cart_info', 'unique'); $info = []; $cartNew = []; foreach ($cartInfo as $k => $cart) { $cart = json_decode($cart, true); $cartNew['cart_num'] = $cart['cart_num']; $cartNew['truePrice'] = $cart['truePrice']; $cartNew['productInfo']['image'] = $cart['productInfo']['image']; $cartNew['productInfo']['store_name'] = $cart['productInfo']['store_name']; $cartNew['productInfo']['unit_name'] = $cart['productInfo']['unit_name'] ?? ''; array_push($info, $cartNew); unset($cart); } $orderInfo['delivery_id'] = $express; $orderInfo['delivery_name'] = $type == 'refund' ? '用户退回' : $order['delivery_name'];; $orderInfo['delivery_code'] = $type == 'refund' ? '' : $order['delivery_code']; $orderInfo['delivery_type'] = $order['delivery_type']; $orderInfo['user_address'] = $order['user_address']; $orderInfo['user_mark'] = $order['mark']; $orderInfo['cartInfo'] = $info; return app('json')->successful([ 'order' => $orderInfo, 'express' => [ 'result' => ['list' => $expressServices->query($cacheName, $express, $orderInfo['delivery_code']) ] ] ]); } /** * 订单评价 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function comment(Request $request, StoreOrderCartInfoServices $cartInfoServices, StoreProductReplyServices $replyServices) { $group = $request->postMore([ ['unique', ''], ['comment', ''], ['pics', ''], ['product_score', 5], ['service_score', 5] ]); $unique = $group['unique']; unset($group['unique']); if (!$unique) return app('json')->fail('参数错误!'); $cartInfo = $cartInfoServices->getOne(['unique' => $unique]); $uid = $request->uid(); $user_info = $request->user(); $group['nickname'] = $user_info['nickname']; $group['avatar'] = $user_info['avatar']; if (!$cartInfo) return app('json')->fail('评价商品不存在!'); $orderUid = $this->services->value(['id' => $cartInfo['oid']], 'uid'); if ($uid != $orderUid) return app('json')->fail('评价商品不存在!'); if ($replyServices->be(['oid' => $cartInfo['oid'], 'unique' => $unique])) return app('json')->fail('该商品已评价!'); $group['comment'] = htmlspecialchars(trim($group['comment'])); if ($group['product_score'] < 1) return app('json')->fail('请为商品评分'); else if ($group['service_score'] < 1) return app('json')->fail('请为商家服务评分'); if ($cartInfo['cart_info']['combination_id']) $productId = $cartInfo['cart_info']['product_id']; else if ($cartInfo['cart_info']['seckill_id']) $productId = $cartInfo['cart_info']['product_id']; else if ($cartInfo['cart_info']['bargain_id']) $productId = $cartInfo['cart_info']['product_id']; else $productId = $cartInfo['product_id']; if ($group['pics']) $group['pics'] = json_encode(is_array($group['pics']) ? $group['pics'] : explode(',', $group['pics'])); $group = array_merge($group, [ 'uid' => $uid, 'oid' => $cartInfo['oid'], 'unique' => $unique, 'product_id' => $productId, 'add_time' => time(), 'reply_type' => 'product' ]); $res = $replyServices->save($group); if (!$res) { return app('json')->fail('评价失败!'); } try { $this->services->checkOrderOver($replyServices, $cartInfoServices->getCartColunm(['oid' => $cartInfo['oid']], 'unique', ''), $cartInfo['oid']); } catch (\Exception $e) { return app('json')->fail($e->getMessage()); } //缓存抽奖次数 /** @var LuckLotteryServices $luckLotteryServices */ $luckLotteryServices = app()->make(LuckLotteryServices::class); $luckLotteryServices->setCacheLotteryNum((int)$orderUid, 'comment'); /** @var SystemAdminServices $systemAdmin */ $systemAdmin = app()->make(SystemAdminServices::class); $systemAdmin->adminNewPush(); $lottery = $luckLotteryServices->getFactorLottery(4); if (!$lottery) { return app('json')->successful(['to_lottery' => false]); } $lottery = $lottery->toArray(); try { $luckLotteryServices->checkoutUserAuth($uid, (int)$lottery['id'], [], $lottery); $lottery_num = $luckLotteryServices->getLotteryNum($uid, (int)$lottery['id'], [], $lottery); if ($lottery_num > 0) return app('json')->successful(['to_lottery' => true]); } catch (\Exception $e) { return app('json')->successful(['to_lottery' => false]); } } /** * 订单统计数据 * @param Request $request * @return mixed */ public function data(Request $request) { return app('json')->successful($this->services->getOrderData((int)$request->uid(), true)); } /** * 订单退款理由 * @return mixed */ public function refund_reason() { $reason = sys_config('stor_reason') ?: [];//退款理由 $reason = str_replace("\r\n", "\n", $reason);//防止不兼容 $reason = explode("\n", $reason); return app('json')->successful($reason); } /** * 订单退款审核 * @param Request $request * @return mixed */ public function refund_verify(Request $request, StoreOrderRefundServices $services) { $data = $request->postMore([ ['text', ''], ['refund_reason_wap_img', ''], ['refund_reason_wap_explain', ''], ['uni', ''], ['refund_type', 1], ['cart_id', 0], ['refund_num', 0] ]); $uni = $data['uni']; unset($data['uni']); if ($data['refund_reason_wap_img'] != '') { $data['refund_reason_wap_img'] = explode(',', $data['refund_reason_wap_img']); } else { $data['refund_reason_wap_img'] = []; } if (!$uni || $data['text'] == '' || $data['refund_num'] <= 0) return app('json')->fail('参数错误!'); $res = $services->orderApplyRefund($this->services->getUserOrderDetail($uni, (int)$request->uid()), $data['text'], $data['refund_reason_wap_explain'], $data['refund_reason_wap_img'], $data['refund_type'], $data['cart_id'], $data['refund_num']); if ($res) return app('json')->successful('提交申请成功'); else return app('json')->fail('提交失败'); } /** * 用户退货提交快递单号 * @param Request $request * @param StoreOrderRefundServices $services * @return mixed */ public function refund_express(Request $request, StoreOrderRefundServices $services) { [$id, $express_id] = $request->postMore([ ['id', ''], ['express_id', ''] ], true); if ($id == '' || $express_id == '') return app('json')->fail('参数错误!'); $res = $services->editRefundExpress($id, $express_id); if ($res) return app('json')->successful('提交快递单号成功'); else return app('json')->fail('提交失败'); } /** * 订单取消 未支付的订单回退积分,回退优惠券,回退库存 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function cancel(Request $request) { list($id) = $request->postMore([['id', 0]], true); if (!$id) return app('json')->fail('参数错误'); if ($this->services->cancelOrder($id, (int)$request->uid())) return app('json')->successful('取消订单成功'); return app('json')->fail('取消订单失败'); } /** * 订单商品信息 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function product(Request $request, StoreOrderCartInfoServices $services) { list($unique) = $request->postMore([['unique', '']], true); if (!$unique || !($cartInfo = $services->getOne(['unique' => $unique]))) return app('json')->fail('评价商品不存在!'); $cartInfo = $cartInfo->toArray(); $cartProduct = []; $cartProduct['cart_num'] = $cartInfo['cart_info']['cart_num']; $cartProduct['productInfo']['image'] = get_thumb_water($cartInfo['cart_info']['productInfo']['image'] ?? ''); $cartProduct['productInfo']['price'] = $cartInfo['cart_info']['productInfo']['price'] ?? 0; $cartProduct['productInfo']['store_name'] = $cartInfo['cart_info']['productInfo']['store_name'] ?? ''; if (isset($cartInfo['cart_info']['productInfo']['attrInfo'])) { $cartProduct['productInfo']['attrInfo']['product_id'] = $cartInfo['cart_info']['productInfo']['attrInfo']['product_id'] ?? ''; $cartProduct['productInfo']['attrInfo']['suk'] = $cartInfo['cart_info']['productInfo']['attrInfo']['suk'] ?? ''; $cartProduct['productInfo']['attrInfo']['price'] = $cartInfo['cart_info']['productInfo']['attrInfo']['price'] ?? ''; $cartProduct['productInfo']['attrInfo']['image'] = get_thumb_water($cartInfo['cart_info']['productInfo']['attrInfo']['image'] ?? ''); } $cartProduct['product_id'] = $cartInfo['cart_info']['product_id'] ?? 0; $cartProduct['combination_id'] = $cartInfo['cart_info']['combination_id'] ?? 0; $cartProduct['seckill_id'] = $cartInfo['cart_info']['seckill_id'] ?? 0; $cartProduct['bargain_id'] = $cartInfo['cart_info']['bargain_id'] ?? 0; $cartProduct['order_id'] = $this->services->value(['id' => $cartInfo['oid']], 'order_id'); return app('json')->successful($cartProduct); } }
\app\api\controller\v1\user\UserBankController.php
<?php namespace app\api\controller\v1\user; use app\Request; use app\services\user\UserBankServices; /** * 用户地址类 * Class UserController * @package app\api\controller\store */ class UserBankController { protected $services = NUll; /** * UserController constructor. * @param UserBankServices $services */ public function __construct(UserBankServices $services) { $this->services = $services; } /** * 地址 获取单个 * @param Request $request * @param $id * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function bank(Request $request, $id) { if (!$id) { app('json')->fail('缺少参数'); } return app('json')->successful($this->services->bank((int)$id)); } /** * 地址列表 * @param Request $request * @param $page * @param $limit * @return mixed */ public function bank_list(Request $request) { $uid = (int)$request->uid(); return app('json')->successful($this->services->getUserBankList($uid, 'id,is_default,bankname,cardno')); } /** * 设置默认地址 * * @param Request $request * @return mixed */ public function bank_default_set(Request $request) { list($id) = $request->getMore([['id', 0]], true); if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!'); $uid = (int)$request->uid(); $res = $this->services->setDefault($uid, (int)$id); if (!$res) return app('json')->fail('银行卡不存在!'); else return app('json')->successful(); } /** * 获取默认银行卡 * @param Request $request * @return mixed */ public function bank_default(Request $request) { $uid = (int)$request->uid(); $defaultBank = $this->services->getUserDefaultBank($uid, 'id,bankname,cardno,is_default'); if ($defaultBank) { $defaultBank = $defaultBank->toArray(); return app('json')->successful('ok', $defaultBank); } return app('json')->successful('empty', []); } /** * 修改 添加银行卡 * @param Request $request * @return mixed */ public function bank_edit(Request $request) { $bankInfo = $request->postMore([ ['bankname', ''], ['is_default', false], ['cardno', ''], [['id', 'd'], 0], ]); if (!$bankInfo['bankname']) return app('json')->fail('请填写银行名称!'); if (!$bankInfo['cardno']) return app('json')->fail('请填写银行卡卡号!'); $uid = (int)$request->uid(); $res = $this->services->editBank($uid, $bankInfo); if ($res) { return app('json')->success($res['type'] == 'edit' ? $res['msg'] : $res['data']); } else { return app('json')->fail('处理失败'); } } /** * 删除银行卡 * * @param Request $request * @return mixed */ public function bank_del(Request $request) { list($id) = $request->postMore([['id', 0]], true); if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!'); $uid = (int)$request->uid(); $re = $this->services->delBank($uid, (int)$id); if ($re) return app('json')->successful(); else return app('json')->fail('删除银行卡失败!'); } }
\app\api\controller\v1\user\UserExtractController.php
<?php namespace app\api\controller\v1\user; use app\Request; use app\services\user\UserExtractServices; use think\facade\Config; /** * 提现类 * Class UserExtractController * @package app\api\controller\user */ class UserExtractController { protected $services = NUll; /** * UserExtractController constructor. * @param UserExtractServices $services */ public function __construct(UserExtractServices $services) { $this->services = $services; } /** * 提现银行 * @param Request $request * @return mixed */ public function bank(Request $request) { $uid = (int)$request->uid(); return app('json')->successful($this->services->bank($uid)); } /** * 提现申请 * @param Request $request * @return mixed */ public function cash(Request $request) { $extractInfo = $request->postMore([ ['alipay_code', ''], ['extract_type', ''], ['money', 0], ['name', ''], ['bankname', ''], ['cardnum', ''], ['weixin', ''], ['qrcode_url', ''], ['paypwd', ''], ]); $extractType = Config::get('pay.extractType', []); if (!in_array($extractInfo['extract_type'], $extractType)) return app('json')->fail('提现方式不存在'); if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', (float)$extractInfo['money'])) return app('json')->fail('提现金额输入有误'); if (!$extractInfo['cardnum'] == '') if (!preg_match('/^([1-9]{1})(\d{15}|\d{16}|\d{18})$/', $extractInfo['cardnum'])) return app('json')->fail('银行卡号输入有误'); if ($extractInfo['extract_type'] == 'alipay') { if (trim($extractInfo['name']) == '') return app('json')->fail('请输入支付宝账号'); } else if ($extractInfo['extract_type'] == 'bank') { if (!$extractInfo['cardnum']) return app('json')->fail('请输入银行卡账号'); if (!$extractInfo['bankname']) return app('json')->fail('请输入开户行信息'); if (!$extractInfo['paypwd']) return app('json')->fail('请输入支付密码'); if ($extractInfo['paypwd']){ $paypwd=$extractInfo['paypwd']; $user = $request->user()->toArray(); if(md5((string)$paypwd) != $user['paypwd']){ return app('json')->fail('支付密码不正确'); } } } else if ($extractInfo['extract_type'] == 'weixin') { if (!$extractInfo['weixin']) return app('json')->fail('请输入微信账号'); } $uid = (int)$request->uid(); if ($this->services->cash($uid, $extractInfo)) return app('json')->successful('申请提现成功!'); else return app('json')->fail('提现失败'); } }
\app\api\controller\v1\user\UserInviteController.php
<?php namespace app\api\controller\v1\user; use app\Request; use app\services\user\InviteServices; /** * 用户地址类 * Class UserController * @package app\api\controller\store */ class UserInviteController { protected $services = NUll; /** * UserController constructor. * @param InviteServices $services */ public function __construct(InviteServices $services) { $this->services = $services; } /** * 地址 获取单个 * @param Request $request * @param $id * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function invite(Request $request, $id) { if (!$id) { app('json')->fail('缺少参数'); } return app('json')->successful($this->services->invite((int)$id)); } /** * 地址列表 * @param Request $request * @param $page * @param $limit * @return mixed */ public function invite_list(Request $request) { $uid = (int)$request->uid(); return app('json')->successful($this->services->getInviteList($uid, 'id,is_default,invitename,cardno')); } /** * 修改 添加银行卡 * @param Request $request * @return mixed */ public function invite_edit(Request $request) { $inviteInfo = $request->postMore([ ['phone', ''], ['nickname', ''], ['real_name', ''], [['id', 'd'], 0], ]); $uid = (int)$request->uid(); $res = $this->services->editInvite($uid, $inviteInfo); if ($res) { return app('json')->success($res['type'] == 'edit' ? $res['msg'] : $res['data']); } else { return app('json')->fail('处理失败'); } } /** * 删除银行卡 * * @param Request $request * @return mixed */ public function invite_del(Request $request) { list($id) = $request->postMore([['id', 0]], true); if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!'); $uid = (int)$request->uid(); $re = $this->services->delInvite($uid, (int)$id); if ($re) return app('json')->successful(); else return app('json')->fail('删除失败!'); } }
\app\api\controller\v1\InviteController.php
<?php namespace app\api\controller\v1; use app\Request; use app\services\user\InviteServices; use think\facade\Config; use think\exception\ValidateException; use app\api\validate\user\InviteValidates; /** * 用户地址类 * Class UserController * @package app\api\controller\store */ class InviteController { protected $services = NUll; /** * UserController constructor. * @param InviteServices $services */ public function __construct(InviteServices $services) { $this->services = $services; } /** * 地址 获取单个 * @param Request $request * @param $id * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function invite(Request $request, $id) { if (!$id) { app('json')->fail('缺少参数'); } return app('json')->successful($this->services->invite((int)$id)); } /** * 地址列表 * @param Request $request * @param $page * @param $limit * @return mixed */ public function invite_list(Request $request) { $uid = (int)$request->uid(); return app('json')->successful($this->services->getInviteList($uid, 'id,is_default,invitename,cardno')); } /** * 修改 添加银行卡 * @param Request $request * @return mixed */ public function invite_edit(Request $request) { $inviteInfo = $request->postMore([ ['phone', ''], ['nickname', ''], ['real_name', ''], [['id', 'd'], 0], ]); $uid = (int)$request->uid(); $res = $this->services->editInvite($uid, $inviteInfo); if ($res) { return app('json')->success($res['type'] == 'edit' ? $res['msg'] : $res['data']); } else { return app('json')->fail('处理失败'); } } /** * 删除银行卡 * * @param Request $request * @return mixed */ public function invite_del(Request $request) { list($id) = $request->postMore([['id', 0]], true); if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!'); $uid = (int)$request->uid(); $re = $this->services->delInvite($uid, (int)$id); if ($re) return app('json')->successful(); else return app('json')->fail('删除失败!'); } }
\app\api\controller\v1\LoginController.php
<?php namespace app\api\controller\v1; use app\Request; use app\services\wechat\WechatServices; use think\facade\Cache; use app\jobs\TaskJob; use think\facade\Config; use crmeb\services\CacheService; use app\services\user\LoginServices; use think\exception\ValidateException; use app\api\validate\user\RegisterValidates; use app\services\message\sms\SmsSendServices; /**微信小程序授权类 * Class AuthController * @package app\api\controller */ class LoginController { protected $services = NUll; /** * LoginController constructor. * @param LoginServices $services */ public function __construct(LoginServices $services) { $this->services = $services; } /** * H5账号登陆 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function login(Request $request) { [$account, $password, $spread] = $request->postMore([ 'account', 'password', 'spread' ], true); TaskJob::dispatchDo('emptyYesterdayAttachment'); if (!$account || !$password) { return app('json')->fail('请输入账号和密码'); } return app('json')->success('登录成功', $this->services->login($account, $password, $spread)); } /** * 退出登录 * @param Request $request */ public function logout(Request $request) { $key = trim(ltrim($request->header(Config::get('cookie.token_name')), 'Bearer')); CacheService::redisHandler()->delete($key); return app('json')->success('成功'); } public function verifyCode() { $unique = password_hash(uniqid(true), PASSWORD_BCRYPT); Cache::set('sms.key.' . $unique, 0, 300); $time = sys_config('verify_expire_time', 1); return app('json')->success(['key' => $unique, 'expire_time' => $time]); } public function captcha(Request $request) { ob_clean(); $rep = captcha(); $key = app('session')->get('captcha.key'); $uni = $request->get('key'); if ($uni) Cache::set('sms.key.cap.' . $uni, $key, 300); return $rep; } /** * 验证验证码是否正确 * * @param $uni * @param string $code * @return bool * @throws \Psr\SimpleCache\InvalidArgumentException */ protected function checkCaptcha($uni, string $code): bool { $cacheName = 'sms.key.cap.' . $uni; if (!Cache::has($cacheName)) { return false; } $key = Cache::get($cacheName); $code = mb_strtolower($code, 'UTF-8'); $res = password_verify($code, $key); if ($res) { Cache::delete($cacheName); } return $res; } /** * 验证码发送 * @param Request $request * @return mixed */ public function verify(Request $request, SmsSendServices $services) { [$phone, $type, $key, $code] = $request->postMore([['phone', 0], ['type', ''], ['key', ''], ['code', '']], true); $keyName = 'sms.key.' . $key; $nowKey = 'sms.' . date('YmdHi'); if (!Cache::has($keyName)) return app('json')->make(401, '发送验证码失败,请刷新页面重新获取'); if (($num = Cache::get($keyName)) > 2) { if (!$code) return app('json')->make(402, '请输入验证码'); if (!$this->checkCaptcha($key, $code)) return app('json')->fail('验证码输入有误'); } $total = 1; if ($has = Cache::has($nowKey)) { $total = Cache::get($nowKey); if ($total > Config::get('sms.maxMinuteCount', 20)) return app('json')->success('已发送'); } try { validate(RegisterValidates::class)->scene('code')->check(['phone' => $phone]); } catch (ValidateException $e) { return app('json')->fail($e->getError()); } $time = sys_config('verify_expire_time', 1); $smsCode = $this->services->verify($services, $phone, $type, $time, app()->request->ip()); if ($smsCode) { CacheService::set('code_' . $phone, $smsCode, $time * 60); Cache::set($keyName, $num + 1, 300); Cache::set($nowKey, $total, 61); return app('json')->success('发送成功'); } else { return app('json')->fail('发送失败'); } } /** * H5注册新用户 * @param Request $request * @return mixed */ public function register(Request $request) { [$account, $captcha, $password, $spread] = $request->postMore([['account', ''], ['captcha', ''], ['password', ''], ['spread', 0]], true); try { validate(RegisterValidates::class)->scene('register')->check(['account' => $account, 'captcha' => $captcha, 'password' => $password]); } catch (ValidateException $e) { return app('json')->fail($e->getError()); } $verifyCode = CacheService::get('code_' . $account); if (!$verifyCode) return app('json')->fail('请先获取验证码'); $verifyCode = substr($verifyCode, 0, 6); if ($verifyCode != $captcha) return app('json')->fail('验证码错误'); if (strlen(trim($password)) < 6 || strlen(trim($password)) > 16) return app('json')->fail('密码必须是在6到16位之间'); if (md5($password) == md5('123456')) return app('json')->fail('密码太过简单,请输入较为复杂的密码'); $registerStatus = $this->services->register($account, $password, $spread, 'h5'); if ($registerStatus) { return app('json')->success('注册成功'); } return app('json')->fail('注册失败'); } /** * 密码修改 * @param Request $request * @return mixed */ public function reset(Request $request) { [$account, $captcha, $password] = $request->postMore([['account', ''], ['captcha', ''], ['password', '']], true); try { validate(RegisterValidates::class)->scene('register')->check(['account' => $account, 'captcha' => $captcha, 'password' => $password]); } catch (ValidateException $e) { return app('json')->fail($e->getError()); } $verifyCode = CacheService::get('code_' . $account); if (!$verifyCode) return app('json')->fail('请先获取验证码'); $verifyCode = substr($verifyCode, 0, 6); if ($verifyCode != $captcha) { return app('json')->fail('验证码错误'); } if (strlen(trim($password)) < 6 || strlen(trim($password)) > 16) return app('json')->fail('密码必须是在6到16位之间'); if ($password == '123456') return app('json')->fail('密码太过简单,请输入较为复杂的密码'); $resetStatus = $this->services->reset($account, $password); if ($resetStatus) return app('json')->success('修改成功'); return app('json')->fail('修改失败'); } /** * 支付密码修改 * @param Request $request * @return mixed */ public function payreset(Request $request) { [$account, $captcha, $password] = $request->postMore([['account', ''], ['captcha', ''], ['password', '']], true); try { //validate(RegisterValidates::class)->scene('registerpay')->check(['account' => $account, 'captcha' => $captcha, 'paypassword' => $password]); } catch (ValidateException $e) { // return app('json')->fail($e->getError()); } $verifyCode = CacheService::get('code_' . $account); if (!$verifyCode) return app('json')->fail('请先获取验证码'); $verifyCode = substr($verifyCode, 0, 6); if ($verifyCode != $captcha) { return app('json')->fail('验证码错误'); } if (strlen(trim($password)) < 6 || strlen(trim($password)) > 16) return app('json')->fail('密码必须是在6到16位之间'); if ($password == '123456') return app('json')->fail('密码太过简单,请输入较为复杂的密码'); $resetStatus = $this->services->payreset($account, $password); if ($resetStatus) return app('json')->success('修改成功'); return app('json')->fail('修改失败'); } /** * 手机号登录 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function mobile(Request $request) { [$phone, $captcha, $spread] = $request->postMore([['phone', ''], ['captcha', ''], ['spread', 0]], true); //验证手机号 try { validate(RegisterValidates::class)->scene('code')->check(['phone' => $phone]); } catch (ValidateException $e) { return app('json')->fail($e->getError()); } //验证验证码 $verifyCode = CacheService::get('code_' . $phone); if (!$verifyCode) return app('json')->fail('请先获取验证码'); $verifyCode = substr($verifyCode, 0, 6); if ($verifyCode != $captcha) { return app('json')->fail('验证码错误'); } $user_type = $request->getFromType() ? $request->getFromType() : 'h5'; $token = $this->services->mobile($phone, $spread, $user_type); if ($token) { CacheService::delete('code_' . $phone); return app('json')->success('登录成功', $token); } else { return app('json')->fail('登录失败'); } } /** * H5切换登陆 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function switch_h5(Request $request) { $from = $request->post('from', 'wechat'); $user = $request->user(); $token = $this->services->switchAccount($user, $from); if ($token) { $token['userInfo'] = $user; return app('json')->success('登录成功', $token); } else return app('json')->fail('登录失败'); } /** * 绑定手机号 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function binding_phone(Request $request) { list($phone, $captcha, $key) = $request->postMore([ ['phone', ''], ['captcha', ''], ['key', ''] ], true); //验证手机号 try { validate(RegisterValidates::class)->scene('code')->check(['phone' => $phone]); } catch (ValidateException $e) { return app('json')->fail($e->getError()); } if (!$key) { return app('json')->fail('参数错误'); } if (!$phone) { return app('json')->fail('请输入手机号'); } //验证验证码 $verifyCode = CacheService::get('code_' . $phone); if (!$verifyCode) return app('json')->fail('请先获取验证码'); $verifyCode = substr($verifyCode, 0, 6); if ($verifyCode != $captcha) { return app('json')->fail('验证码错误'); } $re = $this->services->bindind_phone($phone, $key); if ($re) { CacheService::delete('code_' . $phone); return app('json')->success('绑定成功', $re); } else return app('json')->fail('绑定失败'); } /** * 绑定手机号 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function user_binding_phone(Request $request) { list($phone, $captcha, $step) = $request->postMore([ ['phone', ''], ['captcha', ''], ['step', 0] ], true); //验证手机号 try { validate(RegisterValidates::class)->scene('code')->check(['phone' => $phone]); } catch (ValidateException $e) { return app('json')->fail($e->getError()); } if (!$step) { //验证验证码 $verifyCode = CacheService::get('code_' . $phone); if (!$verifyCode) return app('json')->fail('请先获取验证码'); $verifyCode = substr($verifyCode, 0, 6); if ($verifyCode != $captcha) return app('json')->fail('验证码错误'); } $uid = (int)$request->uid(); $re = $this->services->userBindindPhone($uid, $phone, $step); if ($re) { CacheService::delete('code_' . $phone); return app('json')->success($re['msg'] ?? '绑定成功', $re['data'] ?? []); } else return app('json')->fail('绑定失败'); } public function update_binding_phone(Request $request) { [$phone, $captcha] = $request->postMore([ ['phone', ''], ['captcha', ''], ], true); //验证手机号 try { validate(RegisterValidates::class)->scene('code')->check(['phone' => $phone]); } catch (ValidateException $e) { return app('json')->fail($e->getError()); } //验证验证码 $verifyCode = CacheService::get('code_' . $phone); if (!$verifyCode) return app('json')->fail('请先获取验证码'); $verifyCode = substr($verifyCode, 0, 6); if ($verifyCode != $captcha) return app('json')->fail('验证码错误'); $uid = (int)$request->uid(); $re = $this->services->updateBindindPhone($uid, $phone); if ($re) { CacheService::delete('code_' . $phone); return app('json')->success($re['msg'] ?? '修改成功', $re['data'] ?? []); } else return app('json')->fail('修改失败'); } /** * 设置扫描二维码状态 * @param string $code * @return mixed */ public function setLoginKey(string $code) { if (!$code) { return app('json')->fail('登录CODE不存在'); } $cacheCode = CacheService::get($code); if ($cacheCode === false || $cacheCode === null) { return app('json')->fail('二维码已过期请重新扫描'); } CacheService::set($code, '0', 600); return app('json')->success(); } /** * apple快捷登陆 * @param Request $request * @param WechatServices $services * @return mixed * @throws \Psr\SimpleCache\InvalidArgumentException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException */ public function appleLogin(Request $request, WechatServices $services) { [$openId, $phone, $email, $captcha] = $request->postMore([ ['openId', ''], ['phone', ''], ['email', ''], ['captcha', ''] ], true); if ($phone) { if (!$captcha) { return app('json')->fail('请输入验证码'); } //验证验证码 $verifyCode = CacheService::get('code_' . $phone); if (!$verifyCode) return app('json')->fail('请先获取验证码'); $verifyCode = substr($verifyCode, 0, 6); if ($verifyCode != $captcha) { CacheService::delete('code_' . $phone); return app('json')->fail('验证码错误'); } } $userInfo = [ 'openId' => $openId, 'unionid' => '', 'avatarUrl' => sys_config('h5_avatar'), 'nickName' => $email, ]; $token = $services->appAuth($userInfo, $phone, 'apple'); if ($token) { return app('json')->success('登录成功', $token); } else if ($token === false) { return app('json')->success('登录成功', ['isbind' => true]); } else { return app('json')->fail('登陆失败'); } } }
\app\services\user\LoginServices.php
/** * 重置支付密码 * @param $account * @param $password */ public function payreset($account, $password) { $user = $this->dao->getOne(['account|phone' => $account]); if (!$user) { throw new ValidateException('用户不存在'); } if (!$this->dao->update($user['uid'], ['paypwd' => md5((string)$password)], 'uid')) { throw new ValidateException('修改支付密码失败'); } return true; }
\app\api\route\v1.php
//手机号修改支付密码
Route::post('register/payreset', 'v1.LoginController/payreset')->name('registerPayreset');
//用户预约
Route::post('user/invite', 'v1.InviteController/invite_edit')->name('inviteEdit');
//用户类 银行卡
Route::get('bank/detail/:id', 'v1.user.UserBankController/bank')->name('bank');//获取单个银行卡
Route::get('bank/list', 'v1.user.UserBankController/bank_list')->name('bankList');//银行卡列表
Route::post('bank/default/set', 'v1.user.UserBankController/bank_default_set')->name('bankDefaultSet');//设置默认银行卡
Route::get('bank/default', 'v1.user.UserBankController/bank_default')->name('bankDefault');//获取默认银行卡
Route::post('bank/edit', 'v1.user.UserBankController/bank_edit')->name('bankEdit');//修改 添加 银行卡
Route::post('bank/del', 'v1.user.UserBankController/bank_del')->name('bankDel');//删除银行卡
\app\services\user\UserBankServices.php
<?php declare (strict_types=1); namespace app\services\user; use app\api\validate\user\BankValidate; use app\services\BaseServices; use app\dao\user\UserBankDao; use crmeb\exceptions\AdminException; use think\Exception; use think\exception\ValidateException; /** * * Class UserAddressServices * @package app\services\user * @method getOne(array $where, ?string $field = '*', array $with = []) 获取一条数据 * @method be($map, string $field = '') 验证数据是否存在 */ class UserBankServices extends BaseServices { /** * UserAddressServices constructor. * @param UserAddressDao $dao */ public function __construct(UserBankDao $dao) { $this->dao = $dao; } /** * 获取单个地址 * @param $id * @param $field * @return array */ public function getBank($id, $field = []) { return $this->dao->get($id, $field); } /** * 获取所有地址 * @param array $where * @param string $field * @return array */ public function getBankList(array $where, string $field = '*'): array { [$page, $limit] = $this->getPageValue(); $list = $this->dao->getList($where, $field, $page, $limit); $count = $this->getBankCount($where); return compact('list', 'count'); } /** * 获取某个用户的所有地址 * @param int $uid * @param string $field * @return array */ public function getUserBankList(int $uid, string $field = '*'): array { [$page, $limit] = $this->getPageValue(); $where = ['uid' => $uid]; $where['is_del'] = 0; return $this->dao->getList($where, $field, $page, $limit); } /** * 获取用户默认地址 * @param int $uid * @param string $field * @return array */ public function getUserDefaultBank(int $uid, string $field = '*') { return $this->dao->getOne(['uid' => $uid, 'is_default' => 1, 'is_del' => 0], $field); } /** * 获取条数 * @param array $where * @return int */ public function getBankCount(array $where): int { return $this->dao->count($where); } /** * 添加地址 * @param array $data * @return bool */ public function create(array $data) { if (!$this->dao->save($data)) throw new AdminException('写入失败'); return true; } /** * 修改地址 * @param $id * @param $data * @return bool */ public function updateBank(int $id, array $data) { if (!$this->dao->update($id, $data)) throw new AdminException('修改失败'); return true; } /** * 设置默认定制 * @param int $uid * @param int $id * @return bool */ public function setDefault(int $uid, int $id) { if (!$this->getBank($id)) { throw new ValidateException('地址不存在'); } if (!$this->dao->update($uid, ['is_default' => 0], 'uid')) throw new Exception('取消原来默认银行卡'); if (!$this->dao->update($id, ['is_default' => 1])) throw new Exception('设置默认银行卡失败'); return true; } /** * 获取单个地址 * @param int $id * @return mixed */ public function bank(int $id) { $bankInfo = $this->getBank($id); if (!$bankInfo || $bankInfo['is_del'] == 1) { throw new ValidateException('数据不存在'); } return $bankInfo->toArray(); } /** * 添加|修改地址 * @param int $uid * @param array $addressInfo * @return mixed */ public function editBank(int $uid, array $bankInfo) { if ($bankInfo['id'] == 0) { $where = [ ['uid', '=', $uid], ['bankname', '=', $bankInfo['bankname']], ['cardno', '=', $bankInfo['cardno']], ['is_del', '=', 0] ]; $res = $this->dao->getCount($where); if ($res) throw new ValidateException('银行卡已存在,请勿重复添加'); } $bankInfo['is_default'] = (int)$bankInfo['is_default'] == true ? 1 : 0; $bankInfo['uid'] = $uid; //数据验证 validate(BankValidate::class)->check($bankInfo); $bank_check = []; if ($bankInfo['id']) { $bank_check = $this->getBank((int)$bankInfo['id']); } if ($bank_check && $bank_check['is_del'] == 0 && $bank_check['uid'] = $uid) { $id = (int)$bankInfo['id']; unset($bankInfo['id']); if (!$this->dao->update($id, $bankInfo, 'id')) { throw new ValidateException('编辑银行卡失败'); } if ($bankInfo['is_default']) { $this->setDefault($uid, $id); } return ['type' => 'edit', 'msg' => '编辑银行卡成功', 'data' => []]; } else { $bankInfo['add_time'] = time(); //首次添加地址,自动设置为默认地址 $bankCount = $this->getBankCount(['uid' => $uid]); if (!$bankCount) $bankInfo['is_default'] = 1; if (!$bank = $this->dao->save($bankInfo)) { throw new ValidateException('添加银行卡失败'); } if ($bankInfo['is_default']) { $this->setDefault($uid, (int)$bank->id); } return ['type' => 'add', 'msg' => '添加银行卡成功', 'data' => ['id' => $bank->id]]; } } /** * 删除地址 * @param int $uid * @param int $id * @return bool */ public function delBank(int $uid, int $id) { $bankInfo = $this->getBank($id); if (!$bankInfo || $bankInfo['is_del'] == 1 || $bankInfo['uid'] != $uid) { throw new ValidateException('数据不存在'); } if ($this->dao->update($id, ['is_del' => '1'], 'id')) return true; else throw new ValidateException('删除地址失败!'); } /** * 设置默认用户地址 * @param $id * @param $uid * @return bool */ public function setDefaultBank(int $id, int $uid) { $res1 = $this->dao->update($uid, ['is_default' => 0], 'uid'); $res2 = $this->dao->update(['id' => $id, 'uid' => $uid], ['is_default' => 1]); $res = $res1 !== false && $res2 !== false; return $res; } }
\app\api\validate\user\BankValidate.php
<?php namespace app\api\validate\user; use think\Validate; /** * 用户银行卡验证类 * Class AddressValidate * @package app\http\validates\user */ class BankValidate extends Validate { //移动 protected $rule = [ 'bankname' => 'require', 'cardno' => 'require', ]; protected $message = [ 'bankname.require' => '银行名称必须填写', 'cardno.require' => '银行卡号必须填写', ]; }
\app\api\validate\user\InviteValidate.php
<?php
namespace app\api\validate\user;
use think\Validate;
/**
* 用户银行卡验证类
* Class AddressValidate
* @package app\http\validates\user
*/
class InviteValidate extends Validate
{
//移动
protected $rule = [
];
}
\app\api\validate\user\RegisterValidates.php
<?php namespace app\api\validate\user; use think\Validate; /** * 注册验证 * Class RegisterValidates * @package app\http\validates\user */ class RegisterValidates extends Validate { protected $regex = ['phone' => '/^1[3456789]\d{9}$/']; protected $rule = [ 'phone' => 'require|regex:phone', 'account' => 'require|regex:phone', 'captcha' => 'require|length:6', 'password' => 'require', 'paypassword' => 'require', ]; protected $message = [ 'phone.require' => '手机号必须填写', 'phone.regex' => '手机号格式错误', 'account.require' => '手机号必须填写', 'account.regex' => '手机号格式错误', 'captcha.require' => '验证码必须填写', 'captcha.length' => '验证码长度不正确', 'password.require' => '密码必须填写', 'paypassword.require' => '支付密码必须填写', ]; public function sceneCode() { return $this->only(['phone']); } public function sceneRegister() { return $this->only(['account', 'captcha', 'password']); } public function sceneRegisterpay() { return $this->only(['account', 'captcha', 'paypassword']); } }
\app\dao\service\StoreServiceInviteDao.php
<?php namespace app\dao\service; use app\dao\BaseDao; use app\model\service\StoreServiceInvite; /** * Class StoreServiceFeedbackDao * @package app\dao\service */ class StoreServiceInviteDao extends BaseDao { protected function setModel(): string { return StoreServiceInvite::class; } /** * 获取用户反馈信息列表 * @param array $where * @param int $page * @param int $limit * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getInvite(array $where, int $page, int $limit) { return $this->search($where)->page($page, $limit)->order('id DESC')->select()->toArray(); } }
\app\dao\user\InviteDao.php
<?php namespace app\dao\user; use app\dao\BaseDao; use app\model\user\Invite; /** * 用户收获银行卡 * Class UserBankDao * @package app\dao\user */ class InviteDao extends BaseDao { /** * 设置模型 * @return string */ protected function setModel(): string { return Invite::class; } /** * 获取列表 * @param array $where * @param string $field * @param int $page * @param int $limit * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getList(array $where, string $field = '*', int $page, int $limit): array { return $this->search($where)->field($field)->page($page, $limit)->order('add_time DESC')->select()->toArray(); } }
\app\dao\user\UserBankDao.php
<?php namespace app\dao\user; use app\dao\BaseDao; use app\model\user\UserBank; /** * 用户收获银行卡 * Class UserBankDao * @package app\dao\user */ class UserBankDao extends BaseDao { /** * 设置模型 * @return string */ protected function setModel(): string { return UserBank::class; } /** * 获取列表 * @param array $where * @param string $field * @param int $page * @param int $limit * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getList(array $where, string $field = '*', int $page, int $limit): array { return $this->search($where)->field($field)->page($page, $limit)->order('is_default DESC')->select()->toArray(); } }
\app\model\service\StoreServiceInvite.php
<?php namespace app\model\service; use crmeb\basic\BaseModel; use crmeb\traits\ModelTrait; use think\Model; /** * 客服留言反馈 * Class StoreServiceFeedback * @package app\model\service */ class StoreServiceInvite extends BaseModel { use ModelTrait; /** * @var string */ protected $name = 'user_invite'; /** * @var string */ protected $pk = 'id'; /** * @param $value * @return false|string */ public function getAddTimeAttr($value) { return date('Y-m-d H:i:s', $value); } /** * 标题搜索 * @param Model $query * @param $value */ public function searchTitleAttr($query, $value) { $value && $query->whereLike('real_name|phone|nickname|uid', "%" . $value . "%"); } }
\app\model\user\Invite.php
<?php namespace app\model\user; use crmeb\basic\BaseModel; use crmeb\traits\ModelTrait; use think\model; /** * Class UserAddress * @package app\model\user */ class Invite extends BaseModel { use ModelTrait; /** * 数据表主键 * @var string */ protected $pk = 'id'; /** * 模型名称 * @var string */ protected $name = 'user_invite'; protected $insert = ['add_time']; protected $hidden = ['add_time']; protected function setAddTimeAttr() { return time(); } /** * 用户uid * @param $query * @param $value */ public function searchUidAttr($query, $value) { $query->where('uid', $value); } /** * 是否删除 * @param Model $query * @param $value */ public function searchIsDelAttr($query, $value) { $query->where('is_del', $value); } }
\app\model\user\UserBank.php
<?php namespace app\model\user; use crmeb\basic\BaseModel; use crmeb\traits\ModelTrait; use think\model; /** * Class UserAddress * @package app\model\user */ class UserBank extends BaseModel { use ModelTrait; /** * 数据表主键 * @var string */ protected $pk = 'id'; /** * 模型名称 * @var string */ protected $name = 'user_bank'; protected $insert = ['add_time']; protected $hidden = ['add_time', 'is_del']; protected function setAddTimeAttr() { return time(); } /** * 用户uid * @param $query * @param $value */ public function searchUidAttr($query, $value) { $query->where('uid', $value); } /** * 是否删除 * @param Model $query * @param $value */ public function searchIsDelAttr($query, $value) { $query->where('is_del', $value); } /** * 是否默认地址 * @param Model $query * @param $value */ public function searchIsDefaultAttr($query, $value) { $query->where('is_default', $value); } }
\app\services\activity\StoreSeckillServices.php
\app\services\product\product\StoreProductServices.php
\app\services\product\sku\StoreProductAttrValueServices.php
\app\services\message\service\StoreServiceInviteServices.php
<?php namespace app\services\message\service; use app\dao\service\StoreServiceInviteDao; use app\services\BaseServices; use crmeb\services\FormBuilder; use crmeb\traits\ServicesTrait; use think\exception\ValidateException; /** * 客服反馈 * Class StoreServiceFeedbackServices * @package app\services\message\service */ class StoreServiceInviteServices extends BaseServices { use ServicesTrait; /** * StoreServiceFeedbackServices constructor. * @param StoreServiceFeedbackDao $dao */ public function __construct(StoreServiceInviteDao $dao) { $this->dao = $dao; } /** * 获取反馈列表 * @param array $where * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getInviteList(array $where) { [$page, $limit] = $this->getPageValue(); $data = $this->dao->getInvite($where, $page, $limit); $count = $this->dao->count($where); return compact('data', 'count'); } }
\app\services\user\InviteServices.php
<?php declare (strict_types=1); namespace app\services\user; use app\api\validate\user\InviteValidate; use app\services\BaseServices; use app\dao\user\InviteDao; use think\Exception; use think\exception\ValidateException; /** * * Class UserAddressServices * @package app\services\user * @method getOne(array $where, ?string $field = '*', array $with = []) 获取一条数据 * @method be($map, string $field = '') 验证数据是否存在 */ class InviteServices extends BaseServices { /** * UserAddressServices constructor. * @param UserAddressDao $dao */ public function __construct(InviteDao $dao) { $this->dao = $dao; } /** * 获取单个地址 * @param $id * @param $field * @return array */ public function getInvite($id, $field = []) { return $this->dao->get($id, $field); } /** * 获取所有地址 * @param array $where * @param string $field * @return array */ public function getInviteList(array $where, string $field = '*'): array { [$page, $limit] = $this->getPageValue(); $list = $this->dao->getList($where, $field, $page, $limit); $count = $this->getInviteCount($where); return compact('list', 'count'); } public function getUserInviteList(int $uid, string $field = '*'): array { [$page, $limit] = $this->getPageValue(); $where = ['uid' => $uid]; $where['is_del'] = 0; return $this->dao->getList($where, $field, $page, $limit); } /** * 获取条数 * @param array $where * @return int */ public function getInviteCount(array $where): int { return $this->dao->count($where); } /** * 添加地址 * @param array $data * @return bool */ public function create(array $data) { if (!$this->dao->save($data)) throw new ValidateException('写入失败'); return true; } /** * 修改地址 * @param $id * @param $data * @return bool */ public function updateInvite(int $id, array $data) { if (!$this->dao->update($id, $data)) throw new ValidateException('修改失败'); return true; } /** * 添加|修改地址 * @param int $uid * @param array $addressInfo * @return mixed */ public function editInvite(int $uid, array $inviteInfo) { //if ($inviteInfo['id'] == 0) { // $where = [ // ['uid', '=', $uid], // ['bankname', '=', $bankInfo['bankname']], // ['cardno', '=', $bankInfo['cardno']], // ['is_del', '=', 0] // ]; // $res = $this->dao->getCount($where); // if ($res) throw new ValidateException('银行卡已存在,请勿重复添加'); // } //$bankInfo['is_default'] = (int)$bankInfo['is_default'] == true ? 1 : 0; $inviteInfo['uid'] = $uid; validate(InviteValidate::class)->check($inviteInfo); $invite_check = []; if ($inviteInfo['id']) { $invite_check = $this->getInvite((int)$inviteInfo['id']); } if ($invite_check && $invite_check['is_del'] == 0 && $invite_check['uid'] = $uid) { $id = (int)$inviteInfo['id']; unset($inviteInfo['id']); if (!$this->dao->update($id, $inviteInfo, 'id')) { throw new ValidateException('编辑预约失败'); } return ['type' => 'edit', 'msg' => '编辑预约成功', 'data' => []]; } else { $inviteInfo['add_time'] = time(); //var_dump($inviteInfo); if (!$invite = $this->dao->save($inviteInfo)) { throw new ValidateException('添加预约失败'); } return ['type' => 'add', 'msg' => '添加预约成功', 'data' => ['id' => $invite->id]]; } } /** * 删除地址 * @param int $uid * @param int $id * @return bool */ public function delInvite(int $uid, int $id) { $inviteInfo = $this->getInvite($id); if (!$inviteInfo || $inviteInfo['is_del'] == 1 || $inviteInfo['uid'] != $uid) { throw new ValidateException('数据不存在'); } if ($this->dao->update($id, ['is_del' => '1'], 'id')) return true; else throw new ValidateException('删除预约失败!'); } }
原文链接:https://blog.csdn.net/withkai44/article/details/123846120
作者:你说php不行了
链接:http://www.phpheidong.com/blog/article/355623/489992b60b0cb998943b/
来源:php黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 php黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-4
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!