Kirin 1 неделя назад
Родитель
Сommit
6750f5e75a

+ 38 - 34
app/controller/admin/v1/system/config/SystemConfig.php

@@ -232,7 +232,7 @@ class SystemConfig extends AuthController
         return $this->success($this->services->getNewFormBuildRule($type));
     }
 
-	/**
+    /**
      * 获取用户配置
      * @return mixed
      */
@@ -241,16 +241,16 @@ class SystemConfig extends AuthController
         return $this->success($this->services->getUserConfig($type));
     }
 
-	/**
- 	* 保存用户配置
-	* @param $type
-	* @return mixed
-	 */
+    /**
+     * 保存用户配置
+     * @param $type
+     * @return mixed
+     */
     public function saveUserConfig($type)
     {
-		$post = $this->request->post();
-		$this->validate($post, \app\validate\admin\setting\SystemConfigValidate::class);
-		$this->services->saveUserConfig($type, $post);
+        $post = $this->request->post();
+        $this->validate($post, \app\validate\admin\setting\SystemConfigValidate::class);
+        $this->services->saveUserConfig($type, $post);
         return $this->success('保存成功');
     }
 
@@ -281,25 +281,25 @@ class SystemConfig extends AuthController
                 }
             }
         }
-		//打开友情链接 && 友情链接有配置内容
-		if (isset($post['links_list']) && !empty($post['links_list']) && isset($post['links_open']) && $post['links_open']) {
-			foreach ($post['links_list'] as $item) {
-				foreach ($item as $v => $k) {
-					if ('' === $item[$v]) {
-						return $this->fail('友情链接内容不能为空');
-					}
-				}
-			}
-		}
-		if (isset($post['filing_list']) && !empty($post['filing_list'])) {
-			foreach ($post['filing_list'] as $item) {
-				foreach ($item as $v => $k) {
-					if ('' === $item[$v]) {
-						return $this->fail('PC底部自定义展示内容不能为空');
-					}
-				}
-			}
-		}
+        //打开友情链接 && 友情链接有配置内容
+        if (isset($post['links_list']) && !empty($post['links_list']) && isset($post['links_open']) && $post['links_open']) {
+            foreach ($post['links_list'] as $item) {
+                foreach ($item as $v => $k) {
+                    if ('' === $item[$v]) {
+                        return $this->fail('友情链接内容不能为空');
+                    }
+                }
+            }
+        }
+        if (isset($post['filing_list']) && !empty($post['filing_list'])) {
+            foreach ($post['filing_list'] as $item) {
+                foreach ($item as $v => $k) {
+                    if ('' === $item[$v]) {
+                        return $this->fail('PC底部自定义展示内容不能为空');
+                    }
+                }
+            }
+        }
         $this->validate($post, \app\validate\admin\setting\SystemConfigValidate::class);
         if (isset($post['upload_type'])) {
             $this->services->checkThumbParam($post);
@@ -330,16 +330,16 @@ class SystemConfig extends AuthController
             }
         }
         //小程序支付
