文件
mashangyoujiu/Application/Retail/Controller/SmsController.class.php

198 行
7.6 KiB
PHP
可执行文件

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace Retail\Controller;
use Api\Controller\AlidayuController;
use Common\Business\Plug;
use Common\Model\MerchantSmsModel;
use Common\Model\SmsOrderModel;
use Common\Model\SystemSmsModel;
use Common\Model\SystemSmsToMerModel;
use Think\Controller;
//[1.6.93]
/**
* 商户短信配置接口
* Class SmsController
* @package Retail\Controller
*/
class SmsController extends BaseController
{
public function index()
{
if (IS_POST) {
//商户短信配置
$MerchantSmsModel = new MerchantSmsModel();
$merchant_config = $MerchantSmsModel->getFind(['merchantid' => $this->merchant_id]);
//系统短信配置
$SystemSmsModel = new SystemSmsModel();
$system = $SystemSmsModel->getFind(['id' => ['gt', 0]], 'accesskeyid,accesskeysecret,accessname,accesscode');
$SystemSmsToMerModel = new SystemSmsToMerModel();
$mer_data = $SystemSmsToMerModel->getFind(['merchantid' => $this->merchant_id]);
$system_config = [
'status' => !empty($mer_data) && $mer_data['status'] == 1 ? 1 : 0,
'max' => !empty($mer_data) ? $mer_data['allnum'] : 0,
'used' => !empty($mer_data) ? $mer_data['usenum'] : 0,
'surplus' => !empty($mer_data) ? (bcsub($mer_data['allnum'], $mer_data['usenum'])) : 0,
];
//若未配置或参数未配置齐全视为不可用
if ($system) {
foreach ($system as $val) {
if (empty($val)) $system_config['status'] = 0;
}
} else {
$system_config['status'] = 0;
}
//商户赊账权限
$Plug = new Plug();
$PlugData = $Plug->PlugPermissions(['merchant_id' => $this->merchant_id, 'identification_arr' => ['credit']]);
if (!empty($PlugData['data']['plug']['credit'])) {
$credit = 1;
} else {
$credit = 0;
}
$this->ajaxReturn([
'status' => 1,
'message' => '获取成功',
'data' => [
'merchant_config' => $merchant_config ? $merchant_config : (object)[],
'system_config' => $system_config,
'credit' => $credit,
]
]);
} else {
$this->display();
}
}
/**
* 保存商户短信设置
*/
public function saveMerSms()
{
if (IS_POST) {
$post = I('post.');
$item = array(
'accesskeyid' => $post['accesskeyid'],
'accesskeysecret' => $post['accesskeysecret'],
'signname' => $post['signname'],
'verifitemplatecode' => $post['verifitemplatecode'],
'registertemplatecode' => $post['registertemplatecode'],
'register' => $post['register'],
'status' => $post['status'],
'mer_credit_code' => $post['mer_credit_code'],
'store_credit_code' => $post['store_credit_code'],
);
$MerchantSmsModel = new MerchantSmsModel();
$find = $MerchantSmsModel->getFind(['merchantid' => $this->merchant_id]);
if (!empty($find)) {
$res = $MerchantSmsModel->updateOrder(['merchantid' => $this->merchant_id], $item);
} else {
$item['addtime'] = time();
$item['merchantid'] = $this->merchant_id;
$res = $MerchantSmsModel->addOrder($item);
}
if ($res) {
$result['status'] = 1;
$result['msg'] = '操作成功';
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '短信设置修改';//操作行为描述
action_log($source, $type, $request_data, $desc);
} else {
$result['status'] = 0;
$result['msg'] = '操作失败';
}
$this->ajaxReturn($result);
}
}
/**
* 获取商户使用短信记录
*/
public function getMerSmsOrder()
{
$type = I('post.type');
$status = I('post.status');
if ($type) {
$map['ismerchantsms'] = $type;
}
if ($status) {
$map['isok'] = $status;
}
$map['merchantid'] = $this->merchant_id;
$SmsOrderModel = new SmsOrderModel();
$count = $SmsOrderModel->getCount($map);
$page = I('post.page');
$limit = I('post.limit');
$list = $SmsOrderModel->getSelect($map, '*', 'id desc', "{$page},{$limit}");
$typeArr = ['1' => '验证码', '2' => '会员充值', '3' => '会员消费', '4' => '成功激活会员',];
$statusArr = ['1' => '成功', '2' => '失败',];
$sceneArr = ['1' => '系统短信', '2' => '商家短信',];
foreach ($list as &$val) {
$val['add_time'] = date('Y-m-d H:i:s', $val['addtime']);
//1激活会员(发验证码) 2会员充值 3会员消费 4成功激活会员
$val['type_name'] = $typeArr[$val['type']] ? $typeArr[$val['type']] : '未知类型';
$val['status_name'] = $statusArr[$val['isok']] ? $statusArr[$val['isok']] : '未知';
$val['scene_name'] = $sceneArr[$val['ismerchantsms']] ? $sceneArr[$val['ismerchantsms']] : '未知';
}
$result['status'] = 1;
$result['msg'] = empty($list) ? '暂无数据' : '获取成功';
$result['data'] = $list ? $list : array();
$result['count'] = $count;
$this->ajaxReturn($result);
}
/**
* 短信测试
*/
public function smSTest()
{
$type = I('post.type');
$phone = I('post.phone');
if (!in_array($type, ['1', '2', '3', '4']) || !verifyMobilePhone($phone)) {
$result['msg'] = "请提交正确的参数";
$result['status'] = 0;
$this->ajaxReturn($result);
}
$AliDaYuApi = new AlidayuController();
switch ($type) {
case '1':
//验证码
$result = $AliDaYuApi->Send($phone, $this->merchant_id);
break;
case '2':
//成功注册会员
$name = D('RetailMerchant')->getFindField(['id' => $this->merchant_id], 'name');
$result = $AliDaYuApi->sendRegisterVipSuccess($phone, $this->merchant_id, $name);
break;
case '3':
case '4':
$item = [
'store_count' => 1,
'store_name' => '测试门店',
'month_wait_still' => '100.00',
'all_wait_still' => '300.00',
];
$response = $AliDaYuApi->sendCreditRemind([$phone], $item, $this->merchant_id, $type == 3 ? 1 : 2);
$result['status'] = 1;
$msg = [];
foreach ($response as $value) {
if ($value['status'] == 0) {
$result['status'] = 0;
}
$msg[] = $value['message'];
}
$result['message'] = implode(',', $msg);
break;
default:
$result['status'] = 0;
$result['message'] = '发送失败';
}
$this->ajaxReturn($result);
}
}