初始版本
This commit is contained in:
207
server/app/coachapi/logic/ShopLogic.php
Executable file
207
server/app/coachapi/logic/ShopLogic.php
Executable file
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
namespace app\coachapi\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\ShopCategoryIndex;
|
||||
use app\common\model\shop\ShopCoachApply;
|
||||
use app\common\service\sms\SmsDriver;
|
||||
use Exception;
|
||||
use think\facade\Config;
|
||||
use think\facade\Db;
|
||||
|
||||
class ShopLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 服务详情
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @author cjhao
|
||||
* @date 2024/10/12 00:27
|
||||
*/
|
||||
public function detail(array $params){
|
||||
|
||||
$detail = Shop::where(['id'=>$params['id'],'audit_status'=>ShopEnum::AUDIT_STATUS_PASS,'server_status'=>ShopEnum::SERVERSTATUSOPEN])
|
||||
->append(['shop_image','category_ids','business_time_desc','province_name','city_name','region_name'])
|
||||
->field('*,round(st_distance_sphere(point('.$params['longitude'].','.$params['latitude'].'),
|
||||
point(longitude, latitude))/1000,2) as distance')
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
|
||||
$detail['distance'] = $detail['distance'].'km';
|
||||
|
||||
$categoryLists = ShopCategoryIndex::alias('SC')
|
||||
->where(['shop_id'=>$params['id'],'is_show'=>1])
|
||||
->join('goods_category GC','SC.category_id = GC.id')
|
||||
->column('GC.name');
|
||||
$detail['category_name'] = implode('|',$categoryLists);
|
||||
return $detail;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 门店申请列表
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author cjhao
|
||||
* @date 2024/10/14 12:41
|
||||
*/
|
||||
public function applyJoin(array $params)
|
||||
{
|
||||
try{
|
||||
$id = $params['id'] ?? '';
|
||||
if(empty($id)){
|
||||
throw new Exception('请选择门店');
|
||||
}
|
||||
if(empty($params['coach_id'])){
|
||||
throw new Exception('请先申请成为技师');
|
||||
}
|
||||
// Db::startTrans();
|
||||
$coach = Coach::where(['id'=>$params['coach_id']])->findOrEmpty();
|
||||
if($coach->shop_id){
|
||||
throw new Exception('您已加入了门店,请勿再申请');
|
||||
}
|
||||
$shopCoachApply = ShopCoachApply::where(['coach_id'=>$params['coach_id'],'audit_status'=>ShopEnum::AUDIT_STATUS_WAIT])
|
||||
->findOrEmpty();
|
||||
if(!$shopCoachApply->isEmpty()){
|
||||
throw new Exception('您的门店申请正在审核中,请勿再申请');
|
||||
}
|
||||
$shop = Shop::where(['id'=>$params['id']])->findOrEmpty();
|
||||
if($coach['city_id'] != $shop['city_id']){
|
||||
throw new Exception('抱歉,只能添加本地的商家哦');
|
||||
}
|
||||
$shopCoachApply = new ShopCoachApply();
|
||||
$shopCoachApply->coach_id = $params['coach_id'];
|
||||
$shopCoachApply->shop_id = $params['id'];
|
||||
$shopCoachApply->type = 1;
|
||||
$shopCoachApply->audit_status = ShopEnum::AUDIT_STATUS_WAIT;
|
||||
$shopCoachApply->save();
|
||||
//提交事务
|
||||
// Db::commit();
|
||||
return true;
|
||||
}catch (Exception $e) {
|
||||
// Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 申请详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author cjhao
|
||||
* @date 2024/10/20 03:43
|
||||
*/
|
||||
public function applyDetail($params)
|
||||
{
|
||||
$coachShopId = Coach::where(['id'=>$params['coach_id']])->value('shop_id');
|
||||
$shop = Shop::where(['id'=>$params['id']])
|
||||
->append(['shop_image','category_ids','region_desc','business_time_desc'])
|
||||
->withoutField('update_time,delete_time')
|
||||
->findOrEmpty()->toArray();
|
||||
|
||||
$shop['type'] = '';
|
||||
$shop['audit_remark'] = '';
|
||||
$shop['audit_status'] = '';
|
||||
//分为已经加入商家
|
||||
if($coachShopId){
|
||||
$shopApply = ShopCoachApply::where(['coach_id'=>$params['coach_id'],'shop_id'=>$coachShopId])
|
||||
->order('id desc')
|
||||
->field('shop_id,type,audit_status,audit_remark')
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
$shop['audit_status'] = $shopApply['audit_status'];
|
||||
$shop['audit_remark'] = $shopApply['audit_remark'];
|
||||
$shop['type'] = $shopApply['type'];
|
||||
|
||||
}else{
|
||||
//没有加入商家
|
||||
$shopApply = ShopCoachApply::where(['coach_id'=>$params['coach_id'],'shop_id'=>$params['id']])
|
||||
->order('id desc')
|
||||
->field('id,shop_id,type,audit_status,audit_remark')
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
$shop['type'] = 1;
|
||||
$shop['audit_status'] = '';
|
||||
$shop['audit_remark'] = '';
|
||||
if($shopApply && 1 == $shopApply['type'] && (ShopEnum::AUDIT_STATUS_REFUSE == $shopApply['audit_status'] || ShopEnum::AUDIT_STATUS_WAIT == $shopApply['audit_status'])){
|
||||
$shop['audit_status'] = $shopApply['audit_status'];
|
||||
$shop['audit_remark'] = $shopApply['audit_remark'];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return $shop;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 取消
|
||||
* @param array $params
|
||||
* @return bool|string
|
||||
* @author cjhao
|
||||
* @date 2024/10/20 23:09
|
||||
*/
|
||||
public function cancel($params){
|
||||
$id = $params['id'] ?? '';
|
||||
if(empty($id)){
|
||||
return '请选择商家';
|
||||
}
|
||||
$shopCoachApply = ShopCoachApply::where(['coach_id'=>$params['coach_id'],'shop_id'=>$params['id']])
|
||||
->order('id desc')
|
||||
->findOrEmpty();
|
||||
if($shopCoachApply->isEmpty()){
|
||||
return '你未申请该商家';
|
||||
}
|
||||
if(ShopEnum::AUDIT_STATUS_WAIT != $shopCoachApply->audit_status){
|
||||
return '商家审核状态已改变';
|
||||
}
|
||||
$shopCoachApply->audit_status = ShopEnum::AUDIT_STATUS_CANCEL;
|
||||
$shopCoachApply->save();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 申请退出
|
||||
* @param int $coachId
|
||||
* @return bool
|
||||
* @author cjhao
|
||||
* @date 2024/11/17 12:57
|
||||
*/
|
||||
public function applyQuit(int $coachId){
|
||||
try{
|
||||
|
||||
// Db::startTrans();
|
||||
$coach = Coach::where(['id'=>$coachId])->findOrEmpty();
|
||||
if(0 == $coach->shop_id){
|
||||
throw new Exception('您未申请门店');
|
||||
}
|
||||
$shopCoachApply = ShopCoachApply::where(['coach_id'=>$coachId,'audit_status'=>ShopEnum::AUDIT_STATUS_WAIT,'type'=>2])
|
||||
->findOrEmpty();
|
||||
if(!$shopCoachApply->isEmpty()){
|
||||
throw new Exception('您的退出请求正在审核中,请勿再申请');
|
||||
}
|
||||
$shopCoachApply = new ShopCoachApply();
|
||||
$shopCoachApply->coach_id = $coachId;
|
||||
$shopCoachApply->shop_id = $coach->shop_id;
|
||||
$shopCoachApply->type = 2;
|
||||
$shopCoachApply->audit_status = ShopEnum::AUDIT_STATUS_WAIT;
|
||||
$shopCoachApply->save();
|
||||
//提交事务
|
||||
// Db::commit();
|
||||
return true;
|
||||
}catch (Exception $e) {
|
||||
// Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user