初始版本
This commit is contained in:
44
server/app/api/logic/CityLogic.php
Executable file
44
server/app/api/logic/CityLogic.php
Executable file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace app\api\logic;
|
||||
use app\common\model\city\City;
|
||||
|
||||
class CityLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 获取城市列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author cjhao
|
||||
* @date 2024/10/6 17:49
|
||||
*/
|
||||
public function getCityLists()
|
||||
{
|
||||
$lists = City::where(['level'=>2])->select()->toArray();
|
||||
$cityLists = [];
|
||||
foreach ($lists as $city){
|
||||
$parent = $cityLists[$city['parent_id']] ?? [];
|
||||
if($parent){
|
||||
$parent['sons'][] =[
|
||||
'id' => $city['city_id'],
|
||||
'name' => $city['name'],
|
||||
];
|
||||
}else{
|
||||
$parent = [
|
||||
'id' => $city['parent_id'],
|
||||
'name' => $city['parent_name'],
|
||||
'sons' => [
|
||||
[
|
||||
'id' => $city['city_id'],
|
||||
'name' => $city['name'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
$cityLists[$city['parent_id']] = $parent;
|
||||
}
|
||||
return array_values($cityLists);
|
||||
}
|
||||
}
|
||||
124
server/app/api/logic/CoachLogic.php
Executable file
124
server/app/api/logic/CoachLogic.php
Executable file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
namespace app\api\logic;
|
||||
use app\common\enum\coach\CoachEnum;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\coach\Coach;
|
||||
use app\common\model\coach\CoachLifePhoto;
|
||||
use app\common\model\coach\Collect;
|
||||
use app\common\model\goods\Goods;
|
||||
use app\common\model\goods\GoodsComment;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\shop\Shop;
|
||||
use app\common\model\skill\Skill;
|
||||
use app\common\service\FileService;
|
||||
|
||||
class CoachLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 技能列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author cjhao
|
||||
* @date 2024/9/4 17:00
|
||||
*/
|
||||
public function skillLists()
|
||||
{
|
||||
$lists = Skill::where(['is_show'=>1])
|
||||
->field('id,name')
|
||||
->select()
|
||||
->toArray();
|
||||
array_unshift($lists,['id'=>0,'name'=>'全部']);
|
||||
|
||||
return $lists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 师傅详情
|
||||
* @param $params
|
||||
* @return array|void
|
||||
* @author cjhao
|
||||
* @date 2024/9/4 17:23
|
||||
*/
|
||||
public function detail($params)
|
||||
{
|
||||
$id = $params['id'] ?? '';
|
||||
$cityId = $params['city_id'] ?? '';
|
||||
$longitude = $params['longitude'] ?? '';
|
||||
$latitude = $params['latitude'] ?? '';
|
||||
if(empty($id) && empty($cityId)){
|
||||
return [];
|
||||
}
|
||||
$field = 'id,skill_id,gender,age,shop_id,education,nation,work_status,work_photo,name,0 as distance,introduction,id_card,order_num,good_comment,certification,health_certificate';
|
||||
if($latitude && $longitude){
|
||||
$field = 'id,skill_id,gender,age,shop_id,education,nation,work_status,work_photo,name,round(st_distance_sphere(point('.$longitude.','.$latitude.'),
|
||||
point(longitude,latitude))/1000,2) as distance,introduction,id_card,order_num,good_comment,certification,health_certificate';
|
||||
}
|
||||
|
||||
$detail = Coach::where(['id'=>$id,'audit_status'=>CoachEnum::AUDIT_STATUS_PASS])
|
||||
->append(['distance_desc'])
|
||||
->field($field)
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
$lifePhoto = CoachLifePhoto::where(['coach_id'=>$id])->field('uri')->select()->toArray();
|
||||
array_unshift($lifePhoto,['uri'=>$detail['work_photo']]);
|
||||
$detail['life_photo'] = array_column($lifePhoto,'uri');
|
||||
$detail['shop_name'] = '';
|
||||
$detail['shop'] = [];
|
||||
if($detail['shop_id']){
|
||||
$field = 'id,name,good_comment,logo,work_status,0 as distance';
|
||||
if($latitude && $longitude){
|
||||
$field = 'id,name,good_comment,logo,work_status,round(st_distance_sphere(point('.$longitude.','.$latitude.'),point(longitude, latitude))/1000,2) as distance';
|
||||
}
|
||||
$detail['shop'] = Shop::where(['id'=>$detail['shop_id']])
|
||||
->field($field)
|
||||
->findOrEmpty();
|
||||
$consumption = Order::where(['pay_status'=>PayEnum::ISPAID])
|
||||
->where('shop_id','=',$detail['shop_id'])
|
||||
->value('round(sum(order_amount)/count(id),2) as consumption');
|
||||
$detail['shop']['consumption'] = $consumption;
|
||||
}
|
||||
$detail['id_card'] = substr_replace($detail['id_card'], '***************', 3);
|
||||
|
||||
$detail['skill_name'] = Skill::where(['id'=>$detail['skill_id']])->value('name');
|
||||
$detail['first_appoint'] = \app\common\logic\CoachLogic::getLatelyLeisureTime($detail['id']);
|
||||
$detail['comment_num'] = GoodsComment::where(['coach_id'=>$id])->count();
|
||||
$detail['good_comment'] = $detail['good_comment'].'%';
|
||||
$allCityGoodsIds = Goods::alias('G')
|
||||
->leftjoin('goods_city_index GCI','G.id = GCI.goods_id')
|
||||
->where(['GCI.id '=>null,'status'=>1])
|
||||
->column('G.id') ?: [];
|
||||
$cityGoodsIds = Goods::alias('G')
|
||||
->leftjoin('goods_city_index GCI','G.id = GCI.goods_id')
|
||||
->where(['status'=>1,'city_id'=>$cityId])
|
||||
->column('G.id') ?: [];
|
||||
$detail['goods_lists'] = Goods::alias('G')
|
||||
->join('coach_goods_index GCI','G.id = GCI.goods_id')
|
||||
->where(['GCI.coach_id'=>$id])
|
||||
->where(['G.id'=>array_merge($allCityGoodsIds,$cityGoodsIds)])
|
||||
->field('G.id,name,image,price,scribing_price,duration,order_num')
|
||||
->limit(8)
|
||||
->select()->toArray();
|
||||
//评论列表
|
||||
$detail['comment_lists'] = GoodsComment::alias('GC')
|
||||
->join('user U','GC.user_id = U.id')
|
||||
->where(['coach_id'=>$params['id']])
|
||||
->field('GC.id,U.nickname,U.avatar,comment,service_comment,reply,GC.create_time')
|
||||
->append(['goods_comment_image'])
|
||||
->limit(8)
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($detail['comment_lists'] as $key => $commentLists){
|
||||
$detail['comment_lists'][$key]['avatar'] = FileService::getFileUrl($commentLists['avatar']);
|
||||
}
|
||||
$detail['is_collect'] = Collect::where(['relation_id'=>$params['id'],'user_id'=>$params['user_id'],'type'=>1])->findOrEmpty()->toArray() ? 1 : 0;
|
||||
return $detail;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
153
server/app/api/logic/ConfigLogic.php
Executable file
153
server/app/api/logic/ConfigLogic.php
Executable file
@@ -0,0 +1,153 @@
|
||||
<?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\api\logic;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\decorate\DecorateTabbar;
|
||||
use app\common\model\decorate\Navigation;
|
||||
use app\common\model\TextList;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\FileService;
|
||||
|
||||
class ConfigLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 基础配置信息
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author ljj
|
||||
* @date 2022/2/23 10:30 上午
|
||||
*/
|
||||
public function config()
|
||||
{
|
||||
$config = [
|
||||
// 登录方式
|
||||
'login_way' => ConfigService::get('login', 'login_way', config('project.login.login_way')),
|
||||
// 注册强制绑定手机
|
||||
'coerce_mobile' => ConfigService::get('login', 'coerce_mobile', config('project.login.coerce_mobile')),
|
||||
// 政策协议
|
||||
'login_agreement' => ConfigService::get('login', 'login_agreement', config('project.login.login_agreement')),
|
||||
// 第三方登录 开关
|
||||
'third_auth' => ConfigService::get('login', 'third_auth', config('project.login.third_auth')),
|
||||
// 微信授权登录
|
||||
'wechat_auth' => ConfigService::get('login', 'wechat_auth', config('project.login.wechat_auth')),
|
||||
// qq授权登录
|
||||
'qq_auth' => ConfigService::get('login', 'qq_auth', config('project.login.qq_auth')),
|
||||
//版权信息
|
||||
'info' => ConfigService::get('copyright', 'info'),
|
||||
//ICP备案号
|
||||
'icp_number' => ConfigService::get('copyright', 'icp_number'),
|
||||
//ICP备案链接
|
||||
'icp_link' => ConfigService::get('copyright', 'icp_link'),
|
||||
// //底部导航
|
||||
// 'navigation_menu' => DecorateTabbar::getTabbarLists(1),
|
||||
// 导航颜色
|
||||
// 'style' => ConfigService::get('tabbar', 'style', '{}'),
|
||||
//地图key
|
||||
'tencent_map_key' => ConfigService::get('map','tencent_map_key',''),
|
||||
//网站名称
|
||||
'web_name' => ConfigService::get('platform_logo', 'platform_name',''),
|
||||
//网站logo
|
||||
'web_logo' => FileService::getFileUrl(ConfigService::get('platform_logo', 'platform_logo')),
|
||||
//商城名称
|
||||
'shop_name' => ConfigService::get('user', 'user_name',''),
|
||||
'short_name' => ConfigService::get('user', 'short_name',''),
|
||||
//商城logo
|
||||
'shop_logo' => FileService::getFileUrl(ConfigService::get('user', 'user_logo','')),
|
||||
//版本号
|
||||
'version' => request()->header('version'),
|
||||
//默认头像
|
||||
'default_avatar' => ConfigService::get('config', 'default_avatar', FileService::getFileUrl(config('project.default_image.user_avatar'))),
|
||||
//H5设置
|
||||
'h5_settings' => [
|
||||
// 渠道状态 0-关闭 1-开启
|
||||
'status' => ConfigService::get('web_page', 'status', 1),
|
||||
// 关闭后渠道后访问页面 0-空页面 1-自定义链接
|
||||
'page_status' => ConfigService::get('web_page', 'page_status', 0),
|
||||
// 自定义链接
|
||||
'page_url' => ConfigService::get('web_page', 'page_url', ''),
|
||||
'url' => request()->domain() . '/mobile'
|
||||
],
|
||||
//文件域名
|
||||
'domain' => request()->domain().'/',
|
||||
//联系客服
|
||||
'service_mobile' => ConfigService::get('platform', 'service_mobile',''),
|
||||
'copyright'=>ConfigService::get('copyright', 'config', [])
|
||||
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 政策协议
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2022/2/23 11:42 上午
|
||||
*/
|
||||
public function agreement()
|
||||
{
|
||||
$service = TextList::where(['id'=>1])->field('title,content')->findOrEmpty();
|
||||
$privacy = TextList::where(['id'=>2])->field('title,content')->findOrEmpty();
|
||||
$config = [
|
||||
//隐私协议
|
||||
'service_title' => $service['title'],
|
||||
'service_agreement' => $service['content'],
|
||||
//服务协议
|
||||
'privacy_title' => $privacy['title'],
|
||||
'privacy_agreement' => $privacy['content'],
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取客服配置
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2024/8/28 下午4:06
|
||||
*/
|
||||
public function getKefuConfig()
|
||||
{
|
||||
$defaultData = [
|
||||
'way' => 1,
|
||||
'name' => '',
|
||||
'remarks' => '',
|
||||
'phone' => '',
|
||||
'service_phone' => '',
|
||||
'business_time' => '',
|
||||
'qr_code' => '',
|
||||
'enterprise_id' => '',
|
||||
'kefu_link' => ''
|
||||
];
|
||||
$config = [
|
||||
'mnp' => ConfigService::get('kefu_config', 'mnp', $defaultData),
|
||||
'oa' => ConfigService::get('kefu_config', 'oa', $defaultData),
|
||||
'h5' => ConfigService::get('kefu_config', 'h5', $defaultData),
|
||||
];
|
||||
if (!empty($config['mnp']['qr_code'])) $config['mnp']['qr_code'] = FileService::getFileUrl($config['mnp']['qr_code']);
|
||||
if (!empty($config['oa']['qr_code'])) $config['oa']['qr_code'] = FileService::getFileUrl($config['oa']['qr_code']);
|
||||
if (!empty($config['h5']['qr_code'])) $config['h5']['qr_code'] = FileService::getFileUrl($config['h5']['qr_code']);
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
84
server/app/api/logic/DecorateLogic.php
Executable file
84
server/app/api/logic/DecorateLogic.php
Executable file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
namespace app\api\logic;
|
||||
use app\common\model\decorate\DecoratePage;
|
||||
use app\common\model\decorate\DecorateStyle;
|
||||
use app\common\model\decorate\DecorateTabbar;
|
||||
use app\common\model\goods\Goods;
|
||||
|
||||
/**
|
||||
* 装修逻辑类
|
||||
* Class DecorateLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class DecorateLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取装修页面
|
||||
* @param int $id
|
||||
* @param int $cityId
|
||||
* @return array
|
||||
* @author cjhao
|
||||
* @date 2024/10/8 15:11
|
||||
*/
|
||||
public function page(int $type,$cityId)
|
||||
{
|
||||
$detail = DecoratePage::where(['type'=>$type,'source'=>1])->findOrEmpty()->toArray();
|
||||
if(1 == $type && $cityId){
|
||||
$data = json_decode($detail['data'],true);
|
||||
foreach ($data as $key => $datum){
|
||||
if('area-goods' == $datum['name']){
|
||||
$allCityGoodsIds = Goods::alias('G')
|
||||
->leftjoin('goods_city_index GCI','G.id = GCI.goods_id')
|
||||
->where(['GCI.id '=>null,'status'=>1])
|
||||
->column('G.id');
|
||||
$cityGoodsIds = Goods::alias('G')
|
||||
->leftjoin('goods_city_index GCI','G.id = GCI.goods_id')
|
||||
->where(['status'=>1,'city_id'=>$cityId])
|
||||
->column('G.id');
|
||||
$goodsIds = array_merge($allCityGoodsIds,$cityGoodsIds);
|
||||
$showNum = $datum['content']['show_num'] ?? 1;
|
||||
$goodsLists = Goods::where(['status'=>1,'id'=>$goodsIds])
|
||||
->field('id,name,image,price,scribing_price,duration,order_num+virtual_order_num as order_num')
|
||||
->limit($showNum)
|
||||
->order('sort desc,id desc')
|
||||
->select()
|
||||
->toArray();
|
||||
$datum['content']['goods_list'] = $goodsLists;
|
||||
$data[$key] = $datum;
|
||||
$detail['data'] = json_encode($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取装修风格
|
||||
* @return array
|
||||
* @author cjhao
|
||||
* @date 2024/10/8 15:13
|
||||
*/
|
||||
public function style()
|
||||
{
|
||||
$detail = DecorateStyle::where(['source'=>1])->findOrEmpty()->toArray();
|
||||
return $detail;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 底部菜单
|
||||
* @return array
|
||||
* @author cjhao
|
||||
* @date 2024/10/8 15:59
|
||||
*/
|
||||
public function tabbar()
|
||||
{
|
||||
$detail = DecorateTabbar::where(['source'=>1])->findOrEmpty()->toArray();
|
||||
return $detail;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
56
server/app/api/logic/GoodsCategoryLogic.php
Executable file
56
server/app/api/logic/GoodsCategoryLogic.php
Executable file
@@ -0,0 +1,56 @@
|
||||
<?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\api\logic;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\goods\GoodsCategory;
|
||||
|
||||
class GoodsCategoryLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 其它分类列表
|
||||
* @param $id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author ljj
|
||||
* @date 2022/3/29 3:15 下午
|
||||
*/
|
||||
public function otherLists($id)
|
||||
{
|
||||
if (!$id) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$category = GoodsCategory::where(['id'=>$id,'is_show'=>1])->order(['sort'=>'desc','id'=>'asc'])->findOrEmpty()->toArray();
|
||||
if (!$category) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($category['level'] == 2) {
|
||||
$category = GoodsCategory::where(['id'=>$category['pid'],'is_show'=>1])->order(['sort'=>'desc','id'=>'asc'])->findOrEmpty()->toArray();
|
||||
}
|
||||
|
||||
$sons = GoodsCategory::where(['pid'=>$category['id'],'is_show'=>1])->order(['sort'=>'desc','id'=>'asc'])->select()->toArray();
|
||||
return ['info'=>$category,'sons'=>$sons];
|
||||
}
|
||||
}
|
||||
203
server/app/api/logic/GoodsCommentLogic.php
Executable file
203
server/app/api/logic/GoodsCommentLogic.php
Executable file
@@ -0,0 +1,203 @@
|
||||
<?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\api\logic;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\coach\Coach;
|
||||
use app\common\model\goods\GoodsComment;
|
||||
use app\common\model\goods\GoodsCommentImage;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\order\OrderGoods;
|
||||
use app\common\model\shop\Shop;
|
||||
use app\common\service\FileService;
|
||||
use think\facade\Db;
|
||||
|
||||
class GoodsCommentLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 服务评价分类
|
||||
* @param $parmas
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2022/2/18 2:09 下午
|
||||
*/
|
||||
public function commentCategory($parmas)
|
||||
{
|
||||
$all_count = GoodsComment::where('goods_id', $parmas['goods_id'])->count();
|
||||
$image_count = GoodsComment::alias('gc')->where('goods_id', $parmas['goods_id'])->join('goods_comment_image gci', 'gc.id = gci.comment_id')->group('gci.comment_id')->count();
|
||||
$good_count = GoodsComment::where('goods_id', $parmas['goods_id'])->where('service_comment','>',3)->count();
|
||||
$medium_bad_count = GoodsComment::where('goods_id', $parmas['goods_id'])->where('service_comment','<=',3)->count();
|
||||
|
||||
if($all_count == 0) {
|
||||
$percentStr = '100%';
|
||||
$star = 5;
|
||||
}else {
|
||||
$percent = round((($good_count / $all_count) * 100));
|
||||
$percentStr = round((($good_count / $all_count) * 100)).'%';
|
||||
if ($percent >= 100) {
|
||||
$star = 5;
|
||||
} else if ($percent >= 80) {
|
||||
$star = 4;
|
||||
} else if ($percent >= 60) {
|
||||
$star = 3;
|
||||
} else if ($percent >= 40) {
|
||||
$star = 2;
|
||||
} else if ($percent >= 20) {
|
||||
$star = 1;
|
||||
} else {
|
||||
$star = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return ['comment'=>
|
||||
[
|
||||
[
|
||||
'id' => 0,
|
||||
'name' => '全部',
|
||||
'count' => $all_count
|
||||
],
|
||||
[
|
||||
'id' => 1,
|
||||
'name' => '有图',
|
||||
'count' => $image_count
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'name' => '好评',
|
||||
'count' => $good_count
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'name' => '中差评',
|
||||
'count' => $medium_bad_count
|
||||
]
|
||||
] ,
|
||||
'percent' => $percentStr,
|
||||
'star' => $star,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 评价服务信息
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author ljj
|
||||
* @date 2022/2/21 6:12 下午
|
||||
*/
|
||||
public function commentGoodsInfo($params)
|
||||
{
|
||||
$info = GoodsComment::alias('GC')
|
||||
->where(['order_goods_id'=>$params['order_goods_id'],'user_id'=>$params['user_id']])
|
||||
->join('user U','U.id = GC.user_id')
|
||||
->append(['goods_comment_image'])
|
||||
->field('U.nickname,U.avatar,GC.id,GC.service_comment,GC.comment,GC.reply,GC.create_time')
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
$info['avatar'] = FileService::getFileUrl($info['avatar']);
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 添加服务评价
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author ljj
|
||||
* @date 2022/2/21 6:23 下午
|
||||
*/
|
||||
public function add($params)
|
||||
{
|
||||
// 启动事务
|
||||
Db::startTrans();
|
||||
try {
|
||||
//获取订单商品信息
|
||||
$order_goods = OrderGoods::where(['id'=>$params['order_goods_id']])->findOrEmpty();
|
||||
$order = Order::where(['id'=>$order_goods['order_id']])->findOrEmpty();
|
||||
//添加评价数据
|
||||
$goods_comment = GoodsComment::create([
|
||||
'goods_id' => $order_goods['goods_id'],
|
||||
'user_id' => $params['user_id'],
|
||||
'coach_id' => $order['coach_id'],
|
||||
'shop_id' => $order['shop_id'],
|
||||
'order_goods_id' => $order_goods['id'],
|
||||
'service_comment' => $params['service_comment'],
|
||||
'comment' => $params['comment'] ?? '',
|
||||
]);
|
||||
//添加评价图片数据
|
||||
if (isset($params['image'])) {
|
||||
$image_data = [];
|
||||
foreach ($params['image'] as $val) {
|
||||
$image_data[] = [
|
||||
'comment_id' => $goods_comment->id,
|
||||
'uri' => $val,
|
||||
];
|
||||
}
|
||||
$goods_comment_image = new GoodsCommentImage;
|
||||
$goods_comment_image->saveAll($image_data);
|
||||
}
|
||||
|
||||
//技师的好评
|
||||
\app\common\logic\CoachLogic::updateCoachComment($order['coach_id']);
|
||||
if($order['shop_id']){
|
||||
\app\common\logic\ShopLogic::updateShopComment($order['shop_id']);
|
||||
}
|
||||
//修改订单商品表评价状态
|
||||
OrderGoods::update(['is_comment' => 1], ['id' => $order_goods['id']]);
|
||||
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 评价详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author ljj
|
||||
* @date 2024/7/31 下午5:37
|
||||
*/
|
||||
public function commentDetail($params)
|
||||
{
|
||||
$info = GoodsComment::alias('GC')
|
||||
->where(['order_goods_id'=>$params['id'],'user_id'=>$params['user_id']])
|
||||
->join('user U','U.id = GC.user_id')
|
||||
->append(['goods_comment_image'])
|
||||
->field('U.nickname,U.avatar,GC.id,GC.service_comment,GC.comment,GC.reply,GC.create_time')
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
$info['avatar'] = FileService::getFileUrl($info['avatar']);
|
||||
|
||||
return $info;
|
||||
}
|
||||
}
|
||||
126
server/app/api/logic/GoodsLogic.php
Executable file
126
server/app/api/logic/GoodsLogic.php
Executable file
@@ -0,0 +1,126 @@
|
||||
<?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\api\logic;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\coach\Collect;
|
||||
use app\common\model\decorate\DecoratePage;
|
||||
use app\common\model\goods\Goods;
|
||||
use app\common\model\goods\GoodsCollect;
|
||||
use app\common\model\goods\GoodsComment;
|
||||
use app\common\model\order\OrderTime;
|
||||
use app\common\service\ConfigService;
|
||||
|
||||
class GoodsLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 服务详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author ljj
|
||||
* @date 2022/2/18 10:40 上午
|
||||
*/
|
||||
public function detail($params)
|
||||
{
|
||||
$detail = Goods::where(['id'=>$params['id']])
|
||||
->append(['goods_image'])
|
||||
->field('id,name,price,duration,scribing_price,order_num+virtual_order_num as total_order_num,tags,content')
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
$goodsImage = array_column($detail['goods_image']->toArray(),'uri');
|
||||
$detail['goods_image'] = $goodsImage;
|
||||
$detail['comment_count'] = GoodsComment::where(['goods_id'=>$params['id']])->count();
|
||||
$detail['is_collect'] =Collect::where(['relation_id'=>$params['id'],'user_id'=>$params['user_id'],'type'=>2])->findOrEmpty()->toArray() ? 1 : 0;;
|
||||
$decorate = DecoratePage::where(['type'=>5,'source'=>1])->findOrEmpty()->toArray();
|
||||
$decorateData = json_decode($decorate['data'],true);
|
||||
$commentNum = 0;
|
||||
$enabled = 1;
|
||||
foreach($decorateData as $data){
|
||||
if('goods-comment' == $data['name']){
|
||||
$commentNum = $data['content']['num'] ?? 0;
|
||||
$enabled = $data['content']['enabled'] ?? 0;
|
||||
}
|
||||
}
|
||||
$detail['comment_lists'] = [];
|
||||
if($commentNum > 0 && $enabled){
|
||||
$goodsCommentLists = GoodsComment::alias('gc')
|
||||
->leftjoin('goods_comment_image gci', 'gc.id = gci.comment_id')
|
||||
->with(['goods_comment_image','user'])
|
||||
->where(['gc.goods_id'=>$params['id']])
|
||||
->field('gc.id,gc.goods_id,gc.user_id,gc.service_comment,gc.comment,gc.reply,gc.create_time')
|
||||
->append(['comment_level'])
|
||||
->order('gc.id','desc')
|
||||
->group('gc.id')
|
||||
->limit($commentNum)
|
||||
->select()
|
||||
->toArray();
|
||||
$detail['comment_lists'] = $goodsCommentLists;
|
||||
}
|
||||
|
||||
return $detail;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 预约上门时间
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author ljj
|
||||
* @date 2022/3/11 2:32 下午
|
||||
*/
|
||||
public function appointTime()
|
||||
{
|
||||
return [
|
||||
'order_time' => ConfigService::get('order_time','time',7),
|
||||
'appoint_time' => OrderTime::order(['sort'=>'desc','id'=>'desc'])->field('start_time,end_time')->select()->toArray(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 收藏服务
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author ljj
|
||||
* @date 2022/3/16 4:14 下午
|
||||
*/
|
||||
public function collect($params)
|
||||
{
|
||||
if($params['is_collect']){
|
||||
$goods_collect = GoodsCollect::where(['goods_id'=>$params['id'],'user_id'=>$params['user_id']])->findOrEmpty();
|
||||
if(!$goods_collect->isEmpty()){
|
||||
return true;
|
||||
}
|
||||
|
||||
$goods_collect->goods_id = $params['id'];
|
||||
$goods_collect->user_id = $params['user_id'];
|
||||
$goods_collect->save();
|
||||
}else {
|
||||
GoodsCollect::where(['goods_id'=>$params['id'],'user_id'=>$params['user_id']])->delete();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
375
server/app/api/logic/IndexLogic.php
Executable file
375
server/app/api/logic/IndexLogic.php
Executable file
@@ -0,0 +1,375 @@
|
||||
<?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\api\logic;
|
||||
|
||||
|
||||
use app\common\enum\DefaultEnum;
|
||||
use app\common\enum\user\UserTerminalEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\logic\CityLogic;
|
||||
use app\common\model\coach\Collect;
|
||||
use app\common\model\decorate\DecoratePage;
|
||||
use app\common\model\goods\Goods;
|
||||
use app\common\model\goods\GoodsCategory;
|
||||
use app\common\model\goods\GoodsSearchLog;
|
||||
use app\common\model\HotSearch;
|
||||
use app\common\model\IndexVisit;
|
||||
use app\common\model\staff\Staff;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\TencentMapKeyService;
|
||||
use think\Exception;
|
||||
|
||||
class IndexLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 搜索记录
|
||||
* @param int $userId
|
||||
* @return array
|
||||
* @author cjhao
|
||||
* @date 2024/9/5 10:47
|
||||
*/
|
||||
public function searchLog(int $userId)
|
||||
{
|
||||
$searchLog = GoodsSearchLog::where(['user_id'=>$userId])->column('keyword');
|
||||
$hotSearchLog = HotSearch::where(['user_id'=>$userId])->column('name');
|
||||
return [
|
||||
'search_log' => $searchLog,
|
||||
'hot_search_log' => $hotSearchLog
|
||||
];
|
||||
|
||||
}
|
||||
/**
|
||||
* @notes 首页信息
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author ljj
|
||||
* @date 2022/2/23 4:48 下午
|
||||
*/
|
||||
public function index($get)
|
||||
{
|
||||
// //首页菜单
|
||||
// $home_menu = Menu::where(['decorate_type'=>MenuEnum::NAVIGATION_HOME,'status'=>DefaultEnum::SHOW])
|
||||
// ->field('id,name,image,link_type,link_address')
|
||||
// ->order(['sort'=>'asc','id'=>'desc'])
|
||||
// ->append(['link'])
|
||||
// ->select()
|
||||
// ->toArray();
|
||||
//
|
||||
// $shop_page = array_column(MenuEnum::SHOP_PAGE,NULL,'index');
|
||||
// foreach ($home_menu as &$menu) {
|
||||
// $menu['is_tab'] = 0;
|
||||
// if ($menu['link_type'] == 1) {
|
||||
// $menu['is_tab'] = $shop_page[$menu['link_address']]['is_tab'];
|
||||
// }
|
||||
// }
|
||||
|
||||
// 装修配置
|
||||
$decoratePage = DecoratePage::where('id',1)->json(['data'],true)->value('data');
|
||||
|
||||
//热门服务
|
||||
$hot_service = Goods::where(['status'=>DefaultEnum::SHOW])
|
||||
->field('id,name,remarks,image')
|
||||
->order(['order_num'=>'desc','sort'=>'asc','id'=>'desc'])
|
||||
->limit(5)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
//师傅推荐
|
||||
$staff_where = [];
|
||||
if (isset($get['city_id']) && $get['city_id'] != '') {
|
||||
$staff_where[] = ['city_id','=',$get['city_id']];
|
||||
}
|
||||
$recommend_staff = Staff::where(['status'=>DefaultEnum::SHOW,'is_recommend'=>DefaultEnum::SHOW])
|
||||
->field('id,user_id,name,goods_ids')
|
||||
->append(['goods_name','user_image'])
|
||||
->order(['id'=>'desc'])
|
||||
->where($staff_where)
|
||||
->limit(5)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
//首页推荐服务分类
|
||||
$recommend_goods_category = GoodsCategory::where(['is_show'=>DefaultEnum::SHOW,'is_recommend'=>DefaultEnum::SHOW,'level'=>1])
|
||||
->field('id,name')
|
||||
->order(['sort'=>'desc','id'=>'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($recommend_goods_category as &$category) {
|
||||
$categoryIds = GoodsCategory::where(['pid'=>$category['id']])->column('id');
|
||||
Array_push($categoryIds,$category['id']);
|
||||
$category['goods'] = Goods::where(['category_id' => $categoryIds,'status'=>DefaultEnum::SHOW])
|
||||
->field('id,name,unit_id,image,price')
|
||||
->order(['sort'=>'asc','id'=>'desc'])
|
||||
->append(['unit_desc'])
|
||||
->limit(3)
|
||||
->select()->toArray();
|
||||
|
||||
foreach ($category['goods'] as &$goods) {
|
||||
$goods['price'] = trim(rtrim(sprintf("%.4f", $goods['price'] ), '0'),'.');
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'decorate_age' => $decoratePage,
|
||||
'hot_service' => $hot_service,
|
||||
'recommend_staff' => $recommend_staff,
|
||||
'recommend_goods_category' => $recommend_goods_category,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 首页访客记录
|
||||
* @return bool
|
||||
* @author Tab
|
||||
* @date 2021/9/11 9:29
|
||||
*/
|
||||
public static function visit()
|
||||
{
|
||||
try {
|
||||
$params = request()->post();
|
||||
if (!isset($params['terminal']) || !in_array($params['terminal'], UserTerminalEnum::ALL_TERMINAL)) {
|
||||
throw new \Exception('终端参数缺失或有误');
|
||||
}
|
||||
$ip = request()->ip();
|
||||
// 一个ip一个终端一天只生成一条记录
|
||||
$record = IndexVisit::where([
|
||||
'ip' => $ip,
|
||||
'terminal' => $params['terminal']
|
||||
])->whereDay('create_time')->findOrEmpty();
|
||||
if (!$record->isEmpty()) {
|
||||
// 增加访客在终端的浏览量
|
||||
$record->visit += 1;
|
||||
$record->save();
|
||||
return true;
|
||||
}
|
||||
// 生成访客记录
|
||||
IndexVisit::create([
|
||||
'ip' => $ip,
|
||||
'terminal' => $params['terminal'],
|
||||
'visit' => 1
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 地址解析(地址转坐标)
|
||||
* @param $get
|
||||
* @return array|mixed
|
||||
* @author ljj
|
||||
* @date 2022/10/13 12:06 下午
|
||||
* 本接口提供由文字地址到经纬度的转换能力,并同时提供结构化的省市区地址信息。
|
||||
*/
|
||||
public static function geocoder($get)
|
||||
{
|
||||
try {
|
||||
$get['key'] = (new TencentMapKeyService())->getTencentMapKey();
|
||||
if (empty($get['key'])) {
|
||||
return ['status'=>1,'message'=>'腾讯地图开发密钥不能为空'];
|
||||
}
|
||||
|
||||
$query = http_build_query($get);
|
||||
$url = 'https://apis.map.qq.com/ws/geocoder/v1/';
|
||||
$result = json_decode(file_get_contents($url.'?'.$query),true);
|
||||
$check = (new TencentMapKeyService())->checkResult($result);
|
||||
|
||||
|
||||
}catch (\Exception $e){
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 逆地址解析(坐标位置描述)
|
||||
* @param $get
|
||||
* @return array|mixed
|
||||
* @author ljj
|
||||
* @date 2022/10/13 2:44 下午
|
||||
* 本接口提供由经纬度到文字地址及相关位置信息的转换能力
|
||||
*/
|
||||
public static function geocoderCoordinate($get)
|
||||
{
|
||||
$get['key'] = (new TencentMapKeyService())->getTencentMapKey();
|
||||
if (empty($get['key'])) {
|
||||
return ['status'=>1,'message'=>'腾讯地图开发密钥不能为空'];
|
||||
}
|
||||
|
||||
$query = http_build_query($get);
|
||||
$url = 'https://apis.map.qq.com/ws/geocoder/v1/';
|
||||
$result = json_decode(file_get_contents($url.'?'.$query),true);
|
||||
if ($result['status'] !== 0) {
|
||||
$check = (new TencentMapKeyService())->checkResult($result);
|
||||
while (!$check) {
|
||||
$data['key'] = (new TencentMapKeyService())->getTencentMapKey(true);
|
||||
if (empty($data['key'])) {
|
||||
break;
|
||||
}
|
||||
|
||||
$query = http_build_query($data);
|
||||
$result = json_decode(file_get_contents($url . '?' . $query), true);
|
||||
$check = (new TencentMapKeyService())->checkResult($result);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 搜索附近地址
|
||||
* @param $params
|
||||
* @return array|mixed
|
||||
* @author ljj
|
||||
* @date 2024/7/23 上午11:20
|
||||
*/
|
||||
public function getNearbyLocation($params)
|
||||
{
|
||||
$longitude = $params['longitude'] ?? '';
|
||||
$latitude = $params['latitude'] ?? '';
|
||||
if(empty($longitude) || empty($latitude)){
|
||||
throw new Exception('请授权获取位置');
|
||||
}
|
||||
//开发秘钥
|
||||
$data['key'] = (new TencentMapKeyService())->getTencentMapKey();
|
||||
if (empty($data['key'])) {
|
||||
return ['status'=>1,'message'=>'腾讯地图开发密钥不能为空'];
|
||||
}
|
||||
|
||||
//排序,按距离由近到远排序
|
||||
$data['orderby'] = '_distance';
|
||||
//排序,按距离由近到远排序
|
||||
$data['boundary'] = "nearby(" . $params['latitude'] . "," . $params['longitude'] . ",1000,1)";
|
||||
//搜索关键字
|
||||
$keyword = $params['keyword'] ?? '';
|
||||
//api地址
|
||||
//未输入搜索关键词时,默认使用周边推荐api
|
||||
$url = 'https://apis.map.qq.com/ws/place/v1/explore';
|
||||
|
||||
if (!empty($keyword)) {
|
||||
$data['keyword'] = $keyword;
|
||||
//输入搜索关键词时,使用周边搜索api
|
||||
$url = 'https://apis.map.qq.com/ws/place/v1/search';
|
||||
}
|
||||
$query = http_build_query($data);
|
||||
$result = json_decode(file_get_contents($url . '?' . $query), true);
|
||||
if ($result['status'] !== 0) {
|
||||
$check = (new TencentMapKeyService())->checkResult($result);
|
||||
while (!$check) {
|
||||
$data['key'] = (new TencentMapKeyService())->getTencentMapKey(true);
|
||||
if (empty($data['key'])) {
|
||||
break;
|
||||
}
|
||||
|
||||
$query = http_build_query($data);
|
||||
$result = json_decode(file_get_contents($url . '?' . $query), true);
|
||||
$check = (new TencentMapKeyService())->checkResult($result);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取当前位置最近的城市
|
||||
* @param $get
|
||||
* @return array|false
|
||||
* @author cjhao
|
||||
* @date 2024/9/3 22:58
|
||||
*/
|
||||
public function getNearbyCity($get)
|
||||
{
|
||||
try {
|
||||
$longitude = $get['longitude'] ?? '';
|
||||
$latitude = $get['latitude'] ?? '';
|
||||
// if(empty($longitude) || empty($latitude)){
|
||||
// throw new Exception('请授权获取位置');
|
||||
// }
|
||||
$cityLists = CityLogic::getNearbyCity($longitude,$latitude);
|
||||
return $cityLists[0] ?? [];
|
||||
|
||||
}catch (Exception $e){
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取首页服务列表
|
||||
* @param $params
|
||||
* @return string
|
||||
* @author cjhao
|
||||
* @date 2024/9/3 23:10
|
||||
*/
|
||||
public function serverLists($params)
|
||||
{
|
||||
try {
|
||||
$cityId = $params['city_id'] ?? '';
|
||||
if(empty($cityId)){
|
||||
throw new Exception('请先授权获取当前位置');
|
||||
}
|
||||
$lists = Goods::alias('G')
|
||||
->join('goods_city_index GCI','G.id = GCI.goods_id')
|
||||
->where(['city_id'=>$cityId])
|
||||
->field('G.id,name,image,price,scribing_price,duration,order_num')
|
||||
->limit()
|
||||
->select()
|
||||
->toArray();
|
||||
return $lists;
|
||||
|
||||
}catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 收藏接口
|
||||
* @param $params
|
||||
* @param $userId
|
||||
* @return true
|
||||
* @author cjhao
|
||||
* @date 2024/9/5 09:32
|
||||
*/
|
||||
public function collect($params,$userId)
|
||||
{
|
||||
$id = $params['id'] ?? '';
|
||||
$type = $params['type'] ?? '';
|
||||
$collect = Collect::where(['user_id'=>$userId,'type'=>$type,'relation_id'=>$id])
|
||||
->findOrEmpty();
|
||||
if($collect->isEmpty()){
|
||||
Collect::create([
|
||||
'user_id'=>$userId,
|
||||
'relation_id'=>$id,
|
||||
'type' => $type
|
||||
]);
|
||||
}else{
|
||||
$collect->delete();
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
369
server/app/api/logic/LoginLogic.php
Executable file
369
server/app/api/logic/LoginLogic.php
Executable file
@@ -0,0 +1,369 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\api\service\{UserTokenService, WechatUserService};
|
||||
use app\common\enum\{LoginEnum, user\UserTerminalEnum};
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\user\{User, UserAuth, UserSession};
|
||||
use app\common\service\{ConfigService, FileService, WeChatService};
|
||||
use think\facade\{Config, Db};
|
||||
|
||||
/**
|
||||
* 登录逻辑
|
||||
* Class LoginLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class LoginLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 账号密码注册
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/7 15:37
|
||||
*/
|
||||
public static function register(array $params)
|
||||
{
|
||||
try {
|
||||
$userSn = User::createUserSn();
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
$password = create_password($params['password'], $passwordSalt);
|
||||
$avatar = ConfigService::get('default_image', 'user_avatar');
|
||||
|
||||
User::create([
|
||||
'sn' => $userSn,
|
||||
'avatar' => $avatar,
|
||||
'nickname' => '用户' . $userSn,
|
||||
'account' => $params['account'],
|
||||
'password' => $password,
|
||||
'channel' => $params['channel'],
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 账号/手机号登录,手机号验证码
|
||||
* @param $params
|
||||
* @return array|false
|
||||
* @author 段誉
|
||||
* @date 2022/9/6 19:26
|
||||
*/
|
||||
public static function login($params)
|
||||
{
|
||||
try {
|
||||
// 账号/手机号 密码登录
|
||||
$where = ['account|mobile' => $params['account']];
|
||||
if ($params['scene'] == LoginEnum::MOBILE_CAPTCHA) {
|
||||
//手机验证码登录
|
||||
$where = ['mobile' => $params['account']];
|
||||
}
|
||||
|
||||
$user = User::where($where)->findOrEmpty();
|
||||
if ($user->isEmpty()) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
|
||||
//更新登录信息
|
||||
$user->login_time = time();
|
||||
$user->login_ip = request()->ip();
|
||||
$user->save();
|
||||
|
||||
//设置token
|
||||
$userInfo = UserTokenService::setToken($user->id, $params['terminal']);
|
||||
|
||||
//返回登录信息
|
||||
$avatar = $user->avatar ?: Config::get('project.default_image.user_avatar');
|
||||
$avatar = FileService::getFileUrl($avatar);
|
||||
|
||||
return [
|
||||
'nickname' => $userInfo['nickname'],
|
||||
'sn' => $userInfo['sn'],
|
||||
'mobile' => $userInfo['mobile'],
|
||||
'avatar' => $avatar,
|
||||
'token' => $userInfo['token'],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 退出登录
|
||||
* @param $userInfo
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 17:56
|
||||
*/
|
||||
public static function logout($userInfo)
|
||||
{
|
||||
//token不存在,不注销
|
||||
if (!isset($userInfo['token'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//设置token过期
|
||||
return UserTokenService::expireToken($userInfo['token']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取微信请求code的链接
|
||||
* @param string $url
|
||||
* @return string
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:47
|
||||
*/
|
||||
public static function codeUrl(string $url)
|
||||
{
|
||||
return WeChatService::getCodeUrl($url);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 公众号登录
|
||||
* @param array $params
|
||||
* @return array|false
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:47
|
||||
*/
|
||||
public static function oaLogin(array $params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
//通过code获取微信 openid
|
||||
$response = WeChatService::getOaResByCode($params);
|
||||
$userServer = new WechatUserService($response, UserTerminalEnum::WECHAT_OA);
|
||||
$userInfo = $userServer->getResopnseByUserInfo()->authUserLogin()->getUserInfo();
|
||||
|
||||
// 更新登录信息
|
||||
self::updateLoginInfo($userInfo['id']);
|
||||
|
||||
Db::commit();
|
||||
return $userInfo;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 小程序-静默登录
|
||||
* @param array $params
|
||||
* @return array|false
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:47
|
||||
*/
|
||||
public static function silentLogin(array $params)
|
||||
{
|
||||
try {
|
||||
//通过code获取微信 openid
|
||||
$response = WeChatService::getMnpResByCode($params);
|
||||
$userServer = new WechatUserService($response, UserTerminalEnum::WECHAT_MMP);
|
||||
$userInfo = $userServer->getResopnseByUserInfo('silent')->getUserInfo();
|
||||
|
||||
if (!empty($userInfo)) {
|
||||
// 更新登录信息
|
||||
self::updateLoginInfo($userInfo['id']);
|
||||
}
|
||||
|
||||
return $userInfo;
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 小程序-授权登录
|
||||
* @param array $params
|
||||
* @return array|false
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:47
|
||||
*/
|
||||
public static function mnpLogin(array $params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
//通过code获取微信 openid
|
||||
$response = WeChatService::getMnpResByCode($params);
|
||||
$userServer = new WechatUserService($response, UserTerminalEnum::WECHAT_MMP);
|
||||
$userInfo = $userServer->getResopnseByUserInfo()->authUserLogin()->getUserInfo();
|
||||
|
||||
// 更新登录信息
|
||||
self::updateLoginInfo($userInfo['id']);
|
||||
|
||||
Db::commit();
|
||||
return $userInfo;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 更新登录信息
|
||||
* @param $userId
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:46
|
||||
*/
|
||||
public static function updateLoginInfo($userId)
|
||||
{
|
||||
$user = User::findOrEmpty($userId);
|
||||
if ($user->isEmpty()) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
|
||||
$time = time();
|
||||
$user->login_time = $time;
|
||||
$user->login_ip = request()->ip();
|
||||
$user->update_time = $time;
|
||||
$user->save();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 小程序端绑定微信
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:46
|
||||
*/
|
||||
public static function mnpAuthLogin(array $params)
|
||||
{
|
||||
try {
|
||||
//通过code获取微信openid
|
||||
$response = WeChatService::getMnpResByCode($params);
|
||||
$response['user_id'] = $params['user_id'];
|
||||
$response['terminal'] = UserTerminalEnum::WECHAT_MMP;
|
||||
|
||||
return self::createAuth($response);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 公众号端绑定微信
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 10:43
|
||||
*/
|
||||
public static function oaAuthLogin(array $params)
|
||||
{
|
||||
try {
|
||||
//通过code获取微信openid
|
||||
$response = WeChatService::getOaResByCode($params);
|
||||
$response['user_id'] = $params['user_id'];
|
||||
$response['terminal'] = UserTerminalEnum::WECHAT_OA;
|
||||
|
||||
return self::createAuth($response);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 生成授权记录
|
||||
* @param $response
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 10:43
|
||||
*/
|
||||
public static function createAuth($response)
|
||||
{
|
||||
//先检查openid是否有记录
|
||||
$isAuth = UserAuth::where('openid', '=', $response['openid'])->findOrEmpty();
|
||||
if (!$isAuth->isEmpty()) {
|
||||
throw new \Exception('当前已绑定该微信');
|
||||
}
|
||||
|
||||
if (isset($response['unionid']) && !empty($response['unionid'])) {
|
||||
//在用unionid找记录,防止生成两个账号,同个unionid的问题
|
||||
$userAuth = UserAuth::where(['unionid' => $response['unionid']])
|
||||
->findOrEmpty();
|
||||
if (!$userAuth->isEmpty() && $userAuth->user_id != $response['user_id']) {
|
||||
throw new \Exception('当前已绑定该微信');
|
||||
}
|
||||
}
|
||||
|
||||
//如果没有授权,直接生成一条微信授权记录
|
||||
UserAuth::create([
|
||||
'user_id' => $response['user_id'],
|
||||
'openid' => $response['openid'],
|
||||
'unionid' => $response['unionid'] ?? '',
|
||||
'terminal' => $response['terminal'],
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 解绑微信(测试用)
|
||||
* @param $user_id
|
||||
* @return bool
|
||||
* @author ljj
|
||||
* @date 2023/1/11 10:35 上午
|
||||
*/
|
||||
public static function unbinding($user_id)
|
||||
{
|
||||
$session = UserSession::where(['user_id'=>$user_id])->findOrEmpty()->toArray();
|
||||
UserAuth::where(['user_id'=>$user_id,'terminal'=>$session['terminal']])->delete();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 更新用户头像昵称
|
||||
* @param $post
|
||||
* @param $user_id
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DbException
|
||||
* @author ljj
|
||||
* @date 2023/2/2 6:36 下午
|
||||
*/
|
||||
public static function updateUser($post,$user_id)
|
||||
{
|
||||
Db::name('user')->where(['id'=>$user_id])->update(['nickname'=>$post['nickname'],'avatar'=>FileService::setFileUrl($post['avatar']),'is_new_user'=>0]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
892
server/app/api/logic/OrderLogic.php
Executable file
892
server/app/api/logic/OrderLogic.php
Executable file
@@ -0,0 +1,892 @@
|
||||
<?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\api\logic;
|
||||
|
||||
|
||||
use app\common\enum\GoodsEnum;
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\OrderLogEnum;
|
||||
use app\common\enum\OrderRefundEnum;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\logic\OrderLogLogic;
|
||||
use app\common\logic\RefundLogic;
|
||||
use app\common\model\city\City;
|
||||
use app\common\model\coach\Coach;
|
||||
use app\common\model\deposit\DepositPackage;
|
||||
use app\common\model\goods\Goods;
|
||||
use app\common\model\goods\GoodsComment;
|
||||
use app\common\model\goods\GoodsCommentImage;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\order\OrderAppend;
|
||||
use app\common\model\order\OrderGap;
|
||||
use app\common\model\order\OrderGoods;
|
||||
use app\common\model\pay\PayWay;
|
||||
use app\common\model\RechargeOrder;
|
||||
use app\common\model\shop\Shop;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\user\UserAddress;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\FileService;
|
||||
use DateTime;
|
||||
use think\Exception;
|
||||
use think\facade\Db;
|
||||
|
||||
class OrderLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 订单结算详情
|
||||
* @param $params
|
||||
* @return array|false
|
||||
* @author ljj
|
||||
* @date 2022/2/24 6:19 下午
|
||||
*/
|
||||
public function settlement($params)
|
||||
{
|
||||
try {
|
||||
//获取用户信息
|
||||
$user = User::findOrEmpty($params['user_id'])->toArray();
|
||||
$addressId = $params['address_id'] ?? 0;
|
||||
$tripWay = $params['trip_way'] ?? 0;
|
||||
$appointTime = $params['appoint_time'] ?? '';
|
||||
$carAmount = 0;//车费
|
||||
$city = [];//当前城市
|
||||
$tripWayLists = [];//出行方式列表
|
||||
$userAddress = []; //地址
|
||||
$coach = [];//技师信息
|
||||
$distance = '';//订单距离
|
||||
$tips = '';
|
||||
$coach = Coach::where(['id'=>$params['coach_id']])
|
||||
->field( 'id,shop_id,sn,work_photo,name,longitude,latitude,longitude_location,latitude_location,deposit,work_status,server_status')
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
if(empty($coach)){
|
||||
throw new Exception('技师不存在');
|
||||
}
|
||||
if(0 == $coach['work_status']){
|
||||
throw new Exception('技师休息中');
|
||||
}
|
||||
if(0 == $coach['server_status']){
|
||||
throw new Exception('技师已暂停服务');
|
||||
}
|
||||
//获取服务信息
|
||||
$goodsInfo = self::getOrderGoods($params['goods'],$params['appoint_time'] ?? 0);
|
||||
if($appointTime){
|
||||
if($appointTime <= time()){
|
||||
throw new Exception('服务时间不能小于当前时间');
|
||||
}
|
||||
$serverTimeLists = $this->getCoachServerTime($params['coach_id'],$params['goods'][0]['id']);
|
||||
$serverTimeLists = array_column($serverTimeLists,null,'time_date');
|
||||
//预约天
|
||||
$appointTimeMd = date('m-d',$appointTime);
|
||||
//预约小时
|
||||
$appointTimeHi = date('H:i',$appointTime);
|
||||
$timeLists = $serverTimeLists[$appointTimeMd]['time_lists'] ?? [];
|
||||
|
||||
if(empty($timeLists)){
|
||||
throw new Exception('预约时间错误');
|
||||
}
|
||||
$timeLists = array_column($timeLists,null,'time');
|
||||
$time = $timeLists[$appointTimeHi] ?? [];
|
||||
if(empty($time)){
|
||||
throw new Exception('预约时间段错误');
|
||||
}
|
||||
if(2 == $time['status']){
|
||||
throw new Exception('当前时间技师休息中,无法预约');
|
||||
}
|
||||
if(3 == $time['status']){
|
||||
throw new Exception('当前时间区间有被预约,请更换其他时间区间');
|
||||
}
|
||||
$totalDuration = $goodsInfo['total_duration'];
|
||||
$dateTime = new DateTime(date('Y-m-d H:i:s',$appointTime));
|
||||
if($totalDuration > 30){
|
||||
$nums = intval($totalDuration / 30);
|
||||
for ($i = 0;$nums > $i;$i++){
|
||||
$dateTime->modify('+30 minutes');
|
||||
$appointTimeEnd = strtotime($dateTime->format('Y-m-d H:i'));
|
||||
}
|
||||
}else{
|
||||
$dateTime->modify('+'. $totalDuration.' minutes');
|
||||
$appointTimeEnd = strtotime($dateTime->format('Y-m-d H:i'));
|
||||
}
|
||||
$appointTimeEnd = round_date_time($appointTimeEnd);
|
||||
$appointTimeEndMd = date('m-d',$appointTimeEnd);
|
||||
$appointTimeEndHi = date('H:i',$appointTimeEnd);
|
||||
$timeLists = $serverTimeLists[$appointTimeEndMd]['time_lists'] ?? [];
|
||||
$timeLists = array_column($timeLists,null,'time');
|
||||
$time = $timeLists[$appointTimeEndHi] ?? [];
|
||||
if(empty($time)){
|
||||
throw new Exception('当前时间区间有被预约,请更换其他时间区间');
|
||||
}
|
||||
if(2 == $time['status']){
|
||||
throw new Exception('当前时间技师休息中,无法预约');
|
||||
}
|
||||
if(3 == $time['status']){
|
||||
throw new Exception('当前时间区间有被预约,请更换其他时间区间');
|
||||
}
|
||||
}
|
||||
//验证技师的接单数量
|
||||
// $this->ckechCoachTakeOrderNum($coach);
|
||||
|
||||
|
||||
//设置用户地址
|
||||
$userAddress = UserAddress::getUserAddress($params['user_id'], $addressId);
|
||||
$goodsCityLists = $goodsInfo['city_lists'];
|
||||
if($userAddress){
|
||||
$file = 'id,shop_id,sn,work_photo,name,round(st_distance_sphere(point('.$userAddress['longitude'].','.$userAddress['latitude'].'),
|
||||
point(longitude_location, latitude_location))/1000,2) as distance';
|
||||
if(empty($coach['longitude_location']) || empty($coach['latitude_location'])){
|
||||
$file ='id,shop_id,sn,work_photo,name,round(st_distance_sphere(point('.$userAddress['longitude'].','.$userAddress['latitude'].'),
|
||||
point(longitude, latitude))/1000,2) as distance';
|
||||
}
|
||||
$coach = Coach::where(['id'=>$params['coach_id']])
|
||||
->field( $file)
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
|
||||
// if(empty($userAddress)){
|
||||
// throw new Exception('用户地址不存在,请重新选择');
|
||||
// }
|
||||
$city = City::where(['city_id'=>$userAddress['city_id']])->findOrEmpty()->toArray();
|
||||
if($addressId && empty($city)){
|
||||
throw new Exception('当前城市未开通出行方式,请联系管理员');
|
||||
}
|
||||
if($addressId && true !== $goodsCityLists && !in_array($userAddress['city_id'],$goodsCityLists)){
|
||||
throw new Exception('抱歉,商品暂不支持该服务地址');
|
||||
}
|
||||
$coachServerScope = ConfigService::get('server_setting', 'coach_server_scope');
|
||||
if($addressId && $coach['distance'] > $coachServerScope){
|
||||
throw new Exception('当前最大服务范围'.$coachServerScope.'公里,请重新选择地址');
|
||||
}
|
||||
$distance = intval(ceil($coach['distance']));
|
||||
$tips = '全程'.$coach['distance'].'公里,出租出行收取来回费用,白天起步价'.$city['start_price'].'元,超过'.$city['start_km'].'公里部分,每公里'.$city['continue_price'].'元';
|
||||
if($city['taxi']){
|
||||
$amount = 0;
|
||||
if($distance <= $city['start_km']){
|
||||
$amount = $city['start_price'];
|
||||
}else{
|
||||
$amount += $city['start_price'];
|
||||
$surplus = round($distance-$city['start_km'],2);
|
||||
$amount += round($city['continue_price'] * $surplus,2);
|
||||
}
|
||||
$tripWayLists[] = [
|
||||
'type' => OrderEnum::TRIP_WAY_TAXI,
|
||||
'type_desc' => OrderEnum::getTripWayDesc(OrderEnum::TRIP_WAY_TAXI),
|
||||
'tips' => $tips,
|
||||
'amount' => round($amount,2),
|
||||
];
|
||||
}
|
||||
$nowH = date('H');
|
||||
if($city['bus'] && $nowH > $city['bus_start_time'] && $city['bus_end_time'] > $nowH){
|
||||
$tips = '当前城市'.$city['bus_start_time'].'-'.$city['bus_end_time'].'可选择交通地铁出行方式';
|
||||
$tripWayLists[] = [
|
||||
'type' => OrderEnum::TRIP_WAY_BUS,
|
||||
'type_desc' => OrderEnum::getTripWayDesc(OrderEnum::TRIP_WAY_BUS),
|
||||
'tips' => $tips,
|
||||
'amount' => $city['bus_fare'],
|
||||
];
|
||||
}
|
||||
$tripWayLists = array_column($tripWayLists,null,'type');
|
||||
$carAmount = $tripWayLists[$tripWay]['amount'] ?? 0;
|
||||
}
|
||||
// 订单金额
|
||||
$totalAmount = round($goodsInfo['total_amount']+$carAmount,2);
|
||||
//订单应付金额
|
||||
$orderAmount = $totalAmount;
|
||||
//订单服务总数量
|
||||
$totalNum = $goodsInfo['total_num'];
|
||||
//订单服务总价
|
||||
$totalGoodsPrice = $goodsInfo['total_amount'];
|
||||
$result = [
|
||||
'terminal' => $params['terminal'],
|
||||
'total_num' => $totalNum,
|
||||
'total_goods_price' => $totalGoodsPrice,
|
||||
'total_amount' => $orderAmount,
|
||||
'order_amount' => $orderAmount,
|
||||
'user_id' => $user['id'],
|
||||
'user_remark' => $params['user_remark'] ?? '',
|
||||
'appoint_time' => $params['appoint_time'] ?? '',
|
||||
'address' => $userAddress,
|
||||
'goods' => $goodsInfo['goods_lists'],
|
||||
'trip_way_lists' => array_values($tripWayLists),
|
||||
'trip_way' => $tripWay,
|
||||
'city' => $city,
|
||||
'coach_id' => $params['coach_id'] ?? '',
|
||||
'coach' => $coach,
|
||||
'total_duration' => $goodsInfo['total_duration'],
|
||||
'distance' => $distance,
|
||||
'distance_desc' => $distance ? $coach['distance'].'km' : $distance,
|
||||
'pay_way_list' => PayLogic::getPayWayList($params['terminal'],$params['user_id']),
|
||||
'car_amount' => $carAmount,
|
||||
'city_lists' => $goodsInfo['city_lists'],
|
||||
];
|
||||
return $result;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 验证技师的接单数量
|
||||
* @param $coach
|
||||
* @return int|mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author cjhao
|
||||
* @date 2024/11/26 23:44
|
||||
*/
|
||||
public function ckechCoachTakeOrderNum($coach){
|
||||
$deposit = $coach['deposit'];
|
||||
$depositPackageLists = [];
|
||||
$takeOrderNum = 0;
|
||||
if($coach['shop_id']){
|
||||
$deposit = Shop::where(['id'=>$coach['shop_id']])->value('deposit');
|
||||
$where[] = ['type','=',1];
|
||||
$orderNum = Order::where(['shop_id'=>$coach['shop_id']])
|
||||
->where('order_status','>=',OrderEnum::ORDER_STATUS_WAIT_RECEIVING)
|
||||
->where('order_status','<',OrderEnum::ORDER_STATUS_CLOSE)
|
||||
->whereDay('create_time')->count();
|
||||
}else{
|
||||
$where[] = ['type','=',2];
|
||||
$orderNum = Order::where(['coach_id'=>$coach['id']])
|
||||
->where('order_status','>=',OrderEnum::ORDER_STATUS_WAIT_RECEIVING)
|
||||
->where('order_status','<',OrderEnum::ORDER_STATUS_CLOSE)
|
||||
->whereDay('create_time')->count();
|
||||
}
|
||||
$depositPackageLists = DepositPackage::where($where)->order('money desc')->select()->toArray();
|
||||
//套餐列表
|
||||
foreach ($depositPackageLists as $depositPackage){
|
||||
if($deposit >= $depositPackage['money']){
|
||||
$takeOrderNum = $depositPackage['order_limit'];
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
if($orderNum >= $takeOrderNum){
|
||||
throw new Exception('技师接单数量已达上限');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @notes 获取订单服务信息
|
||||
* @param $goods
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2022/2/24 6:09 下午
|
||||
*/
|
||||
public function getOrderGoods($postGoods,$appointTime)
|
||||
{
|
||||
$postGoods = array_column($postGoods,null,'id');
|
||||
$goodsLists = (new Goods())->field('id,status,name,shop_id,tags,duration,image,price,overtime_price,overtime_duration,shop_ratio,commission_ratio,appoint_start_time,appoint_end_time')
|
||||
->where(['id'=>array_keys($postGoods),'audit_status'=>GoodsEnum::AUDIT_STATUS_PASS])
|
||||
->with(['goods_city'])
|
||||
->select()
|
||||
->toArray();
|
||||
if(count($goodsLists) != count($postGoods)){
|
||||
throw new Exception('商品已失效,请返回上个页面重新选择服务');
|
||||
}
|
||||
$totalAmount = 0;
|
||||
$totalNum = 0;
|
||||
$totalDuration = 0;
|
||||
$cityLists = [];
|
||||
$appointStartI = date('H:i',$appointTime);
|
||||
foreach ($goodsLists as $key => $goods){
|
||||
$goodsNum = $postGoods[$goods['id']]['goods_num'] ?? 0;
|
||||
if(0 >= $goodsNum){
|
||||
throw new Exception('商品数量或商品数据错误');
|
||||
}
|
||||
$goodsLists[$key]['goods_num'] = $goodsNum;
|
||||
$totalAmount += round($goods['price'] * $goodsNum,2);
|
||||
$totalNum += $goodsNum;
|
||||
$totalDuration += ($goods['duration'] * $goodsNum);
|
||||
$appointEndI = date('H:i',$appointTime+$goods['duration'] * 60);
|
||||
if($goods['appoint_start_time'] >! $appointStartI && $goods['appoint_start_time'] <! $appointEndI){
|
||||
throw new Exception('商品服务时间为:'.$goods['appoint_start_time'].'~'.$goods['appoint_end_time']);
|
||||
}
|
||||
if($goods['appoint_end_time'] >! $appointStartI && $goods['appoint_end_time'] < !$appointEndI){
|
||||
throw new Exception('商品服务时间为:'.$goods['appoint_start_time'].'~'.$goods['appoint_end_time']);
|
||||
}
|
||||
if(empty($goods['status'])){
|
||||
throw new Exception('商品已下架,请返回上个页面重新选择服务');
|
||||
}
|
||||
if($goods['goods_city']){
|
||||
foreach ($goods['goods_city'] as $city){
|
||||
$cityLists[] = $city['city_id'];
|
||||
}
|
||||
}else{
|
||||
$cityLists = true;
|
||||
}
|
||||
}
|
||||
//服务数量
|
||||
return [
|
||||
'goods_lists' => $goodsLists,
|
||||
'total_amount' => $totalAmount,
|
||||
'total_num' => $totalNum,
|
||||
'total_duration'=> $totalDuration,
|
||||
'city_lists' => $cityLists,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 提交订单
|
||||
* @param $params
|
||||
* @return array|false
|
||||
* @author ljj
|
||||
* @date 2022/2/25 9:40 上午
|
||||
*/
|
||||
public function submitOrder($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
$this->submitOrderCheck($params);
|
||||
//创建订单信息
|
||||
$order = self::addOrder($params);
|
||||
//订单日志
|
||||
(new OrderLogLogic())->record(OrderLogEnum::TYPE_USER,OrderLogEnum::USER_ADD_ORDER,$order['id'],$params['user_id']);
|
||||
|
||||
//提交事务
|
||||
Db::commit();
|
||||
return ['order_id' => $order['id'], 'type' => 'order'];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 创建订单信息
|
||||
* @param $params
|
||||
* @return Order|\think\Model
|
||||
* @author ljj
|
||||
* @date 2022/2/25 9:40 上午
|
||||
*/
|
||||
public static function addOrder($params)
|
||||
{
|
||||
|
||||
$serverFinishTime = $params['appoint_time'] + ($params['total_duration'] * 60);
|
||||
$shopId = 0;
|
||||
if($params['goods'][0]['shop_id']){
|
||||
$shopId = $params['goods'][0]['shop_id'];
|
||||
}
|
||||
if($params['coach']['shop_id']){
|
||||
$shopId = $params['coach']['shop_id'];
|
||||
}
|
||||
//创建订单信息
|
||||
$order = Order::create([
|
||||
'sn' => generate_sn((new Order()), 'sn'),
|
||||
'user_id' => $params['user_id'],
|
||||
'shop_id' => $shopId,
|
||||
'coach_id' => $params['coach_id'],
|
||||
'order_terminal' => $params['terminal'],
|
||||
'goods_price' => $params['total_goods_price'],
|
||||
'total_order_amount' => $params['order_amount'],
|
||||
'order_amount' => $params['order_amount'],
|
||||
'total_amount' => $params['total_amount'],
|
||||
'total_num' => $params['total_num'],
|
||||
'user_remark' => $params['user_remark'],
|
||||
'contact' => $params['address']['contact'],
|
||||
'mobile' => $params['address']['mobile'],
|
||||
'province_id' => $params['address']['province_id'],
|
||||
'city_id' => $params['address']['city_id'],
|
||||
'district_id' => $params['address']['district_id'],
|
||||
'address_id' => $params['address']['id'],
|
||||
'address_snap' => json_encode($params['address']),
|
||||
'trip_way' => $params['trip_way'],
|
||||
'appoint_time' => $params['appoint_time'],
|
||||
'server_finish_time' => $serverFinishTime,
|
||||
'car_amount' => $params['car_amount'],
|
||||
'car_config_snap' => $params['city'],
|
||||
'order_distance' => $params['distance'],
|
||||
'total_duration' => $params['total_duration'],
|
||||
]);
|
||||
$orderGoods = [];
|
||||
foreach ($params['goods'] as $goods){
|
||||
$orderGoods[] = [
|
||||
'order_id' => $order->id,
|
||||
'goods_id' => $goods['id'],
|
||||
'goods_name' => $goods['name'],
|
||||
'goods_num' => $goods['goods_num'],
|
||||
'goods_image' => FileService::setFileUrl($goods['image']),
|
||||
'goods_price' => $goods['price'],
|
||||
'total_price' => round($goods['price'] * $goods['goods_num'],2),
|
||||
'total_pay_price' => round($goods['price'] * $goods['goods_num'],2),
|
||||
'duration' => $goods['duration'],
|
||||
'goods_snap' => $goods
|
||||
];
|
||||
}
|
||||
//创建订单服务信息
|
||||
(new OrderGoods())->saveAll($orderGoods);
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 订单详情
|
||||
* @param $id
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2022/2/28 11:23 上午
|
||||
*/
|
||||
public function detail($id)
|
||||
{
|
||||
$result = Order::field('id,sn,pay_way,goods_price,order_status,pay_status,appoint_time,order_amount,server_finish_time,create_time,coach_id,cancel_time,total_gap_amount,total_append_amount,total_order_amount,order_distance,address_snap,car_amount,user_remark')
|
||||
->where(['id'=>$id])
|
||||
->order('id','desc')
|
||||
->append(['appoint_time','pay_way_desc','appoint_date','order_status_desc','pay_btn','gap_btn','append_btn','user_cancel_btn','del_btn','comment_btn','look_comment_btn','order_cancel_time'])
|
||||
->with(['order_goods' => function($query){
|
||||
$query->field('id,order_id,goods_id,goods_snap,is_comment,duration,goods_image,goods_num,goods_name,goods_price')->hidden(['goods_snap']);
|
||||
},'order_gap','order_append'])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
|
||||
if(!isset($result['address_snap']['house_number'])){
|
||||
$result['address_snap']['house_number'] = '';
|
||||
}
|
||||
// if(in_array($result['order_status'],[OrderEnum::ORDER_STATUS_DEPART,OrderEnum::ORDER_STATUS_ARRIVE,OrderEnum::ORDER_STATUS_START_SERVER,OrderEnum::ORDER_STATUS_SERVER_FINISH])){
|
||||
$coach = Coach::where(['id'=>$result['coach_id']])->field('id,mobile,name,work_photo,sn')->findOrEmpty()->toArray();
|
||||
$result['coach_info'] = [
|
||||
'name' => $coach['name'] ?? '',
|
||||
'work_photo' => $coach['work_photo'] ?? '',
|
||||
'sn' => $coach['sn'] ?? '',
|
||||
'mobile'=> $coach['mobile'],
|
||||
];
|
||||
// }
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 取消订单
|
||||
* @param $params
|
||||
* @return bool|string
|
||||
* @author ljj
|
||||
* @date 2022/2/28 11:36 上午
|
||||
*/
|
||||
public function cancel($params)
|
||||
{
|
||||
// 启动事务
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
//TODO 已支付订单原路退回金额
|
||||
$order = Order::where('id',$params['id'])->findOrEmpty()->toArray();
|
||||
$totalRefundAmount = 0;
|
||||
if($order['pay_status'] == PayEnum::ISPAID) {
|
||||
$totalRefundAmount = $order['total_order_amount'];
|
||||
(new RefundLogic())->refund($order,$order['total_order_amount'],0,OrderRefundEnum::TYPE_USER,1,$params['user_id']);
|
||||
}
|
||||
//更新订单状态
|
||||
Order::update([
|
||||
'total_refund_amount' => $totalRefundAmount,
|
||||
'order_status' => OrderEnum::ORDER_STATUS_CLOSE,
|
||||
'cancel_time' => time(),
|
||||
],['id'=>$params['id']]);
|
||||
|
||||
//添加订单日志
|
||||
(new OrderLogLogic())->record(OrderLogEnum::TYPE_USER,OrderLogEnum::USER_CANCEL_ORDER,$params['id'],$params['user_id']);
|
||||
//取消订单-通知用户
|
||||
event('Notice', [
|
||||
'scene_id' => NoticeEnum::ORDER_CANCEL_NOTICE,
|
||||
'params' => [
|
||||
'user_id' => $order['user_id'],
|
||||
'order_id' => $order['id']
|
||||
]
|
||||
]);
|
||||
//取消订单-通知师傅
|
||||
event('Notice', [
|
||||
'scene_id' => NoticeEnum::ORDER_CANCEL_NOTICE_STAFF,
|
||||
'params' => [
|
||||
'coach_id' => $order['coach_id'],
|
||||
'order_id' => $order['id']
|
||||
]
|
||||
]);
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除订单
|
||||
* @param $id
|
||||
* @return bool
|
||||
* @author ljj
|
||||
* @date 2022/2/28 11:50 上午
|
||||
*/
|
||||
public function del($id)
|
||||
{
|
||||
Order::destroy($id);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 支付方式
|
||||
* @param $params
|
||||
* @return mixed
|
||||
* @author ljj
|
||||
* @date 2024/7/24 下午7:08
|
||||
*/
|
||||
public static function payWay($params)
|
||||
{
|
||||
try {
|
||||
// 获取待支付金额
|
||||
if ($params['from'] == 'order') {
|
||||
// 订单
|
||||
$order = Order::findOrEmpty($params['order_id'])->toArray();
|
||||
}
|
||||
if ($params['from'] == 'recharge') {
|
||||
// 充值
|
||||
$order = RechargeOrder::findOrEmpty($params['order_id'])->toArray();
|
||||
}
|
||||
|
||||
if ($params['from'] == 'orderGap') {
|
||||
// 补差价
|
||||
$order = OrderGap::findOrEmpty($params['order_id'])->toArray();
|
||||
}
|
||||
if ($params['from'] == 'orderAppend') {
|
||||
// 加钟
|
||||
$order = OrderAppend::findOrEmpty($params['order_id'])->toArray();
|
||||
}
|
||||
if (empty($order)) {
|
||||
throw new \Exception('订单不存在');
|
||||
}
|
||||
|
||||
// 获取订单剩余支付时间
|
||||
$cancelUnpaidOrders = ConfigService::get('transaction', 'cancel_unpaid_orders',1);
|
||||
$cancelUnpaidOrdersTimes = ConfigService::get('transaction', 'cancel_unpaid_orders_times',30);
|
||||
$cancelTime = 0;
|
||||
if(!in_array($params['from'],['order_gap','order_append'])){
|
||||
if (empty($cancelUnpaidOrders)) {
|
||||
// 不自动取消待支付订单
|
||||
$cancelTime = 0;
|
||||
} else {
|
||||
// 指定时间内取消待支付订单
|
||||
$cancelTime = strtotime($order['create_time']) + intval($cancelUnpaidOrdersTimes) * 60;
|
||||
}
|
||||
}
|
||||
$pay_way = PayWay::alias('pw')
|
||||
->join('dev_pay dp', 'pw.pay_id = dp.id')
|
||||
->where(['pw.scene'=>$params['scene'],'pw.status'=>YesNoEnum::YES])
|
||||
->field('dp.id,dp.name,dp.pay_way,dp.image,pw.is_default')
|
||||
->order(['sort'=>'asc','id'=>'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($pay_way as $k=>&$item) {
|
||||
if ($item['pay_way'] == PayEnum::BALANCE_PAY) {
|
||||
$user_money = User::where(['id' => $params['user_id']])->value('user_money');
|
||||
$item['extra'] = '可用余额:'.$user_money;
|
||||
}
|
||||
// 充值时去除余额支付
|
||||
if ($params['from'] == 'recharge' && $item['pay_way'] == PayEnum::BALANCE_PAY) {
|
||||
unset($pay_way[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'lists' => array_values($pay_way),
|
||||
'order_amount' => $order['order_amount'],
|
||||
'cancel_time' => $cancelTime,
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取技师服务时间
|
||||
* @param $coachId
|
||||
* @param $goodsId
|
||||
* @return array|false
|
||||
* @author cjhao
|
||||
* @date 2024/11/26 22:44
|
||||
*/
|
||||
public function getCoachServerTime($coachId,$goodsId)
|
||||
{
|
||||
try {
|
||||
if(empty($coachId)){
|
||||
throw new Exception('请选择技师');
|
||||
}
|
||||
$coachServerTimeLists = \app\common\logic\CoachLogic::getCoachServerTime($coachId,$goodsId);
|
||||
$timeLists = [];
|
||||
// 获取当前日期的时间戳
|
||||
$currentDate = strtotime(date('Y-m-d'));
|
||||
// 获取明天和后天的时间戳
|
||||
$tomorrowDate = strtotime('tomorrow');
|
||||
$afterTomorrowDate = strtotime('+2 days',$currentDate);
|
||||
foreach ($coachServerTimeLists as $key => $serverTimeList){
|
||||
$timeTips = '';
|
||||
$timestamp = strtotime(date('Y-'.$key));
|
||||
if ($timestamp >=$currentDate && $timestamp <$tomorrowDate) {
|
||||
$timeTips = '今天';
|
||||
} elseif ($timestamp >=$tomorrowDate && $timestamp <$afterTomorrowDate) {
|
||||
$timeTips = '明天';
|
||||
} elseif ($timestamp >=$afterTomorrowDate && $timestamp < strtotime('+3 days',$currentDate)) {
|
||||
$timeTips = '后天';
|
||||
} else {
|
||||
$weekdays = array('星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六');
|
||||
$weekdayIndex = date('w',$timestamp);
|
||||
$timeTips = $weekdays[$weekdayIndex];
|
||||
}
|
||||
$timeLists[] = [
|
||||
'time_date' => $key,
|
||||
'time_tips' => $timeTips,
|
||||
'time_lists' => $serverTimeList
|
||||
];
|
||||
|
||||
}
|
||||
return $timeLists;
|
||||
|
||||
}catch (Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 订单差价
|
||||
* @param array $params
|
||||
* @return array|false
|
||||
* @author cjhao
|
||||
* @date 2024/9/19 11:04
|
||||
*/
|
||||
public function orderGap(array $params)
|
||||
{
|
||||
// 启动事务
|
||||
// Db::startTrans();
|
||||
try {
|
||||
$order = Order::where(['id'=>$params['order_id'],'user_id'=>$params['user_id']])->findOrEmpty();
|
||||
if($order->isEmpty()){
|
||||
throw new Exception('订单不存在');
|
||||
}
|
||||
if(PayEnum::UNPAID == $order->pay_status){
|
||||
throw new Exception('当前订单未支付');
|
||||
}
|
||||
if(OrderEnum::ORDER_STATUS_SERVER_FINISH == $order->order_status){
|
||||
throw new Exception('订单已完成');
|
||||
}
|
||||
$orderGap = OrderGap::create([
|
||||
'sn' => generate_sn((new OrderGap()), 'sn'),
|
||||
'user_id' => $params['user_id'],
|
||||
'order_id' => $order->id,
|
||||
'order_amount' => $params['order_amount'],
|
||||
'remark' => $params['remark'],
|
||||
]);
|
||||
// 提交事务
|
||||
// Db::commit();
|
||||
return [
|
||||
'id' => $orderGap->id,
|
||||
'order_id' => $order->id,
|
||||
'sn' => $orderGap->sn,
|
||||
'type' => 'orderGap'
|
||||
];
|
||||
}catch (Exception $e){
|
||||
// Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 订单加钟
|
||||
* @param array $params
|
||||
* @return array|bool
|
||||
* @author cjhao
|
||||
* @date 2024/9/20 00:40
|
||||
*/
|
||||
public function orderAppend(array $params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = Order::where(['id'=>$params['order_id'],'user_id'=>$params['user_id']])->findOrEmpty();
|
||||
if($order->isEmpty()){
|
||||
throw new Exception('订单不存在');
|
||||
}
|
||||
if(PayEnum::UNPAID == $order->pay_status){
|
||||
throw new Exception('当前订单未支付');
|
||||
}
|
||||
if(OrderEnum::ORDER_STATUS_SERVER_FINISH == $order->order_status){
|
||||
throw new Exception('订单已完成');
|
||||
}
|
||||
$goods = Goods::where(['id'=>$params['goods'][0]['id']])->findOrEmpty()->toArray();
|
||||
//加钟时长
|
||||
$overtimeDuration = $goods['overtime_duration'];
|
||||
//加钟价
|
||||
$overtimePrice = round($goods['overtime_price'] * $params['goods'][0]['goods_num'],2);
|
||||
$action = $params['action'] ?? 'settlement';
|
||||
if('settlement' === $action){
|
||||
return [
|
||||
'order_id' => $order->id,
|
||||
'goods_id' => $goods['id'],
|
||||
'goods_name' => $goods['name'],
|
||||
'goods_num' => (int)$params['goods'][0]['goods_num'],
|
||||
'duration' => $overtimeDuration,
|
||||
'goods_price' => $goods['overtime_price'],
|
||||
'order_amount' => $overtimePrice,
|
||||
];
|
||||
}
|
||||
$serverFinishTime = $order['server_finish_time'];
|
||||
$totalDurations = $overtimeDuration;
|
||||
//判断下订单也没有加时
|
||||
$totalDuration = OrderAppend::where(['order_id'=>$order->id,'pay_status'=>PayEnum::ISPAID])->sum('duration');
|
||||
if($totalDuration){
|
||||
$totalDurations += $totalDuration;
|
||||
}
|
||||
$serverTime = point_timestamps($serverFinishTime,$totalDurations*60*$params['goods'][0]['goods_num']);
|
||||
$dateTime = date('m-d',$serverFinishTime);
|
||||
$coachServerTime = \app\common\logic\CoachLogic::getCoachServerTime($order['coach_id'])[$dateTime] ?? [];
|
||||
$coachServerTime = array_column($coachServerTime,null,'time');
|
||||
foreach ($serverTime as $key => $time){
|
||||
|
||||
$coachTime = $coachServerTime[$time['time']] ?? [];
|
||||
if(empty($coachTime)){
|
||||
throw new Exception('技师当前占无时间段可预约');
|
||||
}
|
||||
//开始时间是重叠的,第一个key不判断
|
||||
if(0 != $key && 3 == $coachTime['status']){
|
||||
throw new Exception('当前时段已被预约');
|
||||
}
|
||||
if(2 == $coachTime['status']){
|
||||
throw new Exception( '当前时段技师在休息');
|
||||
}
|
||||
}
|
||||
$orderAppend = OrderAppend::create([
|
||||
'sn' => generate_sn((new OrderAppend()), 'sn'),
|
||||
'user_id' => $params['user_id'],
|
||||
'order_id' => $order->id,
|
||||
'goods_id' => $goods['id'],
|
||||
'goods_name' => $goods['name'],
|
||||
'goods_image' => $goods['image'],
|
||||
'goods_num' => $params['goods'][0]['goods_num'],
|
||||
'goods_price' => $goods['overtime_price'],
|
||||
'goods_snap' => $goods,
|
||||
'order_amount' => $overtimePrice,
|
||||
'duration' => $overtimeDuration,
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return [
|
||||
'id' => $orderAppend->id,
|
||||
'order_id' => $order->id,
|
||||
'sn' => $orderAppend->sn,
|
||||
'type' => 'orderAppend'
|
||||
];
|
||||
}catch (Exception $e){
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 订单评论
|
||||
* @param $params
|
||||
* @return false|void
|
||||
* @author cjhao
|
||||
* @date 2024/9/24 20:45
|
||||
*/
|
||||
public function comment($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = Order::where(['id'=>$params['id'],'user_id'=>$params['user_id']])->with(['order_goods'])->findOrEmpty();
|
||||
if($order->isEmpty()){
|
||||
throw new Exception('订单不存在');
|
||||
}
|
||||
if(OrderEnum::ORDER_STATUS_SERVER_FINISH != $order->order_status){
|
||||
throw new Exception('订单未完成服务,不能评论');
|
||||
}
|
||||
$comment = GoodsComment::where(['order_goods_id'=>$order['order_goods'][0]['id']])->findOrEmpty();
|
||||
if(!$comment->isEmpty()){
|
||||
throw new Exception('订单已评论');
|
||||
}
|
||||
$goodsComment = GoodsComment::create([
|
||||
'goods_id' => $order['order_goods'][0]['goods_id'],
|
||||
'user_id' => $params['user_id'],
|
||||
'order_goods_id' => $order['order_goods'][0]['id'],
|
||||
'service_comment' => $params['service_comment'],
|
||||
'comment' => $params['content'],
|
||||
]);
|
||||
$imageLists = $params['image_lists'] ?? [];
|
||||
if($imageLists){
|
||||
$commentImage = [];
|
||||
foreach ($imageLists as $image){
|
||||
$commentImage[] = [
|
||||
'comment_id' => $goodsComment['id'],
|
||||
'uri' => $image,
|
||||
];
|
||||
}
|
||||
(new GoodsCommentImage())->saveAll($commentImage);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
}catch (Exception $e){
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 下单前验证
|
||||
* @param $params
|
||||
* @return true
|
||||
* @author cjhao
|
||||
* @date 2025/4/27 10:56
|
||||
*/
|
||||
public function submitOrderCheck($params)
|
||||
{
|
||||
//验证在默认使用地址的情况下,默认地址是否可用
|
||||
$city = $params['city'] ?? '';
|
||||
$userAddress = $params['address'] ?? [];
|
||||
$coach = $params['coach'] ?? [];
|
||||
$goodsCityLists = $params['city_lists'] ?? [];
|
||||
if(empty($params['address_id'])){
|
||||
if(empty($city)){
|
||||
throw new Exception('当前城市未开通出行方式,请联系管理员');
|
||||
}
|
||||
if(true !== $goodsCityLists && !in_array($userAddress['city_id'],$goodsCityLists)){
|
||||
throw new Exception('抱歉,商品暂不支持该服务地址');
|
||||
}
|
||||
$coachServerScope = ConfigService::get('server_setting', 'coach_server_scope');
|
||||
if($coach['distance'] > $coachServerScope){
|
||||
throw new Exception('当前最大服务范围'.$coachServerScope.'公里,请重新选择地址');
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
272
server/app/api/logic/PayLogic.php
Executable file
272
server/app/api/logic/PayLogic.php
Executable file
@@ -0,0 +1,272 @@
|
||||
<?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\api\logic;
|
||||
|
||||
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\logic\PayNotifyLogic;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\order\OrderAppend;
|
||||
use app\common\model\order\OrderGap;
|
||||
use app\common\model\pay\PayWay;
|
||||
use app\common\model\RechargeOrder;
|
||||
use app\common\model\user\User;
|
||||
use app\common\service\AliPayService;
|
||||
use app\common\service\BalancePayService;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\WeChatPayService;
|
||||
|
||||
class PayLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 支付方式
|
||||
* @param $params
|
||||
* @return array|false
|
||||
* @author ljj
|
||||
* @date 2022/2/28 2:56 下午
|
||||
*/
|
||||
public static function payWay($params)
|
||||
{
|
||||
try {
|
||||
$order = [];
|
||||
// 获取待支付金额
|
||||
if ($params['from'] == 'order') {
|
||||
// 订单
|
||||
$order = Order::findOrEmpty($params['order_id'])->toArray();
|
||||
}
|
||||
if ($params['from'] == 'recharge') {
|
||||
// 充值
|
||||
$order = RechargeOrder::findOrEmpty($params['order_id'])->toArray();
|
||||
}
|
||||
|
||||
if ($params['from'] == 'order_gap') {
|
||||
// 补差价
|
||||
$order = OrderGap::findOrEmpty($params['order_id'])->toArray();
|
||||
}
|
||||
if ($params['from'] == 'order_append') {
|
||||
// 加钟
|
||||
$order = OrderAppend::findOrEmpty($params['order_id'])->toArray();
|
||||
}
|
||||
|
||||
if (empty($order)) {
|
||||
throw new \Exception('订单不存在');
|
||||
}
|
||||
|
||||
// 获取订单剩余支付时间
|
||||
$cancelUnpaidOrders = ConfigService::get('transaction', 'cancel_unpaid_orders',1);
|
||||
$cancelUnpaidOrdersTimes = ConfigService::get('transaction', 'cancel_unpaid_orders_times',30);
|
||||
$cancelTime = 0;
|
||||
if(!in_array($params['from'],['order_gap','order_append'])){
|
||||
if (empty($cancelUnpaidOrders)) {
|
||||
// 不自动取消待支付订单
|
||||
$cancelTime = 0;
|
||||
} else {
|
||||
// 指定时间内取消待支付订单
|
||||
$cancelTime = strtotime($order['create_time']) + intval($cancelUnpaidOrdersTimes) * 60;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$pay_way = PayWay::alias('pw')
|
||||
->join('dev_pay dp', 'pw.pay_id = dp.id')
|
||||
->where(['pw.scene'=>$params['scene'],'pw.status'=>YesNoEnum::YES])
|
||||
->field('dp.id,dp.name,dp.pay_way,dp.image,pw.is_default')
|
||||
->order(['sort'=>'asc','id'=>'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($pay_way as $k=>&$item) {
|
||||
if ($item['pay_way'] == PayEnum::WECHAT_PAY) {
|
||||
$item['extra'] = '微信快捷支付';
|
||||
}
|
||||
|
||||
if ($item['pay_way'] == PayEnum::BALANCE_PAY) {
|
||||
$user_money = User::where(['id' => $params['user_id']])->value('user_money');
|
||||
$item['extra'] = '可用余额:'.$user_money;
|
||||
}
|
||||
// 充值时去除余额支付
|
||||
if ($params['from'] == 'recharge' && $item['pay_way'] == PayEnum::BALANCE_PAY) {
|
||||
unset($pay_way[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'lists' => array_values($pay_way),
|
||||
'order_amount' => $order['order_amount'],
|
||||
'cancel_time' => $cancelTime,
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 支付
|
||||
* @param $payWay // 支付方式
|
||||
* @param $from //订单来源(商品订单?充值订单?其他订单?)
|
||||
* @param $order_id //订单id
|
||||
* @param $terminal //终端
|
||||
* @return array|bool|string|void
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2021/7/29 14:49
|
||||
*/
|
||||
public static function pay($payWay, $from, $order_id, $terminal)
|
||||
{
|
||||
$order = [];
|
||||
//更新支付方式
|
||||
switch ($from) {
|
||||
case 'order':
|
||||
Order::update(['pay_way' => $payWay], ['id' => $order_id]);
|
||||
$order = Order::where('id',$order_id)->findOrEmpty()->toArray();
|
||||
break;
|
||||
case 'recharge':
|
||||
RechargeOrder::update(['pay_way' => $payWay], ['id' => $order_id]);
|
||||
$order = RechargeOrder::where('id',$order_id)->findOrEmpty()->toArray();
|
||||
break;
|
||||
case 'orderGap':
|
||||
$order = OrderGap::where('id',$order_id)->findOrEmpty();
|
||||
$order->pay_way = $payWay;
|
||||
$order->save();
|
||||
$order = $order->toArray();
|
||||
break;
|
||||
case 'orderAppend':
|
||||
$order = OrderAppend::where('id',$order_id)->findOrEmpty();
|
||||
$order->pay_way = $payWay;
|
||||
$order->save();
|
||||
$order = $order->toArray();
|
||||
break;
|
||||
}
|
||||
|
||||
if (empty($order)) {
|
||||
self::setError('订单错误');
|
||||
}
|
||||
|
||||
if($order['order_amount'] == 0) {
|
||||
PayNotifyLogic::handle($from, $order['sn']);
|
||||
return ['pay_way'=>$payWay];
|
||||
}
|
||||
|
||||
switch ($payWay) {
|
||||
case PayEnum::WECHAT_PAY:
|
||||
$payService = (new WeChatPayService($terminal, $order['user_id'] ?? null));
|
||||
$result = $payService->pay($from, $order);
|
||||
break;
|
||||
case PayEnum::BALANCE_PAY:
|
||||
//余额支付
|
||||
$payService = (new BalancePayService());
|
||||
$result = $payService->pay($from, $order);
|
||||
if (false !== $result) {
|
||||
PayNotifyLogic::handle($from, $order['sn']);
|
||||
}
|
||||
break;
|
||||
case PayEnum::ALI_PAY:
|
||||
$payService = (new AliPayService($terminal));
|
||||
$result = $payService->pay($from, $order);
|
||||
break;
|
||||
default:
|
||||
self::$error = '订单异常';
|
||||
$result = false;
|
||||
}
|
||||
|
||||
//支付成功, 执行支付回调
|
||||
if (false === $result && !self::hasError()) {
|
||||
self::setError($payService->getError());
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取支付结果
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2024/3/21 5:48 下午
|
||||
*/
|
||||
public static function getPayResult($params)
|
||||
{
|
||||
switch ($params['from']) {
|
||||
case 'order' :
|
||||
$result = Order::where(['id' => $params['order_id']])
|
||||
->field(['id', 'sn', 'pay_time', 'pay_way', 'order_amount', 'pay_status'])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
$result['total_amount'] = '¥' . $result['order_amount'];
|
||||
break;
|
||||
case 'recharge' :
|
||||
$result = RechargeOrder::where(['id' => $params['order_id']])
|
||||
->field(['id','sn','pay_time','pay_way','order_amount','pay_status'])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
$result['total_amount'] = '¥' . $result['order_amount'];
|
||||
break;
|
||||
case 'orderGap':
|
||||
// 补差价
|
||||
$result = OrderGap::where('id',$params['order_id'])->findOrEmpty()->toArray();
|
||||
$result['total_amount'] = '¥' . $result['order_amount'];
|
||||
break;
|
||||
case 'orderAppend':
|
||||
// 加钟
|
||||
$result = OrderAppend::where('id',$params['order_id'])->findOrEmpty()->toArray();
|
||||
$result['total_amount'] = '¥' . $result['order_amount'];
|
||||
break;
|
||||
default :
|
||||
$result = [];
|
||||
}
|
||||
if (empty($result)) {
|
||||
self::$error = '订单信息不存在';
|
||||
}
|
||||
$result['pay_way_desc'] = PayEnum::getPayTypeDesc($result['pay_way']);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取支付方式
|
||||
* @param int $scene
|
||||
* @param int $userId
|
||||
* @return array
|
||||
* @author cjhao
|
||||
* @date 2024/10/11 22:49
|
||||
*/
|
||||
public static function getPayWayList(int $scene,int $userId){
|
||||
$pay_way = PayWay::alias('pw')
|
||||
->join('dev_pay dp', 'pw.pay_id = dp.id')
|
||||
->where(['pw.scene'=>$scene,'pw.status'=>YesNoEnum::YES])
|
||||
->field('dp.id,dp.name,dp.pay_way,dp.image,pw.is_default')
|
||||
->order(['sort'=>'asc','id'=>'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($pay_way as $k=>&$item) {
|
||||
if ($item['pay_way'] == PayEnum::WECHAT_PAY) {
|
||||
$item['extra'] = '微信快捷支付';
|
||||
}
|
||||
|
||||
if ($item['pay_way'] == PayEnum::BALANCE_PAY) {
|
||||
$user_money = User::where(['id' => $userId])->value('user_money');
|
||||
$item['extra'] = '可用余额:'.$user_money;
|
||||
}
|
||||
}
|
||||
return $pay_way;
|
||||
}
|
||||
}
|
||||
50
server/app/api/logic/RechargeLogic.php
Executable file
50
server/app/api/logic/RechargeLogic.php
Executable file
@@ -0,0 +1,50 @@
|
||||
<?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\api\logic;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\RechargeOrder;
|
||||
|
||||
class RechargeLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 充值
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2022/12/16 16:09
|
||||
*/
|
||||
public function recharge($params)
|
||||
{
|
||||
$order = RechargeOrder::create([
|
||||
'sn' => generate_sn((new RechargeOrder()),'sn'),
|
||||
'user_id' => $params['user_id'],
|
||||
'order_terminal'=> $params['terminal'],
|
||||
'pay_way' => $params['pay_way'] ?? 0,
|
||||
'order_amount' => $params['money'],
|
||||
]);
|
||||
|
||||
return [
|
||||
'order_id' => $order->id,
|
||||
'from' => 'recharge'
|
||||
];
|
||||
}
|
||||
}
|
||||
63
server/app/api/logic/RegisterLogic.php
Executable file
63
server/app/api/logic/RegisterLogic.php
Executable file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | 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团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\user\User;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\FileService;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* 注册逻辑层
|
||||
* Class RegisterLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class RegisterLogic extends BaseLogic
|
||||
{
|
||||
public static function register($params)
|
||||
{
|
||||
try {
|
||||
$defaultAvatar = ConfigService::get('config', 'default_avatar', FileService::getFileUrl(config('project.default_image.user_avatar')));
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
$password = create_password($params['password'], $passwordSalt);
|
||||
// 创建用户
|
||||
$data = [
|
||||
'channel' => $params['channel'],
|
||||
'sn' => create_user_sn(),
|
||||
'nickname' => $params['mobile'],
|
||||
'avatar' => $defaultAvatar,
|
||||
'mobile' => $params['mobile'],
|
||||
'account' => $params['mobile'],
|
||||
'password' => $password,
|
||||
];
|
||||
$user = User::create($data);
|
||||
|
||||
return true;
|
||||
} catch(\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
53
server/app/api/logic/SearchLogic.php
Executable file
53
server/app/api/logic/SearchLogic.php
Executable file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\HotSearch;
|
||||
use app\common\service\ConfigService;
|
||||
|
||||
/**
|
||||
* 搜索逻辑
|
||||
* Class SearchLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class SearchLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 热搜列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/23 14:34
|
||||
*/
|
||||
public static function hotLists()
|
||||
{
|
||||
$data = HotSearch::field(['name', 'sort'])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()->toArray();
|
||||
|
||||
return [
|
||||
// 功能状态 0-关闭 1-开启
|
||||
'status' => ConfigService::get('hot_search', 'status', 0),
|
||||
// 热门搜索数据
|
||||
'data' => $data,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
49
server/app/api/logic/ShareLogic.php
Executable file
49
server/app/api/logic/ShareLogic.php
Executable file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | 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团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\api\logic;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\WeChatService;
|
||||
|
||||
/**
|
||||
* 分享逻辑层
|
||||
* Class ShareLogic
|
||||
* @package app\shopapi\logic
|
||||
*/
|
||||
class ShareLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 获取小程序码
|
||||
* @param $params
|
||||
* @return bool|mixed|string
|
||||
* @author ljj
|
||||
* @date 2023/2/28 5:09 下午
|
||||
*/
|
||||
public function getMnpQrCode($params)
|
||||
{
|
||||
$data['page'] = $params['page'];
|
||||
if (isset($params['id']) && $params['id'] != '') {
|
||||
$data['scene'] = 'id='.$params['id'];
|
||||
}
|
||||
|
||||
$result = WeChatService::makeMpQrCode($data,'base64');
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
190
server/app/api/logic/ShopLogic.php
Executable file
190
server/app/api/logic/ShopLogic.php
Executable file
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\enum\GoodsEnum;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\enum\shop\ShopEnum;
|
||||
use app\common\model\coach\Coach;
|
||||
use app\common\model\coach\Collect;
|
||||
use app\common\model\goods\Goods;
|
||||
use app\common\model\goods\GoodsCategory;
|
||||
use app\common\model\goods\GoodsComment;
|
||||
use app\common\model\IndexVisit;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\shop\Shop;
|
||||
use app\common\model\shop\ShopCoachApply;
|
||||
use app\common\model\shop\ShopVisit;
|
||||
use app\common\model\user\User;
|
||||
use app\common\service\FileService;
|
||||
|
||||
class ShopLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 商家详情
|
||||
* @param $params
|
||||
* @param $userInfo
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author cjhao
|
||||
* @date 2024/11/19 12:14
|
||||
*/
|
||||
public function detail($params,$userInfo)
|
||||
{
|
||||
$field = 'id,name,good_comment,logo,work_status,province_id,region_id,city_id,shop_address_detail,longitude,latitude,monday,tuesday,wednesday,thursday,friday,saturday,sunday,business_start_time,business_end_time,synopsis,business_license,mobile';
|
||||
if (!empty($params['longitude']) && !empty($params['latitude'])) {
|
||||
$field .= ',round(st_distance_sphere(point('.$params['longitude'].','.$params['latitude'].'),
|
||||
point(longitude, latitude))/1000,2) as distance';
|
||||
}
|
||||
$detail = Shop::where(['id'=>$params['id'],'audit_status'=>ShopEnum::AUDIT_STATUS_PASS,'server_status'=>ShopEnum::SERVERSTATUSOPEN])
|
||||
->with(['shop_image'])
|
||||
->field($field)
|
||||
->append(['distance_desc','category_ids','work_status_desc','region_desc','business_time_desc'])
|
||||
->findOrEmpty();
|
||||
$ids = array_column($detail->category_ids->toArray(),'category_id');
|
||||
$categoryLists = GoodsCategory::where(['is_show'=>1,'id'=>$ids])->column('name');
|
||||
$detail['category_name'] = implode('|',$categoryLists);
|
||||
if (!is_array($detail['category_name'])) {
|
||||
$detail['category_name'] = [$detail['category_name']];
|
||||
}
|
||||
$week = strtolower(date('l'));
|
||||
$shopWeek = $detail[$week] ?? 0;
|
||||
if(!$shopWeek){
|
||||
$detail['work_status'] = 0;
|
||||
$detail['work_status_desc'] = ShopEnum::getWorkStatus($detail['work_status']);
|
||||
}else{
|
||||
$nowHi = date('H:i');
|
||||
$detail['business_start_time'] = format_business_time($detail['business_start_time']);
|
||||
$detail['business_end_time'] = format_business_time($detail['business_end_time']);
|
||||
if($detail['business_start_time'] > $nowHi || $detail['business_end_time'] < $nowHi){
|
||||
$detail['work_status'] = 0;
|
||||
$detail['work_status_desc'] = ShopEnum::getWorkStatus($detail['work_status']);
|
||||
}
|
||||
}
|
||||
$consumption = Order::where(['pay_status'=>PayEnum::ISPAID])
|
||||
->where('shop_id','=',$params['id'])
|
||||
->value('round(sum(order_amount)/count(id),2) as consumption');
|
||||
$detail['consumption'] = $consumption ? : 0;
|
||||
$map1 = [
|
||||
['SGI.shop_id','=',$params['id']],
|
||||
];
|
||||
|
||||
$detail['goods_lists'] = Goods::alias('G')
|
||||
->leftjoin('shop_goods_index SGI','G.id = SGI.goods_id')
|
||||
->whereRaw('(SGI.shop_id ='. $params['id'].') or (G.shop_id = '.$params['id'].' and G.audit_status = '.GoodsEnum::AUDIT_STATUS_PASS .')')
|
||||
->field('G.id,name,image,price,scribing_price,duration,order_num')
|
||||
->limit(8)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$coachIds = ShopCoachApply::where(['shop_id'=>$params['id'],'audit_status'=>ShopEnum::AUDIT_STATUS_PASS])->column('coach_id');
|
||||
$commentLists = GoodsComment::where(['coach_id'=>$coachIds])
|
||||
->field('id,user_id,service_comment,comment,reply')
|
||||
->append(['goods_comment_image'])
|
||||
->limit(5)
|
||||
->select()
|
||||
->toArray();
|
||||
$userIds = array_column($commentLists,'user_id');
|
||||
$userLists = User::where(['id'=>$userIds])->column('nickname,avatar','id');
|
||||
foreach ($commentLists as $key => $comment_list){
|
||||
$commentLists[$key]['nickname'] = $userLists[$comment_list['user_id']]['nickname'] ?? '';
|
||||
$commentLists[$key]['avatar'] = FileService::getFileUrl($userLists[$comment_list['user_id']]['avatar'] ?? '');
|
||||
}
|
||||
$detail['comment_lists'] = $commentLists;
|
||||
if(!empty($params['terminal'])){
|
||||
$ip = request()->ip();
|
||||
// 一个ip一个终端一天只生成一条记录
|
||||
$record = ShopVisit::where([
|
||||
'shop_id' => $params['id'],
|
||||
'ip' => $ip,
|
||||
'terminal' => $params['terminal']
|
||||
])->whereDay('create_time')->findOrEmpty();
|
||||
if (!$record->isEmpty()) {
|
||||
// 增加访客在终端的浏览量
|
||||
$record->visit += 1;
|
||||
$record->save();
|
||||
}
|
||||
// 生成访客记录
|
||||
ShopVisit::create([
|
||||
'shop_id' => $params['id'],
|
||||
'ip' => $ip,
|
||||
'terminal' => $params['terminal'],
|
||||
'visit' => 1
|
||||
]);
|
||||
}
|
||||
|
||||
$detail['is_collect'] = Collect::where(['relation_id'=>$params['id'],'user_id'=>$userInfo['user_id'] ?? 0,'type'=>3])->findOrEmpty()->toArray() ? 1 : 0;
|
||||
|
||||
return $detail->toArray();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function commentCategory($shopId)
|
||||
{
|
||||
$coachIds = Coach::where(['shop_id'=>$shopId])->field('id')->select()->toArray();
|
||||
$coachIds = array_column($coachIds,'id');
|
||||
$orderGoodsIds = Order::alias('O')
|
||||
->join('order_goods OG','O.id = OG.order_id')
|
||||
->where(['coach_id'=>$coachIds,'is_comment'=>1])
|
||||
->field('OG.id')
|
||||
->select()
|
||||
->toArray();
|
||||
$orderGoodsIds = array_column($orderGoodsIds,'id');
|
||||
$all_count = GoodsComment::where('order_goods_id','in', $orderGoodsIds)->count();
|
||||
$image_count = GoodsComment::alias('gc')->where('order_goods_id','in',$orderGoodsIds)->join('goods_comment_image gci', 'gc.id = gci.comment_id')->group('gci.comment_id')->count();
|
||||
$good_count = GoodsComment::where('order_goods_id', 'in',$orderGoodsIds)->where('service_comment','>',3)->count();
|
||||
$medium_bad_count = GoodsComment::where('order_goods_id', 'in',$orderGoodsIds)->where('service_comment','<=',3)->count();
|
||||
|
||||
if($all_count == 0) {
|
||||
$percentStr = '100%';
|
||||
$star = 5;
|
||||
}else {
|
||||
$percent = round((($good_count / $all_count) * 100));
|
||||
$percentStr = round((($good_count / $all_count) * 100)).'%';
|
||||
if ($percent >= 100) {
|
||||
$star = 5;
|
||||
} else if ($percent >= 80) {
|
||||
$star = 4;
|
||||
} else if ($percent >= 60) {
|
||||
$star = 3;
|
||||
} else if ($percent >= 40) {
|
||||
$star = 2;
|
||||
} else if ($percent >= 20) {
|
||||
$star = 1;
|
||||
} else {
|
||||
$star = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return ['comment'=>
|
||||
[
|
||||
[
|
||||
'id' => 0,
|
||||
'name' => '全部',
|
||||
'count' => $all_count
|
||||
],
|
||||
[
|
||||
'id' => 1,
|
||||
'name' => '有图',
|
||||
'count' => $image_count
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'name' => '好评',
|
||||
'count' => $good_count
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'name' => '中差评',
|
||||
'count' => $medium_bad_count
|
||||
]
|
||||
] ,
|
||||
'percent' => $percentStr,
|
||||
'star' => $star,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
58
server/app/api/logic/StaffLogic.php
Executable file
58
server/app/api/logic/StaffLogic.php
Executable file
@@ -0,0 +1,58 @@
|
||||
<?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\api\logic;
|
||||
|
||||
|
||||
use app\common\enum\DefaultEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\goods\Goods;
|
||||
use app\common\model\staff\Staff;
|
||||
|
||||
class StaffLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 师傅详情
|
||||
* @param $id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author ljj
|
||||
* @date 2022/2/23 6:34 下午
|
||||
*/
|
||||
public function detail($id)
|
||||
{
|
||||
$result = Staff::where(['id'=>$id])
|
||||
->field('id,user_id,name,mobile,goods_ids,province_id,city_id,district_id,address,create_time')
|
||||
->append(['user_image','province','city','district'])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
|
||||
if ($result) {
|
||||
$goods_ids = explode(',',trim($result['goods_ids'],','));
|
||||
$result['goods'] = Goods::where(['id'=>$goods_ids,'status'=>DefaultEnum::SHOW])
|
||||
->field('id,name,unit_id,image,price')
|
||||
->append(['unit_desc'])
|
||||
->select()->toArray();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
122
server/app/api/logic/StaffOrderLogic.php
Executable file
122
server/app/api/logic/StaffOrderLogic.php
Executable file
@@ -0,0 +1,122 @@
|
||||
<?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\api\logic;
|
||||
|
||||
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\OrderLogEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\logic\OrderLogLogic;
|
||||
use app\common\model\order\Order;
|
||||
use think\facade\Db;
|
||||
|
||||
class StaffOrderLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 订单服务详情
|
||||
* @param $id
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2022/3/1 3:24 下午
|
||||
*/
|
||||
public function detail($id)
|
||||
{
|
||||
$result = Order::where('id',$id)
|
||||
->append(['appoint_time','appoint_week','door_time','order_status_desc','pay_way_desc','confirm_service_btn','verification_btn','province','city','district'])
|
||||
->with(['order_goods' => function($query){
|
||||
$query->field('order_id,goods_snap,goods_name,goods_price,goods_num,unit_name')->append(['goods_image'])->hidden(['goods_snap']);
|
||||
},'staff' => function($query){
|
||||
$query->field('id,name,mobile,user_id');
|
||||
}])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 确认服务
|
||||
* @param $id
|
||||
* @return bool
|
||||
* @author ljj
|
||||
* @date 2022/3/1 3:43 下午
|
||||
*/
|
||||
public function confirmService($id)
|
||||
{
|
||||
Order::update(['order_status'=>OrderEnum::ORDER_STATUS_SERVICE],['id'=>$id]);
|
||||
|
||||
$order = Order::where('id',$id)->findOrEmpty()->toArray();
|
||||
|
||||
// 师傅确认服务通知 - 通知买家
|
||||
event('Notice', [
|
||||
'scene_id' => NoticeEnum::STAFF_CONFIRM_ORDER_NOTICE,
|
||||
'params' => [
|
||||
'user_id' => $order['user_id'],
|
||||
'order_id' => $order['id']
|
||||
]
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 订单核销
|
||||
* @param $params
|
||||
* @return Order|bool
|
||||
* @author ljj
|
||||
* @date 2022/3/1 3:59 下午
|
||||
*/
|
||||
public function verification($params)
|
||||
{
|
||||
// 启动事务
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = Order::where('verification_code',$params['verification_code'])->findOrEmpty()->toArray();
|
||||
|
||||
//更新订单状态
|
||||
Order::update([
|
||||
'order_status' => OrderEnum::ORDER_STATUS_FINISH,
|
||||
'verification_status' => OrderEnum::VERIFICATION,
|
||||
'finish_time' => time(),
|
||||
],['id'=>$order['id']]);
|
||||
|
||||
//添加订单日志
|
||||
(new OrderLogLogic())->record(OrderLogEnum::TYPE_USER,OrderLogEnum::USER_VERIFICATION,$order['id'],$params['user_id']);
|
||||
|
||||
// 订单完成通知 - 通知买家
|
||||
event('Notice', [
|
||||
'scene_id' => NoticeEnum::ORDER_FINISH_NOTICE,
|
||||
'params' => [
|
||||
'user_id' => $order['user_id'],
|
||||
'order_id' => $order['id']
|
||||
]
|
||||
]);
|
||||
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
59
server/app/api/logic/SubscribeLogic.php
Executable file
59
server/app/api/logic/SubscribeLogic.php
Executable file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | LikeShop有特色的全开源社交分销电商系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 商业用途务必购买系统授权,以免引起不必要的法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | 微信公众号:好象科技
|
||||
// | 访问官网:http://www.likemarket.net
|
||||
// | 访问社区:http://bbs.likemarket.net
|
||||
// | 访问手册:http://doc.likemarket.net
|
||||
// | 好象科技开发团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: LikeShopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\notice\NoticeSetting;
|
||||
|
||||
/**
|
||||
* 小程序订阅消息
|
||||
*/
|
||||
class SubscribeLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 获取小程序模板ID (取已启用的3条)
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author Tab
|
||||
* @date 2021/10/12 11:56
|
||||
*/
|
||||
public static function lists()
|
||||
{
|
||||
$where = [
|
||||
['mnp_notice', '<>', ''],
|
||||
['type', '=', 1]
|
||||
];
|
||||
$lists = NoticeSetting::where($where)->field('mnp_notice')->select()->toArray();
|
||||
|
||||
$template_id = [];
|
||||
foreach ($lists as $item) {
|
||||
if (isset($item['mnp_notice']['status']) && $item['mnp_notice']['status'] != YesNoEnum::YES) {
|
||||
continue;
|
||||
}
|
||||
$template_id[] = $item['mnp_notice']['template_id'] ?? '';
|
||||
// 限制3条
|
||||
if (count($template_id) == 3) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $template_id;
|
||||
}
|
||||
}
|
||||
204
server/app/api/logic/UserAddressLogic.php
Executable file
204
server/app/api/logic/UserAddressLogic.php
Executable file
@@ -0,0 +1,204 @@
|
||||
<?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\api\logic;
|
||||
|
||||
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\city\City;
|
||||
use app\common\model\coach\Coach;
|
||||
use app\common\model\goods\GoodsCityIndex;
|
||||
use app\common\model\user\UserAddress;
|
||||
use app\common\service\ConfigService;
|
||||
|
||||
class UserAddressLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 地址列表
|
||||
* @param $user_id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author ljj
|
||||
* @date 2022/2/24 10:45 上午
|
||||
*/
|
||||
public function lists($user_id,$params)
|
||||
{
|
||||
$goodsId = $params['goods_id'] ?? '';
|
||||
$coachId = $params['coach_id'] ?? '';
|
||||
$field = 'id,contact,gender,mobile,province_id,city_id,district_id,house_number,address,is_default,0 as distance';
|
||||
if($coachId){
|
||||
$coach = Coach::where(['id'=>$coachId])->findOrEmpty();
|
||||
if(!$coach->isEmpty()){
|
||||
$longitude = $coach['longitude_location'] ?: $coach['longitude'];
|
||||
$latitude = $coach['latitude_location'] ?: $coach['latitude'];
|
||||
$field = 'id,contact,gender,mobile,province_id,city_id,district_id,house_number,address,is_default,round(st_distance_sphere(point('.$longitude.','.$latitude.'),
|
||||
point(longitude, latitude))/1000,2) as distance';
|
||||
}
|
||||
}
|
||||
$lists = UserAddress::field($field)
|
||||
->order(['is_default'=>'desc','id'=>'desc'])
|
||||
->append(['province','city','district','gender_desc'])
|
||||
->where(['user_id'=>$user_id])
|
||||
->select()
|
||||
->toArray();
|
||||
$userAddressLists = [
|
||||
'usable' => [],
|
||||
'distance_disable' => [],
|
||||
'server_disable' => [],
|
||||
];
|
||||
$coachServerScope = ConfigService::get('server_setting', 'coach_server_scope');
|
||||
if($goodsId){
|
||||
$cityLists = GoodsCityIndex::where(['goods_id'=>$goodsId])->column('city_id');
|
||||
if(empty($cityLists)){
|
||||
$cityLists = true;
|
||||
}
|
||||
}else{
|
||||
$cityLists = City::column('city_id');
|
||||
}
|
||||
foreach ($lists as $userAddress){
|
||||
if($goodsId){
|
||||
if(true === $cityLists){
|
||||
$userAddressLists['usable'][] = $userAddress;
|
||||
continue;
|
||||
}
|
||||
if(!in_array($userAddress['city_id'],$cityLists)){
|
||||
$userAddressLists['server_disable'][] = $userAddress;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if($coachId && !$coach->isEmpty() && $coachServerScope < $userAddress['distance']){
|
||||
$userAddressLists['distance_disable'][] = $userAddress;
|
||||
continue;
|
||||
}
|
||||
|
||||
$userAddressLists['usable'][] = $userAddress;
|
||||
}
|
||||
return $userAddressLists;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 添加地址
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author ljj
|
||||
* @date 2022/2/24 10:51 上午
|
||||
*/
|
||||
public function add($params)
|
||||
{
|
||||
if (isset($params['is_default']) && $params['is_default'] == YesNoEnum::YES) {
|
||||
UserAddress::where(['user_id' => $params['user_id']])->update(['is_default' => YesNoEnum::NO]);
|
||||
} else {
|
||||
$isFirst = UserAddress::where(['user_id' => $params['user_id']])->findOrEmpty();
|
||||
if ($isFirst->isEmpty()) {
|
||||
$params['is_default'] = YesNoEnum::YES;
|
||||
}
|
||||
}
|
||||
|
||||
UserAddress::create([
|
||||
'user_id' => $params['user_id'],
|
||||
'contact' => $params['contact'],
|
||||
'mobile' => $params['mobile'],
|
||||
'gender' => $params['gender'] ?? 1,
|
||||
'province_id' => $params['province_id'],
|
||||
'city_id' => $params['city_id'],
|
||||
'district_id' => $params['district_id'],
|
||||
'address' => $params['address'] ?? '',
|
||||
'longitude' => $params['longitude'],
|
||||
'latitude' => $params['latitude'],
|
||||
'house_number'=> $params['house_number'],
|
||||
'is_default' => $params['is_default'] ?? 0,
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 地址详情
|
||||
* @param $id
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2022/2/24 11:55 上午
|
||||
*/
|
||||
public function detail($id)
|
||||
{
|
||||
return UserAddress::where(['id'=>$id])->append(['province','city','district','gender_desc'])->findOrEmpty()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑地址
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author ljj
|
||||
* @date 2022/2/24 11:59 上午
|
||||
*/
|
||||
public function edit($params)
|
||||
{
|
||||
if (isset($params['is_default']) && $params['is_default'] == YesNoEnum::YES) {
|
||||
UserAddress::where(['user_id' => $params['user_id']])->update(['is_default' => YesNoEnum::NO]);
|
||||
}
|
||||
|
||||
UserAddress::update([
|
||||
'contact' => $params['contact'],
|
||||
'mobile' => $params['mobile'],
|
||||
'gender' => $params['gender'] ?? 1,
|
||||
'province_id' => $params['province_id'],
|
||||
'city_id' => $params['city_id'],
|
||||
'district_id' => $params['district_id'],
|
||||
'address' => $params['address'] ?? '',
|
||||
'longitude' => $params['longitude'] ?? 0,
|
||||
'latitude' => $params['latitude'] ?? 0,
|
||||
'is_default' => $params['is_default'] ?? 0,
|
||||
'house_number'=> $params['house_number'],
|
||||
],['id'=>$params['id'],'user_id'=>$params['user_id']]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 设置默认地址
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author ljj
|
||||
* @date 2022/2/24 12:08 下午
|
||||
*/
|
||||
public function setDefault($params)
|
||||
{
|
||||
UserAddress::where(['user_id' => $params['user_id']])->update(['is_default' => YesNoEnum::NO]);
|
||||
|
||||
UserAddress::update(['is_default' => YesNoEnum::YES],['id'=>$params['id'],'user_id'=>$params['user_id']]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除地址
|
||||
* @param $id
|
||||
* @return bool
|
||||
* @author ljj
|
||||
* @date 2022/2/24 2:35 下午
|
||||
*/
|
||||
public function del($id)
|
||||
{
|
||||
UserAddress::destroy($id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
392
server/app/api/logic/UserLogic.php
Executable file
392
server/app/api/logic/UserLogic.php
Executable file
@@ -0,0 +1,392 @@
|
||||
<?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\api\logic;
|
||||
|
||||
|
||||
use app\api\service\WechatUserService;
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\user\UserTerminalEnum;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\coach\Collect;
|
||||
use app\common\model\decorate\DecoratePage;
|
||||
use app\common\model\goods\Goods;
|
||||
use app\common\model\goods\GoodsComment;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\user\UserAuth;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\sms\SmsDriver;
|
||||
use app\common\service\WeChatConfigService;
|
||||
use app\common\service\WeChatService;
|
||||
use EasyWeChat\Factory;
|
||||
use think\facade\Config;
|
||||
|
||||
class UserLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 用户中心
|
||||
* @param $userInfo
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2022/2/23 5:24 下午
|
||||
*/
|
||||
public function center($userInfo)
|
||||
{
|
||||
$userId = $userInfo['user_id'] ?? 0;
|
||||
$terminal = $userInfo['terminal'] ?? 0;
|
||||
$user = User::where(['id'=>$userId])
|
||||
->field('id,sn,nickname,account,avatar,user_money,mobile,sex,create_time,is_new_user')
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
//支付是否需要授权
|
||||
$user['pay_auth'] = 1;
|
||||
if (in_array($terminal, [UserTerminalEnum::WECHAT_MMP, UserTerminalEnum::WECHAT_OA])) {
|
||||
$auth = self::hasWechatAuth($userId);
|
||||
$user['pay_auth'] = $auth ? YesNoEnum::YES : YesNoEnum::NO;
|
||||
}
|
||||
$user['collect_coach_num'] = Collect::where(['type'=>1,'user_id'=>$userId])->count();
|
||||
$user['collect_goods_num'] = Collect::where(['type'=>2,'user_id'=>$userId])->count();
|
||||
$user['collect_shop_num'] = Collect::where(['type'=>3,'user_id'=>$userId])->count();
|
||||
$user['goods_comment_num'] = GoodsComment::where(['user_id'=>$userId])->count();
|
||||
$user['wait_comment_num'] = Order::alias('O')
|
||||
->join('order_goods OG','O.id = OG.order_id')
|
||||
->where(['user_id'=>$userId,'order_status'=>OrderEnum::ORDER_STATUS_SERVER_FINISH,'is_comment'=>0])
|
||||
->count();
|
||||
|
||||
$user['waitpay_order_num'] = Order::where(['user_id'=>$userId,'order_status'=>OrderEnum::ORDER_STATUS_WAIT_PAY])->count();
|
||||
$user['appoint_order_num'] = Order::where(['user_id'=>$userId,'order_status'=>OrderEnum::ORDER_STATUS_WAIT_RECEIVING])->count();
|
||||
$user['server_order_num'] = Order::where(['user_id'=>$userId,'order_status'=>OrderEnum::ORDER_STATUS_START_SERVER])->count();
|
||||
$user['complete_order_num'] = Order::where(['user_id'=>$userId,'order_status'=>OrderEnum::ORDER_STATUS_SERVER_FINISH])->count();
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 客服配置
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2022/2/24 2:53 下午
|
||||
*/
|
||||
public function customerService()
|
||||
{
|
||||
// $qrCode = ConfigService::get('customer_service', 'qr_code');
|
||||
// $qrCode = empty($qrCode) ? '' : FileService::getFileUrl($qrCode);
|
||||
// $config = [
|
||||
// 'qr_code' => $qrCode,
|
||||
// 'wechat' => ConfigService::get('customer_service', 'wechat', ''),
|
||||
// 'phone' => ConfigService::get('customer_service', 'phone', ''),
|
||||
// 'service_time' => ConfigService::get('customer_service', 'service_time', ''),
|
||||
// ];
|
||||
|
||||
// 装修配置
|
||||
$decoratePage = DecoratePage::where('id',3)->json(['data'],true)->value('data');
|
||||
|
||||
return $decoratePage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 用户收藏列表
|
||||
* @param $user_id
|
||||
* @return mixed
|
||||
* @author ljj
|
||||
* @date 2022/2/24 3:07 下午
|
||||
*/
|
||||
public function collectLists($user_id)
|
||||
{
|
||||
$lists = Goods::alias('g')
|
||||
->join('goods_collect gc', 'g.id = gc.goods_id')
|
||||
->field('gc.goods_id,g.image,g.name,g.price,g.unit_id,g.status')
|
||||
->append(['unit_desc'])
|
||||
->where(['gc.user_id'=>$user_id])
|
||||
->order('gc.id','desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $lists;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 用户信息
|
||||
* @param $userId
|
||||
* @return array|bool
|
||||
* @author ljj
|
||||
* @date 2022/3/7 5:52 下午
|
||||
*/
|
||||
public static function info($user_id,$code = '')
|
||||
{
|
||||
try {
|
||||
$user = User::where(['id'=>$user_id])
|
||||
->field('id,sn,sex,account,password,nickname,real_name,avatar,mobile,create_time')
|
||||
->findOrEmpty();
|
||||
$user['has_password'] = !empty($user['password']);
|
||||
$user['has_auth'] = self::hasWechatAuth($user_id);
|
||||
$user['version'] = config('project.version');
|
||||
$user['wx_nickname'] = $user['nickname'];
|
||||
if('' != $code){
|
||||
$params['code'] = $code;
|
||||
$response = WeChatService::getOaResByCode($params);
|
||||
$user['wx_nickname'] = $response['nickname'] ?? '';
|
||||
}
|
||||
$user->hidden(['password']);
|
||||
return $user->toArray();
|
||||
}catch (\Exception $e){
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 设置用户信息
|
||||
* @param int $userId
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author ljj
|
||||
* @date 2022/2/24 3:44 下午
|
||||
*/
|
||||
public static function setInfo(int $userId,array $params):bool
|
||||
{
|
||||
User::update(['id'=>$userId,$params['field']=>$params['value']]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取微信手机号并绑定
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author ljj
|
||||
* @date 2022/2/24 4:41 下午
|
||||
*/
|
||||
public static function getMobileByMnp(array $params)
|
||||
{
|
||||
try {
|
||||
$getMnpConfig = WeChatConfigService::getMnpConfig();
|
||||
$app = Factory::miniProgram($getMnpConfig);
|
||||
$response = $app->phone_number->getUserPhoneNumber($params['code']);
|
||||
|
||||
$phoneNumber = $response['phone_info']['purePhoneNumber'] ?? '';
|
||||
if (empty($phoneNumber)) {
|
||||
throw new \Exception('获取手机号码失败');
|
||||
}
|
||||
|
||||
$user = User::where([
|
||||
['mobile', '=', $phoneNumber],
|
||||
['id', '<>', $params['user_id']]
|
||||
])->findOrEmpty();
|
||||
|
||||
if (!$user->isEmpty()) {
|
||||
throw new \Exception('手机号已被其他账号绑定');
|
||||
}
|
||||
|
||||
// 绑定手机号
|
||||
User::update([
|
||||
'id' => $params['user_id'],
|
||||
'mobile' => $phoneNumber
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 重置登录密码
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 18:06
|
||||
*/
|
||||
public static function resetPassword(array $params)
|
||||
{
|
||||
try {
|
||||
// 校验验证码
|
||||
$smsDriver = new SmsDriver();
|
||||
if (!$smsDriver->verify($params['mobile'], $params['code'], NoticeEnum::RESET_PASSWORD_CAPTCHA)) {
|
||||
throw new \Exception('验证码错误');
|
||||
}
|
||||
|
||||
// 重置密码
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
$password = create_password($params['password'], $passwordSalt);
|
||||
|
||||
// 更新
|
||||
User::where('account', $params['mobile'])->update([
|
||||
'password' => $password
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 设置登录密码
|
||||
* @author Tab
|
||||
* @date 2021/10/22 18:10
|
||||
*/
|
||||
public static function setPassword($params)
|
||||
{
|
||||
try {
|
||||
$user = User::findOrEmpty($params['user_id']);
|
||||
if ($user->isEmpty()) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
if (!empty($user->password)) {
|
||||
throw new \Exception('用户已设置登录密码');
|
||||
}
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
$password = create_password($params['password'], $passwordSalt);
|
||||
$user->password = $password;
|
||||
$user->save();
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 修稿密码
|
||||
* @param $params
|
||||
* @param $userId
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:13
|
||||
*/
|
||||
public static function changePassword(array $params, int $userId)
|
||||
{
|
||||
try {
|
||||
$user = User::findOrEmpty($userId);
|
||||
if ($user->isEmpty()) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
|
||||
// 密码盐
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
|
||||
if (!empty($user['password'])) {
|
||||
if (empty($params['old_password'])) {
|
||||
throw new \Exception('请填写旧密码');
|
||||
}
|
||||
$oldPassword = create_password($params['old_password'], $passwordSalt);
|
||||
if ($oldPassword != $user['password']) {
|
||||
throw new \Exception('原密码不正确');
|
||||
}
|
||||
}
|
||||
|
||||
// 保存密码
|
||||
$password = create_password($params['password'], $passwordSalt);
|
||||
$user->password = $password;
|
||||
$user->save();
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 判断用户是否有设置登录密码
|
||||
* @param $userId
|
||||
* @author Tab
|
||||
* @date 2021/10/22 18:25
|
||||
*/
|
||||
public static function hasPassword($userId)
|
||||
{
|
||||
$user = User::findOrEmpty($userId);
|
||||
return empty($user->password) ? false : true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 绑定手机号
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author Tab
|
||||
* @date 2021/8/25 17:55
|
||||
*/
|
||||
public static function bindMobile($params)
|
||||
{
|
||||
try {
|
||||
$smsDriver = new SmsDriver();
|
||||
$result = $smsDriver->verify($params['mobile'], $params['code']);
|
||||
if(!$result) {
|
||||
throw new \Exception('验证码错误');
|
||||
}
|
||||
$user = User::where('mobile', $params['mobile'])->findOrEmpty();
|
||||
if(!$user->isEmpty()) {
|
||||
throw new \Exception('该手机号已被其他账号绑定');
|
||||
}
|
||||
unset($params['code']);
|
||||
User::update($params);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 是否有微信授权信息
|
||||
* @param $userId
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:36
|
||||
*/
|
||||
public static function hasWechatAuth(int $userId)
|
||||
{
|
||||
//是否有微信授权登录
|
||||
$terminal = [UserTerminalEnum::WECHAT_MMP, UserTerminalEnum::WECHAT_OA];
|
||||
$auth = UserAuth::where(['user_id' => $userId])
|
||||
->whereIn('terminal', $terminal)
|
||||
->findOrEmpty();
|
||||
return !$auth->isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 我的钱包
|
||||
* @param int $userId
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2022/12/12 9:35 上午
|
||||
*/
|
||||
public static function wallet(int $userId): array
|
||||
{
|
||||
$result = User::where(['id' => $userId])
|
||||
->field('id,user_money,user_earnings')
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
$result['total_money'] = round($result['user_money'] + $result['user_earnings'],2);
|
||||
$result['recharge_open'] = ConfigService::get('recharge', 'recharge_open',1);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
78
server/app/api/logic/WechatLogic.php
Executable file
78
server/app/api/logic/WechatLogic.php
Executable file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | LikeShop有特色的全开源社交分销电商系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 商业用途务必购买系统授权,以免引起不必要的法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | 微信公众号:好象科技
|
||||
// | 访问官网:http://www.likemarket.net
|
||||
// | 访问社区:http://bbs.likemarket.net
|
||||
// | 访问手册:http://doc.likemarket.net
|
||||
// | 好象科技开发团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: LikeShopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\WeChatConfigService;
|
||||
use EasyWeChat\Factory;
|
||||
use EasyWeChat\Kernel\Exceptions\Exception;
|
||||
|
||||
/**
|
||||
* 微信逻辑层
|
||||
* Class WechatLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class WechatLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 微信JSSDK授权接口
|
||||
* @param $params
|
||||
* @return array|false|string
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
* @author Tab
|
||||
* @date 2021/8/30 19:20
|
||||
*/
|
||||
public static function jsConfig($params)
|
||||
{
|
||||
try {
|
||||
// $config = [
|
||||
// 'app_id' => ConfigService::get('official_account','app_id'),
|
||||
// 'secret' => ConfigService::get('official_account','app_secret')
|
||||
// ];
|
||||
$config = WeChatConfigService::getOaConfig();
|
||||
$app = Factory::officialAccount($config);
|
||||
$url = urldecode($params['url']);
|
||||
$app->jssdk->setUrl($url);
|
||||
$apis = [
|
||||
'onMenuShareTimeline',
|
||||
'onMenuShareAppMessage',
|
||||
'onMenuShareQQ',
|
||||
'onMenuShareWeibo',
|
||||
'onMenuShareQZone',
|
||||
'openLocation',
|
||||
'getLocation',
|
||||
'chooseWXPay',
|
||||
'updateAppMessageShareData',
|
||||
'updateTimelineShareData',
|
||||
'openAddress',
|
||||
'scanQRCode'
|
||||
];
|
||||
|
||||
$data = $app->jssdk->getConfigArray($apis, $debug = false, $beta = false);
|
||||
|
||||
return $data;
|
||||
} catch (Exception |\think\Exception $e) {
|
||||
|
||||
self::setError('公众号配置出错:' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user