feat : refund and catering
This commit is contained in:
@@ -8,7 +8,8 @@ class OrderCode
|
||||
* @var int 状态:1=未支付,11=未出,21=出餐,31=已出发,41=待取餐,51=完成,97=未完成退款,98=完成退款,99=取消
|
||||
*/
|
||||
CONST int WAIT_PAY = 1; //待支付
|
||||
CONST int PAYED = 11; //已支付待出餐
|
||||
CONST int PAYED = 11; //已支付待写入配餐数据
|
||||
CONST int WAIT_CATERING = 16; //已支付待出餐
|
||||
CONST int PLAN = 21; //出餐未出发
|
||||
CONST int DEPART = 31; //已出发
|
||||
CONST int ARRIVE = 41; // 已送达(待取餐)
|
||||
@@ -22,6 +23,7 @@ class OrderCode
|
||||
*/
|
||||
const array CAN_REFUND_STATUS = [
|
||||
self::PAYED,
|
||||
self::WAIT_CATERING,
|
||||
self::PLAN,
|
||||
self::DEPART,
|
||||
self::ARRIVE,
|
||||
|
||||
51
app/Model/OrderMealCateringLog.php
Normal file
51
app/Model/OrderMealCateringLog.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use Hyperf\Database\Model\Builder;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $cycle_id
|
||||
* @property int $site_id
|
||||
* @property int $sku_id
|
||||
* @property int $quantity
|
||||
* @property int $status
|
||||
* @property string $create_time
|
||||
* @property string $update_time
|
||||
*/
|
||||
class OrderMealCateringLog extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'order_meal_catering_log';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = [];
|
||||
protected array $guarded = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*/
|
||||
protected array $casts = ['id' => 'integer', 'cycle_id' => 'integer', 'site_id' => 'integer', 'sku_id' => 'integer', 'quantity' => 'integer', 'status' => 'integer'];
|
||||
|
||||
const string CREATED_AT = 'create_time';
|
||||
const string UPDATED_AT = 'update_time';
|
||||
|
||||
/**
|
||||
* @param int $siteId
|
||||
* @param int $cycleId
|
||||
* @param int $skuId
|
||||
* @return Builder|\Hyperf\Database\Model\Model|null
|
||||
*/
|
||||
public function getInfoBySiteIdAndCycleIdAndSkuId(int $siteId, int $cycleId,int $skuId): \Hyperf\Database\Model\Model|Builder|null
|
||||
{
|
||||
return $this->where('site_id', $siteId)->where('cycle_id', $cycleId)->where('sku_id',$skuId)->first();
|
||||
}
|
||||
}
|
||||
46
app/Model/OrderOptionCateringLog.php
Normal file
46
app/Model/OrderOptionCateringLog.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use Hyperf\Database\Model\Builder;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $cycle_id
|
||||
* @property int $site_id
|
||||
* @property int $quantity
|
||||
* @property int $add_staple_food_num
|
||||
* @property int $status
|
||||
* @property string $create_time
|
||||
* @property string $update_time
|
||||
*/
|
||||
class OrderOptionCateringLog extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'order_option_catering_log';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*/
|
||||
protected array $casts = ['id' => 'integer', 'cycle_id' => 'integer', 'site_id' => 'integer', 'quantity' => 'integer', 'add_staple_food_num' => 'integer', 'status' => 'integer'];
|
||||
|
||||
/**
|
||||
* @param int $siteId
|
||||
* @param int $cycleId
|
||||
* @return Builder|\Hyperf\Database\Model\Model|null
|
||||
*/
|
||||
public function getInfoBySiteIdAndCycleId(int $siteId, int $cycleId): \Hyperf\Database\Model\Model|Builder|null
|
||||
{
|
||||
return $this->where('site_id', $siteId)->where('cycle_id', $cycleId)->first();
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ use Hyperf\DbConnection\Model\Model;
|
||||
* @property string $notify_json
|
||||
* @property string $remark
|
||||
* @property string $reason
|
||||
* @property int $admin_id
|
||||
* @property string $create_time
|
||||
* @property string $update_time
|
||||
*/
|
||||
@@ -45,7 +46,7 @@ class RefundOrder extends Model
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*/
|
||||
protected array $casts = ['id' => 'integer', 'user_id' => 'integer', 'order_type' => 'integer', 'order_id' => 'integer', 'pay_id' => 'integer', 'refund_status' => 'integer', 'refund_type' => 'integer'];
|
||||
protected array $casts = ['id' => 'integer', 'user_id' => 'integer', 'order_type' => 'integer', 'order_id' => 'integer', 'pay_id' => 'integer', 'refund_status' => 'integer', 'refund_type' => 'integer', 'admin_id' => 'integer'];
|
||||
|
||||
const string CREATED_AT = 'create_time';
|
||||
const string UPDATED_AT = 'update_time';
|
||||
|
||||
@@ -45,7 +45,7 @@ class RefundOrderService extends BaseService
|
||||
if ($orderInfo->status != OrderCode::PAYED) throw new ErrException('该订单状态已变更,请勿重复操作,刷新后无法退款请联系客服');
|
||||
|
||||
//立即取消
|
||||
$this->joinRefundQueue($orderId, $type, $orderInfo->amount, '用户主动取消订单');
|
||||
$this->joinRefundQueue($orderId, $type, $orderInfo->actual_price, '用户主动取消订单');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ use App\Service\ServiceTrait\Api\GoodOrderTrait;
|
||||
use App\Service\ServiceTrait\Api\OrderTrait;
|
||||
use App\Service\ServiceTrait\Api\PayFinishTrait;
|
||||
use App\Service\ServiceTrait\Api\RefundOrderTrait;
|
||||
use App\Service\ServiceTrait\CateringTrait;
|
||||
use App\Service\ServiceTrait\Common\OrderChangeStatusTrait;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
@@ -22,7 +24,9 @@ class WxJsRechargeOrderService extends WxJsRechargeBaseService
|
||||
GoodOrderTrait,
|
||||
PayFinishTrait,
|
||||
RefundOrderTrait,
|
||||
OrderTrait;
|
||||
OrderTrait,
|
||||
OrderChangeStatusTrait,
|
||||
CateringTrait;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -55,6 +59,11 @@ class WxJsRechargeOrderService extends WxJsRechargeBaseService
|
||||
*/
|
||||
protected mixed $refundInfo;
|
||||
|
||||
/**
|
||||
* @var bool 是否加入配餐数据
|
||||
*/
|
||||
protected bool $isCatering = true;
|
||||
|
||||
/**
|
||||
* @return ResponseInterface
|
||||
* @throws ContainerExceptionInterface
|
||||
@@ -73,8 +82,13 @@ class WxJsRechargeOrderService extends WxJsRechargeBaseService
|
||||
$this->manageOrder();
|
||||
|
||||
$this->manageWxOrder();
|
||||
//
|
||||
$this->isCatering = $this->manageAddCateringLog();
|
||||
});
|
||||
|
||||
//已经截单 自动退款
|
||||
if (!$this->isCatering) $this->joinRefundQueue($this->orderId,OrderCode::ORDER_TYPE_GOOD,$this->orderInfo->actual_price,'已截单,系统自动退款');
|
||||
|
||||
//todo 发送订阅通知
|
||||
// $this->sendGainCoinMsg();
|
||||
|
||||
@@ -105,6 +119,8 @@ class WxJsRechargeOrderService extends WxJsRechargeBaseService
|
||||
$this->manageRefundOrder();
|
||||
|
||||
$this->manageOrderByRefund();
|
||||
|
||||
$this->manageSubCateringLog();
|
||||
});
|
||||
|
||||
$this->sendStockMq($this->orderInfo->id,$this->orderInfo->status);
|
||||
|
||||
@@ -7,6 +7,9 @@ use App\Constants\Common\PayCode;
|
||||
use App\Constants\Common\RefundCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Order;
|
||||
use App\Model\OrderGood;
|
||||
use App\Model\OrderMealCateringLog;
|
||||
use App\Model\OrderOptionCateringLog;
|
||||
use App\Model\PayOrder;
|
||||
use App\Model\RefundOrder;
|
||||
use Exception;
|
||||
@@ -35,6 +38,24 @@ trait GoodOrderTrait
|
||||
#[Inject]
|
||||
protected RefundOrder $refundOrderModel;
|
||||
|
||||
/**
|
||||
* @var OrderGood
|
||||
*/
|
||||
#[Inject]
|
||||
protected OrderGood $orderGoodModel;
|
||||
|
||||
/**
|
||||
* @var OrderOptionCateringLog
|
||||
*/
|
||||
#[Inject]
|
||||
protected OrderOptionCateringLog $orderOptionCateringLogModel;
|
||||
|
||||
/**
|
||||
* @var OrderMealCateringLog
|
||||
*/
|
||||
#[Inject]
|
||||
protected OrderMealCateringLog $orderMealCateringLogModel;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
@@ -61,8 +82,6 @@ trait GoodOrderTrait
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
@@ -79,5 +98,4 @@ trait GoodOrderTrait
|
||||
throw new ErrException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
163
app/Service/ServiceTrait/CateringTrait.php
Normal file
163
app/Service/ServiceTrait/CateringTrait.php
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\ServiceTrait;
|
||||
|
||||
use App\Constants\Common\OrderCode;
|
||||
use App\Model\OrderMealCateringLog;
|
||||
use App\Model\OrderOptionCateringLog;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
trait CateringTrait
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return bool 添加失败需要退款
|
||||
*/
|
||||
private function manageAddCateringLog(): bool
|
||||
{
|
||||
return match ($this->orderInfo->type) {
|
||||
OrderCode::ORDER_TYPE_MEAL => $this->manageAddMealCateringLog(),
|
||||
OrderCode::ORDER_TYPE_OPTIONAL => $this->manageAddOptionCateringLog(),
|
||||
default => true,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void 减少失败不影响退款数据
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
private function manageSubCateringLog(): void
|
||||
{
|
||||
match ($this->orderInfo->type) {
|
||||
OrderCode::ORDER_TYPE_MEAL => $this->manageSubMealCateringLog(),
|
||||
OrderCode::ORDER_TYPE_OPTIONAL => $this->manageSubOptionCateringLog(),
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
private function manageSubOptionCateringLog(): void
|
||||
{
|
||||
// todo 减少可以不减少根据订单 cycle_id 获取加一碗米饭 的数量 减少查询压力
|
||||
// $addStapleFoodNum = 0;
|
||||
|
||||
$logInfo = $this->orderOptionCateringLogModel->getInfoBySiteIdAndCycleId($this->orderInfo->site_id, $this->orderInfo->cycle_id);
|
||||
|
||||
if (empty($logInfo)) {
|
||||
$this->log->error(__CLASS__.':Function:refundCallBackHandle:manageSubOptionCateringLog:订单套餐配餐记录不存在,订单信息:'.json_encode($this->orderInfo->toArray()));
|
||||
return;
|
||||
}
|
||||
|
||||
if ($logInfo->status == 2) {
|
||||
$this->log->error(__CLASS__.':Function:refundCallBackHandle:manageSubOptionCateringLog:已经截单不需要修改,订单信息:'.json_encode($this->orderInfo->toArray()));
|
||||
return;
|
||||
}
|
||||
|
||||
$logInfo->quantity = $logInfo->quantity + $this->orderInfo->copies;
|
||||
// $logInfo->add_staple_food_num = $this->orderInfo->add_staple_food_num - $addStapleFoodNum;
|
||||
|
||||
if (!$logInfo->save()) {
|
||||
$this->log->error(__CLASS__.':Function:refundCallBackHandle:manageSubOptionCateringLog:修改配餐记录失败,订单信息:'.json_encode($this->orderInfo->toArray()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
private function manageSubMealCateringLog(): void
|
||||
{
|
||||
$orderGoods = $this->orderGoodModel->where('order_id',$this->orderInfo->id)->pluck('copies','sku_id')->toArray();
|
||||
|
||||
foreach ($orderGoods as $key => $orderGood) {
|
||||
$logInfo = $this->orderMealCateringLogModel->getInfoBySiteIdAndCycleIdAndSkuId($this->orderInfo->site_id,$this->orderInfo->cycle_id,(int)$key);
|
||||
|
||||
if (empty($logInfo)) {
|
||||
$this->log->error(__CLASS__.':Function:refundCallBackHandle:manageSubMealCateringLog:订单套餐配餐记录不存在,订单信息:'.json_encode($this->orderInfo->toArray()).':订单商品信息:'.json_encode($orderGoods));
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($logInfo->status == 2) {
|
||||
$this->log->error(__CLASS__.':Function:refundCallBackHandle:manageSubMealCateringLog:已经截单不需要修改,订单信息:'.json_encode($this->orderInfo->toArray()).':订单商品信息:'.json_encode($orderGoods));
|
||||
continue;
|
||||
}
|
||||
|
||||
$logInfo->quantity = $logInfo->quantity - $orderGood;
|
||||
|
||||
if (!$logInfo->save()) {
|
||||
$this->log->error(__CLASS__.':Function:refundCallBackHandle:manageSubMealCateringLog:修改配餐记录失败,订单信息:'.json_encode($this->orderInfo->toArray()).':订单商品信息:'.json_encode($orderGoods));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加自选配餐数据
|
||||
* @return bool
|
||||
*/
|
||||
private function manageAddOptionCateringLog(): bool
|
||||
{
|
||||
//todo 根据订单 cycle_id 获取加一碗米饭 的数量
|
||||
$addStapleFoodNum = 0;
|
||||
|
||||
$logInfo = $this->orderOptionCateringLogModel->getInfoBySiteIdAndCycleId($this->orderInfo->site_id, $this->orderInfo->cycle_id);
|
||||
|
||||
if (empty($logInfo)) {
|
||||
$logInfo = new OrderOptionCateringLog();
|
||||
|
||||
$logInfo->site_id = $this->orderInfo->site_id;
|
||||
$logInfo->cycle_id = $this->orderInfo->cycle_id;
|
||||
$logInfo->quantity = 0;
|
||||
$logInfo->add_staple_food_num = 0;
|
||||
$logInfo->status = 1;
|
||||
}
|
||||
|
||||
if ($logInfo->status == 2) return false;
|
||||
|
||||
$logInfo->quantity = $logInfo->quantity + $this->orderInfo->copies;
|
||||
$logInfo->add_staple_food_num = $this->orderInfo->add_staple_food_num + $addStapleFoodNum;
|
||||
|
||||
if (!$logInfo->save()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加套餐配餐数据
|
||||
* @return bool
|
||||
*/
|
||||
private function manageAddMealCateringLog(): bool
|
||||
{
|
||||
$orderGoods = $this->orderGoodModel->where('order_id',$this->orderInfo->id)->pluck('copies','sku_id')->toArray();
|
||||
|
||||
foreach ($orderGoods as $key => $orderGood) {
|
||||
$logInfo = $this->orderMealCateringLogModel->getInfoBySiteIdAndCycleIdAndSkuId($this->orderInfo->site_id,$this->orderInfo->cycle_id,(int)$key);
|
||||
|
||||
if (empty($logInfo)) {
|
||||
$logInfo = new OrderMealCateringLog();
|
||||
|
||||
$logInfo->site_id = $this->orderInfo->site_id;
|
||||
$logInfo->cycle_id = $this->orderInfo->cycle_id;
|
||||
$logInfo->sku_id = (int)$key;
|
||||
$logInfo->quantity = 0;
|
||||
$logInfo->status = 1;
|
||||
}
|
||||
|
||||
if ($logInfo->status == 2) return false;
|
||||
|
||||
$logInfo->quantity = $logInfo->quantity + $orderGood;
|
||||
|
||||
if (!$logInfo->save()) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
47
env.local
Normal file
47
env.local
Normal file
@@ -0,0 +1,47 @@
|
||||
# [app] -- 集群配置需一致
|
||||
APP_NAME=hhl_meal
|
||||
APP_ENV=dev
|
||||
API_RETURN_KEY=hhl@shenzhen
|
||||
JWT_KEY=hhl@shenzhen
|
||||
JWT_EXPIRE=2592000
|
||||
ADMIN_JWT_EXPIRE=86400
|
||||
|
||||
# [crontab] -- 集群配置 仅需一台true即可 其他都是false 根据 restart_pre.sh 自动生成
|
||||
CRONTAB_ENABLE=false
|
||||
|
||||
# [mysql] -- 集群配置需一致
|
||||
DB_DRIVER=mysql
|
||||
DB_HOST=192.168.15.68
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=hhl_meal
|
||||
DB_USERNAME=hhl
|
||||
DB_PASSWORD=hhltest
|
||||
DB_CHARSET=utf8mb4
|
||||
DB_COLLATION=utf8mb4_unicode_ci
|
||||
DB_PREFIX=app_
|
||||
|
||||
# [redis] -- 集群配置需一致
|
||||
REDIS_HOST=192.168.15.68
|
||||
REDIS_AUTH=hhltest
|
||||
REDIS_PORT=6379
|
||||
REDIS_DB=0
|
||||
SYSTEM_REDIS_DB=1
|
||||
LOCK_REDIS_DB=2
|
||||
|
||||
# [rabbitmq] -- 集群配置需一致
|
||||
AMQP_HOST=192.168.15.68
|
||||
AMQP_PORT=5672
|
||||
AMQP_USER=admin
|
||||
AMQP_PASSWORD=123456
|
||||
AMQP_VHOST=/
|
||||
|
||||
# [ali] -- 集群配置需一致
|
||||
ALI_ACCESS_KEY_ID=LTAI5tFsBsKskcrRmkjpMXay
|
||||
ALI_ACCESS_KEY_SECRET=YSIMtOGLu7W8tpQLKdgioTUYmgXB8M
|
||||
ALI_BUCKET=hhl-catering
|
||||
ALI_REGION=cn-shenzhen
|
||||
ALI_CALLBACK_URL=https://new-api-pre.hehele.cc/common/oss/ossCallBack
|
||||
ALI_OSS_URL=https://hhl-catering.oss-cn-shenzhen.aliyuncs.com/
|
||||
ALI_STS_ENDPOINT=sts.cn-shenzhen.aliyuncs.com
|
||||
ALI_ROLE_ARN=acs:ram::1644087445786901:role/oss
|
||||
ALI_OSS_ENDPOINT=oss-cn-shenzhen.aliyuncs.com
|
||||
Reference in New Issue
Block a user