From 43935f4cf4e65e50320b929183b1d311e800c89d Mon Sep 17 00:00:00 2001 From: fengxinyhyl Date: Tue, 16 Apr 2024 17:49:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=AD=E4=B9=B0=E9=A2=84=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/user/DepositRecordDao.php | 30 +++++ .../dao/{store => user}/LotteryRecordDao.php | 7 +- app/common/model/user/DepositRecord.php | 44 +++++++ .../model/{store => user}/LotteryRecord.php | 2 +- .../store/order/StoreOrderRepository.php | 1 + .../user/DepositRecordRepository.php | 123 ++++++++++++++++++ .../LotteryRecordRepository.php | 4 +- app/controller/api/Auth.php | 2 +- 8 files changed, 204 insertions(+), 9 deletions(-) create mode 100644 app/common/dao/user/DepositRecordDao.php rename app/common/dao/{store => user}/LotteryRecordDao.php (91%) create mode 100644 app/common/model/user/DepositRecord.php rename app/common/model/{store => user}/LotteryRecord.php (96%) create mode 100644 app/common/repositories/user/DepositRecordRepository.php rename app/common/repositories/{store => user}/LotteryRecordRepository.php (95%) diff --git a/app/common/dao/user/DepositRecordDao.php b/app/common/dao/user/DepositRecordDao.php new file mode 100644 index 0000000..2de6ca3 --- /dev/null +++ b/app/common/dao/user/DepositRecordDao.php @@ -0,0 +1,30 @@ + +// +---------------------------------------------------------------------- +namespace app\common\dao\user; + +use app\common\dao\BaseDao; +use app\common\model\user\DepositRecord; +use app\common\model\user\UserRecharge; +use app\common\repositories\store\order\StoreOrderRepository; + +class DepositRecordDao extends BaseDao +{ + protected function getModel(): string + { + return DepositRecord::class; + } + + 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); + } +} diff --git a/app/common/dao/store/LotteryRecordDao.php b/app/common/dao/user/LotteryRecordDao.php similarity index 91% rename from app/common/dao/store/LotteryRecordDao.php rename to app/common/dao/user/LotteryRecordDao.php index cd87d98..a12f398 100644 --- a/app/common/dao/store/LotteryRecordDao.php +++ b/app/common/dao/user/LotteryRecordDao.php @@ -8,19 +8,16 @@ // +---------------------------------------------------------------------- // | Author: CRMEB Team // +---------------------------------------------------------------------- -namespace app\common\dao\store; +namespace app\common\dao\user; use app\common\dao\BaseDao; use app\common\model\store\Lottery; -use app\common\model\store\LotteryRecord; +use app\common\model\user\LotteryRecord; class LotteryRecordDao extends BaseDao { - - protected function getModel(): string { return LotteryRecord::class; } - } diff --git a/app/common/model/user/DepositRecord.php b/app/common/model/user/DepositRecord.php new file mode 100644 index 0000000..50344d3 --- /dev/null +++ b/app/common/model/user/DepositRecord.php @@ -0,0 +1,44 @@ + +// +---------------------------------------------------------------------- +namespace app\common\model\user; + +use app\common\model\BaseModel; + + +class DepositRecord extends BaseModel +{ + + public static function tablePk(): string + { + return 'id'; + } + + public static function tableName(): string + { + return 'deposit_record'; + } + + public function getPayParams($return_url = '') + { + $params = [ + 'order_sn' => $this->order_id, + 'pay_price' => $this->price, + 'attach' => 'deposit_record', + 'body' => '用户预存' + ]; + if ($return_url) { + $params['return_url'] = $return_url; + } + return $params; + } + + +} diff --git a/app/common/model/store/LotteryRecord.php b/app/common/model/user/LotteryRecord.php similarity index 96% rename from app/common/model/store/LotteryRecord.php rename to app/common/model/user/LotteryRecord.php index 0820457..0885123 100644 --- a/app/common/model/store/LotteryRecord.php +++ b/app/common/model/user/LotteryRecord.php @@ -8,7 +8,7 @@ // +---------------------------------------------------------------------- // | Author: CRMEB Team // +---------------------------------------------------------------------- -namespace app\common\model\store; +namespace app\common\model\user; use app\common\model\BaseModel; diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 35d9f5a..f387b7a 100755 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -86,6 +86,7 @@ class StoreOrderRepository extends BaseRepository const TYPE_SN_PRESELL = 'wxp'; const TYPE_SN_USER_ORDER = 'wxs'; const TYPE_SN_USER_RECHARGE = 'wxu'; + const TYPE_SN_USER_DEPOSIT = 'wxd'; const TYPE_SN_SERVER_ORDER = 'cs'; const TYPE_SN_REFUND = 'rwx'; /** diff --git a/app/common/repositories/user/DepositRecordRepository.php b/app/common/repositories/user/DepositRecordRepository.php new file mode 100644 index 0000000..8ad6d32 --- /dev/null +++ b/app/common/repositories/user/DepositRecordRepository.php @@ -0,0 +1,123 @@ + +// +---------------------------------------------------------------------- + + +namespace app\common\repositories\user; + +use app\common\dao\user\DepositRecordDao; +use app\common\model\user\DepositRecord; +use app\common\model\user\User; +use app\common\model\user\UserRecharge; +use app\common\repositories\BaseRepository; +use crmeb\jobs\SendSmsJob; +use crmeb\services\PayService; +use think\facade\Db; +use think\facade\Queue; + +/** + * Class UserRechargeRepository + * @package app\common\repositories\user + * @author xaboy + * @day 2020/6/2 + * @mixin DepositRecordDao + */ +class DepositRecordRepository extends BaseRepository +{ + const TYPE_WECHAT = 'weixin'; + const TYPE_ROUTINE = 'routine'; + /** + * UserRechargeRepository constructor. + * @param DepositRecordDao $dao + */ + public function __construct(DepositRecordDao $dao) + { + $this->dao = $dao; + } + + public function create($uid, int $depositId, string $type) + { + return $this->dao->create([ + 'uid' => $uid, + 'deposit_id' => $depositId, + 'deposit_type' => $type, + 'order_id' => $this->dao->createOrderId($uid) + ]); + } + + public function getList($where, $page, $limit) + { + $query = $this->dao->searchJoinQuery($where)->order('a.pay_time DESC,a.create_time DESC'); + $count = $query->count(); + $list = $query->page($page, $limit)->select(); + return compact('count', 'list'); + } + + + /** + * @param string $type + * @param User $user + * @param UserRecharge $recharge + * @param string $return_url + * @return mixed + * @author xaboy + * @day 2020/10/22 + */ + public function pay(string $type, User $user, DepositRecord $depositRecord, $return_url = '', $isApp = false) + { + if (in_array($type, ['weixin', 'alipay'], true) && $isApp) { + $type .= 'App'; + } + $service = new PayService($type, $depositRecord->getPayParams($type === 'alipay' ? $return_url : ''),'deposit_record'); + $config = $service->pay($user); + return $config + ['deposit_id' => $depositRecord['deposit_id'], 'type' => $type]; + } + + /** + * //TODO 余额充值成功 + * + * @param $orderId + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author xaboy + * @day 2020/6/19 + */ + 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'); + + 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(); + }); + Queue::push(SendSmsJob::class,['tempId' => 'USER_BALANCE_CHANGE', 'id' =>$orderId]); + + //小程序发货管理 + event('mini_order_shipping', ['recharge', $recharge, 3, '', '']); + + event('user.recharge',compact('recharge')); + } +} diff --git a/app/common/repositories/store/LotteryRecordRepository.php b/app/common/repositories/user/LotteryRecordRepository.php similarity index 95% rename from app/common/repositories/store/LotteryRecordRepository.php rename to app/common/repositories/user/LotteryRecordRepository.php index 1951cc2..936c640 100644 --- a/app/common/repositories/store/LotteryRecordRepository.php +++ b/app/common/repositories/user/LotteryRecordRepository.php @@ -8,11 +8,11 @@ // +---------------------------------------------------------------------- // | Author: CRMEB Team // +---------------------------------------------------------------------- -namespace app\common\repositories\store; +namespace app\common\repositories\user; use app\common\dao\store\GuaranteeDao; use app\common\dao\store\LotteryDao; -use app\common\dao\store\LotteryRecordDao; +use app\common\dao\user\LotteryRecordDao; use app\common\repositories\BaseRepository; use app\common\repositories\user\UserAssetsRepository; diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index b7a39fd..e1cbe1a 100755 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -15,7 +15,7 @@ namespace app\controller\api; use app\common\repositories\store\DepositRepository; -use app\common\repositories\store\LotteryRecordRepository; +use app\common\repositories\user\LotteryRecordRepository; use app\common\repositories\store\LotteryRepository; use app\common\repositories\store\order\StoreGroupOrderRepository; use app\common\repositories\store\order\StoreOrderRepository;