diff --git a/app/admin/controller/ActivityZoneController.php b/app/admin/controller/ActivityZoneController.php new file mode 100644 index 00000000..75e3464e --- /dev/null +++ b/app/admin/controller/ActivityZoneController.php @@ -0,0 +1,95 @@ +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); + } + + +} \ No newline at end of file diff --git a/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php b/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php index deaa23fe..4575398f 100644 --- a/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php +++ b/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php @@ -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); diff --git a/app/admin/lists/ActivityZoneLists.php b/app/admin/lists/ActivityZoneLists.php new file mode 100644 index 00000000..16a5d401 --- /dev/null +++ b/app/admin/lists/ActivityZoneLists.php @@ -0,0 +1,84 @@ + ['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(); + } + +} \ No newline at end of file diff --git a/app/admin/lists/store_product/StoreProductLists.php b/app/admin/lists/store_product/StoreProductLists.php index a1a494aa..9b7c897f 100644 --- a/app/admin/lists/store_product/StoreProductLists.php +++ b/app/admin/lists/store_product/StoreProductLists.php @@ -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) { diff --git a/app/admin/logic/ActivityZoneLogic.php b/app/admin/logic/ActivityZoneLogic.php new file mode 100644 index 00000000..9cc018d5 --- /dev/null +++ b/app/admin/logic/ActivityZoneLogic.php @@ -0,0 +1,102 @@ + $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(); + } +} \ No newline at end of file diff --git a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php index a3445587..96cceca8 100644 --- a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php +++ b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php @@ -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; diff --git a/app/admin/validate/ActivityZoneValidate.php b/app/admin/validate/ActivityZoneValidate.php new file mode 100644 index 00000000..eeb3621c --- /dev/null +++ b/app/admin/validate/ActivityZoneValidate.php @@ -0,0 +1,88 @@ + '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']); + } + +} \ No newline at end of file diff --git a/app/common/model/ActivityZone.php b/app/common/model/ActivityZone.php new file mode 100644 index 00000000..62bf752b --- /dev/null +++ b/app/common/model/ActivityZone.php @@ -0,0 +1,27 @@ +hasOne(StoreProduct::class, 'id', 'product_id')->bind(['store_name', 'unit']); + } + +} \ No newline at end of file