100 行
4.2 KiB
PHP
可执行文件
100 行
4.2 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace NotifyApi\Controller;
|
|
//[1.6.48]
|
|
use Api\Controller\AlidayuController;
|
|
use Common\Business\Plug;
|
|
use Credit\Model\CreditArrearageModel;
|
|
use Credit\Model\CreditStoreConfigViewModel;
|
|
use Think\Controller;
|
|
|
|
/**
|
|
* 赊账插件定时任务
|
|
* Class CreditController
|
|
* @package NotifyApi\Controller
|
|
*/
|
|
class CreditController extends Controller
|
|
{
|
|
/**
|
|
* 赊账每月统计向员工发送催收通知
|
|
* @return bool
|
|
*/
|
|
public function sendStatisticalNotice()
|
|
{
|
|
//1.判断是否安装赊账插件
|
|
//2.获取所有正常的商户
|
|
//3.循环发送短信
|
|
// 3.1.判断商户是否有赊账的权限
|
|
// 3.2.判断是否设置接收通知的手机号
|
|
// 3.3.统计门店数量、本月待还、总待还
|
|
// 3.4.发送短信
|
|
if (!in_array('Credit', C('MODULE_ALLOW_LIST'))) {
|
|
return false;
|
|
}
|
|
$mMap = [
|
|
'status' => 1,
|
|
];
|
|
$merList = D('RetailMerchant')->getSelect($mMap, 'id,name,mobile');
|
|
$Plug = new Plug();
|
|
$Arrearage = new CreditArrearageModel();
|
|
$StoreAndConfig = new CreditStoreConfigViewModel();
|
|
$AlidayuController = new AlidayuController();
|
|
foreach ($merList as $value) {
|
|
$PlugData = $Plug->PlugPermissions(['merchant_id' => $value['id'], 'identification_arr' => ['credit']]);
|
|
if (empty($PlugData['data']['plug']['credit'])) {
|
|
continue;
|
|
} else {
|
|
$storeMap = [
|
|
'merchantid' => $value['id'],
|
|
'status' => 1,
|
|
'state' => 0,
|
|
'is_credit' => 1,
|
|
];
|
|
//门店数量
|
|
$storeOfMerchant = $StoreAndConfig->getCount($storeMap);
|
|
//门店Id和赊账提醒电话数组
|
|
$storeInfo = $StoreAndConfig->getSelect($storeMap, 'credit_phone,id,storetag');
|
|
//商户本月待还金额总计
|
|
$storeArrMoneyTotal = 0;
|
|
//商户总待还金额统计
|
|
$storeTotalRepayMoney = 0;
|
|
foreach ($storeInfo as $val) {
|
|
$month_begin = mktime(0, 0, 0, date('m'), 1, date('Y'));
|
|
$month_end = mktime(23, 59, 59, date('m'), date('t'), date('Y'));
|
|
$monthWhere = [
|
|
'store_id' => $val['id'],
|
|
'status' => 1,
|
|
'add_time' => ['between', [$month_begin, $month_end]],
|
|
'state' => 2,
|
|
];
|
|
// 本月赊账待还金额
|
|
$ArrearageWaitMoney = $Arrearage->getSum($monthWhere, 'money');
|
|
$monthWhere['add_time'] = ['lt', time()];
|
|
// 总待还
|
|
$ArrearageTotalWaitMoney = $Arrearage->getSum($monthWhere, 'money');
|
|
// 门店设置通知手机号
|
|
$storeArrMoneyTotal += $ArrearageWaitMoney;
|
|
$storeTotalRepayMoney += $ArrearageTotalWaitMoney;
|
|
if (empty($val['credit_phone'])) {
|
|
continue;
|
|
} else {
|
|
$creditPhoneArr = json_decode($val['credit_phone'], true);
|
|
$sendData = [
|
|
'store_name' => $storeInfo['storetag'],
|
|
'month_wait_still' => $ArrearageWaitMoney,
|
|
'all_wait_still' => $ArrearageTotalWaitMoney,
|
|
];
|
|
$AlidayuController->sendCreditRemind($creditPhoneArr, $sendData, $value['id'], 2);
|
|
}
|
|
}
|
|
$merSendData = [
|
|
'store_count' => $storeOfMerchant,
|
|
'month_wait_still' => $storeArrMoneyTotal,
|
|
'all_wait_still' => $storeTotalRepayMoney,
|
|
];
|
|
$AlidayuController->sendCreditRemind([$merList['mobile']], $merSendData, $value['id'], 1);
|
|
}
|
|
}
|
|
}
|
|
}
|