From 3371a7391e290537e64460bb45bae7bcc54ff83c Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Tue, 19 Mar 2024 10:59:11 +0800 Subject: [PATCH] =?UTF-8?q?app=E7=89=88=E6=9C=AC=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=92=8C=E5=95=86=E6=88=B7=E5=95=86=E5=93=81=E7=9A=84=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=89=B9=E5=8F=91=E4=BB=B7=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/system/AppUpdateDao.php | 56 +++++++++++++ app/common/model/system/AppUpdate.php | 20 +++++ .../store/product/ProductRepository.php | 4 + .../repositories/system/LhappRepository.php | 64 ++++++++++++++ app/controller/admin/system/Lhapp.php | 84 +++++++++++++++++++ 5 files changed, 228 insertions(+) create mode 100644 app/common/dao/system/AppUpdateDao.php create mode 100644 app/common/model/system/AppUpdate.php create mode 100644 app/common/repositories/system/LhappRepository.php create mode 100644 app/controller/admin/system/Lhapp.php diff --git a/app/common/dao/system/AppUpdateDao.php b/app/common/dao/system/AppUpdateDao.php new file mode 100644 index 00000000..be39bb94 --- /dev/null +++ b/app/common/dao/system/AppUpdateDao.php @@ -0,0 +1,56 @@ + +// +---------------------------------------------------------------------- + + +namespace app\common\dao\system; + + +use app\common\dao\BaseDao; +use app\common\model\BaseModel; +use app\common\model\system\AppUpdate; +use think\db\exception\DbException; + +/** + * Class AppUpdateDao + * @package app\common\dao\system + * @author xaboy + * @day 2020-04-24 + */ +class AppUpdateDao extends BaseDao +{ + + /** + * @return BaseModel + * @author xaboy + * @day 2020-03-30 + */ + protected function getModel(): string + { + return AppUpdate::class; + } + + public function search(array $where = []) + { + return AppUpdate::getDB() + ->when(isset($where['id']) && $where['id'] !== '',function($query) use($where){ + $query->where('id',$where['id']); + }) + ->when(isset($where['type']) && $where['type'] !== '',function($query) use($where){ + $query->where('type',$where['type']); + }); + } + public function delete(int $id) + { + return ($this->getModel()::getDB())->where('id', $id)->delete(); + } + +} diff --git a/app/common/model/system/AppUpdate.php b/app/common/model/system/AppUpdate.php new file mode 100644 index 00000000..e9b57ba2 --- /dev/null +++ b/app/common/model/system/AppUpdate.php @@ -0,0 +1,20 @@ +save($id, $settleParams, $content, $product, $productType); if ($productType == 1) { //秒杀商品 @@ -652,6 +653,8 @@ class ProductRepository extends BaseRepository !$cdkeey_stock ?: $value['stock'] = $cdkeey_stock; } $new_price = $value['price'] ? (($value['price'] < 0) ? 0 : $value['price']) : 0; + + $wholesale_price = $value['wholesale_price'] ? (($value['wholesale_price'] < 0) ? 0 : $value['wholesale_price']) : 0; $new_stock = $value['stock'] ? (($value['stock'] < 0) ? 0 : $value['stock']) : 0; $array = [ 'detail' => json_encode($value['detail'] ?? ''), @@ -659,6 +662,7 @@ class ProductRepository extends BaseRepository "image" => $value["image"] ?? '', "cost" => $value['cost'] ? (($value['cost'] < 0) ? 0 : $value['cost']) : 0, "price" => $new_price, + "wholesale_price" => $wholesale_price, "volume" => isset($value['volume']) ? ($value['volume'] ? (($value['volume'] < 0) ? 0 : $value['volume']) : 0) : 0, "weight" => isset($value['weight']) ? ($value['weight'] ? (($value['weight'] < 0) ? 0 : $value['weight']) : 0) : 0, "stock" => $new_stock, diff --git a/app/common/repositories/system/LhappRepository.php b/app/common/repositories/system/LhappRepository.php new file mode 100644 index 00000000..2568824b --- /dev/null +++ b/app/common/repositories/system/LhappRepository.php @@ -0,0 +1,64 @@ + +// +---------------------------------------------------------------------- + + +namespace app\common\repositories\system; + + +use app\common\dao\system\AppUpdateDao; +use app\common\repositories\BaseRepository; +use think\db\exception\DbException; +use think\exception\ValidateException; +use think\facade\Cache; + +/** + * Class LhappRepository + * @package app\common\repositories\system + * @author xaboy + * @day 2020-04-24 + * @mixin CacheDao + */ +class LhappRepository extends BaseRepository +{ + + + /** + * CacheRepository constructor. + * @param CacheDao $dao + */ + public function __construct(AppUpdateDao $dao) + { + $this->dao = $dao; + } + + public function getList($where, $page, $limit) + { + $query = $this->dao->search($where); + $count = $query->count(); + $list = $query->page($page, $limit)->order('id DESC')->select(); + return compact('count', 'list'); + } + + public function detail($id) + { + $find = $this->dao->search(['id' => $id])->find(); + if (!$find) throw new ValidateException('数据不存在'); + return $find; + } + + public function delete($id) + { + $res = $this->dao->delete($id); + return $res; + } + +} diff --git a/app/controller/admin/system/Lhapp.php b/app/controller/admin/system/Lhapp.php new file mode 100644 index 00000000..344ce0bd --- /dev/null +++ b/app/controller/admin/system/Lhapp.php @@ -0,0 +1,84 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\admin\system; + +use app\common\repositories\system\LhappRepository; +use think\exception\ValidateException; +use crmeb\basic\BaseController; +use think\App; + +class Lhapp extends BaseController +{ + /** + * @var LhappRepository + */ + protected $repository; + + /** + * CacheRepository constructor. + * @param App $app + */ + public function __construct(App $app, LhappRepository $repository) + { + parent::__construct($app); + $this->repository = $repository; + } + + public function list() + { + [$page, $limit] = $this->getPage(); + $where = $this->request->params(['type']); + return app('json')->success($this->repository->getList($where, $page, $limit)); + } + + public function create() + { + $this->repository->create($this->getValidParams()); + return app('json')->success('添加成功'); + } + + public function update($id) + { + if (!$this->repository->exists($id)) { + return app('json')->fail('数据不存在'); + } + $this->repository->update($id, $this->getValidParams()); + return app('json')->success('修改成功'); + } + + public function detail($id) + { + $data = $this->repository->detail($id); + return app('json')->success($data); + } + + public function delete($id) + { + $res = $this->repository->delete($id); + if ($res) { + return app('json')->success('删除成功'); + } else { + return app('json')->fail('删除失败'); + } + } + + protected function getValidParams() + { + $data = $this->request->params(['title', 'content', 'type', 'phone_brand', 'version', 'dow_url', 'force', 'quiet']); + if (empty($data['title'])) throw new ValidateException('title标题不能为空'); + if (empty($data['content'])) throw new ValidateException('content内容不能为空'); + if (empty($data['type'])) throw new ValidateException('type类型不能为空'); + if (empty($data['version'])) throw new ValidateException('version版本号不能为空'); + if (empty($data['dow_url'])) throw new ValidateException('dow_url下载地址不能为空'); + return $data; + } + +}