| | |
| | | { |
| | | //如果不是股东,列出条件 by lyzflash |
| | | $is_shareholder = $this->isShareholderUser(); |
| | | if (!$is_shareholder){ |
| | | if ( (new ShareholderApplyModel)->becomeShareholderByTeam($this->user['user_id'],110,$this->user['app_id'])){ |
| | | // 股东信息 |
| | | $this->shareholder = ShareholderUserModel::detail($this->user['user_id'],['user','grade']); |
| | | //如果不是股东,列出条件 by lyzflash |
| | | $is_shareholder = $this->isShareholderUser(); |
| | | } |
| | | } |
| | | $setting = $this->setting['basic']['values']; |
| | | $agent_total = $agent_money = $team_money = 0; |
| | | //统计下级分销商总数 |
| | |
| | | $product['total_num'] = $item['total_num']; |
| | | // 商品总价 |
| | | $product['total_price'] = bcmul($product['product_price'], $item['total_num'], 2); |
| | | // 商品总结算价 |
| | | $product['total_settlement_price'] = bcmul($product['settlement_price'], $item['total_num'], 2); |
| | | // 供应商 |
| | | $product['shop_supplier_id'] = $item['shop_supplier_id']; |
| | | $product['supplier_price'] = bcmul($product['supplier_price'], $item['total_num'], 2); |
| | |
| | | $item['spec_sku_id'] = $item['product_sku']['spec_sku_id']; |
| | | // 商品购买总金额 |
| | | $item['total_price'] = helper::bcmul($item['product_price'], $params['product_num']); |
| | | // 商品总结算价 |
| | | $item['total_settlement_price'] = helper::bcmul($item['settlement_price'], $params['product_num']); |
| | | } |
| | | $supplierData[] = [ |
| | | 'shop_supplier_id' => $product['shop_supplier_id'], |
| | |
| | | } |
| | | |
| | | return $model->with(['user', 'vipUser', 'referee','orderMaster'=>['product'=>['image']]]) |
| | | ->where('is_invalid', '=', 0) |
| | | ->order(['create_time' => 'desc']) |
| | | ->paginate($query); |
| | | } |
| | |
| | | ->where('s.is_delete', '=', '0') |
| | | ->where('s.is_recycle', '=', 0) |
| | | //->where('s.is_full', '=', 1) |
| | | ->field("s.shop_supplier_id,s.name,s.fav_count,logo_id,category_id,server_score,product_sales,address,link_phone") |
| | | ->field("s.shop_supplier_id,s.name,s.fav_count,logo_id,category_id,server_score,product_sales,address,link_phone,longitude,latitude") |
| | | ->order($sort) |
| | | ->paginate($param); |
| | | $product_model = new ProductModel(); |
| | |
| | | $v['productList'] = $productList; |
| | | $v['logos'] = isset($v['logo'])?$v['logo']['file_path']:''; |
| | | $v['category_name'] = $v['category']['name']; |
| | | $v['latitude'] = (float)$v['latitude']; |
| | | $v['longitude'] = (float)$v['longitude']; |
| | | unset($v['logo']); |
| | | unset($v['category']); |
| | | } |
| | |
| | | // 设置订单商品总金额(不含优惠折扣) |
| | | $this->setOrderTotalPrice($supplier['productList']); |
| | | $orderTotalPrice += $this->orderData['order_total_price']; |
| | | // 设置订单商品总结算金额(不含优惠折扣) |
| | | // 设置订单商品总结算金额 |
| | | $this->setOrderSettlementPrice($supplier['productList']); |
| | | $settlementPrice += $this->orderData['settlement_price']; |
| | | // 先计算商品满减 |
| | |
| | | 'consumption_bonus' => isset($product['consumption_bonus'])?$product['consumption_bonus']:0, |
| | | 'total_num' => $product['total_num'], |
| | | 'total_price' => $product['total_price'], |
| | | 'total_settlement_price' => $product['total_settlement_price'], |
| | | 'total_pay_price' => $product['total_pay_price'], |
| | | 'supplier_money' => $product['supplier_money'], |
| | | 'is_agent' => $product['is_agent'], |
| | |
| | | $product['max_points_num'] = $product['points_num']; |
| | | } else { |
| | | // 商品不允许积分抵扣 |
| | | if (!$product['is_points_discount']) continue; |
| | | if (!$product['is_points_discount']||$product['is_vip']||$product['is_newcomer']||$product['is_repurchase']) continue; |
| | | // 积分抵扣比例 |
| | | $deductionRatio = helper::bcdiv($setting['discount']['max_money_ratio'], 100); |
| | | // 最多可抵扣的金额 |
| | |
| | | const DIRECT_SUPPLIER = 50; // 直推供应商佣金 |
| | | |
| | | const VIEWPOINT_MONEY = 60; // 见点佣金 |
| | | const DIFFERENTIALPRIZE=70;//级差 |
| | | const EQUALLEVELAWARD= 80;//平级奖 |
| | | |
| | | |
| | | |
| | |
| | | self::DIRECT_REFEREE => '平台直推佣金', |
| | | self::DIRECT_SUPPLIER => '直推商家佣金', |
| | | self::VIEWPOINT_MONEY => '见点佣金', |
| | | self::DIFFERENTIALPRIZE=> '级差奖', |
| | | self::EQUALLEVELAWARD=> '平级奖', |
| | | ]; |
| | | } |
| | | |
| | |
| | | |
| | | public static function getUserOrderCount($user_id) |
| | | { |
| | | return (new static())->where('second_user_id', '=', $user_id) |
| | | return (new static())->where(['second_user_id'=>$user_id,'is_invalid'=>0]) |
| | | ->count(); |
| | | } |
| | | |
| | |
| | | 'order_id' => $order['order_id'], |
| | | 'order_type' => $order_type, |
| | | 'order_price' => bcsub($order['pay_price'], $order['express_price'], 2), |
| | | 'first_money' => $agentUser['first_user_id'] > 0 ? $one_money : 0, |
| | | 'first_money' => $one_money, |
| | | 'second_money' => $two_money, |
| | | 'first_user_id' => $one_money > 0 ?$agentUser['first_user_id']:0, |
| | | 'second_user_id' => $agentUser['second_user_id'], |
| | |
| | | $is_expire = User::isExpire($user_id); |
| | | // 队长详情 |
| | | $model = static::detail($user_id); |
| | | if (!$model || $model['is_delete']) { |
| | | if (!$model) { |
| | | return false; |
| | | } |
| | | if ($model['is_delete']){ |
| | | return false; |
| | | } |
| | | if ($money_type == 20){ |
| | |
| | | public static function isExpire($user_id) |
| | | { |
| | | $team = self::detail($user_id); |
| | | if (!$team) { |
| | | return false; |
| | | } |
| | | $setting = Setting::getItem('basic', $team['app_id']); |
| | | return !!$team && $team['is_expire'] && $team['is_permanent'] == 0 && $setting['expire_day'] > 0; |
| | | } |
| | |
| | | } |
| | | if ($config['become'] == '110'){ |
| | | $subordinateUserId=(new TeamRefereeModel())->where(['heads_id'=>$userId])->column('user_id'); |
| | | $subordinateUserId[]=$userId; |
| | | $vipNum=(new \app\common\model\user\User)->getRefereeGradeCount($subordinateUserId,$config['referee_grade_ids']); |
| | | $supplierNum=(new \app\common\model\supplier\Supplier())->getSubordinateNum($subordinateUserId); |
| | | $user=(new \app\common\model\user\User)->where(['user_id'=>$userId,'is_delete'=>0])->find(); |
| | |
| | | { |
| | | protected $name = 'vip_area_order'; |
| | | protected $pk = 'id'; |
| | | public $append=['vip_area_type_text']; |
| | | public $append = ['vip_area_type_text']; |
| | | |
| | | /** |
| | | * VIP专区订单类型 |
| | | * @param $value |
| | |
| | | public function getVipAreaTypeTextAttr($value, $data) |
| | | { |
| | | $types = VipAreaTypeEnum::getTypeName(); |
| | | return $types[$data['vip_area_type']]; |
| | | return $types[$data['vip_area_type']]; |
| | | } |
| | | |
| | | /** |
| | |
| | | ->where('order_type', '=', $orderType) |
| | | ->find(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取订单的所有VIP专区订单记录 |
| | | */ |
| | |
| | | if ($order['order_status']['value'] != 30) { |
| | | return false; |
| | | } |
| | | |
| | | |
| | | // 获取该订单的所有VIP专区订单记录 |
| | | $models = self::getAllDetailsByOrderId($order['order_id'], $orderType); |
| | | if ($models->isEmpty()) { |
| | | return false; |
| | | } |
| | | |
| | | |
| | | // 佣金结算天数 |
| | | $settleDays = Setting::getItem('settlement', $order['app_id'])['settle_days']; |
| | | $success = false; |
| | |
| | | if ($model['is_settled'] == 1) { |
| | | continue; |
| | | } |
| | | |
| | | |
| | | // 写入结算时间 |
| | | $deadlineTime = $model['settle_time'] ?: 0; |
| | | if($deadlineTime == 0){ |
| | | $deadlineTime = $order['receipt_time'] + $settleDays * 86400; |
| | | if ($deadlineTime == 0) { |
| | | $deadlineTime = $order['receipt_time'] + $settleDays * 86400; |
| | | $model->save([ |
| | | 'settle_time' => $deadlineTime |
| | | ]); |
| | | } |
| | | |
| | | |
| | | // 未到结算时间,跳过 |
| | | if ($deadlineTime > time()) { |
| | | continue; |
| | |
| | | if ($model['vip_area_user_id'] != 0) { |
| | | User::grantMoney($model['vip_area_user_id'], $model['vip_area_money'], VipAreaTypeEnum::getTypeName()[$model['vip_area_type']]); |
| | | } |
| | | // 发放VIP专区补贴给下级用户(当下级获得推广佣金或复购佣金时) |
| | | // 发放下级收益补贴给下级用户(当下级获得推广佣金或复购佣金时) |
| | | if ($model['vip_area_type'] == 10 || $model['vip_area_type'] == 20) { |
| | | // 获取下级用户的推荐人(即上级用户) |
| | | $superiorUser = UserModel::detail($model['vip_area_user_id']); |
| | | if ($superiorUser && $superiorUser['referee_id']) { |
| | | $vipUser = VipUserModel::detail($superiorUser['vip_area_user_id']); |
| | | if ($vipUser['grade']['operating_subsidy']>0){ |
| | | if ($vipUser['grade']['operating_subsidy'] > 0) { |
| | | // 获取补贴比例设置 |
| | | $subsidyRate = $vipUser['grade']['operating_subsidy']; |
| | | // 计算VIP专区补贴 |
| | | // 计算下级收益补贴 |
| | | $subsidyAmount = bcmul($model['vip_area_money'], bcdiv((string)$subsidyRate, '100', 4), 2); |
| | | User::grantMoney($superiorUser['referee_id'], $subsidyAmount, 'VIP专区补贴'); |
| | | User::grantMoney($superiorUser['referee_id'], $subsidyAmount, '下级收益补贴'); |
| | | // 记录分销订单 |
| | | self::createDistributionOrder($order, $superiorUser['referee_id'], $subsidyAmount, 'vip_subsidy',$model['vip_area_money']); |
| | | self::createDistributionOrder($order, $superiorUser['referee_id'], $subsidyAmount, 'vip_subsidy', $model['vip_area_money']); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | // 发放平台直推佣金(满足直推条件后) |
| | | //self::grantPlatformCommission($order, $model); |
| | | |
| | | |
| | | // 更新VIP订单记录 |
| | | $model->save([ |
| | | 'is_settled' => 1, |
| | | 'settle_time' => time() |
| | | ]); |
| | | |
| | | |
| | | $success = true; |
| | | } |
| | | |
| | | |
| | | return $success; |
| | | } |
| | | |
| | |
| | | // 获取平台直推佣金设置 |
| | | $setting = Setting::getItem('basic', $order['app_id']); |
| | | $requiredReferralCount = $setting['referee_buy_count'] ?? 0; |
| | | |
| | | |
| | | // 如果设置了直推条件且用户有推荐人 |
| | | if ($requiredReferralCount > 0 && $model['vip_area_user_id'] > 0) { |
| | | // 检查推荐人是否满足直推条件(直推用户数量) |
| | | $directReferralsCount = UserModel::where('referee_id', '=', $model['vip_area_user_id'])->count(); |
| | | |
| | | |
| | | if ($directReferralsCount >= $requiredReferralCount) { |
| | | // 计算平台直推佣金 |
| | | $platformCommissionRate = $setting['platform_commission_rate'] ?? 5; |
| | | $platformCommissionAmount = bcmul($model['order_price'], bcdiv((string)$platformCommissionRate, '100', 4), 2); |
| | | |
| | | |
| | | // 发放平台直推佣金 |
| | | User::grantMoney($model['vip_area_user_id'], $platformCommissionAmount, '平台直推佣金'); |
| | | |
| | | |
| | | // 记录分销订单 |
| | | self::createDistributionOrder($order, $model['vip_area_user_id'], $platformCommissionAmount, 'platform_commission',$model['vip_area_money']); |
| | | self::createDistributionOrder($order, $model['vip_area_user_id'], $platformCommissionAmount, 'platform_commission', $model['vip_area_money']); |
| | | } |
| | | } |
| | | } |
| | |
| | | * @param $type |
| | | * @return bool |
| | | */ |
| | | protected static function createDistributionOrder($order, $userId, $amount, $type,$subordinate_money) |
| | | protected static function createDistributionOrder($order, $userId, $amount, $type, $subordinate_money) |
| | | { |
| | | // 创建分销订单记录以跟踪各种类型的佣金 |
| | | $distributionOrder = new self(); |
| | | $vip_area_type = 0; |
| | | switch($type) { |
| | | switch ($type) { |
| | | case 'vip_subsidy': |
| | | $vip_area_type = 30; // VIP专区补贴 |
| | | break; |
| | |
| | | $vip_area_type = 40; // 平台直推佣金 |
| | | break; |
| | | } |
| | | |
| | | |
| | | return $distributionOrder->save([ |
| | | 'user_id' => $userId, |
| | | 'order_id' => $order['order_id'], |
| | |
| | | 'settle_time' => 0, |
| | | 'app_id' => $order['app_id'] |
| | | ]; |
| | | $list=[]; |
| | | $list = []; |
| | | // 计算佣金金额 |
| | | $orderPrice = bcsub(bcsub($order['pay_price'], $order['express_price'], 2), $order['settlement_price'], 2); |
| | | $viewpoint_money=0; |
| | | //$viewpoint_money = 0; |
| | | // 获取当前买家的推荐人信息 |
| | | $userModel = UserModel::detail($order['user_id']); |
| | | if (!empty($userModel) && !empty($userModel['referee_id'])) { |
| | |
| | | $vipGrade = Grade::detail($vipUser['grade_id']); |
| | | if ($vipGrade) { |
| | | $config = Setting::getItem('basic', $order['app_id']); |
| | | if (!empty($config['become__buy_product_ids'])) { |
| | | $purchase_count=(new self())->getPurchaseCount($order['user_id']); |
| | | foreach ($order['product'] as $product){ |
| | | if ($product['is_repurchase']==1){ |
| | | $viewpoint_money=bcadd($viewpoint_money,($product['is_viewpoint_money']?$product['viewpoint_money']:$vipGrade['viewpoint_money']),2); |
| | | } |
| | | if (in_array($product['product_id'], $config['become__buy_product_ids'])||$product['is_vip']) { |
| | | // 获取商品数量 |
| | | $quantity = $product['total_num']; |
| | | // 为每个商品生成分红订单 |
| | | for ($i = 0; $i < $quantity; $i++) { |
| | | if ($purchase_count==1){ |
| | | $list[]=array_merge($data,['vip_area_type'=>10,'vip_area_money'=>$vipGrade['agent_money'],'is_vip'=>1,'purchase_count'=>$purchase_count]); |
| | | $purchase_count = (new self())->getPurchaseCount($order['user_id']); |
| | | $vip_quantity=0; |
| | | $product_price_repurchase=0; |
| | | foreach ($order['product'] as $product) { |
| | | /*if ($product['is_repurchase'] == 1) { |
| | | $viewpoint_money = bcadd($viewpoint_money, ($product['is_viewpoint_money'] ? $product['viewpoint_money'] : $vipGrade['viewpoint_money']), 2); |
| | | }*/ |
| | | if (in_array($product['product_id'], $config['become__buy_product_ids']) || $product['is_vip']) { |
| | | // 获取商品数量 |
| | | $vip_quantity = bcadd($vip_quantity, $product['total_num'], 2); |
| | | // 为每个商品生成分红订单 |
| | | /*for ($i = 0; $i < $quantity; $i++) { |
| | | if ($purchase_count == 1) { |
| | | $list[] = array_merge($data, ['vip_area_type' => 10, 'vip_area_money' => $vipGrade['agent_money'], 'is_vip' => 1, 'purchase_count' => $purchase_count]); |
| | | $purchase_count++; |
| | | } else { |
| | | if ($vipGrade['repurchase_money'] > 0) { |
| | | $list[] = array_merge($data, ['vip_area_type' => 20, 'vip_area_money' => $vipGrade['repurchase_money'], 'is_vip' => 1, 'purchase_count' => $purchase_count]); |
| | | $purchase_count++; |
| | | }else{ |
| | | if ($vipGrade['repurchase_money']>0){ |
| | | $list[]=array_merge($data,['vip_area_type'=>20,'vip_area_money'=>$vipGrade['repurchase_money'],'is_vip'=>1,'purchase_count'=>$purchase_count]); |
| | | $purchase_count++; |
| | | } |
| | | } |
| | | } |
| | | }*/ |
| | | } |
| | | //复购专区利润 |
| | | if($product['is_repurchase']){ |
| | | $product_price_repurchase=bcadd($product_price_repurchase, bcsub($product['total_pay_price'], $product['total_settlement_price'], 2)); |
| | | |
| | | } |
| | | } |
| | | if ($vip_quantity>0){ |
| | | if ($purchase_count == 1) { |
| | | $list[] = array_merge($data, ['vip_area_type' => 10, 'vip_area_money' => bcmul($vipGrade['agent_money'],$vip_quantity,2), 'is_vip' => 1, 'purchase_count' => $purchase_count]); |
| | | } else { |
| | | if ($vipGrade['repurchase_money'] > 0) { |
| | | $list[] = array_merge($data, ['vip_area_type' => 20, 'vip_area_money' => bcmul($vipGrade['repurchase_money'],$vip_quantity,2), 'is_vip' => 1, 'purchase_count' => $purchase_count]); |
| | | } |
| | | } |
| | | } |
| | | if ($product_price_repurchase>0){ |
| | | //复购专区级差奖 |
| | | if ($setting['jcaward']){ |
| | | $refereeJc=User::getAllJcUser($userModel['user_id']); |
| | | foreach ($refereeJc as $v){ |
| | | $list[] = array_merge($data, ['vip_area_type' => 70, 'vip_area_money' =>bcmul($product_price_repurchase, bcdiv($v['bonus_percent'], 100, 4), 2),'vip_area_user_id'=>$v['user_id']]); |
| | | } |
| | | } |
| | | //复购专区平级奖 |
| | | if ($setting['pjaward']){ |
| | | $refereeJc=User::getAllPjUser($userModel['user_id'],$setting['pjaward_level']); |
| | | foreach ($refereeJc as $v){ |
| | | $list[] = array_merge($data, ['vip_area_type' => 80, 'vip_area_money' => bcmul($product_price_repurchase, bcdiv($v['bonus_percent'], 100, 4), 2),'vip_area_user_id'=>$v['user_id']]); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 检查并处理直推佣金 |
| | | $directReferralsCount=0; |
| | | $user=UserModel::detail($order['user_id']); |
| | | $directReferralsCount = 0; |
| | | $user = UserModel::detail($order['user_id']); |
| | | //见点奖 |
| | | if (!empty($user['referee_id'])){ |
| | | /* if (!empty($user['referee_id'])) { |
| | | if ($viewpoint_money > 0 && (new User())->getViewpointMoneyQualification($user['referee_id'], $setting)) { |
| | | $list[] = array_merge($data, ['vip_area_type' => 60, 'vip_area_money' => $viewpoint_money]); |
| | | } |
| | | }*/ |
| | | $requiredReferralCount = $setting['referee_buy_count'] ?? 0; |
| | | if (!empty($user['referee_id'])) { |
| | | // 检查推荐人是否满足直推条件(直推用户数量) |
| | | $directReferralsCount = UserModel::where('referee_id', '=', $user['referee_id'])->count(); |
| | | if ($viewpoint_money>0&&(new User())->getViewpointMoneyQualification($user['referee_id'],$setting)){ |
| | | $list[]=array_merge($data,['vip_area_type'=>60,'vip_area_money'=>$viewpoint_money]); |
| | | } |
| | | } |
| | | $requiredReferralCount = $setting['referee_buy_count'] ?? 0; |
| | | if ($vipGrade['commission']>0 && $directReferralsCount >= $requiredReferralCount&&$orderPrice>0){ |
| | | if ($vipGrade['commission'] > 0 && $directReferralsCount >= $requiredReferralCount && $orderPrice > 0) { |
| | | // 计算平台直推佣金金额 |
| | | $commissionAmount = bcmul($orderPrice, bcdiv($vipGrade['commission'], '100', 4), 2); |
| | | $list[]=array_merge($data,['vip_area_type'=>40,'vip_area_money'=>$commissionAmount]); |
| | | $list[] = array_merge($data, ['vip_area_type' => 40, 'vip_area_money' => $commissionAmount]); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // 处理供应商推荐人佣金 |
| | | if($order['supplier']['referee_id']!=0){ |
| | | $supplierReferee=VipUserModel::detail($order['supplier']['referee_id']); |
| | | if ($supplierReferee){ |
| | | $vipGradeSupplier=Grade::detail($supplierReferee['grade_id']); |
| | | if ($vipGradeSupplier['supplier_money']>0&&$orderPrice>0){ |
| | | if ($order['supplier']['referee_id'] != 0) { |
| | | $supplierReferee = VipUserModel::detail($order['supplier']['referee_id']); |
| | | if ($supplierReferee) { |
| | | $vipGradeSupplier = Grade::detail($supplierReferee['grade_id']); |
| | | if ($vipGradeSupplier['supplier_money'] > 0 && $orderPrice > 0) { |
| | | // 计算直推店铺交易额佣金金额 |
| | | $supplier_money = bcmul($orderPrice, bcdiv($vipGrade['supplier_money'], '100', 4), 2); |
| | | $list[]=array_merge($data,['vip_area_type'=>50,'vip_area_money'=>$supplier_money,'vip_area_user_id'=>$supplierReferee['user_id'],'referee_id'=>$supplierReferee['referee_id']]); |
| | | $list[] = array_merge($data, ['vip_area_type' => 50, 'vip_area_money' => $supplier_money, 'vip_area_user_id' => $supplierReferee['user_id'], 'referee_id' => $supplierReferee['referee_id']]); |
| | | } |
| | | } |
| | | } |
| | | log_write($list); |
| | | if (empty($list)){ |
| | | if (empty($list)) { |
| | | return true; |
| | | } |
| | | // 保存VIP专区订单记录 |
| | | return $model->saveAll($list); |
| | | }catch (\Exception $e){ |
| | | log_write('创建VIP专区订单失败:'.$e->getMessage()); |
| | | } catch (\Exception $e) { |
| | | log_write('创建VIP专区订单失败:' . $e->getMessage()); |
| | | return false; |
| | | } |
| | | |
| | | } |
| | | |
| | | public function getPurchaseCount($user_id) |
| | | { |
| | | return self::where(['user_id'=>$user_id,'is_vip'=>1])->count()+1; |
| | | return self::where(['user_id' => $user_id, 'is_vip' => 1,'is_invalid'=>0])->count() + 1; |
| | | } |
| | | } |
| | |
| | | 'subsidy_rate' => '10', |
| | | // 平台直推佣金比例 |
| | | 'platform_commission_rate' => '5', |
| | | 'jcaward'=>'0', |
| | | 'pjaward'=>'0', |
| | | 'pjaward_level'=>1 |
| | | ], |
| | | ], |
| | | 'settlement' => [ |
| | |
| | | } |
| | | return false; |
| | | } |
| | | /** |
| | | |
| | | * 获取用户所有级差上级 |
| | | |
| | | */ |
| | | |
| | | public static function getAllJcUser($user_id, $jcUser = [], $percent_total = 0, $is_add = true) |
| | | |
| | | { |
| | | |
| | | $user = User::detail($user_id); |
| | | $is_add && $percent_total += $user['grade']['differential_prize'] - $percent_total; |
| | | if($user['referee_id']) { |
| | | $is_add = false; |
| | | $parent = User::detail($user['referee_id']); |
| | | if (!$parent){ |
| | | return $jcUser; |
| | | } |
| | | if ($parent['grade']['weight'] > $user['grade']['weight'] && $parent['grade']['differential_prize'] > $percent_total) { |
| | | $jcUser[] = [ |
| | | 'user_id' => $parent['user_id'], |
| | | 'bonus_percent' => $parent['grade']['differential_prize'] - $percent_total //分红比例 |
| | | ]; |
| | | $is_add = true; |
| | | |
| | | } |
| | | if($parent['user_id']) { |
| | | return self::getAllJcUser($parent['user_id'], $jcUser, $percent_total, $is_add); |
| | | } |
| | | |
| | | } |
| | | return $jcUser; |
| | | |
| | | } |
| | | |
| | | /** |
| | | |
| | | * 获取用户所有平级 |
| | | |
| | | * 每个级别都发放$pjaward_level层平级奖 |
| | | |
| | | */ |
| | | |
| | | public static function getAllPjUser($user_id, $pjaward_level, $pjUser = []) |
| | | |
| | | { |
| | | |
| | | $user = User::detail($user_id); |
| | | $pj_user[$user['grade_id']][] = []; |
| | | $pj_user = self::getPjUser($user_id, $pj_user); |
| | | if ($pj_user) { |
| | | foreach ($pj_user as $u) { |
| | | foreach ($u as $k => $item) { |
| | | if ($k > 0 && $k <= $pjaward_level) { |
| | | $pjUser[] = $item; |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | return $pjUser; |
| | | |
| | | } |
| | | /** |
| | | |
| | | * 获取所有平级 |
| | | |
| | | */ |
| | | |
| | | private static function getPjUser($user_id, $pj_user = []) |
| | | |
| | | { |
| | | |
| | | $user = User::detail($user_id); |
| | | if($user['referee_id']) { |
| | | $parent = User::detail($user['referee_id']); |
| | | if (!$parent){ |
| | | return $pj_user; |
| | | } |
| | | // 记录平级用户 |
| | | if($parent && $parent['grade']['weight'] >= $user['grade']['weight']) { |
| | | if ( $parent['grade']['equal_level_award']){ |
| | | $pj_user[$parent['grade_id']][] = [ |
| | | 'user_id' => $parent['user_id'], |
| | | 'bonus_percent' => $parent['grade']['equal_level_award'], // 平级分红比例 |
| | | ]; |
| | | } |
| | | } |
| | | if($parent['referee_id']) { |
| | | return self::getPjUser($parent['user_id'], $pj_user); |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | return $pj_user; |
| | | |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 所有分类 |
| | | */ |
| | | public static function getCategoryALL() |
| | | { |
| | | $model = new static; |
| | | if (!Cache::get('category_all_' . $model::$app_id)) { |
| | | $data = $model->with(['images'])->order(['sort' => 'asc', 'create_time' => 'asc'])->select(); |
| | | $all = !empty($data) ? $data->toArray() : []; |
| | | $tree = []; |
| | | foreach ($all as $first) { |
| | | if ($first['parent_id'] != 0) continue; |
| | | $twoTree = []; |
| | | foreach ($all as $two) { |
| | | if ($two['parent_id'] != $first['category_id']) continue; |
| | | $threeTree = []; |
| | | foreach ($all as $three) |
| | | $three['parent_id'] == $two['category_id'] |
| | | && $threeTree[$three['category_id']] = $three; |
| | | !empty($threeTree) && $two['child'] = $threeTree; |
| | | array_push($twoTree, $two); |
| | | } |
| | | if (!empty($twoTree)) { |
| | | $temp_two_tree = array_column($twoTree, 'sort'); |
| | | array_multisort($temp_two_tree, SORT_ASC, $twoTree); |
| | | $first['child'] = $twoTree; |
| | | } |
| | | array_push($tree, $first); |
| | | } |
| | | Cache::tag('cache')->set('category_all_' . $model::$app_id, compact('all', 'tree')); |
| | | } |
| | | return Cache::get('category_all_' . $model::$app_id); |
| | | } |
| | | |
| | | /** |
| | | * 获取所有分类 |
| | | */ |
| | | public static function getCacheAll() |
| | |
| | | protected $pk = 'shop_supplier_id'; |
| | | |
| | | |
| | | |
| | | /** |
| | | * 关联应用表 |
| | | */ |
| | |
| | | $quantity=0; |
| | | foreach ($product as $item){ |
| | | // 检查商品是否是指定的分红商品 |
| | | if (in_array($item['product_id'], $config['become__buy_product_ids'])) { |
| | | if (in_array($item['product_id'], $config['become__buy_product_ids'])||$item['is_vip']==1) { |
| | | // 获取商品数量 |
| | | $quantity+= $item['total_num']; |
| | | } |
| | |
| | | ->where('pay_status', '=', 20) |
| | | ->where('order_status', '=', 30) |
| | | ->where('is_delete', '=', 0) |
| | | ->where('create_time', '>=', $bonusData['start_time']) |
| | | ->where('create_time', '<', $bonusData['end_time']); |
| | | ->where('create_time', '>=', strtotime($bonusData['start_time'])) |
| | | ->where('create_time', '<=', strtotime($bonusData['end_time'])); |
| | | return $model->sum('pay_price'); |
| | | } |
| | | } |
| | |
| | | return 0; |
| | | } |
| | | |
| | | public static function getPurchaseCount($userId, $postData,$product_ids) |
| | | public static function getPurchaseCount($userId, $postData) |
| | | { |
| | | $model = new static(); |
| | | //搜索时间段 |
| | | if (!empty($postData['create_time'])) { |
| | | $sta_time = array_shift($postData['create_time']); |
| | | $end_time = array_pop($postData['create_time']); |
| | | $model = $model->whereBetweenTime('order.create_time', $sta_time, date('Y-m-d 23:59:59', strtotime($end_time))); |
| | | if (!empty($postData['start_time'])) { |
| | | $sta_time = $postData['start_time']; |
| | | $end_time = $postData['end_time']; |
| | | $model = $model->whereBetweenTime('order.create_time', strtotime($sta_time), strtotime($end_time)); |
| | | } |
| | | return $model->alias('o_product') |
| | | ->join('order', 'order.order_id = o_product.order_id') |
| | | ->where('order.pay_status', '=', OrderPayStatusEnum::SUCCESS) |
| | | ->where('order.order_status', '<>', OrderStatusEnum::CANCELLED) |
| | | ->where('o_product.user_id', '=', $userId) |
| | | ->where('o_product.product_id', 'in', $product_ids) |
| | | ->where('o_product.is_vip',1) |
| | | ->group('o_product.product_id') |
| | | ->sum("total_num"); |
| | | } |
| | |
| | | */ |
| | | public function getList($user_id = null, $is_settled = -1) |
| | | { |
| | | $model = $this; |
| | | $model = $this->where('is_invalid', '=', 0); |
| | | // 检索查询条件 |
| | | if ($user_id > 1) { |
| | | $model = $model->where('first_user_id|second_user_id', '=', $user_id); |
| | |
| | | //是否有可分红订单,1有,0无 |
| | | $is_bonus = 1; |
| | | $first_data = Order::orderFirst(); |
| | | if (empty($first_data)) { |
| | | if (empty($first_data)||!isset($first_data)) { |
| | | $is_bonus = 0; |
| | | $first_data['create_time']=date('Y-m-d'); |
| | | } |
| | | //可结算时间需要加上分红结算天数 |
| | | $create_time = strtotime($first_data['create_time']) + intval(Setting::getItem('settlement')['settle_days']) * 86400; |
| | |
| | | */ |
| | | class User extends UserModel |
| | | { |
| | | public static function checkExistByGradeId($grade_id) |
| | | { |
| | | self::where('grade_id',$grade_id)->find(); |
| | | } |
| | | |
| | | /** |
| | | * 获取股东用户列表 |
| | | */ |
| | |
| | | // 先获取所有股东 |
| | | $model = new static; |
| | | $shareholders = $model->where('is_delete', '=', 0)->with(['grade'])->select(); |
| | | |
| | | // 如果没有设置分红条件,返回所有股东 |
| | | if (empty($setting['consumption_amount']) && empty($setting['condition_purchase_count'])) { |
| | | return $shareholders; |
| | | } |
| | | |
| | | |
| | | // 过滤满足条件的股东 |
| | | $eligibleShareholders = []; |
| | | foreach ($shareholders as $shareholder) { |
| | | $userId = $shareholder['user_id']; |
| | | $isEligible = true; |
| | | |
| | | |
| | | // 检查消费金额条件 |
| | | if (!empty($setting['consumption_amount'])) { |
| | | $totalConsumption = (new OrderModel)->getUserTotalConsumption($userId,$bonusData); |
| | |
| | | |
| | | // 检查购买次数条件 |
| | | if (!empty($setting['condition_purchase_count']) && $isEligible) { |
| | | $purchaseCount = (new OrderProductModel)::getPurchaseCount($userId,$bonusData,$shareholder['product_ids']); |
| | | $purchaseCount = (new OrderProductModel)::getPurchaseCount($userId,$bonusData); |
| | | if ($purchaseCount < $setting['condition_purchase_count']) { |
| | | $isEligible = false; |
| | | } |
| | |
| | | */ |
| | | public function getList($param=[],$user_id = null, $is_settled = -1) |
| | | { |
| | | $model = $this->with(['user', 'vipUser'=>['user'], 'referee','orderMaster'=>['product'=>['image']]]); |
| | | $model = $this->with(['user', 'vipUser'=>['user'], 'referee','orderMaster'=>['product'=>['image']]]) |
| | | ->where('is_invalid', '=', 0); |
| | | // 筛选用户 |
| | | $user_id > 0 && $model = $model->where('user_id', '=', $user_id); |
| | | // 筛选结算状态 |
| | |
| | | * 删除缓存 |
| | | */ |
| | | private function deleteCache() |
| | | { |
| | | { Cache::delete('category_all_' . static::$app_id); |
| | | return Cache::delete('category_' . static::$app_id); |
| | | } |
| | | |
| | |
| | | public static function getEditData($model = null, $scene = 'edit') |
| | | { |
| | | // 商品分类 |
| | | $category = CategoryModel::getCacheTree(); |
| | | $category = CategoryModel::getCategoryALL()['tree']; |
| | | // 配送模板,仅仅查当前模板 |
| | | $delivery = []; |
| | | if($model){ |
| | |
| | | { |
| | | // 模板详情 |
| | | $model = CategoryModel::detail($category_id); |
| | | $data = $this->request->post(); |
| | | $data['shop_supplier_id'] = $this->getSupplierId(); |
| | | // 更新记录 |
| | | if ($model->edit($this->request->post())) { |
| | | if ($model->edit($data)) { |
| | | return $this->renderSuccess('更新成功'); |
| | | } |
| | | return $this->renderError($model->getError() ?: '更新失败'); |
| | |
| | | */ |
| | | public function edit($data) |
| | | { |
| | | if ($this['shop_supplier_id']==0){ |
| | | $this->error = '该分类为平台分类,不可以修改'; |
| | | return false; |
| | | } |
| | | // 验证:一级分类如果存在子类,则不允许移动 |
| | | if ($data['parent_id'] > 0 && static::hasSubCategory($this['category_id'])) { |
| | | $this->error = '该分类下存在子分类,不可以移动'; |
| | |
| | | */ |
| | | public function remove($categoryId) |
| | | { |
| | | if ($this['shop_supplier_id']==0){ |
| | | $this->error = '该分类为平台分类,不允许删除'; |
| | | return false; |
| | | } |
| | | // 判断是否存在商品 |
| | | if ($productCount = (new Product)->getProductTotal(['category_id' => $categoryId])) { |
| | | $this->error = '该分类下存在' . $productCount . '个商品,不允许删除'; |
| | |
| | | private function deleteCache($shop_supplier_id) |
| | | { |
| | | Cache::delete('category_supplier_'.$shop_supplier_id); |
| | | Cache::delete('category_all_' . static::$app_id); |
| | | return Cache::delete('category_' . static::$app_id); |
| | | } |
| | | |
| | |
| | | */ |
| | | class Supplier extends SupplierModel |
| | | { |
| | | |
| | | protected $append=['coordinate']; |
| | | public function getCoordinateAttr($v,$data) |
| | | { |
| | | return $data['latitude'].','.$data['longitude']; |
| | | } |
| | | /** |
| | | *检查登录 |
| | | */ |
| | |
| | | */ |
| | | public function edit($data){ |
| | | $isexist = $this->where('name','=',$data['name'])->where('shop_supplier_id','<>',$data['shop_supplier_id'])->find(); |
| | | $latitude=0; |
| | | $longitude=0; |
| | | if (!empty($data['coordinate'])){ |
| | | $coordinate=explode(',',$data['coordinate']); |
| | | $latitude=$coordinate[0]; |
| | | $longitude=$coordinate[1]; |
| | | } |
| | | if($isexist){ |
| | | $this->error = '店铺名称已存在'; |
| | | return false; |
| | |
| | | 'description' => $data['description'], |
| | | 'logo_id' => $data['logo_id'], |
| | | 'business_id' => $data['business_id'], |
| | | 'latitude' =>$latitude, |
| | | 'longitude' => $longitude, |
| | | 'app_id' => self::$app_id, |
| | | 'name' => $data['name'], |
| | | 'is_full' => 1, |
| | |
| | | // category: [], |
| | | loading: false, |
| | | open_user: false, |
| | | |
| | | }; |
| | | }, |
| | | props: ['form', 'areaList', 'branchList', 'user_info'], |
| | | |
| | | |
| | | methods: { |
| | | /*添加用户*/ |
| | | onSubmit() { |
| | |
| | | |
| | | /*初始化城市id*/ |
| | | initCity() { |
| | | this.form.city_id = '' |
| | | this.form.branch.city_id = ''; |
| | | }, |
| | | /*初始化区id*/ |
| | | initRegion() { |
| | | this.form.region_id = '' |
| | | this.form.branch.region_id = '' |
| | | }, |
| | | |
| | | /*打开弹出层*/ |
| | |
| | | <div class="common-seach-wrap"> |
| | | <el-form size="small" :inline="true" :model="formInline" class="demo-form-inline"> |
| | | <el-form-item label="结算时间"> |
| | | <el-date-picker |
| | | <el-date-picker |
| | | size="small" |
| | | style="margin-right: 15px;" |
| | | v-model="year" |
| | |
| | | value-format="yyyy" |
| | | placeholder="选择年"> |
| | | </el-date-picker> |
| | | <el-date-picker |
| | | <el-date-picker |
| | | size="small" |
| | | style="margin-right: 15px;" |
| | | v-model="month" |
| | |
| | | this.getData(); |
| | | } |
| | | }, |
| | | chooseYear(e) { |
| | | chooseYear(e) { |
| | | this.choose = e; |
| | | if(e != null && !(this.week != '' && this.week != null && this.month == null)) { |
| | | this.getData(); |
| | |
| | | <el-radio v-model="form.is_open" label="0">关闭</el-radio> |
| | | </div> |
| | | </el-form-item> |
| | | <el-form-item label="是否开启级差奖"> |
| | | <div> |
| | | <el-radio v-model="form.jcaward" label="1">开启</el-radio> |
| | | <el-radio v-model="form.jcaward" label="0">关闭</el-radio> |
| | | </div> |
| | | </el-form-item> |
| | | <el-form-item label="是否开启平级奖"> |
| | | <div> |
| | | <el-radio v-model="form.pjaward" label="1">开启</el-radio> |
| | | <el-radio v-model="form.pjaward" label="0">关闭</el-radio> |
| | | </div> |
| | | </el-form-item> |
| | | <el-form-item label="平级奖励层级" v-if="form.pjaward==1"> |
| | | <div> |
| | | <el-input v-model="form.pjaward_level" type="number" class="max-w460"></el-input> |
| | | <div class="tips">默认1级,即只往上找一个平级</div> |
| | | </div> |
| | | </el-form-item> |
| | | <el-form-item label="成为VIP需要购买的商品"> |
| | | <div> |
| | | <el-row> |
| | |
| | | is_open: '0', |
| | | become__buy_product_ids: [], |
| | | referee_buy_count: '0', |
| | | product_image: [] |
| | | product_image: [], |
| | | jcaward: '0', |
| | | pjaward: '0', |
| | | pjaward_level: '1' |
| | | }, |
| | | /*是否打开产品弹出层*/ |
| | | isproduct: false, |
| | |
| | | <el-form-item label="坐标"> |
| | | <el-row class="mb16"> |
| | | <el-col :span="24"> |
| | | <el-input v-model="form.supplier.coordinate" class="max-w460"></el-input> |
| | | <el-input v-model="formData.coordinate" class="max-w460"></el-input> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row class="mb16"> |
| | | <el-col :span="24"> |
| | | <Getpoint :form="form.supplier" @getMapdata="getMapdataFunc" @chose="choseFunc"></Getpoint> |
| | | <Getpoint :form="formData.supplier" @getMapdata="getMapdataFunc" @chose="choseFunc"></Getpoint> |
| | | </el-col> |
| | | </el-row> |
| | | </el-form-item> |
| | |
| | | description:'', |
| | | logo_id:0, |
| | | //business_id:0, |
| | | notice: '' |
| | | notice: '', |
| | | coordinate:'' |
| | | }, |
| | | /*是否打开图片选择*/ |
| | | isupload:false, |
| | |
| | | methods:{ |
| | | /*初始化城市id*/ |
| | | initCity() { |
| | | this.form.supplier.city_id = '' |
| | | this.formData.city_id = '' |
| | | }, |
| | | |
| | | /*初始化区id*/ |
| | | initRegion() { |
| | | this.form.supplier.region_id = '' |
| | | this.formData.region_id = '' |
| | | }, |
| | | |
| | | /*获取经纬度*/ |
| | | getMapdataFunc(e) { |
| | | this.form.supplier.coordinate = e.data[0].toFixed(6) + ',' + e.data[1].toFixed(6); |
| | | this.formData.coordinate = e.data[0].toFixed(6) + ',' + e.data[1].toFixed(6); |
| | | }, |
| | | /*选择的地址*/ |
| | | choseFunc(e){ |
| | | this.form.supplier.coordinate=e.location.lat+','+e.location.lng; |
| | | this.form.supplier.address=e.address; |
| | | this.formData.coordinate=e.location.lat+','+e.location.lng; |
| | | this.formData.address=e.address; |
| | | |
| | | }, |
| | | |