添加活动专区

This commit is contained in:
DESKTOP-GMUNQ1B\Administrator 2024-12-20 14:38:51 +08:00
parent 94b42547fc
commit 5e83ad2b4c
8 changed files with 405 additions and 4 deletions

View File

@ -0,0 +1,95 @@
<?php
namespace app\admin\controller;
use app\admin\controller\BaseAdminController;
use app\admin\lists\ActivityZoneLists;
use app\admin\logic\ActivityZoneLogic;
use app\admin\validate\ActivityZoneValidate;
/**
* ActivityZone控制器
* Class ActivityZoneController
* @package app\admin\controller
*/
class ActivityZoneController extends BaseAdminController
{
/**
* @notes 获取列表
* @return \think\response\Json
* @author admin
* @date 2024/12/20 10:52
*/
public function lists()
{
return $this->dataLists(new ActivityZoneLists());
}
/**
* @notes 添加
* @return \think\response\Json
* @author admin
* @date 2024/12/20 10:52
*/
public function add()
{
$params = (new ActivityZoneValidate())->post()->goCheck('add');
$result = ActivityZoneLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(ActivityZoneLogic::getError());
}
/**
* @notes 编辑
* @return \think\response\Json
* @author admin
* @date 2024/12/20 10:52
*/
public function edit()
{
$params = (new ActivityZoneValidate())->post()->goCheck('edit');
$result = ActivityZoneLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(ActivityZoneLogic::getError());
}
/**
* @notes 删除
* @return \think\response\Json
* @author admin
* @date 2024/12/20 10:52
*/
public function delete()
{
$params = (new ActivityZoneValidate())->post()->goCheck('delete');
ActivityZoneLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取详情
* @return \think\response\Json
* @author admin
* @date 2024/12/20 10:52
*/
public function detail()
{
$params = (new ActivityZoneValidate())->goCheck('detail');
$result = ActivityZoneLogic::detail($params);
return $this->data($result);
}
}

View File

@ -39,6 +39,7 @@ class PurchaseProductOfferController extends BaseAdminController
public function add()
{
$params = (new PurchaseProductOfferValidate())->post()->goCheck('add');
$params['admin_id'] = $this->adminId;
$result = PurchaseProductOfferLogic::add($params);
return $this->success('设置成功', [], 1, 1);

View File

@ -0,0 +1,84 @@
<?php
namespace app\admin\lists;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\ActivityZone;
use app\common\lists\ListsSearchInterface;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_unit\StoreProductUnit;
/**
* ActivityZone列表
* Class ActivityZoneLists
* @package app\admin\lists
*/
class ActivityZoneLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author admin
* @date 2024/12/20 10:52
*/
public function setSearch(): array
{
return [
'=' => ['type'],
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author admin
* @date 2024/12/20 10:52
*/
public function lists(): array
{
$query = ActivityZone::where($this->searchWhere);
if (!empty($this->params['keyword'])) {
$productIds = StoreProduct::where('store_name', 'like', "%{$this->params['keyword']}%")->column('id');
$query->whereIn('product_id', $productIds);
}
$list = $query->with('product')
->field(['id', 'type', 'product_id'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
$unitIds = array_unique(array_column($list, 'unit'));
$unit = StoreProductUnit::whereIn('id', $unitIds)->field('id,name')->withTrashed()->select()->toArray();
$unit = reset_index($unit, 'id');
foreach ($list as &$item) {
$item['unit_name'] = $unit[$item['unit']]['name'] ?? '';
}
return $list;
}
/**
* @notes 获取数量
* @return int
* @author admin
* @date 2024/12/20 10:52
*/
public function count(): int
{
$query = ActivityZone::where($this->searchWhere);
if (!empty($this->params['keyword'])) {
$productIds = StoreProduct::where('store_name', 'like', "%{$this->params['keyword']}%")->column('id');
$query->whereIn('product_id', $productIds);
}
return $query->count();
}
}

View File

@ -4,6 +4,7 @@ namespace app\admin\lists\store_product;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\ActivityZone;
use app\common\model\cate\Cate;
use app\common\model\store_product\StoreProduct;
use app\common\lists\ListsSearchInterface;
@ -80,6 +81,10 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
$query->where('is_show', 1);
}
}
if (!empty($this->params['activity_zone_type'])) {
$exceptIds = ActivityZone::where('type', $this->params['activity_zone_type'])->column('product_id');
$query->where('is_show', 1)->where('product_type', '<>', 5)->whereNotIn('id', $exceptIds);
}
$list = $query->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item) use($is_warehouse, $userShip) {

View File

@ -0,0 +1,102 @@
<?php
namespace app\admin\logic;
use app\common\model\ActivityZone;
use app\common\logic\BaseLogic;
use support\exception\BusinessException;
use think\facade\Db;
/**
* ActivityZone逻辑
* Class ActivityZoneLogic
* @package app\admin\logic
*/
class ActivityZoneLogic extends BaseLogic
{
/**
* @notes 添加
* @param array $params
* @return bool
* @author admin
* @date 2024/12/20 10:52
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
$insert = [];
$time = time();
foreach ($params['product_ids'] as $product_id) {
$insert[] = [
'type' => $params['type'],
'product_id' => $product_id,
'create_time' => $time,
'update_time' => $time,
];
}
ActivityZone::insertAll($insert);
Db::commit();
return true;
} catch (\Throwable $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
}
/**
* @notes 编辑
* @param array $params
* @return bool
* @author admin
* @date 2024/12/20 10:52
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ActivityZone::where('id', $params['id'])->update([
'type' => $params['type'],
'product_id' => $params['product_id'],
]);
Db::commit();
return true;
} catch (\Throwable $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
}
/**
* @notes 删除
* @param array $params
* @return bool
* @author admin
* @date 2024/12/20 10:52
*/
public static function delete(array $params): bool
{
return ActivityZone::destroy($params['id']);
}
/**
* @notes 获取详情
* @param $params
* @return array
* @author admin
* @date 2024/12/20 10:52
*/
public static function detail($params): array
{
return ActivityZone::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -41,13 +41,12 @@ class PurchaseProductOfferLogic extends BaseLogic
{
Db::startTrans();
try {
$procurementOrder = BeforehandOrder::where('order_type', 7)->where('is_buying', 0)->where('create_time', '>=', strtotime('-3 days'))->find();
$procurementOrder = BeforehandOrder::where('order_type', 7)->where('buyer_id', $params['buyer_id'])->where('is_buying', 0)->where('create_time', '>=', strtotime('-3 days'))->find();
if (empty($procurementOrder)) {
$beforeOrder = BeforehandOrder::where('id', $params['order_id'])->findOrEmpty()->toArray();
unset($beforeOrder['id'], $beforeOrder['create_time'], $beforeOrder['update_time']);
$procurementOrder = new BeforehandOrder();
$procurementOrder->setAttrs($beforeOrder);
$procurementOrder->order_id = getNewOrderId('CG');
$procurementOrder->buyer_id = $params['buyer_id'];
$procurementOrder->admin_id = $params['admin_id'];
$procurementOrder->order_type = 7;
$procurementOrder->total_price = 0;
$procurementOrder->pay_price = 0;

View File

@ -0,0 +1,88 @@
<?php
namespace app\admin\validate;
use app\common\validate\BaseValidate;
/**
* ActivityZone验证器
* Class ActivityZoneValidate
* @package app\admin\validate
*/
class ActivityZoneValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'type' => 'require',
'product_ids' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'type' => '类型',
'product_ids' => '商品',
];
/**
* @notes 添加场景
* @return ActivityZoneValidate
* @author admin
* @date 2024/12/20 10:52
*/
public function sceneAdd()
{
return $this->only(['type','product_ids']);
}
/**
* @notes 编辑场景
* @return ActivityZoneValidate
* @author admin
* @date 2024/12/20 10:52
*/
public function sceneEdit()
{
return $this->only(['id','type','product_ids']);
}
/**
* @notes 删除场景
* @return ActivityZoneValidate
* @author admin
* @date 2024/12/20 10:52
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ActivityZoneValidate
* @author admin
* @date 2024/12/20 10:52
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace app\common\model;
use app\common\model\BaseModel;
use app\common\model\store_product\StoreProduct;
use think\model\concern\SoftDelete;
/**
* ActivityZone模型
* Class ActivityZone
* @package app\common\model
*/
class ActivityZone extends BaseModel
{
use SoftDelete;
protected $name = 'activity_zone';
protected $deleteTime = 'delete_time';
public function product()
{
return $this->hasOne(StoreProduct::class, 'id', 'product_id')->bind(['store_name', 'unit']);
}
}