You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.2 KiB
PHP
101 lines
3.2 KiB
PHP
<?php
|
|
namespace Base\Service;
|
|
|
|
class MendService
|
|
{
|
|
public static $statusList = [
|
|
0 => '处理中',
|
|
1 => '处理成功',
|
|
2 => '处理失败',
|
|
];
|
|
|
|
public function getStatusText($status)
|
|
{
|
|
return self::$statusList[$status] ?? '未知';
|
|
}
|
|
|
|
public function addMendTask($params, $permPromote = null, $handlePromote = null)
|
|
{
|
|
$userId = $params['user_id'] ?? 0;
|
|
$remark = $params['remark'] ?? '';
|
|
$orderTime = $params['order_time'] ?? '';
|
|
$toPromoteId = $params['promote_id_to'] ?? '';
|
|
|
|
$promoteService = new PromoteService();
|
|
if ($toPromoteId == -1) {
|
|
$toPromoteId = 0;
|
|
}
|
|
if ($toPromoteId === '') {
|
|
throw new \Exception('请选择需要变更的渠道');
|
|
}
|
|
|
|
$user = M('user', 'tab_')->where(['id' => $userId])->find();
|
|
if (!$user) {
|
|
throw new \Exception('用户不存在');
|
|
}
|
|
if ($user['promote_id'] == $toPromoteId) {
|
|
throw new \Exception('没有变更数据');
|
|
}
|
|
if ($orderTime == '') {
|
|
throw new \Exception('没有订单日期');
|
|
}
|
|
|
|
if ($permPromote) {
|
|
$levelColumn = 'level'. $permPromote['level'] . '_id';
|
|
$promote = M('promote', 'tab_')->where(['id' => $user['promote_id']])->where([$levelColumn => $permPromote['id']])->find();
|
|
if (!$promote) {
|
|
throw new \Exception('所属推广员异常');
|
|
}
|
|
}
|
|
|
|
if ($this->checkOrderTime(strtotime($orderTime))) {
|
|
throw new \Exception('仅能补链本周数据,请重新选择补链时间');
|
|
}
|
|
|
|
if ($this->checkPromote(strtotime($orderTime), $user['account'])) {
|
|
throw new \Exception('在订单日期内含有多个推广员,无法补链');
|
|
}
|
|
|
|
$data = [
|
|
'from_promote_id' => $user['promote_id'],
|
|
'to_promote_id' => $toPromoteId,
|
|
'order_time' => $orderTime,
|
|
'type' => 2,
|
|
'shift_ids' => [$userId],
|
|
'creator_type' => $handlePromote ? 1 : 0,
|
|
'creator_id' => $handlePromote ? $handlePromote['id'] : $_SESSION["onethink_admin"]["user_auth"]["uid"]
|
|
];
|
|
|
|
if(!empty($params['remark'])){
|
|
$data['remark'] = $params['remark'];
|
|
}
|
|
|
|
$result = $promoteService->addShiftTask($data);
|
|
if (!$result['status']) {
|
|
throw new \Exception($result['msg']);
|
|
}
|
|
}
|
|
|
|
private function checkOrderTime($orderTime)
|
|
{
|
|
$sdefaultDate = date('Y-m-d');
|
|
$first = 1; //周一开始
|
|
$w = date('w',strtotime($sdefaultDate));
|
|
$checktime = strtotime("$sdefaultDate -" . ($w ? $w - $first : 6) .' days'); //本周开始时间
|
|
if($orderTime >= $checktime){
|
|
//在本周允许换绑
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private function checkPromote($orderTime, $account)
|
|
{
|
|
$res = M('Spend','tab_')->field('promote_id')->where(['pay_time' => array('EGT', $orderTime), 'user_account' => $account])->group('promote_id')->select();
|
|
if(count($res)>1) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
} |