CRMEB/crmeb/app/services/order/StoreOrderSuccessServices.php
2021-11-10 11:57:11 +08:00

109 lines
4.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\services\order;
use app\dao\order\StoreOrderDao;
use app\jobs\OrderJob;
use app\services\activity\lottery\LuckLotteryServices;
use app\services\activity\StorePinkServices;
use app\services\activity\StoreSeckillServices;
use app\services\BaseServices;
use app\services\pay\PayServices;
use app\services\product\product\StoreProductCouponServices;
use app\services\user\UserBillServices;
use app\services\user\UserServices;
use app\jobs\ProductLogJob;
use think\exception\ValidateException;
use think\facade\Log;
/**
* Class StoreOrderSuccessServices
* @package app\services\order
* @method getOne(array $where, ?string $field = '*', array $with = []) 获取去一条数据
*/
class StoreOrderSuccessServices extends BaseServices
{
/**
*
* StoreOrderSuccessServices constructor.
* @param StoreOrderDao $dao
*/
public function __construct(StoreOrderDao $dao)
{
$this->dao = $dao;
}
/**
* 0元支付
* @param array $orderInfo
* @param int $uid
* @return bool
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function zeroYuanPayment(array $orderInfo, int $uid, string $payType = PayServices::YUE_PAY)
{
if ($orderInfo['paid']) {
throw new ValidateException('该订单已支付!');
}
/** @var UserServices $services */
$services = app()->make(UserServices::class);
$userInfo = $services->getUserInfo($uid);
/** @var UserBillServices $userBillServices */
$userBillServices = app()->make(UserBillServices::class);
$res = $userBillServices->income('pay_product', $userInfo['uid'], $orderInfo['pay_price'], $userInfo['now_money'], $orderInfo['id']);
$res = $res && $this->paySuccess($orderInfo, $payType);//余额支付成功
return $res;
}
/**
* 支付成功
* @param array $orderInfo
* @param string $paytype
* @return bool
*/
public function paySuccess(array $orderInfo, string $paytype = PayServices::WEIXIN_PAY, array $other = [])
{
$updata = ['paid' => 1, 'pay_type' => $paytype, 'pay_time' => time()];
if ($other && isset($other['trade_no'])) {
$updata['trade_no'] = $other['trade_no'];
}
$res1 = $this->dao->update($orderInfo['id'], $updata);
$resPink = true;
if ($orderInfo['combination_id'] && $res1 && !$orderInfo['refund_status']) {
/** @var StorePinkServices $pinkServices */
$pinkServices = app()->make(StorePinkServices::class);
/** @var StoreOrderServices $orderServices */
$orderServices = app()->make(StoreOrderServices::class);
$resPink = $pinkServices->createPink($orderServices->tidyOrder($orderInfo, true));//创建拼团
}
//缓存抽奖次数 除过线下支付
if (isset($orderInfo['pay_type']) && $orderInfo['pay_type'] != 'offline') {
/** @var LuckLotteryServices $luckLotteryServices */
$luckLotteryServices = app()->make(LuckLotteryServices::class);
$luckLotteryServices->setCacheLotteryNum((int)$orderInfo['uid'], 'order');
}
//订单支付成功后置事件
event('order.orderPaySuccess', [$orderInfo]);
//用户推送消息事件
event('notice.notice', [$orderInfo, 'order_pay_success']);
//支付成功给客服发送消息
event('notice.notice', [$orderInfo, 'admin_pay_success_code']);
$res = $res1 && $resPink;
return false !== $res;
}
}