50], [['formulae'], 'string', 'max' => 100], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'ID', 'user_id' => 'User ID', 'pay_date' => 'Pay Date', 'attendance_days' => 'Attendance Days', 'try_attendance_days' => 'Try Attendance Days', 'assessment_pay' => 'Assessment Pay', 'goodjob_pay' => 'Goodjob Pay', 'pass_pay' => 'Pass Pay', 'incentive_pay' => 'Incentive Pay', 'bonus_pay' => 'Bonus Pay', 'extjob_pay' => 'Extjob Pay', 'commission' => 'Commission', 'group_pay' => 'Group Pay', 'try_extjob_pay' => 'Try Extjob Pay', 'grants_pay' => 'Grants Pay', 'give_social_pay' => 'Give Social Pay', 'late_pay' => 'Late Pay', 'leave_pay' => 'Leave Pay', 'sick_pay' => 'Sick Pay', 'social_pay' => 'Social Pay', 'fine_pay' => 'Fine Pay', 'electricity_pay' => 'Electricity Pay', 'deposit' => 'Deposit', 'public_pay' => 'Public Pay', 'calls' => 'Calls', 'bus' => 'Bus', 'bonus' => 'Bonus', 'turnover' => 'Turnover', 'full_attendance_pay' => 'Full Attendance Pay', 'pass_time_pay' => 'Pass Time Pay', 'formulae' => 'Formulae', 'absence_pay' => 'Absence Pay', 'absenteeism_pay' => 'Absenteeism Pay', 'driver_num' => 'Driver Num', 'driver_price' => 'Driver Price', 'fix_total' => 'Fix Total', 'fix_rate' => 'Fix Rate', 'real_pay' => 'Real Pay', 'tax' => 'Tax', 'get_full_attendance_pay' => 'Get Full Attendance Pay', 'get_pass_time_pay' => 'Get Pass Time Pay', 'try_pay' => 'Try Pay', 'formal_pay' => 'Formal Pay', 'should_pay' => 'Should Pay', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } public function getUser() { return $this->hasOne(UserT::className(),['id'=>'user_id']); } public function calPay() { $this->calCommission(); $user_info = $this->user; $group_info = $user_info->group; if($user_info->worktype){ $workday = WorkDayT::findOne(['date' => $this->pay_date]); if($user_info->is_double == 1){ $worktype = $workday ? $workday->double_break : '0'; }else{ $worktype = $workday ? $workday->single_break : '0'; } }else{ $this->should_pay = 0; $this->real_pay = 0; $this->save(); return; } if($worktype == 0){ $this->should_pay = 0; $this->real_pay = 0; $this->save(); return; } $ext_day_pay = 0; // if($group_info) { // $ext_day_pay = ($group_info->base_pay + $group_info->job_pay + $group_info->station_pay + $user_info->ext_pay)/$worktype; // } else { // $ext_day_pay = $user_info->ext_pay / $worktype; // } $ext_day_pay = $this->formal_pay / $worktype; // var_dump($workday); // var_dump($this->formal_pay); // var_dump($worktype); // var_dump($this->attendance_days); // die; // $try_day_pay = $user_info->try_pay / $worktype; $try_day_pay = $this->try_pay / $worktype; $should_pay = 0; $should_pay += $this->try_attendance_days * $try_day_pay; $should_pay += $this->attendance_days * $ext_day_pay; $should_pay += $this->try_extjob_pay; $should_pay += $this->extjob_pay; $should_pay += $this->give_social_pay; $should_pay += $this->commission; $should_pay += $this->calls; $should_pay += $this->bus; $should_pay += $this->bonus; $should_pay += $this->get_pass_time_pay; $should_pay += $this->get_full_attendance_pay; //echo $should_pay; // $should_pay += $this->turnover; // if($group_info){ // $should_pay += $group_info->base_pay + $group_info->job_pay + $group_info->station_pay; // } $this->should_pay = $should_pay; $real_pay = $should_pay - $this->late_pay; $real_pay -= $this->leave_pay; $real_pay -= $this->sick_pay; $real_pay -= $this->social_pay; $real_pay -= $this->fine_pay; $real_pay -= $this->electricity_pay; $real_pay -= $this->deposit; $real_pay -= $this->public_pay; $real_pay -= $this->tax; if($this->full_attendance_pay > 1){ $real_pay -= $this->full_attendance_pay; }else{ $real_pay -= ($this->commission * $this->full_attendance_pay); } if($this->pass_time_pay > 1){ $real_pay -= $this->pass_time_pay; }else{ $real_pay -= ($this->commission * $this->pass_time_pay); } $this->real_pay = $real_pay; $this->save(); } /** * 提成计算 * @param null $ft * @return int */ public function calCommission($ft = null) { $commission = 0; $formulae = $ft ? $ft : ($this->formulae ? $this->formulae : ''); if($formulae != '') { $grticheng = $this->calGrticheng(); if($grticheng == 0) $grticheng = 0; $grbaofei = $this->calGrbaofei(); if($grbaofei == 0) $grbaofei = 0; $gsbaofei = $this->calGsbaofei(); if($gsbaofei == 0) $gsbaofei = 0; $bmbaofei = $this->calBmbaofei(); if($bmbaofei == 0) $bmbaofei = 0; $yyg = $this->turnover; if($yyg == 0) $yyg = 0; $new_data = str_replace('grTicheng',$grticheng,$formulae); $new_data = str_replace('grBaoFei',$grbaofei,$new_data); $new_data = str_replace('gsBaoFei',$gsbaofei,$new_data); $new_data = str_replace('bmBaoFei',$bmbaofei,$new_data); $new_data = str_replace('yyg',$yyg,$new_data); // echo '$commission=round('.$new_data.',2);';exit; eval('$commission=round('.$new_data.',2);'); } $commission += $this->driver_num * $this->driver_price; $commission += $this->fix_total * $this->fix_rate / 100; $this->commission = $commission; $this->save(); return $commission; } /** * 计算个人提成 */ public function calGrticheng() { //个人提成 $grbaofei = 0; $pay_order_users = PayOrderUserT::find() ->where('pay_date="'.$this->pay_date.'" and user_id='.$this->user_id) ->all(); foreach($pay_order_users as $pay_order_user) { // $pay_order_user->calPay(); // var_dump($pay_order_user->real_pay); $grbaofei += $pay_order_user->real_pay; } // die; return round($grbaofei,2); } /** * 计算个人保费 */ public function calGrbaofei() { //个人保费 $grbaofei = 0; $query = OrderT::find() ->leftJoin('pay_order_user_t','pay_order_user_t.order_id=order_t.id') ->where('pay_order_user_t.pay_date="'.$this->pay_date.'"') ->groupBy('order_t.car_no'); $user = $this->user; $query = $query->andWhere(['in','order_t.user_id',$user->id]); // echo $query->createCommand()->rawSql; $grbaofei = $query->sum('total1_clear'); return round($grbaofei,2); } /** * 计算全公司当月保费 * @return int|mixed */ public function calGsbaofei() { $gsbaofei = 0; $query = OrderT::find() ->leftJoin('pay_order_user_t','pay_order_user_t.order_id=order_t.id') ->where('pay_order_user_t.pay_date="'.$this->pay_date.'"') ->groupBy('order_t.car_no'); // echo $query->createCommand()->rawSql; $gsbaofei = $query->sum('total1_clear'); return round($gsbaofei,2); } public function calBmbaofei() { $bmbaofei = 0; $query = OrderT::find() ->leftJoin('pay_order_user_t','pay_order_user_t.order_id=order_t.id') ->where('pay_order_user_t.pay_date="'.$this->pay_date.'"') ->groupBy('order_t.car_no'); $user = $this->user; $user_ids = $user->getChildrenUserIDs(); $query = $query->andWhere(['in','order_t.user_id',$user_ids]); $bmbaofei = $query->sum('total1_clear'); return round($bmbaofei,2); } }