feat(shopro): 中羿体育活动报名费处理
- 新增报名费商品类别和商品创建逻辑 - 实现报名费价格动态更新 - 添加活动报名功能 - 优化 SkuPrice trait 中的 sku 处理逻辑 - 修复活动列表和详情页面的一些小问题
This commit is contained in:
@@ -3,20 +3,24 @@
|
||||
namespace addons\shopro\controller\zy;
|
||||
|
||||
use think\Db;
|
||||
use think\Cache;
|
||||
use think\Exception;
|
||||
use app\admin\model\zy\Club;
|
||||
use app\admin\model\zy\Stadium;
|
||||
use app\admin\model\zy\game\Game;
|
||||
use think\exception\PDOException;
|
||||
use app\admin\model\shopro\Category;
|
||||
use app\admin\model\zy\game\GameJoin;
|
||||
use think\exception\ValidateException;
|
||||
use app\admin\model\shopro\goods\Goods;
|
||||
use addons\shopro\service\order\OrderCreate;
|
||||
|
||||
use app\admin\controller\shopro\traits\SkuPrice;
|
||||
|
||||
class Activity extends Base
|
||||
{
|
||||
use SkuPrice;
|
||||
|
||||
protected $noNeedLogin = ['index', 'test'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new \app\admin\model\zy\game\Activity;
|
||||
@@ -79,22 +83,46 @@ class Activity extends Base
|
||||
|
||||
public function add()
|
||||
{
|
||||
$result = false;
|
||||
$params = $this->request->param();
|
||||
$params['public_time'] = json_encode($params['public_time'] ?? []);
|
||||
$params['join_start_time'] = json_encode($params['join_start_time'] ?? []);
|
||||
$params['join_end_time'] = json_encode($params['join_end_time'] ?? []);
|
||||
$params['quit_time'] = json_encode($params['quit_time'] ?? []);
|
||||
$params['cost'] = json_encode($params['cost'] ?? []);
|
||||
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['join_start_time'] = json_encode($params['join_start_time'] ?? []);
|
||||
$params['join_end_time'] = json_encode($params['join_end_time'] ?? []);
|
||||
$params['quit_time'] = json_encode($params['quit_time'] ?? []);
|
||||
$params['cost']['goods_category_id'] = $category->id;
|
||||
$params['cost'] = json_encode($params['cost'] ?? []);
|
||||
$result = $this->model->allowField(true)->save($params);
|
||||
Db::commit();
|
||||
} catch (ValidateException | PDOException | Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result === false) {
|
||||
if (empty($result)) {
|
||||
$this->error('操作失败');
|
||||
}
|
||||
$this->success('Success');
|
||||
@@ -102,16 +130,30 @@ class Activity extends Base
|
||||
|
||||
public function update()
|
||||
{
|
||||
$result = false;
|
||||
$params = $this->request->param();
|
||||
$model = $this->model->get($params['id']);
|
||||
if (empty($model)) {
|
||||
$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['join_start_time'] = json_encode($params['join_start_time'] ?? []);
|
||||
$params['join_end_time'] = json_encode($params['join_end_time'] ?? []);
|
||||
$params['quit_time'] = json_encode($params['quit_time'] ?? []);
|
||||
$params['cost']['goods_category_id'] = $cost['goods_category_id'];
|
||||
$params['cost'] = json_encode($params['cost'] ?? []);
|
||||
Db::startTrans();
|
||||
try {
|
||||
@@ -121,7 +163,7 @@ class Activity extends Base
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result === false) {
|
||||
if (empty($result)) {
|
||||
$this->error('操作失败');
|
||||
}
|
||||
$this->success('Success');
|
||||
@@ -158,12 +200,15 @@ class Activity extends Base
|
||||
if ($game['join_start_time'] > date('Y-m-d H:i:s')) {
|
||||
$this->error('活动报名时间未开始');
|
||||
}
|
||||
|
||||
$this->svalidate($params, ".create");
|
||||
if (empty($params['users']) || !is_array($params['users']) || empty($params['goods_list']) || !is_array($params['goods_list'])) {
|
||||
$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);
|
||||
$result = $orderCreate->calc('create');
|
||||
$order = $orderCreate->create($result);
|
||||
|
||||
$join = new GameJoin;
|
||||
$join->allowField(true)->save([
|
||||
'act_id' => $game['act_id'],
|
||||
@@ -180,6 +225,6 @@ class Activity extends Base
|
||||
$this->error($e->getMessage(), $e);
|
||||
}
|
||||
|
||||
$this->success('Success', $join);
|
||||
$this->success('Success');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ trait StockWarning
|
||||
$stockWarning = new StockLogModel();
|
||||
|
||||
$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_text = is_array($goodsSkuPrice['goods_sku_text']) ? join(',', $goodsSkuPrice['goods_sku_text']) : $goodsSkuPrice['goods_sku_text'];
|
||||
$stockWarning->before = $before;
|
||||
|
||||
Reference in New Issue
Block a user