feat : coupon
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Constants\Common\CouponCode;
|
|||||||
use App\Constants\Common\OrderCode;
|
use App\Constants\Common\OrderCode;
|
||||||
use App\Lib\Log;
|
use App\Lib\Log;
|
||||||
use App\Model\Order;
|
use App\Model\Order;
|
||||||
|
use App\Model\OrderGood;
|
||||||
use App\Model\UserCoupon;
|
use App\Model\UserCoupon;
|
||||||
use App\Service\ServiceTrait\Api\CouponTrait;
|
use App\Service\ServiceTrait\Api\CouponTrait;
|
||||||
use App\Service\ServiceTrait\Api\OrderTrait;
|
use App\Service\ServiceTrait\Api\OrderTrait;
|
||||||
@@ -54,6 +55,12 @@ class CancelOrderConsumer extends ConsumerMessage
|
|||||||
#[Inject]
|
#[Inject]
|
||||||
protected UserCoupon $userCouponModel;
|
protected UserCoupon $userCouponModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var OrderGood
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected OrderGood $orderGoodModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $data
|
* @param $data
|
||||||
* @param AMQPMessage $message
|
* @param AMQPMessage $message
|
||||||
@@ -92,7 +99,11 @@ class CancelOrderConsumer extends ConsumerMessage
|
|||||||
$this->rollbackCoupon($orderType, $orderInfo);
|
$this->rollbackCoupon($orderType, $orderInfo);
|
||||||
|
|
||||||
$orderInfo->status = OrderCode::CANCEL;
|
$orderInfo->status = OrderCode::CANCEL;
|
||||||
if (!$orderInfo->save()) throw new Exception('CancelOrderConsumer:error:orderStatusSaveError:'.json_encode($orderInfo->toArray()));
|
|
||||||
|
$updateGoods = $this->orderGoodModel->where('order_id',$orderInfo->id)->update([
|
||||||
|
'status' => OrderCode::CANCEL,
|
||||||
|
]);
|
||||||
|
if (!$orderInfo->save() || !$updateGoods) throw new Exception('CancelOrderConsumer:error:orderStatusSaveError:'.json_encode($orderInfo->toArray()));
|
||||||
|
|
||||||
Db::commit();
|
Db::commit();
|
||||||
}catch (Exception $e){
|
}catch (Exception $e){
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ use Psr\Container\NotFoundExceptionInterface;
|
|||||||
])]
|
])]
|
||||||
class OrderController extends AbstractController
|
class OrderController extends AbstractController
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
#[RequestMapping(path: "list", methods: "GET")]
|
#[RequestMapping(path: "list", methods: "GET")]
|
||||||
#[Scene(scene: "list")]
|
#[Scene(scene: "list")]
|
||||||
public function list()
|
public function list()
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Model;
|
namespace App\Model;
|
||||||
|
|
||||||
|
use App\Constants\Common\OrderCode;
|
||||||
use Hyperf\DbConnection\Model\Model;
|
use Hyperf\DbConnection\Model\Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,4 +53,15 @@ class OrderGood extends Model
|
|||||||
{
|
{
|
||||||
return $this->where('order_id', $orderId)->select('sku_id')->selectRaw('SUM(`quantity`) as `quantity`')->groupBy('sku_id')->get()->toArray();
|
return $this->where('order_id', $orderId)->select('sku_id')->selectRaw('SUM(`quantity`) as `quantity`')->groupBy('sku_id')->get()->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $orderIds
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function isCateringByOrderIds(array $orderIds): int
|
||||||
|
{
|
||||||
|
return $this->whereIn('order_id', $orderIds)->update([
|
||||||
|
'status' => OrderCode::PLAN
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ abstract class CateringBaseService extends BaseService
|
|||||||
protected int $cycleId;
|
protected int $cycleId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int todo 厨房id 自选的需要
|
* @var int
|
||||||
*/
|
*/
|
||||||
protected int $kitchenId;
|
protected int $kitchenId;
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,11 @@ use App\Constants\Admin\CateringCode;
|
|||||||
use App\Constants\Common\OrderCode;
|
use App\Constants\Common\OrderCode;
|
||||||
use App\Exception\ErrException;
|
use App\Exception\ErrException;
|
||||||
use App\Model\Order;
|
use App\Model\Order;
|
||||||
|
use App\Model\OrderGood;
|
||||||
use App\Model\OrderMealCateringLog;
|
use App\Model\OrderMealCateringLog;
|
||||||
use App\Service\Admin\Catering\CateringBaseService;
|
use App\Service\Admin\Catering\CateringBaseService;
|
||||||
|
use Exception;
|
||||||
|
use Hyperf\DbConnection\Db;
|
||||||
use Hyperf\Di\Annotation\Inject;
|
use Hyperf\Di\Annotation\Inject;
|
||||||
|
|
||||||
class CheckService extends CateringBaseService
|
class CheckService extends CateringBaseService
|
||||||
@@ -38,6 +41,12 @@ class CheckService extends CateringBaseService
|
|||||||
#[Inject]
|
#[Inject]
|
||||||
protected Order $orderModel;
|
protected Order $orderModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var OrderGood
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected OrderGood $orderGoodModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@@ -61,7 +70,10 @@ class CheckService extends CateringBaseService
|
|||||||
|
|
||||||
if (empty($orderIds)) throw new ErrException('数据错误');
|
if (empty($orderIds)) throw new ErrException('数据错误');
|
||||||
|
|
||||||
$this->orderModel->whereIn('id', $orderIds)->update(['status' => OrderCode::PLAN]);
|
// $this->orderModel->whereIn('id', $orderIds)->update(['status' => OrderCode::PLAN]);
|
||||||
|
Db::transaction(function () use ($orderIds) {
|
||||||
|
if (!$this->orderModel->isCateringByOrderIds($orderIds) || !$this->orderGoodModel->isCateringByOrderIds($orderIds)) throw new Exception('修改订单数据状态失败');
|
||||||
|
});
|
||||||
|
|
||||||
return $this->return->success();
|
return $this->return->success();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ class CateringService extends CateringBaseService
|
|||||||
$this->logInfo->status = CateringCode::CATERING_STATUS_FINISH;
|
$this->logInfo->status = CateringCode::CATERING_STATUS_FINISH;
|
||||||
if (!$this->logInfo->save()) throw new Exception('配餐失败1');
|
if (!$this->logInfo->save()) throw new Exception('配餐失败1');
|
||||||
|
|
||||||
if (!$this->orderModel->isCateringByOrderIds($this->orderIds)) throw new Exception('配餐失败2');
|
if (!$this->orderModel->isCateringByOrderIds($this->orderIds) || !$this->orderGoodModel->isCateringByOrderIds($this->orderIds)) throw new Exception('配餐失败2');
|
||||||
|
|
||||||
Db::commit();
|
Db::commit();
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ class CateringService extends CateringBaseService
|
|||||||
$currentDate = date('Y-m-d H:i:s');
|
$currentDate = date('Y-m-d H:i:s');
|
||||||
foreach ($this->orderList as &$order) {
|
foreach ($this->orderList as &$order) {
|
||||||
foreach ($order['copies_list'] as &$copiesItem) {
|
foreach ($order['copies_list'] as &$copiesItem) {
|
||||||
if ($currentCode % $this->printBoxMaxNum === 0) {
|
if ($currentCode / $this->printBoxMaxNum === 0) {
|
||||||
$startCode = $currentCode + 1;
|
$startCode = $currentCode + 1;
|
||||||
$endCode = min($currentCode + $this->printBoxMaxNum, $this->totalCopies);
|
$endCode = min($currentCode + $this->printBoxMaxNum, $this->totalCopies);
|
||||||
$codeGroups = $this->splitArrayIntoPartitions(range($startCode, $endCode));
|
$codeGroups = $this->splitArrayIntoPartitions(range($startCode, $endCode));
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ class SkuService extends BaseService
|
|||||||
$this->updateOssObjects(explode(',',$imageIds));
|
$this->updateOssObjects(explode(',',$imageIds));
|
||||||
|
|
||||||
$insertModel->spu_id = $spuId;
|
$insertModel->spu_id = $spuId;
|
||||||
$insertModel->title = $this->request->input('title');
|
$insertModel->title = $spuInfo->title.$this->request->input('title');
|
||||||
$insertModel->price = $this->request->input('price');
|
$insertModel->price = $this->request->input('price');
|
||||||
$insertModel->image_ids = $imageIds;
|
$insertModel->image_ids = $imageIds;
|
||||||
$insertModel->param = $this->request->input('param','');
|
$insertModel->param = $this->request->input('param','');
|
||||||
|
|||||||
@@ -10,13 +10,145 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Service\Admin\Order;
|
namespace App\Service\Admin\Order;
|
||||||
|
|
||||||
|
use App\Cache\Redis\Api\SiteCache;
|
||||||
|
use App\Model\Order;
|
||||||
|
use App\Model\OrderGood;
|
||||||
|
use App\Model\Sku;
|
||||||
use App\Service\Admin\BaseService;
|
use App\Service\Admin\BaseService;
|
||||||
|
use Hyperf\Di\Annotation\Inject;
|
||||||
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
|
|
||||||
class OrderListService extends BaseService
|
class OrderListService extends BaseService
|
||||||
{
|
{
|
||||||
public function handle()
|
/**
|
||||||
|
* @var Order
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected Order $orderModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var OrderGood
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected OrderGood $orderGoodModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Sku
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected Sku $skuModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var SiteCache
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected SiteCache $siteCache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
|
public function handle(): array
|
||||||
{
|
{
|
||||||
//todo Write logic
|
$limit = (int)$this->request->input('limit', 20);
|
||||||
return $this->return->success();
|
|
||||||
|
//todo where
|
||||||
|
$orderList = $this->orderModel
|
||||||
|
->when($this->request->input('search_user_id'), function ($query) {
|
||||||
|
$query->where('user_id', $this->request->input('search_user_id'));
|
||||||
|
})
|
||||||
|
->when($this->request->input('search_status'), function ($query) {
|
||||||
|
$query->where('status', $this->request->input('search_status'));
|
||||||
|
})
|
||||||
|
->select([
|
||||||
|
'id',
|
||||||
|
'cycle_id',
|
||||||
|
'order_sno',
|
||||||
|
'user_id',
|
||||||
|
'site_id',
|
||||||
|
'copies',
|
||||||
|
'type',
|
||||||
|
'actual_price',
|
||||||
|
'total_price',
|
||||||
|
'status',
|
||||||
|
'create_time',
|
||||||
|
'pay_time'
|
||||||
|
])
|
||||||
|
->orderByDesc('id')
|
||||||
|
->paginate($limit)
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
if (!empty($orderList['data'])) {
|
||||||
|
$this->buildData($orderList['data']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->return->success('success', ['list' => $orderList]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建订单列表数据
|
||||||
|
* @param array $orderList
|
||||||
|
* @return void
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
|
private function buildData(array &$orderList): void
|
||||||
|
{
|
||||||
|
$orderIds = array_column($orderList, 'id');
|
||||||
|
|
||||||
|
$orderSkuList = $this->orderGoodModel->whereIn('order_id', $orderIds)->get()->toArray();
|
||||||
|
$skuIds = [];
|
||||||
|
$newOrderSkuList = [];
|
||||||
|
foreach ($orderSkuList as $orderSku) {
|
||||||
|
if (empty($newOrderSkuList[$orderSku['order_id']])) {
|
||||||
|
$newOrderSkuList[$orderSku['order_id']] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($newOrderSkuList[$orderSku['order_id']][$orderSku['copies']])) {
|
||||||
|
$newOrderSkuList[$orderSku['order_id']][$orderSku['copies']] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$newOrderSkuList[$orderSku['order_id']][$orderSku['copies']][] = $orderSku;
|
||||||
|
|
||||||
|
if (in_array($orderSku['sku_id'], $skuIds)) continue;
|
||||||
|
|
||||||
|
$skuIds[] = $orderSku['sku_id'];
|
||||||
|
}
|
||||||
|
unset($orderSkuList);
|
||||||
|
|
||||||
|
|
||||||
|
$skuList = $this->skuModel->getDataArrByIds($skuIds);
|
||||||
|
$skuList = array_column($skuList, null,'id');
|
||||||
|
|
||||||
|
|
||||||
|
foreach ($orderList as &$order) {
|
||||||
|
$orderCopiesList = [];
|
||||||
|
for ($i = 1; $i <= ($order['copies'] ?? 0); $i++) {
|
||||||
|
|
||||||
|
$oneCopiesInfo = [
|
||||||
|
'total_price' => '0.00',
|
||||||
|
'total_quantity' => 0,
|
||||||
|
'sku_list' => [],
|
||||||
|
'take_food_code' => [], //todo 取餐码
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($newOrderSkuList[$order['id']][$i] as $item) {
|
||||||
|
if ($item['order_id'] != $order['id'] || $item['copies'] != $i) continue;
|
||||||
|
|
||||||
|
$skuInfo = $skuList[$item['sku_id']] ?? [];
|
||||||
|
$oneCopiesInfo['total_price'] = bcadd($oneCopiesInfo['total_price'], bcmul($item['unit_price'],(string)$item['quantity'],2), 2);
|
||||||
|
$oneCopiesInfo['total_quantity'] += $item['quantity'];
|
||||||
|
|
||||||
|
$oneCopiesInfo['sku_list'][] = $skuInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
$orderCopiesList[] = $oneCopiesInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
$order['copies_list'] = $orderCopiesList;
|
||||||
|
$order['site'] = $this->siteCache->getSiteInfo((int)$order['site_id']) ?? [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,10 +49,12 @@ class OrderListService extends BaseService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
*/
|
*/
|
||||||
public function handle(): array
|
public function handle(): array
|
||||||
{
|
{
|
||||||
$limit = $this->request->input('limit', 20);
|
$limit = (int)$this->request->input('limit', 20);
|
||||||
|
|
||||||
$orderList = $this->orderModel
|
$orderList = $this->orderModel
|
||||||
->where('user_id', $this->userId)
|
->where('user_id', $this->userId)
|
||||||
|
|||||||
@@ -170,6 +170,7 @@ class PlaceOrderService extends BaseOrderService
|
|||||||
'is_comment' => OrderCode::GOOD_COMMENT_NULL,
|
'is_comment' => OrderCode::GOOD_COMMENT_NULL,
|
||||||
'copies' => $copiesNum,
|
'copies' => $copiesNum,
|
||||||
'type' => $one['type'],
|
'type' => $one['type'],
|
||||||
|
'status' => OrderCode::WAIT_PAY,
|
||||||
'create_time' => date('Y-m-d H:i:s'),
|
'create_time' => date('Y-m-d H:i:s'),
|
||||||
'update_time' => date('Y-m-d H:i:s'),
|
'update_time' => date('Y-m-d H:i:s'),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -81,7 +81,11 @@ trait GoodOrderTrait
|
|||||||
$this->orderInfo->status = OrderCode::PAYED;
|
$this->orderInfo->status = OrderCode::PAYED;
|
||||||
$this->orderInfo->pay_time = date('Y-m-d H:i:s');
|
$this->orderInfo->pay_time = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
if (!$this->orderInfo->save()) {
|
$updateGoods = $this->orderGoodModel->where('order_id',$this->orderInfo->id)->update([
|
||||||
|
'status' => OrderCode::PAYED,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!$this->orderInfo->save() || !$updateGoods) {
|
||||||
$this->log->debug(__CLASS__.':Function:manageOrder:更新充值订单的状态失败:'.$this->orderInfo->id);
|
$this->log->debug(__CLASS__.':Function:manageOrder:更新充值订单的状态失败:'.$this->orderInfo->id);
|
||||||
throw new ErrException('更新充值订单的状态失败');
|
throw new ErrException('更新充值订单的状态失败');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user