商城模型化

This commit is contained in:
邹景立 2021-09-13 12:11:44 +08:00
parent 6ce89f1399
commit d44cad80c9
39 changed files with 401 additions and 234 deletions

View File

@ -2,11 +2,14 @@
namespace app\data\command; namespace app\data\command;
use app\data\model\ShopOrder;
use app\data\model\ShopOrderItem;
use app\data\service\OrderService; use app\data\service\OrderService;
use think\admin\Command; use think\admin\Command;
use think\admin\Exception; use think\admin\Exception;
use think\console\Input; use think\console\Input;
use think\console\Output; use think\console\Output;
use think\Model;
/** /**
* 商城订单自动清理 * 商城订单自动清理
@ -43,10 +46,10 @@ class OrderClean extends Command
try { try {
$map = [['status', '<', 3], ['payment_status', '=', 0]]; $map = [['status', '<', 3], ['payment_status', '=', 0]];
$map[] = ['create_at', '<', date('Y-m-d H:i:s', strtotime('-30 minutes'))]; $map[] = ['create_at', '<', date('Y-m-d H:i:s', strtotime('-30 minutes'))];
[$total, $count] = [$this->app->db->name('ShopOrder')->where($map)->count(), 0]; [$total, $count] = [ShopOrder::mk()->where($map)->count(), 0];
$this->app->db->name('ShopOrder')->where($map)->select()->map(function ($item) use ($total, &$count) { ShopOrder::mk()->where($map)->select()->map(function (Model $item) use ($total, &$count) {
$this->queue->message($total, ++$count, "开始取消未支付的订单 {$item['order_no']}"); $this->queue->message($total, ++$count, "开始取消未支付的订单 {$item['order_no']}");
$this->app->db->name('ShopOrder')->where(['order_no' => $item['order_no']])->update([ $item->save([
'status' => 0, 'status' => 0,
'cancel_status' => 1, 'cancel_status' => 1,
'cancel_datetime' => date('Y-m-d H:i:s'), 'cancel_datetime' => date('Y-m-d H:i:s'),
@ -69,13 +72,13 @@ class OrderClean extends Command
try { try {
$map = [['status', '=', 0], ['payment_status', '=', 0]]; $map = [['status', '=', 0], ['payment_status', '=', 0]];
$map[] = ['create_at', '<', date('Y-m-d H:i:s', strtotime('-3 days'))]; $map[] = ['create_at', '<', date('Y-m-d H:i:s', strtotime('-3 days'))];
[$total, $count] = [$this->app->db->name('ShopOrder')->where($map)->count(), 0]; [$total, $count] = [ShopOrder::mk()->where($map)->count(), 0];
foreach ($this->app->db->name('ShopOrder')->where($map)->cursor() as $item) { ShopOrder::mk()->where($map)->select()->map(function (Model $item) use ($total, &$count) {
$this->queue->message($total, ++$count, "开始清理已取消的订单 {$item['order_no']}"); $this->queue->message($total, ++$count, "开始清理已取消的订单 {$item['order_no']}");
$this->app->db->name('ShopOrder')->where(['order_no' => $item['order_no']])->delete(); ShopOrder::mk()->where(['order_no' => $item['order_no']])->delete();
$this->app->db->name('ShopOrderItem')->where(['order_no' => $item['order_no']])->delete(); ShopOrderItem::mk()->where(['order_no' => $item['order_no']])->delete();
$this->queue->message($total, $count, "完成清理已取消的订单 {$item['order_no']}", 1); $this->queue->message($total, $count, "完成清理已取消的订单 {$item['order_no']}", 1);
} });
} catch (\Exception $exception) { } catch (\Exception $exception) {
$this->queue->error($exception->getMessage()); $this->queue->error($exception->getMessage());
} }

View File

@ -2,11 +2,16 @@
namespace app\data\command; namespace app\data\command;
use app\data\model\DataUser;
use app\data\service\UserUpgradeService; use app\data\service\UserUpgradeService;
use think\admin\Command; use think\admin\Command;
use think\admin\Exception;
use think\console\Input; use think\console\Input;
use think\console\input\Argument; use think\console\input\Argument;
use think\console\Output; use think\console\Output;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/** /**
* 更新用户代理关系 * 更新用户代理关系
@ -27,10 +32,10 @@ class UserAgent extends Command
* @param Input $input * @param Input $input
* @param Output $output * @param Output $output
* @return void * @return void
* @throws \think\admin\Exception * @throws Exception
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
protected function execute(Input $input, Output $output) protected function execute(Input $input, Output $output)
{ {
@ -39,11 +44,11 @@ class UserAgent extends Command
if (empty($puid)) $this->setQueueError("参数PID无效请传入正确的参数!"); if (empty($puid)) $this->setQueueError("参数PID无效请传入正确的参数!");
// 检查当前用户资料 // 检查当前用户资料
$user = $this->app->db->name('DataUser')->where(['id' => $uuid])->find(); $user = DataUser::mk()->where(['id' => $uuid])->find();
if (empty($user)) $this->setQueueError("读取用户数据失败!"); if (empty($user)) $this->setQueueError("读取用户数据失败!");
// 检查上级代理用户 // 检查上级代理用户
$parant = $this->app->db->name('DataUser')->where(['id' => $puid])->find(); $parant = DataUser::mk()->where(['id' => $puid])->find();
if (empty($parant)) $this->setQueueError('读取代理数据失败!'); if (empty($parant)) $this->setQueueError('读取代理数据失败!');
// 检查异常关系处理 // 检查异常关系处理
@ -53,7 +58,7 @@ class UserAgent extends Command
// 更新自己的代理关系 // 更新自己的代理关系
$path1 = rtrim($parant['path'] ?: '-', '-') . "-{$parant['id']}-"; $path1 = rtrim($parant['path'] ?: '-', '-') . "-{$parant['id']}-";
$this->app->db->name('DataUser')->where(['id' => $user['id']])->update([ DataUser::mk()->where(['id' => $user['id']])->update([
'path' => $path1, 'layer' => substr_count($path1, '-'), 'path' => $path1, 'layer' => substr_count($path1, '-'),
'pid0' => $parant['id'], 'pid1' => $parant['id'], 'pid2' => $parant['pid1'], 'pid0' => $parant['id'], 'pid1' => $parant['id'], 'pid2' => $parant['pid1'],
]); ]);
@ -62,13 +67,13 @@ class UserAgent extends Command
// 更新下级的代理关系 // 更新下级的代理关系
$path2 = "{$user['path']}{$user['id']}-"; $path2 = "{$user['path']}{$user['id']}-";
[$total, $count] = [$this->app->db->name('DataUser')->whereLike('path', "{$path2}%")->count(), 0]; [$total, $count] = [DataUser::mk()->whereLike('path', "{$path2}%")->count(), 0];
foreach ($this->app->db->name('DataUser')->whereLike('path', "{$path2}%")->order('layer desc')->select() as $vo) { foreach (DataUser::mk()->whereLike('path', "{$path2}%")->order('layer desc')->select() as $vo) {
$this->setQueueMessage($total, ++$count, "开始更新下级用户[{$vo['id']}]代理绑定!"); $this->setQueueMessage($total, ++$count, "开始更新下级用户[{$vo['id']}]代理绑定!");
// 更新下级用户代理数据 // 更新下级用户代理数据
$path3 = preg_replace("#^{$path2}#", "{$path1}{$user['id']}-", $vo['path']); $path3 = preg_replace("#^{$path2}#", "{$path1}{$user['id']}-", $vo['path']);
$attrs = array_reverse(str2arr($path3, '-')); $attrs = array_reverse(str2arr($path3, '-'));
$this->app->db->name('DataUser')->where(['id' => $vo['id']])->update([ DataUser::mk()->where(['id' => $vo['id']])->update([
'path' => $path3, 'layer' => substr_count($path3, '-'), 'path' => $path3, 'layer' => substr_count($path3, '-'),
'pid0' => $attrs[0] ?? 0, 'pid1' => $attrs[0] ?? 0, 'pid2' => $attrs[1] ?? 0, 'pid0' => $attrs[0] ?? 0, 'pid1' => $attrs[0] ?? 0, 'pid2' => $attrs[1] ?? 0,
]); ]);

View File

@ -2,6 +2,7 @@
namespace app\data\command; namespace app\data\command;
use app\data\model\DataUser;
use app\data\service\UserBalanceService; use app\data\service\UserBalanceService;
use app\data\service\UserRebateService; use app\data\service\UserRebateService;
use think\admin\Command; use think\admin\Command;
@ -30,8 +31,8 @@ class UserAmount extends Command
*/ */
protected function execute(Input $input, Output $output) protected function execute(Input $input, Output $output)
{ {
[$total, $count, $error] = [$this->app->db->name('DataUser')->count(), 0, 0]; [$total, $count, $error] = [DataUser::mk()->count(), 0, 0];
foreach ($this->app->db->name('DataUser')->field('id')->cursor() as $user) try { foreach (DataUser::mk()->field('id')->cursor() as $user) try {
$this->queue->message($total, ++$count, "刷新用户 [{$user['id']}] 余额及返利开始"); $this->queue->message($total, ++$count, "刷新用户 [{$user['id']}] 余额及返利开始");
UserRebateService::instance()->amount($user['id']); UserRebateService::instance()->amount($user['id']);
UserBalanceService::instance()->amount($user['id']); UserBalanceService::instance()->amount($user['id']);

View File

@ -2,6 +2,7 @@
namespace app\data\command; namespace app\data\command;
use app\data\model\DataUserTransfer;
use app\data\service\UserRebateService; use app\data\service\UserRebateService;
use think\admin\Command; use think\admin\Command;
use think\admin\Exception; use think\admin\Exception;
@ -41,8 +42,8 @@ class UserTransfer extends Command
protected function execute(Input $input, Output $output) protected function execute(Input $input, Output $output)
{ {
$map = [['type', 'in', ['wechat_banks', 'wechat_wallet']], ['status', 'in', [3, 4]]]; $map = [['type', 'in', ['wechat_banks', 'wechat_wallet']], ['status', 'in', [3, 4]]];
[$total, $count, $error] = [$this->app->db->name('DataUserTransfer')->where($map)->count(), 0, 0]; [$total, $count, $error] = [DataUserTransfer::mk()->where($map)->count(), 0, 0];
foreach ($this->app->db->name('DataUserTransfer')->where($map)->cursor() as $vo) try { foreach (DataUserTransfer::mk()->where($map)->cursor() as $vo) try {
$this->queue->message($total, ++$count, "开始处理订单 {$vo['code']} 提现"); $this->queue->message($total, ++$count, "开始处理订单 {$vo['code']} 提现");
if ($vo['status'] === 3) { if ($vo['status'] === 3) {
$this->queue->message($total, $count, "尝试处理订单 {$vo['code']} 打款", 1); $this->queue->message($total, $count, "尝试处理订单 {$vo['code']} 打款", 1);
@ -52,7 +53,7 @@ class UserTransfer extends Command
[$config, $result] = $this->createTransferWallet($vo); [$config, $result] = $this->createTransferWallet($vo);
} }
if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') { if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') {
$this->app->db->name('DataUserTransfer')->where(['code' => $vo['code']])->update([ DataUserTransfer::mk()->where(['code' => $vo['code']])->update([
'status' => 4, 'status' => 4,
'appid' => $config['appid'], 'appid' => $config['appid'],
'openid' => $config['openid'], 'openid' => $config['openid'],
@ -62,7 +63,7 @@ class UserTransfer extends Command
'change_desc' => '创建微信提现成功', 'change_desc' => '创建微信提现成功',
]); ]);
} else { } else {
$this->app->db->name('DataUserTransfer')->where(['code' => $vo['code']])->update([ DataUserTransfer::mk()->where(['code' => $vo['code']])->update([
'change_time' => date('Y-m-d H:i:s'), 'change_desc' => $result['err_code_des'] ?? '线上提现失败', 'change_time' => date('Y-m-d H:i:s'), 'change_desc' => $result['err_code_des'] ?? '线上提现失败',
]); ]);
} }
@ -77,7 +78,7 @@ class UserTransfer extends Command
} catch (\Exception $exception) { } catch (\Exception $exception) {
$error++; $error++;
$this->queue->message($total, $count, "处理提现订单 {$vo['code']} 失败, {$exception->getMessage()}", 1); $this->queue->message($total, $count, "处理提现订单 {$vo['code']} 失败, {$exception->getMessage()}", 1);
$this->app->db->name('DataUserTransfer')->where(['code' => $vo['code']])->update([ DataUserTransfer::mk()->where(['code' => $vo['code']])->update([
'change_time' => date('Y-m-d H:i:s'), 'change_desc' => $exception->getMessage(), 'change_time' => date('Y-m-d H:i:s'), 'change_desc' => $exception->getMessage(),
]); ]);
} }
@ -217,7 +218,7 @@ class UserTransfer extends Command
$result = TransfersBank::instance($config)->query($item['trade_no']); $result = TransfersBank::instance($config)->query($item['trade_no']);
if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') { if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') {
if ($result['status'] === 'SUCCESS') { if ($result['status'] === 'SUCCESS') {
$this->app->db->name('DataUserTransfer')->where(['code' => $item['code']])->update([ DataUserTransfer::mk()->where(['code' => $item['code']])->update([
'status' => 5, 'status' => 5,
'appid' => $config['appid'], 'appid' => $config['appid'],
'openid' => $config['openid'], 'openid' => $config['openid'],
@ -227,7 +228,7 @@ class UserTransfer extends Command
]); ]);
} }
if (in_array($result['status'], ['FAILED', 'BANK_FAIL'])) { if (in_array($result['status'], ['FAILED', 'BANK_FAIL'])) {
$this->app->db->name('DataUserTransfer')->where(['code' => $item['code']])->update([ DataUserTransfer::mk()->where(['code' => $item['code']])->update([
'status' => 0, 'status' => 0,
'change_time' => date('Y-m-d H:i:s'), 'change_time' => date('Y-m-d H:i:s'),
'change_desc' => '微信提现打款失败', 'change_desc' => '微信提现打款失败',
@ -254,7 +255,7 @@ class UserTransfer extends Command
[$config['appid'], $config['openid']] = [$item['appid'], $item['openid']]; [$config['appid'], $config['openid']] = [$item['appid'], $item['openid']];
$result = Transfers::instance($config)->query($item['trade_no']); $result = Transfers::instance($config)->query($item['trade_no']);
if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') { if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') {
$this->app->db->name('DataUserTransfer')->where(['code' => $item['code']])->update([ DataUserTransfer::mk()->where(['code' => $item['code']])->update([
'status' => 5, 'status' => 5,
'appid' => $config['appid'], 'appid' => $config['appid'],
'openid' => $config['openid'], 'openid' => $config['openid'],

View File

@ -2,6 +2,7 @@
namespace app\data\command; namespace app\data\command;
use app\data\model\DataUser;
use app\data\service\UserUpgradeService; use app\data\service\UserUpgradeService;
use think\admin\Command; use think\admin\Command;
use think\admin\Exception; use think\admin\Exception;
@ -30,8 +31,8 @@ class UserUpgrade extends Command
protected function execute(Input $input, Output $output) protected function execute(Input $input, Output $output)
{ {
try { try {
[$total, $count] = [$this->app->db->name('DataUser')->count(), 0]; [$total, $count] = [DataUser::mk()->count(), 0];
foreach ($this->app->db->name('DataUser')->field('id')->cursor() as $user) { foreach (DataUser::mk()->field('id')->cursor() as $user) {
$this->queue->message($total, ++$count, "正在计算用户 [{$user['id']}] 的等级"); $this->queue->message($total, ++$count, "正在计算用户 [{$user['id']}] 的等级");
UserUpgradeService::instance()->upgrade($user['id']); UserUpgradeService::instance()->upgrade($user['id']);
$this->queue->message($total, $count, "完成计算用户 [{$user['id']}] 的等级", 1); $this->queue->message($total, $count, "完成计算用户 [{$user['id']}] 的等级", 1);

View File

@ -57,5 +57,4 @@ class Goods extends Controller
{ {
$this->success('获取区域成功', ExpressService::instance()->region(3, 1)); $this->success('获取区域成功', ExpressService::instance()->region(3, 1));
} }
} }

View File

@ -6,6 +6,8 @@ use app\data\service\payment\AlipayPaymentService;
use app\data\service\payment\JoinpayPaymentService; use app\data\service\payment\JoinpayPaymentService;
use app\data\service\payment\WechatPaymentService; use app\data\service\payment\WechatPaymentService;
use think\admin\Controller; use think\admin\Controller;
use think\admin\Exception;
use WeChat\Exceptions\InvalidResponseException;
/** /**
* 异步通知处理 * 异步通知处理

View File

@ -5,6 +5,7 @@ namespace app\data\controller\api;
use app\data\service\UserAdminService; use app\data\service\UserAdminService;
use app\wechat\service\WechatService; use app\wechat\service\WechatService;
use think\admin\Controller; use think\admin\Controller;
use think\admin\Exception;
use think\Response; use think\Response;
/** /**
@ -64,7 +65,7 @@ class Wechat extends Controller
/** /**
* 加载网页授权数据 * 加载网页授权数据
* @return \think\Response * @return Response
* @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException * @throws \WeChat\Exceptions\LocalCacheException
* @throws \think\admin\Exception * @throws \think\admin\Exception

View File

@ -72,7 +72,8 @@ class Wxapp extends Controller
/** /**
* 小程序数据解密 * 小程序数据解密
* @throws HttpResponseException * @throws \think\admin\Exception
* @throws \think\db\exception\DbException
*/ */
public function decode() public function decode()
{ {
@ -106,6 +107,7 @@ class Wxapp extends Controller
* 授权CODE换取会话信息 * 授权CODE换取会话信息
* @param string $code 换取授权CODE * @param string $code 换取授权CODE
* @return array [openid, sessionkey] * @return array [openid, sessionkey]
* @throws \WeChat\Exceptions\LocalCacheException
*/ */
private function _getSessionKey(string $code): array private function _getSessionKey(string $code): array
{ {

View File

@ -3,6 +3,7 @@
namespace app\data\controller\api\auth; namespace app\data\controller\api\auth;
use app\data\controller\api\Auth; use app\data\controller\api\Auth;
use app\data\model\DataUserAddress;
use think\admin\extend\CodeExtend; use think\admin\extend\CodeExtend;
/** /**
@ -12,15 +13,11 @@ use think\admin\extend\CodeExtend;
*/ */
class Address extends Auth class Address extends Auth
{ {
/**
* 绑定数据表
* @var string
*/
private $table = 'DataUserAddress';
/** /**
* 添加收货地址 * 添加收货地址
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/ */
public function set() public function set()
{ {
@ -43,22 +40,22 @@ class Address extends Auth
]); ]);
if (empty($data['code'])) { if (empty($data['code'])) {
unset($data['code']); unset($data['code']);
$count = $this->app->db->name($this->table)->where($data)->count(); $count = DataUserAddress::mk()->where($data)->count();
if ($count > 0) $this->error('抱歉,该地址已经存在!'); if ($count > 0) $this->error('抱歉,该地址已经存在!');
$data['code'] = CodeExtend::uniqidDate(20, 'A'); $data['code'] = CodeExtend::uniqidDate(20, 'A');
if ($this->app->db->name($this->table)->insert($data) === false) { if (DataUserAddress::mk()->insert($data) === false) {
$this->error('添加地址失败!'); $this->error('添加地址失败!');
} }
} else { } else {
$map = ['uuid' => $this->uuid, 'code' => $data['code']]; $map = ['uuid' => $this->uuid, 'code' => $data['code']];
$address = $this->app->db->name($this->table)->where($map)->find(); $address = DataUserAddress::mk()->where($map)->find();
if (empty($address)) $this->error('修改地址不存在!'); if (empty($address)) $this->error('修改地址不存在!');
$this->app->db->name($this->table)->where($map)->update($data); DataUserAddress::mk()->where($map)->update($data);
} }
// 去除其它默认选项 // 去除其它默认选项
if (isset($data['type']) && $data['type'] > 0) { if (isset($data['type']) && $data['type'] > 0) {
$map = [['uuid', '=', $this->uuid], ['code', '<>', $data['code']]]; $map = [['uuid', '=', $this->uuid], ['code', '<>', $data['code']]];
$this->app->db->name($this->table)->where($map)->update(['type' => 0]); DataUserAddress::mk()->where($map)->update(['type' => 0]);
} }
$this->success('地址保存成功!', $this->_getAddress($data['code'])); $this->success('地址保存成功!', $this->_getAddress($data['code']));
} }
@ -71,7 +68,7 @@ class Address extends Auth
*/ */
public function get() public function get()
{ {
$query = $this->_query($this->table)->withoutField('deleted'); $query = $this->_query('DataUserAddress')->withoutField('deleted');
$query->equal('code')->where(['uuid' => $this->uuid, 'deleted' => 0]); $query->equal('code')->where(['uuid' => $this->uuid, 'deleted' => 0]);
$result = $query->order('type desc,id desc')->page(false, false, false, 15); $result = $query->order('type desc,id desc')->page(false, false, false, 15);
$this->success('获取地址数据!', $result); $this->success('获取地址数据!', $result);
@ -79,7 +76,9 @@ class Address extends Auth
/** /**
* 修改地址状态 * 修改地址状态
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/ */
public function state() public function state()
{ {
@ -91,32 +90,34 @@ class Address extends Auth
]); ]);
// 检查地址是否存在 // 检查地址是否存在
$map = ['uuid' => $data['uuid'], 'code' => $data['code']]; $map = ['uuid' => $data['uuid'], 'code' => $data['code']];
if ($this->app->db->name($this->table)->where($map)->count() < 1) { if (DataUserAddress::mk()->where($map)->count() < 1) {
$this->error('修改的地址不存在!'); $this->error('修改的地址不存在!');
} }
// 更新默认地址状态 // 更新默认地址状态
$data['type'] = intval($data['type']); $data['type'] = intval($data['type']);
$this->app->db->name($this->table)->where($map)->update(['type' => $data['type']]); DataUserAddress::mk()->where($map)->update(['type' => $data['type']]);
// 去除其它默认选项 // 去除其它默认选项
if ($data['type'] > 0) { if ($data['type'] > 0) {
$map = [['uuid', '=', $this->uuid], ['code', '<>', $data['code']]]; $map = [['uuid', '=', $this->uuid], ['code', '<>', $data['code']]];
$this->app->db->name($this->table)->where($map)->update(['type' => 0]); DataUserAddress::mk()->where($map)->update(['type' => 0]);
} }
$this->success('默认设置成功!', $this->_getAddress($data['code'])); $this->success('默认设置成功!', $this->_getAddress($data['code']));
} }
/** /**
* 删除收货地址 * 删除收货地址
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/ */
public function remove() public function remove()
{ {
$map = $this->_vali([ $map = $this->_vali([
'uuid.value' => $this->uuid, 'code.require' => '地址编号不能为空!', 'uuid.value' => $this->uuid, 'code.require' => '地址编号不能为空!',
]); ]);
$address = $this->app->db->name($this->table)->where($map)->find(); $address = DataUserAddress::mk()->where($map)->find();
if (empty($address)) $this->error('需要删除的地址不存在!'); if (empty($address)) $this->error('需要删除的地址不存在!');
if ($this->app->db->name($this->table)->where($map)->update(['deleted' => 1]) !== false) { if (DataUserAddress::mk()->where($map)->update(['deleted' => 1]) !== false) {
$this->success('删除地址成功!'); $this->success('删除地址成功!');
} else { } else {
$this->error('删除地址失败!'); $this->error('删除地址失败!');
@ -134,7 +135,7 @@ class Address extends Auth
private function _getAddress(string $code): ?array private function _getAddress(string $code): ?array
{ {
$map = ['code' => $code, 'uuid' => $this->uuid, 'deleted' => 0]; $map = ['code' => $code, 'uuid' => $this->uuid, 'deleted' => 0];
return $this->app->db->name($this->table)->withoutField('deleted')->where($map)->find(); return DataUserAddress::mk()->withoutField('deleted')->where($map)->find();
} }
} }

View File

@ -141,7 +141,6 @@ class Center extends Auth
/** /**
* 绑定用户邀请人 * 绑定用户邀请人
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException

View File

@ -116,7 +116,9 @@ class News extends Auth
/** /**
* 获取用户收藏的资讯 * 获取用户收藏的资讯
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/ */
public function getCollect() public function getCollect()
{ {
@ -171,7 +173,9 @@ class News extends Auth
/** /**
* 获取用户收藏的资讯 * 获取用户收藏的资讯
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/ */
public function getLike() public function getLike()
{ {

View File

@ -3,6 +3,9 @@
namespace app\data\controller\api\auth; namespace app\data\controller\api\auth;
use app\data\controller\api\Auth; use app\data\controller\api\Auth;
use app\data\model\DataUserAddress;
use app\data\model\ShopOrder;
use app\data\model\ShopOrderItem;
use app\data\service\ExpressService; use app\data\service\ExpressService;
use app\data\service\GoodsService; use app\data\service\GoodsService;
use app\data\service\OrderService; use app\data\service\OrderService;
@ -38,7 +41,7 @@ class Order extends Auth
public function get() public function get()
{ {
$map = ['uuid' => $this->uuid, 'deleted_status' => 0]; $map = ['uuid' => $this->uuid, 'deleted_status' => 0];
$query = $this->_query('ShopOrder')->in('status')->equal('order_no'); $query = $this->_query(ShopOrder::class)->in('status')->equal('order_no');
$result = $query->where($map)->order('id desc')->page(true, false, false, 20); $result = $query->where($map)->order('id desc')->page(true, false, false, 20);
if (count($result['list']) > 0) OrderService::instance()->buildData($result['list']); if (count($result['list']) > 0) OrderService::instance()->buildData($result['list']);
$this->success('获取订单数据成功!', $result); $this->success('获取订单数据成功!', $result);
@ -82,7 +85,7 @@ class Order extends Auth
// 限制购买数量 // 限制购买数量
if (isset($goods['limit_max_num']) && $goods['limit_max_num'] > 0) { if (isset($goods['limit_max_num']) && $goods['limit_max_num'] > 0) {
$map = [['a.uuid', '=', $this->uuid], ['a.status', 'in', [2, 3, 4, 5]], ['b.goods_code', '=', $goods['code']]]; $map = [['a.uuid', '=', $this->uuid], ['a.status', 'in', [2, 3, 4, 5]], ['b.goods_code', '=', $goods['code']]];
$buys = $this->app->db->name('ShopOrderr')->alias('a')->join('store_order_item b', 'a.order_no=b.order_no')->where($map)->sum('b.stock_sales'); $buys = ShopOrder::mk()->alias('a')->join('store_order_item b', 'a.order_no=b.order_no')->where($map)->sum('b.stock_sales');
if ($buys + $count > $goods['limit_max_num']) $this->error('超过限购数量'); if ($buys + $count > $goods['limit_max_num']) $this->error('超过限购数量');
} }
// 限制购买身份 // 限制购买身份
@ -166,8 +169,8 @@ class Order extends Auth
$order['amount_total'] = $order['amount_goods']; $order['amount_total'] = $order['amount_goods'];
// 写入商品数据 // 写入商品数据
$this->app->db->transaction(function () use ($order, $items) { $this->app->db->transaction(function () use ($order, $items) {
$this->app->db->name('ShopOrder')->insert($order); ShopOrder::mk()->insert($order);
$this->app->db->name('ShopOrderItem')->insertAll($items); ShopOrderItem::mk()->insertAll($items);
}); });
// 同步商品库存销量 // 同步商品库存销量
foreach (array_unique(array_column($items, 'goods_code')) as $code) { foreach (array_unique(array_column($items, 'goods_code')) as $code) {
@ -211,14 +214,14 @@ class Order extends Auth
]); ]);
// 用户收货地址 // 用户收货地址
$map = ['uuid' => $this->uuid, 'code' => $data['code']]; $map = ['uuid' => $this->uuid, 'code' => $data['code']];
$addr = $this->app->db->name('DataUserAddress')->where($map)->find(); $addr = DataUserAddress::mk()->where($map)->find();
if (empty($addr)) $this->error('收货地址异常'); if (empty($addr)) $this->error('收货地址异常');
// 订单状态检查 // 订单状态检查
$map = ['uuid' => $this->uuid, 'order_no' => $data['order_no']]; $map = ['uuid' => $this->uuid, 'order_no' => $data['order_no']];
$tCount = $this->app->db->name('ShopOrderItem')->where($map)->sum('truck_number'); $tCount = ShopOrderItem::mk()->where($map)->sum('truck_number');
// 根据地址计算运费 // 根据地址计算运费
$map = ['status' => 1, 'deleted' => 0, 'order_no' => $data['order_no']]; $map = ['status' => 1, 'deleted' => 0, 'order_no' => $data['order_no']];
$tCode = $this->app->db->name('ShopOrderItem')->where($map)->column('truck_code'); $tCode = ShopOrderItem::mk()->where($map)->column('truck_code');
[$amount, , , $remark] = ExpressService::instance()->amount($tCode, $addr['province'], $addr['city'], $tCount); [$amount, , , $remark] = ExpressService::instance()->amount($tCode, $addr['province'], $addr['city'], $tCount);
$this->success('计算运费成功', ['amount' => $amount, 'remark' => $remark]); $this->success('计算运费成功', ['amount' => $amount, 'remark' => $remark]);
} }
@ -238,17 +241,17 @@ class Order extends Auth
]); ]);
// 用户收货地址 // 用户收货地址
$map = ['uuid' => $this->uuid, 'code' => $data['code'], 'deleted' => 0]; $map = ['uuid' => $this->uuid, 'code' => $data['code'], 'deleted' => 0];
$addr = $this->app->db->name('DataUserAddress')->where($map)->find(); $addr = DataUserAddress::mk()->where($map)->find();
if (empty($addr)) $this->error('收货地址异常'); if (empty($addr)) $this->error('收货地址异常');
// 订单状态检查 // 订单状态检查
$map1 = ['uuid' => $this->uuid, 'order_no' => $data['order_no']]; $map1 = ['uuid' => $this->uuid, 'order_no' => $data['order_no']];
$order = $this->app->db->name('ShopOrder')->where($map1)->whereIn('status', [1, 2])->find(); $order = ShopOrder::mk()->where($map1)->whereIn('status', [1, 2])->find();
if (empty($order)) $this->error('不能修改地址'); if (empty($order)) $this->error('不能修改地址');
if (empty($order['truck_type'])) $this->success('无需快递配送', ['order_no' => $order['order_no']]); if (empty($order['truck_type'])) $this->success('无需快递配送', ['order_no' => $order['order_no']]);
// 根据地址计算运费 // 根据地址计算运费
$map2 = ['status' => 1, 'deleted' => 0, 'order_no' => $data['order_no']]; $map2 = ['status' => 1, 'deleted' => 0, 'order_no' => $data['order_no']];
$tCount = $this->app->db->name('ShopOrderItem')->where($map1)->sum('truck_number'); $tCount = ShopOrderItem::mk()->where($map1)->sum('truck_number');
$tCodes = $this->app->db->name('ShopOrderItem')->where($map2)->column('truck_code'); $tCodes = ShopOrderItem::mk()->where($map2)->column('truck_code');
[$amount, $tCount, $tCode, $remark] = ExpressService::instance()->amount($tCodes, $addr['province'], $addr['city'], $tCount); [$amount, $tCount, $tCode, $remark] = ExpressService::instance()->amount($tCodes, $addr['province'], $addr['city'], $tCount);
// 创建订单发货信息 // 创建订单发货信息
$express = [ $express = [
@ -283,7 +286,7 @@ class Order extends Auth
if ($update['amount_total'] <= 0) $update['amount_total'] = 0.00; if ($update['amount_total'] <= 0) $update['amount_total'] = 0.00;
// 更新用户订单数据 // 更新用户订单数据
$map = ['uuid' => $this->uuid, 'order_no' => $data['order_no']]; $map = ['uuid' => $this->uuid, 'order_no' => $data['order_no']];
if ($this->app->db->name('ShopOrder')->where($map)->update($update) !== false) { if (ShopOrder::mk()->where($map)->update($update) !== false) {
// 触发订单确认事件 // 触发订单确认事件
$this->app->event->trigger('ShopOrderPerfect', $order['order_no']); $this->app->event->trigger('ShopOrderPerfect', $order['order_no']);
// 返回处理成功数据 // 返回处理成功数据
@ -299,7 +302,7 @@ class Order extends Auth
public function channel() public function channel()
{ {
$data = $this->_vali(['uuid.value' => $this->uuid, 'order_no.require' => '单号不能为空']); $data = $this->_vali(['uuid.value' => $this->uuid, 'order_no.require' => '单号不能为空']);
$payments = $this->app->db->name('ShopOrder')->where($data)->value('payment_allow'); $payments = ShopOrder::mk()->where($data)->value('payment_allow');
if (empty($payments)) $this->error('获取订单支付参数失败'); if (empty($payments)) $this->error('获取订单支付参数失败');
// 读取支付通道配置 // 读取支付通道配置
$query = $this->app->db->name('BaseUserPayment')->where(['status' => 1, 'deleted' => 0]); $query = $this->app->db->name('BaseUserPayment')->where(['status' => 1, 'deleted' => 0]);
@ -311,9 +314,7 @@ class Order extends Auth
/** /**
* 获取订单支付状态 * 获取订单支付状态
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/ */
public function payment() public function payment()
{ {
@ -330,7 +331,7 @@ class Order extends Auth
if ($order['payment_status'] > 0) $this->error('已经完成支付'); if ($order['payment_status'] > 0) $this->error('已经完成支付');
// 更新订单备注 // 更新订单备注
if (!empty($data['order_remark'])) { if (!empty($data['order_remark'])) {
$this->app->db->name('ShopOrder')->where($map)->update([ ShopOrder::mk()->where($map)->update([
'order_remark' => $data['order_remark'], 'order_remark' => $data['order_remark'],
]); ]);
} }
@ -344,7 +345,7 @@ class Order extends Auth
// 返回订单数据及支付发起参数 // 返回订单数据及支付发起参数
$type = $order['amount_real'] <= 0 ? 'empty' : $data['payment_code']; $type = $order['amount_real'] <= 0 ? 'empty' : $data['payment_code'];
$param = PaymentService::instance($type)->create($openid, $order['order_no'], $order['amount_real'], '商城订单支付', '', $data['payment_back'], $data['payment_image']); $param = PaymentService::instance($type)->create($openid, $order['order_no'], $order['amount_real'], '商城订单支付', '', $data['payment_back'], $data['payment_image']);
$this->success('获取支付参数', ['order' => $this->app->db->name('ShopOrder')->where($map)->find() ?: new \stdClass(), 'param' => $param]); $this->success('获取支付参数', ['order' => ShopOrder::mk()->where($map)->find() ?: new \stdClass(), 'param' => $param]);
} catch (HttpResponseException $exception) { } catch (HttpResponseException $exception) {
throw $exception; throw $exception;
} catch (\Exception $exception) { } catch (\Exception $exception) {
@ -362,7 +363,7 @@ class Order extends Auth
{ {
[$map, $order] = $this->getOrderData(); [$map, $order] = $this->getOrderData();
if (in_array($order['status'], [1, 2, 3])) { if (in_array($order['status'], [1, 2, 3])) {
$result = $this->app->db->name('ShopOrder')->where($map)->update([ $result = ShopOrder::mk()->where($map)->update([
'status' => 0, 'status' => 0,
'cancel_status' => 1, 'cancel_status' => 1,
'cancel_remark' => '用户主动取消订单', 'cancel_remark' => '用户主动取消订单',
@ -383,16 +384,14 @@ class Order extends Auth
/** /**
* 用户主动删除已取消的订单 * 用户主动删除已取消的订单
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/ */
public function remove() public function remove()
{ {
[$map, $order] = $this->getOrderData(); [$map, $order] = $this->getOrderData();
if (empty($order)) $this->error('读取订单失败'); if (empty($order)) $this->error('读取订单失败');
if (in_array($order['status'], [0])) { if (in_array($order['status'], [0])) {
$result = $this->app->db->name('ShopOrder')->where($map)->update([ $result = ShopOrder::mk()->where($map)->update([
'status' => 0, 'status' => 0,
'deleted_status' => 1, 'deleted_status' => 1,
'deleted_remark' => '用户主动删除订单', 'deleted_remark' => '用户主动删除订单',
@ -413,15 +412,13 @@ class Order extends Auth
/** /**
* 订单确认收货 * 订单确认收货
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/ */
public function confirm() public function confirm()
{ {
[$map, $order] = $this->getOrderData(); [$map, $order] = $this->getOrderData();
if (in_array($order['status'], [5])) { if (in_array($order['status'], [5])) {
if ($this->app->db->name('ShopOrder')->where($map)->update(['status' => 6]) !== false) { if (ShopOrder::mk()->where($map)->update(['status' => 6]) !== false) {
// 触发订单确认事件 // 触发订单确认事件
$this->app->event->trigger('ShopOrderConfirm', $order['order_no']); $this->app->event->trigger('ShopOrderConfirm', $order['order_no']);
// 返回处理成功数据 // 返回处理成功数据
@ -443,8 +440,11 @@ class Order extends Auth
*/ */
private function getOrderData(): array private function getOrderData(): array
{ {
$map = $this->_vali(['uuid.value' => $this->uuid, 'order_no.require' => '单号不能为空']); $map = $this->_vali([
$order = $this->app->db->name('ShopOrder')->where($map)->find(); 'uuid.value' => $this->uuid,
'order_no.require' => '单号不能为空',
]);
$order = ShopOrder::mk()->where($map)->find();
if (empty($order)) $this->error('读取订单失败'); if (empty($order)) $this->error('读取订单失败');
return [$map, $order]; return [$map, $order];
} }
@ -455,7 +455,7 @@ class Order extends Auth
public function total() public function total()
{ {
$data = ['t0' => 0, 't1' => 0, 't2' => 0, 't3' => 0, 't4' => 0, 't5' => 0, 't6' => 0]; $data = ['t0' => 0, 't1' => 0, 't2' => 0, 't3' => 0, 't4' => 0, 't5' => 0, 't6' => 0];
$query = $this->app->db->name('ShopOrder')->where(['uuid' => $this->uuid, 'deleted_status' => 0]); $query = ShopOrder::mk()->where(['uuid' => $this->uuid, 'deleted_status' => 0]);
foreach ($query->field('status,count(1) count')->group('status')->cursor() as $item) { foreach ($query->field('status,count(1) count')->group('status')->cursor() as $item) {
$data["t{$item['status']}"] = $item['count']; $data["t{$item['status']}"] = $item['count'];
} }

View File

@ -4,6 +4,9 @@ namespace app\data\controller\api\auth;
use app\data\controller\api\Auth; use app\data\controller\api\Auth;
use app\data\service\RebateService; use app\data\service\RebateService;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/** /**
* 用户返利管理 * 用户返利管理
@ -12,27 +15,21 @@ use app\data\service\RebateService;
*/ */
class Rebate extends Auth class Rebate extends Auth
{ {
/**
* 绑定数据表
* @var string
*/
private $table = 'DataUserRebate';
/** /**
* 获取用户返利记录 * 获取用户返利记录
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public function get() public function get()
{ {
$date = trim(input('date', date('Y-m')), '-'); $date = trim(input('date', date('Y-m')), '-');
[$map, $year] = [['uuid' => $this->uuid], substr($date, 0, 4)]; [$map, $year] = [['uuid' => $this->uuid], substr($date, 0, 4)];
$query = $this->_query($this->table)->where($map)->equal('type,status')->whereLike('date', "{$date}%"); $query = $this->_query('DataUserRebate')->where($map)->equal('type,status')->whereLike('date', "{$date}%");
$this->success('获取返利统计', array_merge($query->order('id desc')->page(true, false, false, 10), [ $this->success('获取返利统计', array_merge($query->order('id desc')->page(true, false, false, 10), [
'total' => [ 'total' => [
'年度' => $this->_query($this->table)->where($map)->equal('type,status')->whereLike('date', "{$year}%")->db()->sum('amount'), '年度' => $this->_query('DataUserRebate')->where($map)->equal('type,status')->whereLike('date', "{$year}%")->db()->sum('amount'),
'月度' => $this->_query($this->table)->where($map)->equal('type,status')->whereLike('date', "{$date}%")->db()->sum('amount'), '月度' => $this->_query('DataUserRebate')->where($map)->equal('type,status')->whereLike('date', "{$date}%")->db()->sum('amount'),
], ],
])); ]));
} }
@ -43,7 +40,7 @@ class Rebate extends Auth
public function prize() public function prize()
{ {
[$map, $data] = [['number' => $this->user['vip_code']], []]; [$map, $data] = [['number' => $this->user['vip_code']], []];
$prizes = $this->app->db->name($this->table)->group('name')->column('name'); $prizes = $this->app->db->name('DataUserRebate')->group('name')->column('name');
$rebate = $this->app->db->name('BaseUserUpgrade')->where($map)->value('rebate_rule', ''); $rebate = $this->app->db->name('BaseUserUpgrade')->where($map)->value('rebate_rule', '');
$codemap = array_merge($prizes, str2arr($rebate)); $codemap = array_merge($prizes, str2arr($rebate));
foreach (RebateService::PRIZES as $prize) { foreach (RebateService::PRIZES as $prize) {

View File

@ -3,6 +3,7 @@
namespace app\data\controller\api\auth; namespace app\data\controller\api\auth;
use app\data\controller\api\Auth; use app\data\controller\api\Auth;
use app\data\model\DataUserTransfer;
use app\data\service\UserRebateService; use app\data\service\UserRebateService;
use app\data\service\UserTransferService; use app\data\service\UserTransferService;
use think\admin\extend\CodeExtend; use think\admin\extend\CodeExtend;
@ -14,12 +15,6 @@ use think\admin\extend\CodeExtend;
*/ */
class Transfer extends Auth class Transfer extends Auth
{ {
/**
* 绑定数据表
* @var string
*/
private $table = 'DataUserTransfer';
/** /**
* 提交提现处理 * 提交提现处理
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
@ -84,7 +79,7 @@ class Transfer extends Auth
} }
// 当日提现次数限制 // 当日提现次数限制
$map = ['uuid' => $this->uuid, 'type' => $data['type'], 'date' => $data['date']]; $map = ['uuid' => $this->uuid, 'type' => $data['type'], 'date' => $data['date']];
$count = $this->app->db->name($this->table)->where($map)->count(); $count = DataUserTransfer::mk()->where($map)->count();
if ($count >= $transfers[$data['type']]['dayNumber']) $this->error("当日提现次数受限"); if ($count >= $transfers[$data['type']]['dayNumber']) $this->error("当日提现次数受限");
// 提现金额范围控制 // 提现金额范围控制
if ($transfers[$data['type']]['minAmount'] > $data['amount']) { if ($transfers[$data['type']]['minAmount'] > $data['amount']) {
@ -94,7 +89,7 @@ class Transfer extends Auth
$this->error("不能大于{$transfers[$data['type']]['minAmount']}"); $this->error("不能大于{$transfers[$data['type']]['minAmount']}");
} }
// 写入用户提现数据 // 写入用户提现数据
if ($this->app->db->name($this->table)->insert($data) !== false) { if (DataUserTransfer::mk()->insert($data) !== false) {
UserRebateService::instance()->amount($this->uuid); UserRebateService::instance()->amount($this->uuid);
$this->success('提现申请成功'); $this->success('提现申请成功');
} else { } else {
@ -110,7 +105,7 @@ class Transfer extends Auth
*/ */
public function get() public function get()
{ {
$query = $this->_query($this->table)->where(['uuid' => $this->uuid]); $query = $this->_query(DataUserTransfer::mk())->where(['uuid' => $this->uuid]);
$result = $query->like('date,code')->in('status')->order('id desc')->page(true, false, false, 10); $result = $query->like('date,code')->in('status')->order('id desc')->page(true, false, false, 10);
// 统计历史数据 // 统计历史数据
$map = [['uuid', '=', $this->uuid], ['status', '>', 0]]; $map = [['uuid', '=', $this->uuid], ['status', '>', 0]];
@ -119,21 +114,20 @@ class Transfer extends Auth
'total' => [ 'total' => [
'锁定' => $locks, '锁定' => $locks,
'可提' => $total - $count, '可提' => $total - $count,
'上月' => $this->app->db->name($this->table)->where($map)->whereLike('date', date("Y-m-%", strtotime('-1 month')))->sum('amount'), '上月' => DataUserTransfer::mk()->where($map)->whereLike('date', date("Y-m-%", strtotime('-1 month')))->sum('amount'),
'本月' => $this->app->db->name($this->table)->where($map)->whereLike('date', date("Y-m-%"))->sum('amount'), '本月' => DataUserTransfer::mk()->where($map)->whereLike('date', date("Y-m-%"))->sum('amount'),
'全年' => $this->app->db->name($this->table)->where($map)->whereLike('date', date("Y-%"))->sum('amount'), '全年' => DataUserTransfer::mk()->where($map)->whereLike('date', date("Y-%"))->sum('amount'),
], ],
])); ]));
} }
/** /**
* 用户取消提现 * 用户取消提现
* @throws \think\db\exception\DbException
*/ */
public function cancel() public function cancel()
{ {
$data = $this->_vali(['uuid.value' => $this->uuid, 'code.require' => '单号不能为空!']); $data = $this->_vali(['uuid.value' => $this->uuid, 'code.require' => '单号不能为空!']);
$this->app->db->name($this->table)->where($data)->whereIn('status', [1, 2, 3])->update([ DataUserTransfer::mk()->where($data)->whereIn('status', [1, 2, 3])->update([
'status' => 0, 'change_time' => date("Y-m-d H:i:s"), 'change_desc' => '用户主动取消提现', 'status' => 0, 'change_time' => date("Y-m-d H:i:s"), 'change_desc' => '用户主动取消提现',
]); ]);
UserRebateService::instance()->amount($this->uuid); UserRebateService::instance()->amount($this->uuid);
@ -142,12 +136,11 @@ class Transfer extends Auth
/** /**
* 用户确认提现 * 用户确认提现
* @throws \think\db\exception\DbException
*/ */
public function confirm() public function confirm()
{ {
$data = $this->_vali(['uuid.value' => $this->uuid, 'code.require' => '单号不能为空!']); $data = $this->_vali(['uuid.value' => $this->uuid, 'code.require' => '单号不能为空!']);
$this->app->db->name($this->table)->where($data)->whereIn('status', [4])->update([ DataUserTransfer::mk()->where($data)->whereIn('status', [4])->update([
'status' => 5, 'change_time' => date("Y-m-d H:i:s"), 'change_desc' => '用户主动确认收款', 'status' => 5, 'change_time' => date("Y-m-d H:i:s"), 'change_desc' => '用户主动确认收款',
]); ]);
UserRebateService::instance()->amount($this->uuid); UserRebateService::instance()->amount($this->uuid);

View File

@ -4,7 +4,6 @@ namespace app\data\controller\base\postage;
use app\data\service\ExpressService; use app\data\service\ExpressService;
use think\admin\Controller; use think\admin\Controller;
use think\admin\service\SystemService;
use think\exception\HttpResponseException; use think\exception\HttpResponseException;
/** /**
@ -99,7 +98,7 @@ class Company extends Controller
try { try {
$result = ExpressService::instance()->company(); $result = ExpressService::instance()->company();
if (empty($result['code'])) $this->error($result['info']); if (empty($result['code'])) $this->error($result['info']);
foreach ($result['data'] as $vo) SystemService::instance()->save($this->table, [ foreach ($result['data'] as $vo) data_save($this->table, [
'code_1' => $vo['code_1'], 'code_2' => $vo['code_2'], 'code_1' => $vo['code_1'], 'code_2' => $vo['code_2'],
'code_3' => $vo['code_3'], 'name' => $vo['title'], 'deleted' => 0, 'code_3' => $vo['code_3'], 'name' => $vo['title'], 'deleted' => 0,
], 'code_1'); ], 'code_1');

View File

@ -0,0 +1,15 @@
<?php
namespace app\data\model;
use think\admin\Model;
/**
* 用户数据模型
* Class DataUser
* @package app\data\model
*/
class DataUser extends Model
{
}

View File

@ -0,0 +1,15 @@
<?php
namespace app\data\model;
use think\admin\Model;
/**
* 用户地址模型
* Class DataUserAddress
* @package app\data\model
*/
class DataUserAddress extends Model
{
}

View File

@ -0,0 +1,15 @@
<?php
namespace app\data\model;
use think\admin\Model;
/**
* 用户余额模型
* Class DataUserBalance
* @package app\data\model
*/
class DataUserBalance extends Model
{
}

View File

@ -0,0 +1,15 @@
<?php
namespace app\data\model;
use think\admin\Model;
/**
* 用户消息模型
* Class DataUserMessage
* @package app\data\model
*/
class DataUserMessage extends Model
{
}

View File

@ -0,0 +1,15 @@
<?php
namespace app\data\model;
use think\admin\Model;
/**
* 用户支付模型
* Class DataUserPayment
* @package app\data\model
*/
class DataUserPayment extends Model
{
}

View File

@ -0,0 +1,15 @@
<?php
namespace app\data\model;
use think\admin\Model;
/**
* 用户返利模型
* Class DataUserRebate
* @package app\data\model
*/
class DataUserRebate extends Model
{
}

View File

@ -0,0 +1,15 @@
<?php
namespace app\data\model;
use think\admin\Model;
/**
* 用户令牌模型
* Class DataUserToken
* @package app\data\model
*/
class DataUserToken extends Model
{
}

View File

@ -0,0 +1,15 @@
<?php
namespace app\data\model;
use think\admin\Model;
/**
* 用户提现模型
* Class DataUserTransfer
* @package app\data\model
*/
class DataUserTransfer extends Model
{
}

View File

@ -0,0 +1,15 @@
<?php
namespace app\data\model;
use think\admin\Model;
/**
* 商城订单主模型
* Class ShopOrder
* @package app\data\model
*/
class ShopOrder extends Model
{
}

View File

@ -0,0 +1,15 @@
<?php
namespace app\data\model;
use think\admin\Model;
/**
* 商城订单详情模型
* Class ShopOrderItem
* @package app\data\model
*/
class ShopOrderItem extends Model
{
}

View File

@ -2,6 +2,7 @@
namespace app\data\service; namespace app\data\service;
use app\data\model\DataUserMessage;
use think\admin\Service; use think\admin\Service;
/** /**
@ -107,7 +108,7 @@ class MessageService extends Service
*/ */
public function checkVerifyCode(string $code, string $phone, string $tplcode = 'zt.tplcode_register'): bool public function checkVerifyCode(string $code, string $phone, string $tplcode = 'zt.tplcode_register'): bool
{ {
$cache = $this->app->cache->get($ckey = md5("code-{$tplcode}-{$phone}"), []); $cache = $this->app->cache->get(md5("code-{$tplcode}-{$phone}"), []);
return is_array($cache) && isset($cache['code']) && $cache['code'] == $code; return is_array($cache) && isset($cache['code']) && $cache['code'] == $code;
} }
@ -154,7 +155,7 @@ class MessageService extends Service
public function send(string $phone, string $content): array public function send(string $phone, string $content): array
{ {
[$state, $message, $record] = $this->_request('v2/sendSms', ['mobile' => $phone, 'content' => $content]); [$state, $message, $record] = $this->_request('v2/sendSms', ['mobile' => $phone, 'content' => $content]);
$this->app->db->name('DataUserMessage')->insert([ DataUserMessage::mk()->insert([
'phone' => $phone, 'content' => $content, 'result' => $message, 'status' => $state ? 1 : 0, 'phone' => $phone, 'content' => $content, 'result' => $message, 'status' => $state ? 1 : 0,
]); ]);
return [$state, $message, $record]; return [$state, $message, $record];

View File

@ -2,6 +2,8 @@
namespace app\data\service; namespace app\data\service;
use app\data\model\DataUserPayment;
use app\data\model\ShopOrder;
use app\data\service\payment\AlipayPaymentService; use app\data\service\payment\AlipayPaymentService;
use app\data\service\payment\BalancePyamentService; use app\data\service\payment\BalancePyamentService;
use app\data\service\payment\EmptyPaymentService; use app\data\service\payment\EmptyPaymentService;
@ -162,7 +164,7 @@ abstract class PaymentService
* 根据配置实例支付服务 * 根据配置实例支付服务
* @param string $code 支付配置编号 * @param string $code 支付配置编号
* @return JoinpayPaymentService|WechatPaymentService|AlipayPaymentService|BalancePyamentService|VoucherPaymentService|EmptyPaymentService * @return JoinpayPaymentService|WechatPaymentService|AlipayPaymentService|BalancePyamentService|VoucherPaymentService|EmptyPaymentService
* @throws Exception * @throws \think\admin\Exception
*/ */
public static function instance(string $code): PaymentService public static function instance(string $code): PaymentService
{ {
@ -291,7 +293,7 @@ abstract class PaymentService
*/ */
protected function createPaymentAction(string $orderNo, string $paymentTitle, string $paymentAmount) protected function createPaymentAction(string $orderNo, string $paymentTitle, string $paymentAmount)
{ {
$this->app->db->name('DataUserPayment')->insert([ DataUserPayment::mk()->insert([
'payment_code' => $this->code, 'payment_code' => $this->code,
'payment_type' => $this->type, 'payment_type' => $this->type,
'order_no' => $orderNo, 'order_no' => $orderNo,
@ -314,7 +316,7 @@ abstract class PaymentService
protected function updatePaymentAction(string $orderNo, string $paymentTrade, string $paymentAmount, string $paymentRemark = '在线支付'): bool protected function updatePaymentAction(string $orderNo, string $paymentTrade, string $paymentAmount, string $paymentRemark = '在线支付'): bool
{ {
// 更新支付记录 // 更新支付记录
data_save('DataUserPayment', [ data_save(DataUserPayment::mk(), [
'order_no' => $orderNo, 'order_no' => $orderNo,
'payment_code' => $this->code, 'payment_code' => $this->code,
'payment_type' => $this->type, 'payment_type' => $this->type,
@ -345,7 +347,7 @@ abstract class PaymentService
public function updateOrder(string $orderNo, string $paymentTrade, string $paymentAmount, string $paymentRemark = '在线支付', string $paymentImage = ''): bool public function updateOrder(string $orderNo, string $paymentTrade, string $paymentAmount, string $paymentRemark = '在线支付', string $paymentImage = ''): bool
{ {
$map = ['status' => 2, 'order_no' => $orderNo, 'payment_status' => 0]; $map = ['status' => 2, 'order_no' => $orderNo, 'payment_status' => 0];
$order = $this->app->db->name('ShopOrder')->where($map)->find(); $order = ShopOrder::mk()->where($map)->find();
if (empty($order)) return false; if (empty($order)) return false;
// 检查订单支付状态 // 检查订单支付状态
if ($this->type === self::PAYMENT_VOUCHER) { if ($this->type === self::PAYMENT_VOUCHER) {
@ -368,7 +370,7 @@ abstract class PaymentService
'payment_datetime' => date('Y-m-d H:i:s'), 'payment_datetime' => date('Y-m-d H:i:s'),
]; ];
if (empty($data['payment_type'])) unset($data['payment_type']); if (empty($data['payment_type'])) unset($data['payment_type']);
$this->app->db->name('ShopOrder')->where($map)->update($data); ShopOrder::mk()->where($map)->update($data);
// 触发订单更新事件 // 触发订单更新事件
if ($status >= 4) { if ($status >= 4) {
$this->app->event->trigger('ShopOrderPayment', $orderNo); $this->app->event->trigger('ShopOrderPayment', $orderNo);

View File

@ -2,6 +2,9 @@
namespace app\data\service; namespace app\data\service;
use app\data\model\DataUser;
use app\data\model\DataUserRebate;
use app\data\model\ShopOrder;
use think\admin\Exception; use think\admin\Exception;
use think\admin\extend\CodeExtend; use think\admin\extend\CodeExtend;
use think\admin\Service; use think\admin\Service;
@ -58,16 +61,10 @@ class RebateService extends Service
protected $from1; protected $from1;
protected $from2; protected $from2;
/**
* 绑定数据表
* @var string
*/
private $table = 'DataUserRebate';
/** /**
* 执行订单返利处理 * 执行订单返利处理
* @param string $orderNo * @param string $orderNo
* @throws Exception * @throws \think\admin\Exception
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
@ -76,7 +73,7 @@ class RebateService extends Service
{ {
// 获取订单数据 // 获取订单数据
$map = ['order_no' => $orderNo, 'payment_status' => 1]; $map = ['order_no' => $orderNo, 'payment_status' => 1];
$this->order = $this->app->db->name('ShopOrder')->where($map)->find(); $this->order = ShopOrder::mk()->where($map)->find();
if (empty($this->order)) throw new Exception('订单不存在'); if (empty($this->order)) throw new Exception('订单不存在');
if ($this->order['payment_type'] === 'balance') return; if ($this->order['payment_type'] === 'balance') return;
// throw new Exception('余额支付不反利'); // throw new Exception('余额支付不反利');
@ -85,18 +82,18 @@ class RebateService extends Service
if ($this->order['rebate_amount'] <= 0) throw new Exception('订单返利为零'); if ($this->order['rebate_amount'] <= 0) throw new Exception('订单返利为零');
// 获取用户数据 // 获取用户数据
$map = ['id' => $this->order['uuid'], 'deleted' => 0]; $map = ['id' => $this->order['uuid'], 'deleted' => 0];
$this->user = $this->app->db->name('DataUser')->where($map)->find(); $this->user = DataUser::mk()->where($map)->find();
if (empty($this->user)) throw new Exception('用户不存在'); if (empty($this->user)) throw new Exception('用户不存在');
// 获取直接代理数据 // 获取直接代理数据
if ($this->order['puid1'] > 0) { if ($this->order['puid1'] > 0) {
$map = ['id' => $this->order['puid1']]; $map = ['id' => $this->order['puid1']];
$this->from1 = $this->app->db->name('DataUser')->where($map)->find(); $this->from1 = DataUser::mk()->where($map)->find();
if (empty($this->from1)) throw new Exception('直接代理不存在'); if (empty($this->from1)) throw new Exception('直接代理不存在');
} }
// 获取间接代理数据 // 获取间接代理数据
if ($this->order['puid2'] > 0) { if ($this->order['puid2'] > 0) {
$map = ['id' => $this->order['puid2']]; $map = ['id' => $this->order['puid2']];
$this->from2 = $this->app->db->name('DataUser')->where($map)->find(); $this->from2 = DataUser::mk()->where($map)->find();
if (empty($this->from2)) throw new Exception('间接代理不存在'); if (empty($this->from2)) throw new Exception('间接代理不存在');
} }
// 批量发放配置奖励 // 批量发放配置奖励
@ -148,12 +145,12 @@ class RebateService extends Service
{ {
if (empty($this->from1)) return false; if (empty($this->from1)) return false;
$map = ['order_uuid' => $this->user['id']]; $map = ['order_uuid' => $this->user['id']];
if ($this->app->db->name($this->table)->where($map)->count() > 0) return false; if (DataUserRebate::mk()->where($map)->count() > 0) return false;
if (!$this->checkPrizeStatus(self::PRIZE_01, $this->from1['vip_code'])) return false; if (!$this->checkPrizeStatus(self::PRIZE_01, $this->from1['vip_code'])) return false;
// 创建返利奖励记录 // 创建返利奖励记录
$key = "{$this->from1['vip_code']}_{$this->user['vip_code']}"; $key = "{$this->from1['vip_code']}_{$this->user['vip_code']}";
$map = ['type' => self::PRIZE_01, 'order_no' => $this->order['order_no'], 'order_uuid' => $this->order['uuid']]; $map = ['type' => self::PRIZE_01, 'order_no' => $this->order['order_no'], 'order_uuid' => $this->order['uuid']];
if ($this->config("frist_state_vip_{$key}") && $this->app->db->name($this->table)->where($map)->count() < 1) { if ($this->config("frist_state_vip_{$key}") && DataUserRebate::mk()->where($map)->count() < 1) {
$value = $this->config("frist_value_vip_{$key}"); $value = $this->config("frist_value_vip_{$key}");
if ($this->config("frist_type_vip_{$key}") == 1) { if ($this->config("frist_type_vip_{$key}") == 1) {
$val = floatval($value ?: '0.00'); $val = floatval($value ?: '0.00');
@ -196,11 +193,10 @@ class RebateService extends Service
* @param array $map * @param array $map
* @param string $name * @param string $name
* @param float $amount * @param float $amount
* @throws \think\db\exception\DbException
*/ */
private function writeRabate(int $uuid, array $map, string $name, float $amount) private function writeRabate(int $uuid, array $map, string $name, float $amount)
{ {
$this->app->db->name($this->table)->insert(array_merge($map, [ DataUserRebate::mk()->insert(array_merge($map, [
'uuid' => $uuid, 'uuid' => $uuid,
'date' => date('Y-m-d'), 'date' => date('Y-m-d'),
'code' => CodeExtend::uniqidDate(20, 'R'), 'code' => CodeExtend::uniqidDate(20, 'R'),
@ -227,14 +223,14 @@ class RebateService extends Service
$map = []; $map = [];
$map[] = ['order_uuid', '=', $this->user['id']]; $map[] = ['order_uuid', '=', $this->user['id']];
$map[] = ['order_no', '<>', $this->order['order_no']]; $map[] = ['order_no', '<>', $this->order['order_no']];
if ($this->app->db->name($this->table)->where($map)->count() < 1) return false; if (DataUserRebate::mk()->where($map)->count() < 1) return false;
// 检查上级可否奖励 // 检查上级可否奖励
if (empty($this->from1) || empty($this->from1['vip_code'])) return false; if (empty($this->from1) || empty($this->from1['vip_code'])) return false;
if (!$this->checkPrizeStatus(self::PRIZE_02, $this->from1['vip_code'])) return false; if (!$this->checkPrizeStatus(self::PRIZE_02, $this->from1['vip_code'])) return false;
// 创建返利奖励记录 // 创建返利奖励记录
$key = "vip_{$this->from1['vip_code']}_{$this->user['vip_code']}"; $key = "vip_{$this->from1['vip_code']}_{$this->user['vip_code']}";
$map = ['type' => self::PRIZE_02, 'order_no' => $this->order['order_no'], 'order_uuid' => $this->order['uuid']]; $map = ['type' => self::PRIZE_02, 'order_no' => $this->order['order_no'], 'order_uuid' => $this->order['uuid']];
if ($this->config("repeat_state_{$key}") && $this->app->db->name($this->table)->where($map)->count() < 1) { if ($this->config("repeat_state_{$key}") && DataUserRebate::mk()->where($map)->count() < 1) {
$value = $this->config("repeat_value_{$key}"); $value = $this->config("repeat_value_{$key}");
if ($this->config("repeat_type_{$key}") == 1) { if ($this->config("repeat_type_{$key}") == 1) {
$val = floatval($value ?: '0.00'); $val = floatval($value ?: '0.00');
@ -263,7 +259,7 @@ class RebateService extends Service
// 创建返利奖励记录 // 创建返利奖励记录
$key = "{$this->user['vip_code']}"; $key = "{$this->user['vip_code']}";
$map = ['type' => self::PRIZE_03, 'order_no' => $this->order['order_no'], 'order_uuid' => $this->order['uuid']]; $map = ['type' => self::PRIZE_03, 'order_no' => $this->order['order_no'], 'order_uuid' => $this->order['uuid']];
if ($this->config("direct_state_vip_{$key}") && $this->app->db->name($this->table)->where($map)->count() < 1) { if ($this->config("direct_state_vip_{$key}") && DataUserRebate::mk()->where($map)->count() < 1) {
$value = $this->config("direct_value_vip_{$key}"); $value = $this->config("direct_value_vip_{$key}");
if ($this->config("direct_type_vip_{$key}") == 1) { if ($this->config("direct_type_vip_{$key}") == 1) {
$val = floatval($value ?: '0.00'); $val = floatval($value ?: '0.00');
@ -291,7 +287,7 @@ class RebateService extends Service
if (!$this->checkPrizeStatus(self::PRIZE_04, $this->from2['vip_code'])) return false; if (!$this->checkPrizeStatus(self::PRIZE_04, $this->from2['vip_code'])) return false;
$key = "{$this->user['vip_code']}"; $key = "{$this->user['vip_code']}";
$map = ['type' => self::PRIZE_04, 'order_no' => $this->order['order_no'], 'order_uuid' => $this->order['uuid']]; $map = ['type' => self::PRIZE_04, 'order_no' => $this->order['order_no'], 'order_uuid' => $this->order['uuid']];
if ($this->config("indirect_state_vip_{$key}") && $this->app->db->name($this->table)->where($map)->count() < 1) { if ($this->config("indirect_state_vip_{$key}") && DataUserRebate::mk()->where($map)->count() < 1) {
$value = $this->config("indirect_value_vip_{$key}"); $value = $this->config("indirect_value_vip_{$key}");
if ($this->config("indirect_type_vip_{$key}") == 1) { if ($this->config("indirect_type_vip_{$key}") == 1) {
$val = floatval($value ?: '0.00'); $val = floatval($value ?: '0.00');
@ -319,7 +315,7 @@ class RebateService extends Service
if (empty($puids) || $this->order['amount_total'] <= 0) return false; if (empty($puids) || $this->order['amount_total'] <= 0) return false;
// 获取可以参与奖励的代理 // 获取可以参与奖励的代理
$vips = $this->app->db->name('BaseUserUpgrade')->whereLike('rebate_rule', '%,' . self::PRIZE_05 . ',%')->column('number'); $vips = $this->app->db->name('BaseUserUpgrade')->whereLike('rebate_rule', '%,' . self::PRIZE_05 . ',%')->column('number');
$users = $this->app->db->name('DataUser')->whereIn('vip_code', $vips)->whereIn('id', $puids)->orderField('id', $puids)->select()->toArray(); $users = DataUser::mk()->whereIn('vip_code', $vips)->whereIn('id', $puids)->orderField('id', $puids)->select()->toArray();
// 查询需要计算奖励的商品 // 查询需要计算奖励的商品
foreach ($this->app->db->name('ShopOrderItem')->where(['order_no' => $this->order['order_no']])->cursor() as $item) { foreach ($this->app->db->name('ShopOrderItem')->where(['order_no' => $this->order['order_no']])->cursor() as $item) {
$itemJson = $this->app->db->name('BaseUserDiscount')->where(['status' => 1, 'deleted' => 0])->value('items'); $itemJson = $this->app->db->name('BaseUserDiscount')->where(['status' => 1, 'deleted' => 0])->value('items');
@ -330,7 +326,7 @@ class RebateService extends Service
if ($tRate > $rule['discount'] && $tRate < 100) { if ($tRate > $rule['discount'] && $tRate < 100) {
$map = ['uuid' => $user['id'], 'type' => self::PRIZE_05]; $map = ['uuid' => $user['id'], 'type' => self::PRIZE_05];
$map['code'] = "{$this->order['order_no']}#{$item['id']}#{$tVip}.{$user['vip_code']}"; $map['code'] = "{$this->order['order_no']}#{$item['id']}#{$tVip}.{$user['vip_code']}";
if ($this->app->db->name($this->table)->where($map)->count() < 1) { if (DataUserRebate::mk()->where($map)->count() < 1) {
$dRate = ($rate = $tRate - $rule['discount']) / 100; $dRate = ($rate = $tRate - $rule['discount']) / 100;
$name = "等级差额奖励{$tVip}#{$user['vip_code']}商品原价{$item['total_selling']}元的{$rate}%"; $name = "等级差额奖励{$tVip}#{$user['vip_code']}商品原价{$item['total_selling']}元的{$rate}%";
$amount = $dRate * $item['total_selling']; $amount = $dRate * $item['total_selling'];
@ -360,11 +356,11 @@ class RebateService extends Service
$prevLevel = $this->user['vip_code']; $prevLevel = $this->user['vip_code'];
// 获取可以参与奖励的代理 // 获取可以参与奖励的代理
$vips = $this->app->db->name('BaseUserUpgrade')->whereLike('rebate_rule', '%,' . self::PRIZE_06 . ',%')->column('number'); $vips = $this->app->db->name('BaseUserUpgrade')->whereLike('rebate_rule', '%,' . self::PRIZE_06 . ',%')->column('number');
foreach ($this->app->db->name('DataUser')->whereIn('vip_code', $vips)->whereIn('id', $puids)->orderField('id', $puids)->cursor() as $user) { foreach (DataUser::mk()->whereIn('vip_code', $vips)->whereIn('id', $puids)->orderField('id', $puids)->cursor() as $user) {
if ($user['vip_code'] > $prevLevel) { if ($user['vip_code'] > $prevLevel) {
if (($amount = $this->_prize06amount($prevLevel + 1, $user['vip_code'])) > 0.00) { if (($amount = $this->_prize06amount($prevLevel + 1, $user['vip_code'])) > 0.00) {
$map = ['uuid' => $user['id'], 'type' => self::PRIZE_06, 'order_no' => $this->order['order_no'], 'order_uuid' => $this->order['uuid']]; $map = ['uuid' => $user['id'], 'type' => self::PRIZE_06, 'order_no' => $this->order['order_no'], 'order_uuid' => $this->order['uuid']];
if ($this->app->db->name($this->table)->where($map)->count() < 1) { if (DataUserRebate::mk()->where($map)->count() < 1) {
$name = "{$this->name(self::PRIZE_06)}[ VIP{$prevLevel} > VIP{$user['vip_code']} ] 每单 {$amount}"; $name = "{$this->name(self::PRIZE_06)}[ VIP{$prevLevel} > VIP{$user['vip_code']} ] 每单 {$amount}";
$this->writeRabate($user['id'], $map, $name, $amount); $this->writeRabate($user['id'], $map, $name, $amount);
} }
@ -417,7 +413,7 @@ class RebateService extends Service
// 创建返利奖励记录 // 创建返利奖励记录
$key = "{$this->user['vip_code']}"; $key = "{$this->user['vip_code']}";
$map = ['type' => self::PRIZE_07, 'order_no' => $this->order['order_no'], 'order_uuid' => $this->order['uuid']]; $map = ['type' => self::PRIZE_07, 'order_no' => $this->order['order_no'], 'order_uuid' => $this->order['uuid']];
if ($this->config("upgrade_state_vip_{$key}") && $this->app->db->name($this->table)->where($map)->count() < 1) { if ($this->config("upgrade_state_vip_{$key}") && DataUserRebate::mk()->where($map)->count() < 1) {
$value = $this->config("upgrade_value_vip_{$key}"); $value = $this->config("upgrade_value_vip_{$key}");
if ($this->config("upgrade_type_vip_{$key}") == 1) { if ($this->config("upgrade_type_vip_{$key}") == 1) {
$val = floatval($value ?: '0.00'); $val = floatval($value ?: '0.00');
@ -435,16 +431,13 @@ class RebateService extends Service
/** /**
* 用户平推奖励发放 * 用户平推奖励发放
* @return boolean * @return boolean
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/ */
private function _prize08(): bool private function _prize08(): bool
{ {
if (empty($this->from1)) return false; if (empty($this->from1)) return false;
$map = ['vip_code' => $this->user['vip_code']]; $map = ['vip_code' => $this->user['vip_code']];
$uuids = array_reverse(str2arr(trim($this->user['path'], '-'), '-')); $uuids = array_reverse(str2arr(trim($this->user['path'], '-'), '-'));
$puids = $this->app->db->name('DataUser')->whereIn('id', $uuids)->orderField('id', $uuids)->where($map)->column('id'); $puids = DataUser::mk()->whereIn('id', $uuids)->orderField('id', $uuids)->where($map)->column('id');
if (count($puids) < 2) return false; if (count($puids) < 2) return false;
} }
} }

View File

@ -2,9 +2,10 @@
namespace app\data\service; namespace app\data\service;
use app\data\model\DataUser;
use app\data\model\DataUserToken;
use think\admin\Exception; use think\admin\Exception;
use think\admin\Service; use think\admin\Service;
use think\db\exception\DbException;
/** /**
* 用户数据管理服务 * 用户数据管理服务
@ -55,19 +56,19 @@ class UserAdminService extends Service
* @param string $type 接口类型 * @param string $type 接口类型
* @param boolean $force 强刷令牌 * @param boolean $force 强刷令牌
* @return array * @return array
* @throws Exception * @throws \think\admin\Exception
* @throws DbException * @throws \think\db\exception\DbException
*/ */
public function set(array $map, array $data, string $type, bool $force = false): array public function set(array $map, array $data, string $type, bool $force = false): array
{ {
unset($data['id'], $data['deleted'], $data['create_at']); unset($data['id'], $data['deleted'], $data['create_at']);
if ($uuid = $this->app->db->name('DataUser')->where($map)->where(['deleted' => 0])->value('id')) { if ($uuid = DataUser::mk()->where($map)->where(['deleted' => 0])->value('id')) {
if (!empty($data)) { if (!empty($data)) {
$map = ['id' => $uuid, 'deleted' => 0]; $map = ['id' => $uuid, 'deleted' => 0];
$this->app->db->name('DataUser')->strict(false)->where($map)->update($data); DataUser::mk()->strict(false)->where($map)->update($data);
} }
} else { } else {
$uuid = $this->app->db->name('DataUser')->strict(false)->insertGetId($data); $uuid = DataUser::mk()->strict(false)->insertGetId($data);
} }
if ($force) { if ($force) {
UserTokenService::instance()->token(intval($uuid), $type); UserTokenService::instance()->token(intval($uuid), $type);
@ -80,17 +81,18 @@ class UserAdminService extends Service
* @param integer $uuid 用户UID * @param integer $uuid 用户UID
* @param ?string $type 接口类型 * @param ?string $type 接口类型
* @return array * @return array
* @throws DbException * @throws \think\admin\Exception
* @throws Exception * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/ */
public function get(int $uuid, ?string $type = null): array public function get(int $uuid, ?string $type = null): array
{ {
$map = ['id' => $uuid, 'deleted' => 0]; $user = DataUser::mk()->where(['id' => $uuid, 'deleted' => 0])->find();
$user = $this->app->db->name('DataUser')->where($map)->find();
if (empty($user)) throw new Exception('指定UID用户不存在'); if (empty($user)) throw new Exception('指定UID用户不存在');
if (!is_null($type)) { if (!is_null($type)) {
$map = ['uuid' => $uuid, 'type' => $type]; $map = ['uuid' => $uuid, 'type' => $type];
$data = $this->app->db->name('DataUserToken')->where($map)->find(); $data = DataUserToken::mk()->where($map)->find();
if (empty($data)) { if (empty($data)) {
[$state, $info, $data] = UserTokenService::instance()->token($uuid, $type); [$state, $info, $data] = UserTokenService::instance()->token($uuid, $type);
if (empty($state) || empty($data)) throw new Exception($info); if (empty($state) || empty($data)) throw new Exception($info);
@ -108,8 +110,7 @@ class UserAdminService extends Service
*/ */
public function total(int $uuid): array public function total(int $uuid): array
{ {
$query = $this->app->db->name('DataUser'); return ['my_invite' => DataUser::mk()->where(['pid1' => $uuid])->count()];
return ['my_invite' => $query->where(['pid1' => $uuid])->count()];
} }
/** /**
@ -123,7 +124,7 @@ class UserAdminService extends Service
{ {
if (!empty($unionid)) { if (!empty($unionid)) {
[$map1, $map2] = [[['unionid', '=', $unionid]], [[$field, '=', $openid]]]; [$map1, $map2] = [[['unionid', '=', $unionid]], [[$field, '=', $openid]]];
if ($uuid = $this->app->db->name('DataUser')->whereOr([$map1, $map2])->value('id')) { if ($uuid = DataUser::mk()->whereOr([$map1, $map2])->value('id')) {
return ['id' => $uuid]; return ['id' => $uuid];
} }
} }
@ -142,7 +143,7 @@ class UserAdminService extends Service
{ {
if (count($list) < 1) return $list; if (count($list) < 1) return $list;
$uids = array_unique(array_column($list, $keys)); $uids = array_unique(array_column($list, $keys));
$users = $this->app->db->name('DataUser')->whereIn('id', $uids)->column($cols, 'id'); $users = DataUser::mk()->whereIn('id', $uids)->column($cols, 'id');
foreach ($list as &$vo) $vo[$bind] = $users[$vo[$keys]] ?? []; foreach ($list as &$vo) $vo[$bind] = $users[$vo[$keys]] ?? [];
return $list; return $list;
} }

View File

@ -2,6 +2,8 @@
namespace app\data\service; namespace app\data\service;
use app\data\model\DataUserBalance;
use think\admin\Exception;
use think\admin\Service; use think\admin\Service;
/** /**
@ -25,7 +27,7 @@ class UserBalanceService extends Service
{ {
$map = [['status', '>=', 4], ['order_no', '=', $orderNo]]; $map = [['status', '>=', 4], ['order_no', '=', $orderNo]];
$order = $this->app->db->name('ShopOrder')->where($map)->find(); $order = $this->app->db->name('ShopOrder')->where($map)->find();
if (empty($order)) throw new \think\admin\Exception('需处理的订单状态异常'); if (empty($order)) throw new Exception('需处理的订单状态异常');
if ($order['reward_balance'] > 0) data_save('DataUserBalance', [ if ($order['reward_balance'] > 0) data_save('DataUserBalance', [
'uuid' => $order['uuid'], 'uuid' => $order['uuid'],
@ -48,16 +50,16 @@ class UserBalanceService extends Service
public function amount(int $uuid, array $nots = []): array public function amount(int $uuid, array $nots = []): array
{ {
if ($uuid > 0) { if ($uuid > 0) {
$total = abs($this->app->db->name('DataUserBalance')->whereRaw("uuid='{$uuid}' and amount>0 and deleted=0")->sum('amount')); $total = abs(DataUserBalance::mk()->whereRaw("uuid='{$uuid}' and amount>0 and deleted=0")->sum('amount'));
$count = abs($this->app->db->name('DataUserBalance')->whereRaw("uuid='{$uuid}' and amount<0 and deleted=0")->sum('amount')); $count = abs(DataUserBalance::mk()->whereRaw("uuid='{$uuid}' and amount<0 and deleted=0")->sum('amount'));
if (empty($nots)) { if (empty($nots)) {
$this->app->db->name('DataUser')->where(['id' => $uuid])->update(['balance_total' => $total, 'balance_used' => $count]); $this->app->db->name('DataUser')->where(['id' => $uuid])->update(['balance_total' => $total, 'balance_used' => $count]);
} else { } else {
$count -= $this->app->db->name('DataUserBalance')->whereRaw("uuid={$uuid}")->whereIn('code', $nots)->sum('amount'); $count -= DataUserBalance::mk()->whereRaw("uuid={$uuid}")->whereIn('code', $nots)->sum('amount');
} }
} else { } else {
$total = abs($this->app->db->name('DataUserBalance')->whereRaw("amount>0 and deleted=0")->sum('amount')); $total = abs(DataUserBalance::mk()->whereRaw("amount>0 and deleted=0")->sum('amount'));
$count = abs($this->app->db->name('DataUserBalance')->whereRaw("amount<0 and deleted=0")->sum('amount')); $count = abs(DataUserBalance::mk()->whereRaw("amount<0 and deleted=0")->sum('amount'));
} }
return [$total, $count]; return [$total, $count];
} }

View File

@ -2,6 +2,10 @@
namespace app\data\service; namespace app\data\service;
use app\data\model\DataUser;
use app\data\model\DataUserRebate;
use app\data\model\DataUserTransfer;
use app\data\model\ShopOrder;
use think\admin\Service; use think\admin\Service;
/** /**
@ -15,19 +19,18 @@ class UserRebateService extends Service
* 同步刷新用户返利 * 同步刷新用户返利
* @param integer $uuid * @param integer $uuid
* @return array [total, count, lock] * @return array [total, count, lock]
* @throws \think\db\exception\DbException
*/ */
public function amount(int $uuid): array public function amount(int $uuid): array
{ {
if ($uuid > 0) { if ($uuid > 0) {
$count = $this->app->db->name('DataUserTransfer')->whereRaw("uuid='{$uuid}' and status>0")->sum('amount'); $count = DataUserTransfer::mk()->whereRaw("uuid='{$uuid}' and status>0")->sum('amount');
$total = $this->app->db->name('DataUserRebate')->whereRaw("uuid='{$uuid}' and status=1 and deleted=0")->sum('amount'); $total = DataUserRebate::mk()->whereRaw("uuid='{$uuid}' and status=1 and deleted=0")->sum('amount');
$locks = $this->app->db->name('DataUserRebate')->whereRaw("uuid='{$uuid}' and status=0 and deleted=0")->sum('amount'); $locks = DataUserRebate::mk()->whereRaw("uuid='{$uuid}' and status=0 and deleted=0")->sum('amount');
$this->app->db->name('DataUser')->where(['id' => $uuid])->update(['rebate_total' => $total, 'rebate_used' => $count, 'rebate_lock' => $locks]); DataUser::mk()->where(['id' => $uuid])->update(['rebate_total' => $total, 'rebate_used' => $count, 'rebate_lock' => $locks]);
} else { } else {
$count = $this->app->db->name('DataUserTransfer')->whereRaw("status>0")->sum('amount'); $count = DataUserTransfer::mk()->whereRaw("status>0")->sum('amount');
$total = $this->app->db->name('DataUserRebate')->whereRaw("status=1 and deleted=0")->sum('amount'); $total = DataUserRebate::mk()->whereRaw("status=1 and deleted=0")->sum('amount');
$locks = $this->app->db->name('DataUserRebate')->whereRaw("status=0 and deleted=0")->sum('amount'); $locks = DataUserRebate::mk()->whereRaw("status=0 and deleted=0")->sum('amount');
} }
return [$total, $count, $locks]; return [$total, $count, $locks];
} }
@ -43,11 +46,11 @@ class UserRebateService extends Service
public function confirm(string $orderNo): array public function confirm(string $orderNo): array
{ {
$map = [['status', '>=', 4], ['order_no', '=', $orderNo]]; $map = [['status', '>=', 4], ['order_no', '=', $orderNo]];
$order = $this->app->db->name('ShopOrder')->where($map)->find(); $order = ShopOrder::mk()->where($map)->find();
if (empty($order)) return [0, '需处理的订单状态异常!']; if (empty($order)) return [0, '需处理的订单状态异常!'];
$map = [['status', '=', 0], ['order_no', 'like', "{$orderNo}%"]]; $map = [['status', '=', 0], ['order_no', 'like', "{$orderNo}%"]];
$this->app->db->name('DataUserRebate')->where($map)->update(['status' => 1]); DataUserRebate::mk()->where($map)->update(['status' => 1]);
if (UserUpgradeService::instance()->upgrade($order['uuid'])) { if (UserUpgradeService::instance()->upgrade($order['uuid'])) {
return [1, '重新计算用户金额成功!']; return [1, '重新计算用户金额成功!'];
} else { } else {

View File

@ -2,10 +2,8 @@
namespace app\data\service; namespace app\data\service;
use app\data\model\DataUserToken;
use think\admin\Service; use think\admin\Service;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/** /**
* 用户接口授权服务 * 用户接口授权服务
@ -27,15 +25,15 @@ class UserTokenService extends Service
* @param string $token 认证令牌 * @param string $token 认证令牌
* @param array $data 认证数据 * @param array $data 认证数据
* @return array [ 检查状态状态描述用户UID, 有效时间 ] * @return array [ 检查状态状态描述用户UID, 有效时间 ]
* @throws DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws DbException * @throws \think\db\exception\DbException
* @throws ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
public function check(string $type, string $token, array $data = []): array public function check(string $type, string $token, array $data = []): array
{ {
if (empty($data)) { if (empty($data)) {
$map = ['type' => $type, 'token' => $token]; $map = ['type' => $type, 'token' => $token];
$data = $this->app->db->name('DataUserToken')->where($map)->find(); $data = DataUserToken::mk()->where($map)->find();
} }
if (empty($data) || empty($data['uuid'])) { if (empty($data) || empty($data['uuid'])) {
return [0, '请重新登录,登录认证无效', 0, 0]; return [0, '请重新登录,登录认证无效', 0, 0];
@ -62,12 +60,11 @@ class UserTokenService extends Service
* 延期 TOKEN 有效时间 * 延期 TOKEN 有效时间
* @param string $type 接口类型 * @param string $type 接口类型
* @param string $token 授权令牌 * @param string $token 授权令牌
* @throws DbException
*/ */
public function expire(string $type, string $token) public function expire(string $type, string $token)
{ {
$map = ['type' => $type, 'token' => $token]; $map = ['type' => $type, 'token' => $token];
$this->app->db->name('DataUserToken')->where($map)->update([ DataUserToken::mk()->where($map)->update([
'time' => time() + $this->expire, 'time' => time() + $this->expire,
]); ]);
} }
@ -77,7 +74,6 @@ class UserTokenService extends Service
* @param int $uuid 授权用户 * @param int $uuid 授权用户
* @param string $type 接口类型 * @param string $type 接口类型
* @return array [创建状态, 状态描述, 令牌数据] * @return array [创建状态, 状态描述, 令牌数据]
* @throws DbException
*/ */
public function token(int $uuid, string $type): array public function token(int $uuid, string $type): array
{ {
@ -85,13 +81,13 @@ class UserTokenService extends Service
$time = time(); $time = time();
$map1 = [['token', '<>', 'token'], ['time', '<', $time]]; $map1 = [['token', '<>', 'token'], ['time', '<', $time]];
$map2 = [['token', '<>', 'token'], ['type', '=', $type], ['uuid', '=', $uuid]]; $map2 = [['token', '<>', 'token'], ['type', '=', $type], ['uuid', '=', $uuid]];
$this->app->db->name('DataUserToken')->whereOr([$map1, $map2])->delete(); DataUserToken::mk()->whereOr([$map1, $map2])->delete();
// 创建新的认证数据 // 创建新的认证数据
do $map = ['type' => $type, 'token' => md5(uniqid() . rand(100, 999))]; do $map = ['type' => $type, 'token' => md5(uniqid() . rand(100, 999))];
while ($this->app->db->name('DataUserToken')->where($map)->count() > 0); while (DataUserToken::mk()->where($map)->count() > 0);
// 写入用户认证数据 // 写入用户认证数据
$data = array_merge($map, ['uuid' => $uuid, 'time' => $time + $this->expire, 'tokenv' => $this->_buildTokenVerify()]); $data = array_merge($map, ['uuid' => $uuid, 'time' => $time + $this->expire, 'tokenv' => $this->_buildTokenVerify()]);
if ($this->app->db->name('DataUserToken')->insert($data) !== false) { if (DataUserToken::mk()->insert($data) !== false) {
return [1, '刷新认证成功', $data]; return [1, '刷新认证成功', $data];
} else { } else {
return [0, '刷新认证失败', []]; return [0, '刷新认证失败', []];

View File

@ -2,6 +2,7 @@
namespace app\data\service; namespace app\data\service;
use app\data\model\DataUserTransfer;
use think\admin\Service; use think\admin\Service;
/** /**
@ -100,15 +101,15 @@ class UserTransferService extends Service
public function amount(int $uuid): array public function amount(int $uuid): array
{ {
if ($uuid > 0) { if ($uuid > 0) {
$locks = abs($this->app->db->name('DataUserTransfer')->whereRaw("uuid='{$uuid}' and status=3")->sum('amount')); $locks = abs(DataUserTransfer::mk()->whereRaw("uuid='{$uuid}' and status=3")->sum('amount'));
$total = abs($this->app->db->name('DataUserTransfer')->whereRaw("uuid='{$uuid}' and status>=1")->sum('amount')); $total = abs(DataUserTransfer::mk()->whereRaw("uuid='{$uuid}' and status>=1")->sum('amount'));
$count = abs($this->app->db->name('DataUserTransfer')->whereRaw("uuid='{$uuid}' and status>=4")->sum('amount')); $count = abs(DataUserTransfer::mk()->whereRaw("uuid='{$uuid}' and status>=4")->sum('amount'));
$audit = abs($this->app->db->name('DataUserTransfer')->whereRaw("uuid='{$uuid}' and status>=1 and status<3")->sum('amount')); $audit = abs(DataUserTransfer::mk()->whereRaw("uuid='{$uuid}' and status>=1 and status<3")->sum('amount'));
} else { } else {
$locks = abs($this->app->db->name('DataUserTransfer')->whereRaw("status=3")->sum('amount')); $locks = abs(DataUserTransfer::mk()->whereRaw("status=3")->sum('amount'));
$total = abs($this->app->db->name('DataUserTransfer')->whereRaw("status>=1")->sum('amount')); $total = abs(DataUserTransfer::mk()->whereRaw("status>=1")->sum('amount'));
$count = abs($this->app->db->name('DataUserTransfer')->whereRaw("status>=4")->sum('amount')); $count = abs(DataUserTransfer::mk()->whereRaw("status>=4")->sum('amount'));
$audit = abs($this->app->db->name('DataUserTransfer')->whereRaw("status>=1 and status<3")->sum('amount')); $audit = abs(DataUserTransfer::mk()->whereRaw("status>=1 and status<3")->sum('amount'));
} }
return [$total, $count, $audit, $locks]; return [$total, $count, $audit, $locks];
} }

View File

@ -2,6 +2,10 @@
namespace app\data\service; namespace app\data\service;
use app\data\model\DataUser;
use app\data\model\DataUserBalance;
use app\data\model\ShopOrder;
use app\data\model\ShopOrderItem;
use think\admin\Service; use think\admin\Service;
/** /**
@ -34,7 +38,7 @@ class UserUpgradeService extends Service
*/ */
public function bindAgent(int $uuid, int $pid0 = 0, int $mode = 1): array public function bindAgent(int $uuid, int $pid0 = 0, int $mode = 1): array
{ {
$user = $this->app->db->name('DataUser')->where(['id' => $uuid])->find(); $user = DataUser::mk()->where(['id' => $uuid])->find();
if (empty($user)) return [0, '用户查询失败']; if (empty($user)) return [0, '用户查询失败'];
if ($user['pids'] && in_array($mode, [0, 1])) return [1, '已经绑定代理']; if ($user['pids'] && in_array($mode, [0, 1])) return [1, '已经绑定代理'];
// 检查代理用户 // 检查代理用户
@ -42,7 +46,7 @@ class UserUpgradeService extends Service
if (empty($pid0)) return [0, '绑定的代理不存在']; if (empty($pid0)) return [0, '绑定的代理不存在'];
if ($uuid == $pid0) return [0, '不能绑定自己为代理']; if ($uuid == $pid0) return [0, '不能绑定自己为代理'];
// 检查代理资格 // 检查代理资格
$agent = $this->app->db->name('DataUser')->where(['id' => $pid0])->find(); $agent = DataUser::mk()->where(['id' => $pid0])->find();
if (empty($agent['vip_code'])) return [0, '代理无推荐资格']; if (empty($agent['vip_code'])) return [0, '代理无推荐资格'];
if (stripos($agent['path'], "-{$uuid}-") !== false) return [0, '不能绑定下属']; if (stripos($agent['path'], "-{$uuid}-") !== false) return [0, '不能绑定下属'];
// 组装代理数据 // 组装代理数据
@ -51,16 +55,16 @@ class UserUpgradeService extends Service
$this->app->db->transaction(function () use ($user, $agent, $mode) { $this->app->db->transaction(function () use ($user, $agent, $mode) {
// 更新用户代理 // 更新用户代理
$path1 = rtrim($agent['path'] ?: '-', '-') . "-{$agent['id']}-"; $path1 = rtrim($agent['path'] ?: '-', '-') . "-{$agent['id']}-";
$this->app->db->name('DataUser')->where(['id' => $user['id']])->update([ DataUser::mk()->where(['id' => $user['id']])->update([
'pid0' => $agent['id'], 'pid1' => $agent['id'], 'pid2' => $agent['pid1'], 'pid0' => $agent['id'], 'pid1' => $agent['id'], 'pid2' => $agent['pid1'],
'pids' => $mode > 0 ? 1 : 0, 'path' => $path1, 'layer' => substr_count($path1, '-'), 'pids' => $mode > 0 ? 1 : 0, 'path' => $path1, 'layer' => substr_count($path1, '-'),
]); ]);
// 更新下级代理 // 更新下级代理
$path2 = "{$user['path']}{$user['id']}-"; $path2 = "{$user['path']}{$user['id']}-";
if ($this->app->db->name('DataUser')->whereLike('path', "{$path2}%")->count() > 0) { if (DataUser::mk()->whereLike('path', "{$path2}%")->count() > 0) {
foreach ($this->app->db->name('DataUser')->whereLike('path', "{$path2}%")->order('layer desc')->select() as $vo) { foreach (DataUser::mk()->whereLike('path', "{$path2}%")->order('layer desc')->select() as $vo) {
$attr = array_reverse(str2arr($path3 = preg_replace("#^{$path2}#", "{$path1}{$user['id']}-", $vo['path']), '-')); $attr = array_reverse(str2arr($path3 = preg_replace("#^{$path2}#", "{$path1}{$user['id']}-", $vo['path']), '-'));
$this->app->db->name('DataUser')->where(['id' => $vo['id']])->update([ DataUser::mk()->where(['id' => $vo['id']])->update([
'pid0' => $attr[0] ?? 0, 'pid1' => $attr[0] ?? 0, 'pid2' => $attr[1] ?? 0, 'path' => $path3, 'layer' => substr_count($path3, '-'), 'pid0' => $attr[0] ?? 0, 'pid1' => $attr[0] ?? 0, 'pid2' => $attr[1] ?? 0, 'path' => $path3, 'layer' => substr_count($path3, '-'),
]); ]);
} }
@ -85,16 +89,16 @@ class UserUpgradeService extends Service
*/ */
public function upgrade(int $uuid, bool $parent = true, ?string $orderNo = null): bool public function upgrade(int $uuid, bool $parent = true, ?string $orderNo = null): bool
{ {
$user = $this->app->db->name('DataUser')->where(['id' => $uuid])->find(); $user = DataUser::mk()->where(['id' => $uuid])->find();
if (empty($user)) return true; if (empty($user)) return true;
// 初始化等级参数 // 初始化等级参数
$levels = $this->levels(); $levels = $this->levels();
[$vipName, $vipCode, $vipTeam] = [$levels[0]['name'] ?? '普通用户', 0, []]; [$vipName, $vipCode, $vipTeam] = [$levels[0]['name'] ?? '普通用户', 0, []];
// 统计用户数据 // 统计用户数据
foreach ($levels as $key => $level) if ($level['upgrade_team'] === 1) $vipTeam[] = $key; foreach ($levels as $key => $level) if ($level['upgrade_team'] === 1) $vipTeam[] = $key;
$orderAmount = $this->app->db->name('ShopOrder')->where("uuid={$uuid} and status>=4")->sum('amount_total'); $orderAmount = ShopOrder::mk()->where("uuid={$uuid} and status>=4")->sum('amount_total');
$teamsDirect = $this->app->db->name('DataUser')->where(['pid1' => $uuid])->whereIn('vip_code', $vipTeam)->count(); $teamsDirect = DataUser::mk()->where(['pid1' => $uuid])->whereIn('vip_code', $vipTeam)->count();
$teamsIndirect = $this->app->db->name('DataUser')->where(['pid2' => $uuid])->whereIn('vip_code', $vipTeam)->count(); $teamsIndirect = DataUser::mk()->where(['pid2' => $uuid])->whereIn('vip_code', $vipTeam)->count();
$teamsUsers = $teamsDirect + $teamsIndirect; $teamsUsers = $teamsDirect + $teamsIndirect;
// 动态计算用户等级 // 动态计算用户等级
foreach ($levels as $item) { foreach ($levels as $item) {
@ -113,7 +117,7 @@ class UserUpgradeService extends Service
} }
} }
// 购买入会商品升级 // 购买入会商品升级
$query = $this->app->db->name('ShopOrderItem')->alias('b')->join('shop_order a', 'b.order_no=a.order_no'); $query = ShopOrderItem::mk()->alias('b')->join('shop_order a', 'b.order_no=a.order_no');
$tmpCode = $query->whereRaw("a.uuid={$uuid} and a.payment_status=1 and a.status>=4 and b.vip_entry=1")->max('b.vip_upgrade'); $tmpCode = $query->whereRaw("a.uuid={$uuid} and a.payment_status=1 and a.status>=4 and b.vip_entry=1")->max('b.vip_upgrade');
if ($tmpCode > $vipCode && isset($levels[$tmpCode])) { if ($tmpCode > $vipCode && isset($levels[$tmpCode])) {
[$vipName, $vipCode] = [$levels[$tmpCode]['name'], $levels[$tmpCode]['number']]; [$vipName, $vipCode] = [$levels[$tmpCode]['name'], $levels[$tmpCode]['number']];
@ -121,14 +125,14 @@ class UserUpgradeService extends Service
$orderNo = null; $orderNo = null;
} }
// 后台余额充值升级 // 后台余额充值升级
$tmpCode = $this->app->db->name('DataUserBalance')->where(['uuid' => $uuid, 'deleted' => 0])->max('upgrade'); $tmpCode = DataUserBalance::mk()->where(['uuid' => $uuid, 'deleted' => 0])->max('upgrade');
if ($tmpCode > $vipCode && isset($levels[$tmpCode])) { if ($tmpCode > $vipCode && isset($levels[$tmpCode])) {
[$vipName, $vipCode] = [$levels[$tmpCode]['name'], $levels[$tmpCode]['number']]; [$vipName, $vipCode] = [$levels[$tmpCode]['name'], $levels[$tmpCode]['number']];
} }
// 统计用户订单金额 // 统计用户订单金额
$orderAmountTotal = $this->app->db->name('ShopOrder')->whereRaw("uuid={$uuid} and status>=4")->sum('amount_goods'); $orderAmountTotal = ShopOrder::mk()->whereRaw("uuid={$uuid} and status>=4")->sum('amount_goods');
$teamsAmountDirect = $this->app->db->name('ShopOrder')->whereRaw("puid1={$uuid} and status>=4")->sum('amount_goods'); $teamsAmountDirect = ShopOrder::mk()->whereRaw("puid1={$uuid} and status>=4")->sum('amount_goods');
$teamsAmountIndirect = $this->app->db->name('ShopOrder')->whereRaw("puid2={$uuid} and status>=4")->sum('amount_goods'); $teamsAmountIndirect = ShopOrder::mk()->whereRaw("puid2={$uuid} and status>=4")->sum('amount_goods');
// 更新用户团队数据 // 更新用户团队数据
$data = [ $data = [
'vip_name' => $vipName, 'vip_name' => $vipName,
@ -143,7 +147,7 @@ class UserUpgradeService extends Service
]; ];
if (!empty($orderNo)) $data['vip_order'] = $orderNo; if (!empty($orderNo)) $data['vip_order'] = $orderNo;
if ($data['vip_code'] !== $user['vip_code']) $data['vip_datetime'] = date('Y-m-d H:i:s'); if ($data['vip_code'] !== $user['vip_code']) $data['vip_datetime'] = date('Y-m-d H:i:s');
$this->app->db->name('DataUser')->where(['id' => $uuid])->update($data); DataUser::mk()->where(['id' => $uuid])->update($data);
// 用户升级事件 // 用户升级事件
if ($user['vip_code'] < $vipCode) $this->app->event->trigger('UserUpgradeLevel', [ if ($user['vip_code'] < $vipCode) $this->app->event->trigger('UserUpgradeLevel', [
'uuid' => $user['id'], 'order_no' => $orderNo, 'vip_code_old' => $user['vip_code'], 'vip_code_new' => $vipCode, 'uuid' => $user['id'], 'order_no' => $orderNo, 'vip_code_old' => $user['vip_code'], 'vip_code_new' => $vipCode,

View File

@ -2,8 +2,13 @@
namespace app\data\service\payment; namespace app\data\service\payment;
use AliPay\App;
use AliPay\Wap;
use AliPay\Web;
use app\data\service\PaymentService; use app\data\service\PaymentService;
use think\admin\Exception; use think\admin\Exception;
use WeChat\Exceptions\InvalidResponseException;
use WeChat\Exceptions\LocalCacheException;
/** /**
* 支付宝支付基础服务 * 支付宝支付基础服务
@ -48,11 +53,11 @@ class AlipayPaymentService extends PaymentService
} }
} }
if ($tradeType === static::PAYMENT_WECHAT_APP) { if ($tradeType === static::PAYMENT_WECHAT_APP) {
$payment = \AliPay\App::instance($this->config); $payment = App::instance($this->config);
} elseif ($tradeType === static::PAYMENT_ALIPAY_WAP) { } elseif ($tradeType === static::PAYMENT_ALIPAY_WAP) {
$payment = \AliPay\Wap::instance($this->config); $payment = Wap::instance($this->config);
} elseif ($tradeType === static::PAYMENT_ALIPAY_WEB) { } elseif ($tradeType === static::PAYMENT_ALIPAY_WEB) {
$payment = \AliPay\Web::instance($this->config); $payment = Web::instance($this->config);
} else { } else {
throw new Exception("支付类型[{$tradeType}]暂时不支持!"); throw new Exception("支付类型[{$tradeType}]暂时不支持!");
} }
@ -80,7 +85,7 @@ class AlipayPaymentService extends PaymentService
*/ */
public function notify(): string public function notify(): string
{ {
$notify = \AliPay\App::instance($this->config)->notify(); $notify = App::instance($this->config)->notify();
if (in_array($notify['trade_status'], ['TRADE_SUCCESS', 'TRADE_FINISHED'])) { if (in_array($notify['trade_status'], ['TRADE_SUCCESS', 'TRADE_FINISHED'])) {
if ($this->updatePaymentAction($notify['out_trade_no'], $notify['trade_no'], $notify['total_amount'])) { if ($this->updatePaymentAction($notify['out_trade_no'], $notify['trade_no'], $notify['total_amount'])) {
return 'success'; return 'success';
@ -96,12 +101,12 @@ class AlipayPaymentService extends PaymentService
* 查询订单数据 * 查询订单数据
* @param string $orderNo * @param string $orderNo
* @return array * @return array
* @throws \WeChat\Exceptions\InvalidResponseException * @throws InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException * @throws LocalCacheException
*/ */
public function query(string $orderNo): array public function query(string $orderNo): array
{ {
return \AliPay\App::instance($this->config)->query($orderNo); return App::instance($this->config)->query($orderNo);
} }
/** /**

View File

@ -2,6 +2,8 @@
namespace app\data\service\payment; namespace app\data\service\payment;
use app\data\model\DataUserBalance;
use app\data\model\ShopOrder;
use app\data\service\PaymentService; use app\data\service\PaymentService;
use app\data\service\UserBalanceService; use app\data\service\UserBalanceService;
use think\admin\Exception; use think\admin\Exception;
@ -43,14 +45,14 @@ class BalancePyamentService extends PaymentService
* @param string $paymentReturn 完成回跳地址 * @param string $paymentReturn 完成回跳地址
* @param string $paymentImage 支付凭证图片 * @param string $paymentImage 支付凭证图片
* @return array * @return array
* @throws Exception * @throws \think\admin\Exception
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
public function create(string $openid, string $orderNo, string $paymentAmount, string $paymentTitle, string $paymentRemark, string $paymentReturn = '', string $paymentImage = ''): array public function create(string $openid, string $orderNo, string $paymentAmount, string $paymentTitle, string $paymentRemark, string $paymentReturn = '', string $paymentImage = ''): array
{ {
$order = $this->app->db->name('ShopOrder')->where(['order_no' => $orderNo])->find(); $order = ShopOrder::mk()->where(['order_no' => $orderNo])->find();
if (empty($order)) throw new Exception("订单不存在"); if (empty($order)) throw new Exception("订单不存在");
if ($order['status'] !== 2) throw new Exception("不可发起支付"); if ($order['status'] !== 2) throw new Exception("不可发起支付");
// 创建支付行为 // 创建支付行为
@ -62,11 +64,11 @@ class BalancePyamentService extends PaymentService
// 扣减用户余额 // 扣减用户余额
$this->app->db->transaction(function () use ($order, $paymentAmount) { $this->app->db->transaction(function () use ($order, $paymentAmount) {
// 更新订单余额 // 更新订单余额
$this->app->db->name('ShopOrder')->where(['order_no' => $order['order_no']])->update([ ShopOrder::mk()->where(['order_no' => $order['order_no']])->update([
'payment_balance' => $paymentAmount, 'payment_balance' => $paymentAmount,
]); ]);
// 扣除余额金额 // 扣除余额金额
data_save('DataUserBalance', [ data_save(DataUserBalance::mk(), [
'uuid' => $order['uuid'], 'uuid' => $order['uuid'],
'code' => "KC{$order['order_no']}", 'code' => "KC{$order['order_no']}",
'name' => "账户余额支付", 'name' => "账户余额支付",

View File

@ -2,12 +2,10 @@
namespace app\data\service\payment; namespace app\data\service\payment;
use app\data\model\ShopOrder;
use app\data\service\PaymentService; use app\data\service\PaymentService;
use think\admin\Exception; use think\admin\Exception;
use think\admin\extend\CodeExtend; use think\admin\extend\CodeExtend;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/** /**
* 空支付支付 * 空支付支付
@ -46,14 +44,14 @@ class EmptyPaymentService extends PaymentService
* @param string $paymentReturn 完成回跳地址 * @param string $paymentReturn 完成回跳地址
* @param string $paymentImage 支付凭证图片 * @param string $paymentImage 支付凭证图片
* @return array * @return array
* @throws Exception * @throws \think\admin\Exception
* @throws DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws DbException * @throws \think\db\exception\DbException
* @throws ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
public function create(string $openid, string $orderNo, string $paymentAmount, string $paymentTitle, string $paymentRemark, string $paymentReturn = '', string $paymentImage = ''): array public function create(string $openid, string $orderNo, string $paymentAmount, string $paymentTitle, string $paymentRemark, string $paymentReturn = '', string $paymentImage = ''): array
{ {
$order = $this->app->db->name('ShopOrder')->where(['order_no' => $orderNo])->find(); $order = ShopOrder::mk()->where(['order_no' => $orderNo])->find();
if (empty($order)) throw new Exception("订单不存在"); if (empty($order)) throw new Exception("订单不存在");
if ($order['status'] !== 2) throw new Exception("不可发起支付"); if ($order['status'] !== 2) throw new Exception("不可发起支付");
// 创建支付行为 // 创建支付行为

View File

@ -2,6 +2,7 @@
namespace app\data\service\payment; namespace app\data\service\payment;
use app\data\model\ShopOrder;
use app\data\service\PaymentService; use app\data\service\PaymentService;
use think\admin\Exception; use think\admin\Exception;
use think\admin\extend\CodeExtend; use think\admin\extend\CodeExtend;
@ -42,14 +43,14 @@ class VoucherPaymentService extends PaymentService
* @param string $paymentReturn 完成回跳地址 * @param string $paymentReturn 完成回跳地址
* @param string $paymentImage 支付凭证图片 * @param string $paymentImage 支付凭证图片
* @return array * @return array
* @throws Exception * @throws \think\admin\Exception
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
public function create(string $openid, string $orderNo, string $paymentAmount, string $paymentTitle, string $paymentRemark, string $paymentReturn = '', string $paymentImage = ''): array public function create(string $openid, string $orderNo, string $paymentAmount, string $paymentTitle, string $paymentRemark, string $paymentReturn = '', string $paymentImage = ''): array
{ {
$order = $this->app->db->name('ShopOrder')->where(['order_no' => $orderNo])->find(); $order = ShopOrder::mk()->where(['order_no' => $orderNo])->find();
if (empty($order)) throw new Exception("订单不存在"); if (empty($order)) throw new Exception("订单不存在");
if ($order['status'] !== 2) throw new Exception("不可发起支付"); if ($order['status'] !== 2) throw new Exception("不可发起支付");
if (empty($paymentImage)) throw new Exception('支付凭证不能为空'); if (empty($paymentImage)) throw new Exception('支付凭证不能为空');