From facf77ee3efab2d73c0af9473ea5a728351baf87 Mon Sep 17 00:00:00 2001 From: fengxinyhyl Date: Tue, 19 Mar 2024 23:41:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=91=E6=8D=A2=E8=BD=AC=E8=AE=A9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/user/UserDao.php | 5 ++ .../user/UserAssetsLogRepository.php | 24 +++--- .../user/UserAssetsRepository.php | 75 +++++++++++++++++++ .../repositories/user/UserRepository.php | 14 ++++ app/controller/api/Auth.php | 42 +++++++++++ app/controller/api/user/User.php | 44 +++++++++++ crmeb/services/SmsService.php | 4 +- route/api.php | 9 ++- 8 files changed, 203 insertions(+), 14 deletions(-) diff --git a/app/common/dao/user/UserDao.php b/app/common/dao/user/UserDao.php index be9e915..30b111b 100644 --- a/app/common/dao/user/UserDao.php +++ b/app/common/dao/user/UserDao.php @@ -131,6 +131,11 @@ class UserDao extends BaseDao return $query; } + + public function getUserByPhone($phone){ + return User::where('phone', $phone)->find(); + } + /** * @param $keyword * @return BaseQuery diff --git a/app/common/repositories/user/UserAssetsLogRepository.php b/app/common/repositories/user/UserAssetsLogRepository.php index 0845ba0..743b552 100644 --- a/app/common/repositories/user/UserAssetsLogRepository.php +++ b/app/common/repositories/user/UserAssetsLogRepository.php @@ -39,13 +39,13 @@ class UserAssetsLogRepository extends BaseRepository const CHANGE_TYPE_ORDER = 1; // 个人下单 const CHANGE_TYPE_SIGN = 2; // 签到 - const CHANGE_TYPE_SHARE = 3; // 消费积分兑换分红点 + const CHANGE_TYPE_SHARE_EXCHANGE = 3; // 消费积分兑换分红点 const CHANGE_TYPE_SHARE_GET = 4; // 分红点返佣 const CHANGE_TYPE_SPREAD_GET = 5; // 推广返佣 const CHANGE_TYPE_CULTIVATE = 6; // 培育奖 const CHANGE_TYPE_AGENT = 7; // 区域代理奖 const CHANGE_TYPE_HUITONG = 8; // 惠通宝兑换消费积分 - const CHANGE_TYPE_HUITONG_TO = 9; // 转让他人 + const CHANGE_TYPE_HUITONG_SEND = 9; // 转让他人 const CHANGE_TYPE_HUITONG_GET = 10; // 他人转让 const STATUS_FROZEN = 0; // 冻结 @@ -72,16 +72,16 @@ class UserAssetsLogRepository extends BaseRepository public function getChangeType() { return array( - self::CHANGE_TYPE_ORDER => '个人下单', - self::CHANGE_TYPE_SIGN => '签到', - self::CHANGE_TYPE_SHARE => '消费积分兑换分红点', - self::CHANGE_TYPE_SHARE_GET => '分红点返佣', - self::CHANGE_TYPE_SPREAD_GET => '推广返佣', - self::CHANGE_TYPE_CULTIVATE => '培育奖', - self::CHANGE_TYPE_AGENT => '区域代理奖', - self::CHANGE_TYPE_HUITONG => '惠通宝兑换消费积分', - self::CHANGE_TYPE_HUITONG_TO => '转让他人', - self::CHANGE_TYPE_HUITONG_GET => '他人转让', + self::CHANGE_TYPE_ORDER => '个人下单', + self::CHANGE_TYPE_SIGN => '签到', + self::CHANGE_TYPE_SHARE_EXCHANGE => '消费积分兑换分红点', + self::CHANGE_TYPE_SHARE_GET => '分红点返佣', + self::CHANGE_TYPE_SPREAD_GET => '推广返佣', + self::CHANGE_TYPE_CULTIVATE => '培育奖', + self::CHANGE_TYPE_AGENT => '区域代理奖', + self::CHANGE_TYPE_HUITONG => '惠通宝兑换消费积分', + self::CHANGE_TYPE_HUITONG_SEND => '转让他人', + self::CHANGE_TYPE_HUITONG_GET => '他人转让', ); } diff --git a/app/common/repositories/user/UserAssetsRepository.php b/app/common/repositories/user/UserAssetsRepository.php index ab127b5..acde277 100644 --- a/app/common/repositories/user/UserAssetsRepository.php +++ b/app/common/repositories/user/UserAssetsRepository.php @@ -198,4 +198,79 @@ class UserAssetsRepository extends BaseRepository $logRepository->addLog($logList); } + + + /** + * notes + * @param $uid + * @param $count + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @create 2024/3/19 22:33 + * @update 2024/3/19 22:33 + * @author zhangkxiang + * @editor + */ + public function consumeToShare($uid, $count){ + $config = $this->getConfig(); + $assets = $this->assets($uid); + if($assets['consume'] < $config['consume_to_share'] * $count){ + throw new \Exception('消费积分不足'); + } + $logList = array(); + $consume = -1 * $config['consume_to_share'] * $count; + $logList[] = array( + 'uid' => $uid, + 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_CONSUME, + 'type' => UserAssetsLogRepository::CHANGE_TYPE_SHARE_EXCHANGE, + 'status' => UserAssetsLogRepository::STATUS_SUCCESS, + 'count' => $consume, + ); + $logList[] = array( + 'uid' => $uid, + 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_SHARE_POINT, + 'type' => UserAssetsLogRepository::CHANGE_TYPE_SHARE_EXCHANGE, + 'status' => UserAssetsLogRepository::STATUS_SUCCESS, + 'count' => $count, + ); + app()->make(UserAssetsLogRepository::class)->addLog($logList); + $this->changeEvent($uid, UserAssetsLogRepository::STATUS_SUCCESS, array('consume' => $consume)); + $this->dao->update($uid, array('share_point' => $assets['share_point'] + $count, 'share_point_time' => time())); + } + + + public function sendHuitong($uid, $phone, $count){ + $assets = $this->assets($uid); + if($assets['huitong'] < $count){ + throw new \Exception('惠通宝不足'); + } + /** + * @var UserRepository $userRepository + */ + $userRepository = app()->make(UserRepository::class); + $toUser = $userRepository->getUserByPhone($phone); + if(!$toUser){ + throw new \Exception('用户不存在'); + } + + $logList[] = array( + 'uid' => $toUser['uid'], + 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_HUITONG, + 'type' => UserAssetsLogRepository::CHANGE_TYPE_HUITONG_GET, + 'status' => UserAssetsLogRepository::STATUS_SUCCESS, + 'count' => $count, + ); + $logList[] = array( + 'uid' => $uid, + 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_HUITONG, + 'type' => UserAssetsLogRepository::CHANGE_TYPE_HUITONG_SEND, + 'status' => UserAssetsLogRepository::STATUS_SUCCESS, + 'count' => -1 * $count, + ); + app()->make(UserAssetsLogRepository::class)->addLog($logList); + $this->changeEvent($uid, UserAssetsLogRepository::STATUS_SUCCESS, array('huitong' => -1 * $count)); + $toAssets = $this->assets($toUser['uid']); + $this->dao->update($toUser['uid'], array('huitong' => $toAssets['huitong'] + $count)); + } } diff --git a/app/common/repositories/user/UserRepository.php b/app/common/repositories/user/UserRepository.php index 6cb655c..a5f2db3 100644 --- a/app/common/repositories/user/UserRepository.php +++ b/app/common/repositories/user/UserRepository.php @@ -196,6 +196,20 @@ class UserRepository extends BaseRepository return $query->find(); } + + /** + * notes + * @param $phone + * @return array|Model|null + * @create 2024/3/19 23:13 + * @update 2024/3/19 23:13 + * @author zhangkxiang + * @editor + */ + public function getUserByPhone($phone){ + return $this->dao->getUserByPhone($phone); + } + public function getPulbicLst(array $where, $page, $limit) { $query = $this->dao->search($where); diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index ff4df94..b995c0d 100644 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -184,6 +184,14 @@ class Auth extends BaseController return app('json')->success($data); } + /** + * notes 兑换配置 + * @return mixed + * @create 2024/3/19 22:20 + * @update 2024/3/19 22:20 + * @author zhangkxiang + * @editor + */ public function exchangeConfig(){ $config = app(UserAssetsRepository::class)->getConfig(); $huitong = app(HuitongRepository::class)->getCurrent(); @@ -195,6 +203,39 @@ class Auth extends BaseController return app('json')->success($data); } + + public function toShare(){ + $count = $this->request->param('count', 1); + $uid = 3; + + try { + app(UserAssetsRepository::class)->consumeToShare($uid, $count); + }catch (\Exception $e){ + return app('json')->fail($e->getMessage()); + } + return app('json')->success(); + } + + + public function toHuitong(){ + $count = $this->request->param('count', 1); + $phone = $this->request->param('phoneTo', "13166665555"); + $smsCode = $this->request->param('smsCode', 0156); + $type = $this->request->param('type', 'intention'); + $uid = 3; + Log::info("code: {$smsCode}, type: {$type}"); +// $checkSms = app()->make(SmsService::class)->checkSmsCode('18362705640', $smsCode, $type); +// if (!$smsCode || !$checkSms) +// return app('json')->fail('验证码不正确'); + + try { + app(UserAssetsRepository::class)->sendHuitong($uid, $phone, $count); + }catch (\Exception $e){ + return app('json')->fail($e->getMessage()); + } + return app('json')->success(); + } + /** * @param UserRepository $repository * @return mixed @@ -361,6 +402,7 @@ class Auth extends BaseController try { $sms_code = str_pad(random_int(1, 9999), 4, 0, STR_PAD_LEFT); $sms_time = systemConfig('sms_time') ? systemConfig('sms_time') : 30; + Log::info("{$data['phone']} send {$sms_code} with {$data['type']} "); SmsService::create()->send($data['phone'], 'VERIFICATION_CODE', ['code' => $sms_code, 'time' => $sms_time]); } catch (Exception $e) { return app('json')->fail($e->getMessage()); diff --git a/app/controller/api/user/User.php b/app/controller/api/user/User.php index 31b689a..374e8e7 100644 --- a/app/controller/api/user/User.php +++ b/app/controller/api/user/User.php @@ -19,6 +19,7 @@ use app\common\repositories\store\service\StoreServiceRepository; use app\common\repositories\system\CacheRepository; use app\common\repositories\user\MemberinterestsRepository; use app\common\repositories\user\UserAssetsLogRepository; +use app\common\repositories\user\UserAssetsRepository; use app\common\repositories\user\UserBillRepository; use app\common\repositories\user\UserBrokerageRepository; use app\common\repositories\user\UserRepository; @@ -31,6 +32,7 @@ use think\App; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; +use think\facade\Log; class User extends BaseController { @@ -61,6 +63,48 @@ class User extends BaseController } + /** + * notes 消费积分兑分红点 + * @return mixed + * @create 2024/3/19 22:39 + * @update 2024/3/19 22:39 + * @author zhangkxiang + * @editor + */ + public function consumeToShare(){ + $count = $this->request->param('count', 1); + $uid = $this->user->uid; + + try { + app(UserAssetsRepository::class)->consumeToShare($uid, $count); + }catch (\Exception $e){ + return app('json')->fail($e->getMessage()); + } + return app('json')->success(); + } + + + + public function sendHuitong(){ + $count = $this->request->param('count', 1); + $phone = $this->request->param('phoneTo'); + $smsCode = $this->request->param('smsCode'); + $type = $this->request->param('type', 'intention'); + $uid = $this->user->uid; + Log::info("code: {$smsCode}, type: {$type}"); + $checkSms = app()->make(SmsService::class)->checkSmsCode('18362705640', $smsCode, $type); + if (!$smsCode || !$checkSms) + return app('json')->fail('验证码不正确'); + + try { + app(UserAssetsRepository::class)->sendHuitong($uid, $phone, $count); + }catch (\Exception $e){ + return app('json')->fail($e->getMessage()); + } + return app('json')->success(); + } + + /** diff --git a/crmeb/services/SmsService.php b/crmeb/services/SmsService.php index ef0a14c..e190213 100644 --- a/crmeb/services/SmsService.php +++ b/crmeb/services/SmsService.php @@ -57,7 +57,9 @@ class SmsService { if (!env('DEVELOPMENT',false)) { $sms_key = $this->sendSmsKey($phone, $type); - if (!$cache_code = Cache::get($sms_key)) return false; + $cache_code = Cache::get($sms_key); + if (!$cache_code) return false; + \think\facade\Log::info('sms_key:'.$sms_key." and cache_code:".$cache_code." and code:".$code); if ($code != $cache_code) return false; Cache::delete($sms_key); } diff --git a/route/api.php b/route/api.php index 049b69b..270eb23 100644 --- a/route/api.php +++ b/route/api.php @@ -21,9 +21,13 @@ use think\facade\Route; Route::group('api/', function () { Route::any('test', 'api.Auth/test'); + Route::get('toshare', 'api.Auth/toShare'); + Route::get('tohuitong', 'api.Auth/toHuitong'); + + //兑换配置 - Route::get('exchangeConfig', 'api.Auth/exchangeConfig'); + Route::get('exchange/config', 'api.Auth/exchangeConfig'); //强制登录 Route::group(function () { @@ -110,6 +114,9 @@ Route::group('api/', function () { Route::group('user', function () { //用户资产明细 Route::get('assetsLog', 'User/assetsLog'); + //消费积分兑分红点 + Route::post('exchange/share', 'User/consumeToShare'); + Route::post('send/huitong', 'User/sendHuitong'); //切换账号 Route::get('account', 'User/account');