From 37cdc10f62b8124ea75a820e03703e13bfb3263b Mon Sep 17 00:00:00 2001 From: guojia <445241500@qq.com> Date: Sun, 28 Apr 2024 21:20:57 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/Merchant.php | 11 +-- app/common/model/Style.php | 92 ++++++++++++++++++++++++++ app/store/controller/Merchant.php | 25 ++++++- app/store/model/Style.php | 65 ++++++++++++++++++ public/install/data/install_struct.sql | 15 ++++- 5 files changed, 200 insertions(+), 8 deletions(-) create mode 100644 app/common/model/Style.php create mode 100644 app/store/model/Style.php diff --git a/app/common/model/Merchant.php b/app/common/model/Merchant.php index 907adce0..3f39f2ce 100644 --- a/app/common/model/Merchant.php +++ b/app/common/model/Merchant.php @@ -29,9 +29,9 @@ class Merchant extends BaseModel protected $pk = 'merchant_id'; /** - * 关联logo图片 - * @return HasOne - */ + * 关联logo图片 + * @return HasOne + */ public function logoImage(): HasOne { return $this->hasOne('UploadFile', 'file_id', 'logo_image_id'); @@ -41,11 +41,12 @@ class Merchant extends BaseModel * 关联logo图片 * @return HasOne */ - public function licenseImage(): HasOne + public function licenseImage(): HasMany { - return $this->hasOne('UploadFile', 'file_id', 'license_img_id'); + return $this->HasMany('UploadFile', 'file_id', 'license_img_id'); } + /** * 详情信息 * @param int $storeId diff --git a/app/common/model/Style.php b/app/common/model/Style.php new file mode 100644 index 00000000..2dc5a29d --- /dev/null +++ b/app/common/model/Style.php @@ -0,0 +1,92 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\common\model; + +use cores\BaseModel; +use think\model\relation\HasOne; + +/** + * 商家记录表模型 + * Class Store + * @package app\common\model + */ +class Style extends BaseModel +{ + // 定义表名 + protected $name = 'style'; + + // 定义主键 + protected $pk = 'style_id'; + + + /** + * 详情信息 + * @param int $storeId + * @return static|array|null + */ + public static function detail() + { + try { + $list = self::withoutGlobalScope() + ->where('1', '=', 1) + ->find(); + return $list ?? null; + } catch (\Exception $e) { + return null; + } + } + + /** + * 获取列表数据 + * @param bool $isRecycle 是否在回收站 + * @return \think\Paginator + * @throws \think\db\exception\DbException + */ + public function getList(array $param = []): \think\Paginator + { + return $this->with(['logoImage']) + ->where($this->getFilter($param)) + ->where('is_delete', '=', 0) + ->order(['sort' => 'asc', $this->getPk()]) + ->paginate(15); + } + + /** + * 设置列表查询条件 + * @param array $param + * @return array + */ + private function getFilter(array $param = []): array + { + // 默认查询参数 + $params = $this->setQueryDefaultValue($param, [ + 'search' => '', // 搜索关键词: 门店名称/联系人/电话 + ]); + // 检索查询条件 + $filter = []; + // 搜索关键词 + !empty($params['search']) && $filter[] = ['shop_name|shop_label', 'like', "%{$params['search']}%"]; + // 门店状态 + //is_numeric($params['status']) && $filter[] = ['status', '=', (int)$params['status']]; + return $filter; + } + + /** + * 软删除 + * @return bool + */ + public function setDelete(): bool + { + return $this->save(['is_delete' => 1]); + } +} diff --git a/app/store/controller/Merchant.php b/app/store/controller/Merchant.php index 6f7c0db9..6c782f67 100644 --- a/app/store/controller/Merchant.php +++ b/app/store/controller/Merchant.php @@ -15,6 +15,7 @@ namespace app\store\controller; use app\common\model\store\StoreSettle; use think\response\Json; use app\store\model\Merchant as MerchantModel; +use app\store\model\Style as StyleModel; use app\common\model\Channel; use app\store\model\store\User as StoreUserModel; @@ -25,7 +26,6 @@ use app\store\model\store\User as StoreUserModel; */ class Merchant extends Controller { - /** * 获取当前登录的商城信息 * @return Json @@ -46,7 +46,6 @@ class Merchant extends Controller $userIds = array_column($list2['data'], "user_name"); $list = array_diff($list, $userIds); - return $this->renderSuccess(compact('list')); } @@ -125,4 +124,26 @@ class Merchant extends Controller return $this->renderSuccess(compact('detail')); } + /** + * 更新商城信息 + * @return Json + */ + public function setPageStyle(): Json + { + // 新增记录 + $model = new StyleModel; + $data = $this->postForm(); + if ($model->add($data)) { + return $this->renderSuccess('添加成功'); + } + return $this->renderError($model->getError() ?: '添加失败'); + } + + public function getPageStyle(): Json + { + // 新增记录 + $detail = StyleModel::detail(); + return $this->renderSuccess(compact('detail')); + } + } diff --git a/app/store/model/Style.php b/app/store/model/Style.php new file mode 100644 index 00000000..ada6cd9e --- /dev/null +++ b/app/store/model/Style.php @@ -0,0 +1,65 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\store\model; + +use app\common\model\Style as model; + +/** + * 商家记录表模型 + * Class Store + * @package app\store\model + */ +class Style extends model +{ + /** + * 更新记录 + * @param array $data + * @return bool + */ + public function edit(array $data): bool + { + // 是否删除图片 + !isset($data['logo_image_id']) && $data['logo_image_id'] = 0; + return $this->save($data) !== false; + } + + /** + * 新增记录 + * @param array $data + * @return bool + */ + public function add(array $data): bool + { + return $this->save($this->createData($data)); + } + + /** + * 创建数据 + * @param array $data + * @return array + */ + private function createData(array $data): array + { + $data['store_id'] = self::$storeId; + return $data; + } + + /** + * 软删除 + * @return bool + */ + public function setDelete(): bool + { + return $this->save(['is_delete' => 1]); + } +} diff --git a/public/install/data/install_struct.sql b/public/install/data/install_struct.sql index e3cb8327..94c593ef 100644 --- a/public/install/data/install_struct.sql +++ b/public/install/data/install_struct.sql @@ -1716,7 +1716,7 @@ CREATE TABLE `yoshop_merchant` ( `shop_name` varchar(100) NOT NULL DEFAULT '' COMMENT '名称', `shop_label` varchar(100) NOT NULL DEFAULT '' COMMENT '标签', `logo_image_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '门店logo图片ID', -`license_img_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '营业执照图片ID', +`license_img_id` varchar(200) NOT NULL DEFAULT '' COMMENT '营业执照图片ID', `user_name` varchar(100) NOT NULL DEFAULT '' COMMENT '买家用户名', `sort` int(11) NOT NULL DEFAULT '0' COMMENT '门店排序(数字越小越靠前)', `is_delete` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '是否删除', @@ -1727,6 +1727,19 @@ CREATE TABLE `yoshop_merchant` ( KEY `store_id` (`store_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='商户表'; +DROP TABLE IF EXISTS `yoshop_style`; +CREATE TABLE `yoshop_style` ( + `style_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', + `style` varchar(100) NOT NULL DEFAULT '' COMMENT '风格', + `is_delete` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '是否删除', + `store_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商城ID', + `merchant_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商户ID', + `create_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间', + `update_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间', + PRIMARY KEY (`style_id`), + KEY `store_id` (`store_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='风格表'; + DROP TABLE IF EXISTS `yoshop_squarelike`; CREATE TABLE `yoshop_squarelike` ( `squarelike_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',