pull/1/head
limu 10 months ago
parent b89c162045
commit abb5d1d393
  1. 23
      app/api/controller/Store.php
  2. 69
      app/api/service/Store.php
  3. 42
      app/api/validate/store/Store.php
  4. 32
      app/common/model/store/StoreSettle.php

@ -18,6 +18,7 @@ use app\api\service\Store as StoreService;
use think\db\exception\DataNotFoundException; use think\db\exception\DataNotFoundException;
use think\db\exception\DbException; use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException; 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); $userInfo = UserService::getCurrentLoginUser(true);
$params = $this->request->param();
$validate = new StoreValidte();
// 表单验证
if (!$validate->check($params)) {
return $this->renderError($validate->getError());
}
$service = new StoreService; $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 public function getStoreType(): Json
{ {
return $this->renderSuccess(config('store.store_type')); 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));
}
} }

@ -17,7 +17,10 @@ use app\api\service\Client as ClientService;
use app\api\service\Setting as SettingService; use app\api\service\Setting as SettingService;
use app\api\model\store\Module as StoreModuleModel; use app\api\model\store\Module as StoreModuleModel;
use app\api\model\dealer\Setting as DealerSettingModel; use app\api\model\dealer\Setting as DealerSettingModel;
use app\common\model\store\StoreSettle;
use app\common\service\BaseService; 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,
];
} }
} }

@ -0,0 +1,42 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
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',],
];
}

@ -0,0 +1,32 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
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';
}
Loading…
Cancel
Save