From abb5d1d39396b08fc586cf55f615325f2d473966 Mon Sep 17 00:00:00 2001 From: limu Date: Thu, 25 Jan 2024 16:49:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A5=E9=A9=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/Store.php | 23 ++++++++- app/api/service/Store.php | 69 +++++++++++++++++++++++++- app/api/validate/store/Store.php | 42 ++++++++++++++++ app/common/model/store/StoreSettle.php | 32 ++++++++++++ 4 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 app/api/validate/store/Store.php create mode 100644 app/common/model/store/StoreSettle.php diff --git a/app/api/controller/Store.php b/app/api/controller/Store.php index ef117773..eba08597 100644 --- a/app/api/controller/Store.php +++ b/app/api/controller/Store.php @@ -18,6 +18,7 @@ use app\api\service\Store as StoreService; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; +use app\api\validate\store\Store as StoreValidte; /** * 商城基础信息 @@ -43,12 +44,32 @@ class Store extends Controller { // 当前用户信息 $userInfo = UserService::getCurrentLoginUser(true); + $params = $this->request->param(); + $validate = new StoreValidte(); + // 表单验证 + if (!$validate->check($params)) { + return $this->renderError($validate->getError()); + } $service = new StoreService; - return $this->renderSuccess('申请成功,请耐心等待'); + $res = $service->joinStore($params, $userInfo->user_id); + if ($res['code'] == 0) { + return $this->renderSuccess('申请成功,请耐心等待'); + } else { + return $this->renderError($res['msg']); + } + } public function getStoreType(): Json { return $this->renderSuccess(config('store.store_type')); } + + public function joinData():Json + { + // 当前用户信息 + $userInfo = UserService::getCurrentLoginUser(true); + $service = new StoreService; + return $this->renderSuccess($service->joinData($userInfo->user_id)); + } } \ No newline at end of file diff --git a/app/api/service/Store.php b/app/api/service/Store.php index 507e09f6..3b85f69d 100644 --- a/app/api/service/Store.php +++ b/app/api/service/Store.php @@ -17,7 +17,10 @@ use app\api\service\Client as ClientService; use app\api\service\Setting as SettingService; use app\api\model\store\Module as StoreModuleModel; use app\api\model\dealer\Setting as DealerSettingModel; +use app\common\model\store\StoreSettle; use app\common\service\BaseService; +use think\facade\Db; +use think\Exception; /** * 商城基础信息 @@ -111,8 +114,72 @@ class Store extends BaseService } //申请入驻 - public function joinStore() + public function joinStore($data, $user_id) { + $has = \app\admin\model\Store::where(['user_id' => $user_id])->find(); + if ($has) { + return ['code' => 1, 'msg' => '请勿重复申请入驻']; + } + //商城主体信息 + $addData = [ + 'store_name' => $data['store_name'], + 'user_id' => $user_id, + 'sort' => 100, + 'create_time' => time(), + 'update_time' => time(), + 'status' => 0 + ]; + try { + // 新增记录 + $model = new \app\admin\model\Store; + $res = $model->insertGetId($addData); + if (!$res) { + throw new Exception($model->getError()); + } + //附加资料 + $settleData = [ + 'store_id' => $res, + 'store_cat' => $data['store_cat'], + 'store_address' => $data['store_address'], + 'store_brand' => $data['store_brand'], + 'store_settle_type' => $data['store_settle_type'], + 'authorize' => $data['authorize'], + 'has_tax' => $data['has_tax'], + 'user_name' => $data['user_name'], + 'user_position' => $data['user_position'], + 'user_mobile' => $data['user_mobile'], + 'user_wx' => $data['user_wx'], + 'user_email' => $data['user_email'], + 'store_model' => $data['store_model'], + 'send_type' => $data['send_type'], + 'has_factory' => $data['has_factory'], + 'has_offline' => $data['has_offline'], + 'has_online_shop' => $data['has_online_shop'], + 'created_at' => time(), + 'store_type' => empty($data['has_online_shop']) ? json_encode([]) : json_encode($data['store_type']), + ]; + $settleModel = new StoreSettle(); + if (!$settleModel->insert($settleData)) { + throw new Exception($settleModel->getError()); + } + return ['code' => 0, 'msg' => 'success']; + } catch (\Exception $e) { + return ['code' => 1, 'msg' => $e->getMessage()]; + } + } + public function joinData($user_id) + { + $storeInfo = Db::query('select * from yoshop_store where user_id = ' . $user_id); + $settle = []; + if (!empty($storeInfo)) { + $res = Db::query('select * from yoshop_store_settle where store_id = ' . $storeInfo[0]['store_id']); + $settle = $res ? $res[0] : []; + $settle['store_type'] = json_decode($settle['store_type']); + } + return [ + 'info' => $storeInfo, + 'settle' => $settle, + ]; } } \ No newline at end of file diff --git a/app/api/validate/store/Store.php b/app/api/validate/store/Store.php new file mode 100644 index 00000000..602c0bf2 --- /dev/null +++ b/app/api/validate/store/Store.php @@ -0,0 +1,42 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\api\validate\store; + +use think\Validate; + +/** + * 验证类:订单提交 + * Class Checkout + * @package app\api\validate\order + */ +class Store extends Validate +{ + /** + * 验证规则 + * @var array + */ + protected $rule = [ + 'store_name' => ['require'], + 'store_cat' => ['require'], + 'store_address' => ['require',], + 'store_brand' => ['require',], + 'user_name' => ['require',], + 'user_position' => ['require',], + 'user_mobile' => ['require', 'number'], + 'user_wx' => ['require',], + 'user_email' => ['require',], + 'store_model' => ['require',], + 'store_type' => ['require',], + ]; + +} diff --git a/app/common/model/store/StoreSettle.php b/app/common/model/store/StoreSettle.php new file mode 100644 index 00000000..0d7c8353 --- /dev/null +++ b/app/common/model/store/StoreSettle.php @@ -0,0 +1,32 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\common\model\store; + +use cores\BaseModel; +use app\common\model\Region as RegionModel; +use think\model\relation\HasOne; + +/** + * 商家入驻资料 + * Class Shop + * @package app\common\model\store + */ +class StoreSettle extends BaseModel +{ + // 定义表名 + protected $name = 'store_settle'; + + // 定义主键 + protected $pk = 'id'; + +}