初始版本

This commit is contained in:
贾祥聪
2025-08-19 14:16:51 +08:00
commit f937a1f9b9
4373 changed files with 359728 additions and 0 deletions

View File

@@ -0,0 +1,315 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\goods;
use app\common\enum\DefaultEnum;
use app\common\enum\GoodsEnum;
use app\common\logic\BaseLogic;
use app\common\model\city\City;
use app\common\model\goods\Goods;
use app\common\model\goods\GoodsCategory;
use app\common\model\goods\GoodsCityIndex;
use app\common\model\goods\GoodsImage;
use app\common\model\goods\GoodsSkillIndex;
use app\common\model\skill\Skill;
use think\facade\Db;
class GoodsLogic extends BaseLogic
{
/**
* @notes 分类列表
* @return GoodsCategory[]|array|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author cjhao
* @date 2024/8/19 15:41
*/
public function categoryLists()
{
return GoodsCategory::where(['is_show'=>1,'level'=>1])
// ->with(['son'])
->withCount(['goods'])
->field('id,name,image,is_show')
->select()
->toArray();
}
/**
* @notes 城市列表
* @return City[]|array|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author cjhao
* @date 2024/8/19 15:55
*/
public function cityLists(){
return City::field('city_id as id,name')->select()->toArray();
}
/**
* @notes 技能列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author cjhao
* @date 2024/8/19 16:34
*/
public function skillLists()
{
return Skill::field('id,name')->select()->toArray();
}
/**
* @notes 添加服务
* @param $params
* @return bool|string
* @author ljj
* @date 2022/2/9 3:28 下午
*/
public function add($params)
{
// 启动事务
Db::startTrans();
try {
$goodsImage = $params['goods_image'];
$image = array_shift($params['goods_image']);
//添加服务信息
$goods = Goods::create([
'name' => $params['name'],
'category_id' => $params['category_id'],
'image' => $image,
'price' => $params['price'],
'duration' => $params['duration'],
'scribing_price' => $params['scribing_price'] ?? 0.00,
'status' => $params['status'],
'sort' => $params['sort'] ?? DefaultEnum::SORT,
'tags' => $params['tags'] ?? '',
'content' => $params['content'] ?? '',
'overtime_price' => $params['overtime_price'] ?? '',
'overtime_duration' => $params['overtime_duration'] ?? '',
'commission_ratio' => $params['commission_ratio'] ?? '',
'shop_ratio' => $params['shop_ratio'] ?? '',
'virtual_order_num' => $params['virtual_order_num'] ?? '',
'appoint_start_time' => $params['appoint_start_time'] ?? '',
'appoint_end_time' => $params['appoint_end_time'] ?? '',
'audit_status' => GoodsEnum::AUDIT_STATUS_PASS,
'audit_remark' => '',
]);
$goodsImageLists = [];
//添加服务轮播图信息
foreach ($goodsImage as $image_uri) {
$goodsImageLists[] = [
'goods_id' => $goods->id,
'uri' => $image_uri,
];
}
(new GoodsImage())->saveAll($goodsImageLists);
$goodsCityLists = [];
$goodsSkillLists = [];
foreach ($params['skill_id'] as $skillId)
{
$goodsSkillLists[] = [
'goods_id' => $goods->id,
'skill_id' => $skillId
];
}
(new GoodsSkillIndex())->saveAll($goodsSkillLists);
if($params['city_id']){
foreach ($params['city_id'] as $cityId){
$goodsCityLists[] = [
'goods_id' => $goods->id,
'city_id' => $cityId
];
}
}
(new GoodsCityIndex())->saveAll($goodsCityLists);
// 提交事务
Db::commit();
return true;
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 查看服务详情
* @param $id
* @return array
* @author ljj
* @date 2022/2/9 3:51 下午
*/
public function detail($id)
{
$result = Goods::where('id',$id)
->withoutField('order_num,update_time,delete_time')
->append(['category_desc','goods_image'])
->findOrEmpty()
->toArray();
$goods_image = [];
foreach ($result['goods_image'] as &$image) {
$goods_image[] = $image['uri'];
}
$result['goods_image'] = $goods_image;
$result['city_id'] = GoodsCityIndex::where(['goods_id'=>$id])->column('city_id');
$result['skill_id'] = GoodsSkillIndex::where(['goods_id'=>$id])->column('skill_id');
if(empty($result['city_id'])){
$result['city_id'] = null;
}
return $result;
}
/**
* @notes 编辑服务
* @param $params
* @return bool|string
* @author ljj
* @date 2022/2/9 4:06 下午
*/
public function edit($params)
{
// 启动事务
Db::startTrans();
try {
$goodsImage = $params['goods_image'];
$image = array_shift($params['goods_image']);
//更新服务信息
Goods::update([
'name' => $params['name'],
'category_id' => $params['category_id'],
'image' => $image,
'price' => $params['price'],
'duration' => $params['duration'],
'scribing_price' => $params['scribing_price'] ?? 0.00,
'status' => $params['status'],
'sort' => $params['sort'] ?? DefaultEnum::SORT,
'tags' => $params['tags'] ?? '',
'content' => $params['content'] ?? '',
'overtime_price' => $params['overtime_price'] ?? '',
'overtime_duration' => $params['overtime_duration'] ?? '',
'commission_ratio' => $params['commission_ratio'] ?? '',
'shop_ratio' => $params['shop_ratio'] ?? '',
'virtual_order_num' => $params['virtual_order_num'] ?? '',
'appoint_start_time' => $params['appoint_start_time'] ?? '',
'appoint_end_time' => $params['appoint_end_time'] ?? '',
],['id'=>$params['id']]);
$goodsImageLists = [];
//删除旧的轮播图
GoodsImage::where('goods_id',$params['id'])->delete();
//添加服务轮播图信息
foreach ($goodsImage as $image_uri) {
$goodsImageLists[] = [
'goods_id' => $params['id'],
'uri' => $image_uri,
];
}
(new GoodsImage())->saveAll($goodsImageLists);
//删除管理图片,删除管理城市
GoodsSkillIndex::where('goods_id',$params['id'])->delete();
GoodsCityIndex::where('goods_id',$params['id'])->delete();
$goodsCityLists = [];
$goodsSkillLists = [];
foreach ($params['skill_id'] as $skillId)
{
$goodsSkillLists[] = [
'goods_id' => $params['id'],
'skill_id' => $skillId
];
}
(new GoodsSkillIndex())->saveAll($goodsSkillLists);
if($params['city_id']) {
foreach ($params['city_id'] as $cityId) {
$goodsCityLists[] = [
'goods_id' => $params['id'],
'city_id' => $cityId
];
}
}
(new GoodsCityIndex())->saveAll($goodsCityLists);
// 提交事务
Db::commit();
return true;
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 删除服务
* @param $ids
* @return bool|string
* @author ljj
* @date 2022/2/9 4:13 下午
*/
public function del($ids)
{
// 启动事务
// Db::startTrans();
try {
//删除师傅绑定的服务
// foreach ($ids as $id) {
// $staff_lists = Staff::whereRaw("FIND_IN_SET($id,goods_ids)")->select()->toArray();
// foreach ($staff_lists as $list) {
// $goods_ids = str_replace(','.$id.',',',',$list['goods_ids']);
// if ($goods_ids == ',') {
// $goods_ids = '';
// }
// Staff::update(['goods_ids'=>$goods_ids],['id'=>$list['id']]);
// }
// }
//删除服务
Goods::destroy($ids);
// 提交事务
// Db::commit();
return true;
} catch (\Exception $e) {
// 回滚事务
// Db::rollback();
return $e->getMessage();
}
}
/**
* @notes 修改服务状态
* @param $params
* @return Goods
* @author ljj
* @date 2022/2/9 4:54 下午
*/
public function status($params)
{
return Goods::update(['status'=>$params['status']],['id'=>$params['ids']]);
}
}