区分批发和零售订单、购物车数据
This commit is contained in:
parent
881759cc18
commit
6f6e11e296
18
app/common/Enum.php
Normal file
18
app/common/Enum.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace app\common;
|
||||
|
||||
class Enum
|
||||
{
|
||||
|
||||
const SALE_TYPE_RETAIL = 1; //零售类型
|
||||
const SALE_TYPE_WHOLESALE = 2; //批发类型
|
||||
const STATUS_ENABLE = 1; //允许状态
|
||||
const STATUS_DISABLE = 0; //禁用状态
|
||||
|
||||
const MAP = [
|
||||
self::SALE_TYPE_RETAIL => '零售',
|
||||
self::SALE_TYPE_WHOLESALE => '批发',
|
||||
];
|
||||
|
||||
}
|
@ -247,6 +247,9 @@ class StoreOrderDao extends BaseDao
|
||||
break;
|
||||
}
|
||||
})
|
||||
->when(isset($where['sale_type']) && $where['sale_type'] !== '', function ($query) use ($where) {
|
||||
$query->where('sale_type', $where['sale_type']);
|
||||
})
|
||||
->order('StoreOrder.create_time DESC');
|
||||
|
||||
return $query;
|
||||
|
@ -14,6 +14,7 @@
|
||||
namespace app\common\model\store\order;
|
||||
|
||||
|
||||
use app\common\Enum;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\community\Community;
|
||||
use app\common\model\store\product\ProductGroupUser;
|
||||
@ -201,4 +202,17 @@ class StoreOrder extends BaseModel
|
||||
{
|
||||
return StoreRefundOrder::where('order_id',$this->order_id)->where('status',3)->sum('refund_price');
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为批发
|
||||
* @param $wholesale
|
||||
* @param $merId
|
||||
* @param $saleType
|
||||
* @return bool
|
||||
*/
|
||||
public static function isWholesale($wholesale, $merId, $saleType)
|
||||
{
|
||||
return $wholesale >= 1 && $merId > 0 && $saleType == Enum::SALE_TYPE_WHOLESALE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -297,4 +297,14 @@ class Merchant extends BaseModel
|
||||
return $this->wholesale == 1;
|
||||
}
|
||||
|
||||
public function typeNames()
|
||||
{
|
||||
return $this->merchantType()->bind(['type_name']);
|
||||
}
|
||||
|
||||
public function streetNames()
|
||||
{
|
||||
return $this->hasOne(GeoStreet::class, 'street_code', 'street_id')->bind(['street_name']);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace app\common\repositories\store\order;
|
||||
|
||||
use app\common\dao\store\coupon\StoreCouponUserDao;
|
||||
use app\common\Enum;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use app\common\model\store\product\ProductCate;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
@ -40,6 +41,9 @@ use think\facade\{Cache, Db, Queue};
|
||||
|
||||
class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
{
|
||||
|
||||
public $saleType = Enum::SALE_TYPE_RETAIL;
|
||||
|
||||
public function v2CartIdByOrderInfo($user, array $cartId, array $takes = null, array $useCoupon = null, bool $useIntegral = false, int $addressId = null, $createOrder = false)
|
||||
{
|
||||
$uid = $user->uid;
|
||||
@ -83,7 +87,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
// 循环计算每个店铺的订单数据
|
||||
foreach ($merchantCartList as &$merchantCart) {
|
||||
//用户关联了商户id且下单店铺支持批发
|
||||
$isWholeSale = $merchantCart['wholesale'] == 1 && $merId > 0;
|
||||
$isWholeSale = StoreOrder::isWholesale($merchantCart['wholesale'], $merId, $this->saleType);
|
||||
$postageRule = [];
|
||||
$total_price = 0;
|
||||
$total_num = 0;
|
||||
@ -901,7 +905,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
'order_refund_switch',
|
||||
'order',
|
||||
'cartCoupon'
|
||||
) + ['allow_address' => !$allow_no_address, 'order_delivery_status' => $orderDeliveryStatus];
|
||||
) + ['allow_address' => !$allow_no_address, 'order_delivery_status' => $orderDeliveryStatus, 'sale_type' => $this->saleType];
|
||||
Cache::set('order_create_cache' . $uid . '_' . $key, $data, 600);
|
||||
return $data;
|
||||
}
|
||||
@ -1116,6 +1120,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
'platform_coupon_price' => $merchantCart['order']['platform_coupon_price'],
|
||||
'pay_type' => $pay_type,
|
||||
'refund_switch' => $merchantCart['order']['order_refund_switch'],
|
||||
'sale_type' => $orderInfo['sale_type'],
|
||||
];
|
||||
$allUseCoupon = array_merge($allUseCoupon, $merchantCart['order']['useCouponIds']);
|
||||
$orderList[] = $_order;
|
||||
|
@ -1661,6 +1661,7 @@ class ProductRepository extends BaseRepository
|
||||
'bar_code' => $value['bar_code'],
|
||||
];
|
||||
if ($this->isWholesale) {
|
||||
$_value['ot_price'] = $value['price'];
|
||||
$_value['price'] = $value['wholesale_price'];
|
||||
}
|
||||
if ($productType == 0) {
|
||||
|
@ -25,6 +25,7 @@ use app\common\model\system\merchant\Merchant;
|
||||
use app\common\repositories\BaseRepository;
|
||||
use app\common\repositories\store\coupon\StoreCouponRepository;
|
||||
use app\common\repositories\store\coupon\StoreCouponUserRepository;
|
||||
use app\common\repositories\store\MerchantTakeRepository;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
use app\common\repositories\store\product\ProductCopyRepository;
|
||||
use app\common\repositories\store\product\ProductRepository;
|
||||
@ -283,7 +284,7 @@ class MerchantRepository extends BaseRepository
|
||||
*/
|
||||
public function getList($where, $page, $limit, $userInfo)
|
||||
{
|
||||
$field = 'care_count,is_trader,type_id,mer_id,mer_banner,mini_banner,mer_name, mark,mer_avatar,product_score,service_score,postage_score,sales,status,is_best,create_time,long,lat,is_margin';
|
||||
$field = 'care_count,is_trader,type_id,mer_id,mer_banner,mini_banner,mer_name, mark,mer_avatar,product_score,service_score,postage_score,sales,status,is_best,create_time,long,lat,is_margin,mer_address,street_id,service_phone,mer_info';
|
||||
$where['status'] = 1;
|
||||
$where['mer_state'] = 1;
|
||||
$where['is_del'] = 0;
|
||||
@ -305,8 +306,10 @@ class MerchantRepository extends BaseRepository
|
||||
$query = $this->dao->search($where)->with(['type_name']);
|
||||
$count = $query->count();
|
||||
$status = systemConfig('mer_location') && isset($where['location']);
|
||||
$list = $query->page($page, $limit)->setOption('field', [])->field($field)->select()
|
||||
->each(function ($item) use ($status, $where) {
|
||||
/** @var MerchantTakeRepository $repository */
|
||||
$repository = app()->make(MerchantTakeRepository::class);
|
||||
$list = $query->with(['streetNames','typeNames'])->page($page, $limit)->setOption('field', [])->field($field)->select()
|
||||
->each(function ($item) use ($status, $where, $repository) {
|
||||
if ($status && $item['lat'] && $item['long'] && isset($where['location']['lat'], $where['location']['long'])) {
|
||||
$distance = getDistance($where['location']['lat'], $where['location']['long'], $item['lat'], $item['long']);
|
||||
if ($distance < 0.9) {
|
||||
@ -319,7 +322,18 @@ class MerchantRepository extends BaseRepository
|
||||
}
|
||||
$item['distance'] = $distance;
|
||||
}
|
||||
$item['recommend'] = isset($where['delivery_way']) ? $item['CityRecommend'] : $item['AllRecommend'];
|
||||
$delivery = $repository->get($item['mer_id']) + systemConfig(['tx_map_key']);
|
||||
$item['mer_certificate'] = merchantConfig($item['mer_id'], 'mer_certificate');
|
||||
if (empty($item['mer_certificate'][0])) {
|
||||
$item['mer_certificate'] = [];
|
||||
}
|
||||
$item['mer_take_time'] = $delivery['mer_take_time'];
|
||||
// if(isset($where['type_id'])&& $where['type_id']==12){
|
||||
// $item['recommend'] = $item['AllRecommendType'];
|
||||
// }else{
|
||||
// $item['recommend'] = isset($where['delivery_way']) ? $item['CityRecommend'] : $item['AllRecommend'];
|
||||
//
|
||||
// }
|
||||
return $item;
|
||||
});
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
namespace app\controller\api\store\merchant;
|
||||
|
||||
use app\common\repositories\store\service\StoreServiceRepository;
|
||||
use app\common\model\system\merchant\MerchantType;
|
||||
use app\common\repositories\user\UserMerchantRepository;
|
||||
use think\App;
|
||||
use crmeb\basic\BaseController;
|
||||
@ -43,7 +43,10 @@ class Merchant extends BaseController
|
||||
public function lst()
|
||||
{
|
||||
[$page, $limit] = $this->getPage();
|
||||
$where = $this->request->params(['keyword', 'order', 'is_best', 'location', 'category_id', 'type_id','is_trader']);
|
||||
$where = $this->request->params(['merchant_category_id', 'keyword', 'order', 'is_best', 'location', 'category_id', 'type_id', 'type_code', 'is_trader', 'street_id']);
|
||||
if (empty($where['type_id'])) {
|
||||
$where['type_id'] = MerchantType::where('is_allow_apply', 1)->where('is_search_display', 1)->column('mer_type_id');
|
||||
}
|
||||
return app('json')->success($this->repository->getList($where, $page, $limit, $this->userInfo));
|
||||
}
|
||||
|
||||
|
@ -231,7 +231,7 @@ class StoreCart extends BaseController
|
||||
*/
|
||||
public function checkParams(validate $validate)
|
||||
{
|
||||
$data = $this->request->params(['product_id','product_attr_unique','cart_num','is_new',['product_type',0],['group_buying_id',0],['spread_id',0]]);
|
||||
$data = $this->request->params(['product_id','product_attr_unique','cart_num','is_new',['product_type',0],['group_buying_id',0],['spread_id',0], ['sale_type',1]]);
|
||||
$validate->check($data);
|
||||
if ($data['spread_id']) {
|
||||
if ($data['spread_id'] !== $this->request->userInfo()->uid){
|
||||
|
@ -63,6 +63,7 @@ class StoreOrder extends BaseController
|
||||
$uid = $user->uid;
|
||||
if (!($count = count($cartId)) || $count != count($cartRepository->validIntersection($cartId, $uid)))
|
||||
return app('json')->fail('数据无效');
|
||||
$orderCreateRepository->saleType = (int)$this->request->param('sale_type', 1);
|
||||
$orderInfo = $orderCreateRepository->v2CartIdByOrderInfo($user, $cartId, $takes, $couponIds, $useIntegral, $addressId);
|
||||
|
||||
return app('json')->success($orderInfo);
|
||||
@ -137,6 +138,7 @@ class StoreOrder extends BaseController
|
||||
[$page, $limit] = $this->getPage();
|
||||
$where['status'] = $this->request->param('status');
|
||||
$where['search'] = $this->request->param('store_name');
|
||||
$where['sale_type'] = $this->request->param('sale_type', 1);
|
||||
$where['uid'] = $this->request->uid();
|
||||
$where['paid'] = 1;
|
||||
// $where['is_user'] = 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user