diff --git a/Application/Admin/Controller/ConsoleController.class.php b/Application/Admin/Controller/ConsoleController.class.php index 69a182a70..e0cd49d15 100644 --- a/Application/Admin/Controller/ConsoleController.class.php +++ b/Application/Admin/Controller/ConsoleController.class.php @@ -6,6 +6,7 @@ namespace Admin\Controller; use Admin\Model\SpendModel; use Think\Think; use Base\Tool\Printer; +use Base\Tool\TaskClient; use Base\Service\PromoteService; use GuzzleHttp\Client; @@ -324,4 +325,45 @@ class ConsoleController extends Think { } ); } + + public function divideWarnCheck() + { + $redis = new \Org\RedisSDK\Redis(['host'=>'127.0.0.1','port'=>6379],[]); + $warns = M('partner_divide_warn', 'tab_')->alias('pdw') + ->field('pdw.*, cgr.ratio, sum(s.pay_amount) as total_amount, p.partner') + ->join('tab_partner p on pdw.partner_id = p.id') + ->join('tab_game g on pdw.partner_id = g.partner_id') + ->join('tab_cp_game_ratio cgr on cgr.game_id = g.id and begin_total_amount = 0 and is_del = 0') + ->join('tab_spend s on s.game_id = g.id') + ->where(['pdw.status'=>1, 's.pay_status'=>1]) + ->group('pdw.id') + ->select(); + if (!$warns) return; + $taskClient = new TaskClient(); + $current_time = date('Y-m-d H:i:s'); + foreach ($warns as $info) { + if (!$info['ratio']) return; + $total_amount = ceil(($info['ratio'] / 100) * $info['total_amount']); + $cacheKey = "divide:warn:check:{$info['partner_id']}"; + if (!($lastStep = $redis->get($cacheKey))) { + $lastStep = 0; + } + if ((intval($info['advance_amount']) - intval($total_amount)) <= $info['warming_amount']) { + if ($total_amount - $lastStep >= $info['warn_frequency']) { // 达到预警 + // 发送预警短信 + $content = "{$info['partner']}的预付分成款已于{$current_time}余额不足{$info['warming_amount']}元,请尽快进行充值。"; + $sendRes = $taskClient->sendSmsBatch(json_decode($info['phones'], true), $content); + if ($sendRes['code'] != TaskClient::SUCCESS) { + continue; + } + // 变换缓存值,如果为0,需要设置过期时间 + if ($lastStep) { + $redis->set($cacheKey, $total_amount); + } else { + $redis->setex($cacheKey, 86400 * 30, $total_amount); + } + } + } + } + } } diff --git a/Application/Admin/Controller/GameController.class.php b/Application/Admin/Controller/GameController.class.php index 111b5fa45..4fe8865c9 100644 --- a/Application/Admin/Controller/GameController.class.php +++ b/Application/Admin/Controller/GameController.class.php @@ -525,6 +525,7 @@ class GameController extends ThinkController M('Game', 'tab_')->where($map)->data(array('relation_game_id' => $anogame['id']))->save(); } + $pic = M('Picture')->find($gda['icon']); $count = M('Game', 'tab_')->where(array('icon' => $gda['icon']))->count();//统计icon是否为多个游戏的图标 if ($pic != '' && $count == 1) { //只有一个游戏指向这个图标 @@ -847,6 +848,114 @@ class GameController extends ThinkController } + public function companyGames($id) + { + $games = M('Game', 'tab_') + ->where(['partner_id'=>$id]) + ->join("tab_cp_game_ratio on tab_game.id = tab_cp_game_ratio.game_id and begin_total_amount = 0 and is_del = 0", "left") + ->field("relation_game_name, game_id, tab_cp_game_ratio.ratio") + ->group('relation_game_id')->select(); + echo M()->getLastSql(); + var_dump($games); + } + + public function devide_warn_list($row = 10, $p = 1) + { + $map = ['pdw.status'=>1]; + if (!empty($_GET['partner_id'])) { + $map['pdw.partner_id'] = $_GET['partner_id']; + } + if (!empty($_GET['relation_game_id'])) { + $partner = M('Game', 'tab_')->field('partner_id')->where(['relation_game_id'=>$_GET['relation_game_id']])->find(); + $map['pdw.partner_id'] = $partner['partner_id']; + } + $list = M('partner_divide_warn', 'tab_') + ->alias('pdw')->field("pdw.*, p.partner, sum(s.pay_amount) as total_amount, group_concat(distinct(g.relation_game_name)) as game_name") + ->join("tab_partner p on p.id = pdw.partner_id") + ->join("tab_game g on pdw.partner_id = g.partner_id", 'left') + ->join('tab_spend s on s.game_id = g.id', 'left') + ->where(array_merge($map, ['s.pay_status'=>1])) + ->group('pdw.id, p.partner') + ->page($p, $row)->select(); + $count = M('partner_divide_warn', 'tab_')->alias('pdw')->join("tab_game g on pdw.partner_id = g.partner_id", 'left')->where($map)->count(); + // if (!empty($list)) { + // foreach ($list as &$item) { + // $item['create_time'] = date('Y-m-d', $item['create_time']); + // $item['upt_time'] = date('Y-m-d', $item['upt_time']); + // } + // } + $page = set_pagination($count, $row); + if ($page) { + $this->assign('_page', $page); + } + $partners = M('partner', 'tab_')->field("id, partner")->where(['status'=>1])->order('last_up_time desc')->select(); + $this->assign('partners', $partners); + $this->assign('list_data', $list); + $this->display(); + } + + public function devide_warn_edit($id=0, $delete=0) + { + if (IS_POST) { + if (empty($_POST['advance_amount']) || empty($_POST['warming_amount']) || empty($_POST['warn_frequency']) || empty($_POST['phones'])) { + return $this->error("请填写必填数据"); + } + if ($_POST['phones']) { + $_POST['phones'] = array_unique($_POST['phones']); + foreach ($_POST['phones'] as $phone) { + if (!preg_match('/^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/', $phone)) { + return $this->error("请输入正确的手机号码:{$phone}"); + } + } + $_POST['phones'] = json_encode($_POST['phones']); + } else { + $_POST['phones'] = '[]'; + } + if (!is_numeric($_POST['advance_amount']) || !is_numeric($_POST['warming_amount']) || !is_numeric($_POST['warn_frequency'])) { + return $this->error("金额需为数字!"); + } + if ($_POST['advance_amount'] < $_POST['warming_amount']) { + return $this->error("预警金额不能大于预付金额"); + } + if ($_POST['warming_amount'] < $_POST['warn_frequency']) { + return $this->error("预警金额频率不能大于预警金额"); + } + + if ($id) { + $_POST['upt_time'] = time(); + $_POST['operater_id'] = is_login(); + $upt = M('partner_divide_warn', 'tab_')->where(['id'=>$id])->save($_POST); + return $upt ? $this->success("更新成功") : $this->error("更新失败"); + } else { + if (M('partner_divide_warn', 'tab_')->where(['partner_id'=>$_POST['partner_id'], 'status'=>1])->find()) { + return $this->error('已有当前合作伙伴的预警设置'); + } + $_POST['upt_time'] = $_POST['create_time'] = time(); + $_POST['operater_id'] = is_login(); + $ins = M('partner_divide_warn', 'tab_')->add($_POST); + return $ins ? $this->success("新增成功") : $this->error("新增失败"); + } + } else { + $partners = M('partner', 'tab_')->field("id, partner")->where(['status'=>1])->order('last_up_time desc')->select(); + $this->assign('partners', $partners); + if ($id) { + if ($delete) { + $_POST['upt_time'] = $_POST['create_time'] = time(); + $_POST['operater_id'] = is_login(); + $_POST['status'] = 2; + $del = M('partner_divide_warn', 'tab_')->where(['id'=>$id])->save($_POST); + return $del ? $this->success("删除成功") : $this->error("删除失败"); + } else { + $warnInfo = M('partner_divide_warn', 'tab_')->where(['id'=>$id])->find(); + if (!$warnInfo) return $this->error('未找到该记录'); + $warnInfo['phones'] = json_decode($warnInfo['phones'], true); + $this->assign('warnInfo', $warnInfo); + } + } + $this->display(); + } + } + /** * 编辑CP分成比例 */ diff --git a/Application/Admin/Controller/PublicController.class.php b/Application/Admin/Controller/PublicController.class.php index 7b210c0f2..7daf4f29a 100644 --- a/Application/Admin/Controller/PublicController.class.php +++ b/Application/Admin/Controller/PublicController.class.php @@ -346,7 +346,7 @@ class PublicController extends \Think\Controller public function telsafecode($phone = '', $delay = 10, $flag = true) { $taskClient = new TaskClient(); - $result = $taskClient->sendSms($phone, get_client_ip()); + $result = $taskClient->sendSmsCode($phone, get_client_ip()); $data = []; if ($result['code'] == TaskClient::SUCCESS) { $data['status'] = 1; diff --git a/Application/Admin/View/Game/devide_warn_edit.html b/Application/Admin/View/Game/devide_warn_edit.html new file mode 100644 index 000000000..7a6a246d0 --- /dev/null +++ b/Application/Admin/View/Game/devide_warn_edit.html @@ -0,0 +1,131 @@ + + + + + + + + + + + + + +
+
预警编辑
+
    + +
  • + + +
  • +
  • + + * +
  • +
  • + + * +
  • +
  • + + * +
  • + + $phone):?> + +
  • + + * + +
  • + +
  • + + + +
  • + + + +
  • + + * + +
  • + +
  • + + +
  • +
+
+ + + +
+ + + \ No newline at end of file diff --git a/Application/Admin/View/Game/devide_warn_list.html b/Application/Admin/View/Game/devide_warn_list.html new file mode 100644 index 000000000..fe91d76ef --- /dev/null +++ b/Application/Admin/View/Game/devide_warn_list.html @@ -0,0 +1,205 @@ + + + + + + + + + + + + +
+ + +
+
+ +
+
+ +
+
+ +
+ + +
+
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
预警对象游戏名称游戏总流水预付金额预警金额预警金额频率预警手机号修改时间创建时间操作人操作
aOh! 暂时还没有内容!
{$data.partner}{$data.game_name}{$data.total_amount}{$data.advance_amount}{$data.warming_amount}{$data.warn_frequency}{$data.upt_time|date='Y-m-d H:i:s',###}{$data.create_time|date='Y-m-d H:i:s',###}{:get_admin_nickname($data['operater_id'])} + 编辑 + 解除 +
+
+
+
+ {$_page|default=''} +
+ + + +
+ + + + if(C('COLOR_STYLE')=='blue_color') echo ' + + '; + + + + + + + + diff --git a/Application/Base/Tool/TaskClient.class.php b/Application/Base/Tool/TaskClient.class.php index 0b8371c94..f65f50949 100644 --- a/Application/Base/Tool/TaskClient.class.php +++ b/Application/Base/Tool/TaskClient.class.php @@ -28,9 +28,27 @@ class TaskClient return json_decode($result, true); } - public function sendSms($mobile, $clientIp, $type = 'common') + public function sendSmsCode(string $mobile, string $clientIp) { - return $this->post('/message/sms-send', ['mobile' => $mobile, 'type' => $type, 'client_ip' => $clientIp]); + $options = ['type' => 'code', 'client_ip' => $clientIp]; + return $this->sendSms($mobile, $options); + } + + public function sendSmsContent(string $mobile, string $content) + { + $options = ['type' => 'content', 'content' => $content]; + return $this->sendSms($mobile, $options); + } + + public function sendSmsBatch(array $mobiles, string $content) + { + $options = ['type' => 'batch', 'content' => $content]; + return $this->sendSms($mobiles, $options); + } + + private function sendSms($mobile, array $options) + { + return $this->post('/message/sms-send', ['mobile' => $mobile, 'options' => $options]); } public function checkSms($mobile, $code) diff --git a/Application/Mobile/Controller/CommonController.class.php b/Application/Mobile/Controller/CommonController.class.php index 34778e276..d1b0e631a 100644 --- a/Application/Mobile/Controller/CommonController.class.php +++ b/Application/Mobile/Controller/CommonController.class.php @@ -220,7 +220,7 @@ class CommonController extends BaseController { { $phone = I('phone'); $taskClient = new TaskClient(); - $result = $taskClient->sendSms($phone, get_client_ip()); + $result = $taskClient->sendSmsCode($phone, get_client_ip()); $data = []; if ($result['code'] == TaskClient::SUCCESS) { $this->respondSuccess('发送成功'); diff --git a/Application/Mobile/Controller/SsgController.class.php b/Application/Mobile/Controller/SsgController.class.php index e674fcb59..8acbf792e 100644 --- a/Application/Mobile/Controller/SsgController.class.php +++ b/Application/Mobile/Controller/SsgController.class.php @@ -414,7 +414,7 @@ class SsgController extends BaseController { { $phone = I('phone'); $taskClient = new TaskClient(); - $result = $taskClient->sendSms($phone, get_client_ip()); + $result = $taskClient->sendSmsCode($phone, get_client_ip()); $data = []; if ($result['code'] == TaskClient::SUCCESS) { $data['status'] = 1; diff --git a/Application/Mobile/Controller/UserController.class.php b/Application/Mobile/Controller/UserController.class.php index fffb9cd55..afdfcdbde 100644 --- a/Application/Mobile/Controller/UserController.class.php +++ b/Application/Mobile/Controller/UserController.class.php @@ -581,7 +581,7 @@ class UserController extends BaseController public function telsafecode($phone = '', $delay = 10, $flag = true) { $taskClient = new TaskClient(); - $result = $taskClient->sendSms($phone, get_client_ip()); + $result = $taskClient->sendSmsCode($phone, get_client_ip()); $data = []; if ($result['code'] == TaskClient::SUCCESS) { $data['status'] = 1; diff --git a/Data/update.sql b/Data/update.sql index 95d041538..8b3cd9b2e 100644 --- a/Data/update.sql +++ b/Data/update.sql @@ -1206,3 +1206,18 @@ ALTER TABLE `tab_promote_company` ADD COLUMN `bank_name` VARCHAR(60) NOT NULL DEFAULT '0' COMMENT '收款银行' AFTER `bank_cardname`, ADD COLUMN `bank_address` VARCHAR(60) NOT NULL DEFAULT '0' COMMENT '开户网点' AFTER `bank_name`, ADD COLUMN `content` VARCHAR(255) NULL DEFAULT '' COMMENT '备注' AFTER `bank_address`; + +-- 2020-1-17 预付款预警 +CREATE TABLE `tab_partner_divide_warn` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '公司预警表', + `partner_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '公司ID', + `advance_amount` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '预付款', + `warming_amount` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '预警金额', + `phones` json DEFAULT NULL, + `warn_frequency` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '预警金额频率', + `status` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '状态 1正常 2删除', + `create_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间', + `upt_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '修改时间', + `operater_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '操作者ID', + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;