where('year_month', date("Ym", strtotime("-1 month")))->value('bonus_money'); return helper::bcsub($data,0,2); } /** * 获取达量奖励总额 * @param int $shopId 门店ID * @param int $type 类型 默认0 0-店老板-达量奖励 1-店内业绩合计-达量奖励 * @return string */ public static function bonusAmount($shopId, $type = 0) { if ($type == 2){ $filter[] = ['role', '>=', User::SHOP_BOSS]; } elseif ($type == 1) { $filter[] = ['role', '>', User::SHOP_BOSS]; } else { $filter[] = ['role', '=', User::SHOP_BOSS]; } /* if (empty($userIds)) { return '0.00'; }*/ $data = self::where('clearing_status', 1)->where($filter) ->where('shop_id',$shopId)->sum('bonus_money'); return helper::bcsub($data,0,2); } public static function bonusList($userId){ return self::field('year,month,bonus_money,create_time') ->where('user_id',$userId) ->where('clearing_status',1)->order('id','desc') ->paginate(15); } /** * 门店个人奖励金明细 * @param $param * @return mixed * @author: zjwhust * @Time: 2022/5/13 9:13 */ public function shopBonusDetail($param){ // 检索查询条件 $filter = $this->getQueryFilter($param); // 获取数据列表 $query = $this->alias('bonus') ->field(" bonus.sales_volume, concat(bonus.year,'-',bonus.month) as date, bonus.bonus_ladder, bonus.bonus_money, bonus.bonus_rate, bonus.role, bonus.user_id, shops.shop_id, shops.shop_name, shops.city_id, areas.name, user.nick_name, user.mobile ") ->leftJoin('shops', 'shops.shop_id = bonus.shop_id') ->leftJoin('user', 'user.user_id = bonus.user_id') ->leftJoin('areas','shops.city_id=areas.id') ->where('shops.is_delete',0) ->where($filter) // ->order(['bonus.create_time' => 'desc']) // ->group('bonus.user_id,bonus.shop_id,bonus.role') ->paginate()->each(function($v) { $v['bonus_money'] = helper::bcsub($v['bonus_money'],0,2); }); return $query; } /** * 门店个人奖励金列表 * @param $param * @return mixed * @author: zjwhust * @Time: 2022/5/12 15:21 */ public function shopBonusList($param){ // 检索查询条件 $filter = $this->getQueryFilter($param); // 获取数据列表 $query = $this->alias('bonus') ->field(' sum(bonus.sales_volume) as sales_volume_total, sum(bonus.order_count) as order_count_total, sum(bonus.bonus_money) as bonus_money_total, bonus.role, bonus.user_id, shops.shop_id, shops.shop_name, shops.city_id, areas.name, user.nick_name, user.mobile ') ->leftJoin('shops', 'shops.shop_id = bonus.shop_id') ->leftJoin('user', 'user.user_id = bonus.user_id') ->leftJoin('areas','shops.city_id=areas.id') ->where('shops.is_delete',0) ->where($filter) // ->order(['bonus.create_time' => 'desc']) ->group('bonus.user_id,bonus.shop_id,bonus.role') ->paginate(); return $query; } /** * 设置检索查询条件 * @param array $param * @return array */ private function getQueryFilter(array $param): array { // 默认参数 $params = $this->setQueryDefaultValue($param, [ ]); // 检索查询条件 $filter = []; // 结算月份起止时间 if (isset($param['betweenTime'])&&!empty($params['betweenTime'])){ $times = between_time($param['betweenTime']); }else{ $times['end_time'] = strtotime(date('Y-m-01 00:00:00')) - 1 ;//上月的最后一秒 $times['start_time'] =strtotime(date('Y-m-01 00:00:00',strtotime('-1 month'))); } $from = date('Ym',$times['start_time']); $to = date('Ym',$times['end_time']); $filter[] = ['bonus.year_month', '>=', $from]; $filter[] = ['bonus.year_month', '<=', $to ]; //角色ID if(isset($params['roleId'])&&$params['roleId']>0){ $filter[] = ['bonus.role','=',$params['roleId']]; } //会员昵称 if (isset($params['nickName'])&&!empty($params['nickName'])) { $filter[] = ['user.nick_name', 'like', "%{$params['nickName']}%"]; } //手机号码 !empty($params['mobile']) && $filter[] = ['user.mobile', 'like', "%{$params['mobile']}%"]; //用户ID if(isset($params['userId'])&&$params['userId']>0){ $filter[] = ['bonus.user_id','=',$params['userId']]; } //门店名称 if(isset($params['shopName'])&&!empty($params['shopName'])){ $filter[] = ['shops.shop_name','like', "%{$params['shopName']}%"]; } //门店ID if(isset($params['shopId'])&&$params['shopId']>0){ $filter[] = ['shops.shop_id','=',$params['shopId']]; } //门店城市 if(isset($params['cityId'])&&$params['cityId']>0){ $filter[] = ['shops.city_id','=',$params['cityId']]; } //门店城市名称 if(isset($params['cityName'])&&!empty($params['cityName'])){ $cityIds = ChefAreas::where('name','like','%'.$params['cityName'].'%')->where('level',2)->column('id'); $filter[] = ['shops.city_id','in',$cityIds]; } return $filter; } public function commerDetails($params){ if (!empty($params['betweenTime'])){ $times = between_time($params['betweenTime']); $times['start_time'] = intval(date('Ym',$times['start_time'])); $times['end_time'] = intval(date('Ym',$times['end_time'])); } if (isset($times['start_time'])){ $where[] = ['bonus_history.year_month', '>=', $times['start_time']]; $where[] = ['bonus_history.year_month', '<=', $times['end_time'] ]; } $where[] = ['bonus_history.is_delete','=',0]; $where[] = ['bonus_history.role','=',User::COMMISSION_USER]; if (!empty($params['userId']) && $params['userId'] >0 )$where[] = ['bonus_history.user_id','=', $params['userId']]; if (!empty($params['nickName']))$where[] = ['user.nick_name', 'like','%'.$params['nickName'].'%']; if (!empty($params['mobile']))$where[] = ['user.mobile', 'like','%'.trim($params['mobile']).'%']; if (!empty($params['sellerGrade']) && $params['sellerGrade'] >0)$where[] = ['user.seller_grade','=', $params['sellerGrade']]; return self::alias('bonus_history') ->leftJoin('user user','bonus_history.user_id=user.user_id') ->where($where) ->field('`user`.nick_name,`user`.mobile,`user`.seller_grade,bonus_history.user_id,'. '`bonus_history`.`year`,`bonus_history`.`month`,CONVERT(`bonus_history`.`year_month`,CHAR) as `year_month`,'.//CONVERT(`bonus_history`.`year_month`,CHAR) as `year_month`, 'bonus_history.sales_volume,bonus_history.bonus_rate,bonus_history.bonus_money,bonus_history.bonus_ladder') ->paginate(15); } }