feat(shopro): 中羿体育活动报名费处理
- 新增报名费商品类别和商品创建逻辑 - 实现报名费价格动态更新 - 添加活动报名功能 - 优化 SkuPrice trait 中的 sku 处理逻辑 - 修复活动列表和详情页面的一些小问题
This commit is contained in:
@@ -3,20 +3,24 @@
|
|||||||
namespace addons\shopro\controller\zy;
|
namespace addons\shopro\controller\zy;
|
||||||
|
|
||||||
use think\Db;
|
use think\Db;
|
||||||
use think\Cache;
|
|
||||||
use think\Exception;
|
use think\Exception;
|
||||||
use app\admin\model\zy\Club;
|
use app\admin\model\zy\Club;
|
||||||
use app\admin\model\zy\Stadium;
|
use app\admin\model\zy\Stadium;
|
||||||
use app\admin\model\zy\game\Game;
|
use app\admin\model\zy\game\Game;
|
||||||
use think\exception\PDOException;
|
use think\exception\PDOException;
|
||||||
|
use app\admin\model\shopro\Category;
|
||||||
use app\admin\model\zy\game\GameJoin;
|
use app\admin\model\zy\game\GameJoin;
|
||||||
use think\exception\ValidateException;
|
use think\exception\ValidateException;
|
||||||
|
use app\admin\model\shopro\goods\Goods;
|
||||||
use addons\shopro\service\order\OrderCreate;
|
use addons\shopro\service\order\OrderCreate;
|
||||||
|
use app\admin\controller\shopro\traits\SkuPrice;
|
||||||
|
|
||||||
class Activity extends Base
|
class Activity extends Base
|
||||||
{
|
{
|
||||||
|
use SkuPrice;
|
||||||
|
|
||||||
protected $noNeedLogin = ['index', 'test'];
|
protected $noNeedLogin = ['index', 'test'];
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->model = new \app\admin\model\zy\game\Activity;
|
$this->model = new \app\admin\model\zy\game\Activity;
|
||||||
@@ -79,22 +83,46 @@ class Activity extends Base
|
|||||||
|
|
||||||
public function add()
|
public function add()
|
||||||
{
|
{
|
||||||
$result = false;
|
|
||||||
$params = $this->request->param();
|
$params = $this->request->param();
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
$category = new Category;
|
||||||
|
$category->name = $params['name'];
|
||||||
|
$category->parent_id = 157;
|
||||||
|
$category->description = '报名费商品';
|
||||||
|
$category->save();
|
||||||
|
foreach ($this->model->costKey as $key => $val) {
|
||||||
|
if (isset($params['cost'][$key])) {
|
||||||
|
$goods = new Goods;
|
||||||
|
$goods->category_ids = $category->id;
|
||||||
|
$goods->subtitle = $key;
|
||||||
|
$goods->title = $val;
|
||||||
|
$goods->type = 'virtual';
|
||||||
|
$goods->limit_type = 'none';
|
||||||
|
$goods->dispatch_type = 'autosend';
|
||||||
|
$goods->dispatch_id = 2;
|
||||||
|
$goods->is_sku = 0;
|
||||||
|
$goods->original_price = $params['price'][$key];
|
||||||
|
$goods->price = $params['cost'][$key];
|
||||||
|
$goods->save();
|
||||||
|
$this->zySku($goods, 'add');
|
||||||
|
} else {
|
||||||
|
throw new Exception('请填写' . $val);
|
||||||
|
}
|
||||||
|
}
|
||||||
$params['public_time'] = json_encode($params['public_time'] ?? []);
|
$params['public_time'] = json_encode($params['public_time'] ?? []);
|
||||||
$params['join_start_time'] = json_encode($params['join_start_time'] ?? []);
|
$params['join_start_time'] = json_encode($params['join_start_time'] ?? []);
|
||||||
$params['join_end_time'] = json_encode($params['join_end_time'] ?? []);
|
$params['join_end_time'] = json_encode($params['join_end_time'] ?? []);
|
||||||
$params['quit_time'] = json_encode($params['quit_time'] ?? []);
|
$params['quit_time'] = json_encode($params['quit_time'] ?? []);
|
||||||
|
$params['cost']['goods_category_id'] = $category->id;
|
||||||
$params['cost'] = json_encode($params['cost'] ?? []);
|
$params['cost'] = json_encode($params['cost'] ?? []);
|
||||||
Db::startTrans();
|
|
||||||
try {
|
|
||||||
$result = $this->model->allowField(true)->save($params);
|
$result = $this->model->allowField(true)->save($params);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
} catch (ValidateException | PDOException | Exception $e) {
|
} catch (ValidateException | PDOException | Exception $e) {
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
$this->error($e->getMessage());
|
$this->error($e->getMessage());
|
||||||
}
|
}
|
||||||
if ($result === false) {
|
if (empty($result)) {
|
||||||
$this->error('操作失败');
|
$this->error('操作失败');
|
||||||
}
|
}
|
||||||
$this->success('Success');
|
$this->success('Success');
|
||||||
@@ -102,16 +130,30 @@ class Activity extends Base
|
|||||||
|
|
||||||
public function update()
|
public function update()
|
||||||
{
|
{
|
||||||
$result = false;
|
|
||||||
$params = $this->request->param();
|
$params = $this->request->param();
|
||||||
$model = $this->model->get($params['id']);
|
$model = $this->model->get($params['id']);
|
||||||
if (empty($model)) {
|
if (empty($model)) {
|
||||||
$this->error(__('No rows were found'));
|
$this->error(__('No rows were found'));
|
||||||
}
|
}
|
||||||
|
$cost = json_decode($model->cost, true);
|
||||||
|
$goods = Goods::where('category_ids', $cost['goods_category_id'])->select();
|
||||||
|
foreach ($this->model->costKey as $key => $val) {
|
||||||
|
if (isset($params['cost'][$key])) {
|
||||||
|
foreach ($goods as $g) { //更新报名费价格
|
||||||
|
if ($g['title'] == $val && $g['price'] != $params['cost'][$key]) {
|
||||||
|
$g->save(['price' => $params['cost'][$key]]);
|
||||||
|
$this->zySku($g, 'edit');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Exception('请填写' . $val);
|
||||||
|
}
|
||||||
|
}
|
||||||
$params['public_time'] = json_encode($params['public_time'] ?? []);
|
$params['public_time'] = json_encode($params['public_time'] ?? []);
|
||||||
$params['join_start_time'] = json_encode($params['join_start_time'] ?? []);
|
$params['join_start_time'] = json_encode($params['join_start_time'] ?? []);
|
||||||
$params['join_end_time'] = json_encode($params['join_end_time'] ?? []);
|
$params['join_end_time'] = json_encode($params['join_end_time'] ?? []);
|
||||||
$params['quit_time'] = json_encode($params['quit_time'] ?? []);
|
$params['quit_time'] = json_encode($params['quit_time'] ?? []);
|
||||||
|
$params['cost']['goods_category_id'] = $cost['goods_category_id'];
|
||||||
$params['cost'] = json_encode($params['cost'] ?? []);
|
$params['cost'] = json_encode($params['cost'] ?? []);
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
@@ -121,7 +163,7 @@ class Activity extends Base
|
|||||||
Db::rollback();
|
Db::rollback();
|
||||||
$this->error($e->getMessage());
|
$this->error($e->getMessage());
|
||||||
}
|
}
|
||||||
if ($result === false) {
|
if (empty($result)) {
|
||||||
$this->error('操作失败');
|
$this->error('操作失败');
|
||||||
}
|
}
|
||||||
$this->success('Success');
|
$this->success('Success');
|
||||||
@@ -158,12 +200,15 @@ class Activity extends Base
|
|||||||
if ($game['join_start_time'] > date('Y-m-d H:i:s')) {
|
if ($game['join_start_time'] > date('Y-m-d H:i:s')) {
|
||||||
$this->error('活动报名时间未开始');
|
$this->error('活动报名时间未开始');
|
||||||
}
|
}
|
||||||
|
if (empty($params['users']) || !is_array($params['users']) || empty($params['goods_list']) || !is_array($params['goods_list'])) {
|
||||||
$this->svalidate($params, ".create");
|
$this->error('请核对报名人员');
|
||||||
|
}
|
||||||
|
if (GameJoin::get(['game_id' => $game['id'], 'act_id' => $game['act_id'], 'user_id' => $this->auth->id])) {
|
||||||
|
$this->error('您已报名此活动');
|
||||||
|
}
|
||||||
$orderCreate = new OrderCreate($params);
|
$orderCreate = new OrderCreate($params);
|
||||||
$result = $orderCreate->calc('create');
|
$result = $orderCreate->calc('create');
|
||||||
$order = $orderCreate->create($result);
|
$order = $orderCreate->create($result);
|
||||||
|
|
||||||
$join = new GameJoin;
|
$join = new GameJoin;
|
||||||
$join->allowField(true)->save([
|
$join->allowField(true)->save([
|
||||||
'act_id' => $game['act_id'],
|
'act_id' => $game['act_id'],
|
||||||
@@ -180,6 +225,6 @@ class Activity extends Base
|
|||||||
$this->error($e->getMessage(), $e);
|
$this->error($e->getMessage(), $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->success('Success', $join);
|
$this->success('Success');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ trait StockWarning
|
|||||||
$stockWarning = new StockLogModel();
|
$stockWarning = new StockLogModel();
|
||||||
|
|
||||||
$stockWarning->goods_id = $goodsSkuPrice['goods_id'];
|
$stockWarning->goods_id = $goodsSkuPrice['goods_id'];
|
||||||
$stockWarning->admin_id = $admin['id'];
|
$stockWarning->admin_id = $admin['id'] ?? 0;
|
||||||
$stockWarning->goods_sku_price_id = $goodsSkuPrice['id'];
|
$stockWarning->goods_sku_price_id = $goodsSkuPrice['id'];
|
||||||
$stockWarning->goods_sku_text = is_array($goodsSkuPrice['goods_sku_text']) ? join(',', $goodsSkuPrice['goods_sku_text']) : $goodsSkuPrice['goods_sku_text'];
|
$stockWarning->goods_sku_text = is_array($goodsSkuPrice['goods_sku_text']) ? join(',', $goodsSkuPrice['goods_sku_text']) : $goodsSkuPrice['goods_sku_text'];
|
||||||
$stockWarning->before = $before;
|
$stockWarning->before = $before;
|
||||||
|
|||||||
@@ -40,7 +40,13 @@ trait SkuPrice
|
|||||||
protected function editSimSku($goods, $type = 'add')
|
protected function editSimSku($goods, $type = 'add')
|
||||||
{
|
{
|
||||||
$params = $this->request->only([
|
$params = $this->request->only([
|
||||||
'stock', 'stock_warning', 'sn', 'weight', 'cost_price', 'original_price', 'price'
|
'stock',
|
||||||
|
'stock_warning',
|
||||||
|
'sn',
|
||||||
|
'weight',
|
||||||
|
'cost_price',
|
||||||
|
'original_price',
|
||||||
|
'price'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
@@ -83,7 +89,36 @@ trait SkuPrice
|
|||||||
// 检测库存预警
|
// 检测库存预警
|
||||||
$this->checkStockWarning($skuPrice, $type);
|
$this->checkStockWarning($skuPrice, $type);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 中羿体育项目报名费sku处理
|
||||||
|
private function zySku($goods, $type)
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'goods_id' => $goods->id,
|
||||||
|
'stock' => 999,
|
||||||
|
'cost_price' => 0,
|
||||||
|
'original_price' => 0,
|
||||||
|
'price' => $goods['price'][0] ?? 0,
|
||||||
|
'original_price' => $goods['price'][0] ?? 0,
|
||||||
|
'stock_warning' => null
|
||||||
|
];
|
||||||
|
if ($type == 'edit') {
|
||||||
|
$skuPrice = SkuPriceModel::where('goods_id', $goods->id)->order('id', 'asc')->find();
|
||||||
|
if ($skuPrice) {
|
||||||
|
SkuPriceModel::where('goods_id', $goods->id)->where('id', '<>', $skuPrice->id)->delete();
|
||||||
|
SkuModel::where('goods_id', $goods->id)->delete();
|
||||||
|
}
|
||||||
|
unset($data['stock']);
|
||||||
|
}
|
||||||
|
if (!isset($skuPrice) || !$skuPrice) {
|
||||||
|
$skuPrice = new SkuPriceModel();
|
||||||
|
}
|
||||||
|
$skuPrice->save($data);
|
||||||
|
if ($type == 'add') {
|
||||||
|
$this->addStockLog($skuPrice, 0, $data['stock'], $type);
|
||||||
|
$this->checkStockWarning($skuPrice, $type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -97,7 +132,8 @@ trait SkuPrice
|
|||||||
protected function editMultSku($goods, $type = 'add')
|
protected function editMultSku($goods, $type = 'add')
|
||||||
{
|
{
|
||||||
$params = $this->request->only([
|
$params = $this->request->only([
|
||||||
'skus', 'sku_prices'
|
'skus',
|
||||||
|
'sku_prices'
|
||||||
]);
|
]);
|
||||||
$skus = $params['skus'] ?? [];
|
$skus = $params['skus'] ?? [];
|
||||||
$skuPrices = $params['sku_prices'] ?? [];
|
$skuPrices = $params['sku_prices'] ?? [];
|
||||||
|
|||||||
@@ -25,12 +25,11 @@ class Activity extends Model
|
|||||||
protected $deleteTime = false;
|
protected $deleteTime = false;
|
||||||
|
|
||||||
// 追加属性
|
// 追加属性
|
||||||
protected $append = [
|
protected $append = [];
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public $costKey = ['man' => '男报名费', 'woman' => '女报名费', 'extra' => '附加费', 'server' => '服务费'];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user