parent
0d76d0846d
commit
43935f4cf4
@ -0,0 +1,30 @@ |
||||
<?php |
||||
// +---------------------------------------------------------------------- |
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ] |
||||
// +---------------------------------------------------------------------- |
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved. |
||||
// +---------------------------------------------------------------------- |
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 |
||||
// +---------------------------------------------------------------------- |
||||
// | Author: CRMEB Team <admin@crmeb.com> |
||||
// +---------------------------------------------------------------------- |
||||
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); |
||||
} |
||||
} |
@ -0,0 +1,44 @@ |
||||
<?php |
||||
// +---------------------------------------------------------------------- |
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ] |
||||
// +---------------------------------------------------------------------- |
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved. |
||||
// +---------------------------------------------------------------------- |
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 |
||||
// +---------------------------------------------------------------------- |
||||
// | Author: CRMEB Team <admin@crmeb.com> |
||||
// +---------------------------------------------------------------------- |
||||
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; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,123 @@ |
||||
<?php |
||||
|
||||
// +---------------------------------------------------------------------- |
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ] |
||||
// +---------------------------------------------------------------------- |
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved. |
||||
// +---------------------------------------------------------------------- |
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 |
||||
// +---------------------------------------------------------------------- |
||||
// | Author: CRMEB Team <admin@crmeb.com> |
||||
// +---------------------------------------------------------------------- |
||||
|
||||
|
||||
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')); |
||||
} |
||||
} |
Loading…
Reference in new issue