| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- <?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;
- use app\common\repositories\merchant\order\OrderMerchantRepository;
- /**
- * 用户线下充值
- * 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;
- if (!$user->mer_id || !$user->locktime) {
- Db::name('user')->where('uid', $unionUser->uid)->update(['mer_id' => $order->mer_id, 'locktime' => date('Y-m-d H:i:s')]);
- }
- // $user->save();
- //同步用户部分------------------------------------
- //同步红包
- // Db::name("user_sign_hongbao")->where('order_id', $order->id)->update(['uid' => $unionUser->uid]);
- // //同步佣金
- // Db::name("user_sign_hongbao")->where('order_id', $order->id)->update(['uid' => $unionUser->uid]);
- // //同步积分
- // Db::name("user_sign_score")->where('order_id', $order->id)->update(['uid' => $unionUser->uid]);
- // //同步复购金
- // Db::name("user_sign_fugou")->where('order_id', $order->id)->update(['uid' => $unionUser->uid]);
-
- // //同步贡献值
- // Db::name("user_sign_gongxian")->where('order_id', $order->id)->update(['uid' => $unionUser->uid]);
- //同步后返佣
- $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
- $order_data = [
- 'order_sn' => $order->out_trade_no,
- 'order_id' => $order->id,
- 'pay_price' => $order->money,
- 'uid' => $unionUser->uid,
- 'mer_id' => $order->mer_id
- ];
- $user = Db::name('user')->where('uid', $unionUser->uid)->find();
- $OrderMerchantRepository->feidacang_fenyong($user, $order_data, 0);
- $OrderMerchantRepository->feidacang_fenyong_mer($user, $order_data, 0);
- //锁客
- $flag = 1;
- $order = (object)$order;
- $userRepository = app()->make(UserRepository::class);
- $user = $userRepository->getOne(['uid' => $unionUser->uid]);
- $userRepository->doBind($user, $order, $flag);
- OrderMerchant::getDB()->where('pay_user_id', $unionUser->unionid)->update(['uid' => $unionUser->uid, 'binds' => 1]);
- }
- } catch (\Throwable $e) {
- Log::info($e->getMessage());
- }
- });
- }
- }
|