mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-05-22 06:49:15 +08:00
修改订单处理
This commit is contained in:
parent
20d899b757
commit
4530ca11c4
@ -113,7 +113,7 @@ class Center extends Auth
|
||||
// 查询邀请的朋友
|
||||
$query = $this->_query($this->table);
|
||||
$query->like('nickname|username#nickname')->equal('pid1,id#uid');
|
||||
$query->field('id,pid1,username,nickname,headimg,amount_total,create_at');
|
||||
$query->field('id,pid0,pid1,pid2,pids,username,nickname,headimg,amount_total,create_at');
|
||||
$result = $query->where($map)->order('id desc')->page(true, false, false, 15);
|
||||
// 统计当前用户所有下属数
|
||||
$total = $this->app->db->name($this->table)->where($map)->count();
|
||||
@ -135,7 +135,7 @@ class Center extends Auth
|
||||
public function bindFrom()
|
||||
{
|
||||
$data = $this->_vali(['from.require' => '邀请人不能为空']);
|
||||
[$state, $message] = UpgradeService::instance()->bindAgent($this->uuid, $data['from']);
|
||||
[$state, $message] = UpgradeService::instance()->bindAgent($this->uuid, $data['from'], false);
|
||||
if ($state) {
|
||||
$this->success($message, UserService::instance()->total($this->uuid));
|
||||
} else {
|
||||
|
@ -42,7 +42,7 @@ class OrderService extends Service
|
||||
* @return integer
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function syncUserVipEntry(int $uid): int
|
||||
private function syncUserEntry(int $uid): int
|
||||
{
|
||||
// 检查是否购买入会礼包
|
||||
$query = $this->app->db->table('shop_order a')->join('shop_order_item b', 'a.order_no=b.order_no');
|
||||
@ -59,21 +59,24 @@ class OrderService extends Service
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据订单更新用户等级
|
||||
* @param string $order_no
|
||||
* @return array|null
|
||||
* @return array|null [USER, ORDER, ENTRY]
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function syncUserLevel(string $order_no): ?array
|
||||
{
|
||||
// 查询数据
|
||||
$order = $this->app->db->name('ShopOrder')->where("order_no='{$order_no}' and status>=4")->find();
|
||||
// 目标订单数据
|
||||
$map = [['order_no', '=', $order_no], ['status', '>=', 4]];
|
||||
$order = $this->app->db->name('ShopOrder')->where($map)->find();
|
||||
if (empty($order)) return null;
|
||||
// 订单用户数据
|
||||
$user = $this->app->db->name('DataUser')->where(['id' => $order['uid']])->find();
|
||||
if (empty($user)) return null;
|
||||
// 更新用户购买资格
|
||||
$entry = $this->syncUserVipEntry($order['uid']);
|
||||
$entry = $this->syncUserEntry($order['uid']);
|
||||
// 尝试绑定代理用户
|
||||
if (empty($user['pid1']) && ($order['puid1'] > 0 || $user['pid1'] > 0)) {
|
||||
$puid1 = $order['puid1'] > 0 ? $order['puid1'] : $user['bid'];
|
||||
@ -88,7 +91,7 @@ class OrderService extends Service
|
||||
}
|
||||
// 重新计算用户等级
|
||||
UpgradeService::instance()->syncLevel($user['id']);
|
||||
return [$order, $user, $entry];
|
||||
return [$user, $order, $entry];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,22 +47,21 @@ class UpgradeService extends Service
|
||||
{
|
||||
$user = $this->app->db->name('DataUser')->where(['id' => $uid])->find();
|
||||
if (empty($user)) return [0, '用户查询失败'];
|
||||
if (!empty($user['pid1'])) return [0, '用户已绑定上级'];
|
||||
|
||||
if (!empty($user['pids'])) return [0, '已绑定推荐人'];
|
||||
// 检查代理用户
|
||||
if (empty($pid)) $pid = $user['pid0'];
|
||||
if (empty($pid)) return [0, '绑定用户不存在'];
|
||||
if (intval($uid) === intval($pid)) return [0, '推荐人不能是自己'];
|
||||
|
||||
if (empty($pid)) return [0, '绑定推荐人不存在'];
|
||||
if ($uid == $pid) return [0, '推荐人不能是自己'];
|
||||
$parant = $this->app->db->name('DataUser')->where(['id' => $pid])->find();
|
||||
if (empty($parant['pids']) || empty($parant['vip_number'])) return [0, '推荐人无推荐资格'];
|
||||
|
||||
if (is_numeric(stripos($parant['path'], "-{$uid}-"))) return [0, '不能绑定下属'];
|
||||
$data = ['pid0' => $parant['id'], 'pid1' => $parant['id'], 'pid2' => $parant['pid1']];
|
||||
$data['path'] = rtrim($parant['path'] ?: '-', '-') . "-{$parant['id']}-";
|
||||
$data['layer'] = substr_count($data['path'], '-');
|
||||
// 非正式绑定时,不写入 pid1 及 pid2 字段
|
||||
if (empty($force)) [$data['pid1'], $data['pid2']] = [0, 0];
|
||||
|
||||
if (stripos($parant['path'], "-{$uid}-") !== false) return [0, '不能绑定下属'];
|
||||
// 组装代理数据
|
||||
$path = rtrim($parant['path'] ?: '-', '-') . "-{$parant['id']}-";
|
||||
$data = [
|
||||
'pid0' => $parant['id'], 'pid1' => $parant['id'], 'pid2' => $parant['pid1'],
|
||||
'pids' => $force ? 1 : 0, 'path' => $path, 'layer' => substr_count($path, '-'),
|
||||
];
|
||||
// 更新用户代理
|
||||
if ($this->app->db->name('DataUser')->where(['id' => $uid])->update($data) !== false) {
|
||||
return [1, '绑定代理成功'];
|
||||
} else {
|
||||
|
@ -4,6 +4,8 @@ use app\data\command\OrderClear;
|
||||
use app\data\command\UserBalance;
|
||||
use app\data\command\UserUpgrade;
|
||||
use app\data\command\UserTransfer;
|
||||
use app\data\service\OrderService;
|
||||
use app\data\service\RebateCurrentService;
|
||||
use think\Console;
|
||||
|
||||
if (app()->request->isCli()) {
|
||||
@ -17,7 +19,8 @@ if (app()->request->isCli()) {
|
||||
// 注册订单支付处理事件
|
||||
app()->event->listen('ShopOrderPayment', function ($orderNo) {
|
||||
app()->log->notice("订单支付事件,订单号:{$orderNo}");
|
||||
\app\data\service\RebateCurrentService::instance()->execute($orderNo);
|
||||
OrderService::instance()->syncUserLevel($orderNo);
|
||||
RebateCurrentService::instance()->execute($orderNo);
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user