20], [['SUPPLIER_NAME', 'SUPPLIER_CODE', 'COMPANY_NAME', 'ACCOUNT_BANK', 'ACCOUNT_NAME'], 'string', 'max' => 100], [['SALES_MAN'], 'string', 'max' => 30], [['start_date', 'end_date'], 'safe'], ]; } /** * @Author wanglg * @Desc 获取供应商渠道预付款总数据 * @param $params * @return ActiveDataProvider */ public function search($params) { $supplier_models = parent::getSupplierList(); $supplier_ids = ArrayHelper::getColumn($supplier_models, 'org_id'); $supplier_models = BaseSupplier::findAll(['ID'=>$supplier_ids]); $yufu_supplier = []; foreach ($supplier_models as $k=>$v){ //只显示预付的供应商 if ($v->SETT_TYPE==288){ $yufu_supplier[] = $v->ID; } } $now_time = isset($params['run_date']) ? $params['run_date'] . ' 00:00:00' : date('Y-m-01 00:00:00'); $end_time = isset($params['end_date']) ? $params['end_date'] . ' 23:59:59' : date('Y-m-t 23:59:59'); $query = OperaBalanceHis::find()->select(['a.*', 'sum(if(b.pay_type=1,-b.change_value,b.change_value)) as sum_change_value', 'abs(sum(if(b.pay_type=1,-b.change_value,b.change_value))) as sum_change_value_abs']); $query->from('opera_balance_his a'); $query->leftJoin('opera_balance_his b', "a.id=b.id and b.pay_time between '{$now_time}' and '{$end_time}'"); $query->leftJoin('order_main c', 'c.ORDER_ID=a.order_id AND c.CANCEL_FLAG=0'); $query->andFilterWhere(['between', 'a.pay_time', $now_time, $end_time]); $query->orderBy('sum_change_value_abs desc'); $query->groupBy('a.supplier_id'); $query->all(); // 根据用户角色设置查询条件 $where = $this -> userRoleWhere('c'); // $product = $this->productTypeWhere('c'); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $query->andFilterWhere(array_merge([ 'a.supplier_id' => $yufu_supplier, ], $where)); // $query->andFilterWhere($product); if (isset($params['supplier_id']) && $params['supplier_id'] != '') $query->andFilterWhere([ 'a.supplier_id' => $params['supplier_id'] ]); $sql = $query->createCommand()->getRawSql(); return $dataProvider; } /** * @Author wanglg * @Desc 获取渠道商总数据 * @param $params * @return ActiveDataProvider */ public function searchChannel($params) { $supplier_models = parent::getChannelList(); $supplier_ids = ArrayHelper::getColumn($supplier_models, 'org_id'); $supplier_models = BaseSupplier::findAll(['ID'=>$supplier_ids]); $yufu_supplier = []; foreach ($supplier_models as $k=>$v){ //只显示预付的供应商 if ($v->SETT_TYPE==288){ $yufu_supplier[] = $v->ID; } } $now_time = isset($params['run_date']) ? $params['run_date']. ' 00:00:00' : date('Y-m-01 00:00:00'); $end_time = isset($params['end_date']) ? $params['end_date']. ' 23:59:59' : date('Y-m-t 23:59:59'); $query = ChannelBalanceHis::find()->select(['a.*', 'sum(if(b.pay_type=1,-b.change_value,b.change_value)) as sum_change_value', 'abs(sum(if(b.pay_type=1,-b.change_value,b.change_value))) as sum_change_value_abs']); $query->from('channel_balance_his a'); $query->leftJoin('channel_balance_his b', "a.id=b.id and b.pay_time between '{$now_time}' and '{$end_time}'"); $query->leftJoin('order_main c', 'a.order_id=c.ORDER_ID AND c.CANCEL_FLAG=0'); $query->andFilterWhere(['between', 'a.pay_time', $now_time, $end_time]); $query->orderBy('sum_change_value_abs desc'); $query->groupBy('a.supplier_id'); $query->all(); $where = $this -> userRoleWhere('c'); // $product = $this -> productTypeWhere('c'); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(array_merge([ 'a.supplier_id' => $yufu_supplier, ], $where)); // $query->andFilterWhere($product); if (isset($params['supplier_id']) && $params['supplier_id'] != '') $query->andFilterWhere([ 'a.supplier_id' => $params['supplier_id'] ]); return $dataProvider; } /** * 获取供应商列表 * @Desc * @return array */ public static function getSupplierListStatic() { $model = new BaseSupplier(); $suppler_list = $model->getSupplierList(); return ArrayHelper::map($suppler_list, 'org_id', 'org_name'); } public static function getChannelListStatic() { $model = new BaseSupplier(); $suppler_list = $model-> getChannelList(); return ArrayHelper::map($suppler_list, 'org_id', 'org_name'); } /** * Function Description:计算本月余额变动 * Function Name: * * * @author LUOCJ */ public static function getMonthBalanceChange($id) { //月初和月尾日期 $start_date = date('Y-m-01'); $end_date = date('Y-m-t'); $models = OperaBalanceHis::find()->where(['and', ['=', 'supplier_id', $id], ['between', 'pay_time', $start_date, $end_date], ['pay_status' => 2]])->all(); $change = 0.00; foreach ($models as $model) { if ($model['pay_type'] == 1) $change -= $model['change_value']; else $change += $model['change_value']; } return $change; } /** * @Author wanglg * @Desc 报表统计查询权限条件 * @param $alias查询条件关联别名设置 */ public function userRoleWhere($alias=''){ $alias = empty($alias) ? '' : $alias.'.'; if(Yii::$app->user->identity['USER_ROLE'] == BaseUserAuth::HOTEL_OPERATOR){ // 酒店运营人员 $where = [$alias.'PRINCIPAL_ID' => Yii::$app->user->id]; }elseif(Yii::$app->user->identity['USER_ROLE'] == BaseUserAuth::HOTEL_PURCHASE){ // 酒店采购人员 $where = [$alias.'SALES_MAN' => Yii::$app->user->id]; }elseif(Yii::$app->user->identity['USER_ROLE'] == BaseUserAuth::HOTEL_ADMIN || Yii::$app->user->identity['USER_ROLE'] == BaseUserAuth::HOTEL_CUS_ADMIN || Yii::$app->user->identity['USER_ROLE'] == BaseUserAuth::SYS_CS || Yii::$app->user->identity['USER_ROLE'] == BaseUserAuth::FINANCIAL_OFFICER || Yii::$app->user->identity['USER_ROLE'] == BaseUserAuth::SYS_ADMIN || Yii::$app->user->identity['USER_ROLE'] == BaseUserAuth::MAIN_CORP){ // 酒店管理员、客服管理人员、后台管理人员和系统管理员、财务人员、运营管理人员可以查看所有数据 $where = []; }else{ $where = [$alias.'ID' => -1]; } return $where; } /** * @Author wanglg * @Desc酒店和巴士where条件设置 * @param string $alias * @return array */ public function productTypeWhere($alias=''){ // 酒店管理员只能查看酒店, 巴士只能看巴士 $alias = empty($alias) ? '' : $alias.'.'; if(Yii::$app->user->identity['USER_ROLE'] == BaseUserAuth::BUS_OPERA_CUS || Yii::$app->user->identity['USER_ROLE'] == BaseUserAuth::BUS_OPERA_ADMIN){ $where = ['<>', $alias.'ORDER_PROD_TYPE', 25]; // ?待确认 }elseif(Yii::$app->user->identity['USER_ROLE'] == BaseUserAuth::HOTEL_OPERATOR || Yii::$app->user->identity['USER_ROLE'] == BaseUserAuth::HOTEL_PURCHASE || Yii::$app->user->identity['USER_ROLE'] == BaseUserAuth::HOTEL_CUSTOMER || Yii::$app->user->identity['USER_ROLE'] == BaseUserAuth::HOTEL_CUS_ADMIN || Yii::$app->user->identity['USER_ROLE'] == BaseUserAuth::HOTEL_ADMIN){ $where = [$alias.'ORDER_PROD_TYPE' => 25]; }else{ $where = []; } return $where; } }