diff --git a/app/admin/controller/ActivityZoneController.php b/app/admin/controller/ActivityZoneController.php index 54f92700..00d406c9 100644 --- a/app/admin/controller/ActivityZoneController.php +++ b/app/admin/controller/ActivityZoneController.php @@ -91,11 +91,4 @@ class ActivityZoneController extends BaseAdminController return $this->data($result); } - public function export() - { - $params = $this->request->get(); - $file_path = ActivityZoneLogic::export($params); - return $this->success('导出成功', ['url' => $file_path]); - } - } \ No newline at end of file diff --git a/app/admin/controller/ActivityZoneFormController.php b/app/admin/controller/ActivityZoneFormController.php new file mode 100644 index 00000000..876ea116 --- /dev/null +++ b/app/admin/controller/ActivityZoneFormController.php @@ -0,0 +1,98 @@ +dataLists(new ActivityZoneFormLists()); + } + + + /** + * @notes 添加 + * @return \think\response\Json + * @author admin + * @date 2024/12/20 10:52 + */ + public function add() + { + $params = (new ActivityZoneFormValidate())->post()->goCheck('add'); + $result = ActivityZoneFormLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ActivityZoneFormLogic::getError()); + } + + + /** + * @notes 编辑 + * @return \think\response\Json + * @author admin + * @date 2024/12/20 10:52 + */ + public function edit() + { + $params = (new ActivityZoneFormValidate())->post()->goCheck('edit'); + $result = ActivityZoneFormLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ActivityZoneFormLogic::getError()); + } + + + /** + * @notes 删除 + * @return \think\response\Json + * @author admin + * @date 2024/12/20 10:52 + */ + public function delete() + { + $params = (new ActivityZoneFormValidate())->post()->goCheck('delete'); + ActivityZoneFormLogic::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 ActivityZoneFormValidate())->goCheck('detail'); + $result = ActivityZoneFormLogic::detail($params); + return $this->data($result); + } + + public function export() + { + $params = $this->request->get(); + $file_path = ActivityZoneFormLogic::export($params); + return $this->success('导出成功', ['url' => $file_path]); + } + +} \ No newline at end of file diff --git a/app/admin/lists/ActivityZoneFormLists.php b/app/admin/lists/ActivityZoneFormLists.php new file mode 100644 index 00000000..2c12baf5 --- /dev/null +++ b/app/admin/lists/ActivityZoneFormLists.php @@ -0,0 +1,87 @@ + ['type'], + '%like%' => ['title'], + ]; + } + + + /** + * @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 = ActivityZoneForm::where($this->searchWhere); + $cateIds = []; + $list = $query + ->field(['id', 'type', 'cate_ids', 'title', 'remark']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->each(function ($item) use (&$cateIds) { + $item['cate_ids'] = explode(',', $item['cate_ids']); + foreach ($item['cate_ids'] as $cateId) { + if (!empty($cateId) && !in_array($cateId, $cateIds)) { + $cateIds[] = $cateId; + } + } + }) + ->toArray(); + $cateList = StoreCategory::where('id', 'in', $cateIds)->field('id,name')->select()->toArray(); + $cateList = reset_index($cateList, 'id'); + foreach ($list as &$item) { + $item['cate_names'] = []; + foreach ($item['cate_ids'] as $cateId) { + if (isset($cateList[$cateId])) { + $item['cate_names'][] = $cateList[$cateId]['name']; + } + } + $item['cate_names'] = implode(',', $item['cate_names']); + } + return $list; + } + + + /** + * @notes 获取数量 + * @return int + * @author admin + * @date 2024/12/20 10:52 + */ + public function count(): int + { + $query = ActivityZoneForm::where($this->searchWhere); + return $query->count(); + } + +} \ No newline at end of file diff --git a/app/admin/lists/ActivityZoneLists.php b/app/admin/lists/ActivityZoneLists.php index 16a5d401..2a883a86 100644 --- a/app/admin/lists/ActivityZoneLists.php +++ b/app/admin/lists/ActivityZoneLists.php @@ -28,7 +28,7 @@ class ActivityZoneLists extends BaseAdminDataLists implements ListsSearchInterfa public function setSearch(): array { return [ - '=' => ['type'], + '=' => ['form_id'], ]; } @@ -45,12 +45,12 @@ class ActivityZoneLists extends BaseAdminDataLists implements ListsSearchInterfa 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'); + if (!empty($this->params['store_name'])) { + $productIds = StoreProduct::where('store_name', 'like', "%{$this->params['store_name']}%")->column('id'); $query->whereIn('product_id', $productIds); } $list = $query->with('product') - ->field(['id', 'type', 'product_id']) + ->field(['id', 'form_id', 'product_id']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select() @@ -74,8 +74,8 @@ class ActivityZoneLists extends BaseAdminDataLists implements ListsSearchInterfa 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'); + if (!empty($this->params['store_name'])) { + $productIds = StoreProduct::where('store_name', 'like', "%{$this->params['store_name']}%")->column('id'); $query->whereIn('product_id', $productIds); } return $query->count(); diff --git a/app/admin/lists/store_product/StoreProductLists.php b/app/admin/lists/store_product/StoreProductLists.php index 9b7c897f..3bfcd58e 100644 --- a/app/admin/lists/store_product/StoreProductLists.php +++ b/app/admin/lists/store_product/StoreProductLists.php @@ -81,8 +81,8 @@ 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'); + if (!empty($this->params['activity_zone_form_id'])) { + $exceptIds = ActivityZone::where('form_id', $this->params['activity_zone_form_id'])->column('product_id'); $query->where('is_show', 1)->where('product_type', '<>', 5)->whereNotIn('id', $exceptIds); } $list = $query->limit($this->limitOffset, $this->limitLength) diff --git a/app/admin/logic/ActivityZoneFormLogic.php b/app/admin/logic/ActivityZoneFormLogic.php new file mode 100644 index 00000000..5f76614a --- /dev/null +++ b/app/admin/logic/ActivityZoneFormLogic.php @@ -0,0 +1,145 @@ +save($params); + $productIds = StoreProduct::where('two_cate_id', 'in', $secondCateIds)->whereOr('cate_id', 'in', $thirdCateIds)->column('id'); + $productInfo = []; + $time = time(); + foreach ($productIds as $productId) { + $productInfo[] = [ + 'product_id' => $productId, + 'form_id' => $activityZoneForm->id, + 'create_time' => $time, + 'update_time' => $time, + ]; + } + if (!empty($productInfo)) { + ActivityZone::insertAll($productInfo); + } + + 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 { + ActivityZoneForm::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 ActivityZoneForm::destroy($params['id']); + } + + + /** + * @notes 获取详情 + * @param $params + * @return array + * @author admin + * @date 2024/12/20 10:52 + */ + public static function detail($params): array + { + return ActivityZoneForm::findOrEmpty($params['id'])->toArray(); + } + + public static function export($params) + { + $service = new ActivityZoneService(); + $activityZoneForm = ActivityZoneForm::findOrEmpty($params['id'])->toArray(); + $products = ActivityZone::with('product')->field('id,product_id')->where('form_id', $params['id'])->select()->toArray(); + $unitIds = array_unique(array_column($products, 'unit')); + $unit = StoreProductUnit::whereIn('id', $unitIds)->field('id,name')->withTrashed()->select()->toArray(); + $unit = reset_index($unit, 'id'); + foreach ($products as &$item) { + $item['unit_name'] = $unit[$item['unit']]['name'] ?? ''; + unset($item['unit'], $item['product_id']); + } + $data = ConfigLogic::getDictByType('activity_zone'); + foreach ($data['activity_zone'] as $value) { + if ($value['value'] == $activityZoneForm['type']) { + $typeName = $value['remark']; + break; + } + } + return $service->export($products, $activityZoneForm['title'], $typeName ?? '', $activityZoneForm['remark']); + } + +} \ No newline at end of file diff --git a/app/admin/logic/ActivityZoneLogic.php b/app/admin/logic/ActivityZoneLogic.php index a5425ee0..5f4eec89 100644 --- a/app/admin/logic/ActivityZoneLogic.php +++ b/app/admin/logic/ActivityZoneLogic.php @@ -5,8 +5,6 @@ namespace app\admin\logic; use app\common\model\ActivityZone; use app\common\logic\BaseLogic; -use app\common\model\store_product_unit\StoreProductUnit; -use app\common\service\xlsx\ActivityZoneService; use support\exception\BusinessException; use think\facade\Db; @@ -35,7 +33,7 @@ class ActivityZoneLogic extends BaseLogic $time = time(); foreach ($params['product_ids'] as $product_id) { $insert[] = [ - 'type' => $params['type'], + 'form_id' => $params['form_id'], 'product_id' => $product_id, 'create_time' => $time, 'update_time' => $time, @@ -64,7 +62,7 @@ class ActivityZoneLogic extends BaseLogic Db::startTrans(); try { ActivityZone::where('id', $params['id'])->update([ - 'type' => $params['type'], + 'form_id' => $params['form_id'], 'product_id' => $params['product_id'], ]); @@ -102,25 +100,4 @@ class ActivityZoneLogic extends BaseLogic return ActivityZone::findOrEmpty($params['id'])->toArray(); } - public static function export($params) - { - $service = new ActivityZoneService(); - $products = ActivityZone::with('product')->field('id,product_id,type')->where('type', $params['type'])->select()->toArray(); - $unitIds = array_unique(array_column($products, 'unit')); - $unit = StoreProductUnit::whereIn('id', $unitIds)->field('id,name')->withTrashed()->select()->toArray(); - $unit = reset_index($unit, 'id'); - foreach ($products as &$item) { - $item['unit_name'] = $unit[$item['unit']]['name'] ?? ''; - unset($item['unit'], $item['product_id']); - } - $data = ConfigLogic::getDictByType('activity_zone'); - foreach ($data['activity_zone'] as $value) { - if ($value['value'] == $params['type']) { - $typeName = $value['remark']; - break; - } - } - return $service->export($products, $typeName ?? '', $params['remark']); - } - } \ No newline at end of file diff --git a/app/admin/validate/ActivityZoneFormValidate.php b/app/admin/validate/ActivityZoneFormValidate.php new file mode 100644 index 00000000..697f7cfd --- /dev/null +++ b/app/admin/validate/ActivityZoneFormValidate.php @@ -0,0 +1,89 @@ + 'require', + 'type' => 'require', + 'title' => 'require', + 'cate_ids' => 'require', + 'remark' => 'string', + ]; + + + /** + * 参数描述 + * @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', 'title', 'cate_ids']); + } + + + /** + * @notes 编辑场景 + * @return ActivityZoneValidate + * @author admin + * @date 2024/12/20 10:52 + */ + public function sceneEdit() + { + return $this->only(['id', 'type', 'title', 'cate_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']); + } + +} \ No newline at end of file diff --git a/app/admin/validate/ActivityZoneValidate.php b/app/admin/validate/ActivityZoneValidate.php index eeb3621c..cb9cc65e 100644 --- a/app/admin/validate/ActivityZoneValidate.php +++ b/app/admin/validate/ActivityZoneValidate.php @@ -14,15 +14,14 @@ use app\common\validate\BaseValidate; class ActivityZoneValidate extends BaseValidate { - /** - * 设置校验规则 - * @var string[] - */ + /** + * 设置校验规则 + * @var string[] + */ protected $rule = [ 'id' => 'require', - 'type' => 'require', + 'form_id' => 'require', 'product_ids' => 'require', - ]; @@ -32,9 +31,8 @@ class ActivityZoneValidate extends BaseValidate */ protected $field = [ 'id' => 'id', - 'type' => '类型', + 'form_id' => '表单', 'product_ids' => '商品', - ]; @@ -46,7 +44,7 @@ class ActivityZoneValidate extends BaseValidate */ public function sceneAdd() { - return $this->only(['type','product_ids']); + return $this->only(['form_id', 'product_ids']); } @@ -58,7 +56,7 @@ class ActivityZoneValidate extends BaseValidate */ public function sceneEdit() { - return $this->only(['id','type','product_ids']); + return $this->only(['id', 'form_id', 'product_ids']); } diff --git a/app/common/model/ActivityZoneForm.php b/app/common/model/ActivityZoneForm.php new file mode 100644 index 00000000..ab50bf52 --- /dev/null +++ b/app/common/model/ActivityZoneForm.php @@ -0,0 +1,19 @@ +getActiveSheet(); @@ -26,7 +26,7 @@ class ActivityZoneService $sheet->mergeCells('A5:F5'); $sheet->mergeCells('B6:C6'); - $sheet->setCellValue('A1', "供 投 里 海 农 特 产 品 下 单 清 单({$typeName})"); + $sheet->setCellValue('A1', $title); $sheet->setCellValue('A2', '姓名:'); $sheet->setCellValue('C2', '电话:'); $sheet->setCellValue('E2', '会员角色:'); @@ -103,7 +103,7 @@ class ActivityZoneService $sheet->getStyle('A1:F' . ($count + 9))->applyFromArray($styleArray); $writer = new Xlsx($spreadsheet); - $url = '/export/' . date('Y-m') . "/供投里海农特产品下单清单({$typeName})" . date('YmdHi') . '.xlsx'; + $url = '/export/' . date('Y-m') . $title . date('YmdHi') . '.xlsx'; $file_path = public_path() . $url; if (!is_dir(dirname($file_path))) { mkdir(dirname($file_path), 0777, true);