WIN-2308041133\Administrator 2 недель назад
Родитель
Сommit
eadb464e1d

+ 1 - 0
app/adminapi/controller/v1/merchant/SystemStore.php

@@ -112,6 +112,7 @@ class SystemStore extends AuthController
     public function save($id = 0)
     {
         $data = $this->request->postMore([
+            ['uid' => 0],
             ['name', ''],
             ['introduction', ''],
             ['image', ''],

+ 1 - 1
app/adminapi/controller/v1/user/UserLevel.php

@@ -70,7 +70,7 @@ class UserLevel extends AuthController
         if (!$data['grade']) return app('json')->fail(400325);
         if (!$data['icon']) return app('json')->fail(400327);
         if (!$data['image']) return app('json')->fail(400328);
-        if (!$data['exp_num']) return app('json')->fail(400329);
+//        if (!$data['exp_num']) return app('json')->fail(400329);
         $this->services->save((int)$data['id'], $data);
         return app('json')->success(100000);
     }

+ 70 - 0
app/api/controller/v1/admin/StoreOrderController.php

@@ -22,6 +22,7 @@ use app\services\order\StoreOrderWapServices;
 use app\services\order\StoreOrderWriteOffServices;
 use app\services\pay\OrderOfflineServices;
 use app\services\serve\ServeServices;
+use app\services\system\store\SystemStoreServices;
 use app\services\user\UserServices;
 use app\services\shipping\ExpressServices;
 
@@ -676,4 +677,73 @@ class StoreOrderController
         $services->agreeExpress($id);
         return app('json')->success(100010);
     }
+
+    /**
+     * 获取门店信息
+     * @param Request $request
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function get_store_info(Request $request)
+    {
+        $uid = $request->uid();
+        /** @var SystemStoreServices $storeServices */
+        $storeServices = app()->make(SystemStoreServices::class);
+        // 根据uid获取门店信息
+        $storeInfo = $storeServices->getOne(['uid' => $uid]);
+        if ($storeInfo) {
+            $info = $storeServices->getStoreDispose($storeInfo['id']);
+            return app('json')->success(compact('info'));
+        }
+        return app('json')->success(['info' => null]);
+    }
+
+    /**
+     * 保存门店信息
+     * @param Request $request
+     * @return mixed
+     */
+    public function save_store(Request $request)
+    {
+        $uid = $request->uid();
+        $data = $request->postMore([
+            ['name', ''],
+            ['introduction', ''],
+            ['image', ''],
+            ['oblong_image', ''],
+            ['phone', ''],
+            ['address', ''],
+            ['detailed_address', ''],
+            ['latlng', ''],
+            ['day_time', []],
+        ]);
+
+        /** @var SystemStoreServices $storeServices */
+        $storeServices = app()->make(SystemStoreServices::class);
+
+        // 检查同uid是否已有门店
+        $existingStore = $storeServices->getOne(['uid' => $uid]);
+        $storeId = $existingStore ? $existingStore['id'] : 0;
+
+        // 处理数据
+        $data['uid'] = $uid;
+        $data['address'] = implode(',', $data['address']);
+        $data['latlng'] = explode(',', $data['latlng']);
+        if (!isset($data['latlng'][0]) || !isset($data['latlng'][1])) {
+            return app('json')->fail(400125);
+        }
+        $data['latitude'] = $data['latlng'][0];
+        $data['longitude'] = $data['latlng'][1];
+        $data['day_time'] = implode(' - ', $data['day_time']);
+        unset($data['latlng']);
+        if ($data['image'] && strstr($data['image'], 'http') === false) {
+            $site_url = sys_config('site_url');
+            $data['image'] = $site_url . $data['image'];
+        }
+
+        $storeServices->saveStore((int)$storeId, $data);
+        return app('json')->success(100014);
+    }
 }

+ 18 - 0
app/api/controller/v1/store/StoreCartController.php

@@ -13,6 +13,8 @@ namespace app\api\controller\v1\store;
 use app\Request;
 use app\services\activity\combination\StorePinkServices;
 use app\services\order\StoreCartServices;
+use app\services\order\StoreOrderCartInfoServices;
+use app\services\product\product\StoreProductServices;
 
 /**
  * 购物车类
@@ -86,6 +88,22 @@ class StoreCartController
             }
         } elseif ($where['advanceId']) {
             $type = 6;
+        }
+                //        检测是否是礼包商品
+        $storeServices = app()->make(StoreProductServices::class);
+        $is_gift = $storeServices->value(['id'=>$where['productId']],'is_gift');
+        // 礼包商品只能购买一次检查
+        if ($is_gift == 1) {
+            /** @var StoreOrderCartInfoServices $cartInfoServices */
+            $cartInfoServices = app()->make(StoreOrderCartInfoServices::class);
+            // 直接查询用户是否购买过该礼包商品的已支付订单
+            if ($cartInfoServices->hasUserPurchasedProduct($request->uid(), $where['productId'])) {
+                return app('json')->fail('礼包商品只能购买一次');
+            }
+        }
+        $is_repeat = $storeServices->value(['id'=>$where['productId']],'is_repeat');
+        if ($is_repeat == 1){
+            return app('json')->fail('复购商品商品不支持加入购物车');
         }
         $res = $cartService->setCart($request->uid(), $where['productId'], $where['cartNum'], $where['uniqueId'], $type, $new, $where['combinationId'], $where['secKillId'], $where['bargainId'], $where['advanceId']);
         if (!$res) return app('json')->fail(100022);

