初始版本
This commit is contained in:
164
server/app/api/validate/PlaceOrderValidate.php
Executable file
164
server/app/api/validate/PlaceOrderValidate.php
Executable file
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\validate;
|
||||
|
||||
|
||||
use app\common\enum\GoodsEnum;
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\user\UserTerminalEnum;
|
||||
use app\common\logic\CoachLogic;
|
||||
use app\common\model\coach\Coach;
|
||||
use app\common\model\goods\Goods;
|
||||
use app\common\model\user\User;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
class PlaceOrderValidate extends BaseValidate
|
||||
{
|
||||
protected $rule = [
|
||||
// 'terminal' => 'require|in:' . UserTerminalEnum::WECHAT_MMP . ',' . UserTerminalEnum::WECHAT_OA . ','
|
||||
// . UserTerminalEnum::H5 . ',' . UserTerminalEnum::PC . ',' . UserTerminalEnum::IOS .
|
||||
// ',' . UserTerminalEnum::ANDROID,
|
||||
'action' => 'require',// 下单动作(结算/下单)
|
||||
'goods' => 'require|array|checkGoods',// 下单服务
|
||||
'trip_way' => 'requireIf:action,sumbit|in:'.OrderEnum::TRIP_WAY_TAXI.','.OrderEnum::TRIP_WAY_BUS,
|
||||
'coach_id' => 'requireIf:action,sumbit|checkCoach',
|
||||
'appoint_time' => 'requireIf:action,sumbit|checkAppoint',// 预约时间
|
||||
'address_id' => 'requireIf:action,sumbit|checkAddress',
|
||||
// 'pay_way' => 'requireIf:action,sumbit',
|
||||
];
|
||||
|
||||
|
||||
protected $message = [
|
||||
'user_id.require' => '参数缺失',
|
||||
'action.require' => '下单动作缺失',
|
||||
'goods.require' => '缺失下单服务信息',
|
||||
'goods.array' => '下单服务信息格式不正确',
|
||||
'trip_way.requireIf' => '请选择出行方式',
|
||||
'trip_way.in' => '出行方式错误',
|
||||
'coach_id.requireIf' => '请选择技师',
|
||||
'appoint_time.requireIf' => '请选择预约时间',
|
||||
'address_id.requireIf' => '请选择地址',
|
||||
'terminal.require' => '终端参数缺失',
|
||||
'terminal.in' => '终端参数状态值不正确',
|
||||
'pay_way.requireIf' => '请选择支付方式',
|
||||
// 'appoint_time_start.require' => '请选择预约上门开始时间',
|
||||
// 'appoint_time_end.require' => '请选择预约上门结束时间',
|
||||
];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @notes 验证下单服务信息
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author ljj
|
||||
* @date 2022/2/24 5:01 下午
|
||||
*/
|
||||
public function checkGoods($value, $rule, $data)
|
||||
{
|
||||
foreach ($value as $goods){
|
||||
if (!isset($goods['id']) || !isset($goods['goods_num'])) {
|
||||
return '下单服务参数缺失';
|
||||
}
|
||||
$result = Goods::where(['id'=>$goods['id']])->findOrEmpty();
|
||||
if ($result->isEmpty()) {
|
||||
return '下单服务不存在';
|
||||
}
|
||||
if ($result['status'] == GoodsEnum::UNSHELVE) {
|
||||
return '服务已下架';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取预约时间
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return string|true
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author cjhao
|
||||
* @date 2024/9/9 14:45
|
||||
*/
|
||||
public function checkAppoint($value,$rule,$data)
|
||||
{
|
||||
if('sumbit' != $data['action']){
|
||||
return true;
|
||||
}
|
||||
$dateMd = date('m-d',$value);
|
||||
$dateHi = date('H:i',$value);
|
||||
$coachOrderAppoint = CoachLogic::getCoachServerTime($data['coach_id']);
|
||||
$dateMdOrderAppoint = $coachOrderAppoint[$dateMd] ?? [];
|
||||
$dateMdOrderAppoint = array_column($dateMdOrderAppoint,null,'time');
|
||||
$dateTime = $dateMdOrderAppoint[$dateHi] ?? [];
|
||||
if(empty($dateTime)){
|
||||
return '预约时间段错误';
|
||||
}
|
||||
if(3 == $dateTime['status']){
|
||||
return '当前时段已被预约';
|
||||
}
|
||||
if(2 == $dateTime['status']){
|
||||
return '当前时段技师在休息';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkAddress($value,$rule,$data)
|
||||
{
|
||||
if(empty($value) && 'sumbit' == $data['action']){
|
||||
return '请选择地址';
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 验证技师
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return string|true
|
||||
* @author cjhao
|
||||
* @date 2024/9/9 15:00
|
||||
*/
|
||||
public function checkCoach($value,$rule,$data)
|
||||
{
|
||||
if('sumbit' != $data['action']){
|
||||
return true;
|
||||
}
|
||||
$coach = Coach::where(['id'=>$value])->findOrEmpty();
|
||||
if($coach->isEmpty()){
|
||||
return '技师不存在';
|
||||
}
|
||||
if(0 == $coach->work_status){
|
||||
return '技师休息中';
|
||||
}
|
||||
if(0 == $coach->server_status){
|
||||
return '技师已停止服务';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user