diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index 9f4495c53..bdb51a290 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -237,10 +237,19 @@ class StoreProductLogic extends BaseLogic $rose=bcmul($price_div, 100, 2); } $data['rose']=$rose; - StoreProduct::update($data, ['id' => $params['id']]); + $find=StoreProduct::where(['id' => $params['id']])->find(); + if($find['purchase']!=$params['purchase']){ + SqlChannelPriceLog($params['id'],21,$find['purchase'],$params['purchase'],); + } + if($find['cost']!=$params['cost']){ + SqlChannelPriceLog($params['id'],4,$find['cost'],$params['cost'],); + } + if($find['price']!=$params['price']){ + SqlChannelPriceLog($params['id'],22,$find['price'],$params['price'],); + } + $find->save($data); // 修改活动专区商品 (new ActivityZoneLogic())->updateProduct($params['id'], $data); - // $dealCate = self::dealChangeCate($params['cate_id']); //修改 StoreBranchProduct::where('product_id', $params['id'])->whereNotIn('store_id', [17, 18])->update([ @@ -268,6 +277,7 @@ class StoreProductLogic extends BaseLogic return true; } catch (\Throwable $e) { Db::rollback(); + d($e); throw new BusinessException('编辑商品失败' . $e->getMessage()); } } diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index e5ee0b415..1cded3f70 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -68,7 +68,7 @@ class IndexController extends BaseApiController // } // $a=StoreOrderCartInfo::where('store_id',2)->whereBetweenTime('create_time','2025-01-01','2025-01-8')->select()->toArray(); // d($a); - DemoLogic::test(); + // DemoLogic::test(); d(1); $arr = Db::name('ceshi_copy')->select(); foreach ($arr as $k => $v) { diff --git a/app/common/logic/ChangePriceLogLogic.php b/app/common/logic/ChangePriceLogLogic.php new file mode 100644 index 000000000..fb82ea2df --- /dev/null +++ b/app/common/logic/ChangePriceLogLogic.php @@ -0,0 +1,20 @@ + $product_id, + 'group_id' => $group_id, + 'before_price' => $before_price, + 'after_price' => $after_price, + 'create_time' => time() + ]); + } +} diff --git a/app/common/model/change_price_log/ChangePriceLog.php b/app/common/model/change_price_log/ChangePriceLog.php new file mode 100644 index 000000000..dc60a6236 --- /dev/null +++ b/app/common/model/change_price_log/ChangePriceLog.php @@ -0,0 +1,23 @@ +insert($model, $id, $nums, $pm, $url,$admin_id); } +/** + * 价格日志记录 + * @param model 模型 + * @param id 更新的模型组件id + * @param nums 更新的数量 + */ +function SqlChannelPriceLog($product_id=0, $group_id=0, $before_price=0,$after_price=0):void +{ + (new ChangePriceLogLogic())->insert($product_id, $group_id, $before_price, $after_price); +} // if (!function_exists('getNewOrderSn')) { // /** diff --git a/app/store/controller/change_price_log/ChangePriceLogController.php b/app/store/controller/change_price_log/ChangePriceLogController.php new file mode 100644 index 000000000..deb0ff18e --- /dev/null +++ b/app/store/controller/change_price_log/ChangePriceLogController.php @@ -0,0 +1,95 @@ +dataLists(new ChangePriceLogLists()); + } + + + /** + * @notes 添加价格变更记录 + * @return \think\response\Json + * @author admin + * @date 2025/01/10 15:54 + */ + public function add() + { + $params = (new ChangePriceLogValidate())->post()->goCheck('add'); + $result = ChangePriceLogLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ChangePriceLogLogic::getError()); + } + + + /** + * @notes 编辑价格变更记录 + * @return \think\response\Json + * @author admin + * @date 2025/01/10 15:54 + */ + public function edit() + { + $params = (new ChangePriceLogValidate())->post()->goCheck('edit'); + $result = ChangePriceLogLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ChangePriceLogLogic::getError()); + } + + + /** + * @notes 删除价格变更记录 + * @return \think\response\Json + * @author admin + * @date 2025/01/10 15:54 + */ + public function delete() + { + $params = (new ChangePriceLogValidate())->post()->goCheck('delete'); + ChangePriceLogLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取价格变更记录详情 + * @return \think\response\Json + * @author admin + * @date 2025/01/10 15:54 + */ + public function detail() + { + $params = (new ChangePriceLogValidate())->goCheck('detail'); + $result = ChangePriceLogLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/store/lists/change_price_log/ChangePriceLogLists.php b/app/store/lists/change_price_log/ChangePriceLogLists.php new file mode 100644 index 000000000..00edc68ed --- /dev/null +++ b/app/store/lists/change_price_log/ChangePriceLogLists.php @@ -0,0 +1,80 @@ + ['product_id', 'group_id', 'before_price', 'after_price'], + ]; + } + + + /** + * @notes 获取价格变更记录列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2025/01/10 15:54 + */ + public function lists(): array + { + if ($this->request->get('store_name')) { + $store_name = $this->request->get('store_name'); + $ids = StoreProduct::where('store_name', 'like', '%' . $store_name . '%')->where('status',1)->column('id'); + if ($ids) { + $this->searchWhere[] = ['product_id', 'in', $ids]; + $this->ids = $ids; + } else { + return []; + } + } + return ChangePriceLog::where($this->searchWhere) + ->field(['id', 'product_id', 'group_id', 'before_price', 'after_price']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取价格变更记录数量 + * @return int + * @author admin + * @date 2025/01/10 15:54 + */ + public function count(): int + { + if($this->request->get('store_name')){ + if($this->ids<=0){ + return 0; + } + } + return ChangePriceLog::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/store/logic/change_price_log/ChangePriceLogLogic.php b/app/store/logic/change_price_log/ChangePriceLogLogic.php new file mode 100644 index 000000000..301b6aa9a --- /dev/null +++ b/app/store/logic/change_price_log/ChangePriceLogLogic.php @@ -0,0 +1,99 @@ + $params['product_id'], + 'group_id' => $params['group_id'], + 'before_price' => $params['before_price'], + 'after_price' => $params['after_price'] + ]); + + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 编辑价格变更记录 + * @param array $params + * @return bool + * @author admin + * @date 2025/01/10 15:54 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + ChangePriceLog::where('id', $params['id'])->update([ + 'product_id' => $params['product_id'], + 'group_id' => $params['group_id'], + 'before_price' => $params['before_price'], + 'after_price' => $params['after_price'] + ]); + + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 删除价格变更记录 + * @param array $params + * @return bool + * @author admin + * @date 2025/01/10 15:54 + */ + public static function delete(array $params): bool + { + return ChangePriceLog::destroy($params['id']); + } + + + /** + * @notes 获取价格变更记录详情 + * @param $params + * @return array + * @author admin + * @date 2025/01/10 15:54 + */ + public static function detail($params): array + { + return ChangePriceLog::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/store/validate/change_price_log/ChangePriceLogValidate.php b/app/store/validate/change_price_log/ChangePriceLogValidate.php new file mode 100644 index 000000000..66d0f8d5a --- /dev/null +++ b/app/store/validate/change_price_log/ChangePriceLogValidate.php @@ -0,0 +1,82 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return ChangePriceLogValidate + * @author admin + * @date 2025/01/10 15:54 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return ChangePriceLogValidate + * @author admin + * @date 2025/01/10 15:54 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return ChangePriceLogValidate + * @author admin + * @date 2025/01/10 15:54 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return ChangePriceLogValidate + * @author admin + * @date 2025/01/10 15:54 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file