+ 29 - 0
app/api/controller/v1/store/StoreProductController.php

@@ -11,6 +11,7 @@
 namespace app\api\controller\v1\store;
 
 use app\Request;
+use app\services\order\StoreOrderCartInfoServices;
 use app\services\product\product\StoreCategoryServices;
 use app\services\product\product\StoreProductReplyServices;
 use app\services\product\product\StoreProductServices;
@@ -203,5 +204,33 @@ class StoreProductController
         ]);
         return app('json')->success($this->services->getAdvanceList($where));
     }
+    /**
+     * 分享礼包商品时检测是否购买过该礼包商品
+     * @param Request $request
+     * @return mixed
+     */
+    public function gift_check(Request $request, $id)
+    {
+        if (!$id) {
+            return app('json')->fail(100100);
+        }
+
+        // 检查该商品是否是礼包商品
+        $is_gift = $this->services->value(['id' => $id], 'is_gift');
+        if ($is_gift != 1) {
+            return app('json')->fail('购买过该礼包商品后才能分享');
+        }
+
+        // 检查用户是否购买过该礼包商品
+        /** @var StoreOrderCartInfoServices $cartInfoServices */
+        $cartInfoServices = app()->make(StoreOrderCartInfoServices::class);
+        $hasPurchased = $cartInfoServices->hasUserPurchasedProduct($request->uid(), $id);
+
+        if (!$hasPurchased) {
+            return app('json')->fail('购买过该礼包商品后才能分享');
+        }
+
+        return app('json')->success(true);
+    }
 
 }

+ 4 - 1
app/api/route/v1.php

@@ -105,7 +105,9 @@ Route::group(function () {
         Route::post('switch_h5', 'v1.LoginController/switch_h5')->name('switch_h5')->option(['real_name' => '切换账号']);// 切换账号
         //商品类
         Route::get('product/code/:id', 'v1.store.StoreProductController/code')->name('productCode')->option(['real_name' => '商品分享二维码']);//商品分享二维码 推广员
-
+        //门店类
+        Route::get('admin/store/info', 'v1.admin.StoreOrderController/get_store_info')->name('adminStoreInfo')->option(['real_name' => '获取门店信息']);//获取门店信息
+        Route::post('admin/store/save', 'v1.admin.StoreOrderController/save_store')->name('adminStoreSave')->option(['real_name' => '保存门店信息']);//保存门店信息
         //公共类
         Route::post('upload/image', 'v1.PublicController/upload_image')->name('uploadImage')->option(['real_name' => '图片上传']);//图片上传
     })->option(['mark' => 'common', 'mark_name' => '公共接口']);
@@ -367,6 +369,7 @@ Route::group(function () {
         Route::get('reply/list/:id', 'v1.store.StoreProductController/reply_list')->name('replyList')->option(['real_name' => '商品评价列表']);//商品评价列表
         Route::get('reply/config/:id', 'v1.store.StoreProductController/reply_config')->name('replyConfig')->option(['real_name' => '商品评价数量和好评度']);//商品评价数量和好评度
         Route::get('advance/list', 'v1.store.StoreProductController/advanceList')->name('advanceList')->option(['real_name' => '预售商品列表']);//预售商品列表
+        Route::get('gift/check/:id', 'v1.store.StoreProductController/gift_check')->name('giftCheck')->option(['real_name' => '检查礼包商品购买状态']);//检查礼包商品购买状态 给推广码用的
     })->option(['mark' => 'product', 'mark_name' => '商品']);
 
     Route::group(function () {

+ 20 - 0
app/dao/order/StoreOrderCartInfoDao.php

@@ -65,4 +65,24 @@ class StoreOrderCartInfoDao extends BaseDao
         }
         return $data;
     }
+
+    /**
+     * 检查用户是否购买过指定商品
+     * @param int $uid 用户ID
+     * @param int $productId 商品ID
+     * @return bool
+     */
+    public function hasUserPurchasedProduct(int $uid, int $productId): bool
+    {
+        $count = $this->getModel()
+            ->alias('cart_info')
+            ->join('store_order order', 'cart_info.oid = order.id')
+            ->where('order.uid', $uid)
+            ->where('order.paid', 1)
+            ->where('order.is_del', 0)
+            ->where('order.refund_status', 'in', [0, 3])
+            ->where('cart_info.cart_info', 'like', '%"productInfo":{"id":' . $productId . '%')
+            ->count();
+        return $count > 0;
+    }
 }

