购买预存

main
fengxinyhyl 12 months ago
parent f32ae1f28a
commit 7bce2bc7ba
  1. 4
      app/common/dao/user/DepositRecordDao.php
  2. 2
      app/common/model/user/DepositRecord.php
  3. 1
      app/common/repositories/store/DepositRepository.php
  4. 35
      app/common/repositories/user/DepositRecordRepository.php
  5. 3
      app/controller/api/Auth.php
  6. 17
      app/controller/api/Common.php
  7. 32
      app/controller/api/user/UserRecharge.php
  8. 6
      crmeb/listens/pay/UserRechargeSuccessListen.php
  9. 2
      public/system.html

@ -26,10 +26,10 @@ class DepositRecordDao extends BaseDao
public function createOrderId($uid) 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(); $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){ 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);
} }
} }

@ -31,7 +31,7 @@ class DepositRecord extends BaseModel
$params = [ $params = [
'order_sn' => $this->order_id, 'order_sn' => $this->order_id,
'pay_price' => $this->price, 'pay_price' => $this->price,
'attach' => 'deposit_record', 'attach' => 'user_recharge',
'body' => '用户预存' 'body' => '用户预存'
]; ];
if ($return_url) { if ($return_url) {

@ -101,7 +101,6 @@ class DepositRepository extends BaseRepository
{ {
$where = [ $where = [
$this->dao->getPk() => $id, $this->dao->getPk() => $id,
'is_del' => 0,
]; ];
$ret = $this->dao->getWhere($where); $ret = $this->dao->getWhere($where);
return $ret; return $ret;

@ -43,10 +43,11 @@ class DepositRecordRepository extends BaseRepository
$this->dao = $dao; $this->dao = $dao;
} }
public function create($uid, int $depositId, string $type) public function create($uid, $price, int $depositId, string $type)
{ {
return $this->dao->create([ return $this->dao->create([
'uid' => $uid, 'uid' => $uid,
'price' => $price,
'deposit_id' => $depositId, 'deposit_id' => $depositId,
'deposit_type' => $type, 'deposit_type' => $type,
'order_id' => $this->dao->createOrderId($uid) 'order_id' => $this->dao->createOrderId($uid)
@ -76,7 +77,7 @@ class DepositRecordRepository extends BaseRepository
if (in_array($type, ['weixin', 'alipay'], true) && $isApp) { if (in_array($type, ['weixin', 'alipay'], true) && $isApp) {
$type .= 'App'; $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); $config = $service->pay($user);
return $config + ['deposit_id' => $depositRecord['deposit_id'], 'type' => $type]; return $config + ['deposit_id' => $depositRecord['deposit_id'], 'type' => $type];
} }
@ -93,32 +94,14 @@ class DepositRecordRepository extends BaseRepository
*/ */
public function paySuccess($orderId) public function paySuccess($orderId)
{ {
$recharge = $this->dao->getWhere(['order_id' => $orderId]); $record = $this->dao->getWhere(['order_id' => $orderId]);
if ($recharge->paid == 1) return; if (empty($record) or $record->status != 0) return;
$recharge->paid = 1; $record->status = 1;
$recharge->pay_time = date('Y-m-d H:i:s');
Db::transaction(function () use ($recharge) { Db::transaction(function () use ($record) {
$price = bcadd($recharge->price, $recharge->give_price, 2); $record->save();
$mark = '成功充值余额' . floatval($recharge->price) . '元' . ($recharge->give_price > 0 ? ',赠送' . $recharge->give_price . '元' : ''); app(UserRepository::class)->update($record['uid'],['is_lottery' => 1]);
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();
}); });
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){ public function getSum($uid, $field){

@ -83,7 +83,8 @@ class Auth extends BaseController
// } // }
// app(UserAssetsLogRepository::class)->shareAward(1); // 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(); return app('json')->success();
} }

@ -15,6 +15,7 @@ namespace app\controller\api;
use app\common\repositories\delivery\DeliveryOrderRepository; 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\ProductAssistSetRepository;
use app\common\repositories\store\product\ProductGroupBuyingRepository; use app\common\repositories\store\product\ProductGroupBuyingRepository;
use app\common\repositories\store\product\ProductGroupRepository; use app\common\repositories\store\product\ProductGroupRepository;
@ -135,9 +136,19 @@ class Common extends BaseController
*/ */
public function userRechargeQuota(GroupDataRepository $repository) public function userRechargeQuota(GroupDataRepository $repository)
{ {
$recharge_quota = $repository->groupDataId('user_recharge_quota', 0); // $recharge_quota = $repository->groupDataId('user_recharge_quota', 0);
$recharge_attention = explode("\n", systemConfig('recharge_attention')); // $recharge_attention = explode("\n", systemConfig('recharge_attention'));
return app('json')->success(compact('recharge_quota', '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'));
} }
/** /**

@ -14,6 +14,8 @@
namespace app\controller\api\user; namespace app\controller\api\user;
use app\common\repositories\store\DepositRepository;
use app\common\repositories\user\DepositRecordRepository;
use crmeb\basic\BaseController; use crmeb\basic\BaseController;
use app\common\repositories\system\groupData\GroupDataRepository; use app\common\repositories\system\groupData\GroupDataRepository;
use app\common\repositories\user\UserRechargeRepository; use app\common\repositories\user\UserRechargeRepository;
@ -55,6 +57,10 @@ class UserRecharge extends BaseController
if($price > 1000000){ if($price > 1000000){
return app('json')->fail('充值金额超出最大限制'); return app('json')->fail('充值金额超出最大限制');
} }
$depositRepository =app(DepositRepository::class);
$depositRecordRepository =app(DepositRecordRepository::class);
$app = $this->request->isApp(); $app = $this->request->isApp();
$user = $this->request->userInfo(); $user = $this->request->userInfo();
$wechatUserId = $user['wechat_user_id']; $wechatUserId = $user['wechat_user_id'];
@ -66,11 +72,23 @@ class UserRecharge extends BaseController
if ($rechargeId) { if ($rechargeId) {
if (!intval($rechargeId)) if (!intval($rechargeId))
return app('json')->fail('请选择充值金额!'); return app('json')->fail('请选择充值金额!');
$rule = $groupDataRepository->merGet(intval($rechargeId), 0); // $rule = $groupDataRepository->merGet(intval($rechargeId), 0);
if (!$rule || !isset($rule['price']) || !isset($rule['give'])) // if (!$rule || !isset($rule['price']) || !isset($rule['give']))
return app('json')->fail('您选择的充值方式已下架!'); // return app('json')->fail('您选择的充值方式已下架!');
$give = floatval($rule['give']); $deposit = $depositRepository->get($rechargeId);
$price = floatval($rule['price']); 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) if ($price <= 0)
return app('json')->fail('请选择正确的充值金额!'); return app('json')->fail('请选择正确的充值金额!');
} else { } else {
@ -81,7 +99,7 @@ class UserRecharge extends BaseController
return app('json')->fail('最低充值' . floatval($config['store_user_min_recharge'])); return app('json')->fail('最低充值' . floatval($config['store_user_min_recharge']));
$give = 0; $give = 0;
} }
$recharge = $this->repository->create($this->request->uid(), $price, $give, $type); $recharge = $depositRecordRepository->create($this->request->uid(), $price, $rechargeId, $type);
return app('json')->success($this->repository->pay($type, $user, $recharge, $return_url, $app)); return app('json')->success($depositRecordRepository->pay($type, $user, $recharge, $return_url, $app));
} }
} }

@ -14,15 +14,17 @@
namespace crmeb\listens\pay; namespace crmeb\listens\pay;
use app\common\repositories\user\UserRechargeRepository; use app\common\repositories\user\DepositRecordRepository;
use crmeb\interfaces\ListenerInterface; use crmeb\interfaces\ListenerInterface;
use think\facade\Log;
class UserRechargeSuccessListen implements ListenerInterface class UserRechargeSuccessListen implements ListenerInterface
{ {
public function handle($data): void public function handle($data): void
{ {
Log::info('用户充值成功回调'. json_encode($data));
$orderSn = $data['order_sn']; $orderSn = $data['order_sn'];
app()->make(UserRechargeRepository::class)->paySuccess($orderSn); app()->make(DepositRecordRepository::class)->paySuccess($orderSn);
} }
} }

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save