Browse Source

分类

master
weigang 5 years ago
parent
commit
3bd4068a48
  1. 39
      app/JsonRpc/OrderService.php
  2. 18
      app/Model/v3/Category.php
  3. 2
      app/Model/v3/OrderMain.php
  4. 2
      app/Request/v3/SearchGoodsRequest.php
  5. 15
      app/Service/v3/Implementations/CategoryService.php

39
app/JsonRpc/OrderService.php

@ -6,6 +6,8 @@ use App\Commons\Log;
use App\Constants\v3\ErrorCode; use App\Constants\v3\ErrorCode;
use App\Constants\v3\LogLabel; use App\Constants\v3\LogLabel;
use App\Exception\ErrorCodeException; 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\OrderOnlineServiceInterface;
use App\Service\v3\Interfaces\SeparateAccountsServiceInterface; use App\Service\v3\Interfaces\SeparateAccountsServiceInterface;
use Hyperf\DbConnection\Db; use Hyperf\DbConnection\Db;
@ -98,16 +100,49 @@ class OrderService implements OrderServiceInterface
} }
/** /**
* 线上订单单笔退款
* 线上订单单笔退款,主要用于后台强行操作退单退款
* 支持单商品、单店、整单 * 支持单商品、单店、整单
* 按比例计算红包进行退款
* 比如:两个子订单和子订单商品,分别是2元,98元,使用了10元优惠券
* 退2元商品时,退款金额为
* 红包 (2/(98+2)*10 = 0.2
* 退款:2-0.2=1.8
* @param $user_id *用户ID * @param $user_id *用户ID
* @param $global_order_id *全局总订单ID * @param $global_order_id *全局总订单ID
* @param $child_order_id *主订单ID, * @param $child_order_id *主订单ID,
* @param $order_goods_id *订单商品ID * @param $order_goods_id *订单商品ID
* @param $note * @param $note
*/ */
public function onlineSingleRefund($user_id, $global_order_id, $child_order_id, $order_goods_id, $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])->first();
// 子订单
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);
}
}
} }
} }

18
app/Model/v3/Category.php

@ -21,9 +21,7 @@ class Category extends Model
protected $table = 'lanzu_category'; protected $table = 'lanzu_category';
protected $appends = [ protected $appends = [
'goods_types',
'cover_url',
'goods_category_ids',
'cover_url'
]; ];
protected function boot(): void 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');
} }
} }

2
app/Model/v3/OrderMain.php

@ -103,7 +103,7 @@ class OrderMain extends Model
Order::class, Order::class,
'order_main_id', 'order_main_id',
'order_id', 'order_id',
'id',
'global_order_id',
'id' 'id'
); );
} }

2
app/Request/v3/SearchGoodsRequest.php

@ -16,7 +16,7 @@ class SearchGoodsRequest extends BaseFormRequest
{ {
return [ return [
'market_id' => 'required|nonempty|integer', 'market_id' => 'required|nonempty|integer',
'type_id' => 'nonempty|integer',
'type_id' => 'nonempty',
'store_id' => 'nonempty|integer', 'store_id' => 'nonempty|integer',
'keyword' => 'nonempty', 'keyword' => 'nonempty',
'order_by' => 'nonempty|in:default,sales,price', 'order_by' => 'nonempty|in:default,sales,price',

15
app/Service/v3/Implementations/CategoryService.php

@ -32,7 +32,20 @@ class CategoryService implements CategoryServiceInterface
public function all() 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) public function allForStore($storeId)

Loading…
Cancel
Save