feature/main20240421
lqmac 6 months ago
parent d1d1c955e3
commit 6a7f3c06c9
  1. 10
      app/admin/controller/Channel.php
  2. 111
      app/admin/controller/Store.php
  3. 4
      app/api/controller/Merchant.php
  4. 18
      app/common/model/Channel.php
  5. 2
      app/common/model/Merchant.php
  6. 7
      app/store/model/Goods.php
  7. 47
      app/store/model/store/User.php
  8. 4
      app/store/model/store/UserRole.php

@ -33,7 +33,15 @@ class Channel extends Controller
public function index(): Json
{
$model = new ChannelModel;
$list = $model->getList();
$list = $model->getList()->toArray();
foreach ($list['data'] as $kr => $r) {
$res[$kr]['licenseImg'] = [];
if ($r['license_img_id']) {
$img_ids = explode(",", $r['license_img_id']);
$files = UploadFile::getFileList($img_ids);
$list['data'][$kr]['licenseImg'] = $files ?: null;
}
}
return $this->renderSuccess(compact('list'));
}

@ -17,6 +17,11 @@ use app\admin\model\Store as StoreModel;
use app\admin\model\store\SyncTask;
use app\admin\service\store\User as StoreUserService;
use app\common\model\Channel;
use app\common\model\Merchant;
use app\store\model\store\User as StoreUserModel;
use app\store\model\store\Role as role;
use think\facade\Db;
/**
* 商城管理
* Class Store
@ -214,6 +219,104 @@ class Store extends Controller
public function auth(int $storeId): Json
{
$platformList = $this->request->param('platformList');
//多商户新增一个商户用户
$model = StoreModel::detail($storeId);
$storeUserModel = new StoreUserModel;
if ($model->store_version == 1) {
if ($platformList) {
foreach ($platformList as $value) {
$channel = Channel::where('code', $value)->where('status',1)->find();
if ($channel->isEmpty()) {
return $this->renderError('当前渠道不存在');
}
$user_name = $channel->code.$storeId;
//当前账号是否创建
$merchant = Merchant::where('channel_id', $channel->id)->where('store_id', $storeId)->where('is_delete', 0)->find();
if ($merchant) {
continue;
}
//创建账号
//查出当前店铺的商户角色的id
$whererole = [
'store_id' => $storeId,
'role_name' => "商户"
];
$role = role::detail($whererole);
if (!$role) {
return $this->renderError('当前多商户商城商户角色不存在');
}
$params = [
"real_name" => $channel->name,
"user_name" => $user_name,
"roles" => [$role->role_id],
"password" => "123456",
"password_confirm" => "123456",
"sort" => 100,
'storeId' => $storeId,
];
// var_dump($params);
// exit();
$storeUserModel->addNew($params);
//复制商户
$merchantData = [
"shop_name" => $channel->shop_name,
"shop_label" => $channel->shop_label,
"channel_id" => $channel->id,
"channel" => $channel->code,
"store_id" => $storeId,
"user_name" => $user_name,
"score" => 5,
"sale" => 100,
"sort" => 100,
"license_img_id" => "",
"logo_image_id" => 0,
"create_time" => time(),
];
// var_dump($merchantData);
// exit();
if ($channel->logo_image_id) {
//复制图片
$upload_file = Db::name('upload_file')->where('file_id', $channel->logo_image_id)->find();
if ($upload_file) {
$upload_file['store_id'] = $storeId;
$upload_file['create_time'] = time();
unset($upload_file['file_id']);
$logo_image_id = Db::name('upload_file')->insertGetId($upload_file);
$merchantData['logo_image_id'] = $logo_image_id;
}
}
if ($channel->license_img_id) {
$arr = explode(",", $channel->license_img_id);
$license_img_ids = [];
foreach ($arr as $key => $val) {
//复制图片
$upload_file = Db::name('upload_file')->where('file_id', $val)->find();
if ($upload_file) {
$upload_file['store_id'] = $storeId;
$upload_file['create_time'] = time();
unset($upload_file['file_id']);
$license_img_id = Db::name('upload_file')->insertGetId($upload_file);
$license_img_ids[] = $license_img_id;
}
}
$merchantData['license_img_id'] = implode(",", $license_img_ids);
}
Merchant::create($merchantData);
}
}
}
// var_dump($model->store_version);
// exit();
$currItems = SyncTask::where('store_id', $storeId)->select()->toArray();
if ($currItems) {
$delIds = [];
@ -234,10 +337,17 @@ class Store extends Controller
if (in_array($platform, $curr_channels)) {
continue;
}
$merchantId = 0;
if ($model->store_version == 1) {
$merchant = Merchant::where('channel', $platform)->where('store_id', $storeId)->find();
$merchantId = $merchant->merchant_id;
}
$inData[] = [
'store_id' => $storeId,
'channel' => $platform,
'create_time' => time(),
'merchant_id' => $merchantId,
];
}
if ($inData) {
@ -258,5 +368,4 @@ class Store extends Controller
}

@ -133,7 +133,9 @@ class Merchant extends Controller
$pageSize = empty($pageSize) ? 15 : $pageSize;
$sort = $this->request->param('sort');
$sort = empty($sort) ? "merchant_id" : $sort;
$list = $model->getList($this->request->param(), intval($pageSize), $sort)->toArray();
$params = $this->request->param();
$params['is_select_mechant'] = 1;
$list = $model->getList($params, intval($pageSize), $sort)->toArray();
foreach ($list['data'] as $kr => $r) {
$res[$kr]['licenseImg'] = [];

@ -33,6 +33,24 @@ class Channel extends BaseModel
// app()->request->setStoreId(0);
}
/**
* 关联logo图片
* @return HasOne
*/
public function logoImage(): HasOne
{
return $this->hasOne('UploadFile', 'file_id', 'logo_image_id');
}
/**
* 关联logo图片
* @return HasOne
*/
public function licenseImage(): HasMany
{
return $this->HasMany('UploadFile', 'file_id', 'license_img_id');
}
/**
* 菜单信息
* @param int|array $where

@ -127,7 +127,7 @@ class Merchant extends BaseModel
// 搜索关键词
!empty($params['search']) && $filter[] = ['shop_name|shop_label', 'like', "%{$params['search']}%"];
// 门店状态
//is_numeric($params['status']) && $filter[] = ['status', '=', (int)$params['status']];
isset($params['is_select_mechant']) && $filter[] = ['is_select_mechant', '=', (int)$params['is_select_mechant']];
return $filter;
}

@ -321,8 +321,12 @@ class Goods extends GoodsModel
}
$data['alone_grade_equity'] = $aloneGradeEquity;
$categoryIds = $data['categoryIds'];
if ($categoryIds && isset($categoryIds[0]['value'])) {
$categoryIds = array_column($categoryIds, 'value');
}
$data['categoryIds'] = $this->dealCategory($data['categoryIds']);
$data['categoryIds'] = $this->dealCategory($categoryIds);
return $data;
}
@ -330,6 +334,7 @@ class Goods extends GoodsModel
public function dealCategory($category){
$arr = [];
// var_dump($category);
// exit();
foreach ($category as $key => $value) {
//一级
$cate = CategoryRelModel::where('category_id', $value)->find();

@ -15,6 +15,7 @@ namespace app\store\model\store;
use app\common\library\helper;
use app\common\model\store\User as StoreUserModel;
use app\admin\service\store\User as StoreUserService;
use think\facade\Db;
/**
* 商家用户模型
@ -124,7 +125,49 @@ class User extends StoreUserModel
}
return $list;
}
/**
* 新增记录
* @param array $data
* @return bool
*/
public function addNew(array $data): bool
{
$data['user_name'] = strtolower($data['user_name']);
if (self::checkExist($data['user_name'])) {
$this->error = '用户名已存在';
return false;
}
if ($data['password'] !== $data['password_confirm']) {
$this->error = '确认密码不正确';
return false;
}
if (empty($data['roles'])) {
$this->error = '请选择所属角色';
return false;
}
// 整理数据
$data['password'] = encryption_hash($data['password']);
$data['store_id'] = $data['storeId'] ?? self::$storeId;
$data['is_super'] = 0;
// 事务处理
$this->transaction(function () use ($data) {
$roles = $data['roles'];
$storeId = $data['storeId'];
unset($data['roles']);
unset($data['storeId']);
unset($data['password_confirm']);
$data['create_time'] = time();
// 新增管理员记录
$store_user_id = Db::name('store_user')->insertGetId($data);
// $ret = $this->save($data);
// var_dump($ret);
// exit();
// 新增角色关系记录
UserRole::increased((int)$store_user_id, $roles, $storeId);
});
return true;
}
/**
* 新增记录
* @param array $data
@ -147,7 +190,7 @@ class User extends StoreUserModel
}
// 整理数据
$data['password'] = encryption_hash($data['password']);
$data['store_id'] = self::$storeId;
$data['store_id'] = $data['storeId'] ?? self::$storeId;
$data['is_super'] = 0;
// 事务处理
@ -155,7 +198,7 @@ class User extends StoreUserModel
// 新增管理员记录
$this->save($data);
// 新增角色关系记录
UserRole::increased((int)$this['store_user_id'], $data['roles']);
UserRole::increased((int)$this['store_user_id'], $data['roles'], $data['storeId'] ?? 0);
});
return true;
}

@ -27,14 +27,14 @@ class UserRole extends UserRoleModel
* @param array $roleIds
* @return array|false
*/
public static function increased(int $storeUserId, array $roleIds)
public static function increased(int $storeUserId, array $roleIds, int $storeId = 0)
{
$data = [];
foreach ($roleIds as $roleId) {
$data[] = [
'store_user_id' => $storeUserId,
'role_id' => $roleId,
'store_id' => self::$storeId,
'store_id' => $storeId ? $storeId : self::$storeId,
];
}
return (new static)->addAll($data);

Loading…
Cancel
Save