111
This commit is contained in:
parent
7025558890
commit
502586cceb
4
.env
4
.env
|
|
@ -1,4 +1,4 @@
|
|||
APP_DEBUG = false
|
||||
APP_DEBUG = true
|
||||
|
||||
[APP]
|
||||
DEFAULT_TIMEZONE = Asia/Shanghai
|
||||
|
|
@ -11,7 +11,7 @@ USERNAME = youda_test
|
|||
PASSWORD = youda_test
|
||||
HOSTPORT = 3306
|
||||
CHARSET = utf8
|
||||
DEBUG = false
|
||||
DEBUG = true
|
||||
|
||||
[LANG]
|
||||
default_lang = zh-cn
|
||||
|
|
|
|||
|
|
@ -560,22 +560,141 @@ class Goods extends Base
|
|||
#赏品
|
||||
$goods_list = GoodsList::where(['goods_id' => $info['id']])
|
||||
->where(['num' => 1])
|
||||
->where('goods_list_id', '=', 0) // 只查询父奖品
|
||||
->select()->toArray();
|
||||
if ($goods_list) {
|
||||
#循环数据
|
||||
$save_sports_data = [];
|
||||
$start_num = $info['stock'] + 1;
|
||||
|
||||
// 获取宝箱类型的父奖品记录及其prize_code
|
||||
$box_prize_codes = [];
|
||||
foreach ($goods_list as $item) {
|
||||
if ($item['goods_type'] == 4) {
|
||||
$box_prize_codes[$item['prize_code']] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 先处理父奖品(包括宝箱类型的父奖品)
|
||||
for ($i = $start_num; $i <= $data['stock']; $i++) {
|
||||
foreach ($goods_list as $k => $v) {
|
||||
unset($v['id']);
|
||||
unset($v['num']);
|
||||
$v['num'] = $i;
|
||||
$v['surplus_stock'] = $v['stock'];
|
||||
// 保持prize_code不变,这样可以关联到同一套奖品
|
||||
// 添加到待插入数组
|
||||
$save_sports_data[] = $v;
|
||||
}
|
||||
}
|
||||
#添加赏品
|
||||
$res[] = GoodsList::insertAll($save_sports_data);
|
||||
|
||||
// 先插入父奖品
|
||||
if (!empty($save_sports_data)) {
|
||||
$res[] = GoodsList::insertAll($save_sports_data);
|
||||
}
|
||||
|
||||
// 如果有宝箱类型的奖品,需要处理子奖品
|
||||
if (!empty($box_prize_codes)) {
|
||||
// 处理所有新套数的子奖品
|
||||
for ($i = $start_num; $i <= $data['stock']; $i++) {
|
||||
// 先获取当前套数下所有新插入的宝箱类型父奖品
|
||||
$new_box_parents = GoodsList::where([
|
||||
'goods_id' => $info['id'],
|
||||
'num' => $i,
|
||||
'goods_type' => 4,
|
||||
'goods_list_id' => 0
|
||||
])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
if (empty($new_box_parents)) {
|
||||
continue; // 如果没有宝箱父奖品,跳过
|
||||
}
|
||||
|
||||
// 遍历每个宝箱父奖品
|
||||
foreach ($new_box_parents as $new_box_parent) {
|
||||
// 找到第一套中相同prize_code的宝箱父奖品
|
||||
$original_parent = GoodsList::where([
|
||||
'goods_id' => $info['id'],
|
||||
'num' => 1,
|
||||
'goods_type' => 4,
|
||||
'prize_code' => $new_box_parent['prize_code'],
|
||||
'goods_list_id' => 0
|
||||
])
|
||||
->find();
|
||||
|
||||
if (!$original_parent) {
|
||||
continue; // 找不到原始父奖品,跳过
|
||||
}
|
||||
|
||||
// 获取原始父奖品的所有子奖品
|
||||
$child_items = GoodsList::where([
|
||||
'goods_id' => $info['id'],
|
||||
'goods_list_id' => $original_parent['id']
|
||||
])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
if (empty($child_items)) {
|
||||
continue; // 没有子奖品,跳过
|
||||
}
|
||||
|
||||
// 复制所有子奖品到新的套数,每个子奖品创建新的prize_code
|
||||
$child_save_data = [];
|
||||
foreach ($child_items as $child_item) {
|
||||
// 查找所有套数中是否已经有相同奖品的同一个子奖品
|
||||
$existing_children = [];
|
||||
for ($j = 1; $j < $i; $j++) {
|
||||
// 找到对应套数的父奖品
|
||||
$existing_parent = GoodsList::where([
|
||||
'goods_id' => $info['id'],
|
||||
'num' => $j,
|
||||
'prize_code' => $new_box_parent['prize_code'],
|
||||
'goods_list_id' => 0
|
||||
])
|
||||
->find();
|
||||
|
||||
if ($existing_parent) {
|
||||
// 找到这个父奖品下与当前子奖品对应的子奖品
|
||||
$similar_child = GoodsList::where([
|
||||
'goods_id' => $info['id'],
|
||||
'num' => $j,
|
||||
'goods_list_id' => $existing_parent['id'],
|
||||
'title' => $child_item['title'], // 使用标题匹配相似子奖品
|
||||
'shang_id' => $child_item['shang_id'] // 确保奖品类型相同
|
||||
])
|
||||
->find();
|
||||
|
||||
if ($similar_child) {
|
||||
$existing_children[] = $similar_child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$child_data = $child_item;
|
||||
unset($child_data['id']);
|
||||
$child_data['num'] = $i; // 设置新的套数
|
||||
$child_data['goods_list_id'] = $new_box_parent['id']; // 关联到新的父奖品
|
||||
$child_data['surplus_stock'] = $child_data['stock']; // 重置库存
|
||||
|
||||
// 如果存在其他套数的相同子奖品,使用相同的prize_code
|
||||
if (!empty($existing_children)) {
|
||||
$child_data['prize_code'] = $existing_children[0]['prize_code'];
|
||||
} else {
|
||||
// 否则生成新的prize_code
|
||||
$child_data['prize_code'] = getPrizeCode() . '_' . time() . '_' . mt_rand(1000, 9999);
|
||||
}
|
||||
|
||||
$child_save_data[] = $child_data;
|
||||
}
|
||||
|
||||
// 批量插入子奖品
|
||||
if (!empty($child_save_data)) {
|
||||
$res[] = GoodsList::insertAll($child_save_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -611,10 +730,7 @@ class Goods extends Base
|
|||
$result = GoodsModel::where(['id' => $id])->update(['status' => $status]);
|
||||
} elseif ($status == 3) {
|
||||
$result = GoodsModel::where(['id' => $id])->update(['delete_time' => time(), 'status' => 2]);
|
||||
// $goods = GoodsList::field('id')->where(['goods_id' => $id])->find();
|
||||
// if ($goods) {
|
||||
// GoodsList::field('id')->where(['goods_id' => $id])->delete();
|
||||
// }
|
||||
|
||||
} else {
|
||||
return $this->renderError("请求参数错误");
|
||||
}
|
||||
|
|
@ -797,7 +913,6 @@ class Goods extends Base
|
|||
//2023-11-17无作用
|
||||
$data['reward_num'] = 0;
|
||||
//
|
||||
|
||||
if ($type == 1 || $type == 5 || $type == 10 || $type == 6 || $type == 11) {
|
||||
if ($data['shang_id'] == 1 || $data['shang_id'] == 2 || $data['shang_id'] == 3 || $data['shang_id'] == 5) {
|
||||
if ($data['stock'] != 1) {
|
||||
|
|
@ -812,11 +927,88 @@ class Goods extends Base
|
|||
$stock = $info['stock'];
|
||||
#循环数据
|
||||
$save_sports_data = [];
|
||||
$prize_code = getPrizeCode() . '_' . time();
|
||||
for ($i = 1; $i <= $stock; $i++) {
|
||||
$data['num'] = $i;
|
||||
$data['prize_code'] = $prize_code;
|
||||
$save_sports_data[] = $data;
|
||||
$prize_code = getPrizeCode() . '_' . time(); // 生成唯一的prize_code
|
||||
|
||||
// 处理子奖品添加的情况
|
||||
$goods_list_id = $request->param('goods_list_id/d', 0); // 获取父奖品ID,如果是子奖品
|
||||
$is_box_type = ($data['goods_type'] == 4); // 是否为宝箱类型
|
||||
|
||||
if ($goods_list_id > 0) {
|
||||
// 获取父奖品信息,确保父奖品存在
|
||||
$parent_prize = GoodsList::where('id', $goods_list_id)->find();
|
||||
if (!$parent_prize) {
|
||||
return $this->renderError('宝箱父奖品不存在');
|
||||
}
|
||||
|
||||
// 子奖品应该生成自己的prize_code
|
||||
$data['prize_code'] = getPrizeCode() . '_' . time() . '_' . mt_rand(1000, 9999);
|
||||
$data['goods_list_id'] = $goods_list_id;
|
||||
$data['num'] = $parent_prize['num'];
|
||||
|
||||
// 如果父奖品存在于多个套数中,需要为每个套数创建对应的子奖品
|
||||
$same_prize_parents = GoodsList::where([
|
||||
'goods_id' => $data['goods_id'],
|
||||
'prize_code' => $parent_prize['prize_code'],
|
||||
'goods_list_id' => 0 // 确保只查询父奖品
|
||||
])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
if (count($same_prize_parents) > 1) {
|
||||
// 有多个套数的相同父奖品
|
||||
$multi_data = [];
|
||||
|
||||
foreach ($same_prize_parents as $same_parent) {
|
||||
if ($same_parent['id'] == $goods_list_id) {
|
||||
// 跳过当前指定的父奖品,因为下面要单独处理
|
||||
continue;
|
||||
}
|
||||
|
||||
$child_data = $data;
|
||||
$child_data['goods_list_id'] = $same_parent['id'];
|
||||
$child_data['num'] = $same_parent['num'];
|
||||
$multi_data[] = $child_data;
|
||||
}
|
||||
|
||||
// 先插入指定父奖品的子奖品
|
||||
$res = GoodsList::insert($data);
|
||||
|
||||
// 再插入其他套数的子奖品
|
||||
if (!empty($multi_data)) {
|
||||
GoodsList::insertAll($multi_data);
|
||||
}
|
||||
} else {
|
||||
// 只有一个套数,直接保存
|
||||
$res = GoodsList::insert($data);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 添加正常奖品或宝箱父奖品,为所有套数都添加
|
||||
$data['prize_code'] = $prize_code; // 使用新生成的prize_code
|
||||
for ($i = 1; $i <= $stock; $i++) {
|
||||
$data['num'] = $i;
|
||||
$save_sports_data[] = $data;
|
||||
}
|
||||
|
||||
// 批量插入奖品
|
||||
$res = GoodsList::insertAll($save_sports_data);
|
||||
|
||||
// 如果是宝箱类型,则需要记录下插入后的ID,以供后续可能添加的子奖品使用
|
||||
if ($is_box_type && $res) {
|
||||
// 获取已插入的宝箱奖品ID
|
||||
$inserted_boxes = GoodsList::where('prize_code', $prize_code)
|
||||
->where('goods_id', $data['goods_id'])
|
||||
->where('goods_type', 4)
|
||||
->select()->toArray();
|
||||
|
||||
// 通知前端已成功添加宝箱类型,提示可继续添加子奖品
|
||||
if (!empty($inserted_boxes)) {
|
||||
return $this->renderSuccess('添加成功,您可以继续为此宝箱添加子奖品', [
|
||||
'box_ids' => array_column($inserted_boxes, 'id')
|
||||
]);
|
||||
}
|
||||
}
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
} elseif (in_array($type, [2, 8, 9, 16])) {
|
||||
if (RegMoney($data['real_pro'] * 10000)) {
|
||||
|
|
@ -839,12 +1031,89 @@ class Goods extends Base
|
|||
$stock = $info['stock'];
|
||||
#循环数据
|
||||
$save_sports_data = [];
|
||||
$prize_code = getPrizeCode() . '_' . time();
|
||||
for ($i = 1; $i <= $stock; $i++) {
|
||||
$data['num'] = $i;
|
||||
$data['prize_code'] = $prize_code;
|
||||
$save_sports_data[] = $data;
|
||||
$prize_code = getPrizeCode() . '_' . time(); // 生成唯一的prize_code
|
||||
|
||||
// 处理子奖品添加的情况
|
||||
$goods_list_id = $request->param('goods_list_id/d', 0); // 获取父奖品ID,如果是子奖品
|
||||
$is_box_type = ($data['goods_type'] == 4); // 是否为宝箱类型
|
||||
|
||||
if ($goods_list_id > 0) {
|
||||
// 获取父奖品信息,确保父奖品存在
|
||||
$parent_prize = GoodsList::where('id', $goods_list_id)->find();
|
||||
if (!$parent_prize) {
|
||||
return $this->renderError('宝箱父奖品不存在');
|
||||
}
|
||||
|
||||
// 子奖品应该生成自己的prize_code
|
||||
$data['prize_code'] = getPrizeCode() . '_' . time() . '_' . mt_rand(1000, 9999);
|
||||
$data['goods_list_id'] = $goods_list_id;
|
||||
$data['num'] = $parent_prize['num'];
|
||||
|
||||
// 如果父奖品存在于多个套数中,需要为每个套数创建对应的子奖品
|
||||
$same_prize_parents = GoodsList::where([
|
||||
'goods_id' => $data['goods_id'],
|
||||
'prize_code' => $parent_prize['prize_code'],
|
||||
'goods_list_id' => 0 // 确保只查询父奖品
|
||||
])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
if (count($same_prize_parents) > 1) {
|
||||
// 有多个套数的相同父奖品
|
||||
$multi_data = [];
|
||||
|
||||
foreach ($same_prize_parents as $same_parent) {
|
||||
if ($same_parent['id'] == $goods_list_id) {
|
||||
// 跳过当前指定的父奖品,因为下面要单独处理
|
||||
continue;
|
||||
}
|
||||
|
||||
$child_data = $data;
|
||||
$child_data['goods_list_id'] = $same_parent['id'];
|
||||
$child_data['num'] = $same_parent['num'];
|
||||
$multi_data[] = $child_data;
|
||||
}
|
||||
|
||||
// 先插入指定父奖品的子奖品
|
||||
$res = GoodsList::insert($data);
|
||||
|
||||
// 再插入其他套数的子奖品
|
||||
if (!empty($multi_data)) {
|
||||
GoodsList::insertAll($multi_data);
|
||||
}
|
||||
} else {
|
||||
// 只有一个套数,直接保存
|
||||
$res = GoodsList::insert($data);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 添加正常奖品或宝箱父奖品,为所有套数都添加
|
||||
$data['prize_code'] = $prize_code; // 使用新生成的prize_code
|
||||
for ($i = 1; $i <= $stock; $i++) {
|
||||
$data['num'] = $i;
|
||||
$save_sports_data[] = $data;
|
||||
}
|
||||
|
||||
// 批量插入奖品
|
||||
$res = GoodsList::insertAll($save_sports_data);
|
||||
|
||||
// 如果是宝箱类型,则需要记录下插入后的ID,以供后续可能添加的子奖品使用
|
||||
if ($is_box_type && $res) {
|
||||
// 获取已插入的宝箱奖品ID
|
||||
$inserted_boxes = GoodsList::where('prize_code', $prize_code)
|
||||
->where('goods_id', $data['goods_id'])
|
||||
->where('goods_type', 4)
|
||||
->select()->toArray();
|
||||
|
||||
// 通知前端已成功添加宝箱类型,提示可继续添加子奖品
|
||||
if (!empty($inserted_boxes)) {
|
||||
return $this->renderSuccess('添加成功,您可以继续为此宝箱添加子奖品', [
|
||||
'box_ids' => array_column($inserted_boxes, 'id')
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (RegInt($data['prize_num']) && $data['shang_id'] == 5) {
|
||||
return $this->renderError("擂台赏抽全局赏数量设置错误,请设置大于0的整数");
|
||||
}
|
||||
|
|
@ -981,6 +1250,7 @@ class Goods extends Base
|
|||
//
|
||||
|
||||
if ($type == 1 || $type == 5 || $type == 10 || $type == 6 || $type == 11 || $type == 15) {
|
||||
|
||||
|
||||
} elseif ($type == 2 || $type == 8 || $type == 9 || $type == 16 || $type == 17) {
|
||||
if (RegMoney($data['real_pro'] * 10000)) {
|
||||
|
|
@ -1603,7 +1873,8 @@ class Goods extends Base
|
|||
$goodsData['status'] = 2; // 默认下架状态
|
||||
$goodsData['addtime'] = time();
|
||||
$goodsData['async_code'] = ''; // 清空同步代码,避免混淆
|
||||
$goodsData['is_open'] = 0;
|
||||
$goodsData['is_open'] = 0;
|
||||
$goodsData['king_user_id'] = 0;
|
||||
// 插入新盒子
|
||||
$newGoods = new GoodsModel();
|
||||
$newGoods->save($goodsData);
|
||||
|
|
@ -1619,77 +1890,144 @@ class Goods extends Base
|
|||
$newExtend->save($extendData);
|
||||
}
|
||||
|
||||
// 创建ID映射表,用于处理子奖品关联
|
||||
$idMapping = [];
|
||||
// 创建父奖品prize_code映射表
|
||||
$parentPrizeCodeMapping = [];
|
||||
|
||||
// 创建子奖品prize_code映射表
|
||||
$childPrizeCodeMapping = [];
|
||||
|
||||
// 复制盒子奖品
|
||||
$goodsLists = GoodsList::where(['goods_id' => $id, 'goods_list_id' => 0])->select();
|
||||
foreach ($goodsLists as $item) {
|
||||
$listData = $item->toArray();
|
||||
$oldId = $item['id']; // 保存原始ID,用于建立映射
|
||||
unset($listData['id']);
|
||||
$listData['goods_id'] = $newGoodsId;
|
||||
$listData['addtime'] = time();
|
||||
$listData['surplus_stock'] = $listData['stock'];
|
||||
|
||||
// 处理奖励ID
|
||||
if ($listData['reward_id'] && $listData['reward_id'] != '') {
|
||||
$reward = Reward::where(['reward_id' => $listData['reward_id']])->select();
|
||||
$listData['reward_id'] = 'MHHZ' . date('YmdHis') . mt_rand(1000, 9999);
|
||||
if ($reward) {
|
||||
$rewards = $reward->toArray();
|
||||
foreach ($rewards as $item2) {
|
||||
unset($item2['id']);
|
||||
$item2['reward_id'] = $listData['reward_id'];
|
||||
$item2['create_time'] = time();
|
||||
$item2['update_time'] = time();
|
||||
Reward::insert($item2);
|
||||
}
|
||||
}
|
||||
// 首先获取所有的父奖品,并按prize_code分组
|
||||
$parentPrizes = GoodsList::where(['goods_id' => $id, 'goods_list_id' => 0])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$prizeCodeGroups = [];
|
||||
foreach ($parentPrizes as $prize) {
|
||||
if (!isset($prizeCodeGroups[$prize['prize_code']])) {
|
||||
$prizeCodeGroups[$prize['prize_code']] = [];
|
||||
}
|
||||
|
||||
// 插入新奖品
|
||||
$newGoodsList = new GoodsList();
|
||||
$newGoodsList->save($listData);
|
||||
|
||||
// 记录ID映射关系
|
||||
$idMapping[$oldId] = $newGoodsList->id;
|
||||
$prizeCodeGroups[$prize['prize_code']][] = $prize;
|
||||
}
|
||||
|
||||
// 复制子奖品(宝箱类型的子奖品)
|
||||
$childItems = GoodsList::where(['goods_id' => $id])->where('goods_list_id', '>', 0)->select();
|
||||
foreach ($childItems as $childItem) {
|
||||
$childData = $childItem->toArray();
|
||||
$originalParentId = $childData['goods_list_id'];
|
||||
unset($childData['id']);
|
||||
$childData['goods_id'] = $newGoodsId;
|
||||
$childData['addtime'] = time();
|
||||
$childData['surplus_stock'] = $childData['stock'];
|
||||
|
||||
// 更新goods_list_id为新系统中的ID
|
||||
if (isset($idMapping[$originalParentId])) {
|
||||
$childData['goods_list_id'] = $idMapping[$originalParentId];
|
||||
}
|
||||
|
||||
// 处理奖励ID
|
||||
if ($childData['reward_id'] && $childData['reward_id'] != '') {
|
||||
$reward = Reward::where(['reward_id' => $childData['reward_id']])->select();
|
||||
$childData['reward_id'] = 'MHHZ' . date('YmdHis') . mt_rand(1000, 9999);
|
||||
if ($reward) {
|
||||
$rewards = $reward->toArray();
|
||||
foreach ($rewards as $item2) {
|
||||
unset($item2['id']);
|
||||
$item2['reward_id'] = $childData['reward_id'];
|
||||
$item2['create_time'] = time();
|
||||
$item2['update_time'] = time();
|
||||
Reward::insert($item2);
|
||||
|
||||
// 为每个父prize_code组创建新的prize_code
|
||||
foreach ($prizeCodeGroups as $oldPrizeCode => $prizes) {
|
||||
$newPrizeCode = 'MHHZ' . date('YmdHis') . mt_rand(1000, 9999);
|
||||
$parentPrizeCodeMapping[$oldPrizeCode] = $newPrizeCode;
|
||||
|
||||
// 复制每个prize_code组的奖品
|
||||
foreach ($prizes as $prize) {
|
||||
$newPrizeData = $prize;
|
||||
unset($newPrizeData['id']);
|
||||
$newPrizeData['goods_id'] = $newGoodsId;
|
||||
$newPrizeData['prize_code'] = $newPrizeCode;
|
||||
$newPrizeData['addtime'] = time();
|
||||
$newPrizeData['surplus_stock'] = $newPrizeData['stock'];
|
||||
|
||||
// 处理奖励ID
|
||||
if ($newPrizeData['reward_id'] && $newPrizeData['reward_id'] != '') {
|
||||
$reward = Reward::where(['reward_id' => $newPrizeData['reward_id']])->select();
|
||||
$newPrizeData['reward_id'] = 'MHHZ' . date('YmdHis') . mt_rand(1000, 9999);
|
||||
if ($reward) {
|
||||
$rewards = $reward->toArray();
|
||||
foreach ($rewards as $item2) {
|
||||
unset($item2['id']);
|
||||
$item2['reward_id'] = $newPrizeData['reward_id'];
|
||||
$item2['create_time'] = time();
|
||||
$item2['update_time'] = time();
|
||||
Reward::insert($item2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 插入新奖品
|
||||
$newGoodsList = new GoodsList();
|
||||
$newGoodsList->save($newPrizeData);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取所有子奖品
|
||||
$childPrizes = GoodsList::where(['goods_id' => $id])
|
||||
->where('goods_list_id', '>', 0)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 对子奖品按prize_code分组
|
||||
$childGroups = [];
|
||||
foreach ($childPrizes as $child) {
|
||||
$childPrizeCode = $child['prize_code'];
|
||||
if (!isset($childGroups[$childPrizeCode])) {
|
||||
$childGroups[$childPrizeCode] = [];
|
||||
}
|
||||
$childGroups[$childPrizeCode][] = $child;
|
||||
}
|
||||
|
||||
// 为每组子奖品创建新的prize_code映射
|
||||
foreach ($childGroups as $oldChildCode => $group) {
|
||||
$newChildCode = 'MHHZ' . date('YmdHis') . mt_rand(1000, 9999);
|
||||
$childPrizeCodeMapping[$oldChildCode] = $newChildCode;
|
||||
}
|
||||
|
||||
// 处理每个子奖品
|
||||
foreach ($childPrizes as $childPrize) {
|
||||
// 查找子奖品对应的父奖品
|
||||
$parentPrize = GoodsList::where('id', $childPrize['goods_list_id'])->find();
|
||||
if (!$parentPrize) {
|
||||
continue; // 如果找不到父奖品,跳过
|
||||
}
|
||||
|
||||
// 获取父奖品的prize_code
|
||||
$parentPrizeCode = $parentPrize['prize_code'];
|
||||
|
||||
// 如果父奖品的prize_code有映射,则复制子奖品
|
||||
if (isset($parentPrizeCodeMapping[$parentPrizeCode])) {
|
||||
// 找到新盒子中对应的父奖品
|
||||
$newParent = GoodsList::where([
|
||||
'goods_id' => $newGoodsId,
|
||||
'prize_code' => $parentPrizeCodeMapping[$parentPrizeCode],
|
||||
'num' => $parentPrize['num'] // 确保套数也匹配
|
||||
])->find();
|
||||
|
||||
if ($newParent) {
|
||||
// 复制子奖品数据
|
||||
$newChildData = $childPrize;
|
||||
unset($newChildData['id']);
|
||||
$newChildData['goods_id'] = $newGoodsId;
|
||||
$newChildData['goods_list_id'] = $newParent['id']; // 关联到新的父奖品
|
||||
|
||||
// 使用子奖品的prize_code映射,确保相同的子奖品有相同的prize_code
|
||||
if (isset($childPrizeCodeMapping[$childPrize['prize_code']])) {
|
||||
$newChildData['prize_code'] = $childPrizeCodeMapping[$childPrize['prize_code']];
|
||||
} else {
|
||||
// 如果没有映射,创建一个新的
|
||||
$newChildCode = 'MHHZ' . date('YmdHis') . mt_rand(1000, 9999);
|
||||
$childPrizeCodeMapping[$childPrize['prize_code']] = $newChildCode;
|
||||
$newChildData['prize_code'] = $newChildCode;
|
||||
}
|
||||
|
||||
$newChildData['addtime'] = time();
|
||||
$newChildData['surplus_stock'] = $newChildData['stock'];
|
||||
|
||||
// 处理奖励ID
|
||||
if ($newChildData['reward_id'] && $newChildData['reward_id'] != '') {
|
||||
$reward = Reward::where(['reward_id' => $newChildData['reward_id']])->select();
|
||||
$newChildData['reward_id'] = 'MHHZ' . date('YmdHis') . mt_rand(1000, 9999);
|
||||
if ($reward) {
|
||||
$rewards = $reward->toArray();
|
||||
foreach ($rewards as $item2) {
|
||||
unset($item2['id']);
|
||||
$item2['reward_id'] = $newChildData['reward_id'];
|
||||
$item2['create_time'] = time();
|
||||
$item2['update_time'] = time();
|
||||
Reward::insert($item2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 插入新的子奖品
|
||||
$newChildList = new GoodsList();
|
||||
$newChildList->save($newChildData);
|
||||
}
|
||||
}
|
||||
|
||||
// 插入子奖品
|
||||
$newChildList = new GoodsList();
|
||||
$newChildList->save($childData);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
|
|
|||
|
|
@ -180,8 +180,16 @@ class Statistics extends Base
|
|||
$lirun = round($orderStats->order_zhe_total - $goodslistMoney, 2);
|
||||
$liruns = round(($orderStats->count_price + $orderStats->count_yue + $orderStats->use_integral + $orderStats->use_score + $orderStats->use_coupon) - $goodslistMoney, 2);
|
||||
|
||||
$order_zhe_total=$orderStats->order_zhe_total;
|
||||
$order_total=($orderStats->count_price + $orderStats->count_yue + $orderStats->use_integral + $orderStats->use_score + $orderStats->use_coupon);
|
||||
$order_zhe_total = $orderStats->order_zhe_total;
|
||||
// $order_zhe_total 转int
|
||||
$order_zhe_total = intval($order_zhe_total);
|
||||
if ($order_zhe_total <= 0) {
|
||||
$order_zhe_total = 1;
|
||||
}
|
||||
$order_total = ($orderStats->count_price + $orderStats->count_yue + $orderStats->use_integral + $orderStats->use_score + $orderStats->use_coupon);
|
||||
if ($order_total <= 0) {
|
||||
$order_total = 1;
|
||||
}
|
||||
return [
|
||||
'order_count' => round($orderStats->count, 2),
|
||||
'count_price' => round($orderStats->count_price, 2),
|
||||
|
|
@ -192,12 +200,7 @@ class Statistics extends Base
|
|||
'count_use_coupon' => round($orderStats->use_coupon, 2),
|
||||
'count_heji' => round($orderStats->count_price + $orderStats->count_yue + $orderStats->use_integral + $orderStats->use_score + $orderStats->use_coupon, 2),
|
||||
'order_zhe_total' => round($orderStats->order_zhe_total, 2),
|
||||
// 订单列表数量
|
||||
'count_OrderList' => OrderList::where($whe2)->count(), // ✅ 添加这一行
|
||||
|
||||
// 订单总价验证
|
||||
// 'count_heji_yanzheng' => $count_OrderList * $value['price'], // ✅ 使用 count_OrderList
|
||||
|
||||
'goodslist_price' => round($goodslistMoney, 2),
|
||||
'lirun' => $lirun,
|
||||
'liruns' => $liruns,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{include file="Public:header3"/}
|
||||
|
||||
<body>
|
||||
<div class="layui-fluid" style="margin-top: 15px;">
|
||||
<div class="layui-fluid" style="padding-top: 15px;">
|
||||
<div class=" layui-card">
|
||||
<div class="layui-form layui-card-header layuiadmin-card-header-auto">
|
||||
<div class="layui-form-item">
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
</div>
|
||||
<div class="layui-inline">
|
||||
<div class="layui-input-inline" style="width: 180px;margin-left: 0px">
|
||||
<select name="type" id="goodsType" style="width:100%">
|
||||
<select name="type" id="goodsType" style="width:100%">
|
||||
<option value="">--盒子类型--</option>
|
||||
<!-- 盒子类型由JS动态加载 -->
|
||||
</select>
|
||||
|
|
@ -155,13 +155,11 @@
|
|||
|
||||
<!-- 盒子限购等信息模板 -->
|
||||
<script type="text/html" id="limitInfoTpl">
|
||||
|
||||
<div><b>是否首抽5折:</b>{{d.is_shou_zhe==0?'否':'是'}}</div>
|
||||
<div><b>限购次数:</b>{{d.quanju_xiangou}}次</div>
|
||||
<div><b>每日限购:</b>{{d.daily_xiangou}}次</div>
|
||||
|
||||
<div><b>解锁金额:</b><span class="layui-badge layui-bg-orange">{{d.unlock_amount}}</span></div>
|
||||
|
||||
<div><b>抽奖门槛:</b>{{d.choujiang_xianzhi}}</div>
|
||||
|
||||
</script>
|
||||
|
||||
<!-- 首页显示和锁箱模式模板 -->
|
||||
|
|
@ -295,7 +293,7 @@
|
|||
return d.imgurl_detail ? '<img src="' + d.imgurl_detail + '" style="width:60px;height:60px;" class="layui-admin-img" onclick="previewImg(this)">' : '';
|
||||
}
|
||||
},
|
||||
{ field: 'limit_info', title: '限购信息', width: 150, templet: '#limitInfoTpl' },
|
||||
{ field: 'limit_info', title: '限购信息', width: 160, templet: '#limitInfoTpl' },
|
||||
|
||||
{ field: 'pay_info', title: '支付信息', width: 150, templet: '#payInfoTpl' },
|
||||
{ field: 'is_auto_xiajia', title: '自动下架', width: 150, templet: '#autoOffshelfTpl' },
|
||||
|
|
|
|||
|
|
@ -30,17 +30,10 @@
|
|||
</div>
|
||||
<div class="layui-inline">
|
||||
<div class="layui-input-inline" style="width: 180px;margin-left: 0px">
|
||||
<select name="type" style="width:100%">
|
||||
<select name="type" id="goodsType" style="width:100%">
|
||||
<option value="">--盒子类型--</option>
|
||||
<option value="1" {if condition="$Request.get.type eq 1" }selected{/if}>一番赏</option>
|
||||
<option value="2" {if condition="$Request.get.type eq 2" }selected{/if}>无限赏</option>
|
||||
<option value="3" {if condition="$Request.get.type eq 3" }selected{/if}>擂台赏</option>
|
||||
<option value="5" {if condition="$Request.get.type eq 5" }selected{/if}>积分赏</option>
|
||||
<option value="6" {if condition="$Request.get.type eq 6" }selected{/if}>全局赏</option>
|
||||
<option value="8" {if condition="$Request.get.type eq 8" }selected{/if}>领主赏</option>
|
||||
<option value="9" {if condition="$Request.get.type eq 9" }selected{/if}>连击赏</option>
|
||||
<option value="10" {if condition="$Request.get.type eq 10" }selected{/if}>商城赏</option>
|
||||
<option value="11" {if condition="$Request.get.type eq 11" }selected{/if}>自制赏</option>
|
||||
|
||||
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -65,7 +58,7 @@
|
|||
实际收入:<span style="background-color: yellow;font-weight: 600;">{$sum_shiji}</span>
|
||||
微信收入:<span style="background-color: yellow;font-weight: 600;">{$price_all}</span>
|
||||
余额收入:<span style="background-color: yellow;font-weight: 600;">{$use_money_all}</span>
|
||||
|
||||
|
||||
出货价值:<span style="background-color: yellow;font-weight: 600;">{$sum_chuhuo}</span>
|
||||
订单利润:<span style="background-color: yellow;font-weight: 600;">{if condition="$sum_dingdanlirun < 0"}
|
||||
<span style="color: red;">{$sum_dingdanlirun}</span>
|
||||
|
|
@ -207,15 +200,41 @@
|
|||
</div>
|
||||
{include file="Public:footer"/}
|
||||
<script type="text/javascript">
|
||||
layui.use(['layer', 'laydate', 'table'], function () {
|
||||
layui.use(['layer', 'laydate', 'table', 'form'], function () {
|
||||
var $ = layui.$;
|
||||
//执行一个laydate实例
|
||||
var laydate = layui.laydate;
|
||||
var form = layui.form;
|
||||
laydate.render({
|
||||
elem: '#addtime'
|
||||
, type: 'datetime'
|
||||
, range: true
|
||||
});
|
||||
// 加载盒子类型数据
|
||||
$.ajax({
|
||||
url: '{:url("/admin/api/goods/types")}',
|
||||
type: 'GET',
|
||||
success: function (res) {
|
||||
if (res.code === 0) {
|
||||
// 保存类型数据到全局变量
|
||||
window.goodsTypes = res.data;
|
||||
|
||||
var html = '<option value="">--盒子类型--</option>';
|
||||
console.log('{$Request.get.type}');
|
||||
|
||||
$.each(res.data, function (index, item) {
|
||||
if(item.value=='{$Request.get.type}'){
|
||||
html += '<option value="' + item.value + '" title="' + item.remark + '" selected>' + item.fl_name + '</option>';
|
||||
}else{
|
||||
html += '<option value="' + item.value + '" title="' + item.remark + '">' + item.fl_name + '</option>';
|
||||
}
|
||||
});
|
||||
$('#goodsType').html(html);
|
||||
form.render('select');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// laydate.render({
|
||||
// elem: '#endtime'
|
||||
// // , type: 'datetime'
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@
|
|||
<div id="lirun" style="width: 100%;height:350px;"></div>
|
||||
</div>
|
||||
<div>
|
||||
备注:总收入=订单支付+其他收入;<br />
|
||||
备注:总收入=订单支付(微信收入+钻石收入)+其他收入;<br />
|
||||
备注:总支出=订单出货+其他支出;<br />
|
||||
备注:利润=总收入-总支出;<br />
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ class FuLiWu extends Base
|
|||
}
|
||||
|
||||
if ($goods['unlock_amount'] > $order_money) {
|
||||
return $this->renderError("您需要充值满" . $goods['unlock_amount'] . "元才能查看此福利屋");
|
||||
return $this->renderError("您需要消费满" . $goods['unlock_amount'] . "元才能查看此福利屋");
|
||||
}
|
||||
} else if ($goods['unlock_amount'] > 0) {
|
||||
return $this->renderError("您需要登录并充值满" . $goods['unlock_amount'] . "元才能查看此福利屋");
|
||||
|
|
|
|||
|
|
@ -1289,6 +1289,7 @@ class Goods extends Base
|
|||
$goods['async_date'] = date('Y-m-d H:i:s');
|
||||
$goods['addtime'] = time();
|
||||
$goods['update_time'] = time();
|
||||
$goods['king_user_id'] =0;
|
||||
$goodsModel = new Goodsmodel();
|
||||
$goodsModel->save($goods);
|
||||
$goodsId = $goodsModel->id;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ use app\common\model\UserRecharge;
|
|||
use app\common\model\Ads;
|
||||
use think\facade\Db;
|
||||
use app\common\model\CouponReceive as CouponReceiveModel;
|
||||
|
||||
|
||||
use app\common\helper\ConfigHelper;
|
||||
use app\common\service\RewardService;
|
||||
/**
|
||||
|
|
@ -1059,7 +1059,7 @@ class Notify extends Base
|
|||
if ($order['use_money'] > 0) {
|
||||
$res[] = User::changeMoney($order['user_id'], -$order['use_money'], 3, '购买盒子' . $order['goods_title']);
|
||||
}
|
||||
#扣吧唧币
|
||||
#扣货币1
|
||||
if ($order['use_integral'] > 0) {
|
||||
$res[] = User::changeIntegral($order['user_id'], -$order['use_integral'], 2, '购买盒子' . $order['goods_title']);
|
||||
}
|
||||
|
|
@ -1570,15 +1570,15 @@ class Notify extends Base
|
|||
$infinite_goods = Goods::getInfo($whe, 'lingzhu_is,lingzhu_fan,lingzhu_shang_id,king_user_id');
|
||||
|
||||
if ($infinite_goods['king_user_id'] != 0) {
|
||||
|
||||
$king_user_id = $infinite_goods['king_user_id'];
|
||||
Db::name('goods_king_rank')->where([['user_id', '=', $infinite_goods['king_user_id']], ['goods_id', '=', $v['goods_id']]])->order('id', 'desc')->limit(1)->inc('z_nums', 1)->update();
|
||||
$king_money = $infinite_goods['lingzhu_fan'];
|
||||
|
||||
if ($king_money && $king_money > 0) {
|
||||
|
||||
|
||||
Db::name('goods_king_rank')->where([['user_id', '=', $infinite_goods['king_user_id']], ['goods_id', '=', $v['goods_id']]])->order('id', 'desc')->limit(1)->inc('money', floatval($king_money))->update();
|
||||
|
||||
User::changeIntegral($infinite_goods['king_user_id'], $king_money, 4, '领主收益');
|
||||
// User::changeIntegral($infinite_goods['king_user_id'], $king_money, 4, '领主收益');
|
||||
User::changeMoney2($infinite_goods['king_user_id'], $king_money, 4, '领主收益');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,38 +12,36 @@ use app\common\model\Order;
|
|||
*/
|
||||
class CommonService
|
||||
{
|
||||
/**
|
||||
/**
|
||||
* 获取用户在指定时间范围内的消费情况
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $start_time 开始时间戳
|
||||
* @param int $end_time 结束时间戳
|
||||
* @return array 消费数据
|
||||
* @param int $userId 用户ID
|
||||
* @param int $startTime 开始时间戳
|
||||
* @param int $endTime 结束时间戳
|
||||
* @return array 包含余额消费和微信支付消费的数组
|
||||
*/
|
||||
public static function getUserConsumptionByTimeRange($user_id, $start_time, $end_time)
|
||||
public static function getUserConsumptionByTimeRange($userId, $startTime, $endTime)
|
||||
{
|
||||
// 查询用户在指定时间范围内的订单
|
||||
$query = Order::where('user_id', '=', $user_id)
|
||||
->where('status', '=', 1);
|
||||
|
||||
// 添加时间范围条件
|
||||
if ($start_time) {
|
||||
$query->where('addtime', '>=', $start_time);
|
||||
}
|
||||
|
||||
if ($end_time) {
|
||||
$query->where('addtime', '<=', $end_time);
|
||||
}
|
||||
|
||||
// 计算总消费金额
|
||||
$total_consumed = $query->sum('price');
|
||||
|
||||
// 获取订单数量
|
||||
$order_count = $query->count();
|
||||
|
||||
return [
|
||||
'total_consumed' => $total_consumed,
|
||||
'order_count' => $order_count
|
||||
// 查询用户在指定时间范围内的订单消费情况
|
||||
$consumptionData = Order::where('user_id', '=', $userId)
|
||||
->where(function ($query) {
|
||||
$query->where('price', '>', 0)
|
||||
->whereOr('use_money', '>', 0);
|
||||
})
|
||||
->where('status', '=', 1)
|
||||
->where('pay_time', '>=', $startTime)
|
||||
->where('pay_time', '<=', $endTime)
|
||||
->field('sum(use_money) as balance_consumed, sum(price) as wechat_consumed')
|
||||
->find();
|
||||
|
||||
// 处理查询结果
|
||||
$result = [
|
||||
'money_consumed' => round(floatval($consumptionData['balance_consumed'] ?? 0), 2), // 余额消费
|
||||
'wechat_consumed' => round(floatval($consumptionData['wechat_consumed'] ?? 0), 2), // 微信支付消费
|
||||
'total_consumed' => round(floatval(($consumptionData['balance_consumed'] ?? 0) + ($consumptionData['wechat_consumed'] ?? 0)), 2) // 总消费
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
BIN
public/storage/poster/share/9.png
Normal file
BIN
public/storage/poster/share/9.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
BIN
public/ueditor/php/upload/image/20250410/1744277812131212.png
Normal file
BIN
public/ueditor/php/upload/image/20250410/1744277812131212.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 73 KiB |
Loading…
Reference in New Issue
Block a user