From 6f6e11e296f0f77a02c1881bf70185e226d7359d Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Wed, 13 Mar 2024 16:30:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=BA=E5=88=86=E6=89=B9=E5=8F=91=E5=92=8C?= =?UTF-8?q?=E9=9B=B6=E5=94=AE=E8=AE=A2=E5=8D=95=E3=80=81=E8=B4=AD=E7=89=A9?= =?UTF-8?q?=E8=BD=A6=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/Enum.php | 18 +++++++++++++++ app/common/dao/store/order/StoreOrderDao.php | 3 +++ app/common/model/store/order/StoreOrder.php | 14 ++++++++++++ app/common/model/system/merchant/Merchant.php | 10 +++++++++ .../order/StoreOrderCreateRepository.php | 9 ++++++-- .../store/product/ProductRepository.php | 1 + .../system/merchant/MerchantRepository.php | 22 +++++++++++++++---- .../api/store/merchant/Merchant.php | 7 ++++-- app/controller/api/store/order/StoreCart.php | 2 +- app/controller/api/store/order/StoreOrder.php | 2 ++ 10 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 app/common/Enum.php diff --git a/app/common/Enum.php b/app/common/Enum.php new file mode 100644 index 00000000..a7e2fe25 --- /dev/null +++ b/app/common/Enum.php @@ -0,0 +1,18 @@ + '零售', + self::SALE_TYPE_WHOLESALE => '批发', + ]; + +} diff --git a/app/common/dao/store/order/StoreOrderDao.php b/app/common/dao/store/order/StoreOrderDao.php index d235ade8..1c229cc0 100644 --- a/app/common/dao/store/order/StoreOrderDao.php +++ b/app/common/dao/store/order/StoreOrderDao.php @@ -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; diff --git a/app/common/model/store/order/StoreOrder.php b/app/common/model/store/order/StoreOrder.php index d21bd7e9..e8ebbd8e 100644 --- a/app/common/model/store/order/StoreOrder.php +++ b/app/common/model/store/order/StoreOrder.php @@ -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; + } + } diff --git a/app/common/model/system/merchant/Merchant.php b/app/common/model/system/merchant/Merchant.php index 7422a975..43c7c2af 100644 --- a/app/common/model/system/merchant/Merchant.php +++ b/app/common/model/system/merchant/Merchant.php @@ -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']); + } + } diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index ddc6fba8..a7e0edea 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -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; diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 39919581..fa07030f 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -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) { diff --git a/app/common/repositories/system/merchant/MerchantRepository.php b/app/common/repositories/system/merchant/MerchantRepository.php index c997d5e1..6da50b6f 100644 --- a/app/common/repositories/system/merchant/MerchantRepository.php +++ b/app/common/repositories/system/merchant/MerchantRepository.php @@ -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; }); diff --git a/app/controller/api/store/merchant/Merchant.php b/app/controller/api/store/merchant/Merchant.php index 71d91528..5385d2f3 100644 --- a/app/controller/api/store/merchant/Merchant.php +++ b/app/controller/api/store/merchant/Merchant.php @@ -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)); } diff --git a/app/controller/api/store/order/StoreCart.php b/app/controller/api/store/order/StoreCart.php index 49191ce0..799feba3 100644 --- a/app/controller/api/store/order/StoreCart.php +++ b/app/controller/api/store/order/StoreCart.php @@ -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){ diff --git a/app/controller/api/store/order/StoreOrder.php b/app/controller/api/store/order/StoreOrder.php index 8aa61dcc..b7b40fff 100644 --- a/app/controller/api/store/order/StoreOrder.php +++ b/app/controller/api/store/order/StoreOrder.php @@ -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;