diff --git a/app/common/repositories/store/product/SpuRepository.php b/app/common/repositories/store/product/SpuRepository.php index b020df5..25bf8ec 100755 --- a/app/common/repositories/store/product/SpuRepository.php +++ b/app/common/repositories/store/product/SpuRepository.php @@ -161,6 +161,7 @@ class SpuRepository extends BaseRepository ]); $productMake = app()->make(ProductRepository::class); $count = $query->count(); + Log::info("+++++++++++++++page is".$page); $list = $query->page($page, $limit)->setOption('field', [])->field($this->productFiled)->select(); $append = ['stop_time','svip_price','show_svip_info','is_svip_price']; if ($productMake->getUserIsPromoter($userInfo)) diff --git a/app/common/repositories/user/UserAssetsLogRepository.php b/app/common/repositories/user/UserAssetsLogRepository.php index 11d40a8..d4f0538 100644 --- a/app/common/repositories/user/UserAssetsLogRepository.php +++ b/app/common/repositories/user/UserAssetsLogRepository.php @@ -154,7 +154,6 @@ class UserAssetsLogRepository extends BaseRepository public function serveAward($order){ - $this->_updateUserGroup($order['uid']); /** * @var UserGroupRepository $groupRepository @@ -172,7 +171,10 @@ class UserAssetsLogRepository extends BaseRepository } else { $shareRate = $product['normal_integral_one'] + $product['normal_integral_two']; } - $total = $this->_getValue($profit * (100 - $shareRate) /100); + $total = $this->_getValue($profit - $productItem['total_price'] * (100 - $shareRate)/100); + if($total < 0){ + continue; + } $currentRate = 0; foreach ($groupList as $group){ @@ -204,6 +206,7 @@ class UserAssetsLogRepository extends BaseRepository } } + $this->_updateUserGroup($order['uid']); } @@ -318,8 +321,8 @@ class UserAssetsLogRepository extends BaseRepository $LogList = array(); foreach ($order['orderProduct'] as $productItem) { $product = $this->productRepository->get($productItem['product_id']); - Log::info("product is " . json_encode($product)); - $profit = $productItem['total_price'] - $productItem['cost']; + // 取当前商品的总价 + $profit = $productItem['total_price']; if ($product['is_hot']) { $integralOne = $product['hot_integral_one']; diff --git a/app/common/repositories/user/UserAssetsRepository.php b/app/common/repositories/user/UserAssetsRepository.php index 0ed130a..6e61c5d 100644 --- a/app/common/repositories/user/UserAssetsRepository.php +++ b/app/common/repositories/user/UserAssetsRepository.php @@ -84,19 +84,19 @@ class UserAssetsRepository extends BaseRepository $assets = $this->assets($uid); $update = array('integral_buy' => 0, 'integral_withdraw' => 0, 'diamond' => 0, 'stock' => 0); if (isset($data['integral']) and $data['integral']) { - $tmp = $this->getIntegral($data['integral']); - $update['integral_buy'] = $tmp['integral_buy']; + $tmp = $this->getIntegral($data['integral']); + $update['integral_buy'] = $tmp['integral_buy']; $update['integral_withdraw'] = $tmp['integral_withdraw']; } - if(isset($data['diamond']) and $data['diamond']){ + if (isset($data['diamond']) and $data['diamond']) { $update['diamond'] = $data['diamond']; } - if(isset($data['stock']) and $data['stock']){ + if (isset($data['stock']) and $data['stock']) { $update['stock'] = $data['stock']; } $updateData = array(); - foreach ($update as $key => $value){ - if($value){ + foreach ($update as $key => $value) { + if ($value) { $updateData[$key] = $add ? $assets[$key] + $value : $assets[$key] - $value; } } @@ -126,29 +126,30 @@ class UserAssetsRepository extends BaseRepository */ public function integralToDiamond($uid, $count) { - $config = $this->getConfig(); - $assets = $this->assets($uid); - if ($assets['consume'] < $config['integralToDiamond'] * $count) { - throw new \Exception('消费积分不足'); + $integralField = "integral_withdraw"; + $config = $this->getConfig(); + $assets = $this->assets($uid); + if ($assets[$integralField] < $config['integralToDiamond'] * $count) { + throw new \Exception('积分不足'); } - $logList = array(); - $consume = -1 * $config['consume_to_share'] * $count; - $logList[] = array( + $logList = array(); + $integralCount = -1 * $config['integralToDiamond'] * $count; + $logList[] = array( 'uid' => $uid, - 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_CONSUME, - 'type' => UserAssetsLogRepository::CHANGE_TYPE_SHARE_EXCHANGE, - 'status' => UserAssetsLogRepository::STATUS_SUCCESS, - 'count' => $consume, + 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_INTEGRAL, + 'type' => UserAssetsLogRepository::CHANGE_TYPE_DIAMOND, + 'status' => UserAssetsLogRepository::STATUS_USE, + 'count' => $integralCount, ); - $logList[] = array( + $logList[] = array( 'uid' => $uid, - 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_SHARE_POINT, - 'type' => UserAssetsLogRepository::CHANGE_TYPE_SHARE_EXCHANGE, - 'status' => UserAssetsLogRepository::STATUS_SUCCESS, + 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_DIAMOND, + 'type' => UserAssetsLogRepository::CHANGE_TYPE_DIAMOND, + 'status' => UserAssetsLogRepository::STATUS_GET, 'count' => $count, ); app()->make(UserAssetsLogRepository::class)->addLog($logList); - $this->dao->update($uid, array('consume' => $assets['consume'] + $consume, 'share_point' => $assets['share_point'] + $count, 'share_point_time' => time())); + $this->dao->update($uid, array($integralField => $assets[$integralField] + $integralCount, 'diamond' => $assets['diamond'] + $count)); } /** @@ -166,7 +167,7 @@ class UserAssetsRepository extends BaseRepository public function diamondToStock($uid, $count) { $config = $this->getConfig(); - $assets = $this->assets($uid); + $assets = $this->assets($uid); if ($assets['diamond'] < $config['diamondToStock'] * $count) { throw new \Exception('钻石不足'); } @@ -179,7 +180,7 @@ class UserAssetsRepository extends BaseRepository 'status' => UserAssetsLogRepository::STATUS_USE, 'count' => $diamond, ); - $stock = $count; + $stock = $count; $logList[] = array( 'uid' => $uid, 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_STOCK, @@ -205,11 +206,13 @@ class UserAssetsRepository extends BaseRepository * @author zhangkxiang * @editor */ - public function sendHuitong($uid, $phone, $count) + public function sendIntegral($uid, $phone, $count) { - $assets = $this->assets($uid); - if ($assets['huitong'] < $count) { - throw new \Exception('惠通宝不足'); + $integralField = "integral_withdraw"; + $config = $this->getConfig(); + $assets = $this->assets($uid); + if ($assets[$integralField] < $count) { + throw new \Exception('积分不足'); } /** * @var UserRepository $userRepository @@ -220,14 +223,17 @@ class UserAssetsRepository extends BaseRepository throw new \Exception('用户不存在'); } + $rate = round($config['transferRate'] * $count / 100, 2); + $fromUser = $userRepository->get($uid); $logList[] = array( 'uid' => $toUser['uid'], - 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_HUITONG, - 'type' => UserAssetsLogRepository::CHANGE_TYPE_HUITONG_GET, - 'status' => UserAssetsLogRepository::STATUS_SUCCESS, - 'count' => $count, + 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_INTEGRAL, + 'type' => UserAssetsLogRepository::CHANGE_TYPE_INTEGRAL_GET, + 'status' => UserAssetsLogRepository::STATUS_GET, + 'count' => $count - $rate, + 'fee' => 0, 'ext' => array( 'from_uid' => $uid, 'from_phone' => $fromUser['phone'], @@ -235,23 +241,85 @@ class UserAssetsRepository extends BaseRepository ); $logList[] = array( 'uid' => $uid, - 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_HUITONG, - 'type' => UserAssetsLogRepository::CHANGE_TYPE_HUITONG_SEND, - 'status' => UserAssetsLogRepository::STATUS_SUCCESS, + 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_INTEGRAL, + 'type' => UserAssetsLogRepository::CHANGE_TYPE_INTEGRAL_SEND, + 'status' => UserAssetsLogRepository::STATUS_USE, 'count' => -1 * $count, + 'fee' => $rate, 'ext' => array( 'to_uid' => $toUser['uid'], 'to_phone' => $toUser['phone'], ), ); app()->make(UserAssetsLogRepository::class)->addLog($logList); - $this->dao->update($uid, array('huitong' => $assets['huitong'] - $count)); + $this->dao->update($uid, array($integralField => $assets[$integralField] - $count)); $toAssets = $this->assets($toUser['uid']); - $this->dao->update($toUser['uid'], array('huitong' => $toAssets['huitong'] + $count)); + $this->dao->update($toUser['uid'], array($integralField => $toAssets[$integralField] + $count - $rate)); } + /** + * notes 惠通宝转账 + * @param $uid + * @param $phone + * @param $count + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @create 2024/3/20 11:01 + * @update 2024/3/20 11:01 + * @author zhangkxiang + * @editor + */ + public function sendDiamond($uid, $phone, $count) + { + $config = $this->getConfig(); + $assets = $this->assets($uid); + if ($assets['diamond'] < $count) { + throw new \Exception('积分不足'); + } + /** + * @var UserRepository $userRepository + */ + $userRepository = app()->make(UserRepository::class); + $toUser = $userRepository->getUserByPhone($phone); + if (!$toUser) { + throw new \Exception('用户不存在'); + } + + $rate = round($config['transferRate'] * $count / 100, 2); + + $fromUser = $userRepository->get($uid); + $logList[] = array( + 'uid' => $toUser['uid'], + 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_DIAMOND, + 'type' => UserAssetsLogRepository::CHANGE_TYPE_DIAMOND_GET, + 'status' => UserAssetsLogRepository::STATUS_GET, + 'count' => $count - $rate, + 'fee' => 0, + 'ext' => array( + 'from_uid' => $uid, + 'from_phone' => $fromUser['phone'], + ), + ); + $logList[] = array( + 'uid' => $uid, + 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_DIAMOND, + 'type' => UserAssetsLogRepository::CHANGE_TYPE_DIAMOND_SEND, + 'status' => UserAssetsLogRepository::STATUS_USE, + 'count' => -1 * $count, + 'fee' => $rate, + 'ext' => array( + 'to_uid' => $toUser['uid'], + 'to_phone' => $toUser['phone'], + ), + ); + app()->make(UserAssetsLogRepository::class)->addLog($logList); + $this->dao->update($uid, array('diamond' => $assets['diamond'] - $count)); + $toAssets = $this->assets($toUser['uid']); + $this->dao->update($toUser['uid'], array('diamond' => $toAssets['diamond'] + $count - $rate)); + } public function getSum($field) diff --git a/app/common/repositories/user/UserRepository.php b/app/common/repositories/user/UserRepository.php index b704733..ce4b6e8 100755 --- a/app/common/repositories/user/UserRepository.php +++ b/app/common/repositories/user/UserRepository.php @@ -201,6 +201,11 @@ class UserRepository extends BaseRepository return compact('count', 'list'); } + + public function getUserByPhone($phone){ + return $this->dao->getWhere(['phone' => $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 ccaa8b9..7e17155 100755 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -155,7 +155,7 @@ class Auth extends BaseController */ public function userInfo() { - $user = $this->request->userInfo()->hidden(['label_id', 'group_id', 'pwd', 'addres', 'card_id', 'last_time', 'last_ip', 'create_time', 'mark', 'status', 'spread_uid', 'spread_time', 'real_name', 'birthday', 'brokerage_price']); + $user = $this->request->userInfo()->hidden(['label_id', 'pwd', 'addres', 'card_id', 'last_time', 'last_ip', 'create_time', 'mark', 'status', 'spread_uid', 'spread_time', 'real_name', 'birthday', 'brokerage_price']); $user->append(['service', 'topService', 'total_collect_product', 'total_collect_store', 'total_coupon', 'total_visit_product', 'total_unread', 'total_recharge', 'lock_integral', 'total_integral']); $data = $user->toArray(); $data['total_consume'] = $user['pay_price']; @@ -249,11 +249,11 @@ class Auth extends BaseController public function diamondToStock(){ $count = $this->request->param('count', 1); - $uid = 3; + $uid = 1; try { - app(UserAssetsRepository::class)->consumeToShare($uid, $count); + app(UserAssetsRepository::class)->diamondToStock($uid, $count); }catch (\Exception $e){ - return app('json')->fail($e->getMessage()); + return app('json')->fail($e->getMessage().$e->getFile().$e->getLine()); } return app('json')->success(); } diff --git a/app/controller/api/store/product/StoreSpu.php b/app/controller/api/store/product/StoreSpu.php index d7cf2d2..5f16ca4 100755 --- a/app/controller/api/store/product/StoreSpu.php +++ b/app/controller/api/store/product/StoreSpu.php @@ -62,6 +62,9 @@ class StoreSpu extends BaseController ]); $where['is_gift_bag'] = 0; $where['product_type'] = 0; + if(!is_numeric($limit)){ + $limit = 6; + } $where['order'] = $where['order'] ?: 'star'; if ($where['is_trader'] != 1) unset($where['is_trader']); $data = $this->repository->getApiSearch($where, $page, $limit, $this->userInfo); diff --git a/app/controller/api/user/User.php b/app/controller/api/user/User.php index 59e8615..cce897d 100755 --- a/app/controller/api/user/User.php +++ b/app/controller/api/user/User.php @@ -59,26 +59,33 @@ class User extends BaseController $where = array(); $where[] = array('asset_type','=',$asset_type); if($change_type) $where[] = array('type','=',$change_type); - $where[] = array('status','in',[UserAssetsLogRepository::STATUS_FROZEN, UserAssetsLogRepository::STATUS_SUCCESS, UserAssetsLogRepository::STATUS_USED, UserAssetsLogRepository::STATUS_REFUND]); + $where[] = array('status','in',[UserAssetsLogRepository::STATUS_GET, UserAssetsLogRepository::STATUS_WITHDRAW, UserAssetsLogRepository::STATUS_USE]); return app('json')->success(app(UserAssetsLogRepository::class)->list($uid, $where, $page, $limit)); } /** - * notes 消费积分兑分红点 + * notes 赠送钻石 * @return mixed - * @create 2024/3/19 22:39 - * @update 2024/3/19 22:39 + * @create 2024/3/20 11:00 + * @update 2024/3/20 11:00 * @author zhangkxiang * @editor */ - public function consumeToShare(){ + public function sendDiamond(){ $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($this->user->phone, $smsCode, $type); +// if (!$smsCode || !$checkSms) +// return app('json')->fail('验证码不正确'); try { - app(UserAssetsRepository::class)->consumeToShare($uid, $count); + app(UserAssetsRepository::class)->sendDiamond($uid, $phone, $count); }catch (\Exception $e){ return app('json')->fail($e->getMessage()); } @@ -87,39 +94,50 @@ class User extends BaseController /** - * notes 赠送惠通宝 + * notes 赠送积分 * @return mixed * @create 2024/3/20 11:00 * @update 2024/3/20 11:00 * @author zhangkxiang * @editor */ - public function sendHuitong(){ + public function sendIntegral(){ $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($this->user->phone, $smsCode, $type); - if (!$smsCode || !$checkSms) - return app('json')->fail('验证码不正确'); +// $checkSms = app()->make(SmsService::class)->checkSmsCode($this->user->phone, $smsCode, $type); +// if (!$smsCode || !$checkSms) +// return app('json')->fail('验证码不正确'); try { - app(UserAssetsRepository::class)->sendHuitong($uid, $phone, $count); + app(UserAssetsRepository::class)->sendIntegral($uid, $phone, $count); }catch (\Exception $e){ return app('json')->fail($e->getMessage()); } return app('json')->success(); } - - public function huitongToConsume(){ + public function integralToDiamond(){ $count = $this->request->param('count', 1); $uid = $this->user->uid; try { - app(UserAssetsRepository::class)->huitongToConsume($uid, $count); + app(UserAssetsRepository::class)->integralToDiamond($uid, $count); + }catch (\Exception $e){ + return app('json')->fail($e->getMessage()); + } + return app('json')->success(); + } + + + public function diamondToStock(){ + $count = $this->request->param('count', 1); + $uid = $this->user->uid; + try { + app(UserAssetsRepository::class)->diamondToStock($uid, $count); }catch (\Exception $e){ return app('json')->fail($e->getMessage()); } diff --git a/route/api.php b/route/api.php index 7344bc9..e414ad8 100755 --- a/route/api.php +++ b/route/api.php @@ -33,7 +33,7 @@ Route::group('api/', function () { //积分兑换钻石 Route::post('exchange/diamond', 'api.Auth/consumeToShare'); //钻石兑本票 - Route::post('exchange/stock', 'api.Auth/huitongToConsume'); + Route::post('exchange/stock', 'api.Auth/diamondToStock'); //赠送积分 Route::post('send/integral', 'api.Auth/sendIntegral'); Route::post('send/diamond', 'api.Auth/sendDiamond'); @@ -126,12 +126,13 @@ Route::group('api/', function () { //用户资产明细 Route::get('assetsLog', 'User/assetsLog'); //积分兑换钻石 - Route::post('exchange/diamond', 'User/consumeToShare'); + Route::post('exchange/diamond', 'User/integralToDiamond'); + //钻石兑本票 + Route::post('exchange/stock', 'User/diamondToStock'); //赠送积分 Route::post('send/integral', 'User/sendIntegral'); Route::post('send/diamond', 'User/sendDiamond'); - //钻石兑本票 - Route::post('exchange/stock', 'User/huitongToConsume'); + //切换账号 Route::get('account', 'User/account');