Kirin 3 år sedan
förälder
incheckning
e0864fbc7f

+ 3 - 3
app/admin/controller/finance/UserExtract.php

@@ -153,9 +153,9 @@ class UserExtract extends AuthController
             $res = $res && UserBill::income('提现转换(余额)', $extract['uid'], 'now_money', 'extract_get_now_money', $extract['commission_yue'], $extract['id'], \app\admin\model\user\User::where('uid', $extract['uid'])->value('now_money') + $extract['commission_yue'], '提现申请通过,其中部分佣金转换为余额' . $extract['commission_yue']);
             $res = $res && \app\admin\model\user\User::where('uid', $extract['uid'])->inc('now_money', $extract['commission_yue'])->update();
         }
-        if ($extract['commission_gf'] > 0 && SystemStoreMember::be(['uid' => $extract['uid']])) {
-            $res = $res && SystemStoreMember::where('uid', $extract['uid'])->inc('consume_rights', $extract['commission_gf'])->update();
-        }
+//        if ($extract['commission_gf'] > 0 && SystemStoreMember::be(['uid' => $extract['uid']])) {
+//            $res = $res && SystemStoreMember::where('uid', $extract['uid'])->inc('consume_rights', $extract['commission_gf'])->update();
+//        }
         if ($res) {
             UserExtractModel::commitTrans();
             return JsonService::successful('操作成功!');

+ 12 - 0
app/admin/controller/system/SystemCleardata.php

@@ -54,6 +54,15 @@ class SystemclearData extends AuthController
         self::clearData('user_level', 1);
         self::clearData('user_token', 1);
         self::clearData('user_group', 1);
+        self::clearData('card_info', 1);
+        self::clearData('order_level', 1);
+        self::clearData('payment_received', 1);
+        self::clearData('payment_received', 1);
+        self::clearData('user_ali', 1);
+        self::clearData('user_bank', 1);
+        self::clearData('user_system_recharge', 1);
+        self::clearData('user_token', 1);
+        self::clearData('system_store_member', 1);
         $this->delDirAndFile('./public/uploads/store/comment');
         self::clearData('store_product_relation', 1);
         return Json::successful('清除数据成功!');
@@ -74,6 +83,9 @@ class SystemclearData extends AuthController
         self::clearData('store_seckill', 1);
         self::clearData('store_product', 1);
         self::clearData('store_visit', 1);
+        self::clearData('system_store_stock', 1);
+        self::clearData('system_store_stock_bill', 1);
+        self::clearData('system_store_bill', 1);
         return Json::successful('清除数据成功!');
     }
 

+ 24 - 23
app/api/controller/order/StoreOrderController.php

@@ -63,7 +63,8 @@ class StoreOrderController
         }
         $other = [
             'offlinePostage' => sys_config('offline_postage'),
-            'integralRatio' => sys_config('integral_ratio')
+            'integralRatio' => sys_config('integral_ratio'),
+            'suit' => $cartGroup['suit']
         ];
         $usableCoupons = StoreCouponUser::getUsableCouponList($uid, $cartGroup, $priceGroup['totalPrice']);
         $usableCoupon = isset($usableCoupons[0]) ? $usableCoupons[0] : null;
