// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\services\user; use app\dao\user\UserGiftQuotaDao; use app\services\BaseServices; use crmeb\exceptions\AdminException; use think\facade\Log; /** * 礼包额度服务 * Class UserGiftQuotaServices * @package app\services\user */ class UserGiftQuotaServices extends \app\services\BaseServices { /** * 礼包额度记录类型 * @var array */ protected $incomeData = [ 'order_gift_quota' => [ 'title' => '购买礼包赠送额度', 'type' => 'order_gift_quota', 'mark' => '购买礼包商品消费{%pay_price%}元,赠送额度{%number%}', 'status' => 1, 'pm' => 1 ], 'use_direct_referral_quota' => [ 'title' => '获得礼包直推奖扣除额度', 'type' => 'use_direct_referral_quota', 'mark' => '{%nickname%}购买礼包商品消费{%pay_price%}元,获得直推奖{%number%}', 'status' => 1, 'pm' => 0 ], 'use_spot_quota' => [ 'title' => '获得礼包见点奖扣除额度', 'type' => 'use_spot_quota', 'mark' => '{%nickname%}购买礼包商品消费{%pay_price%}元,获得见点奖{%number%}', 'status' => 1, 'pm' => 0 ], 'freeze_quotas' => [ 'title' => '额度不足冻结', 'type' => 'freeze_quotas', 'mark' => '{%nickname%}购买礼包商品消费{%pay_price%}元,额度不足,{%number%}元被冻结', 'status' => 1, 'pm' => 0 ], 'unfreeze_and_deduct_quotas' => [ 'title' => '解冻并扣除额度', 'type' => 'unfreeze_and_deduct_quotas', 'mark' => '获得新额度,解冻{%number%}元并扣除', 'status' => 1, 'pm' => 0 ], ]; /** * UserGiftQuotaServices constructor. * @param UserGiftQuotaDao $dao */ public function __construct(UserGiftQuotaDao $dao) { $this->dao = $dao; } /** * 写入礼包额度记录 * @param string $type 写入类型 * @param int $uid * @param int|string|array $number * @param int|string $balance * @param $linkId * @return bool|mixed */ public function income(string $type, int $uid, $number, $balance, $linkId) { $data = $this->incomeData[$type] ?? null; if (!$data) { return true; } $data['uid'] = $uid; $data['balance'] = $balance ?? 0; $data['link_id'] = $linkId; if (is_array($number)) { $key = array_keys($number); $key = array_map(function ($item) { return '{%' . $item . '%}'; }, $key); $value = array_values($number); $data['number'] = $number['number'] ?? 0; $data['mark'] = str_replace($key, $value, $data['mark']); } else { $data['number'] = $number; $data['mark'] = str_replace(['{%number%}'], $number, $data['mark']); } $data['add_time'] = time(); return $this->dao->save($data); } }