Browse Source

Merge branch 'phoenix' of http://120.24.33.109:11081/hyzjshwo/lanzu_api_hyperf into phoenix

master
lanzu_qinsheng 5 years ago
parent
commit
cb28758d55
  1. 8
      app/Constants/v3/OrderState.php
  2. 6
      app/Controller/v3/OrderOnlineController.php
  3. 66
      app/JsonRpc/OrderService.php
  4. 18
      app/Model/v3/Category.php
  5. 10
      app/Model/v3/Goods.php
  6. 6
      app/Model/v3/OrderMain.php
  7. 3
      app/Model/v3/ShoppingCart.php
  8. 3
      app/Request/v3/SearchGoodsRequest.php
  9. 15
      app/Service/v3/Implementations/CategoryService.php
  10. 5
      app/Service/v3/Implementations/SearchService.php

8
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];
}

6
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();
//

66
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);
}
}
}
}

18
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');
}
}

10
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);

6
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'
);
}

3
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 = [

3
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',

15
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)

5
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);
}

Loading…
Cancel
Save