+ 18 - 0
app/services/agent/AgentLevelTaskServices.php

@@ -81,6 +81,24 @@ class AgentLevelTaskServices extends BaseServices
             'min_number' => 0,
             'unit' => '单'
         ],
+        [
+            'type' => 6,
+            'method' => 'spreadGiftCount',
+            'name' => '下级购买礼包单数满{$num}',
+            'real_name' => '下级购买礼包',
+            'max_number' => 0,
+            'min_number' => 0,
+            'unit' => '单'
+        ],
+        [
+            'type' => 7,
+            'method' => 'spreadV2Count',
+            'name' => '下级成为V2人数满{$num}人',
+            'real_name' => '下级团队V2人数',
+            'max_number' => 0,
+            'min_number' => 0,
+            'unit' => '单'
+        ],
     ];
 
     /**

+ 10 - 1
app/services/order/StoreCartServices.php

@@ -509,6 +509,15 @@ class StoreCartServices extends BaseServices
         $sum_price = 0;
         $cartList = $this->dao->getUserCartList($uid, '*', ['productInfo', 'attrInfo']);
         if ($cartList) {
+            // 检查是否有礼包商品(is_gift为1)
+            $hasGift = false;
+            foreach ($cartList as $item) {
+                if (($item['productInfo']['is_gift'] ?? 0) == 1) {
+                    $hasGift = true;
+                    break;
+                }
+            }
+
             /** @var StoreProductServices $productServices */
             $productServices = app()->make(StoreProductServices::class);
             /** @var MemberCardServices $memberCardService */
@@ -518,7 +527,7 @@ class StoreCartServices extends BaseServices
             $user = app()->make(UserServices::class);
             $userInfo = $user->getUserInfo($uid);
             $discount = 100;
-            if (sys_config('member_func_status', 1)) {
+            if (!$hasGift && sys_config('member_func_status', 1)) {
                 /** @var SystemUserLevelServices $systemLevel */
                 $systemLevel = app()->make(SystemUserLevelServices::class);
                 $discount = $systemLevel->value(['id' => $userInfo['level'], 'is_del' => 0, 'is_show' => 1], 'discount') ?: 100;

+ 1 - 0
app/services/order/StoreOrderCartInfoServices.php

@@ -23,6 +23,7 @@ use app\dao\order\StoreOrderCartInfoDao;
  * @method array getCartInfoList(array $where, array $field) 获取购物车详情列表
  * @method getSplitCartNum(array $cart_id)
  * @method getOne(array $where, ?string $field = '*', array $with = []) 根据条件获取一条数据
+ * @method hasUserPurchasedProduct(int $uid, int $productId) 检查用户是否购买过指定商品
  */
 class StoreOrderCartInfoServices extends BaseServices
 {

+ 32 - 0
app/services/order/StoreOrderSuccessServices.php

@@ -12,7 +12,9 @@
 namespace app\services\order;
 
 
+use app\adminapi\controller\v1\marketing\StoreCouponUser;
 use app\dao\order\StoreOrderDao;
+use app\services\activity\coupon\StoreCouponIssueServices;
 use app\services\activity\lottery\LuckLotteryServices;
 use app\services\activity\combination\StorePinkServices;
 use app\services\BaseServices;
@@ -106,7 +108,37 @@ class StoreOrderSuccessServices extends BaseServices
             event('OrderShipping', ['product', $orderInfo, 4, '', '']);
         }
         $res = $res1 && $resPink;
+        if ($orderInfo['order_type']==1){  //礼包商品订单赠送复购商品优惠卷
+            $grant_id = sys_config('repeat_voucher',0);
+            $grant_num = sys_config('repeat_voucher_num',0);
+            if ($grant_id>0 && $grant_num>0){
+                for ($i=0;$i<$grant_num;$i++){
+                    self::grantUser($orderInfo['uid'],$grant_id);
+                }
+            }
+        }
         return false !== $res;
     }
 
+    /**
+     * 发放优惠券到指定个人
+     * @return mixed
+     */
+    public function grantUser($id,$uid)
+    {
+        $data['id'] = $id;
+        $data['uid'] = $uid;
+        if (!$data['id']) return app('json')->fail(100100);
+        /** @var StoreCouponIssueServices $issueService */
+        $issueService = app()->make(StoreCouponIssueServices::class);
+        $coupon = $issueService->get($data['id']);
+        if (!$coupon) {
+            return app('json')->fail(100026);
+        } else {
+            $coupon = $coupon->toArray();
+        }
+        $user = explode(',', $data['uid']);
+        $issueService->setCoupon($coupon, $user);
+        return true;
+    }
 }