初始版本
This commit is contained in:
535
server/app/adminapi/logic/shop/ShopLogic.php
Executable file
535
server/app/adminapi/logic/shop/ShopLogic.php
Executable file
@@ -0,0 +1,535 @@
|
||||
<?php
|
||||
namespace app\adminapi\logic\shop;
|
||||
use app\common\enum\accountLog\ShopAccountLogEnum;
|
||||
use app\common\enum\shop\ShopEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\logic\ShopAccountLogLogic;
|
||||
use app\common\model\accountLog\ShopAccountLog;
|
||||
use app\common\model\shop\Shop;
|
||||
use app\common\model\shop\ShopCategoryIndex;
|
||||
use app\common\model\shop\ShopGoodsIndex;
|
||||
use app\common\model\shop\ShopImage;
|
||||
use app\common\model\shop\ShopUpdate;
|
||||
use app\common\model\shop\ShopUser;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\FileService;
|
||||
use think\Exception;
|
||||
use think\facade\Db;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* 门店逻辑类
|
||||
* Class ShopLogic
|
||||
* @package app\adminapi\logic\shop
|
||||
*/
|
||||
class ShopLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 添加门店
|
||||
* @param array $params
|
||||
* @return string|true
|
||||
* @author cjhao
|
||||
* @date 2024/10/3 13:30
|
||||
*/
|
||||
public function add(array $params)
|
||||
{
|
||||
try {
|
||||
Db::startTrans();
|
||||
$number = ShopUser::count()+1;
|
||||
$sn = sprintf("%03d", $number);
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
$password = create_password($params['mobile'], $passwordSalt);
|
||||
$avatar = ConfigService::get('default_image', 'user_avatar');
|
||||
$shopUser = ShopUser::where('account','=',$params['mobile'])
|
||||
->findOrEmpty();
|
||||
if(!$shopUser->isEmpty()){
|
||||
throw new Exception('手机号码已存在');
|
||||
}
|
||||
$shopUser = ShopUser::create([
|
||||
'sn' => $sn,
|
||||
'avatar' => $avatar,
|
||||
'account' => $params['mobile'],
|
||||
'password' => $password,
|
||||
]);
|
||||
$shop = Shop::create([
|
||||
'name' => $params['name'],
|
||||
'shop_user_id' => $shopUser['id'],
|
||||
'mobile' => $params['mobile'],
|
||||
'sn' => sprintf("%03d", Shop::count()+1),
|
||||
'short_name' => $params['short_name'],
|
||||
'business_start_time' => '10:00',
|
||||
'business_end_time' => '22:00',
|
||||
'type' => $params['type'],
|
||||
'social_credit_ode' => $params['social_credit_ode'],
|
||||
'legal_person' => $params['legal_person'],
|
||||
'legal_id_card' => $params['legal_id_card'],
|
||||
'province_id' => $params['province_id'],
|
||||
'city_id' => $params['city_id'],
|
||||
'region_id' => $params['region_id'],
|
||||
'shop_address_detail' => $params['shop_address_detail'],
|
||||
'longitude' => $params['longitude'],
|
||||
'latitude' => $params['latitude'],
|
||||
'id_card_front' => $params['id_card_front'],
|
||||
'id_card_back' => $params['id_card_back'],
|
||||
// 'portrait_shooting' => $params['portrait_shooting'],
|
||||
'logo' => $params['logo'],
|
||||
'business_license' => $params['business_license'],
|
||||
'synopsis' => $params['synopsis'] ?? '',
|
||||
'work_status' => $params['work_status'] ?? '',
|
||||
'server_status' => $params['server_status'] ?? '',
|
||||
'audit_status' => ShopEnum::AUDIT_STATUS_PASS,
|
||||
]);
|
||||
$categoryLists = [];
|
||||
foreach ($params['category_ids'] as $categoryId){
|
||||
$categoryLists[] = [
|
||||
'shop_id' => $shop['id'],
|
||||
'category_id' => $categoryId,
|
||||
];
|
||||
}
|
||||
(new ShopCategoryIndex())->saveAll($categoryLists);
|
||||
|
||||
$goodsLists = [];
|
||||
foreach ($params['goods_ids'] as $goodsId) {
|
||||
$goodsLists[] = [
|
||||
'shop_id' => $shop['id'],
|
||||
'goods_id' => $goodsId,
|
||||
];
|
||||
}
|
||||
(new ShopGoodsIndex())->saveAll($goodsLists);
|
||||
|
||||
$shopImageLists = [];
|
||||
foreach ($params['shop_image'] as $image){
|
||||
$shopImageLists[] = [
|
||||
'shop_id' => $shop['id'],
|
||||
'uri' => $image,
|
||||
];
|
||||
}
|
||||
(new ShopImage())->saveAll($shopImageLists);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
|
||||
}catch (Exception $e){
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑门店
|
||||
* @param array $params
|
||||
* @return string|true
|
||||
* @throws \Exception
|
||||
* @author cjhao
|
||||
* @date 2024/10/3 15:11
|
||||
*/
|
||||
public function edit(array $params)
|
||||
{
|
||||
try {
|
||||
Db::startTrans();
|
||||
$shop = Shop::where(['id'=>$params['id']])->findOrEmpty();
|
||||
$shopUser = ShopUser::where('id','<>',$shop['shop_user_id'])
|
||||
->where('account','=',$params['mobile'])
|
||||
->findOrEmpty();
|
||||
if(!$shopUser->isEmpty()){
|
||||
throw new Exception('手机号码已存在');
|
||||
}
|
||||
ShopUser::where(['id'=>$shop['shop_user_id']])->update(['account'=>$params['mobile']]);
|
||||
Shop::update([
|
||||
'id' => $params['id'],
|
||||
'name' => $params['name'],
|
||||
'short_name' => $params['short_name'],
|
||||
'type' => $params['type'],
|
||||
'social_credit_ode' => $params['social_credit_ode'],
|
||||
'mobile' => $params['mobile'],
|
||||
'legal_person' => $params['legal_person'],
|
||||
'legal_id_card' => $params['legal_id_card'],
|
||||
'province_id' => $params['province_id'],
|
||||
'city_id' => $params['city_id'],
|
||||
'region_id' => $params['region_id'],
|
||||
'shop_address_detail'=> $params['shop_address_detail'],
|
||||
'longitude' => $params['longitude'],
|
||||
'latitude' => $params['latitude'],
|
||||
'id_card_front' => $params['id_card_front'],
|
||||
'id_card_back' => $params['id_card_back'],
|
||||
// 'portrait_shooting' => $params['portrait_shooting'],
|
||||
'logo' => $params['logo'],
|
||||
'business_license' => $params['business_license'],
|
||||
'synopsis' => $params['synopsis'] ?? '',
|
||||
'work_status' => $params['work_status'] ?? '',
|
||||
'server_status' => $params['server_status'] ?? '',
|
||||
]);
|
||||
ShopCategoryIndex::where(['shop_id'=>$params['id']])->delete();
|
||||
ShopGoodsIndex::where(['shop_id'=>$params['id']])->delete();
|
||||
ShopImage::where(['shop_id'=>$params['id']])->delete();
|
||||
$categoryLists = [];
|
||||
foreach ($params['category_ids'] as $categoryId){
|
||||
$categoryLists[] = [
|
||||
'shop_id' => $params['id'],
|
||||
'category_id' => $categoryId,
|
||||
];
|
||||
}
|
||||
(new ShopCategoryIndex())->saveAll($categoryLists);
|
||||
|
||||
$goodsLists = [];
|
||||
foreach ($params['goods_ids'] as $goodsId) {
|
||||
$goodsLists[] = [
|
||||
'shop_id' => $params['id'],
|
||||
'goods_id' => $goodsId,
|
||||
];
|
||||
}
|
||||
(new ShopGoodsIndex())->saveAll($goodsLists);
|
||||
$shopImageLists = [];
|
||||
foreach ($params['shop_image'] as $image){
|
||||
$shopImageLists[] = [
|
||||
'shop_id' => $params['id'],
|
||||
'uri' => $image,
|
||||
];
|
||||
}
|
||||
(new ShopImage())->saveAll($shopImageLists);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
|
||||
}catch (Exception $e){
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 店铺详情接口
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @author cjhao
|
||||
* @date 2024/10/4 00:12
|
||||
*/
|
||||
public function detail(int $id)
|
||||
{
|
||||
$detail = Shop::where(['id'=>$id])
|
||||
->append(['shop_image','region_desc','province_name','city_name'])
|
||||
->withoutField('update_time,delete_time')
|
||||
->findOrEmpty()->toArray();
|
||||
$categoryLists = ShopCategoryIndex::alias('SC')
|
||||
->where(['SC.shop_id'=>$id,'is_show'=>1])
|
||||
->join('goods_category GC','SC.category_id = GC.id')
|
||||
->field('GC.id,GC.name')
|
||||
->select()->toArray();
|
||||
$goodsLists = ShopGoodsIndex::alias('SG')
|
||||
->where(['SG.shop_id'=>$id,'G.status'=>1])
|
||||
->join('goods G','SG.goods_id = G.id')
|
||||
->field('G.id,G.image,G.name')
|
||||
->select()->toArray();
|
||||
$detail['shop_image'] = array_column($detail['shop_image']->toArray(),'uri');
|
||||
$detail['category_lists'] = $categoryLists;
|
||||
$detail['category_ids'] = array_column($categoryLists,'id');
|
||||
$detail['goods_lists'] = $goodsLists;
|
||||
return $detail;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 调整余额
|
||||
* @param array $params
|
||||
* @return string|true
|
||||
* @author cjhao
|
||||
* @date 2024/10/3 16:08
|
||||
*/
|
||||
public function adjustMoney(array $params)
|
||||
{
|
||||
try {
|
||||
Db::startTrans();
|
||||
$shop = Shop::where(['id'=>$params['id']])->findOrEmpty();
|
||||
if($shop->isEmpty()){
|
||||
return '店铺不存在';
|
||||
}
|
||||
|
||||
$action = $params['action'];
|
||||
if(1 == $action){
|
||||
|
||||
$shop->money = $shop->money+$params['money'];
|
||||
$shop->save();
|
||||
|
||||
ShopAccountLogLogic::add(
|
||||
$shop->id,
|
||||
ShopAccountLogEnum::MONEY,
|
||||
ShopAccountLogEnum::ADMIN_INC_MONEY,
|
||||
$action,
|
||||
$params['money'],
|
||||
'',
|
||||
$params['admin_id']
|
||||
);
|
||||
|
||||
}else{
|
||||
if($params['money'] > $shop->money){
|
||||
return '当前店铺金额仅剩:'.$shop->money;
|
||||
}
|
||||
$shop->money = $shop->money - $params['money'];
|
||||
$shop->save();
|
||||
ShopAccountLogLogic::add(
|
||||
$shop->id,
|
||||
ShopAccountLogEnum::MONEY,
|
||||
ShopAccountLogEnum::ADMIN_DEC_MONEY,
|
||||
$action,
|
||||
$params['money'],
|
||||
'',
|
||||
$params['admin_id']
|
||||
);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
}catch (Exception $e){
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 调整余额
|
||||
* @param array $params
|
||||
* @return string|true
|
||||
* @author cjhao
|
||||
* @date 2024/10/3 16:08
|
||||
*/
|
||||
public function adjustDeposit(array $params)
|
||||
{
|
||||
try {
|
||||
Db::startTrans();
|
||||
$shop = Shop::where(['id'=>$params['id']])->findOrEmpty();
|
||||
if($shop->isEmpty()){
|
||||
return '店铺不存在';
|
||||
}
|
||||
|
||||
$action = $params['action'];
|
||||
if(1 == $action){
|
||||
|
||||
$shop->deposit = $shop->deposit + $params['money'];
|
||||
$shop->save();
|
||||
|
||||
ShopAccountLogLogic::add(
|
||||
$shop->id,
|
||||
ShopAccountLogEnum::DEPOSIT,
|
||||
ShopAccountLogEnum::ADMIN_INC_DEPOSIT,
|
||||
$action,
|
||||
$params['money'],
|
||||
'',
|
||||
$params['admin_id']
|
||||
);
|
||||
|
||||
}else{
|
||||
if($params['money'] > $shop->deposit){
|
||||
return '当前店铺保证金仅剩:'.$shop->deposit;
|
||||
}
|
||||
$shop->deposit = $shop->deposit - $params['money'];
|
||||
$shop->save();
|
||||
ShopAccountLogLogic::add(
|
||||
$shop->id,
|
||||
ShopAccountLogEnum::DEPOSIT,
|
||||
ShopAccountLogEnum::ADMIN_DEC_DEPOSIT,
|
||||
$action,
|
||||
$params['money'],
|
||||
'',
|
||||
$params['admin_id']
|
||||
);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
}catch (Exception $e){
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 店铺审核
|
||||
* @param array $params
|
||||
* @return string|true
|
||||
* @author cjhao
|
||||
* @date 2024/10/7 00:44
|
||||
*/
|
||||
public function shopAudit(array $params)
|
||||
{
|
||||
try {
|
||||
// Db::startTrans();
|
||||
$shop = Shop::where(['id'=>$params['id']])->findOrEmpty();
|
||||
if($shop->isEmpty()){
|
||||
throw new Exception('店铺不存在');
|
||||
}
|
||||
if(ShopEnum::AUDIT_STATUS_WAIT != $shop->audit_status){
|
||||
throw new Exception( '店铺的审核状态已改变,请刷新页面');
|
||||
}
|
||||
$status = ShopEnum::AUDIT_STATUS_PASS;
|
||||
$auditRemark = $params['audit_remark'] ?? '';
|
||||
$auditStatus = $params['audit_status'] ?? 0;
|
||||
if(0 == $auditStatus){
|
||||
$status = ShopEnum::AUDIT_STATUS_REFUSE;
|
||||
if(empty($auditRemark)){
|
||||
throw new Exception("请输入备注");
|
||||
}
|
||||
}
|
||||
|
||||
$shop->audit_status = $status;
|
||||
$shop->audit_remark = $params['audit_remark'] ?? '';
|
||||
$shop->save();
|
||||
return true;
|
||||
}catch (Exception $e){
|
||||
// Db::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function updateDetail(int $id)
|
||||
{
|
||||
$updateShop = (new ShopUpdate())
|
||||
->where(['id'=>$id])
|
||||
->withoutField('create_time,update_time,delete_time')
|
||||
->append(['region_name','province_name','city_name'])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
$shop = (new Shop())
|
||||
->where(['id'=>$updateShop['shop_id'],'audit_status'=>ShopEnum::AUDIT_STATUS_PASS])
|
||||
->append(['category_ids','goods_ids','shop_image'])
|
||||
->withoutField('create_time,update_time,delete_time')
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
foreach ($updateShop as $key => $update){
|
||||
$cancel = ['id','shop_id','shop_user_id'];
|
||||
if(in_array($key,$cancel)){
|
||||
continue;
|
||||
}
|
||||
$data = $shop[$key] ?? '';
|
||||
$updateShop[$key.'_update'] = $update == $data ? false: true;
|
||||
if('goods_ids' == $key && $data){
|
||||
$goodsIds = array_column($data->toArray(),'goods_id');
|
||||
// foreach ($update as $goodsKey => $goodsId){
|
||||
// $update[$goodsKey] = (int)$goodsId;
|
||||
// }
|
||||
sort($goodsIds);
|
||||
sort($update);
|
||||
$updateShop[$key.'_update'] = $update == $goodsIds ? false : true;
|
||||
}
|
||||
if('category_ids' == $key && $data){
|
||||
$categoryIds = array_column($data->toArray(),'category_id');
|
||||
// foreach ($update as $goodsKey => $goodsId){
|
||||
// $update[$goodsKey] = (int)$goodsId;
|
||||
// }
|
||||
sort($categoryIds);
|
||||
sort($update);
|
||||
$updateShop[$key.'_update'] = $update == $categoryIds ? false : true;
|
||||
}
|
||||
if('shop_image' == $key && $data){
|
||||
$uriLists = array_column($data->toArray(),'uri');
|
||||
foreach ($uriLists as $uriKey => $uri){
|
||||
$uriLists[$uriKey] = FileService::setFileUrl($uri);
|
||||
}
|
||||
sort($uriLists);
|
||||
sort($update);
|
||||
$updateShop[$key.'_update'] = $uriLists == $update ? false : true;
|
||||
}
|
||||
}
|
||||
return $updateShop;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 资料审核
|
||||
* @param $params
|
||||
* @return string|true
|
||||
* @throws \Exception
|
||||
* @author cjhao
|
||||
* @date 2024/12/11 19:24
|
||||
*/
|
||||
public function updateAudit($params)
|
||||
{
|
||||
try {
|
||||
Db::startTrans();
|
||||
$shopUpdate = ShopUpdate::where(['id'=>$params['id']])->findOrEmpty();
|
||||
if($shopUpdate->isEmpty()){
|
||||
return '申请记录不存在';
|
||||
}
|
||||
if(ShopEnum::AUDIT_STATUS_WAIT != $shopUpdate->audit_status){
|
||||
return '申请的审核状态已改变,请刷新页面';
|
||||
}
|
||||
$status = ShopEnum::AUDIT_STATUS_PASS;
|
||||
if(0 == $params['audit_status']){
|
||||
$status = ShopEnum::AUDIT_STATUS_REFUSE;
|
||||
}
|
||||
$shopUpdate->audit_status = $status;
|
||||
$shopUpdate->audit_remark = $params['audit_remark'] ?? '';
|
||||
$shopUpdate->save();
|
||||
if(0 == $params){
|
||||
Db::commit();
|
||||
return true;
|
||||
}
|
||||
Shop::update([
|
||||
'id' => $shopUpdate['shop_id'],
|
||||
'name' => $shopUpdate['name'],
|
||||
'short_name' => $shopUpdate['short_name'],
|
||||
// 'mobile' => $shopUpdate['mobile'],
|
||||
'type' => $shopUpdate['type'],
|
||||
'business_start_time' => $shopUpdate['business_start_time'],
|
||||
'business_end_time' => $shopUpdate['business_end_time'],
|
||||
'social_credit_ode' => $shopUpdate['social_credit_ode'],
|
||||
'legal_person' => $shopUpdate['legal_person'],
|
||||
'legal_id_card' => $shopUpdate['legal_id_card'],
|
||||
'province_id' => $shopUpdate['province_id'],
|
||||
'city_id' => $shopUpdate['city_id'],
|
||||
'region_id' => $shopUpdate['region_id'],
|
||||
'shop_address_detail' => $shopUpdate['shop_address_detail'],
|
||||
'longitude' => $shopUpdate['longitude'],
|
||||
'latitude' => $shopUpdate['latitude'],
|
||||
'id_card_front' => $shopUpdate['id_card_front'],
|
||||
'id_card_back' => $shopUpdate['id_card_back'],
|
||||
'portrait_shooting' => $shopUpdate['portrait_shooting'],
|
||||
'logo' => $shopUpdate['logo'],
|
||||
'business_license' => $shopUpdate['business_license'],
|
||||
'synopsis' => $shopUpdate['synopsis'] ?? '',
|
||||
]);
|
||||
ShopCategoryIndex::where(['shop_id'=>$shopUpdate['shop_id']])->delete();
|
||||
ShopGoodsIndex::where(['shop_id'=>$shopUpdate['shop_id']])->delete();
|
||||
ShopImage::where(['shop_id'=>$shopUpdate['shop_id']])->delete();
|
||||
// ShopUser::where(['id'=>$shopUpdate['shop_user_id']])->update(['mobile'=>$shopUpdate['mobile']]);
|
||||
$categoryLists = [];
|
||||
foreach ($shopUpdate['category_ids'] as $categoryId){
|
||||
$categoryLists[] = [
|
||||
'shop_id' => $shopUpdate['shop_id'],
|
||||
'category_id' => $categoryId,
|
||||
];
|
||||
}
|
||||
(new ShopCategoryIndex())->saveAll($categoryLists);
|
||||
|
||||
$goodsLists = [];
|
||||
foreach ($shopUpdate['goods_ids'] as $goodsId) {
|
||||
$goodsLists[] = [
|
||||
'shop_id' => $shopUpdate['shop_id'],
|
||||
'goods_id' => $goodsId,
|
||||
];
|
||||
}
|
||||
(new ShopGoodsIndex())->saveAll($goodsLists);
|
||||
$shopImageLists = [];
|
||||
foreach ($shopUpdate['shop_image'] as $image){
|
||||
$shopImageLists[] = [
|
||||
'shop_id' => $shopUpdate['shop_id'],
|
||||
'uri' => $image,
|
||||
];
|
||||
}
|
||||
(new ShopImage())->saveAll($shopImageLists);
|
||||
Db::commit();
|
||||
|
||||
return true;
|
||||
}catch (Exception $e){
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user