-        if(isset($post['pay_routine_open']) && $post['pay_routine_open']) {
+        if (isset($post['pay_routine_open']) && $post['pay_routine_open']) {
             if (empty($post['pay_routine_mchid'])) {
                 return $this->fail('小程序商户号不能为空');
             }
         }
-		if (isset($post['routine_auth_type'])) {
-			if (empty($post['routine_auth_type']) || count($post['routine_auth_type']) == 0) {
-				return app('json')->fail('手机号获取方式至少选择一个');
-			}
-		}
+        if (isset($post['routine_auth_type'])) {
+            if (empty($post['routine_auth_type']) || count($post['routine_auth_type']) == 0) {
+                return app('json')->fail('手机号获取方式至少选择一个');
+            }
+        }
         //全场包邮开关
         if (isset($post['whole_free_shipping'])) {
             $wholeFreeShipping = (int)$post['whole_free_shipping'];
@@ -349,6 +349,10 @@ class SystemConfig extends AuthController
             unset($post['whole_free_shipping']);
         }
 
+        if (isset($post['default_send_day'])) {
+            $post['default_send_day_start_time'] = time();
+        }
+
         foreach ($post as $k => $v) {
             $config_one = $this->services->getOne(['menu_name' => $k]);
             if ($config_one) {

+ 2 - 0
app/controller/admin/v1/user/User.php

@@ -504,6 +504,8 @@ class User extends AuthController
             ['spread_uid', -1],
             ['area_admin', -1],
             ['is_shop', -1],
+            ['reorder', -1],
+            ['max_order_count', -1],
             ['area_admin_province', ''],
             ['area_admin_city', ''],
             ['area_admin_district', ''],

+ 3 - 1
app/jobs/integral/IntegralJob.php

@@ -44,6 +44,8 @@ class IntegralJob extends BaseJobs
 //                $static_integral_ratio = sys_config('static_integral_ratio', 0);
                 $rate = sys_config('static_integral_rate', 3);
                 $award_order_limit = sys_config('award_order_limit');
+
+                $award_order_limit_2 = sys_config('award_order_limit_2');
                 $give_static_integral = bcmul($total_price, $rate);
                 if ($give_static_integral > 0) {
 //                $extract_sum = bcmul($total_price, $rate, 2);
@@ -97,7 +99,7 @@ class IntegralJob extends BaseJobs
                     $give_action_integral = bcdiv(bcmul($total_price, $ratio), 100, 2);
                     if ($give_action_integral > $send && $spread['is_promoter']) {
                         $real_send = bcsub($give_action_integral, $send, 2);
-                        if ($awardIntegralService->getPaySum($spread['uid']) >= $award_order_limit || $spread['award_switch']) {
+                        if ($awardIntegralService->getPaySum2($spread['uid']) >= $award_order_limit_2 || $spread['award_switch']) {
                             $extract_sum = bcmul($real_send, $rate, 2);
                             $mark = '团队用户' . $user['nickname'] . "({$user['uid']})" . '购买商品,获得团队级差积分';
                             $this->sendAward($extract_sum, $spread['uid'], $mark, $order['id']);

+ 20 - 0
app/model/user/AwardIntegral.php

@@ -119,6 +119,26 @@ class AwardIntegral extends BaseModel
             $query->where('order_price', '<', $award_order_limit);
         }
     }
+    /**
+     * 门店ID
+     * @param $query
+     * @param $value
+     */
+    public function searchValidsAttr($query, $value)
+    {
+        $award_order_limit_type = sys_config('award_order_limit_type_2');
+        $award_order_limit = sys_config('award_order_limit_2');
+        if ($award_order_limit_type == 1) $award_order_limit = 0.01;
+        if ($value == 1) {
+            $query->where('status', 0)->where('sent_num<num')->where('order_price', '>=', $award_order_limit);
+        } else if ($value == 2) {
+            $query->where(function ($query) {
+                $query->where('status', 1)->whereOr('sent_num>=num');
+            })->where('order_price', '>=', $award_order_limit);
+        } else {
+            $query->where('order_price', '<', $award_order_limit);
+        }
+    }
 
 
     /**

+ 25 - 0
app/services/order/StoreOrderCreateServices.php

@@ -25,6 +25,7 @@ use app\services\product\category\StoreProductCategoryServices;
 use app\services\product\shipping\ShippingTemplatesFreeServices;
 use app\services\product\shipping\ShippingTemplatesRegionServices;
 use app\services\product\shipping\ShippingTemplatesServices;
+use app\services\user\AwardIntegralServices;
 use app\services\wechat\WechatUserServices;
 use app\services\BaseServices;
 use crmeb\services\CacheService;
@@ -142,6 +143,7 @@ class StoreOrderCreateServices extends BaseServices
         $cartInfo = $cartGroup['cartInfo'];
         $priceGroup = $cartGroup['priceGroup'];
         if ($priceGroup['awardPrice'] > 0 && $useIntegral) throw new ValidateException('增值商品不能使用消费分抵扣!');
+
         $cartIds = [];
         $totalNum = 0;
         $gainIntegral = 0;
@@ -239,6 +241,29 @@ class StoreOrderCreateServices extends BaseServices
         if ($orderInfo['award_price'] < sys_config('min_price', 0) && sys_config('min_price', 0) > 0 && $orderInfo['award_price'] > 0) {
             throw new ValidateException('下单金额不低于' . sys_config('min_price'));
         }
+
+        if ($orderInfo['award_price'] > 0) {
+
+            $awardService = app()->make(AwardIntegralServices::class);
+            $main_orders = $awardService->search(['uid' => $uid, 'link_id' => 0, 'order_price_elt' => $orderInfo['award_price'], 'valid' => 2])->order('id asc')->column('id');//满足复投条件的主单
+            $link_id = 0;
+            foreach ($main_orders as $v) {
+                $can_reorder = $this->dao->search(['uid' => $uid, 'valid' => 1, 'link_id' => $v])->find();
+                if (!$can_reorder) {
+                    $link_id = $v;
+                    break;
+                }
+            }
+            if ($link_id > 0) {
+                if (!$userInfo['reorder']) throw new ValidateException('暂不支持复投');
+            }
+            $order_count = $awardService->search(['uid' => $uid])->count();
+            if ($userInfo['max_order_count'] > 0 && $order_count >= $userInfo['max_order_count']) {
+                throw new ValidateException('报单数量已达上限');
+            }
+
+            throw new ValidateException('下单金额不低于' . sys_config('min_price'));
+        }
         $orderPre = $this->dao->search(['uid' => $uid, 'is_del' => 0, 'is_system_del' => 0])->order('add_time', 'desc')->find();
         if ($orderPre && $orderPre['add_time'] > (time() - (sys_config('order_time', 0) * 60))) {
             throw new ValidateException('请等待' . ((sys_config('order_time', 0) * 60) - (time() - $orderPre['add_time'])) . '秒后再下单');

+ 2 - 0
app/services/system/config/SystemConfigServices.php

@@ -1549,6 +1549,8 @@ WSS;
                 Build::inputNum('shop_integral_trade_commission_shop', $data['shop_integral_trade_commission_shop']['info'], $data['shop_integral_trade_commission_shop']['value'])->min(0)->info($data['shop_integral_trade_commission_shop']['desc']),
                 Build::switch('award_order_limit_type', $data['award_order_limit_type']['info'], $data['award_order_limit_type']['value'])->trueValue('累计', 1)->falseValue('单个订单', 0),
                 Build::inputNum('award_order_limit', $data['award_order_limit']['info'], $data['award_order_limit']['value'])->min(0)->info($data['award_order_limit']['desc']),
+                Build::switch('award_order_limit_type_2', $data['award_order_limit_type_2']['info'], $data['award_order_limit_type_2']['value'])->trueValue('累计', 1)->falseValue('单个订单', 0),
+                Build::inputNum('award_order_limit_2', $data['award_order_limit_2']['info'], $data['award_order_limit_2']['value'])->min(0)->info($data['award_order_limit_2']['desc']),
             ])->option('提现设置', [
                 Build::alert('微信提现到零钱为自动到账(需要开通微信:企业付款到零钱(商家转账到零钱),并确保配置微信支付证书正确,特别注意:需要配置场景、开启API发起转账),其他方式均需要手动转账', Alert::WARNING)->showIcon(true),
                 Build::radio('brokerage_type', $data['brokerage_type']['info'], $data['brokerage_type']['value'])->options($this->getOptions($data['brokerage_type']['parameter']))->control(1, [

+ 10 - 1
app/services/user/AwardIntegralServices.php

@@ -98,6 +98,14 @@ class AwardIntegralServices extends BaseServices
     {
         $where = ['uid' => $uid, 'valid' => 1];
         return $this->dao->sum($where, 'order_price', true);
+    } /**
+     * 获取单条数据
+     * @return float
+     */
+    public function getPaySum2($uid)
+    {
+        $where = ['uid' => $uid, 'valids' => 1];
+        return $this->dao->sum($where, 'order_price', true);
     }
 
 
@@ -142,6 +150,7 @@ class AwardIntegralServices extends BaseServices
 //        $inc_integral = bcdiv($total, $price, 5);
         //计算释放天数
         $default_send_day = sys_config('default_send_day', 90);
+        $rest_time = sys_config('default_send_day_start_time', 0);
         $reorder_inc = sys_config('reorder_int_send_day', 10);
         $order_inc = sys_config('int_send_day', 10);
         //寻找复投机会
@@ -156,7 +165,7 @@ class AwardIntegralServices extends BaseServices
                 break;
             }
         }
-        $last_order_send_day = $this->dao->search(['uid' => $uid])->order('id desc')->value('send_day');
+        $last_order_send_day = $this->dao->search(['uid' => $uid, 'add_time_gt' => $rest_time])->order('id desc')->value('send_day');
         if (!$last_order_send_day) $send_day = $default_send_day;
         else {
             if ($link_id > 0) $send_day = $last_order_send_day + $reorder_inc;

+ 5 - 1
app/services/user/UserServices.php

@@ -608,7 +608,9 @@ class UserServices extends BaseServices
         }
         $f[] = Form::radio('status', '用户状态', $user->getData('status'))->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '锁定']]);
         $f[] = Form::radio('award_switch', '级差奖无需复投', $user->getData('award_switch'))->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