@@ -103,15 +104,15 @@ class StoreOrderController
     }
 
     /**
- * 计算订单金额
- * @param Request $request
- * @param $key
- * @return mixed
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
+     * 计算订单金额
+     * @param Request $request
+     * @param $key
+     * @return mixed
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
     public function computedOrder(Request $request, $key)
     {
 
@@ -120,9 +121,9 @@ class StoreOrderController
         $uid = $request->uid();
         if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0]))
             return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
-        list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $shipping_type,$is_consumer) = UtilService::postMore([
+        list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $shipping_type, $is_consumer) = UtilService::postMore([
             'addressId', 'couponId', ['payType', 'yue'], ['useIntegral', 0], 'mark', ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['formId', ''], ['bargainId', ''],
-            ['shipping_type', 1],['is_consumer',0]
+            ['shipping_type', 1], ['is_consumer', 0]
         ], $request, true);
         $payType = strtolower($payType);
         if ($bargainId) {
@@ -135,8 +136,8 @@ class StoreOrderController
             StoreBargainUser::setBargainUserStatus($bargainId, $uid); //修改砍价状态
         }
         if ($pinkId) {
-            $cache_pink = Cache::get(md5('store_pink_'.$pinkId));
-            if($cache_pink && bcsub($cache_pink['people'], $cache_pink['now_people'], 0) <= 0){
+            $cache_pink = Cache::get(md5('store_pink_' . $pinkId));
+            if ($cache_pink && bcsub($cache_pink['people'], $cache_pink['now_people'], 0) <= 0) {
                 return app('json')->status('ORDER_EXIST', '订单生成失败,该团人员已满', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
             }
             if (StorePink::getIsPinkUid($pinkId, $request->uid()))
@@ -144,7 +145,7 @@ class StoreOrderController
             if (StoreOrder::getIsOrderPink($pinkId, $request->uid()))
                 return app('json')->status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
         }
-        $priceGroup = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral, $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, true, 0, $shipping_type,'','',0,$is_consumer);
+        $priceGroup = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral, $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, true, 0, $shipping_type, '', '', 0, $is_consumer);
         if ($priceGroup)
             return app('json')->status('NONE', 'ok', $priceGroup);
         else
@@ -167,9 +168,9 @@ class StoreOrderController
         $uid = $request->uid();
         if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0]))
             return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
-        list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $from, $shipping_type, $real_name, $phone, $storeId,$is_consumer) = UtilService::postMore([
+        list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $from, $shipping_type, $real_name, $phone, $storeId, $is_consumer) = UtilService::postMore([
             'addressId', 'couponId', 'payType', ['useIntegral', 0], 'mark', ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['formId', ''], ['bargainId', ''], ['from', 'weixin'],
-            ['shipping_type', 1], ['real_name', ''], ['phone', ''], ['store_id', 0],['is_consumer',0]
+            ['shipping_type', 1], ['real_name', ''], ['phone', ''], ['store_id', 0], ['is_consumer', 0]
         ], $request, true);
         $payType = strtolower($payType);
         if ($bargainId) {
@@ -182,8 +183,8 @@ class StoreOrderController
             StoreBargainUser::setBargainUserStatus($bargainId, $uid); //修改砍价状态
         }
         if ($pinkId) {
-            $cache_pink = Cache::get(md5('store_pink_'.$pinkId));
-            if($cache_pink && bcsub($cache_pink['people'], $cache_pink['now_people'], 0) <= 0){
+            $cache_pink = Cache::get(md5('store_pink_' . $pinkId));
+            if ($cache_pink && bcsub($cache_pink['people'], $cache_pink['now_people'], 0) <= 0) {
                 return app('json')->status('ORDER_EXIST', '订单生成失败,该团人员已满', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
             }
             if (StorePink::getIsPinkUid($pinkId, $request->uid()))
@@ -197,7 +198,7 @@ class StoreOrderController
         elseif ($from == 'weixinh5')
             $isChannel = 2;
 
-        $order = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral, $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, false, $isChannel, $shipping_type, $real_name, $phone, $storeId,$is_consumer);
+        $order = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral, $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, false, $isChannel, $shipping_type, $real_name, $phone, $storeId, $is_consumer);
         if ($order === false) return app('json')->fail(StoreOrder::getErrorInfo('订单生成失败'));
         $orderId = $order['order_id'];
         $info = compact('orderId', 'key');
@@ -316,9 +317,9 @@ class StoreOrderController
             return app('json')->fail('订单不存在!');
         if ($order['paid'])
             return app('json')->fail('该订单已支付!');
-        if ($order['pink_id']){
-            $cache_pink = Cache::get(md5('store_pink_'.$order['pink_id']));
-            if(StorePink::isPinkStatus($order['pink_id'])  || ($cache_pink && bcsub($cache_pink['people'], $cache_pink['now_people'], 0) <= 0)){
+        if ($order['pink_id']) {
+            $cache_pink = Cache::get(md5('store_pink_' . $order['pink_id']));
+            if (StorePink::isPinkStatus($order['pink_id']) || ($cache_pink && bcsub($cache_pink['people'], $cache_pink['now_people'], 0) <= 0)) {
                 return app('json')->fail('该订单已失效!');
             }
         }

+ 3 - 0
app/api/controller/user/UserExtractController.php

@@ -7,6 +7,7 @@ use app\models\store\StoreOrder;
 use app\models\user\UserBill;
 use app\models\user\UserExtract;
 use app\Request;
+use crmeb\services\CacheService;
 use crmeb\services\UtilService;
 
 /**
@@ -71,6 +72,8 @@ class UserExtractController
             ['cardnum', ''],
             ['weixin', ''],
         ], $request);
+        if (time() - CacheService::get('UserExtract_' . $request->uid(), 0) < 10) return app('json')->fail('请勿连续多次提交');
+        else CacheService::set('UserExtract_' . $request->uid(), time());
         if (!preg_match('/^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/', $extractInfo['money'])) return app('json')->fail('提现金额输入有误');
         //提现设置最低金额
         if ($extractInfo['money'] < sys_config('user_extract_min_price')) return app('json')->fail('金额小于最低提现金额');

+ 3 - 1
app/models/store/StoreCart.php

@@ -145,6 +145,7 @@ class StoreCart extends BaseModel
         $combinationInfoField = 'id,image,price,postage,sales,stock,title as store_name,is_show,is_del,is_postage,cost,temp_id,weight,volume';
         $model = new self();
         $valid = $invalid = [];
+        $suit = 0;
         $model = $model->alias('c')->field('c.*')->join('store_product p', 'c.product_id = p.id')->where('c.uid', $uid)->where('c.type', 'product')->where('c.is_pay', 0)
             ->where('c.is_del', 0);
         if (!$status) $model = $model->where('c.is_new', 0);
@@ -259,6 +260,7 @@ class StoreCart extends BaseModel
             if (isset($valid[$k]['productInfo'])) {
                 unset($valid[$k]['productInfo']['is_del'], $valid[$k]['productInfo']['is_del'], $valid[$k]['productInfo']['is_show']);
             }
+            $suit += ($cart['productInfo']['is_suit'] ?? 0) * $cart['cart_num'];
         }
         foreach ($invalid as $k => $cart) {
             unset($valid[$k]['uid'], $valid[$k]['is_del'], $valid[$k]['is_new'], $valid[$k]['is_pay'], $valid[$k]['add_time']);
@@ -267,7 +269,7 @@ class StoreCart extends BaseModel
             }
         }
 
-        return compact('valid', 'invalid');
+        return compact('valid', 'invalid', 'suit');
     }
 
     /**

+ 43 - 8
app/models/store/StoreOrder.php

@@ -10,6 +10,7 @@ namespace app\models\store;
 use app\admin\model\store\StoreProductAttrValue;
 use app\admin\model\system\ShippingTemplatesFree;
 use app\admin\model\system\ShippingTemplatesRegion;
+use app\models\system\SystemAwardLevel;
 use app\models\system\SystemGroupLevel;
 use app\models\system\SystemStoreMember;
 use app\models\system\SystemStoreStock;
@@ -464,6 +465,7 @@ class StoreOrder extends BaseModel
                 'shipping_type' => $shipping_type,
                 'is_consumer' => $is_consumer,
                 'reg_store_id' => $userInfo['reg_store_id'],
+                'suit' => $other['suit'],
             ];
             if ($shipping_type === 2) {
                 $orderInfo['verify_code'] = self::getStoreCode();
@@ -830,11 +832,40 @@ class StoreOrder extends BaseModel
         $now_money = User::where('uid', $order['uid'])->value('now_money');
         UserBill::expend('购买商品', $order['uid'], 'now_money', 'pay_money', $order['pay_price'], $order['id'], $now_money, '支付' . floatval($order['pay_price']) . '元购买商品');
         //支付成功后
+        $res2 = true;
+        $res2 = $res2 && self::addSuit($order);
+        $res2 = $res2 && StoreOrder::sendSuit($order);
+        $res2 = $res2 && StoreOrder::sendGroupAward($order);
+        $res2 = $res2 && SystemGroupLevel::checkLevel($order['uid']);
+        $res2 = $res2 && SystemAwardLevel::checkLevel($order['uid']);
         event('OrderPaySuccess', [$order, $formId]);
-        $res = $res1 && $resPink;
+        $res = $res1 && $resPink && $res2;
         return false !== $res;
     }
 
+    public static function addSuit($order)
+    {
+        $userInfo = User::getUserInfo($order['uid']);
+        $spread = User::getUserInfo($userInfo['spread_uid']);
+        if (StoreOrder::where('uid', $order['uid'])->where('paid', 1)->where('refund_status', 0)->where('is_del', 0)->where('is_system_del', 0)
+            ->where('id', '<>', $order['id'])->where('suit', '>', 0)->find()) {
+            $spread = $userInfo;
+        }
+        $re = true;
+        $res = true;
+        while ($spread) {
+            if ($re) {
+                $res = $res && User::where('uid', $spread['uid'])->inc('recommend_suit_num', $order['suit'])
+                        ->inc('group_suit_num', $order['suit'])->update();
+                $re = false;
+            } else {
+                $res = $res && User::where('uid', $spread['uid'])->inc('group_suit_num', $order['suit'])->update();
+            }
+            $spread = User::getUserInfo($spread['spread_uid']);
+        }
+        return $res;
+    }
+
     /*
      * 线下支付消息通知
      * 待完善
@@ -2438,6 +2469,10 @@ class StoreOrder extends BaseModel
 
         $userInfo = User::getUserInfo($order['uid']);
         $spread = User::getUserInfo($userInfo['spread_uid']);
+        if (StoreOrder::where('uid', $order['uid'])->where('paid', 1)->where('refund_status', 0)->where('is_del', 0)->where('is_system_del', 0)
+            ->where('id', '<>', $order['id'])->where('suit', '>', 0)->find()) {
+            $spread = $userInfo;
+        }
         $cartInfo = StoreOrderCartInfo::whereIn('cart_id', $order['cart_id'])->column('cart_info');
         $suit = 0;
         $suit_price = 0;
@@ -2541,13 +2576,13 @@ class StoreOrder extends BaseModel
             }
         }
 
-        if ($suit_give_gf > 0 && SystemStoreMember::be(['uid' => $userInfo['uid']])) {
-            //获得股份
-            $brokeragePrice = bcmul($suit_give_integral, $suit, 2);
-            if ($brokeragePrice > 0) {
-                $res = $res && SystemStoreMember::where('uid', $userInfo['uid'])->inc('consume_rights', $brokeragePrice)->update();
-            }
-        }
+//        if ($suit_give_gf > 0 && SystemStoreMember::be(['uid' => $userInfo['uid']])) {
+//            //获得股份
+//            $brokeragePrice = bcmul($suit_give_gf, $suit, 2);
+//            if ($brokeragePrice > 0) {
+//                $res = $res && SystemStoreMember::where('uid', $userInfo['uid'])->inc('consume_rights', $brokeragePrice)->update();
+//            }
+//        }
 
         return $res;
     }

+ 22 - 21
app/models/system/SystemAwardLevel.php

@@ -30,6 +30,7 @@ class SystemAwardLevel extends BaseModel
     protected $name = 'system_award_level';
 
     use ModelTrait;
+
     /**
      * 获取查询条件
      * @param $where
@@ -37,14 +38,14 @@ class SystemAwardLevel extends BaseModel
      * @param null $model
      * @return SystemUserLevel|null
      */
