diff --git a/app/Constants/v3/OrderState.php b/app/Constants/v3/OrderState.php index 718dffc..af1ff7c 100644 --- a/app/Constants/v3/OrderState.php +++ b/app/Constants/v3/OrderState.php @@ -75,6 +75,14 @@ class OrderState extends AbstractConstants */ const REFUND = [self::REFUNDING, self::REFUNDED, self::REFUND_REFUSE]; + /** + * @Message("可删除") + */ const CAN_DEL = [self::COMPLETED, self::EVALUATED, self::CANCELED, self::REFUNDED, self::REFUND_REFUSE]; + /** + * @Message("可强行退款") + */ + const CAN_REFUND_DIRECT = [self::COMPLETED, self::EVALUATED, self::REFUND_REFUSE]; + } \ No newline at end of file diff --git a/app/Controller/v3/OrderOnlineController.php b/app/Controller/v3/OrderOnlineController.php index 1d6397a..7f90422 100644 --- a/app/Controller/v3/OrderOnlineController.php +++ b/app/Controller/v3/OrderOnlineController.php @@ -91,9 +91,11 @@ class OrderOnlineController extends BaseController ['user_id','=',$userId], ['is_default','=',1], ]) - ->select('id') ->first(); - $res['location'] = $this->userAddressService->getAddressAndDistributionPrice($address->id,$marketId); + $res['location'] = [ + 'address' => $address, + 'distribution_price' => 0 + ]; //返回预约送达时间 数组 $res['appointment_time'] = $this->appointmentTimeService->do(); // diff --git a/app/JsonRpc/OrderService.php b/app/JsonRpc/OrderService.php index e10ffc3..0e662a1 100644 --- a/app/JsonRpc/OrderService.php +++ b/app/JsonRpc/OrderService.php @@ -5,7 +5,10 @@ namespace App\JsonRpc; use App\Commons\Log; use App\Constants\v3\ErrorCode; use App\Constants\v3\LogLabel; +use App\Constants\v3\OrderState; use App\Exception\ErrorCodeException; +use App\Model\v3\Order; +use App\Model\v3\OrderMain; use App\Service\v3\Interfaces\OrderOnlineServiceInterface; use App\Service\v3\Interfaces\SeparateAccountsServiceInterface; use Hyperf\DbConnection\Db; @@ -68,12 +71,13 @@ class OrderService implements OrderServiceInterface } /** - * 线上订单退款,整个订单退 + * 线上订单退款,整个订单退,这个是专门用于处理用户的申请退款的同意退款操作 * @param $global_order_id * @param $user_id * @return array */ - public function onlineRefund($global_order_id, $user_id){ + public function onlineRefund($global_order_id, $user_id) + { Db::beginTransaction(); try { @@ -94,4 +98,62 @@ class OrderService implements OrderServiceInterface } } + + /** + * 线上订单单笔退款,主要用于后台强行操作退单退款 + * 支持单商品、单店、整单 + * 按比例计算红包进行退款 + * 比如:两个子订单和子订单商品,分别是2元,98元,使用了10元优惠券 + * 退2元商品时,退款金额为 + * 红包 :(2/(98+2))*10 = 0.2 + * 退款:2-0.2=1.8元 + * @param $user_id *用户ID + * @param $global_order_id *全局总订单ID + * @param $child_order_id *主订单ID, + * @param $order_goods_id *订单商品ID + * @param $note + */ + public function onlineSingleRefund($user_id, $note, $global_order_id, $child_order_id=null, $order_goods_id=null) + { + if (!$user_id || !$global_order_id || !$note) { + $this->log->event(LogLabel::ORDER_REFUND_LOG, [ + 'jsonrpc_order_service_exception_onlineSingleRefund' => '参数不对', + 'params' => json([$global_order_id, $user_id, $note]) + ]); + throw new ErrorCodeException(ErrorCode::ORDER_REFUND_FAIL); + } + + // 主订单 + $orderMain = OrderMain::query() + ->where(['global_order_id' => $global_order_id]) + ->whereIn('state', OrderState::CAN_REFUND_DIRECT) + ->first(); + + if (empty($orderMain)) { + $this->log->event(LogLabel::ORDER_REFUND_LOG, [ + 'jsonrpc_order_service_exception_onlineSingleRefund' => '订单不存在', + 'params' => json([$global_order_id, $user_id, $note]) + ]); + throw new ErrorCodeException(ErrorCode::ORDER_REFUND_FAIL); + } + + // 子订单 + if ($child_order_id) { + $orderChild = Order::query()->where(['order_main_id' => $orderMain->global_order_id])->first(); + } + + // 单商品退 + if ($order_goods_id) { + if (!$child_order_id) { + $this->log->event(LogLabel::ORDER_REFUND_LOG, [ + 'jsonrpc_order_service_exception_onlineSingleRefund' => '参数不对[单品]', + 'params' => json([$global_order_id, $user_id, $note, $child_order_id]) + ]); + throw new ErrorCodeException(ErrorCode::ORDER_REFUND_FAIL); + } + + + } + + } } \ No newline at end of file diff --git a/app/Model/v3/Category.php b/app/Model/v3/Category.php index 7c3eaa6..1dda811 100644 --- a/app/Model/v3/Category.php +++ b/app/Model/v3/Category.php @@ -21,9 +21,7 @@ class Category extends Model protected $table = 'lanzu_category'; protected $appends = [ - 'goods_types', - 'cover_url', - 'goods_category_ids', + 'cover_url' ]; protected function boot(): void @@ -34,18 +32,18 @@ class Category extends Model }); } - public function getGoodsTypesAttribute() + public function getCoverUrlAttribute() { - return self::query()->where(['parent_id' => $this->attributes['id']])->orderBy('sort', 'desc')->get()->toArray(); + return $this->attachmentService->switchImgToAliOss($this->attributes['cover_img']); } - public function getGoodsCategoryIdsAttribute() + public function goodsTypes() { - return GoodsCategory::query()->where(['category_id' => $this->attributes['id']])->orderBy('sort', 'desc')->pluck('id'); + return $this->hasMany(self::class, 'parent_id', 'id')->with('goodsCategory'); } - - public function getCoverUrlAttribute() + + public function goodsCategory() { - return $this->attachmentService->switchImgToAliOss($this->attributes['cover_img']); + return $this->hasMany(GoodsCategory::class, 'category_id', 'id'); } } \ No newline at end of file diff --git a/app/Model/v3/Goods.php b/app/Model/v3/Goods.php index 2c110c2..c0718cb 100644 --- a/app/Model/v3/Goods.php +++ b/app/Model/v3/Goods.php @@ -92,16 +92,6 @@ class Goods extends Model return $this->attachmentService->switchImgToAliOss($value); } - public function getTagsAttribute($value) - { - if($value){ - $value = str_replace('"','',$value); - $value = explode(',',$value); - return $value; - } - return $value; - } - public function getMonthSalesAttribute() { $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); diff --git a/app/Model/v3/OrderMain.php b/app/Model/v3/OrderMain.php index 9d4f06b..01134a4 100644 --- a/app/Model/v3/OrderMain.php +++ b/app/Model/v3/OrderMain.php @@ -56,6 +56,10 @@ class OrderMain extends Model 'shipping_type_text', ]; + protected $casts = [ + 'global_order_id' => 'string' + ]; + public function getCreatedAtTextAttribute() { return date('Y-m-d H:i:s', $this->attributes['created_at']); @@ -99,7 +103,7 @@ class OrderMain extends Model Order::class, 'order_main_id', 'order_id', - 'id', + 'global_order_id', 'id' ); } diff --git a/app/Model/v3/ShoppingCart.php b/app/Model/v3/ShoppingCart.php index b07b814..e1d246c 100644 --- a/app/Model/v3/ShoppingCart.php +++ b/app/Model/v3/ShoppingCart.php @@ -3,10 +3,11 @@ namespace App\Model\v3; use App\Model\Model; +use Hyperf\Database\Model\SoftDeletes; class ShoppingCart extends Model { - + use SoftDeletes; protected $table = 'lanzu_shopping_cart'; protected $fillable = [ diff --git a/app/Request/v3/SearchGoodsRequest.php b/app/Request/v3/SearchGoodsRequest.php index 7b85add..46ec354 100644 --- a/app/Request/v3/SearchGoodsRequest.php +++ b/app/Request/v3/SearchGoodsRequest.php @@ -16,7 +16,8 @@ class SearchGoodsRequest extends BaseFormRequest { return [ 'market_id' => 'required|nonempty|integer', - 'type_id' => 'nonempty|integer', + 'type_id' => 'nonempty', + 'goods_category_ids' => 'nonempty', 'store_id' => 'nonempty|integer', 'keyword' => 'nonempty', 'order_by' => 'nonempty|in:default,sales,price', diff --git a/app/Service/v3/Implementations/CategoryService.php b/app/Service/v3/Implementations/CategoryService.php index 6be32bd..039e532 100644 --- a/app/Service/v3/Implementations/CategoryService.php +++ b/app/Service/v3/Implementations/CategoryService.php @@ -32,7 +32,20 @@ class CategoryService implements CategoryServiceInterface public function all() { - return Category::query()->where(['parent_id' => 0])->get()->toArray(); + $categories = Category::query() + ->with(['goodsTypes']) + ->where(['parent_id' => 0])->get()->toArray(); + + foreach ($categories as $key => &$category) { + foreach ($category['goods_types'] as $key2 => &$item) { + $item['goods_category_ids'] = ''; + if (isset($item['goods_category']) && $item['goods_category']) { + $item['goods_category_ids'] = implode(',', array_values(array_column($item['goods_category'], 'id'))); + } + } + } + + return $categories; } public function allForStore($storeId) diff --git a/app/Service/v3/Implementations/SearchService.php b/app/Service/v3/Implementations/SearchService.php index e1f5c84..6b6a0b1 100644 --- a/app/Service/v3/Implementations/SearchService.php +++ b/app/Service/v3/Implementations/SearchService.php @@ -23,6 +23,11 @@ class SearchService implements \App\Service\v3\Interfaces\SearchServiceInterface if (isset($params['type_id']) && $params['type_id']) { $typeIds = explode(',', $params['type_id']); + $builder->whereIn('category_id', $typeIds); + } + + if (isset($params['goods_category_ids']) && $params['goods_category_ids']) { + $typeIds = explode(',', $params['goods_category_ids']); $builder->whereIn('goods_category_id', $typeIds); }