diff --git a/app/common/dao/user/DepositRecordDao.php b/app/common/dao/user/DepositRecordDao.php index feb9e79..02b6fda 100644 --- a/app/common/dao/user/DepositRecordDao.php +++ b/app/common/dao/user/DepositRecordDao.php @@ -26,10 +26,10 @@ class DepositRecordDao extends BaseDao public function createOrderId($uid) { $count = (int)DepositRecord::getDB()->where('uid', $uid)->where('create_time', '>=', date("Y-m-d"))->where('create_time', '<', date("Y-m-d", strtotime('+1 day')))->count(); - return StoreOrderRepository::TYPE_SN_USER_DEPOSIT . date('YmdHis', time()) . ($uid . $count); + return StoreOrderRepository::TYPE_SN_USER_RECHARGE . date('YmdHis', time()) . ($uid . $count); } public function getSum($uid, $field){ - return DepositRecord::where('uid', $uid)->where('status', 1)->sum($field); + return DepositRecord::where('uid', $uid)->where('status','in', [1,2])->sum($field); } } diff --git a/app/common/model/user/DepositRecord.php b/app/common/model/user/DepositRecord.php index 50344d3..8100408 100644 --- a/app/common/model/user/DepositRecord.php +++ b/app/common/model/user/DepositRecord.php @@ -31,7 +31,7 @@ class DepositRecord extends BaseModel $params = [ 'order_sn' => $this->order_id, 'pay_price' => $this->price, - 'attach' => 'deposit_record', + 'attach' => 'user_recharge', 'body' => '用户预存' ]; if ($return_url) { diff --git a/app/common/repositories/store/DepositRepository.php b/app/common/repositories/store/DepositRepository.php index 736bbf4..be34876 100644 --- a/app/common/repositories/store/DepositRepository.php +++ b/app/common/repositories/store/DepositRepository.php @@ -101,7 +101,6 @@ class DepositRepository extends BaseRepository { $where = [ $this->dao->getPk() => $id, - 'is_del' => 0, ]; $ret = $this->dao->getWhere($where); return $ret; diff --git a/app/common/repositories/user/DepositRecordRepository.php b/app/common/repositories/user/DepositRecordRepository.php index ebae6cb..07ee3a2 100644 --- a/app/common/repositories/user/DepositRecordRepository.php +++ b/app/common/repositories/user/DepositRecordRepository.php @@ -43,10 +43,11 @@ class DepositRecordRepository extends BaseRepository $this->dao = $dao; } - public function create($uid, int $depositId, string $type) + public function create($uid, $price, int $depositId, string $type) { return $this->dao->create([ 'uid' => $uid, + 'price' => $price, 'deposit_id' => $depositId, 'deposit_type' => $type, 'order_id' => $this->dao->createOrderId($uid) @@ -76,7 +77,7 @@ class DepositRecordRepository extends BaseRepository if (in_array($type, ['weixin', 'alipay'], true) && $isApp) { $type .= 'App'; } - $service = new PayService($type, $depositRecord->getPayParams($type === 'alipay' ? $return_url : ''),'deposit_record'); + $service = new PayService($type, $depositRecord->getPayParams($type === 'alipay' ? $return_url : ''),'user_recharge'); $config = $service->pay($user); return $config + ['deposit_id' => $depositRecord['deposit_id'], 'type' => $type]; } @@ -93,32 +94,14 @@ class DepositRecordRepository extends BaseRepository */ public function paySuccess($orderId) { - $recharge = $this->dao->getWhere(['order_id' => $orderId]); - if ($recharge->paid == 1) return; - $recharge->paid = 1; - $recharge->pay_time = date('Y-m-d H:i:s'); + $record = $this->dao->getWhere(['order_id' => $orderId]); + if (empty($record) or $record->status != 0) return; + $record->status = 1; - Db::transaction(function () use ($recharge) { - $price = bcadd($recharge->price, $recharge->give_price, 2); - $mark = '成功充值余额' . floatval($recharge->price) . '元' . ($recharge->give_price > 0 ? ',赠送' . $recharge->give_price . '元' : ''); - app()->make(UserBillRepository::class)->incBill($recharge->user->uid, 'now_money', 'recharge', [ - 'link_id' => $recharge->recharge_id, - 'status' => 1, - 'title' => '余额充值', - 'number' => $price, - 'mark' => $mark, - 'balance' => bcadd($recharge->user->now_money, $price, 2) - ]); - $recharge->user->now_money = bcadd($recharge->user->now_money, $price, 2); - $recharge->user->save(); - $recharge->save(); + Db::transaction(function () use ($record) { + $record->save(); + app(UserRepository::class)->update($record['uid'],['is_lottery' => 1]); }); - Queue::push(SendSmsJob::class,['tempId' => 'USER_BALANCE_CHANGE', 'id' =>$orderId]); - - //小程序发货管理 - event('mini_order_shipping', ['recharge', $recharge, 3, '', '']); - - event('user.recharge',compact('recharge')); } public function getSum($uid, $field){ diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index 3b84127..71d275e 100755 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -83,7 +83,8 @@ class Auth extends BaseController // } // app(UserAssetsLogRepository::class)->shareAward(1); - app(DepositRecordDailyRepository::class)->runDaily(); +// app(DepositRecordDailyRepository::class)->runDaily(); + event('pay_success_user_recharge', array('order_sn' => 'wxu2024041817195114')); return app('json')->success(); } diff --git a/app/controller/api/Common.php b/app/controller/api/Common.php index c16062e..466283c 100755 --- a/app/controller/api/Common.php +++ b/app/controller/api/Common.php @@ -15,6 +15,7 @@ namespace app\controller\api; use app\common\repositories\delivery\DeliveryOrderRepository; +use app\common\repositories\store\DepositRepository; use app\common\repositories\store\product\ProductAssistSetRepository; use app\common\repositories\store\product\ProductGroupBuyingRepository; use app\common\repositories\store\product\ProductGroupRepository; @@ -135,9 +136,19 @@ class Common extends BaseController */ public function userRechargeQuota(GroupDataRepository $repository) { - $recharge_quota = $repository->groupDataId('user_recharge_quota', 0); - $recharge_attention = explode("\n", systemConfig('recharge_attention')); - return app('json')->success(compact('recharge_quota', 'recharge_attention')); +// $recharge_quota = $repository->groupDataId('user_recharge_quota', 0); +// $recharge_attention = explode("\n", systemConfig('recharge_attention')); +// return app('json')->success(compact('recharge_quota', 'recharge_attention')); + $depositList = app(DepositRepository::class)->selectWhere(['status' => 1]); + $recharge_quota = array(); + foreach ($depositList as $deposit){ + $recharge_quota[] = array( + "id" => $deposit['id'],"data"=>["price"=>$deposit['money'],"give"=>$deposit['diamond']], + ); + } + $recharge_attention = array(""); + $rule = app(CacheRepository::class)->getResult("the_lottery_rule"); + return app('json')->success(compact('recharge_quota', 'recharge_attention', 'rule')); } /** diff --git a/app/controller/api/user/UserRecharge.php b/app/controller/api/user/UserRecharge.php index 271f3b4..9967c3d 100755 --- a/app/controller/api/user/UserRecharge.php +++ b/app/controller/api/user/UserRecharge.php @@ -14,6 +14,8 @@ namespace app\controller\api\user; +use app\common\repositories\store\DepositRepository; +use app\common\repositories\user\DepositRecordRepository; use crmeb\basic\BaseController; use app\common\repositories\system\groupData\GroupDataRepository; use app\common\repositories\user\UserRechargeRepository; @@ -55,6 +57,10 @@ class UserRecharge extends BaseController if($price > 1000000){ return app('json')->fail('充值金额超出最大限制'); } + + $depositRepository =app(DepositRepository::class); + $depositRecordRepository =app(DepositRecordRepository::class); + $app = $this->request->isApp(); $user = $this->request->userInfo(); $wechatUserId = $user['wechat_user_id']; @@ -66,11 +72,23 @@ class UserRecharge extends BaseController if ($rechargeId) { if (!intval($rechargeId)) return app('json')->fail('请选择充值金额!'); - $rule = $groupDataRepository->merGet(intval($rechargeId), 0); - if (!$rule || !isset($rule['price']) || !isset($rule['give'])) - return app('json')->fail('您选择的充值方式已下架!'); - $give = floatval($rule['give']); - $price = floatval($rule['price']); +// $rule = $groupDataRepository->merGet(intval($rechargeId), 0); +// if (!$rule || !isset($rule['price']) || !isset($rule['give'])) +// return app('json')->fail('您选择的充值方式已下架!'); + $deposit = $depositRepository->get($rechargeId); + if($deposit['status'] == 0){ + return app('json')->fail('已下架!'); + } + + $where = array(); + $where[] = array('status', '>', 0); + $list = $depositRecordRepository->selectWhere($where); + if(count($list) >= $deposit['count']){ + return app('json')->fail('已超出限额!'); + } + +// $give = floatval($rule['give']); + $price = floatval($deposit['money']); if ($price <= 0) return app('json')->fail('请选择正确的充值金额!'); } else { @@ -81,7 +99,7 @@ class UserRecharge extends BaseController return app('json')->fail('最低充值' . floatval($config['store_user_min_recharge'])); $give = 0; } - $recharge = $this->repository->create($this->request->uid(), $price, $give, $type); - return app('json')->success($this->repository->pay($type, $user, $recharge, $return_url, $app)); + $recharge = $depositRecordRepository->create($this->request->uid(), $price, $rechargeId, $type); + return app('json')->success($depositRecordRepository->pay($type, $user, $recharge, $return_url, $app)); } } diff --git a/crmeb/listens/pay/UserRechargeSuccessListen.php b/crmeb/listens/pay/UserRechargeSuccessListen.php index 1b1efd4..f50909b 100755 --- a/crmeb/listens/pay/UserRechargeSuccessListen.php +++ b/crmeb/listens/pay/UserRechargeSuccessListen.php @@ -14,15 +14,17 @@ namespace crmeb\listens\pay; -use app\common\repositories\user\UserRechargeRepository; +use app\common\repositories\user\DepositRecordRepository; use crmeb\interfaces\ListenerInterface; +use think\facade\Log; class UserRechargeSuccessListen implements ListenerInterface { public function handle($data): void { + Log::info('用户充值成功回调'. json_encode($data)); $orderSn = $data['order_sn']; - app()->make(UserRechargeRepository::class)->paySuccess($orderSn); + app()->make(DepositRecordRepository::class)->paySuccess($orderSn); } } diff --git a/public/system.html b/public/system.html index 7e075f0..4ef1a04 100755 --- a/public/system.html +++ b/public/system.html @@ -1,3 +1,3 @@ -加载中...
\ No newline at end of file