You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/app/api/service/Store.php

212 lines
7.4 KiB

11 months ago
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\api\service;
use app\api\model\Store as StoreModel;
10 months ago
use \app\common\model\Store as StoreInfoModel;
11 months ago
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\StoreServerConfig;
10 months ago
use app\common\model\store\StoreSettle;
11 months ago
use app\common\service\BaseService;
10 months ago
use think\facade\Db;
use think\Exception;
11 months ago
/**
* 商城基础信息
* Class Store
* @package app\api\service
*/
class Store extends BaseService
{
/**
* 获取商城基础信息
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function data(): array
{
return [
// 店铺基本信息
'storeInfo' => $this->storeInfo(),
// 当前客户端名称
'client' => \getPlatform(),
// 商城设置
'setting' => $this->setting(),
// 分销设置 (仅基础设置)
'dealer' => $this->dealerData(),
// 客户端设置
'clientData' => $this->getClientData(),
// 开启的功能模块
'modules' => $this->getModules(),
//商城服务配置
'storeServerConfig' => $this->getServerConfig()
11 months ago
];
}
/**
* 开启的功能模块
* @return array|mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
10 months ago
private function getModules()
{
11 months ago
return StoreModuleModel::getModules($this->storeId);
}
/**
* 客户端公共数据
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getClientData(): array
{
$service = new ClientService;
return $service->getPublic();
}
/**
* 商城设置
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function setting(): array
{
$service = new SettingService;
return $service->getPublic();
}
/**
* 分销设置 (仅基础设置)
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function dealerData(): array
{
return ['setting' => DealerSettingModel::getPublic()['basic']];
}
/**
* 店铺基本信息(名称、简介、logo)
* @return StoreModel|array|null
*/
private function storeInfo()
{
return StoreModel::getInfo();
}
10 months ago
//申请入驻
10 months ago
public function joinStore($data, $user_id)
10 months ago
{
9 months ago
// $has = Db::query('select * from yoshop_store where user_id = ' . $user_id . ' and status != 2 and is_recycle = 0 and is_delete= 0');
// 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
// ];
$has = Db::query('select * from yoshop_store_settle where user_id = ' . $user_id . ' and status != 2');
10 months ago
if ($has) {
return ['code' => 1, 'msg' => '请勿重复申请入驻'];
}
try {
// 新增记录
9 months ago
// $model = new \app\admin\model\Store;
// $res = $model->insertGetId($addData);
// if (!$res) {
// throw new Exception($model->getError());
// }
10 months ago
//附加资料
$settleData = [
9 months ago
'user_id' => $user_id,
'store_id' => $this->storeId,
10 months ago
'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']),
9 months ago
'status' => 0//审核状态
10 months ago
];
$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()];
}
}
10 months ago
10 months ago
public function joinData($user_id)
{
10 months ago
$storeInfo = Db::query('select * from yoshop_store where user_id = ' . $user_id . ' and and is_recycle = 0 and is_delete= 0');
10 months ago
$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,
];
10 months ago
}
10 months ago
10 months ago
public function getStore()
{
4 months ago
$storeId = $this->storeId;
$storeList = Db::query('select shop_id,shop_name,longitude,latitude from yoshop_store_shop where status = 1 and is_delete= 0 AND store_id = ?',
[$storeId]);
10 months ago
return $storeList;
}
public function getServerConfig() {
$model = new StoreServerConfig();
return $model->with('iconImage')->hidden(['iconImage'])
->order(['sort' => 'desc', 'create_time' => 'desc'])
->select();
}
11 months ago
}