diff --git a/app/admin/controller/product_source_link/ProductSourceLinkController.php b/app/admin/controller/product_source_link/ProductSourceLinkController.php new file mode 100644 index 000000000..e910267d7 --- /dev/null +++ b/app/admin/controller/product_source_link/ProductSourceLinkController.php @@ -0,0 +1,95 @@ +<?php + +namespace app\admin\controller\product_source_link; + + +use app\admin\controller\BaseAdminController; +use app\admin\lists\product_source_link\ProductSourceLinkLists; +use app\admin\logic\product_source_link\ProductSourceLinkLogic; +use app\admin\validate\product_source_link\ProductSourceLinkValidate; + + +/** + * 商品溯源管理控制器 + * Class ProductSourceLinkController + * @package app\admin\controller\product_source_link + */ +class ProductSourceLinkController extends BaseAdminController +{ + + + /** + * @notes 获取商品溯源管理列表 + * @return \think\response\Json + * @author admin + * @date 2025/03/12 10:03 + */ + public function lists() + { + return $this->dataLists(new ProductSourceLinkLists()); + } + + + /** + * @notes 添加商品溯源管理 + * @return \think\response\Json + * @author admin + * @date 2025/03/12 10:03 + */ + public function add() + { + $params = (new ProductSourceLinkValidate())->post()->goCheck('add'); + $result = ProductSourceLinkLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ProductSourceLinkLogic::getError()); + } + + + /** + * @notes 编辑商品溯源管理 + * @return \think\response\Json + * @author admin + * @date 2025/03/12 10:03 + */ + public function edit() + { + $params = (new ProductSourceLinkValidate())->post()->goCheck('edit'); + $result = ProductSourceLinkLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ProductSourceLinkLogic::getError()); + } + + + /** + * @notes 删除商品溯源管理 + * @return \think\response\Json + * @author admin + * @date 2025/03/12 10:03 + */ + public function delete() + { + $params = (new ProductSourceLinkValidate())->post()->goCheck('delete'); + ProductSourceLinkLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取商品溯源管理详情 + * @return \think\response\Json + * @author admin + * @date 2025/03/12 10:03 + */ + public function detail() + { + $params = (new ProductSourceLinkValidate())->goCheck('detail'); + $result = ProductSourceLinkLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/controller/product_source_link_info/ProductSourceLinkInfoController.php b/app/admin/controller/product_source_link_info/ProductSourceLinkInfoController.php new file mode 100644 index 000000000..f50a43fd4 --- /dev/null +++ b/app/admin/controller/product_source_link_info/ProductSourceLinkInfoController.php @@ -0,0 +1,95 @@ +<?php + +namespace app\admin\controller\product_source_link_info; + + +use app\admin\controller\BaseAdminController; +use app\admin\lists\product_source_link_info\ProductSourceLinkInfoLists; +use app\admin\logic\product_source_link_info\ProductSourceLinkInfoLogic; +use app\admin\validate\product_source_link_info\ProductSourceLinkInfoValidate; + + +/** + * 商品溯源详细控制器 + * Class ProductSourceLinkInfoController + * @package app\admin\controller\product_source_link_info + */ +class ProductSourceLinkInfoController extends BaseAdminController +{ + + + /** + * @notes 获取商品溯源详细列表 + * @return \think\response\Json + * @author admin + * @date 2025/03/12 10:08 + */ + public function lists() + { + return $this->dataLists(new ProductSourceLinkInfoLists()); + } + + + /** + * @notes 添加商品溯源详细 + * @return \think\response\Json + * @author admin + * @date 2025/03/12 10:08 + */ + public function add() + { + $params = (new ProductSourceLinkInfoValidate())->post()->goCheck('add'); + $result = ProductSourceLinkInfoLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ProductSourceLinkInfoLogic::getError()); + } + + + /** + * @notes 编辑商品溯源详细 + * @return \think\response\Json + * @author admin + * @date 2025/03/12 10:08 + */ + public function edit() + { + $params = (new ProductSourceLinkInfoValidate())->post()->goCheck('edit'); + $result = ProductSourceLinkInfoLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ProductSourceLinkInfoLogic::getError()); + } + + + /** + * @notes 删除商品溯源详细 + * @return \think\response\Json + * @author admin + * @date 2025/03/12 10:08 + */ + public function delete() + { + $params = (new ProductSourceLinkInfoValidate())->post()->goCheck('delete'); + ProductSourceLinkInfoLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取商品溯源详细详情 + * @return \think\response\Json + * @author admin + * @date 2025/03/12 10:08 + */ + public function detail() + { + $params = (new ProductSourceLinkInfoValidate())->goCheck('detail'); + $result = ProductSourceLinkInfoLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/lists/product_source_link/ProductSourceLinkLists.php b/app/admin/lists/product_source_link/ProductSourceLinkLists.php new file mode 100644 index 000000000..e99c81704 --- /dev/null +++ b/app/admin/lists/product_source_link/ProductSourceLinkLists.php @@ -0,0 +1,67 @@ +<?php + +namespace app\admin\lists\product_source_link; + + +use app\admin\lists\BaseAdminDataLists; +use app\common\model\product_source_link\ProductSourceLink; +use app\common\lists\ListsSearchInterface; + + +/** + * 商品溯源管理列表 + * Class ProductSourceLinkLists + * @package app\admin\listsproduct_source_link + */ +class ProductSourceLinkLists extends BaseAdminDataLists implements ListsSearchInterface +{ + + + /** + * @notes 设置搜索条件 + * @return \string[][] + * @author admin + * @date 2025/03/12 10:03 + */ + public function setSearch(): array + { + return [ + + ]; + } + + + /** + * @notes 获取商品溯源管理列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2025/03/12 10:03 + */ + public function lists(): array + { + return ProductSourceLink::where($this->searchWhere) + ->with(['product','warehouse','purchase']) + // ->join('') + ->field(['id', 'purchase_uid', 'product_id', 'total_nums', 'nums', 'warehouse_id', 'warehouse_total_nums', 'warehouse_nums']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取商品溯源管理数量 + * @return int + * @author admin + * @date 2025/03/12 10:03 + */ + public function count(): int + { + return ProductSourceLink::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/lists/product_source_link_info/ProductSourceLinkInfoLists.php b/app/admin/lists/product_source_link_info/ProductSourceLinkInfoLists.php new file mode 100644 index 000000000..e87e7830f --- /dev/null +++ b/app/admin/lists/product_source_link_info/ProductSourceLinkInfoLists.php @@ -0,0 +1,65 @@ +<?php + +namespace app\admin\lists\product_source_link_info; + + +use app\admin\lists\BaseAdminDataLists; +use app\common\model\product_source_link_info\ProductSourceLinkInfo; +use app\common\lists\ListsSearchInterface; + + +/** + * 商品溯源详细列表 + * Class ProductSourceLinkInfoLists + * @package app\admin\listsproduct_source_link_info + */ +class ProductSourceLinkInfoLists extends BaseAdminDataLists implements ListsSearchInterface +{ + + + /** + * @notes 设置搜索条件 + * @return \string[][] + * @author admin + * @date 2025/03/12 10:08 + */ + public function setSearch(): array + { + return [ + + ]; + } + + + /** + * @notes 获取商品溯源详细列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2025/03/12 10:08 + */ + public function lists(): array + { + return ProductSourceLinkInfo::where($this->searchWhere) + ->field(['id', 'oid', 'product_id', 'nums', 'types', 'link_id', 'total_price']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取商品溯源详细数量 + * @return int + * @author admin + * @date 2025/03/12 10:08 + */ + public function count(): int + { + return ProductSourceLinkInfo::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/logic/product_source_link/ProductSourceLinkLogic.php b/app/admin/logic/product_source_link/ProductSourceLinkLogic.php new file mode 100644 index 000000000..9d25bd9e8 --- /dev/null +++ b/app/admin/logic/product_source_link/ProductSourceLinkLogic.php @@ -0,0 +1,105 @@ +<?php + +namespace app\admin\logic\product_source_link; + + +use app\common\model\product_source_link\ProductSourceLink; +use app\common\logic\BaseLogic; +use support\exception\BusinessException; +use think\facade\Db; + + +/** + * 商品溯源管理逻辑 + * Class ProductSourceLinkLogic + * @package app\admin\logic\product_source_link + */ +class ProductSourceLinkLogic extends BaseLogic +{ + + + /** + * @notes 添加商品溯源管理 + * @param array $params + * @return bool + * @author admin + * @date 2025/03/12 10:03 + */ + public static function add(array $params): bool + { + Db::startTrans(); + try { + ProductSourceLink::create([ + 'purchase_uid' => $params['purchase_uid'], + 'product_id' => $params['product_id'], + 'total_nums' => $params['total_nums'], + 'nums' => $params['nums'], + 'warehouse_id' => $params['warehouse_id'], + 'warehouse_total_nums' => $params['warehouse_total_nums'], + 'warehouse_nums' => $params['warehouse_nums'] + ]); + + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 编辑商品溯源管理 + * @param array $params + * @return bool + * @author admin + * @date 2025/03/12 10:03 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + ProductSourceLink::where('id', $params['id'])->update([ + 'purchase_uid' => $params['purchase_uid'], + 'product_id' => $params['product_id'], + 'total_nums' => $params['total_nums'], + 'nums' => $params['nums'], + 'warehouse_id' => $params['warehouse_id'], + 'warehouse_total_nums' => $params['warehouse_total_nums'], + 'warehouse_nums' => $params['warehouse_nums'] + ]); + + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 删除商品溯源管理 + * @param array $params + * @return bool + * @author admin + * @date 2025/03/12 10:03 + */ + public static function delete(array $params): bool + { + return ProductSourceLink::destroy($params['id']); + } + + + /** + * @notes 获取商品溯源管理详情 + * @param $params + * @return array + * @author admin + * @date 2025/03/12 10:03 + */ + public static function detail($params): array + { + return ProductSourceLink::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/logic/product_source_link_info/ProductSourceLinkInfoLogic.php b/app/admin/logic/product_source_link_info/ProductSourceLinkInfoLogic.php new file mode 100644 index 000000000..fb4acd1cd --- /dev/null +++ b/app/admin/logic/product_source_link_info/ProductSourceLinkInfoLogic.php @@ -0,0 +1,103 @@ +<?php + +namespace app\admin\logic\product_source_link_info; + + +use app\common\model\product_source_link_info\ProductSourceLinkInfo; +use app\common\logic\BaseLogic; +use support\exception\BusinessException; +use think\facade\Db; + + +/** + * 商品溯源详细逻辑 + * Class ProductSourceLinkInfoLogic + * @package app\admin\logic\product_source_link_info + */ +class ProductSourceLinkInfoLogic extends BaseLogic +{ + + + /** + * @notes 添加商品溯源详细 + * @param array $params + * @return bool + * @author admin + * @date 2025/03/12 10:08 + */ + public static function add(array $params): bool + { + Db::startTrans(); + try { + ProductSourceLinkInfo::create([ + 'oid' => $params['oid'], + 'product_id' => $params['product_id'], + 'nums' => $params['nums'], + 'types' => $params['types'], + 'link_id' => $params['link_id'], + 'total_price' => $params['total_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/03/12 10:08 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + ProductSourceLinkInfo::where('id', $params['id'])->update([ + 'oid' => $params['oid'], + 'product_id' => $params['product_id'], + 'nums' => $params['nums'], + 'types' => $params['types'], + 'link_id' => $params['link_id'], + 'total_price' => $params['total_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/03/12 10:08 + */ + public static function delete(array $params): bool + { + return ProductSourceLinkInfo::destroy($params['id']); + } + + + /** + * @notes 获取商品溯源详细详情 + * @param $params + * @return array + * @author admin + * @date 2025/03/12 10:08 + */ + public static function detail($params): array + { + return ProductSourceLinkInfo::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/validate/product_source_link/ProductSourceLinkValidate.php b/app/admin/validate/product_source_link/ProductSourceLinkValidate.php new file mode 100644 index 000000000..5e66b302b --- /dev/null +++ b/app/admin/validate/product_source_link/ProductSourceLinkValidate.php @@ -0,0 +1,82 @@ +<?php + +namespace app\admin\validate\product_source_link; + + +use app\common\validate\BaseValidate; + + +/** + * 商品溯源管理验证器 + * Class ProductSourceLinkValidate + * @package app\admin\validate\product_source_link + */ +class ProductSourceLinkValidate extends BaseValidate +{ + + /** + * 设置校验规则 + * @var string[] + */ + protected $rule = [ + 'id' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return ProductSourceLinkValidate + * @author admin + * @date 2025/03/12 10:03 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return ProductSourceLinkValidate + * @author admin + * @date 2025/03/12 10:03 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return ProductSourceLinkValidate + * @author admin + * @date 2025/03/12 10:03 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return ProductSourceLinkValidate + * @author admin + * @date 2025/03/12 10:03 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/admin/validate/product_source_link_info/ProductSourceLinkInfoValidate.php b/app/admin/validate/product_source_link_info/ProductSourceLinkInfoValidate.php new file mode 100644 index 000000000..a7c1e602e --- /dev/null +++ b/app/admin/validate/product_source_link_info/ProductSourceLinkInfoValidate.php @@ -0,0 +1,82 @@ +<?php + +namespace app\admin\validate\product_source_link_info; + + +use app\common\validate\BaseValidate; + + +/** + * 商品溯源详细验证器 + * Class ProductSourceLinkInfoValidate + * @package app\admin\validate\product_source_link_info + */ +class ProductSourceLinkInfoValidate extends BaseValidate +{ + + /** + * 设置校验规则 + * @var string[] + */ + protected $rule = [ + 'id' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return ProductSourceLinkInfoValidate + * @author admin + * @date 2025/03/12 10:08 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return ProductSourceLinkInfoValidate + * @author admin + * @date 2025/03/12 10:08 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return ProductSourceLinkInfoValidate + * @author admin + * @date 2025/03/12 10:08 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return ProductSourceLinkInfoValidate + * @author admin + * @date 2025/03/12 10:08 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 1cded3f70..6e5693568 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -61,14 +61,14 @@ class IndexController extends BaseApiController public function index() { - // $arr=BeforehandOrderCartInfo::where('bhoid',1284)->select(); - // foreach ($arr as $k=>$v){ - // $product_id=StoreBranchProduct::where('id',$v['product_id'])->value('product_id'); - // BeforehandOrderCartInfo::where('id',$v['id'])->update(['product_id'=>$product_id]); - // } - // $a=StoreOrderCartInfo::where('store_id',2)->whereBetweenTime('create_time','2025-01-01','2025-01-8')->select()->toArray(); - // d($a); - // DemoLogic::test(); + $arr= Db::name('ceshi_copy_copy')->select(); + foreach ($arr as $k => $v) { + $find=Db::name('ceshi_copy')->where('product_id',$v['product_id'])->find(); + if($find){ + Db::name('ceshi_copy_copy')->where('id',$v['id'])->update(['price_two'=>bcadd($v['price'],bcmul($v['price'], $find['purchase'], 2),2),'purchase'=>bcadd($v['price'],bcmul($v['price'], $find['price'], 2),2)]); + + } + } d(1); $arr = Db::name('ceshi_copy')->select(); foreach ($arr as $k => $v) { diff --git a/app/common/model/product_source_link/ProductSourceLink.php b/app/common/model/product_source_link/ProductSourceLink.php new file mode 100644 index 000000000..bd816d8e9 --- /dev/null +++ b/app/common/model/product_source_link/ProductSourceLink.php @@ -0,0 +1,37 @@ +<?php + +namespace app\common\model\product_source_link; + + +use app\common\model\BaseModel; +use app\common\model\delivery_service\DeliveryService; +use app\common\model\store_product\StoreProduct; +use app\common\model\warehouse\Warehouse; +use think\model\concern\SoftDelete; + + +/** + * 商品溯源管理模型 + * Class ProductSourceLink + * @package app\common\model\product_source_link + */ +class ProductSourceLink extends BaseModel +{ + use SoftDelete; + protected $name = 'product_source_link'; + protected $deleteTime = 'delete_time'; + + + public function product() + { + return $this->hasOne(StoreProduct::class, 'id', 'product_id')->bind(['product_name' => 'store_name', 'image']); + } + + public function warehouse(){ + return $this->hasOne(Warehouse::class, 'id', 'warehouse_id')->bind(['warehouse_name'=>'name']); + } + + public function purchase(){ + return $this->hasOne(DeliveryService::class, 'uid', 'purchase_uid')->bind(['purchase_nickname'=>'nickname']); + } +} \ No newline at end of file diff --git a/app/common/model/product_source_link_info/ProductSourceLinkInfo.php b/app/common/model/product_source_link_info/ProductSourceLinkInfo.php new file mode 100644 index 000000000..c9bffb6d3 --- /dev/null +++ b/app/common/model/product_source_link_info/ProductSourceLinkInfo.php @@ -0,0 +1,22 @@ +<?php + +namespace app\common\model\product_source_link_info; + + +use app\common\model\BaseModel; +use think\model\concern\SoftDelete; + + +/** + * 商品溯源详细模型 + * Class ProductSourceLinkInfo + * @package app\common\model\product_source_link_info + */ +class ProductSourceLinkInfo extends BaseModel +{ + use SoftDelete; + protected $name = 'product_source_link_info'; + protected $deleteTime = 'delete_time'; + + +} \ No newline at end of file