<?php
namespace app\common\service\message\dealer;
use app\common\service\message\Basics;
use app\common\model\Setting as SettingModel;
use app\common\enum\dealer\withdraw\ApplyStatus as ApplyStatusEnum;
class Withdraw extends Basics
{
protected $param = [
'withdraw' => [], ];
public function send($param)
{
$this->param = $param;
$this->onSendWxSubMsg();
}
private function onSendWxSubMsg()
{
$withdrawInfo = $this->param['withdraw'];
$userInfo = $this->param['user'];
$wxappId = $withdrawInfo['wxapp_id'];
$template = $this->getTemplateByStatus($withdrawInfo);
if ($template === false) {
return false;
}
return $this->sendWxSubMsg($wxappId, [
'touser' => $userInfo['open_id'],
'template_id' => $template['template_id'],
'page' => 'pages/dealer/index/index',
'data' => $this->getTemplateData($withdrawInfo, $template)
]);
}
private function getTemplateData($withdrawInfo, $template)
{
if ($withdrawInfo['apply_status'] == ApplyStatusEnum::AUDIT_PASS) {
return [
$template['keywords'][0] => ['value' => $withdrawInfo['money']],
$template['keywords'][1] => ['value' => $withdrawInfo['pay_type']['text']],
$template['keywords'][2] => ['value' => '分销商提现'],
];
}
if ($withdrawInfo['apply_status'] == ApplyStatusEnum::AUDIT_REJECT) {
return [
$template['keywords'][0] => ['value' => $withdrawInfo['money']],
$template['keywords'][1] => ['value' => $withdrawInfo['create_time']],
$template['keywords'][2] => ['value' => $this->getSubstr($withdrawInfo['reject_reason'])],
];
}
return [];
}
private function getTemplateByStatus($withdrawInfo)
{
$wxappId = $withdrawInfo['wxapp_id'];
$templateGroup = SettingModel::getItem('submsg', $wxappId)['dealer'];
if (
$withdrawInfo['apply_status'] == ApplyStatusEnum::AUDIT_PASS
&& !empty($templateGroup['withdraw_01']['template_id'])
) {
return $templateGroup['withdraw_01'];
}
if (
$withdrawInfo['apply_status'] == ApplyStatusEnum::AUDIT_REJECT
&& !empty($templateGroup['withdraw_02']['template_id'])
) {
return $templateGroup['withdraw_02'];
}
return false;
}
}