-        $f[] = Form::radio('is_shop', '商家', $user->getData('is_shop'))->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '锁定']]);
+        $f[] = Form::radio('is_shop', '商家', $user->getData('is_shop'))->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
+        $f[] = Form::radio('reorder', '允许复投', $user->getData('reorder'))->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
+        $f[] = Form::input('max_order_count', '最多报单单数', $user->getData('max_order_count'));
         return create_form('编辑', $f, Url::buildUrl('/user/user/' . $id), 'PUT');
     }
 
@@ -911,6 +913,8 @@ class UserServices extends BaseServices
             $edit['area'] = $data['area'];
             $edit['street'] = $data['street'];
             $edit['is_shop'] = (isset($data['is_shop']) && $data['is_shop'] >= 0) ? $data['is_shop'] : $user['is_shop'];
+            $edit['max_order_count'] = (isset($data['max_order_count']) && $data['max_order_count'] >= 0) ? $data['max_order_count'] : $user['max_order_count'];
+            $edit['reorder'] = (isset($data['reorder']) && $data['reorder'] >= 0) ? $data['reorder'] : $user['reorder'];
             if (isset($data['extend_info']) && $data['extend_info']) $edit['extend_info'] = $data['extend_info'];
             if ($user['level'] != $data['level']) {
                 /** @var UserLevelServices $userLevelService */