where(['userId' => $userId])->asArray()->one(); } public static function updateByUserId($userId, $data) { xhUserAsset::updateByCondition(['userId' => $userId], $data); } public static function add($userId, $data) { $user = xhUserAsset::add($data); self::getByUserId($userId); return $user; } /** * 用户资金变化增加积分 * 充值、微信付款、余额付款等改变用户资产 * 此方法用于资金增减并引起积分增加,会员等级升级 */ public static function ioChangeAsset($user, $userAsset, $upAssetData, $merchant, $merchantExtend, $order, $capitalType) { $userId = $user['id']; $merchantId = $merchant['id']; $orderId = $order['id']; $openId = $user['openId']; $integral = isset($upAssetData['integral']) ? $upAssetData['integral'] : 0; $preLevel = $userAsset['member']; $preIntegral = $userAsset['integral']; $addIntegral = stringUtil::calcSub($integral, $preIntegral); $allTM = xhTMessageService::getList($merchantId); //没有积分,后续升级流程不需要再走 if (empty($integral)) { self::updateByUserId($userId, $upAssetData); return; } $typeList = configDict::getConfig('capitalType');//充值支付涉及的流水类型列表 switch ($capitalType) {//根据流水类型定制通知内容 case $typeList['xhOrder']['id']://购买商品 $goodsNum = $order['goodsNum']; $totalFee = $order['actPrice']; $name = $order['orderName']; $sourceType = $order['sourceType']; if ($sourceType == 0) { $shortTempId = 'OPENTM202297555';//下单成功通知 $tempId = isset($allTM[$shortTempId]) ? $allTM[$shortTempId] : 0; if (!empty($tempId)) { $data = [ "touser" => $openId, "template_id" => $tempId, "url" => Yii::$app->params['frontUrl'] . "/center/order-detail?id=$orderId&account=" . $merchant['id'], "data" => [ "first" => ["value" => '亲,您已成功下单!', "color" => "#173177"], "keyword1" => ["value" => (string)$orderId, "color" => "#173177"], "keyword2" => ["value" => $name, "color" => "#173177"], "keyword3" => ["value" => $goodsNum . '件', "color" => "#173177"], "keyword4" => ["value" => number_format($totalFee, 2) . '元', "color" => "#173177"], "keyword5" => ["value" => '微信支付', "color" => "#173177"], "remark" => ["value" => "", "color" => "#173177"]]]; wxUtil::sendTaskInform($data, $merchant); } } else { if ($addIntegral > 0) { $shortTempId = 'TM00230'; $tempId = isset($allTM[$shortTempId]) ? $allTM[$shortTempId] : 0; if (!empty($tempId)) { $changeData = ["touser" => $openId, "template_id" => $tempId, "url" => Yii::$app->params['frontUrl'] . "/center/order-detail?id=$orderId&account=" . $merchant['id'], "data" => [ "first" => ["value" => "您在本店购物获得积分", "color" => "#173177"], "FieldName" => ["value" => "会员名称", "color" => "#0F0F0F"], "Account" => ["value" => $user['userName'], "color" => "#173177"], "change" => ["value" => "增加", "color" => "#0F0F0F"], "CreditChange" => ["value" => $addIntegral, "color" => "#173177"], "CreditTotal" => ["value" => $integral, "color" => "#173177"], "Remark" => ["value" => "点此查看订单明细、添加编辑收花人信息", "color" => "#173177"],],]; wxUtil::sendTaskInform($changeData, $merchant); } } } break; case $typeList['xhActiveOrder']['id']://活动报名 $activeId = $order['activeId']; $active = xhActiveService::getById($activeId); $newApplyNum = $active['applyNum'] + 1;//活动报名人数+1 xhActiveService::updateById($activeId, ['applyNum' => $newApplyNum]); $shortTempId = 'TM00575';//报名成功通知 $tempId = isset($allTM[$shortTempId]) ? $allTM[$shortTempId] : 0; if (!empty($tempId)) { $changeData = ["touser" => $openId, "template_id" => $tempId, "url" => Yii::$app->params['frontUrl'] . '/active/order?id=' . $orderId . '&account=' . $merchant['id'], "data" => [ "first" => ["value" => "您好,您已报名成功", "color" => "#173177"], "keynote1" => ["value" => $active['title'], "color" => "#173177"], "keynote2" => ["value" => date("m-d H:i", $active['startTime']), "color" => "#173177"], "keynote3" => ["value" => $active['address'], "color" => "#173177"], "remark" => ["value" => "欢迎您的参加哦!", "color" => "#173177"],],]; wxUtil::sendTaskInform($changeData, $merchant); } break; case $typeList['xhRecharge']['id']://现金充值 $totalBalance = isset($upAssetData['balance']) ? $upAssetData['balance'] : 0; $rechargeAmount = $order['amount']; $url = empty($user['payPassword']) ? Yii::$app->params['frontUrl'] . '/center/password?account=' . $merchant['id'] : ''; $remark = empty($user['payPassword']) ? '您还没有设置支付密码!点此进行设置。' : '您当前帐户余额:' . $totalBalance . '元'; $shortTempId = 'TM00006';//充值成功通知用户 $tempId = isset($allTM[$shortTempId]) ? $allTM[$shortTempId] : 0; if (!empty($tempId)) { $data = ["touser" => $openId, "template_id" => $tempId, "url" => $url, "data" => [ "first" => ["value" => '亲,您已充值成功。', "color" => "#173177"], "accountType" => ["value" => '会员类型', "color" => "#000000"], "account" => ["value" => '普通', "color" => "#173177"], "amount" => ["value" => $rechargeAmount . '元', "color" => "#173177"], "result" => ["value" => '充值成功', "color" => "#173177"], "remark" => ["value" => $remark, "color" => "#173177"]]]; wxUtil::sendTaskInform($data, $merchant); } break; case $typeList['xhUserUnite']['id']: if ($addIntegral > 0) { $shortTempId = 'TM00230'; $tempId = isset($allTM[$shortTempId]) ? $allTM[$shortTempId] : 0; if (!empty($tempId)) { $changeData = ["touser" => $openId, "template_id" => $tempId, "url" => Yii::$app->params['frontUrl'] . '/center/right?account=' . $merchant['id'], "data" => [ "first" => ["value" => "支付宝绑定成功,获得积分:", "color" => "#173177"], "FieldName" => ["value" => "会员名称", "color" => "#0F0F0F"], "Account" => ["value" => $user['userName'], "color" => "#173177"], "change" => ["value" => "增加", "color" => "#0F0F0F"], "CreditChange" => ["value" => $addIntegral, "color" => "#173177"], "CreditTotal" => ["value" => $integral, "color" => "#173177"], "Remark" => ["value" => "点此查看明细!", "color" => "#173177"],],]; wxUtil::sendTaskInform($changeData, $merchant); } } break; default: } //新增积分 UserIntegralService::increaseToUpgrade($preIntegral, $integral, $preLevel, $userId, $merchantId, $merchantExtend); self::updateByUserId($userId, $upAssetData); } }