初始版本
This commit is contained in:
308
server/app/shopapi/logic/CityLogic.php
Executable file
308
server/app/shopapi/logic/CityLogic.php
Executable file
@@ -0,0 +1,308 @@
|
||||
<?php
|
||||
namespace app\shopapi\logic;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\city\City;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\TencentMapKeyService;
|
||||
use Exception;
|
||||
|
||||
class CityLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 地级市列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author ljj
|
||||
* @date 2022/4/6 2:41 下午
|
||||
*/
|
||||
public function city($params)
|
||||
{
|
||||
$where = [];
|
||||
$where[] = ['level','=',2];
|
||||
if(isset($params['keyword']) && $params['keyword']){
|
||||
$where[] = ['name','like','%'.$params['keyword'].'%'];
|
||||
}
|
||||
$lists = City::where($where)
|
||||
->field('id,parent_id,level,name,gcj02_lng,gcj02_lat,db09_lng,db09_lat')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$lists = self::groupByInitials($lists);
|
||||
unset($lists[null]);
|
||||
|
||||
return $lists;
|
||||
}
|
||||
|
||||
/*
|
||||
* 二维数组根据首字母分组排序
|
||||
* @param array $data 二维数组
|
||||
* @param string $targetKey 首字母的键名
|
||||
* @return array 根据首字母关联的二维数组
|
||||
*/
|
||||
public function groupByInitials(array $data, $targetKey = 'name')
|
||||
{
|
||||
$data = array_map(function ($item) use ($targetKey) {
|
||||
return array_merge($item, [
|
||||
'initials' => $this->getInitials($item[$targetKey]),
|
||||
]);
|
||||
}, $data);
|
||||
$data = $this->sortInitials($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按字母排序
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function sortInitials(array $data)
|
||||
{
|
||||
$sortData = [];
|
||||
foreach ($data as $key => $value) {
|
||||
$sortData[$value['initials']][] = $value;
|
||||
}
|
||||
ksort($sortData);
|
||||
return $sortData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取首字母
|
||||
* @param string $str 汉字字符串
|
||||
* @return string 首字母
|
||||
*/
|
||||
public function getInitials($str)
|
||||
{
|
||||
if (empty($str)) {return '';}
|
||||
$fchar = ord($str[0]);
|
||||
if ($fchar >= ord('A') && $fchar <= ord('z')) {
|
||||
return strtoupper($str[0]);
|
||||
}
|
||||
|
||||
$s1 = iconv('UTF-8', 'GBK', $str);
|
||||
$s2 = iconv('GBK', 'UTF-8', $s1);
|
||||
$s = $s2 == $str ? $s1 : $str;
|
||||
$asc = ord($s[0]) * 256 + ord($s[1]) - 65536;
|
||||
if ($asc >= -20319 && $asc <= -20284) {
|
||||
return 'A';
|
||||
}
|
||||
if ($asc >= -20283 && $asc <= -19776) {
|
||||
return 'B';
|
||||
}
|
||||
if ($asc >= -19775 && $asc <= -19219) {
|
||||
return 'C';
|
||||
}
|
||||
if ($asc >= -19218 && $asc <= -18711) {
|
||||
return 'D';
|
||||
}
|
||||
if ($asc >= -18710 && $asc <= -18527) {
|
||||
return 'E';
|
||||
}
|
||||
if ($asc >= -18526 && $asc <= -18240) {
|
||||
return 'F';
|
||||
}
|
||||
if ($asc >= -18239 && $asc <= -17923) {
|
||||
return 'G';
|
||||
}
|
||||
if ($asc >= -17922 && $asc <= -17418) {
|
||||
return 'H';
|
||||
}
|
||||
if ($asc >= -17417 && $asc <= -16475) {
|
||||
return 'J';
|
||||
}
|
||||
if ($asc >= -16474 && $asc <= -16213) {
|
||||
return 'K';
|
||||
}
|
||||
if ($asc >= -16212 && $asc <= -15641) {
|
||||
return 'L';
|
||||
}
|
||||
if ($asc >= -15640 && $asc <= -15166) {
|
||||
return 'M';
|
||||
}
|
||||
if ($asc >= -15165 && $asc <= -14923) {
|
||||
return 'N';
|
||||
}
|
||||
if ($asc >= -14922 && $asc <= -14915) {
|
||||
return 'O';
|
||||
}
|
||||
if ($asc >= -14914 && $asc <= -14631) {
|
||||
return 'P';
|
||||
}
|
||||
if ($asc >= -14630 && $asc <= -14150) {
|
||||
return 'Q';
|
||||
}
|
||||
if ($asc >= -14149 && $asc <= -14091) {
|
||||
return 'R';
|
||||
}
|
||||
if ($asc >= -14090 && $asc <= -13319) {
|
||||
return 'S';
|
||||
}
|
||||
if ($asc >= -13318 && $asc <= -12839) {
|
||||
return 'T';
|
||||
}
|
||||
if ($asc >= -12838 && $asc <= -12557) {
|
||||
return 'W';
|
||||
}
|
||||
if ($asc >= -12556 && $asc <= -11848) {
|
||||
return 'X';
|
||||
}
|
||||
if ($asc >= -11847 && $asc <= -11056) {
|
||||
return 'Y';
|
||||
}
|
||||
if ($asc >= -11055 && $asc <= -10247) {
|
||||
return 'Z';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @notes 城市列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author cjhao
|
||||
* @date 2024/11/6 10:55
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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 = \app\common\logic\CityLogic::getNearbyCity($longitude,$latitude);
|
||||
return $cityLists[0] ?? [];
|
||||
|
||||
}catch (Exception $e){
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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|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;
|
||||
}
|
||||
}
|
||||
254
server/app/shopapi/logic/CoachLogic.php
Executable file
254
server/app/shopapi/logic/CoachLogic.php
Executable file
@@ -0,0 +1,254 @@
|
||||
<?php
|
||||
namespace app\shopapi\logic;
|
||||
use app\common\enum\coach\CoachEnum;
|
||||
use app\common\enum\GoodsEnum;
|
||||
use app\common\enum\shop\ShopEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\coach\Coach;
|
||||
use app\common\model\coach\CoachGoodsIndex;
|
||||
use app\common\model\coach\CoachServerTime;
|
||||
use app\common\model\deposit\DepositPackage;
|
||||
use app\common\model\goods\Goods;
|
||||
use app\common\model\shop\Shop;
|
||||
use app\common\model\shop\ShopCoachApply;
|
||||
use app\common\service\ConfigService;
|
||||
use think\Exception;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 技师逻辑类
|
||||
* Class CoachLogic
|
||||
* @package app\shopapi\logic
|
||||
*/
|
||||
class CoachLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 获取技师信息
|
||||
* @param $id
|
||||
* @return array|false
|
||||
* @author cjhao
|
||||
* @date 2024/12/8 22:26
|
||||
*/
|
||||
public function info($id,$shopId)
|
||||
{
|
||||
try {
|
||||
if(empty($id)){
|
||||
throw new Exception('请选择技师');
|
||||
}
|
||||
$coach = Coach::where(['id'=>$id,'shop_id'=>$shopId])
|
||||
->field('id,sn,mobile,name,work_photo,work_status,gender,age,shop_id')
|
||||
->findOrEmpty()->toArray();
|
||||
|
||||
return $coach;
|
||||
}catch (Exception $e){
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 申请详情
|
||||
* @param int $id
|
||||
* @return false
|
||||
* @author cjhao
|
||||
* @date 2024/10/16 02:10
|
||||
*/
|
||||
public function applyDetail(int $id)
|
||||
{
|
||||
try {
|
||||
$shopCoachApply = ShopCoachApply::where(['id'=>$id])->findOrEmpty();
|
||||
if($shopCoachApply->isEmpty()){
|
||||
throw new Exception('记录不存在');
|
||||
}
|
||||
$coach = Coach::alias('C')
|
||||
->join('skill S','C.skill_id = S.id')
|
||||
->where(['C.id'=>$shopCoachApply['coach_id']])
|
||||
->field('C.id,C.name,mobile,work_photo,order_num,good_comment,S.name as skill_name,C.audit_status,introduction')
|
||||
->findOrEmpty()->toArray();
|
||||
$coach['good_comment'] = $coach['good_comment'].'%';
|
||||
return $coach;
|
||||
}catch (Exception $e){
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 门店申请审核
|
||||
* @param array $params
|
||||
* @return string|true
|
||||
* @author cjhao
|
||||
* @date 2024/10/16 01:59
|
||||
*/
|
||||
public function applyAudit(array $params)
|
||||
{
|
||||
|
||||
try {
|
||||
$id = $params['id'] ?? '';
|
||||
$auditStatus = $params['audit_status'] ?? '';
|
||||
$auditRemark = $params['audit_remark'] ?? '';
|
||||
if(empty($id)){
|
||||
throw new Exception('请选择审核记录');
|
||||
}
|
||||
if(empty($auditStatus)){
|
||||
throw new Exception('请选择审核状态');
|
||||
}
|
||||
Db::startTrans();
|
||||
$shopCoachApply = ShopCoachApply::where(['id'=>$params['id']])
|
||||
->findOrEmpty();
|
||||
if($shopCoachApply->isEmpty()){
|
||||
throw new Exception('记录不存在');
|
||||
}
|
||||
if(ShopEnum::AUDIT_STATUS_WAIT != $shopCoachApply->audit_status){
|
||||
throw new Exception('当前记录状态已改变');
|
||||
}
|
||||
$shopCoachApply->audit_status = $auditStatus;
|
||||
$shopCoachApply->audit_remark = $auditRemark;
|
||||
$shopCoachApply->save();
|
||||
|
||||
if(ShopEnum::AUDIT_STATUS_PASS == $shopCoachApply->audit_status){
|
||||
if(1 == $shopCoachApply['type']){
|
||||
$deposit = Shop::where(['id'=>$params['shop_id'],'audit_status'=>ShopEnum::AUDIT_STATUS_PASS])->value('deposit');
|
||||
$depositPackageLists = DepositPackage::where(['type'=>2])->order('money desc')->select()->toArray();
|
||||
//套餐列表
|
||||
$coachNum = ConfigService::get('server_setting', 'shop_coach_limit');
|
||||
foreach ($depositPackageLists as $depositPackage){
|
||||
if($deposit >= $depositPackage['money']){
|
||||
$coachNum = $depositPackage['coach_num'];
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
$nowCoachNum = Coach::where(['shop_id'=>$params['shop_id'],'audit_status'=>CoachEnum::AUDIT_STATUS_PASS])->count();
|
||||
if($nowCoachNum >= $coachNum){
|
||||
throw new Exception('服务人员已达到上限');
|
||||
}
|
||||
|
||||
Coach::where(['id'=>$shopCoachApply['coach_id']])->update([
|
||||
'shop_id' => $shopCoachApply['shop_id']
|
||||
]);
|
||||
}else{
|
||||
//退出申请
|
||||
Coach::where(['id'=>$shopCoachApply['coach_id']])->update([
|
||||
'shop_id' => 0
|
||||
]);
|
||||
//清理技师管理的商家项目
|
||||
$goodsIds = Goods::where(['shop_id'=>$shopCoachApply['shop_id'],'audit_status'=>GoodsEnum::AUDIT_STATUS_PASS])
|
||||
->column('id');
|
||||
if($goodsIds){
|
||||
CoachGoodsIndex::where(['coach_id'=>$shopCoachApply['coach_id'],'goods_id'=>$goodsIds])->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
}catch (Exception $e){
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取师傅服务
|
||||
* @param $id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author cjhao
|
||||
* @date 2024/10/21 00:25
|
||||
*/
|
||||
public function getServerTime($id)
|
||||
{
|
||||
try {
|
||||
if(empty($id)){
|
||||
throw new Exception('请选择技师');
|
||||
}
|
||||
$advanceAppoint = ConfigService::get('server_setting', 'advance_appoint');
|
||||
$timestampLists[date('m-d',time())] = time()+60*60;
|
||||
//现在的时间戳和明天,后天零点的时间戳
|
||||
for ($i = 1;$i < $advanceAppoint;$i++){
|
||||
$timestampLists[date('m-d',strtotime('+ '.$i.' days'))] = strtotime('+ '.$i.' days midnight');
|
||||
}
|
||||
$intervalsLists = [];
|
||||
foreach ($timestampLists as $date => $timestamp){
|
||||
$intervalsLists[$date] = get_hour_to_midnight($timestamp);
|
||||
}
|
||||
//订单预约时间
|
||||
$orderAppointLists = \app\common\logic\CoachLogic::getCoachOrderAppoint($id);
|
||||
//师傅空闲时间
|
||||
$serverTimeLists = [];
|
||||
//师傅忙碌时间
|
||||
$serverTimeBusyLists = [];
|
||||
$coachServerTime = CoachServerTime::where(['coach_id'=>$id])
|
||||
->field('date,time,status')
|
||||
->select();
|
||||
foreach ($coachServerTime as $time)
|
||||
{
|
||||
if(1 == $time['status']){
|
||||
$serverTimeLists[$time['date']][] = $time['time'];
|
||||
}else{
|
||||
$serverTimeBusyLists[$time['date']][] = $time['time'];
|
||||
}
|
||||
}
|
||||
// 获取当前日期的时间戳
|
||||
$currentDate = strtotime(date('Y-m-d'));
|
||||
// 获取明天和后天的时间戳
|
||||
$tomorrowDate = strtotime('tomorrow');
|
||||
$afterTomorrowDate = strtotime('+2 days',$currentDate);
|
||||
|
||||
foreach ($intervalsLists as $date => $intervals){
|
||||
$timeTips = '';
|
||||
$timestamp = strtotime(date('Y-'.$date));
|
||||
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];
|
||||
}
|
||||
foreach ($intervals as $key => $interval){
|
||||
$orderAppoint = $orderAppointLists[$date] ?? [];
|
||||
$serverTime = $serverTimeLists[$date] ?? [];
|
||||
$serverTimeBusy = $serverTimeBusyLists[$date]?? [];
|
||||
// $intervalsLists[$date][$key]['status'] = 0;
|
||||
//空闲时间
|
||||
if(in_array($interval['time'],$serverTime) || empty($serverTime)){
|
||||
$intervals[$key]['status'] = 1;
|
||||
}
|
||||
//忙
|
||||
if(in_array($interval['time'],$serverTimeBusy)){
|
||||
$intervals[$key]['status'] = 2;
|
||||
}
|
||||
//已预约
|
||||
if(in_array($interval['time'],$orderAppoint)){
|
||||
$intervals[$key]['status'] = 3;
|
||||
}
|
||||
}
|
||||
$timeLists[] = [
|
||||
'time_date' => $date,
|
||||
'time_tips' => $timeTips,
|
||||
'time_lists' => $intervals
|
||||
];
|
||||
}
|
||||
return $timeLists;
|
||||
}catch (\think\Exception $e){
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
151
server/app/shopapi/logic/ConfigLogic.php
Executable file
151
server/app/shopapi/logic/ConfigLogic.php
Executable file
@@ -0,0 +1,151 @@
|
||||
<?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\shopapi\logic;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
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',''),
|
||||
//名称
|
||||
'name' => ConfigService::get('shop', 'name',''),
|
||||
//logo
|
||||
'logo' => FileService::getFileUrl(ConfigService::get('shop', 'logo','')),
|
||||
//版本号
|
||||
'version' => request()->header('version'),
|
||||
//默认头像
|
||||
'default_avatar' => ConfigService::get('config', 'default_shop_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().'/',
|
||||
|
||||
//网站名称
|
||||
'web_name' => ConfigService::get('platform_logo', 'platform_name',''),
|
||||
//网站logo
|
||||
'web_logo' => FileService::getFileUrl(ConfigService::get('platform_logo', 'platform_logo')),
|
||||
//商城名称
|
||||
'shop_name' => ConfigService::get('shop', 'shop_name',''),
|
||||
//商城logo
|
||||
'shop_logo' => FileService::getFileUrl(ConfigService::get('shop', 'shop_logo','')),
|
||||
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 政策协议
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2022/2/23 11:42 上午
|
||||
*/
|
||||
public function agreement()
|
||||
{
|
||||
$service = TextList::where(['id'=>5])->field('title,content')->findOrEmpty();
|
||||
$privacy = TextList::where(['id'=>6])->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' => '',
|
||||
'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;
|
||||
}
|
||||
}
|
||||
53
server/app/shopapi/logic/DecorateLogic.php
Executable file
53
server/app/shopapi/logic/DecorateLogic.php
Executable file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace app\shopapi\logic;
|
||||
use app\common\model\decorate\DecoratePage;
|
||||
use app\common\model\decorate\DecorateStyle;
|
||||
use app\common\model\decorate\DecorateTabbar;
|
||||
|
||||
/**
|
||||
* 装修逻辑类
|
||||
* Class DecorateLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class DecorateLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取装修页面
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @author cjhao
|
||||
* @date 2024/10/8 15:11
|
||||
*/
|
||||
public function page(int $type)
|
||||
{
|
||||
$detail = DecoratePage::where(['type'=>$type,'source'=>3])->findOrEmpty()->toArray();
|
||||
return $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取装修风格
|
||||
* @return array
|
||||
* @author cjhao
|
||||
* @date 2024/10/8 15:13
|
||||
*/
|
||||
public function style()
|
||||
{
|
||||
$detail = DecorateStyle::where(['source'=>3])->findOrEmpty()->toArray();
|
||||
return $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 底部菜单
|
||||
* @return array
|
||||
* @author cjhao
|
||||
* @date 2024/10/8 15:59
|
||||
*/
|
||||
public function tabbar()
|
||||
{
|
||||
$detail = DecorateTabbar::where(['source'=>3])->findOrEmpty()->toArray();
|
||||
return $detail;
|
||||
}
|
||||
|
||||
}
|
||||
80
server/app/shopapi/logic/DepositLogic.php
Executable file
80
server/app/shopapi/logic/DepositLogic.php
Executable file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
namespace app\shopapi\logic;
|
||||
use app\common\enum\shop\ShopEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\deposit\DepositOrder;
|
||||
use app\common\model\deposit\DepositPackage;
|
||||
use app\common\model\shop\Shop;
|
||||
use think\Exception;
|
||||
|
||||
/**
|
||||
* 保证金套餐逻辑类
|
||||
* Class DepositLogic
|
||||
* @package app\coachapi\logic
|
||||
*/
|
||||
class DepositLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 套餐列表
|
||||
* @param $coachId
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author cjhao
|
||||
* @date 2024/8/27 18:25
|
||||
*/
|
||||
public function depositPackage($shopUserId)
|
||||
{
|
||||
$deposit = Shop::where(['shop_user_id'=>$shopUserId,'audit_status'=>ShopEnum::AUDIT_STATUS_PASS])->value('deposit');
|
||||
$packageLists = DepositPackage::where(['type'=>2])
|
||||
->withoutField('is_show,create_time,update_time,delete_time')
|
||||
->order('id desc')
|
||||
->select();
|
||||
return [
|
||||
'deposit' => $deposit,
|
||||
'package_list' => $packageLists,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 提交订单
|
||||
* @param array $params
|
||||
* @param int $shopId
|
||||
* @return array|bool
|
||||
* @author cjhao
|
||||
* @date 2024/8/27 18:52
|
||||
*/
|
||||
public function sumbitOrder(array $params,int $shopId)
|
||||
{
|
||||
try {
|
||||
$money = $params['money'] ?? 0;
|
||||
$payWay = $params['pay_way'] ?? 0;
|
||||
|
||||
if($money < 0){
|
||||
throw new Exception('充值金额不能小于零');
|
||||
}
|
||||
if(empty($payWay)){
|
||||
throw new Exception('请选择支付方式');
|
||||
}
|
||||
$depositOrder = DepositOrder::create([
|
||||
'sn' => generate_sn((new DepositOrder()), 'sn'),
|
||||
'type' => 2,
|
||||
'order_amount' => $money,
|
||||
'relation_id' => $shopId,
|
||||
'pay_way' => $payWay,
|
||||
]);
|
||||
return [
|
||||
'id' => $depositOrder->id,
|
||||
'sn' => $depositOrder->sn,
|
||||
'type' => 'deposit'
|
||||
];
|
||||
|
||||
}catch (Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
108
server/app/shopapi/logic/GoodsCommentLogic.php
Executable file
108
server/app/shopapi/logic/GoodsCommentLogic.php
Executable file
@@ -0,0 +1,108 @@
|
||||
<?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\shopapi\logic;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\coach\Coach;
|
||||
use app\common\model\goods\GoodsComment;
|
||||
use app\common\model\order\Order;
|
||||
|
||||
/**
|
||||
* 评论控制器类
|
||||
* Class GoodsCommentLogic
|
||||
* @package app\shopapi\logic
|
||||
*/
|
||||
class GoodsCommentLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 评论分类
|
||||
* @param $shopId
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author cjhao
|
||||
* @date 2024/11/1 17:49
|
||||
*/
|
||||
public function commentCategory($shopId)
|
||||
{
|
||||
$orderGoodsIds = Order::alias('O')
|
||||
->join('order_goods OG', 'O.id = OG.order_id')
|
||||
->where(['shop_id' => $shopId, '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,
|
||||
];
|
||||
}
|
||||
}
|
||||
299
server/app/shopapi/logic/GoodsLogic.php
Executable file
299
server/app/shopapi/logic/GoodsLogic.php
Executable file
@@ -0,0 +1,299 @@
|
||||
<?php
|
||||
namespace app\shopapi\logic;
|
||||
use app\common\enum\DefaultEnum;
|
||||
use app\common\enum\GoodsEnum;
|
||||
use app\common\enum\shop\ShopEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\goods\Goods;
|
||||
use app\common\model\goods\GoodsCategory;
|
||||
use app\common\model\goods\GoodsCityIndex;
|
||||
use app\common\model\goods\GoodsImage;
|
||||
use app\common\model\goods\GoodsSkillIndex;
|
||||
use app\common\model\shop\Shop;
|
||||
use app\common\model\skill\Skill;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 服务逻辑类
|
||||
* Class GoodsLogic
|
||||
* @package app\shopapi\logic
|
||||
*/
|
||||
class GoodsLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 分类列表
|
||||
* @return GoodsCategory[]|array|\think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author cjhao
|
||||
* @date 2024/10/5 14:48
|
||||
*/
|
||||
public function categoryLists()
|
||||
{
|
||||
$lists = (new GoodsCategory())->where(['is_show'=>1,'level'=>1])->field('id,name')->select()->toArray();
|
||||
return $lists;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 技能列表
|
||||
* @return Skill[]|array|\think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author cjhao
|
||||
* @date 2024/10/16 16:48
|
||||
*/
|
||||
public function skillLists()
|
||||
{
|
||||
$lists = (new Skill())->where(['is_show'=>1])->field('id,name')->select()->toArray();
|
||||
return $lists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加商品
|
||||
* @param array $params
|
||||
* @return string|true
|
||||
* @author cjhao
|
||||
* @date 2024/10/16 17:38
|
||||
*/
|
||||
public function add(array $params)
|
||||
{
|
||||
// 启动事务
|
||||
Db::startTrans();
|
||||
try {
|
||||
$goodsImage = $params['goods_image'];
|
||||
$image = array_shift($params['goods_image']);
|
||||
//添加服务信息
|
||||
$goods = Goods::create([
|
||||
'name' => $params['name'],
|
||||
'category_id' => $params['category_id'],
|
||||
'shop_id' => $params['shop_id'],
|
||||
'image' => $image,
|
||||
'price' => $params['price'],
|
||||
'duration' => $params['duration'],
|
||||
'scribing_price' => $params['scribing_price'] ?? 0.00,
|
||||
'status' => $params['status'],
|
||||
'sort' => $params['sort'] ?? DefaultEnum::SORT,
|
||||
'tags' => $params['tags'] ?? '',
|
||||
'content' => $params['content'] ?? '',
|
||||
'overtime_price' => $params['overtime_price'] ?? '',
|
||||
'overtime_duration' => $params['overtime_duration'] ?? '',
|
||||
'commission_ratio' => $params['commission_ratio'] ?? '',
|
||||
'shop_ration' => $params['shop_ration'] ?? '',
|
||||
'virtual_order_num' => $params['virtual_order_num'] ?? '',
|
||||
'appoint_start_time' => $params['appoint_start_time'] ?? '',
|
||||
'appoint_end_time' => $params['appoint_end_time'] ?? '',
|
||||
]);
|
||||
$goodsImageLists = [];
|
||||
//添加服务轮播图信息
|
||||
foreach ($goodsImage as $image_uri) {
|
||||
$goodsImageLists[] = [
|
||||
'goods_id' => $goods->id,
|
||||
'uri' => $image_uri,
|
||||
];
|
||||
}
|
||||
(new GoodsImage())->saveAll($goodsImageLists);
|
||||
|
||||
$goodsSkillLists = [];
|
||||
foreach ($params['skill_id'] as $skillId)
|
||||
{
|
||||
$goodsSkillLists[] = [
|
||||
'goods_id' => $goods->id,
|
||||
'skill_id' => $skillId
|
||||
];
|
||||
}
|
||||
(new GoodsSkillIndex())->saveAll($goodsSkillLists);
|
||||
$shopCityId = Shop::where(['id'=>$params['shop_id']])->value('city_id');
|
||||
(new GoodsCityIndex())->save([
|
||||
'goods_id' => $goods->id,
|
||||
'city_id' => $shopCityId
|
||||
]);
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑服务
|
||||
* @param array $params
|
||||
* @return string|true
|
||||
* @author cjhao
|
||||
* @date 2024/10/17 14:43
|
||||
*/
|
||||
public function edit(array $params)
|
||||
{
|
||||
// 启动事务
|
||||
Db::startTrans();
|
||||
try {
|
||||
$goodsImage = $params['goods_image'];
|
||||
$image = array_shift($params['goods_image']);
|
||||
$goods = Goods::where(['id'=>$params['id']])->findOrEmpty();
|
||||
$auditStatus = GoodsEnum::AUDIT_STATUS_PASS;
|
||||
if(GoodsEnum::AUDIT_STATUS_REFUSE == $goods->audit_status){
|
||||
$auditStatus = GoodsEnum::AUDIT_STATUS_WAIT;
|
||||
}
|
||||
$needAudit = ['price','duration','overtime_price','overtime_duration','commission_ratio'];
|
||||
foreach ($params as $field=> $value){
|
||||
if(!isset($needAudit[$field])){
|
||||
$goodsValue = $goods[$field] ?? '';
|
||||
if($value != $goodsValue){
|
||||
$auditStatus = GoodsEnum::AUDIT_STATUS_WAIT;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// if($goods->price != $params['price']){
|
||||
// }
|
||||
// if($goods->price != $params['price']){
|
||||
// $auditStatus = GoodsEnum::AUDIT_STATUS_WAIT;
|
||||
// }
|
||||
// if($goods->duration != $params['duration']){
|
||||
// $auditStatus = GoodsEnum::AUDIT_STATUS_WAIT;
|
||||
// }
|
||||
// if($goods->overtime_price != $params['overtime_price']){
|
||||
// $auditStatus = GoodsEnum::AUDIT_STATUS_WAIT;
|
||||
// }
|
||||
// if($goods->overtime_duration != $params['overtime_duration']){
|
||||
// $auditStatus = GoodsEnum::AUDIT_STATUS_WAIT;
|
||||
// }
|
||||
//更新服务信息
|
||||
Goods::update([
|
||||
'name' => $params['name'],
|
||||
'category_id' => $params['category_id'],
|
||||
'image' => $image,
|
||||
'price' => $params['price'],
|
||||
'duration' => $params['duration'],
|
||||
'scribing_price' => $params['scribing_price'] ?? 0.00,
|
||||
'status' => $params['status'],
|
||||
'sort' => $params['sort'] ?? DefaultEnum::SORT,
|
||||
'tags' => $params['tags'] ?? '',
|
||||
'content' => $params['content'] ?? '',
|
||||
'overtime_price' => $params['overtime_price'] ?? '',
|
||||
'overtime_duration' => $params['overtime_duration'] ?? '',
|
||||
'commission_ratio' => $params['commission_ratio'] ?? '',
|
||||
// 'shop_ration' => $params['shop_ration'] ?? '',
|
||||
'audit_status' => $auditStatus,
|
||||
'virtual_order_num' => $params['virtual_order_num'] ?? '',
|
||||
'appoint_start_time' => $params['appoint_start_time'] ?? '',
|
||||
'appoint_end_time' => $params['appoint_end_time'] ?? '',
|
||||
],['id'=>$params['id']]);
|
||||
$goodsImageLists = [];
|
||||
//删除旧的轮播图
|
||||
GoodsImage::where('goods_id',$params['id'])->delete();
|
||||
//添加服务轮播图信息
|
||||
foreach ($goodsImage as $image_uri) {
|
||||
$goodsImageLists[] = [
|
||||
'goods_id' => $params['id'],
|
||||
'uri' => $image_uri,
|
||||
];
|
||||
}
|
||||
(new GoodsImage())->saveAll($goodsImageLists);
|
||||
//删除管理图片,删除管理城市
|
||||
GoodsSkillIndex::where('goods_id',$params['id'])->delete();
|
||||
$goodsSkillLists = [];
|
||||
foreach ($params['skill_id'] as $skillId)
|
||||
{
|
||||
$goodsSkillLists[] = [
|
||||
'goods_id' => $params['id'],
|
||||
'skill_id' => $skillId
|
||||
];
|
||||
}
|
||||
(new GoodsSkillIndex())->saveAll($goodsSkillLists);
|
||||
|
||||
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除接口
|
||||
* @param $id
|
||||
* @param $shopId
|
||||
* @return string|true
|
||||
* @author cjhao
|
||||
* @date 2024/11/14 15:24
|
||||
*/
|
||||
public static function del($id,$shopId){
|
||||
// 启动事务
|
||||
// Db::startTrans();
|
||||
try {
|
||||
//删除师傅绑定的服务
|
||||
// foreach ($ids as $id) {
|
||||
// $staff_lists = Staff::whereRaw("FIND_IN_SET($id,goods_ids)")->select()->toArray();
|
||||
// foreach ($staff_lists as $list) {
|
||||
// $goods_ids = str_replace(','.$id.',',',',$list['goods_ids']);
|
||||
// if ($goods_ids == ',') {
|
||||
// $goods_ids = '';
|
||||
// }
|
||||
// Staff::update(['goods_ids'=>$goods_ids],['id'=>$list['id']]);
|
||||
// }
|
||||
// }
|
||||
//删除服务
|
||||
Goods::destroy(['id'=>$id,'shop_id'=>$shopId]);
|
||||
|
||||
// 提交事务
|
||||
// Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
// Db::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 修改服务状态
|
||||
* @param $params
|
||||
* @return Goods
|
||||
* @author ljj
|
||||
* @date 2022/2/9 4:54 下午
|
||||
*/
|
||||
public function status($params,$shopId)
|
||||
{
|
||||
return Goods::update(['status'=>$params['status']],['id'=>$params['id'],'shop_id'=>$shopId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 查看服务详情
|
||||
* @param $id
|
||||
* @return array
|
||||
* @author ljj
|
||||
* @date 2022/2/9 3:51 下午
|
||||
*/
|
||||
public function detail($id)
|
||||
{
|
||||
$result = Goods::where('id',$id)
|
||||
->withoutField('order_num,update_time,delete_time')
|
||||
->append(['category_desc','goods_image'])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
$result['commission_ratio'] = floatval($result['commission_ratio']);
|
||||
$goods_image = [];
|
||||
foreach ($result['goods_image'] as &$image) {
|
||||
$goods_image[] = $image['uri'];
|
||||
}
|
||||
$result['goods_image'] = $goods_image;
|
||||
$result['city_id'] = GoodsCityIndex::where(['goods_id'=>$id])->column('city_id');
|
||||
$result['skill_id'] = GoodsSkillIndex::where(['goods_id'=>$id])->column('skill_id');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
98
server/app/shopapi/logic/IndexLogic.php
Executable file
98
server/app/shopapi/logic/IndexLogic.php
Executable file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
namespace app\shopapi\logic;
|
||||
use app\common\enum\coach\CoachEnum;
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\enum\shop\ShopEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\coach\Coach;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\shop\Shop;
|
||||
use app\common\model\shop\ShopCoachApply;
|
||||
use app\common\model\shop\ShopVisit;
|
||||
|
||||
class IndexLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
public function shopData(int $shopId)
|
||||
{
|
||||
$todayShopVisit = ShopVisit::where(['shop_id'=>$shopId])->whereDay('create_time')->sum('visit');
|
||||
$yesterdayShopVisit = ShopVisit::where(['shop_id'=>$shopId])->whereDay('create_time','yesterday')->sum('visit');
|
||||
$todayOrderNum = Order::where(['shop_id'=>$shopId,'pay_status'=>PayEnum::ISPAID])->whereDay('create_time')->count();
|
||||
$yesterdayOrderNum = Order::where(['shop_id'=>$shopId,'pay_status'=>PayEnum::ISPAID])->whereDay('create_time','yesterday')->count();
|
||||
$todayOrderIncome = Order::where(['shop_id'=>$shopId,'pay_status'=>PayEnum::ISPAID])->whereDay('create_time')->sum('total_amount');
|
||||
$yesterdayOrderIncome = Order::where(['shop_id'=>$shopId,'pay_status'=>PayEnum::ISPAID])->whereDay('create_time','yesterday')->sum('total_amount');
|
||||
// 计算浏览量的变化
|
||||
$viewChange =$todayShopVisit - $yesterdayShopVisit;
|
||||
// 计算百分比变化
|
||||
if ($yesterdayShopVisit > 0) {
|
||||
$shopVisitPercentChange = round(($viewChange / $yesterdayShopVisit) * 100,2);
|
||||
} else {
|
||||
$shopVisitPercentChange = $viewChange* 100;
|
||||
}
|
||||
0 == $shopVisitPercentChange && $shopVisitPercentChange = intval($shopVisitPercentChange);
|
||||
$shopVisitPercentChange > 100 && $shopVisitPercentChange = 100;
|
||||
// 计算订单数量的变化
|
||||
$viewChange =$todayOrderNum - $yesterdayOrderNum;
|
||||
// 计算百分比变化
|
||||
if ($yesterdayOrderNum > 0) {
|
||||
$orderNumChange = round(($viewChange / $yesterdayOrderNum) * 100,2);
|
||||
} else {
|
||||
$orderNumChange = $viewChange* 100;
|
||||
}
|
||||
0 == $orderNumChange && $orderNumChange = intval($orderNumChange);
|
||||
$orderNumChange > 100 && $orderNumChange = 100;
|
||||
// 计算订单数量的变化
|
||||
$viewChange = $todayOrderIncome - $yesterdayOrderIncome;
|
||||
// 计算百分比变化
|
||||
if ($yesterdayOrderIncome > 0) {
|
||||
$orderIncomeChange = round(($viewChange / $yesterdayOrderIncome) * 100,2);
|
||||
} else {
|
||||
$orderIncomeChange = $viewChange* 100;
|
||||
}
|
||||
0 == $orderIncomeChange && $orderIncomeChange = intval($orderIncomeChange);
|
||||
$orderIncomeChange > 100 && $orderIncomeChange = 100;
|
||||
$todayDate = date('Y-m-d',time());
|
||||
//今天的时间戳
|
||||
$todayStart = strtotime($todayDate);
|
||||
$todayEnd = strtotime($todayDate . ' 23:59:59');
|
||||
//明天的时间戳
|
||||
$tomorrowStart = strtotime('+1 day',$todayStart);
|
||||
$tomorrowEnd = strtotime('+1 day',$todayEnd);
|
||||
//后天的时间戳
|
||||
$dayAfterTomorrowStart = strtotime('+2 day',$todayStart);
|
||||
$dayAfterTomorrowEnd = strtotime('+2 day',$todayEnd);
|
||||
|
||||
return [
|
||||
'shop_name' => Shop::where(['id'=>$shopId])->value('name'),
|
||||
'shop_data' => [
|
||||
'shop_visit' => $todayShopVisit,
|
||||
'visit_compare' => $shopVisitPercentChange.'%',
|
||||
'order_num' => $todayOrderNum,
|
||||
'order_num_compare' => $orderNumChange.'%',
|
||||
'order_income' => $todayOrderIncome,
|
||||
'order_income_compare' => $orderIncomeChange.'%',
|
||||
],
|
||||
'wait_order_data' => [
|
||||
'today_order_num' => Order::where(['shop_id'=>$shopId,'pay_status'=>PayEnum::ISPAID])->where('order_status','>',OrderEnum::ORDER_STATUS_WAIT_PAY)->where('order_status','<',OrderEnum::ORDER_STATUS_SERVER_FINISH)->whereDay('create_time','today')->count(),
|
||||
'tomorrow_order_num' => Order::where(['shop_id'=>$shopId,'pay_status'=>PayEnum::ISPAID])->where('order_status','>',OrderEnum::ORDER_STATUS_WAIT_PAY)->where('order_status','<',OrderEnum::ORDER_STATUS_SERVER_FINISH)->whereTime('appoint_time','between',[$tomorrowStart,$tomorrowEnd])->count(),
|
||||
'dayafter_order_num' => Order::where(['shop_id'=>$shopId,'pay_status'=>PayEnum::ISPAID])->where('order_status','>',OrderEnum::ORDER_STATUS_WAIT_PAY)->where('order_status','<',OrderEnum::ORDER_STATUS_SERVER_FINISH)->whereTime('appoint_time','between',[$dayAfterTomorrowStart,$dayAfterTomorrowEnd])->count(),
|
||||
],
|
||||
'order_data' => [
|
||||
'wait_server_num' => Order::where(['shop_id'=>$shopId])->where('order_status','>',OrderEnum::ORDER_STATUS_WAIT_RECEIVING)->where('order_status','<',OrderEnum::ORDER_STATUS_SERVER_FINISH)->count(),
|
||||
'wait_take_num' => Order::where(['shop_id'=>$shopId])->where('order_status','=',OrderEnum::ORDER_STATUS_WAIT_RECEIVING)->count(),
|
||||
'depart_num' => Order::where(['shop_id'=>$shopId])->where('order_status','=',OrderEnum::ORDER_STATUS_DEPART)->count(),
|
||||
'arrive_num' => Order::where(['shop_id'=>$shopId])->where('order_status','=',OrderEnum::ORDER_STATUS_ARRIVE)->count(),
|
||||
'start_server_num' => Order::where(['shop_id'=>$shopId])->where('order_status','=',OrderEnum::ORDER_STATUS_START_SERVER)->count(),
|
||||
'finish_server_num' => Order::where(['shop_id'=>$shopId])->where('order_status','=',OrderEnum::ORDER_STATUS_SERVER_FINISH)->count(),
|
||||
],
|
||||
'coach_data' => [
|
||||
'wait_audtit_num' => ShopCoachApply::where(['shop_id'=>$shopId,'audit_status'=>ShopEnum::AUDIT_STATUS_WAIT])->count(),
|
||||
'online_coach_num' => Coach::where(['shop_id'=>$shopId,'audit_status'=>CoachEnum::AUDIT_STATUS_PASS,'work_status'=>CoachEnum::WORK_STATUS_ONLINE])->count(),
|
||||
'downline_coach_num' => Coach::where(['shop_id'=>$shopId,'audit_status'=>CoachEnum::AUDIT_STATUS_PASS,'work_status'=>CoachEnum::WORK_STATUS_DOWNLINE])->count(),
|
||||
],
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
453
server/app/shopapi/logic/LoginLogic.php
Executable file
453
server/app/shopapi/logic/LoginLogic.php
Executable file
@@ -0,0 +1,453 @@
|
||||
<?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\shopapi\logic;
|
||||
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use app\common\enum\shop\ShopEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\coach\Coach;
|
||||
use app\common\model\shop\Shop;
|
||||
use app\common\model\shop\ShopUser;
|
||||
use app\shopapi\service\ShopUserTokenService;
|
||||
use app\common\service\{ConfigService, FileService, sms\SmsDriver, WeChatService};
|
||||
use think\facade\{Db, Config};
|
||||
use think\Exception;
|
||||
|
||||
/**
|
||||
* 登录逻辑
|
||||
* Class LoginLogic
|
||||
* @package app\coachapi\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 {
|
||||
$smsDriver = new SmsDriver();
|
||||
$result = $smsDriver->verify($params['account'], $params['code'], NoticeEnum::REGISTER_CAPTCHA_SHOP);
|
||||
if (!$result) {
|
||||
throw new Exception('验证码错误');
|
||||
}
|
||||
$number = ShopUser::count()+1;
|
||||
$sn = sprintf("%03d", $number);
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
$password = create_password($params['password'], $passwordSalt);
|
||||
$avatar = ConfigService::get('default_image', 'user_avatar');
|
||||
|
||||
ShopUser::create([
|
||||
'sn' => $sn,
|
||||
'avatar' => $avatar,
|
||||
'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' => $params['account']];
|
||||
|
||||
$shopUser = ShopUser::where($where)->findOrEmpty();
|
||||
if ($shopUser->isEmpty()) {
|
||||
throw new Exception('账号不存在');
|
||||
}
|
||||
|
||||
$shop = Shop::where(['shop_user_id'=>$shopUser['id']])->order('id desc')->findOrEmpty();
|
||||
// if($shop->isEmpty()){
|
||||
// throw new Exception('您的账号未申请入驻,请先申请入驻',-10);
|
||||
// }
|
||||
// //待审核
|
||||
// if(ShopEnum::AUDIT_STATUS_WAIT == $shop->audit_status){
|
||||
// throw new Exception('感谢您对我们平台的支持,我们将在1~3个工作日内审核');
|
||||
// }
|
||||
// //审核不通过
|
||||
// if(ShopEnum::AUDIT_STATUS_REFUSE == $shop->audit_status){
|
||||
// throw new Exception($shop->audit_remark,-20);
|
||||
// }
|
||||
//更新登录信息
|
||||
$shopUser->login_time = time();
|
||||
$shopUser->login_ip = request()->ip();
|
||||
$shopUser->save();
|
||||
|
||||
//设置token
|
||||
$shopUserInfo = ShopUserTokenService::setToken($shopUser->id, $params['terminal']);
|
||||
|
||||
//返回登录信息
|
||||
$avatar = $shopUser->avatar ?: Config::get('project.default_image.user_avatar');
|
||||
$avatar = FileService::getFileUrl($avatar);
|
||||
|
||||
return [
|
||||
'sn' => $shopUserInfo['sn'],
|
||||
'account' => $shopUserInfo['account'],
|
||||
'avatar' => $avatar,
|
||||
'token' => $shopUserInfo['token'],
|
||||
'audit_status' => $shop->audit_status,
|
||||
'audit_remark' => $shop->audit_remark,
|
||||
];
|
||||
} catch (Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
self::setReturnCode($e->getCode());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 退出登录
|
||||
* @param $shopInfo
|
||||
* @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($shopInfo)
|
||||
{
|
||||
//token不存在,不注销
|
||||
if (!isset($shopInfo['token'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//设置token过期
|
||||
return ShopUserTokenService::expireToken($shopInfo['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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 重置登录密码
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 18:06
|
||||
*/
|
||||
public function resetPassword(array $params): bool
|
||||
{
|
||||
try {
|
||||
// Db::startTrans();
|
||||
// 校验验证码
|
||||
$smsDriver = new SmsDriver();
|
||||
if (!$smsDriver->verify($params['mobile'], $params['code'], NoticeEnum::RESET_PASSWORD_CAPTCHA_SHOP)) {
|
||||
throw new \Exception('验证码错误');
|
||||
}
|
||||
|
||||
// 重置密码
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
$password = create_password($params['password'], $passwordSalt);
|
||||
|
||||
// 更新
|
||||
ShopUser::where('account', $params['mobile'])->update([
|
||||
'password' => $password
|
||||
]);
|
||||
Db::commit();
|
||||
// return true;
|
||||
} catch (\Exception $e) {
|
||||
// Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 重置登录密码
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 18:06
|
||||
*/
|
||||
public function changePassword(array $params): bool
|
||||
{
|
||||
try {
|
||||
|
||||
// 重置密码
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
$password = create_password($params['password'], $passwordSalt);
|
||||
|
||||
$shopUser = ShopUser::where(['id'=>$params['shop_info']['shop_user_id']])->findOrEmpty();
|
||||
// if($coachUser->isEmpty()){
|
||||
// throw new \Exception('账号不存在');
|
||||
// }
|
||||
// 更新
|
||||
$shopUser->password = $password;
|
||||
$shopUser->save();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
164
server/app/shopapi/logic/OrderLogic.php
Executable file
164
server/app/shopapi/logic/OrderLogic.php
Executable file
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
namespace app\shopapi\logic;
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\OrderLogEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\logic\CoachLogic;
|
||||
use app\common\logic\OrderLogLogic;
|
||||
use app\common\model\coach\Coach;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\order\OrderLog;
|
||||
use app\common\model\settle\SettleOrder;
|
||||
use app\common\service\FileService;
|
||||
use Exception;
|
||||
use think\facade\Db;
|
||||
|
||||
class OrderLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 订单详情
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @author cjhao
|
||||
* @date 2024/9/20 02:19
|
||||
*/
|
||||
public function detail(int $id)
|
||||
{
|
||||
$detail = Order::field('id,sn,order_status,total_order_amount,total_refund_amount,user_remark,total_order_amount,pay_status,pay_way,goods_price,order_amount,total_amount,total_gap_amount,total_append_amount,appoint_time,order_amount,user_remark,address_snap,is_settle,server_finish_time,create_time,refund_amount,coach_id,car_amount,order_distance,update_time,true_server_finish_time')
|
||||
->order('id','desc')
|
||||
->append(['order_distance_desc','dispatch_btn','pay_way_desc','appoint_time','appoint_date','order_status_desc','order_cancel_time'])
|
||||
->with(['order_goods' => function($query){
|
||||
$query->field('order_id,goods_id,goods_num,goods_snap,duration,goods_image,goods_name,goods_price')->hidden(['goods_snap']);
|
||||
},'order_gap','order_append','coach_info'])
|
||||
->where(['id'=>$id])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
if(!isset($detail['address_snap']['house_number'])){
|
||||
$detail['address_snap']['house_number'] = '';
|
||||
}
|
||||
$orderLog = OrderLog::where(['order_id'=>$id,'type'=>OrderLogEnum::TYPE_COACH])
|
||||
->field('content,location,extra,create_time')
|
||||
->select()->toArray();
|
||||
$logLists = [];
|
||||
foreach ($orderLog as $key => $log){
|
||||
$date = date('Y-m-d',strtotime($log['create_time']));
|
||||
if($log['extra']){
|
||||
foreach ($log['extra'] as $key => $extra){
|
||||
$log['extra'][$key] = FileService::getFileUrl($extra);
|
||||
}
|
||||
}
|
||||
$logLists[$date][] = $log;
|
||||
}
|
||||
// $logLists = $orderLog;
|
||||
$settleOrder = [];
|
||||
if($detail['is_settle']){
|
||||
$settleOrder = SettleOrder::where(['order_id'=>$detail['id']])->findOrEmpty();
|
||||
}
|
||||
$shopCommission = $settleOrder['shop_commission'] ?? 0;
|
||||
$shopCarAmount = $settleOrder['shop_car_amount'] ?? 0;
|
||||
$coachCommission = $settleOrder['coach_commission'] ?? 0;
|
||||
$coachCarAmount = $settleOrder['coach_car_amount'] ?? 0;
|
||||
// $totalOrderAmount = $settleOrder['order_amount'] ?? 0;
|
||||
// $carAmount = $settleOrder['car_amount'] ?? 0;
|
||||
$detail['settle_info'] = [
|
||||
'status' => $detail['is_settle'],
|
||||
'order_amount' => $settleOrder['order_amount'] ?? 0,
|
||||
'refund_amount' => $detail['total_refund_amount'],
|
||||
'settle_car' => $settleOrder['car_amount'] ?? 0,
|
||||
'settle_amount' => $settleOrder['total_commission'] ?? 0,
|
||||
'coach_settle' => $settleOrder['coach_commission'] ?? 0,
|
||||
'shop_settle' => $settleOrder['shop_commission'] ?? 0,
|
||||
// 'total_settle_amount'=> round($totalOrderAmount + $carAmount ,2),
|
||||
];
|
||||
$detail['server_log_lists'] = $logLists;
|
||||
return $detail;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 订单更换技师时获取技师列表
|
||||
* @param $params
|
||||
* @return array|bool
|
||||
* @author cjhao
|
||||
* @date 2024/10/9 16:30
|
||||
*/
|
||||
public function coachLists($params,$shopId)
|
||||
{
|
||||
try {
|
||||
$id = $params['id'] ?? '';
|
||||
$keyword = $params['keyword'] ?? '';
|
||||
if(empty($id)){
|
||||
throw new Exception('请选择订单');
|
||||
}
|
||||
$order = Order::where(['id'=>$id])->findOrEmpty();
|
||||
if(OrderEnum::ORDER_STATUS_WAIT_PAY == $order->order_status || OrderEnum::ORDER_STATUS_DEPART < $order->order_status){
|
||||
throw new Exception('当前订单不可更改技师');
|
||||
}
|
||||
$startTime = $order->getData('appoint_time');
|
||||
$serverFinishTime = $order->getData('server_finish_time');
|
||||
$coachLists = CoachLogic::getLeisureCoach($order['coach_id'],$startTime,$serverFinishTime,$order,$keyword);
|
||||
|
||||
return $coachLists;
|
||||
}catch (Exception $e){
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 指派技师
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author cjhao
|
||||
* @date 2024/11/6 14:36
|
||||
*/
|
||||
public function dispatchCoach(array $params)
|
||||
{
|
||||
try {
|
||||
Db::startTrans();
|
||||
$id = $params['id'] ?? '';
|
||||
$coachId = $params['coach_id'] ?? '';
|
||||
if(empty($id)){
|
||||
throw new Exception('请选择订单');
|
||||
}
|
||||
if(empty($coachId)){
|
||||
throw new Exception('请选择技师');
|
||||
}
|
||||
$order = Order::where(['id'=>$id])
|
||||
->findOrEmpty();
|
||||
|
||||
if(OrderEnum::ORDER_STATUS_WAIT_PAY == $order->order_status || OrderEnum::ORDER_STATUS_DEPART < $order->order_status){
|
||||
throw new Exception('当前订单不可更改技师');
|
||||
}
|
||||
$startTime = $order->getData('appoint_time');
|
||||
$serverFinishTime = $order->getData('server_finish_time');
|
||||
$coachLists = CoachLogic::getLeisureCoach($order['coach_id'],$startTime,$serverFinishTime,$order);
|
||||
$coachIds = array_column($coachLists,'id');
|
||||
if(!in_array($coachId,$coachIds)){
|
||||
throw new Exception('该技师该时间段忙');
|
||||
}
|
||||
//技师更换
|
||||
$order->coach_id = $coachId;
|
||||
$order->save();
|
||||
$originalCoachId = $order['coach_id'];
|
||||
$extra = [
|
||||
'original_coach_id' => $originalCoachId,
|
||||
'coach_id' => $coachId
|
||||
];
|
||||
(new OrderLogLogic())
|
||||
->record(OrderLogEnum::TYPE_SHOP,OrderLogEnum::SHOP_CHANGE_COACH,$order['id'],$params['shop_id'],'','',$extra);
|
||||
Db::commit();
|
||||
return true;
|
||||
|
||||
}catch (Exception $e){
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
240
server/app/shopapi/logic/PayLogic.php
Executable file
240
server/app/shopapi/logic/PayLogic.php
Executable file
@@ -0,0 +1,240 @@
|
||||
<?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\shopapi\logic;
|
||||
|
||||
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\enum\user\UserTerminalEnum;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\logic\CoachPayNotifyLogic;
|
||||
use app\common\logic\ShopPayNotifyLogic;
|
||||
use app\common\model\deposit\DepositOrder;
|
||||
use app\common\model\pay\PayWay;
|
||||
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\ShopBalancePayService;
|
||||
use app\common\service\WeChatPayService;
|
||||
use app\common\service\WeChatService;
|
||||
|
||||
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'] == 'deposit') {
|
||||
// // 订单
|
||||
// $order = DepositOrder::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'],['deposit'])){
|
||||
// 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::ALI_PAY) {
|
||||
$item['extra'] = '支付宝支付';
|
||||
}
|
||||
// 充值时去除余额支付
|
||||
if ( $item['pay_way'] == PayEnum::BALANCE_PAY) {
|
||||
unset($pay_way[$k]);
|
||||
}
|
||||
// 充值时去除微信支付
|
||||
if ( $item['pay_way'] == PayEnum::WECHAT_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,$wechatCode = '')
|
||||
{
|
||||
$order = [];
|
||||
//更新支付方式
|
||||
switch ($from) {
|
||||
case 'deposit':
|
||||
DepositOrder::update(['pay_way' => $payWay], ['id' => $order_id]);
|
||||
$order = DepositOrder::where('id',$order_id)->findOrEmpty()->toArray();
|
||||
break;
|
||||
}
|
||||
if (empty($order)) {
|
||||
self::setError('订单错误');
|
||||
}
|
||||
|
||||
if($order['order_amount'] == 0) {
|
||||
ShopPayNotifyLogic::handle($from, $order['sn']);
|
||||
return ['pay_way'=>$payWay];
|
||||
}
|
||||
|
||||
switch ($payWay) {
|
||||
case PayEnum::WECHAT_PAY:
|
||||
if (isset($wechatCode) && $wechatCode != '') {
|
||||
switch ($terminal) {
|
||||
case UserTerminalEnum::WECHAT_MMP:
|
||||
$response = (new WeChatService())->getMnpResByCode($wechatCode);
|
||||
$order['openid'] = $response['openid'];
|
||||
break;
|
||||
case UserTerminalEnum::WECHAT_OA:
|
||||
$response = (new WeChatService())->getOaResByCode($wechatCode);
|
||||
$order['openid'] = $response['openid'];
|
||||
break;
|
||||
}
|
||||
DepositOrder::update(['openid' => $order['openid']], ['id' => $order_id]);
|
||||
}
|
||||
$payService = (new WeChatPayService($terminal, null));
|
||||
$result = $payService->pay($from, $order);
|
||||
break;
|
||||
case PayEnum::BALANCE_PAY:
|
||||
//余额支付
|
||||
$payService = (new ShopBalancePayService());
|
||||
$result = $payService->pay($from, $order);
|
||||
if (false !== $result) {
|
||||
ShopPayNotifyLogic::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 'deposit' :
|
||||
$result = DepositOrder::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;
|
||||
default :
|
||||
$result = [];
|
||||
}
|
||||
if (empty($result)) {
|
||||
self::$error = '订单信息不存在';
|
||||
}
|
||||
$result['pay_way_desc'] = PayEnum::getPayTypeDesc($result['pay_way']);
|
||||
$result['pay_time'] = empty($result['pay_time']) ? '-' : date('Y-m-d H:i:s', $result['pay_time']);
|
||||
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;
|
||||
}
|
||||
}
|
||||
447
server/app/shopapi/logic/ShopLogic.php
Executable file
447
server/app/shopapi/logic/ShopLogic.php
Executable file
@@ -0,0 +1,447 @@
|
||||
<?php
|
||||
namespace app\shopapi\logic;
|
||||
use app\common\enum\coach\CoachEnum;
|
||||
use app\common\enum\GoodsEnum;
|
||||
use app\common\enum\shop\ShopEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\coach\Coach;
|
||||
use app\common\model\coach\CoachServerTime;
|
||||
use app\common\model\coach\CoachUser;
|
||||
use app\common\model\goods\Goods;
|
||||
use app\common\model\shop\Shop;
|
||||
use app\common\model\shop\ShopCategoryIndex;
|
||||
use app\common\model\shop\ShopGoodsIndex;
|
||||
use app\common\model\shop\ShopImage;
|
||||
use app\common\model\shop\ShopUpdate;
|
||||
use app\common\model\shop\ShopUser;
|
||||
use app\common\service\sms\SmsDriver;
|
||||
use Exception;
|
||||
use think\facade\Db;
|
||||
|
||||
class ShopLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 个人中心
|
||||
* @param int $shopId
|
||||
* @return Shop|array|\think\Model
|
||||
* @author cjhao
|
||||
* @date 2024/10/20 03:23
|
||||
*/
|
||||
public function centre(int $shopId)
|
||||
{
|
||||
|
||||
$shop = Shop::where(['id'=>$shopId])
|
||||
->field('sn,name,mobile,logo,audit_status,audit_remark,money,deposit')
|
||||
->findOrEmpty()->toArray();
|
||||
$shop['coach_count'] = Coach::where(['shop_id'=>$shopId])->count();
|
||||
$shop['shop_goods_count'] = Goods::where(['shop_id'=>$shopId,'audit_status'=>GoodsEnum::AUDIT_STATUS_PASS])->count();
|
||||
$shop['goods_count'] = ShopGoodsIndex::where(['shop_id'=>$shopId])->count();
|
||||
$shop['audit_status'] = $shop['audit_status'] ?? 0;
|
||||
$shop['audit_remark'] = $shop['audit_remark'] ?? '';
|
||||
return $shop;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取手机号码
|
||||
* @param int $shopId
|
||||
* @return array
|
||||
* @author cjhao
|
||||
* @date 2024/11/19 11:34
|
||||
*/
|
||||
public function info(int $shopId)
|
||||
{
|
||||
$shop = Shop::where(['id'=>$shopId])
|
||||
->field('sn,name,mobile,logo,audit_status,audit_remark,money,deposit,create_time')
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
return $shop;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 申请
|
||||
* @param array $params
|
||||
* @return string|true
|
||||
* @author cjhao
|
||||
* @date 2024/10/5 20:26
|
||||
*/
|
||||
public function apply(array $params)
|
||||
{
|
||||
try {
|
||||
Db::startTrans();
|
||||
$shop = shop::where(['shop_user_id'=>$params['shop_user_id']])
|
||||
->order('id desc')
|
||||
->findOrEmpty();
|
||||
if( !$shop->isEmpty() && ShopEnum::AUDIT_STATUS_PASS == $shop->audit_status ){
|
||||
return '当前账号已经入驻成功,请勿重复申请';
|
||||
}
|
||||
if( !$shop->isEmpty() && ShopEnum::AUDIT_STATUS_WAIT == $shop->audit_status ){
|
||||
return '当前账号申请正在审核中,请耐心等待';
|
||||
}
|
||||
$shopUser = ShopUser::where(['id'=>$params['shop_user_id']])->findOrEmpty();
|
||||
$shop = Shop::create([
|
||||
'name' => $params['name'],
|
||||
'mobile' => $shopUser['account'],
|
||||
'shop_user_id' => $params['shop_user_id'],
|
||||
'sn' => sprintf("%03d", Shop::count()+1),
|
||||
'short_name' => $params['short_name'],
|
||||
'type' => $params['type'],
|
||||
'social_credit_ode' => $params['social_credit_ode'],
|
||||
'legal_person' => $params['legal_person'],
|
||||
'legal_id_card' => $params['legal_id_card'],
|
||||
'province_id' => $params['province_id'],
|
||||
'city_id' => $params['city_id'],
|
||||
'region_id' => $params['region_id'],
|
||||
'shop_address_detail'=> $params['shop_address_detail'],
|
||||
'longitude' => $params['longitude'],
|
||||
'latitude' => $params['latitude'],
|
||||
'id_card_front' => $params['id_card_front'],
|
||||
'id_card_back' => $params['id_card_back'],
|
||||
'portrait_shooting' => $params['portrait_shooting'],
|
||||
'logo' => $params['logo'],
|
||||
'business_license' => $params['business_license'],
|
||||
'synopsis' => $params['synopsis'] ?? '',
|
||||
'audit_status' => ShopEnum::AUDIT_STATUS_WAIT,
|
||||
'work_status' => $params['work_status'] ?? 0,
|
||||
'server_status' => $params['server_status'] ?? 1,
|
||||
'business_start_time' => $params['business_start_time'] ?? '',
|
||||
'business_end_time' => $params['business_end_time'] ?? '',
|
||||
]);
|
||||
$categoryLists = [];
|
||||
foreach ($params['category_ids'] as $categoryId){
|
||||
$categoryLists[] = [
|
||||
'shop_id' => $shop['id'],
|
||||
'category_id' => $categoryId,
|
||||
];
|
||||
}
|
||||
|
||||
(new ShopCategoryIndex())->saveAll($categoryLists);
|
||||
|
||||
$goodsLists = [];
|
||||
foreach ($params['goods_ids'] as $goodsId) {
|
||||
$goodsLists[] = [
|
||||
'shop_id' => $shop['id'],
|
||||
'goods_id' => $goodsId,
|
||||
];
|
||||
}
|
||||
(new ShopGoodsIndex())->saveAll($goodsLists);
|
||||
|
||||
$shopImageLists = [];
|
||||
$params['shop_image'] = $params['shop_image'] ? : [];
|
||||
foreach ($params['shop_image'] as $image){
|
||||
$shopImageLists[] = [
|
||||
'shop_id' => $shop['id'],
|
||||
'uri' => $image,
|
||||
];
|
||||
}
|
||||
(new ShopImage())->saveAll($shopImageLists);
|
||||
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
}catch (Exception $e){
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情接口
|
||||
* @param int $id
|
||||
* @param int $shopUserId
|
||||
* @return array
|
||||
* @author cjhao
|
||||
* @date 2024/10/5 20:28
|
||||
*/
|
||||
public function detail($shopUserId)
|
||||
{
|
||||
|
||||
$detail = Shop::where(['shop_user_id'=>$shopUserId])
|
||||
->with(['shop_image'])
|
||||
->append(['audit_status_desc','region_desc','province_name','city_name','region_name'])
|
||||
->withoutField('update_time,delete_time')
|
||||
->order('id desc')
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
$categoryLists = ShopCategoryIndex::alias('SC')
|
||||
->where(['SC.shop_id'=>$detail['id'],'is_show'=>1])
|
||||
->join('goods_category GC','SC.category_id = GC.id')
|
||||
->field('GC.id,GC.name')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$goodsLists = ShopGoodsIndex::alias('SG')
|
||||
->where(['SG.shop_id'=>$detail['id'],'G.status'=>1])
|
||||
->join('goods G','SG.goods_id = G.id')
|
||||
->field('G.id,G.name')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
|
||||
$detail['category_lists'] = $categoryLists;
|
||||
$detail['goods_lists'] = $goodsLists;
|
||||
$detail['goods_ids'] = array_column($goodsLists,'id');
|
||||
$detail['category_ids'] = array_column($categoryLists,'id');
|
||||
|
||||
return $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 更新店铺信息
|
||||
* @param array $params
|
||||
* @return string|true
|
||||
* @author cjhao
|
||||
* @date 2024/10/6 16:39
|
||||
*/
|
||||
public function updateInfo(array $params)
|
||||
{
|
||||
try {
|
||||
if(!$params['shop_id']){
|
||||
throw new Exception('请等待你店铺申请通过后,才能提交资料');
|
||||
}
|
||||
|
||||
$shopUpdate = ShopUpdate::where(['shop_id'=>$params['shop_id'],'audit_status'=>CoachEnum::AUDIT_STATUS_WAIT])
|
||||
->findOrEmpty();
|
||||
if(!$shopUpdate->isEmpty()){
|
||||
throw new Exception('您提交资料正在审核中,请勿重复提交');
|
||||
}
|
||||
// $mobile = Shop::where(['mobile'=>$params['mobile']])->where('id','<>',$params['shop_id'])->findOrEmpty();
|
||||
// if(!$mobile->isEmpty()){
|
||||
// throw new Exception('手机号码已存在');
|
||||
// }
|
||||
// ShopUpdate::where(['mobile'=>$params['mobile'],'audit_status'=>ShopEnum::AUDIT_STATUS_WAIT])->where('id','<>',$params['shop_id'])->findOrEmpty();
|
||||
// if(!$mobile->isEmpty()){
|
||||
// throw new Exception('手机号码已存在');
|
||||
// }
|
||||
$shopUser = ShopUser::where(['id'=>$params['shop_user_id']])->findOrEmpty();
|
||||
ShopUpdate::create([
|
||||
'name' => $params['name'],
|
||||
'shop_user_id' => $params['shop_user_id'],
|
||||
'shop_id' => $params['shop_id'],
|
||||
'sn' => $params['sn'],
|
||||
'short_name' => $params['short_name'],
|
||||
'mobile' => $shopUser['account'],
|
||||
'business_start_time' => $params['business_start_time'],
|
||||
'business_end_time' => $params['business_end_time'],
|
||||
'type' => $params['type'],
|
||||
'social_credit_ode' => $params['social_credit_ode'],
|
||||
'legal_person' => $params['legal_person'],
|
||||
'legal_id_card' => $params['legal_id_card'],
|
||||
// 'shop_adress' => $params['shop_adress'],
|
||||
'shop_address_detail' => $params['shop_address_detail'],
|
||||
'province_id' => $params['province_id'],
|
||||
'city_id' => $params['city_id'],
|
||||
'region_id' => $params['region_id'],
|
||||
'longitude' => $params['longitude'],
|
||||
'latitude' => $params['latitude'],
|
||||
'id_card_front' => $params['id_card_front'],
|
||||
'id_card_back' => $params['id_card_back'],
|
||||
'portrait_shooting' => $params['portrait_shooting'],
|
||||
'logo' => $params['logo'],
|
||||
'business_license' => $params['business_license'],
|
||||
'synopsis' => $params['synopsis'] ?? '',
|
||||
'category_ids' => $params['category_ids'],
|
||||
'goods_ids' => $params['goods_ids'],
|
||||
'shop_image' => $params['shop_image'] ?? []
|
||||
]);
|
||||
return true;
|
||||
}catch (Exception $e){
|
||||
return $e->getMessage();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置服务时间
|
||||
* @param array $params
|
||||
* @return string|true
|
||||
* @author cjhao
|
||||
* @date 2024/10/21 00:27
|
||||
*/
|
||||
public function setServerTime(array $params)
|
||||
{
|
||||
try {
|
||||
$coach = Coach::where(['id'=>$params['id'],'shop_id'=>$params['shop_id']])->findOrEmpty();
|
||||
if($coach->isEmpty()){
|
||||
throw new \think\Exception('您无法设置当前技师服务时间');
|
||||
}
|
||||
Db::startTrans();
|
||||
$serverTime = [];
|
||||
foreach ($params['server_time'] as $key => $time){
|
||||
$times = [];
|
||||
foreach ($time['time_lists'] as $timeList){
|
||||
if(in_array($timeList['time'],$times)){
|
||||
continue;
|
||||
}
|
||||
$serverTime[] = [
|
||||
'coach_id' => $params['id'],
|
||||
'date' => $time['time_date'],
|
||||
'time' => $timeList['time'],
|
||||
'status' => $timeList['status']
|
||||
];
|
||||
$times[] = $timeList['time'];
|
||||
}
|
||||
}
|
||||
CoachServerTime::where(['coach_id'=>$params['id']])->delete();
|
||||
(new CoachServerTime())->saveAll($serverTime);
|
||||
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取营业时间
|
||||
* @param int $shopId
|
||||
* @return Shop|array|\think\Model
|
||||
* @author cjhao
|
||||
* @date 2024/10/22 09:32
|
||||
*/
|
||||
public function getBusiness(int $shopId){
|
||||
$detail = Shop::where(['id'=>$shopId])
|
||||
->field('id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,business_start_time,business_end_time')
|
||||
->findOrEmpty()->toArray();
|
||||
$detail['monday'] = 1 == $detail['monday'] ? true : false;
|
||||
$detail['tuesday'] = 1 == $detail['tuesday'] ? true : false;
|
||||
$detail['wednesday'] = 1 == $detail['wednesday'] ? true : false;
|
||||
$detail['thursday'] = 1 == $detail['thursday'] ? true : false;
|
||||
$detail['friday'] = 1 == $detail['friday'] ? true : false;
|
||||
$detail['saturday'] = 1 == $detail['saturday'] ? true : false;
|
||||
$detail['sunday'] = 1 == $detail['sunday'] ? true : false;
|
||||
return $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 设置营业时间
|
||||
* @param array $params
|
||||
* @return true
|
||||
* @author cjhao
|
||||
* @date 2024/10/22 09:43
|
||||
*/
|
||||
public function setBusiness(array $params)
|
||||
{
|
||||
$monday = $params['monday'] ?? 0;
|
||||
$tuesday = $params['tuesday'] ?? 0;
|
||||
$wednesday = $params['wednesday'] ?? 0;
|
||||
$thursday = $params['thursday'] ?? 0;
|
||||
$friday = $params['friday'] ?? 0;
|
||||
$saturday = $params['saturday'] ?? 0;
|
||||
$sunday = $params['sunday'] ?? 0;
|
||||
$businessStartTime = $params['business_start_time'] ?? 0;
|
||||
$businessEndTime = $params['business_end_time'] ?? 0;
|
||||
Shop::where(['id'=>$params['shop_id']])
|
||||
->update([
|
||||
'monday' => $monday,
|
||||
'tuesday' => $tuesday,
|
||||
'wednesday' => $wednesday,
|
||||
'thursday' => $thursday,
|
||||
'friday' => $friday,
|
||||
'saturday' => $saturday,
|
||||
'sunday' => $sunday,
|
||||
'business_start_time' => $businessStartTime,
|
||||
'business_end_time' => $businessEndTime,
|
||||
]);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取资料详情
|
||||
* @param $shopId
|
||||
* @return array
|
||||
* @author cjhao
|
||||
* @date 2024/11/25 11:24
|
||||
*/
|
||||
public function updateInfoDetail($shopUserId)
|
||||
{
|
||||
$detail = ShopUpdate::where(['shop_user_id'=>$shopUserId])
|
||||
->append(['audit_status_desc','region_desc','province_name','city_name','region_name'])
|
||||
->order('id desc')->findOrEmpty()->toArray();
|
||||
if(empty($detail)){
|
||||
$detail = $this->detail($shopUserId);
|
||||
$detail['audit_status'] = '';
|
||||
$detail['audit_remark'] = '';
|
||||
$detail['category_ids'] = array_column($detail['category_lists'],'id');
|
||||
$detail['goods_ids'] = array_column($detail['goods_lists'],'id');
|
||||
$detail['shop_image'] = array_column($detail['shop_image'],'uri');
|
||||
}
|
||||
foreach ($detail['goods_ids'] as $key => $val){
|
||||
$detail['goods_ids'][$key] = intval($val);
|
||||
}
|
||||
foreach ($detail['category_ids'] as $key => $val){
|
||||
$detail['category_ids'][$key] = intval($val);
|
||||
}
|
||||
return $detail;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置服务状态
|
||||
* @param $params
|
||||
* @return string|true
|
||||
* @author cjhao
|
||||
* @date 2024/12/3 20:49
|
||||
*/
|
||||
public function setWorkStatus($params)
|
||||
{
|
||||
try {
|
||||
$coach = Coach::where(['id'=>$params['id'],'shop_id'=>$params['shop_id']])->findOrEmpty();
|
||||
if($coach->isEmpty()){
|
||||
throw new \think\Exception('您无法设置当前技师服务时间');
|
||||
}
|
||||
$status = $params['status'] ?? '';
|
||||
if('' === $status){
|
||||
throw new \think\Exception('请选择状态');
|
||||
}
|
||||
$coach->work_status = $status;
|
||||
$coach->save();
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function bindMobile($params)
|
||||
{
|
||||
try {
|
||||
$mobile = $params['mobile'] ?? '';
|
||||
$code = $params['code'] ?? '';
|
||||
if (empty($mobile) || empty($code)) {
|
||||
throw new \Exception('请输入手机号和验证码');
|
||||
}
|
||||
|
||||
$smsDriver = new SmsDriver();
|
||||
$result = $smsDriver->verify($params['mobile'], $params['code']);
|
||||
if(!$result) {
|
||||
throw new \Exception('验证码错误');
|
||||
}
|
||||
$user = Shop::where(['mobile'=>$params['mobile']])->where('id','<>',$params['shop_id'])->findOrEmpty();
|
||||
if(!$user->isEmpty()) {
|
||||
throw new \Exception('该手机号已被其他账号绑定');
|
||||
}
|
||||
// $user = ShopUpdate::where(['mobile'=>$params['mobile'],'audit_status'=>ShopEnum::AUDIT_STATUS_WAIT])->where('id','<>',$params['shop_id'])->findOrEmpty();
|
||||
// if(!$user->isEmpty()) {
|
||||
// throw new \Exception('该手机号已被其他账号绑定');
|
||||
// }
|
||||
unset($params['code']);
|
||||
$coach = Shop::findOrEmpty($params['shop_id'])->toArray();
|
||||
Shop::update(['mobile'=>$params['mobile'],'id'=>$params['shop_id']]);
|
||||
ShopUser::update(['account'=>$params['mobile'],'id'=>$coach['shop_user_id']]);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
60
server/app/shopapi/logic/SmsLogic.php
Executable file
60
server/app/shopapi/logic/SmsLogic.php
Executable file
@@ -0,0 +1,60 @@
|
||||
<?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\shopapi\logic;
|
||||
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
|
||||
|
||||
/**
|
||||
* 短信逻辑
|
||||
* Class SmsLogic
|
||||
* @package app\coachapi\logic
|
||||
*/
|
||||
class SmsLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 发送验证码
|
||||
* @param $params
|
||||
* @return false|mixed
|
||||
* @author 段誉
|
||||
* @date 2022/9/15 16:17
|
||||
*/
|
||||
public static function sendCode($params)
|
||||
{
|
||||
try {
|
||||
$scene = NoticeEnum::getSceneByShopTag($params['scene']);
|
||||
if (empty($scene)) {
|
||||
throw new \Exception('场景值异常');
|
||||
}
|
||||
|
||||
$result = event('Notice', [
|
||||
'scene_id' => $scene,
|
||||
'params' => [
|
||||
'mobile' => $params['mobile'],
|
||||
'code' => mt_rand(1000, 9999),
|
||||
]
|
||||
]);
|
||||
|
||||
return $result[0];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
428
server/app/shopapi/logic/WithdrawLogic.php
Executable file
428
server/app/shopapi/logic/WithdrawLogic.php
Executable file
@@ -0,0 +1,428 @@
|
||||
<?php
|
||||
namespace app\shopapi\logic;
|
||||
use app\common\enum\accountLog\CoachAccountLogEnum;
|
||||
use app\common\enum\accountLog\ShopAccountLogEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\logic\ShopAccountLogLogic;
|
||||
use app\common\model\accountLog\CoachAccountLog;
|
||||
use app\common\model\accountLog\ShopAccountLog;
|
||||
use app\common\model\coach\Coach;
|
||||
use app\common\model\shop\Shop;
|
||||
use app\common\model\withdraw\WithdrawApply;
|
||||
use app\common\model\withdraw\WithdrawConfig;
|
||||
use app\common\service\ConfigService;
|
||||
use DateTime;
|
||||
use think\Exception;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 提现逻辑类
|
||||
* Class WithdrawLogic
|
||||
* @package app\shopapi\logic
|
||||
*/
|
||||
class WithdrawLogic extends BaseLogic
|
||||
{
|
||||
|
||||
public function lists(int $shopId)
|
||||
{
|
||||
$lists = WithdrawConfig::where(['relation_id'=>$shopId,'source'=>2])
|
||||
->column('type,config','type');
|
||||
$configDefault = [
|
||||
[
|
||||
'type' => 1,
|
||||
],
|
||||
[
|
||||
'type' => 2,
|
||||
],
|
||||
[
|
||||
'type' => 3,
|
||||
],
|
||||
];
|
||||
foreach ($configDefault as $default){
|
||||
$config = $lists[$default['type']] ?? [];
|
||||
if(empty($config)){
|
||||
$lists[$default['type']] = [
|
||||
'type' => $default['type'],
|
||||
'config' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
if(empty($lists)){
|
||||
$lists = [];
|
||||
}
|
||||
$wayLists = ConfigService::get('withdraw', 'way_list');
|
||||
foreach ($lists as $key => $config)
|
||||
{
|
||||
if(!in_array($config['type'],$wayLists)){
|
||||
unset($lists[$key]);
|
||||
}
|
||||
}
|
||||
return array_values($lists);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取提现方式配置
|
||||
* @param $shopId
|
||||
* @param $type
|
||||
* @return WithdrawConfig|array|\think\Model
|
||||
* @author cjhao
|
||||
* @date 2024/9/26 00:22
|
||||
*/
|
||||
public function getWithDrawWay($shopId,$type)
|
||||
{
|
||||
$detail = WithdrawConfig::where(['relation_id'=>$shopId,'type'=>$type,'source'=>2])
|
||||
->findOrEmpty()->toArray();
|
||||
if(empty($detail)){
|
||||
$detail = [
|
||||
'type' => $type,
|
||||
'config' => [],
|
||||
];
|
||||
}
|
||||
switch ($type){
|
||||
case 1:
|
||||
$detail['config']['name'] = $detail['config']['name'] ?? '';
|
||||
$detail['config']['mobile'] = $detail['config']['mobile'] ?? '';
|
||||
break;
|
||||
case 2:
|
||||
$detail['config']['name'] = $detail['config']['name'] ?? '';
|
||||
$detail['config']['account'] = $detail['config']['account'] ?? '';
|
||||
break;
|
||||
case 3:
|
||||
$detail['config']['name'] = $detail['config']['name'] ?? '';
|
||||
$detail['config']['bank'] = $detail['config']['bank'] ?? '';
|
||||
$detail['config']['bank_card'] = $detail['config']['bank_card'] ?? '';
|
||||
break;
|
||||
}
|
||||
return $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 设置提现方式
|
||||
* @param $shopId
|
||||
* @param $post
|
||||
* @return string|true
|
||||
* @author cjhao
|
||||
* @date 2024/9/26 11:36
|
||||
*/
|
||||
public function setWithDrawWay($shopId,$post)
|
||||
{
|
||||
$type = $post['type'] ?? '';
|
||||
if(empty($type)){
|
||||
return '提现配置错误';
|
||||
}
|
||||
switch ($type){
|
||||
case 1:
|
||||
$name = $post['config']['name'] ?? '';
|
||||
$mobile = $post['config']['mobile'] ?? '';
|
||||
if(empty($name)){
|
||||
return '请输入名称';
|
||||
}
|
||||
if(empty($mobile)){
|
||||
return '请输入手机号码';
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
$name = $post['config']['name'] ?? '';
|
||||
$account = $post['config']['account'] ?? '';
|
||||
if(empty($name)){
|
||||
return '请输入名称';
|
||||
}
|
||||
if(empty($account)){
|
||||
return '请输入账号';
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
$name = $post['config']['name'] ?? '';
|
||||
$bank = $post['config']['bank'] ?? '';
|
||||
$bankCard = $post['config']['bank_card'] ?? '';
|
||||
if(empty($name)){
|
||||
return '请输入名称';
|
||||
}
|
||||
if(empty($bank)){
|
||||
return '请输入开户名';
|
||||
}
|
||||
if(empty($bankCard)){
|
||||
return '请输入银行卡号';
|
||||
}
|
||||
break;
|
||||
}
|
||||
$post['shop_id'] = $shopId;
|
||||
$config = WithdrawConfig::where(['type'=>$type,'relation_id'=>$shopId,'source'=>2])->findOrEmpty();
|
||||
if($config->isEmpty()){
|
||||
WithdrawConfig::create([
|
||||
'relation_id' => $shopId,
|
||||
'type' => $type,
|
||||
'config' => $post['config'],
|
||||
'source' => 2,
|
||||
]);
|
||||
}else{
|
||||
$config->config = $post['config'];
|
||||
$config->save();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 提现信息
|
||||
* @param int $coachId
|
||||
* @return array
|
||||
* @author cjhao
|
||||
* @date 2024/10/29 17:54
|
||||
*/
|
||||
public function getWithdrawInfo(int $shopId){
|
||||
|
||||
$lists = WithdrawConfig::where(['relation_id'=>$shopId,'source'=>2])
|
||||
->column('type,config','type');
|
||||
$configDefault = [
|
||||
[
|
||||
'type' => 1,
|
||||
],
|
||||
[
|
||||
'type' => 2,
|
||||
],
|
||||
[
|
||||
'type' => 3,
|
||||
],
|
||||
];
|
||||
foreach ($configDefault as $default){
|
||||
$config = $lists[$default['type']] ?? [];
|
||||
if(empty($config)){
|
||||
$lists[$default['type']] = [
|
||||
'type' => $default['type'],
|
||||
'config' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
if(empty($lists)){
|
||||
$lists = [];
|
||||
}
|
||||
$wayLists = ConfigService::get('withdraw', 'way_list');
|
||||
foreach ($lists as $key => $config)
|
||||
{
|
||||
if(!in_array($config['type'],$wayLists)){
|
||||
unset($lists[$key]);
|
||||
}
|
||||
}
|
||||
$config = [
|
||||
'way_list' => array_values($lists),
|
||||
'min_money' => ConfigService::get('withdraw', 'min_money'),
|
||||
'max_money' => ConfigService::get('withdraw', 'max_money'),
|
||||
'service_charge' => ConfigService::get('withdraw', 'service_charge'),
|
||||
'money' => Shop::where(['id'=>$shopId])->value('money'),
|
||||
'deposit' => Shop::where(['id'=>$shopId])->value('deposit'),
|
||||
'withdraw_cycle_type' => ConfigService::get('withdraw', 'withdraw_cycle_type'),
|
||||
'withdraw_cycle_date' => ConfigService::get('withdraw', 'withdraw_cycle_date'),
|
||||
];
|
||||
$tips = '';
|
||||
if($config['withdraw_cycle_type']){
|
||||
// $dayOfWeek = date('w'); // 注意:'w'返回的是数字,其中0表示周日,6表示周六
|
||||
// $dayOfWeek = $dayOfWeek === 0 ? 7 : $dayOfWeek;
|
||||
$weekDay = getWeekdayByNumber($config['withdraw_cycle_date']);
|
||||
$tips = "平台设置每".$weekDay."可提现";
|
||||
}else{
|
||||
// 获取今天的日期(几号)
|
||||
// $dayOfMonth = date('j'); // 'j'返回不带前导零的日期
|
||||
$tips = "平台设置每月".$config['withdraw_cycle_date']."号可提现";
|
||||
}
|
||||
$config['tips'] = $tips;
|
||||
return $config;
|
||||
}
|
||||
/**
|
||||
* @notes 提现申请
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author cjhao
|
||||
* @date 2024/9/26 15:15
|
||||
*/
|
||||
public function withdrawalApply($params)
|
||||
{
|
||||
try {
|
||||
Db::startTrans();
|
||||
$cycleType = ConfigService::get('withdraw', 'withdraw_cycle_type');
|
||||
$cycleDate = ConfigService::get('withdraw', 'withdraw_cycle_date');
|
||||
$date = new DateTime();
|
||||
if(1 == $cycleType){
|
||||
$dayOfWeek =$date->format('N'); // 1(表示星期一)到 7(表示星期日)
|
||||
if($cycleDate != $dayOfWeek){
|
||||
throw new Exception('提现仅在每周'.getWeekdayByNumber($cycleDate).'可提现');
|
||||
}
|
||||
}else{
|
||||
$dayOfMonth =$date->format('j'); // 1 到 31
|
||||
if($cycleDate != $dayOfMonth){
|
||||
throw new Exception('提现仅在每月'.$cycleDate.'号可提现');
|
||||
}
|
||||
}
|
||||
$coach = Coach::where(['id'=>$params['coach_id']])->findOrEmpty();
|
||||
if($coach->money < $params['money']){
|
||||
throw new Exception('当前可提现金额仅剩:'.$coach->money.'元');
|
||||
}
|
||||
$minMoney = ConfigService::get('withdraw', 'min_money');
|
||||
$maxMoney = ConfigService::get('withdraw', 'max_money');
|
||||
$serviceCharge = ConfigService::get('withdraw', 'service_charge');
|
||||
if($maxMoney < $params['money']){
|
||||
throw new Exception('最高可提现'.$maxMoney.'元');
|
||||
}
|
||||
if($minMoney > $params['money']){
|
||||
throw new Exception('最低提现'.$minMoney.'元');
|
||||
}
|
||||
$applyType = $params['apply_type'];
|
||||
$config = WithdrawConfig::where(['type'=>$applyType,'coach_id'=>$params['coach_id']])->findOrEmpty();
|
||||
if($config->isEmpty()){
|
||||
throw new Exception('请配置提现账户');
|
||||
}
|
||||
$coach->money = round($coach->money - $params['money']);
|
||||
$coach->save();
|
||||
$handlingFee = round( ($params['money'] * $serviceCharge/100),2);
|
||||
(new WithdrawApply())->save([
|
||||
'sn' => generate_sn((new WithdrawApply()), 'sn'),
|
||||
'coach_id' => $params['shop_id'],
|
||||
'type' => $params['apply_type'],
|
||||
'money' => $params['money'],
|
||||
'left_money' => $coach->money,
|
||||
'handling_fee' => $handlingFee,
|
||||
'service_charge' => $serviceCharge,
|
||||
'withdraw_config_snap' => $config
|
||||
]);
|
||||
//提交事务
|
||||
Db::commit();
|
||||
return true;
|
||||
}catch (Exception $e) {
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 提现接口
|
||||
* @param $params
|
||||
* @return string|true
|
||||
* @throws \Exception
|
||||
* @author cjhao
|
||||
* @date 2024/10/30 15:05
|
||||
*/
|
||||
public function apply($params)
|
||||
{
|
||||
try {
|
||||
Db::startTrans();
|
||||
|
||||
$money = $params['money'] ?? 0;
|
||||
$type = $params['type'] ?? '';
|
||||
$applyType = $params['apply_type'] ?? 1;
|
||||
if(empty($type)){
|
||||
throw new Exception('请选择提现账号');
|
||||
}
|
||||
$config = [
|
||||
'min_money' => ConfigService::get('withdraw', 'min_money'),
|
||||
'max_money' => ConfigService::get('withdraw', 'max_money'),
|
||||
'service_charge' => ConfigService::get('withdraw', 'service_charge'),
|
||||
'withdraw_cycle_type' => ConfigService::get('withdraw', 'withdraw_cycle_type'),
|
||||
'withdraw_cycle_date' => ConfigService::get('withdraw', 'withdraw_cycle_date'),
|
||||
];
|
||||
$withdrawConfig = WithdrawConfig::where(['relation_id'=>$params['shop_id'],'source'=>2,'type'=>$type])
|
||||
->value('config');
|
||||
if(empty($withdrawConfig)){
|
||||
throw new Exception('请先配置提现账号信息');
|
||||
}
|
||||
if($config['withdraw_cycle_type']){
|
||||
$dayOfWeek = date('w'); // 注意:'w'返回的是数字,其中0表示周日,6表示周六
|
||||
if($config['withdraw_cycle_date'] != $dayOfWeek){
|
||||
$weekDay = getWeekdayByNumber($config['withdraw_cycle_date']);
|
||||
throw new Exception('请在每'.$weekDay.'来申请提现');
|
||||
}
|
||||
}else{
|
||||
// 获取今天的日期(几号)
|
||||
$dayOfMonth = date('j'); // 'j'返回不带前导零的日期
|
||||
if($config['withdraw_cycle_date'] != $dayOfMonth){
|
||||
throw new Exception('请在每月'.$dayOfMonth.'号来申请提现');
|
||||
}
|
||||
}
|
||||
$shop = shop::where(['id'=> $params['shop_id']])->findOrEmpty();
|
||||
$shopMoney = $shop->money;
|
||||
if(2 == $applyType){
|
||||
$shopMoney = $shop->deposit;
|
||||
}
|
||||
if($shopMoney< $money){
|
||||
throw new Exception('当前可提现余额仅剩'.$shopMoney);
|
||||
}
|
||||
if($money < $config['min_money']){
|
||||
throw new Exception('最小提现额度不能小于'.$config['min_money']);
|
||||
}
|
||||
if($money > $config['max_money']){
|
||||
throw new Exception('最大提现额度不能小于'.$config['max_money']);
|
||||
}
|
||||
$serviceFree = 0;
|
||||
if(1 == $applyType){
|
||||
//手续费
|
||||
$serviceFree = round($money*($config['service_charge']/100),2);
|
||||
}
|
||||
//手续费
|
||||
// $serviceFree = round($money*($config['service_charge']/100),2);
|
||||
//提现操作
|
||||
$withdrawApply = WithdrawApply::create([
|
||||
'sn' => generate_sn((new WithdrawApply()), 'sn', 20),
|
||||
'relation_id' => $params['shop_id'],
|
||||
'source' => 2,
|
||||
'type' => $type,
|
||||
'money' => $money,
|
||||
'apply_type' => $applyType,
|
||||
'left_money' => round($money - $serviceFree,2),
|
||||
'handling_fee' => $serviceFree,
|
||||
'service_charge' => $config['service_charge'],
|
||||
'withdraw_config_snap' => $withdrawConfig,
|
||||
]);
|
||||
if(1 == $applyType){
|
||||
$shop->money = round($shop->money - $money,2);
|
||||
$shop->save();
|
||||
ShopAccountLogLogic::add(
|
||||
$shop->id,
|
||||
ShopAccountLogEnum::MONEY,
|
||||
ShopAccountLogEnum::WITHDRAW_DEC_MONEY,
|
||||
2,
|
||||
$money,
|
||||
$withdrawApply['sn'],
|
||||
);
|
||||
}else{
|
||||
$shop->deposit = round($shop->deposit - $money,2);
|
||||
$shop->save();
|
||||
ShopAccountLogLogic::add(
|
||||
$shop->id,
|
||||
ShopAccountLogEnum::DEPOSIT,
|
||||
ShopAccountLogEnum::WITHDRAW_DEC_DEPOSIT,
|
||||
2,
|
||||
$money,
|
||||
$withdrawApply['sn'],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Db::commit();
|
||||
|
||||
return true;
|
||||
}catch (Exception $e){
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 详情
|
||||
* @param $id
|
||||
* @return WithdrawApply|array|\think\Model
|
||||
* @author cjhao
|
||||
* @date 2024/10/31 09:08
|
||||
*/
|
||||
public function detail($id,$shopId)
|
||||
{
|
||||
$detail = WithdrawApply::where(['id'=>$id,'source'=>2,'relation_id'=>$shopId])
|
||||
->append(['status_desc','type_desc'])
|
||||
->withoutField('delete_time')
|
||||
->findOrEmpty()->toArray();
|
||||
return $detail;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user