| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- /**
- * @package merchant
- *
- * @author xaboy
- * @day 2020/6/2
- *
- *
- */
- namespace app\common\repositories\user;
- use app\common\dao\merchant\order\OrderMerchantDao;
- use app\common\dao\user\UserOfflineRechargeDao;
- use app\common\model\merchant\order\OrderMerchant;
- use app\common\repositories\BaseRepository;
- use think\facade\Db;
- use think\facade\Log;
- /**
- * 用户线下充值
- * Class UserOfflineRechargeRepository
- * @package app\common\repositories\user
- * @author php迷途小书童
- * @created 2021/1/30 15:59
- */
- class UserOfflineRechargeRepository extends BaseRepository
- {
- /**
- * UserRechargeRepository constructor.
- * @param UserOfflineRechargeDao $dao
- */
- public function __construct(UserOfflineRechargeDao $dao)
- {
- $this->dao = $dao;
- }
- /**
- * 线下充值成功后
- * @return bool
- * @author php迷途小书童
- * @created 2021/2/1 15:09
- */
- public function paySuccess($orderId, $orderSn, $uid, $mer_id, $money, $give_money, $pension, $avaiable, $pay_user_id)
- {
- if ($money <= 0) return true;
- Db::transaction(function () use ($money, $mer_id, $give_money, $pension, $uid, $orderId, $orderSn, $avaiable, $pay_user_id) {
- $userRepository = app()->make(UserRepository::class);
- $user = $userRepository->getOne(['uid' => $uid]);
- $recharge_money = bcadd($money, $give_money, 2);
- $recharge = $this->dao->getWhere(['uid' => $uid, 'mer_id' => $mer_id]);
- if (!$recharge) {
- $this->dao->create([
- 'uid' => $uid,
- 'mer_id' => $mer_id,
- 'money' => $recharge_money,
- 'pension' => $pension,
- ]);
- $balance = $recharge_money;
- } else {
- $recharge->money += $recharge_money;
- $recharge->pension += $pension;
- $recharge->save();
- $balance = $recharge->money;
- }
- $unionUsersRepository = app()->make(UnionUsersRepository::class);
- $unionUser = $unionUsersRepository->getWhere(['unionid' => $pay_user_id,'uid' => 0]);
- //更新三方注册信息UID
- if ($unionUser) {
- $recharge->money += $unionUser->balance;
- $recharge->pension += $unionUser->pension;
- $recharge->save();
- $unionUser->uid = $user->uid;
- $unionUser->save();
- }
- $price = bcadd($money, $give_money, 2);
- Log::info('price'.$price.'orderId'.$orderId);
- $mark = '线下扫码充值' . floatval($money) . '元' . ($give_money > 0 ? ',赠送' . $give_money . '元' : '');
- app()->make(UserBillRepository::class)->incBill($uid, 'offline_recharge_money', 'offline_recharge', [
- 'link_id' => $orderId,
- 'pm' => 1,
- 'status' => 1,
- 'title' => '线下扫码充值',
- 'number' => $price,
- 'mark' => $mark,
- 'balance' => $balance,
- 'order_sn' => $orderSn,
- 'mer_id' => $mer_id,
- ]);
- });
- }
- /**
- * 用户绑定成功后
- * @return bool
- * @author php迷途小书童
- * @created 2021/2/1 15:09
- */
- public function userBindSuccess($unionUser)
- {
- Db::transaction(function () use ($unionUser) {
- $recharge = $this->dao->getWhere(['uid' => $unionUser->uid, 'mer_id' => $unionUser->lock_mer_id]);
- if (!$recharge) {
- $this->dao->create([
- 'uid' => $unionUser->uid,
- 'mer_id' => $unionUser->lock_mer_id,
- 'money' => $unionUser->balance,
- 'give_money' => $unionUser->give_money,
- 'pension' => $unionUser->pension,
- ]);
- $balance = $unionUser->balance;
- } else {
- $recharge->money += $unionUser->balance;
- $recharge->give_money += $unionUser->give_money;
- $recharge->pension += $unionUser->pension;
- $recharge->save();
- $balance = $recharge->money;
- }
- $mark = '线下扫码充值' . floatval($unionUser->balance) . '元' . ($unionUser->give_money > 0 ? ',赠送' . $unionUser->give_money . '元' : '');
- app()->make(UserBillRepository::class)->incBill($unionUser->uid, 'offline_recharge_money', 'offline_recharge', [
- 'link_id' => $unionUser->id,
- 'pm' => 1,
- 'status' => 1,
- 'title' => '线下扫码充值',
- 'number' => $unionUser->give_money,
- 'mark' => $mark,
- 'balance' => $balance,
- 'order_sn' => $unionUser->id,
- 'mer_id' => $unionUser->lock_mer_id,
- ]);
- //返养老金
- try {
- $userRepository = app()->make(UserRepository::class);
- $user = $userRepository->getOne(['uid' => $unionUser->uid]);
- if ($unionUser->pension <= 0) return true;
- //496商户线下支付不返回养老金
- $orders = OrderMerchant::getDB()->where('pay_user_id', $unionUser->unionid)->where('status', 1) ->whereNotIn('mer_id', [496]) ->where('binds',0)->select();
- foreach ($orders as $order) {
- app()->make(UserBillRepository::class)->incBill($unionUser->uid, 'now_money', 'commission', [
- 'link_id' => $order->id,
- 'pm' => 1,
- 'status' => 1,
- 'title' => '养老金',
- 'number' => $order->pension,
- 'mark' => '线下消费获得养老金',
- 'commission_type' => 5,
- 'balance' => $user->annuity,
- 'order_sn' => $order->out_trade_no,
- 'mer_id' => $order->mer_id,
- 'source' => 1
- ]);
- $user->annuity += $order->pension;
- $user->annuity_num += 1;
- $user->save();
- OrderMerchant::getDB()->where('pay_user_id', $unionUser->unionid)->update(['uid' => $unionUser->uid, 'binds' => 1]);
- }
- } catch (\Throwable $e) {
- Log::info($e->getMessage());
- }
- });
- }
- }
|