-    public static function setWhere($where,$alert='',$model=null)
+    public static function setWhere($where, $alert = '', $model = null)
     {
-        $model=$model===null ? new self() : $model;
-        if($alert) $model=$model->alias($alert);
-        $alert=$alert ? $alert.'.': '';
-        $model = $model->where("{$alert}is_del",0);
-        if(isset($where['is_show']) && $where['is_show']!=='') $model=$model->where("{$alert}is_show",$where['is_show']);
-        if(isset($where['title']) && $where['title']) $model=$model->where("{$alert}name",'LIKE',"%$where[title]%");
+        $model = $model === null ? new self() : $model;
+        if ($alert) $model = $model->alias($alert);
+        $alert = $alert ? $alert . '.' : '';
+        $model = $model->where("{$alert}is_del", 0);
+        if (isset($where['is_show']) && $where['is_show'] !== '') $model = $model->where("{$alert}is_show", $where['is_show']);
+        if (isset($where['title']) && $where['title']) $model = $model->where("{$alert}name", 'LIKE', "%$where[title]%");
         return $model;
     }
 
@@ -58,25 +59,25 @@ class SystemAwardLevel extends BaseModel
 
     public static function checkLevel($uid)
     {
-        $user = User::where('uid', $uid)->find();
-        $spread = User::where('uid', $user['spread_uid'])->find();
+        $spread = User::where('uid', $uid)->find();
+//        $spread = User::where('uid', $user['spread_uid'])->find();
         while ($spread) {
             //推荐全员
-            $uids = User::where('spread_uid', $spread['uid'])->column('uid');
-            $orders = StoreOrder::where('paid', 1)
-                ->where('status', 'in', [2, 3])
-                ->where('uid', 'in', $uids)
-                ->where('refund_status', 0)
-                ->where('is_del', 0)
-                ->where('is_system_del', 0)->select();
-            $num = 0;
-            foreach ($orders as $v) {
-                $num += StoreCart::where('id', 'in', $v['cart_id'])->where('is_suit', 1)->sum('cart_num');
-            }
+//            $uids = User::where('spread_uid', $spread['uid'])->column('uid');
+//            $orders = StoreOrder::where('paid', 1)
+//                ->where('status', 'in', [2, 3])
+//                ->where('uid', 'in', $uids)
+//                ->where('refund_status', 0)
+//                ->where('is_del', 0)
+//                ->where('is_system_del', 0)->select();
+//            $num = 0;
+//            foreach ($orders as $v) {
+//                $num += StoreCart::where('id', 'in', $v['cart_id'])->where('is_suit', 1)->sum('cart_num');
+//            }
             $level_info = self::where('id', $spread['award_level'])->find();
             $level = self::where('level_num', '>', $level_info['level_num'] ?? 0)->order('level_num', 'desc')->select();
             foreach ($level as $v) {
-                if ($num >= $v['level_num']) {
+                if ($spread['recommend_suit_num'] >= $v['level_num']) {
                     User::where('uid', $spread['uid'])->update(['award_level' => $v['id']]);
                     self::sendBackOrderBrokerage($spread['uid']);
                     break;

+ 27 - 26
app/models/system/SystemGroupLevel.php

@@ -37,16 +37,17 @@ class SystemGroupLevel extends BaseModel
      * @param null $model
      * @return SystemUserLevel|null
      */
-    public static function setWhere($where,$alert='',$model=null)
+    public static function setWhere($where, $alert = '', $model = null)
     {
-        $model=$model===null ? new self() : $model;
-        if($alert) $model=$model->alias($alert);
-        $alert=$alert ? $alert.'.': '';
-        $model = $model->where("{$alert}is_del",0);
-        if(isset($where['is_show']) && $where['is_show']!=='') $model=$model->where("{$alert}is_show",$where['is_show']);
-        if(isset($where['title']) && $where['title']) $model=$model->where("{$alert}name",'LIKE',"%$where[title]%");
+        $model = $model === null ? new self() : $model;
+        if ($alert) $model = $model->alias($alert);
+        $alert = $alert ? $alert . '.' : '';
+        $model = $model->where("{$alert}is_del", 0);
+        if (isset($where['is_show']) && $where['is_show'] !== '') $model = $model->where("{$alert}is_show", $where['is_show']);
+        if (isset($where['title']) && $where['title']) $model = $model->where("{$alert}name", 'LIKE', "%$where[title]%");
         return $model;
     }
+
     public static function getSystemList($where)
     {
         $data = self::setWhere($where)->order('id asc')->page((int)$where['page'], (int)$where['limit'])->select();
@@ -57,30 +58,30 @@ class SystemGroupLevel extends BaseModel
 
     public static function checkLevel($uid)
     {
-        $user = User::where('uid', $uid)->find();
-        $spread = User::where('uid', $user['spread_uid'])->find();
+        $spread = User::where('uid', $uid)->find();
+//        $spread = User::where('uid', $user['spread_uid'])->find();
         while ($spread) {
             //伞下全员
-            $uids = [];
-            $sp = [$spread['uid']];
-            while ($sp) {
-                $sp = User::where('spread_uid', 'in', $sp)->column('uid');
-                if (count($sp)) $uids = array_merge($uids, $sp);
-            }
-            $orders = StoreOrder::where('paid', 1)
-                ->where('status', 'in', [2, 3])
-                ->where('uid', 'in', $uids)
-                ->where('refund_status', 0)
-                ->where('is_del', 0)
-                ->where('is_system_del', 0)->select();
-            $num = 0;
-            foreach ($orders as $v) {
-                $num += StoreCart::where('id', 'in', $v['cart_id'])->where('is_suit', 1)->sum('cart_num');
-            }
+//            $uids = [];
+//            $sp = [$spread['uid']];
+//            while ($sp) {
+//                $sp = User::where('spread_uid', 'in', $sp)->column('uid');
+//                if (count($sp)) $uids = array_merge($uids, $sp);
+//            }
+//            $orders = StoreOrder::where('paid', 1)
+//                ->where('status', 'in', [2, 3])
+//                ->where('uid', 'in', $uids)
+//                ->where('refund_status', 0)
+//                ->where('is_del', 0)
+//                ->where('is_system_del', 0)->select();
+//            $num = 0;
+//            foreach ($orders as $v) {
+//                $num += StoreCart::where('id', 'in', $v['cart_id'])->where('is_suit', 1)->sum('cart_num');
+//            }
             $level_info = self::where('id', $spread['group_level'])->find();
             $level = self::where('level_num', '>', $level_info['level_num'] ?? 0)->order('level_num', 'desc')->select();
             foreach ($level as $v) {
-                if ($num >= $v['level_num']) {
+                if ($spread['group_suit_num'] >= $v['level_num']) {
                     User::where('uid', $spread['uid'])->update(['group_level' => $v['id']]);
                     break;
                 }

+ 33 - 36
app/models/system/SystemStoreStock.php

@@ -1,5 +1,7 @@
 <?php
+
 namespace app\models\system;
+
 use app\admin\model\store\StoreProduct;
 use app\admin\model\store\StoreProductAttrValue;
 use app\models\store\StoreOrderCartInfo;
@@ -9,37 +11,36 @@ use crmeb\traits\ModelTrait;
 class SystemStoreStock extends BaseModel
 {
     use ModelTrait;
-    public  static function lst($where)
+
+    public static function lst($where)
     {
         $model = new self;
-        $model = $model->alias("a")->join("store_product b","a.product_id=b.id","right");
-        if($where['store_id']>0)  $model = $model->where('a.store_id',$where['store_id']);
-        if($where['key']) $model = $model->wherelike('b.store_name',"%".$where['key']."%");
-        if(isset($where['is_warn']) && $where['is_warn']==1) $model = $model->where('a.in_stock','<=',sys_config('warn_stock'));
-        $model = $model->where('a.id','>',0);
+        $model = $model->alias("a")->join("store_product b", "a.product_id=b.id", "right");
+        if ($where['store_id'] > 0) $model = $model->where('a.store_id', $where['store_id']);
+        if ($where['key']) $model = $model->wherelike('b.store_name', "%" . $where['key'] . "%");
+        if (isset($where['is_warn']) && $where['is_warn'] == 1) $model = $model->where('a.in_stock', '<=', sys_config('warn_stock'));
+        $model = $model->where('a.id', '>', 0);
         $model = $model->field('a.product_id,b.store_name,b.image,b.is_show,b.is_del,a.store_id,a.in_stock,a.store_sales,a.repair_sales,a.in_last_time,a.bar_code,a.price,a.is_consumer');
         $count = $model->count();
-        $data = $model->page($where['page'],$where['limit'])->order("product_id desc")->select()->toarray();
-        foreach ($data as &$v)
-        {
-            $v['store'] = SystemStore::where('id',$v['store_id'])->value('name');
+        $data = $model->page($where['page'], $where['limit'])->order("product_id desc")->select()->toarray();
+        foreach ($data as &$v) {
+            $v['store'] = SystemStore::where('id', $v['store_id'])->value('name');
         }
-        return compact('count','data');
+        return compact('count', 'data');
     }
 
     /**
      * 店铺初始商品库存
      * @param int $num
      */
-    public static function store_init($store_id,$num=100)
+    public static function store_init($store_id, $num = 100)
     {
-        $list = StoreProduct::where('is_del',0)->where('is_show',1)->column('id,is_consumer','id');
+        $list = StoreProduct::where('is_del', 0)->where('is_show', 1)->column('id,is_consumer', 'id');
         $data['store_id'] = $store_id;
         $data['in_stock'] = $num;
         $all = [];
-        $rs = StoreProductAttrValue::where('product_id','in',array_keys($list))->field('product_id,unique,image,bar_code,price')->select()->toArray();
-        foreach ($rs as $v)
-        {
+        $rs = StoreProductAttrValue::where('product_id', 'in', array_keys($list))->field('product_id,unique,image,bar_code,price')->select()->toArray();
+        foreach ($rs as $v) {
             $data['product_id'] = $v['product_id'];
             $data['in_last_time'] = time();
             $data['unique'] = $v['unique'];
@@ -62,7 +63,7 @@ class SystemStoreStock extends BaseModel
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public static function replenish($store_id,$data)
+    public static function replenish($store_id, $data)
     {
         if ($data['product_id'] > 0 && $data['in_stock'] > 0) {
             $info = self::where(['store_id' => $store_id, 'product_id' => $data['product_id'], 'bar_code' => $data['bar_code']])->find();
@@ -78,20 +79,19 @@ class SystemStoreStock extends BaseModel
         }
         return false;
     }
-    public static function Refund($orderInfo,$data)
+
+    public static function Refund($orderInfo, $data)
     {
-        $reg_store_id = $orderInfo['reg_store_id'] ;
-        if($orderInfo['create_store_id']>0)
-        {
+        $reg_store_id = $orderInfo['reg_store_id'];
+        if ($orderInfo['create_store_id'] > 0) {
             $reg_store_id = $orderInfo['create_store_id'];
         }
         $store_id = $orderInfo['store_id'];
         $field = "store_sales";
-        if(intval($reg_store_id)>0 && intval($reg_store_id)!=$store_id)
-        {
+        if (intval($reg_store_id) > 0 && intval($reg_store_id) != $store_id) {
             $field = "repair_sales";
         }
-        self::where("product_id",$data['product_id'])->where('unique',$data['product_attr_unique'])->where('store_id',$store_id)->inc('in_stock',$data['cart_num'])->dec($field,$data['cart_num'])->update();
+        self::where("product_id", $data['product_id'])->where('unique', $data['product_attr_unique'])->where('store_id', $store_id)->inc('in_stock', $data['cart_num'])->dec($field, $data['cart_num'])->update();
         return true;
     }
 
@@ -101,17 +101,16 @@ class SystemStoreStock extends BaseModel
      */
     public static function add_store_sales($orderInfo)
     {
+        if ($orderInfo['suit']) return;
         $cartId = is_string($orderInfo['cart_id']) ? json_decode($orderInfo['cart_id'], true) : $orderInfo['cart_id'];
         $cartInfo = StoreOrderCartInfo::whereIn('cart_id', $cartId)->column('cart_info');
-        $reg_store_id = $orderInfo['reg_store_id'] ;
-        if($orderInfo['create_store_id']>0)
-        {
+        $reg_store_id = $orderInfo['reg_store_id'];
+        if ($orderInfo['create_store_id'] > 0) {
             $reg_store_id = $orderInfo['create_store_id'];
         }
         $store_id = $orderInfo['store_id'];
         $field = "store_sales";
-        if(intval($reg_store_id)>0 && intval($reg_store_id)!=$store_id)
-        {
+        if (intval($reg_store_id) > 0 && intval($reg_store_id) != $store_id) {
             $field = "repair_sales";
         }
         foreach ($cartInfo as $value) {
@@ -123,13 +122,11 @@ class SystemStoreStock extends BaseModel
             $bar_code = $product['productInfo']['attrInfo']['bar_code'];
             $price = $product['productInfo']['attrInfo']['price'];
             $image = $product['productInfo']['attrInfo']['image'];
-            if(self::be(compact('product_id','unique','is_consumer','store_id'))) {
-                self::where(compact('product_id', 'unique', 'is_consumer', 'store_id'))->inc($field, $cartNum)->dec('in_stock',$cartNum)->update();
-            }
-            else
-            {
-                $in_stock = 0-intval($cartNum);
-                self::create(compact('product_id', 'unique', 'is_consumer', 'store_id','bar_code','price','image','in_stock'));
+            if (self::be(compact('product_id', 'unique', 'is_consumer', 'store_id'))) {
+                self::where(compact('product_id', 'unique', 'is_consumer', 'store_id'))->inc($field, $cartNum)->dec('in_stock', $cartNum)->update();
+            } else {
+                $in_stock = 0 - intval($cartNum);
+                self::create(compact('product_id', 'unique', 'is_consumer', 'store_id', 'bar_code', 'price', 'image', 'in_stock'));
             }
         }
     }

+ 1 - 0
crmeb/repositories/NoticeRepositories.php

@@ -62,6 +62,7 @@ class NoticeRepositories
                 Log::error('购买后发送提醒失败,错误原因:' . $e->getMessage());
             }
         }
+        if ($order['suit']) return;
         //打印小票
         $switch = sys_config('pay_success_printing_switch') ? true : false;
         if ($switch) {

+ 0 - 13
crmeb/repositories/OrderRepository.php

@@ -159,10 +159,6 @@ class OrderRepository
     {
         $res1 = StoreOrder::gainUserIntegral($order);
         $res2 = User::backOrderBrokerage($order);
-        $res2 = $res2 && SystemGroupLevel::checkLevel($order['uid']);
-        $res2 = $res2 && SystemAwardLevel::checkLevel($order['uid']);
-        $res2 = $res2 && StoreOrder::sendSuit($order);
-        $res2 = $res2 && StoreOrder::sendGroupAward($order);
         StoreOrder::orderTakeAfter($order);
         //满赠优惠券
         WechatUser::userTakeOrderGiveCoupon($uid, $order['pay_price']);
@@ -178,11 +174,6 @@ class OrderRepository
     {
         $res1 = AdminStoreOrder::gainUserIntegral($order);
         $res2 = User::backOrderBrokerage($order);
-//        $res2 = $res2 && StoreOrder::addAchievement($order);
-        $res2 = $res2 && SystemGroupLevel::checkLevel($order['uid']);
-        $res2 = $res2 && SystemAwardLevel::checkLevel($order['uid']);
-        $res2 = $res2 && StoreOrder::sendSuit($order);
-        $res2 = $res2 && StoreOrder::sendGroupAward($order);
         AdminStoreOrder::orderTakeAfter($order);
         //满赠优惠券
         WechatUser::userTakeOrderGiveCoupon($order['uid'], $order['pay_price']);
@@ -199,10 +190,6 @@ class OrderRepository
     {
         $res1 = AdminStoreOrder::gainUserIntegral($order, false);
         $res2 = User::backOrderBrokerage($order, false);
-        $res2 = $res2 && SystemGroupLevel::checkLevel($order['uid']);
-        $res2 = $res2 && SystemAwardLevel::checkLevel($order['uid']);
-        $res2 = $res2 && StoreOrder::sendSuit($order);
-        $res2 = $res2 && StoreOrder::sendGroupAward($order);
         AdminStoreOrder::orderTakeAfter($order);
         UserBill::where('uid', $order['uid'])->where('link_id', $order['id'])->where('type', 'pay_money')->update(['take' => 1]);
         if (!($res1 && $res2)) exception('收货失败!');

+ 2 - 3
crmeb/subscribes/OrderSubscribe.php

@@ -148,9 +148,8 @@ class OrderSubscribe
         NoticeRepositories::noticeOrderPaySuccess($order);
         //检测会员等级
         event('UserLevelAfter', [$order['uid']]);
-        if($order['is_consumer']==0)
-        {
-            SystemStoreMember::add_consume($order['uid'],$order['total_price']);
+        if ($order['is_consumer'] == 0 && !$order['suit']) {
+            SystemStoreMember::add_consume($order['uid'], $order['total_price']);
         }
 
         try {