代码优化提交
This commit is contained in:
@@ -418,7 +418,7 @@ class WebSocketController extends BaseController
|
||||
$momentEntity = $moment['momentEntity'] ?? [];
|
||||
|
||||
// 检查朋友圈数据是否已存在
|
||||
$exists = Db::name('wechat_moments')
|
||||
$exists = Db::table('s2_wechat_moments')
|
||||
->where('snsId', $moment['snsId'])
|
||||
->where('wechatAccountId', $wechatAccountId)
|
||||
->find();
|
||||
@@ -441,13 +441,13 @@ class WebSocketController extends BaseController
|
||||
|
||||
if ($exists) {
|
||||
// 如果已存在,则更新数据
|
||||
Db::name('wechat_moments')->where('id', $exists['id'])->update($dataToSave);
|
||||
Db::table('s2_wechat_moments')->where('id', $exists['id'])->update($dataToSave);
|
||||
} else {
|
||||
// 如果不存在,则插入新数据
|
||||
$dataToSave['wechatAccountId'] = $wechatAccountId;
|
||||
$dataToSave['wechatFriendId'] = $wechatFriendId;
|
||||
$dataToSave['create_time'] = time();
|
||||
Db::name('wechat_moments')->insert($dataToSave);
|
||||
Db::table('s2_wechat_moments')->insert($dataToSave);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,9 +70,10 @@ class GetDeviceListV1Controller extends BaseController
|
||||
protected function getDeviceList(array $where, int $page = 1, int $limit = 10): \think\Paginator
|
||||
{
|
||||
$query = DeviceModel::alias('d')
|
||||
->field(['d.id', 'd.imei', 'd.memo', 'l.wechatId', 'd.alive', '0 totalFriend'])
|
||||
->field(['d.id', 'd.imei', 'd.memo', 'l.wechatId', 'd.alive','wa.nickname','wa.alias', '0 totalFriend'])
|
||||
->leftJoin('device_wechat_login l', 'd.id = l.deviceId')
|
||||
->order('d.alive desc');
|
||||
->leftJoin('wechat_account wa', 'l.wechatId = wa.wechatId')
|
||||
->order('d.id desc');
|
||||
|
||||
foreach ($where as $key => $value) {
|
||||
if (is_numeric($key) && is_array($value) && isset($value[0]) && $value[0] === 'exp') {
|
||||
|
||||
@@ -38,4 +38,11 @@ Route::group('v1/store', function () {
|
||||
Route::get('customer-analysis', 'app\\store\\controller\\StatisticsController@getCustomerAnalysis'); // 获取客户分析数据
|
||||
Route::get('interaction-analysis', 'app\\store\\controller\\StatisticsController@getInteractionAnalysis'); // 获取互动分析数据
|
||||
});
|
||||
|
||||
// 供应商相关路由
|
||||
Route::group('vendor', function () {
|
||||
Route::get('list', 'app\\store\\controller\\VendorController@getList'); // 获取供应商列表
|
||||
Route::get('detail', 'app\\store\\controller\\VendorController@detail'); // 获取供应商详情
|
||||
Route::post('order', 'app\\store\\controller\\VendorController@createOrder'); // 创建订单
|
||||
});
|
||||
})->middleware(['jwt']);
|
||||
@@ -19,7 +19,8 @@ class StatisticsController extends BaseController
|
||||
try {
|
||||
$companyId = $this->userInfo['companyId'];
|
||||
$wechatAccountId = $this->device['wechatAccountId'];
|
||||
|
||||
$ownerWechatId = $this->device['wechatId'];
|
||||
|
||||
// 获取时间范围
|
||||
$timeRange = $this->getTimeRange();
|
||||
$startTime = $timeRange['start_time'];
|
||||
@@ -27,40 +28,44 @@ class StatisticsController extends BaseController
|
||||
$lastStartTime = $timeRange['last_start_time'];
|
||||
$lastEndTime = $timeRange['last_end_time'];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 1. 总客户数
|
||||
$totalCustomers = WechatFriendModel::where(['ownerWechatId'=> $wechatAccountId])
|
||||
$totalCustomers = WechatFriendModel::where(['ownerWechatId'=> $ownerWechatId])
|
||||
->whereTime('createTime', '>=', $startTime)
|
||||
->whereTime('createTime', '<', $endTime)
|
||||
->count();
|
||||
|
||||
// 上期总客户数
|
||||
$lastTotalCustomers = WechatFriendModel::where(['ownerWechatId'=> $wechatAccountId])
|
||||
$lastTotalCustomers = WechatFriendModel::where(['ownerWechatId'=> $ownerWechatId])
|
||||
->whereTime('createTime', '>=', $lastStartTime)
|
||||
->whereTime('createTime', '<', $lastEndTime)
|
||||
->count();
|
||||
|
||||
// 2. 新增客户数
|
||||
$newCustomers = WechatFriendModel::where(['ownerWechatId'=> $wechatAccountId])
|
||||
$newCustomers = WechatFriendModel::where(['ownerWechatId'=> $ownerWechatId])
|
||||
->whereTime('createTime', '>=', $startTime)
|
||||
->whereTime('createTime', '<', $endTime)
|
||||
->count();
|
||||
|
||||
// 上期新增客户数
|
||||
$lastNewCustomers = WechatFriendModel::where(['ownerWechatId'=> $wechatAccountId])
|
||||
$lastNewCustomers = WechatFriendModel::where(['ownerWechatId'=> $ownerWechatId])
|
||||
->whereTime('createTime', '>=', $lastStartTime)
|
||||
->whereTime('createTime', '<', $lastEndTime)
|
||||
->count();
|
||||
|
||||
//3. 互动次数
|
||||
$interactionCount = WechatMessageModel::where(['wechatAccountId'=> $wechatAccountId])
|
||||
->where('createTime', '>=', strtotime($startTime))
|
||||
->where('createTime', '<', strtotime($endTime))
|
||||
->where('createTime', '>=', $startTime)
|
||||
->where('createTime', '<', $endTime)
|
||||
->count();
|
||||
|
||||
// 上期互动次数
|
||||
$lastInteractionCount = WechatMessageModel::where(['wechatAccountId'=> $wechatAccountId])
|
||||
->where('createTime', '>=', strtotime($lastStartTime))
|
||||
->where('createTime', '<', strtotime($lastEndTime))
|
||||
->where('createTime', '>=', $lastStartTime)
|
||||
->where('createTime', '<', $lastEndTime)
|
||||
->count();
|
||||
|
||||
|
||||
@@ -99,6 +104,11 @@ class StatisticsController extends BaseController
|
||||
try {
|
||||
$companyId = $this->userInfo['companyId'];
|
||||
$wechatAccountId = $this->device['wechatAccountId'];
|
||||
$ownerWechatId = $this->device['wechatId'];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 获取时间范围
|
||||
$timeRange = $this->getTimeRange();
|
||||
@@ -106,34 +116,36 @@ class StatisticsController extends BaseController
|
||||
$endTime = $timeRange['end_time'];
|
||||
|
||||
// 1. 客户增长趋势数据
|
||||
$totalCustomers = WechatFriendModel::where(['ownerWechatId'=> $wechatAccountId])
|
||||
$totalCustomers = WechatFriendModel::where(['ownerWechatId'=> $ownerWechatId])
|
||||
->whereTime('createTime', '<', $endTime)
|
||||
->count();
|
||||
|
||||
$newCustomers = WechatFriendModel::where(['ownerWechatId'=> $wechatAccountId])
|
||||
$newCustomers = WechatFriendModel::where(['ownerWechatId'=> $ownerWechatId])
|
||||
->whereTime('createTime', '>=', $startTime)
|
||||
->whereTime('createTime', '<', $endTime)
|
||||
->count();
|
||||
|
||||
// 计算流失客户数(假设超过30天未互动的客户为流失客户)
|
||||
$lostCustomers = WechatFriendModel::where(['ownerWechatId'=> $wechatAccountId])->where('createTime','>',0)
|
||||
->whereTime('deleteTime', '<', date('Y-m-d', strtotime('-30 days')))
|
||||
$thirtyDaysAgo = strtotime('-30 days');
|
||||
$lostCustomers = WechatFriendModel::where(['ownerWechatId'=> $ownerWechatId])
|
||||
->where('createTime', '>', 0)
|
||||
->where('deleteTime', '<', $thirtyDaysAgo)
|
||||
->count();
|
||||
|
||||
// 2. 客户来源分布数据
|
||||
// 朋友推荐
|
||||
$friendRecommend = WechatFriendModel::where(['ownerWechatId'=> $wechatAccountId])
|
||||
->whereIn('addFrom', [17, 1000017])
|
||||
$friendRecommend = WechatFriendModel::where(['ownerWechatId'=> $ownerWechatId])
|
||||
// ->whereIn('addFrom', [17, 1000017])
|
||||
->count();
|
||||
|
||||
// 微信搜索
|
||||
$wechatSearch = WechatFriendModel::where(['ownerWechatId'=> $wechatAccountId])
|
||||
->whereIn('addFrom', [3, 15, 1000003, 1000015])
|
||||
$wechatSearch = WechatFriendModel::where(['ownerWechatId'=> $ownerWechatId])
|
||||
// ->whereIn('addFrom', [3, 15, 1000003, 1000015])
|
||||
->count();
|
||||
|
||||
// 微信群
|
||||
$wechatGroup = WechatFriendModel::where(['ownerWechatId'=> $wechatAccountId])
|
||||
->whereIn('addFrom', [14, 1000014])
|
||||
$wechatGroup = WechatFriendModel::where(['ownerWechatId'=> $ownerWechatId])
|
||||
// ->whereIn('addFrom', [14, 1000014])
|
||||
->count();
|
||||
|
||||
// 其他渠道(总数减去已知渠道)
|
||||
@@ -198,15 +210,15 @@ class StatisticsController extends BaseController
|
||||
$startTime = $timeRange['start_time'];
|
||||
$endTime = $timeRange['end_time'];
|
||||
|
||||
// 转换为时间戳
|
||||
$startTimestamp = strtotime($startTime);
|
||||
$endTimestamp = strtotime($endTime);
|
||||
// 不再需要转换为时间戳,因为getTimeRange已经转换
|
||||
// $startTimestamp = strtotime($startTime);
|
||||
// $endTimestamp = strtotime($endTime);
|
||||
|
||||
// 1. 互动频率分析
|
||||
// 高频互动用户数(每天3次以上)
|
||||
$highFrequencyUsers = WechatMessageModel::where(['wechatAccountId' => $wechatAccountId])
|
||||
->where('createTime', '>=', $startTimestamp)
|
||||
->where('createTime', '<', $endTimestamp)
|
||||
->where('createTime', '>=', $startTime)
|
||||
->where('createTime', '<', $endTime)
|
||||
->field('wechatFriendId, COUNT(*) as count')
|
||||
->group('wechatFriendId')
|
||||
->having('count > 3')
|
||||
@@ -214,8 +226,8 @@ class StatisticsController extends BaseController
|
||||
|
||||
// 中频互动用户数(每天1-3次)
|
||||
$midFrequencyUsers = WechatMessageModel::where(['wechatAccountId' => $wechatAccountId])
|
||||
->where('createTime', '>=', $startTimestamp)
|
||||
->where('createTime', '<', $endTimestamp)
|
||||
->where('createTime', '>=', $startTime)
|
||||
->where('createTime', '<', $endTime)
|
||||
->field('wechatFriendId, COUNT(*) as count')
|
||||
->group('wechatFriendId')
|
||||
->having('count >= 1 AND count <= 3')
|
||||
@@ -223,8 +235,8 @@ class StatisticsController extends BaseController
|
||||
|
||||
// 低频互动用户数(仅有1次)
|
||||
$lowFrequencyUsers = WechatMessageModel::where(['wechatAccountId' => $wechatAccountId])
|
||||
->where('createTime', '>=', $startTimestamp)
|
||||
->where('createTime', '<', $endTimestamp)
|
||||
->where('createTime', '>=', $startTime)
|
||||
->where('createTime', '<', $endTime)
|
||||
->field('wechatFriendId, COUNT(*) as count')
|
||||
->group('wechatFriendId')
|
||||
->having('count = 1')
|
||||
@@ -236,8 +248,8 @@ class StatisticsController extends BaseController
|
||||
'wechatAccountId' => $wechatAccountId,
|
||||
'msgType' => 1
|
||||
])
|
||||
->where('createTime', '>=', $startTimestamp)
|
||||
->where('createTime', '<', $endTimestamp)
|
||||
->where('createTime', '>=', $startTime)
|
||||
->where('createTime', '<', $endTime)
|
||||
->count();
|
||||
|
||||
// 图片互动数量
|
||||
@@ -245,8 +257,8 @@ class StatisticsController extends BaseController
|
||||
'wechatAccountId' => $wechatAccountId,
|
||||
'msgType' => 3
|
||||
])
|
||||
->where('createTime', '>=', $startTimestamp)
|
||||
->where('createTime', '<', $endTimestamp)
|
||||
->where('createTime', '>=', $startTime)
|
||||
->where('createTime', '<', $endTime)
|
||||
->count();
|
||||
|
||||
// 群聊互动数量
|
||||
@@ -254,16 +266,16 @@ class StatisticsController extends BaseController
|
||||
'wechatAccountId' => $wechatAccountId,
|
||||
'type' => 2
|
||||
])
|
||||
->where('createTime', '>=', $startTimestamp)
|
||||
->where('createTime', '<', $endTimestamp)
|
||||
->where('createTime', '>=', $startTime)
|
||||
->where('createTime', '<', $endTime)
|
||||
->count();
|
||||
|
||||
// 产品咨询数量 (通过消息内容模糊查询)
|
||||
$productInquiries = WechatMessageModel::where([
|
||||
'wechatAccountId' => $wechatAccountId
|
||||
])
|
||||
->where('createTime', '>=', $startTimestamp)
|
||||
->where('createTime', '<', $endTimestamp)
|
||||
->where('createTime', '>=', $startTime)
|
||||
->where('createTime', '<', $endTime)
|
||||
->where('content', 'like', '%产品%')
|
||||
->whereOr('content', 'like', '%价格%')
|
||||
->whereOr('content', 'like', '%购买%')
|
||||
@@ -304,8 +316,11 @@ class StatisticsController extends BaseController
|
||||
|
||||
/**
|
||||
* 获取时间范围
|
||||
*
|
||||
* @param bool $toTimestamp 是否将日期转为时间戳,默认为true
|
||||
* @return array 时间范围数组
|
||||
*/
|
||||
private function getTimeRange()
|
||||
private function getTimeRange($toTimestamp = true)
|
||||
{
|
||||
// 可选:today, yesterday, this_week, last_week, this_month, this_quarter, this_year
|
||||
$timeType = input('time_type', 'this_week');
|
||||
@@ -371,6 +386,14 @@ class StatisticsController extends BaseController
|
||||
$lastEndTime = $startTime;
|
||||
}
|
||||
|
||||
// 如果需要转换为时间戳
|
||||
if ($toTimestamp) {
|
||||
$startTime = strtotime($startTime);
|
||||
$endTime = strtotime($endTime);
|
||||
$lastStartTime = strtotime($lastStartTime);
|
||||
$lastEndTime = strtotime($lastEndTime);
|
||||
}
|
||||
|
||||
return [
|
||||
'start_time' => $startTime,
|
||||
'end_time' => $endTime,
|
||||
|
||||
@@ -29,9 +29,35 @@ class SystemConfigController extends BaseController
|
||||
return $this->error('设备不存在');
|
||||
}
|
||||
|
||||
// 获取已解析的配置
|
||||
$config = json_decode($this->device['taskConfig'], true);
|
||||
// 从新表中获取配置
|
||||
$config = Db::name('device_taskconf')
|
||||
->where('deviceId', $deviceId)
|
||||
->field('id,autoLike,autoCustomerDev,groupMessageDeliver,autoGroup,contentSync,aiChat,autoReply,momentsSync')
|
||||
->find();
|
||||
|
||||
// 如果没有找到配置,创建默认配置
|
||||
if (empty($config)) {
|
||||
$taskConfig = [
|
||||
'deviceId' => $deviceId,
|
||||
'autoLike' => 0,
|
||||
'autoCustomerDev' => 0,
|
||||
'groupMessageDeliver' => 0,
|
||||
'autoGroup' => 0,
|
||||
'contentSync' => 0,
|
||||
'aiChat' => 0,
|
||||
'autoReply' => 0,
|
||||
'momentsSync' => 0,
|
||||
'companyId' => $this->device['companyId'] ?? 0,
|
||||
'createTime' => time(),
|
||||
'updateTime' => time()
|
||||
];
|
||||
|
||||
// 添加到数据库
|
||||
Db::name('device_taskconf')->insert($taskConfig);
|
||||
|
||||
// 返回默认配置
|
||||
return successJson($taskConfig);
|
||||
}
|
||||
|
||||
// 返回开关状态
|
||||
return successJson($config);
|
||||
@@ -63,35 +89,58 @@ class SystemConfigController extends BaseController
|
||||
}
|
||||
|
||||
// 验证开关名称是否有效
|
||||
$validSwitches = ['autoLike', 'momentsSync', 'autoCustomerDev', 'groupMessageDeliver', 'autoGroup'];
|
||||
$validSwitches = ['autoLike', 'autoCustomerDev', 'groupMessageDeliver', 'autoGroup', 'contentSync', 'aiChat', 'autoReply', 'momentsSync'];
|
||||
if (!in_array($switchName, $validSwitches)) {
|
||||
return errorJson('无效的开关名称');
|
||||
}
|
||||
|
||||
// 获取当前配置并确保是数组
|
||||
$taskConfig = json_decode($this->device['taskConfig'], true);
|
||||
// 获取当前配置
|
||||
$taskConfig = Db::name('device_taskconf')
|
||||
->where('deviceId', $deviceId)
|
||||
->find();
|
||||
|
||||
// 更新指定开关状态
|
||||
$taskConfig[$switchName] = !$taskConfig[$switchName];
|
||||
$taskConfig = json_encode($taskConfig);
|
||||
|
||||
|
||||
|
||||
// 更新数据库
|
||||
$result = Db::table('s2_device')
|
||||
->where('id', $deviceId)
|
||||
->update([
|
||||
'taskConfig' => $taskConfig,
|
||||
// 如果没有找到配置,创建默认配置
|
||||
if (empty($taskConfig)) {
|
||||
$taskConfig = [
|
||||
'deviceId' => $deviceId,
|
||||
'autoLike' => 0,
|
||||
'autoCustomerDev' => 0,
|
||||
'groupMessageDeliver' => 0,
|
||||
'autoGroup' => 0,
|
||||
'contentSync' => 0,
|
||||
'aiChat' => 0,
|
||||
'autoReply' => 0,
|
||||
'momentsSync' => 0,
|
||||
'companyId' => $this->device['companyId'] ?? 0,
|
||||
'createTime' => time(),
|
||||
'updateTime' => time()
|
||||
]);
|
||||
];
|
||||
|
||||
if ($result === false) {
|
||||
Log::error("更新设备{$switchName}开关状态失败,设备ID:{$deviceId}");
|
||||
return errorJson('更新失败');
|
||||
// 设置要更新的开关
|
||||
$taskConfig[$switchName] = 1;
|
||||
|
||||
// 添加到数据库
|
||||
Db::name('device_taskconf')->insert($taskConfig);
|
||||
} else {
|
||||
// 更新指定开关状态
|
||||
$updateData = [
|
||||
$switchName => !$taskConfig[$switchName],
|
||||
'updateTime' => time()
|
||||
];
|
||||
|
||||
// 更新数据库
|
||||
$result = Db::name('device_taskconf')
|
||||
->where('deviceId', $deviceId)
|
||||
->update($updateData);
|
||||
|
||||
if ($result === false) {
|
||||
Log::error("更新设备{$switchName}开关状态失败,设备ID:{$deviceId}");
|
||||
return errorJson('更新失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 清除缓存
|
||||
$this->clearDeviceCache();
|
||||
$this->clearDeviceCache();
|
||||
|
||||
return successJson([], '更新成功');
|
||||
|
||||
@@ -99,4 +148,4 @@ class SystemConfigController extends BaseController
|
||||
return errorJson('系统错误'. $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
534
Server/application/store/controller/VendorController.php
Normal file
534
Server/application/store/controller/VendorController.php
Normal file
@@ -0,0 +1,534 @@
|
||||
<?php
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\store\model\VendorPackageModel;
|
||||
use app\store\model\VendorProjectModel;
|
||||
use app\store\model\VendorOrderModel;
|
||||
use think\facade\Log;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 套餐控制器
|
||||
*/
|
||||
class VendorController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取套餐列表
|
||||
*
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
try {
|
||||
$page = $this->request->param('page', 1);
|
||||
$limit = $this->request->param('limit', 10);
|
||||
$keyword = $this->request->param('keyword', '');
|
||||
$status = $this->request->param('status', '');
|
||||
|
||||
$where = [
|
||||
['isDel', '=', 0]
|
||||
];
|
||||
|
||||
// 关键词搜索
|
||||
if (!empty($keyword)) {
|
||||
$where[] = ['name', 'like', "%{$keyword}%"];
|
||||
}
|
||||
|
||||
// 状态筛选
|
||||
if ($status !== '') {
|
||||
$where[] = ['status', '=', $status];
|
||||
}
|
||||
|
||||
$list = VendorPackageModel::where($where)
|
||||
->order('id', 'desc')
|
||||
->page($page, $limit)
|
||||
->select();
|
||||
|
||||
$total = VendorPackageModel::where($where)->count();
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => [
|
||||
'list' => $list,
|
||||
'total' => $total,
|
||||
]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('获取套餐列表失败:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '获取失败:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取套餐详情
|
||||
*
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
try {
|
||||
$id = $this->request->param('id', 0);
|
||||
|
||||
if (empty($id)) {
|
||||
return json(['code' => 400, 'msg' => '参数错误']);
|
||||
}
|
||||
|
||||
// 查询套餐基本信息
|
||||
$package = VendorPackageModel::where([
|
||||
['id', '=', $id],
|
||||
['isDel', '=', 0]
|
||||
])->find();
|
||||
|
||||
if (empty($package)) {
|
||||
return json(['code' => 404, 'msg' => '套餐不存在']);
|
||||
}
|
||||
|
||||
// 查询项目列表
|
||||
$projects = VendorProjectModel::where([
|
||||
['packageId', '=', $id],
|
||||
['isDel', '=', 0]
|
||||
])->select();
|
||||
|
||||
$package['projects'] = $projects;
|
||||
|
||||
return json(['code' => 200, 'msg' => '获取成功', 'data' => $package]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('获取套餐详情失败:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '获取失败:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加套餐
|
||||
*
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
try {
|
||||
if (!$this->request->isPost()) {
|
||||
return json(['code' => 400, 'msg' => '请求方式错误']);
|
||||
}
|
||||
|
||||
$param = $this->request->post();
|
||||
|
||||
// 参数验证
|
||||
if (empty($param['name'])) {
|
||||
return json(['code' => 400, 'msg' => '套餐名称不能为空']);
|
||||
}
|
||||
|
||||
// 检查名称是否已存在
|
||||
$exists = VendorPackageModel::where([
|
||||
['name', '=', $param['name']],
|
||||
['isDel', '=', 0]
|
||||
])->find();
|
||||
|
||||
if ($exists) {
|
||||
return json(['code' => 400, 'msg' => '该套餐名称已存在']);
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 创建套餐
|
||||
$package = new VendorPackageModel;
|
||||
$package->name = $param['name'];
|
||||
$package->originalPrice = $param['originalPrice'] ?? 0;
|
||||
$package->price = $param['price'] ?? 0;
|
||||
$package->discount = $param['discount'] ?? 0;
|
||||
$package->advancePayment = $param['advancePayment'] ?? 0;
|
||||
$package->tags = $param['tags'] ?? '';
|
||||
$package->description = $param['description'] ?? '';
|
||||
$package->cover = $param['cover'] ?? '';
|
||||
$package->status = $param['status'] ?? 1;
|
||||
$package->createTime = time();
|
||||
$package->updateTime = time();
|
||||
$package->save();
|
||||
|
||||
// 处理项目信息
|
||||
if (!empty($param['projects']) && is_array($param['projects'])) {
|
||||
foreach ($param['projects'] as $projectData) {
|
||||
if (empty($projectData['name'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 创建项目
|
||||
$project = new VendorProjectModel;
|
||||
$project->packageId = $package->id;
|
||||
$project->name = $projectData['name'];
|
||||
$project->originalPrice = $projectData['originalPrice'] ?? 0;
|
||||
$project->price = $projectData['price'] ?? 0;
|
||||
$project->duration = $projectData['duration'] ?? 0;
|
||||
$project->image = $projectData['image'] ?? '';
|
||||
$project->detail = $projectData['detail'] ?? '';
|
||||
$project->createTime = time();
|
||||
$project->updateTime = time();
|
||||
$project->save();
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return json(['code' => 200, 'msg' => '添加成功', 'data' => ['id' => $package->id]]);
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
Log::error('添加套餐失败:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '添加失败:' . $e->getMessage()]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('添加套餐异常:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '添加异常:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑套餐
|
||||
*
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
try {
|
||||
if (!$this->request->isPost()) {
|
||||
return json(['code' => 400, 'msg' => '请求方式错误']);
|
||||
}
|
||||
|
||||
$param = $this->request->post();
|
||||
|
||||
// 参数验证
|
||||
if (empty($param['id'])) {
|
||||
return json(['code' => 400, 'msg' => '参数错误']);
|
||||
}
|
||||
|
||||
if (empty($param['name'])) {
|
||||
return json(['code' => 400, 'msg' => '套餐名称不能为空']);
|
||||
}
|
||||
|
||||
// 检查套餐是否存在
|
||||
$package = VendorPackageModel::where([
|
||||
['id', '=', $param['id']],
|
||||
['isDel', '=', 0]
|
||||
])->find();
|
||||
|
||||
if (!$package) {
|
||||
return json(['code' => 404, 'msg' => '套餐不存在']);
|
||||
}
|
||||
|
||||
// 检查名称是否已存在
|
||||
$exists = VendorPackageModel::where([
|
||||
['name', '=', $param['name']],
|
||||
['id', '<>', $param['id']],
|
||||
['isDel', '=', 0]
|
||||
])->find();
|
||||
|
||||
if ($exists) {
|
||||
return json(['code' => 400, 'msg' => '该套餐名称已存在']);
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 更新套餐
|
||||
$package->name = $param['name'];
|
||||
$package->originalPrice = $param['originalPrice'] ?? $package->originalPrice;
|
||||
$package->price = $param['price'] ?? $package->price;
|
||||
$package->discount = $param['discount'] ?? $package->discount;
|
||||
$package->advancePayment = $param['advancePayment'] ?? $package->advancePayment;
|
||||
$package->tags = $param['tags'] ?? $package->tags;
|
||||
$package->description = $param['description'] ?? $package->description;
|
||||
$package->cover = $param['cover'] ?? $package->cover;
|
||||
$package->status = $param['status'] ?? $package->status;
|
||||
$package->updateTime = time();
|
||||
$package->save();
|
||||
|
||||
Db::commit();
|
||||
return json(['code' => 200, 'msg' => '更新成功']);
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
Log::error('更新套餐失败:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '更新失败:' . $e->getMessage()]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('编辑套餐异常:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '编辑异常:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除套餐
|
||||
*
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
try {
|
||||
$id = $this->request->param('id', 0);
|
||||
|
||||
if (empty($id)) {
|
||||
return json(['code' => 400, 'msg' => '参数错误']);
|
||||
}
|
||||
|
||||
// 检查套餐是否存在
|
||||
$package = VendorPackageModel::where([
|
||||
['id', '=', $id],
|
||||
['isDel', '=', 0]
|
||||
])->find();
|
||||
|
||||
if (!$package) {
|
||||
return json(['code' => 404, 'msg' => '套餐不存在']);
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 软删除套餐
|
||||
$package->isDel = 1;
|
||||
$package->updateTime = time();
|
||||
$package->save();
|
||||
|
||||
// 软删除关联的项目
|
||||
VendorProjectModel::where('packageId', $id)
|
||||
->update([
|
||||
'isDel' => 1,
|
||||
'updateTime' => time()
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return json(['code' => 200, 'msg' => '删除成功']);
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
Log::error('删除套餐失败:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '删除失败:' . $e->getMessage()]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('删除套餐异常:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '删除异常:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加项目
|
||||
*
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function addProject()
|
||||
{
|
||||
try {
|
||||
if (!$this->request->isPost()) {
|
||||
return json(['code' => 400, 'msg' => '请求方式错误']);
|
||||
}
|
||||
|
||||
$param = $this->request->post();
|
||||
|
||||
// 参数验证
|
||||
if (empty($param['packageId'])) {
|
||||
return json(['code' => 400, 'msg' => '套餐ID不能为空']);
|
||||
}
|
||||
|
||||
if (empty($param['name'])) {
|
||||
return json(['code' => 400, 'msg' => '项目名称不能为空']);
|
||||
}
|
||||
|
||||
// 检查套餐是否存在
|
||||
$package = VendorPackageModel::where([
|
||||
['id', '=', $param['packageId']],
|
||||
['isDel', '=', 0]
|
||||
])->find();
|
||||
|
||||
if (!$package) {
|
||||
return json(['code' => 404, 'msg' => '套餐不存在']);
|
||||
}
|
||||
|
||||
try {
|
||||
// 创建项目
|
||||
$project = new VendorProjectModel;
|
||||
$project->packageId = $param['packageId'];
|
||||
$project->name = $param['name'];
|
||||
$project->originalPrice = $param['originalPrice'] ?? 0;
|
||||
$project->price = $param['price'] ?? 0;
|
||||
$project->duration = $param['duration'] ?? 0;
|
||||
$project->image = $param['image'] ?? '';
|
||||
$project->detail = $param['detail'] ?? '';
|
||||
$project->createTime = time();
|
||||
$project->updateTime = time();
|
||||
$project->save();
|
||||
|
||||
return json(['code' => 200, 'msg' => '添加成功', 'data' => ['id' => $project->id]]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('添加项目失败:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '添加失败:' . $e->getMessage()]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('添加项目异常:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '添加异常:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑项目
|
||||
*
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function editProject()
|
||||
{
|
||||
try {
|
||||
if (!$this->request->isPost()) {
|
||||
return json(['code' => 400, 'msg' => '请求方式错误']);
|
||||
}
|
||||
|
||||
$param = $this->request->post();
|
||||
|
||||
// 参数验证
|
||||
if (empty($param['id'])) {
|
||||
return json(['code' => 400, 'msg' => '项目ID不能为空']);
|
||||
}
|
||||
|
||||
if (empty($param['name'])) {
|
||||
return json(['code' => 400, 'msg' => '项目名称不能为空']);
|
||||
}
|
||||
|
||||
// 检查项目是否存在
|
||||
$project = VendorProjectModel::where([
|
||||
['id', '=', $param['id']],
|
||||
['isDel', '=', 0]
|
||||
])->find();
|
||||
|
||||
if (!$project) {
|
||||
return json(['code' => 404, 'msg' => '项目不存在']);
|
||||
}
|
||||
|
||||
try {
|
||||
// 更新项目
|
||||
$project->name = $param['name'];
|
||||
$project->originalPrice = $param['originalPrice'] ?? $project->originalPrice;
|
||||
$project->price = $param['price'] ?? $project->price;
|
||||
$project->duration = $param['duration'] ?? $project->duration;
|
||||
$project->image = $param['image'] ?? $project->image;
|
||||
$project->detail = $param['detail'] ?? $project->detail;
|
||||
$project->updateTime = time();
|
||||
$project->save();
|
||||
|
||||
return json(['code' => 200, 'msg' => '更新成功']);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('更新项目失败:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '更新失败:' . $e->getMessage()]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('编辑项目异常:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '编辑异常:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除项目
|
||||
*
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function deleteProject()
|
||||
{
|
||||
try {
|
||||
$id = $this->request->param('id', 0);
|
||||
|
||||
if (empty($id)) {
|
||||
return json(['code' => 400, 'msg' => '参数错误']);
|
||||
}
|
||||
|
||||
// 检查项目是否存在
|
||||
$project = VendorProjectModel::where([
|
||||
['id', '=', $id],
|
||||
['isDel', '=', 0]
|
||||
])->find();
|
||||
|
||||
if (!$project) {
|
||||
return json(['code' => 404, 'msg' => '项目不存在']);
|
||||
}
|
||||
|
||||
try {
|
||||
// 软删除项目
|
||||
$project->isDel = 1;
|
||||
$project->updateTime = time();
|
||||
$project->save();
|
||||
|
||||
return json(['code' => 200, 'msg' => '删除成功']);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('删除项目失败:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '删除失败:' . $e->getMessage()]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('删除项目异常:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '删除异常:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
*
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function createOrder()
|
||||
{
|
||||
try {
|
||||
if (!$this->request->isPost()) {
|
||||
return json(['code' => 400, 'msg' => '请求方式错误']);
|
||||
}
|
||||
|
||||
$param = $this->request->post();
|
||||
|
||||
// 参数验证
|
||||
if (empty($param['packageId'])) {
|
||||
return json(['code' => 400, 'msg' => '套餐ID不能为空']);
|
||||
}
|
||||
|
||||
// 检查套餐是否存在
|
||||
$package = VendorPackageModel::where([
|
||||
['id', '=', $param['packageId']],
|
||||
['isDel', '=', 0],
|
||||
['status', '=', 1]
|
||||
])->find();
|
||||
|
||||
if (!$package) {
|
||||
return json(['code' => 404, 'msg' => '套餐不存在或已下架']);
|
||||
}
|
||||
|
||||
// 获取当前用户信息
|
||||
$userId = $this->request->userInfo['id'];
|
||||
|
||||
if (empty($userId)) {
|
||||
return json(['code' => 401, 'msg' => '请先登录']);
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 生成订单
|
||||
$order = new VendorOrderModel;
|
||||
$order->orderNo = VendorOrderModel::generateOrderNo();
|
||||
$order->userId = $userId;
|
||||
$order->packageId = $package->id;
|
||||
$order->packageName = $package->name;
|
||||
$order->totalAmount = $package->price;
|
||||
$order->payAmount = $package->price;
|
||||
$order->advancePayment = $package->advancePayment;
|
||||
$order->status = VendorOrderModel::STATUS_UNPAID;
|
||||
$order->remark = $param['remark'] ?? '';
|
||||
$order->createTime = time();
|
||||
$order->updateTime = time();
|
||||
$order->save();
|
||||
|
||||
Db::commit();
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '订单创建成功',
|
||||
'data' => [
|
||||
'orderId' => $order->id,
|
||||
'orderNo' => $order->orderNo
|
||||
]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
Log::error('创建订单失败:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '创建订单失败:' . $e->getMessage()]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('创建订单异常:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '创建订单异常:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
229
Server/application/store/controller/VendorOrderController.php
Normal file
229
Server/application/store/controller/VendorOrderController.php
Normal file
@@ -0,0 +1,229 @@
|
||||
<?php
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\store\model\VendorPackageModel;
|
||||
use app\store\model\VendorProjectModel;
|
||||
use app\store\model\VendorOrderModel;
|
||||
use think\facade\Log;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 订单控制器
|
||||
*/
|
||||
class VendorOrderController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取订单列表
|
||||
*
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
try {
|
||||
$page = $this->request->param('page', 1);
|
||||
$limit = $this->request->param('limit', 10);
|
||||
$status = $this->request->param('status', '');
|
||||
$keyword = $this->request->param('keyword', '');
|
||||
|
||||
// 获取当前用户信息
|
||||
$userId = $this->request->userInfo['id'];
|
||||
|
||||
$where = [
|
||||
['userId', '=', $userId]
|
||||
];
|
||||
|
||||
// 关键词搜索
|
||||
if (!empty($keyword)) {
|
||||
$where[] = ['orderNo|packageName', 'like', "%{$keyword}%"];
|
||||
}
|
||||
|
||||
// 状态筛选
|
||||
if ($status !== '') {
|
||||
$where[] = ['status', '=', $status];
|
||||
}
|
||||
|
||||
$list = VendorOrderModel::with(['package'])
|
||||
->where($where)
|
||||
->order('id', 'desc')
|
||||
->page($page, $limit)
|
||||
->select();
|
||||
|
||||
$total = VendorOrderModel::where($where)->count();
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => [
|
||||
'list' => $list,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'limit' => $limit
|
||||
]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('获取订单列表失败:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '获取失败:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单详情
|
||||
*
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
try {
|
||||
$id = $this->request->param('id', 0);
|
||||
|
||||
if (empty($id)) {
|
||||
return json(['code' => 400, 'msg' => '参数错误']);
|
||||
}
|
||||
|
||||
// 获取当前用户信息
|
||||
$userId = $this->request->userInfo['id'];
|
||||
|
||||
// 查询订单
|
||||
$order = VendorOrderModel::with(['package'])
|
||||
->where([
|
||||
['id', '=', $id],
|
||||
['userId', '=', $userId]
|
||||
])->find();
|
||||
|
||||
if (empty($order)) {
|
||||
return json(['code' => 404, 'msg' => '订单不存在']);
|
||||
}
|
||||
|
||||
// 查询套餐项目
|
||||
if (!empty($order['package'])) {
|
||||
$projects = VendorProjectModel::where([
|
||||
['packageId', '=', $order['packageId']],
|
||||
['isDel', '=', 0]
|
||||
])->select();
|
||||
|
||||
$order['package']['projects'] = $projects;
|
||||
}
|
||||
|
||||
return json(['code' => 200, 'msg' => '获取成功', 'data' => $order]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('获取订单详情失败:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '获取失败:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新订单状态
|
||||
*
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function updateStatus()
|
||||
{
|
||||
try {
|
||||
if (!$this->request->isPost()) {
|
||||
return json(['code' => 400, 'msg' => '请求方式错误']);
|
||||
}
|
||||
|
||||
$param = $this->request->post();
|
||||
|
||||
// 参数验证
|
||||
if (empty($param['id'])) {
|
||||
return json(['code' => 400, 'msg' => '订单ID不能为空']);
|
||||
}
|
||||
|
||||
if (!isset($param['status'])) {
|
||||
return json(['code' => 400, 'msg' => '订单状态不能为空']);
|
||||
}
|
||||
|
||||
// 检查订单是否存在
|
||||
$order = VendorOrderModel::where('id', $param['id'])->find();
|
||||
|
||||
if (!$order) {
|
||||
return json(['code' => 404, 'msg' => '订单不存在']);
|
||||
}
|
||||
|
||||
// 检查状态是否有效
|
||||
$validStatus = [
|
||||
VendorOrderModel::STATUS_UNPAID,
|
||||
VendorOrderModel::STATUS_PAID,
|
||||
VendorOrderModel::STATUS_COMPLETED,
|
||||
VendorOrderModel::STATUS_CANCELED
|
||||
];
|
||||
|
||||
if (!in_array($param['status'], $validStatus)) {
|
||||
return json(['code' => 400, 'msg' => '无效的订单状态']);
|
||||
}
|
||||
|
||||
// 更新订单状态
|
||||
$updateData = [
|
||||
'status' => $param['status'],
|
||||
'updateTime' => time()
|
||||
];
|
||||
|
||||
// 如果订单状态为已支付,记录支付时间
|
||||
if ($param['status'] == VendorOrderModel::STATUS_PAID) {
|
||||
$updateData['payTime'] = time();
|
||||
}
|
||||
|
||||
try {
|
||||
$order->save($updateData);
|
||||
return json(['code' => 200, 'msg' => '更新成功']);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('更新订单状态失败:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '更新失败:' . $e->getMessage()]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('更新订单状态异常:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '更新异常:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消订单
|
||||
*
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function cancel()
|
||||
{
|
||||
try {
|
||||
if (!$this->request->isPost()) {
|
||||
return json(['code' => 400, 'msg' => '请求方式错误']);
|
||||
}
|
||||
|
||||
$id = $this->request->param('id', 0);
|
||||
|
||||
if (empty($id)) {
|
||||
return json(['code' => 400, 'msg' => '参数错误']);
|
||||
}
|
||||
|
||||
// 获取当前用户信息
|
||||
$userId = $this->request->userInfo['id'];
|
||||
|
||||
// 检查订单是否存在
|
||||
$order = VendorOrderModel::where([
|
||||
['id', '=', $id],
|
||||
['userId', '=', $userId],
|
||||
['status', '=', VendorOrderModel::STATUS_UNPAID]
|
||||
])->find();
|
||||
|
||||
if (!$order) {
|
||||
return json(['code' => 404, 'msg' => '订单不存在或状态不允许取消']);
|
||||
}
|
||||
|
||||
try {
|
||||
// 更新订单状态为已取消
|
||||
$order->status = VendorOrderModel::STATUS_CANCELED;
|
||||
$order->updateTime = time();
|
||||
$order->save();
|
||||
|
||||
return json(['code' => 200, 'msg' => '取消成功']);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('取消订单失败:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '取消失败:' . $e->getMessage()]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('取消订单异常:' . $e->getMessage());
|
||||
return json(['code' => 500, 'msg' => '取消异常:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Server/application/store/model/VendorModel.php
Normal file
34
Server/application/store/model/VendorModel.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 供应商模型
|
||||
*/
|
||||
class VendorModel extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $table = 's2_vendor';
|
||||
|
||||
// 主键
|
||||
protected $pk = 'id';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
|
||||
// 隐藏字段
|
||||
protected $hidden = ['isDel'];
|
||||
|
||||
/**
|
||||
* 与套餐的关联
|
||||
*/
|
||||
public function packages()
|
||||
{
|
||||
return $this->hasMany('VendorPackageModel', 'vendorId', 'id')
|
||||
->where('isDel', 0);
|
||||
}
|
||||
}
|
||||
45
Server/application/store/model/VendorOrderModel.php
Normal file
45
Server/application/store/model/VendorOrderModel.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 订单模型
|
||||
*/
|
||||
class VendorOrderModel extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $table = 'ck_vendor_order';
|
||||
|
||||
// 主键
|
||||
protected $pk = 'id';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
|
||||
// 状态常量
|
||||
const STATUS_UNPAID = 0; // 待支付
|
||||
const STATUS_PAID = 1; // 已支付
|
||||
const STATUS_COMPLETED = 2; // 已完成
|
||||
const STATUS_CANCELED = 3; // 已取消
|
||||
|
||||
/**
|
||||
* 与套餐的关联
|
||||
*/
|
||||
public function package()
|
||||
{
|
||||
return $this->belongsTo('VendorPackageModel', 'packageId', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成唯一订单号
|
||||
* @return string
|
||||
*/
|
||||
public static function generateOrderNo()
|
||||
{
|
||||
return date('YmdHis') . rand(1000, 9999);
|
||||
}
|
||||
}
|
||||
50
Server/application/store/model/VendorPackageModel.php
Normal file
50
Server/application/store/model/VendorPackageModel.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 套餐模型
|
||||
*/
|
||||
class VendorPackageModel extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $table = 'ck_vendor_package';
|
||||
|
||||
// 主键
|
||||
protected $pk = 'id';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
|
||||
// 隐藏字段
|
||||
protected $hidden = ['isDel'];
|
||||
|
||||
/**
|
||||
* 与项目的关联
|
||||
*/
|
||||
public function projects()
|
||||
{
|
||||
return $this->hasMany('VendorProjectModel', 'packageId', 'id')
|
||||
->where('isDel', 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 标签获取器
|
||||
*/
|
||||
public function getTagsAttr($value)
|
||||
{
|
||||
return $value ? explode(',', $value) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 标签修改器
|
||||
*/
|
||||
public function setTagsAttr($value)
|
||||
{
|
||||
return is_array($value) ? implode(',', $value) : $value;
|
||||
}
|
||||
}
|
||||
33
Server/application/store/model/VendorProjectModel.php
Normal file
33
Server/application/store/model/VendorProjectModel.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 套餐项目模型
|
||||
*/
|
||||
class VendorProjectModel extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $table = 'ck_vendor_project';
|
||||
|
||||
// 主键
|
||||
protected $pk = 'id';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
|
||||
// 隐藏字段
|
||||
protected $hidden = ['isDel'];
|
||||
|
||||
/**
|
||||
* 与套餐的关联
|
||||
*/
|
||||
public function package()
|
||||
{
|
||||
return $this->belongsTo('VendorPackageModel', 'packageId', 'id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user