예제 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = MOfficeCampaignScorer::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'department', $this->department])->andFilterWhere(['like', 'position', $this->position])->andFilterWhere(['like', 'mobile', $this->mobile]);
     return $dataProvider;
 }
예제 #2
0
 public function actionOfficeCampaignScorer()
 {
     $scorers = \app\models\MOfficeCampaignScorer::find()->all();
     foreach ($scorers as $scorer) {
         $openidbindmobile = \app\models\OpenidBindMobile::findOne(['mobile' => $scorer->mobile]);
         if (empty($openidbindmobile)) {
             echo "{$scorer->name}({$scorer->mobile})手机未绑定。" . PHP_EOL;
         }
         $staffs = \app\models\MStaff::find()->where(['gh_id' => \app\models\MGh::GH_XIANGYANGUNICOM, 'mobile' => $scorer->mobile])->all();
         if (empty($staffs)) {
             echo "{$scorer->name}({$scorer->mobile})不在Staff表中。" . PHP_EOL;
             $staff = new \app\models\MStaff();
         } else {
             if (count($staffs) > 1) {
                 echo "{$scorer->name}({$scorer->mobile})在Staff表中存在多项。" . PHP_EOL;
                 $n = count($staffs);
                 $selected = -1;
                 for ($i = 0; $i < $n; $i++) {
                     $staff = $staffs[$i];
                     if (empty($staff->openid) || $selected != -1) {
                         $staff->delete();
                     } else {
                         if (!empty($staff->openid)) {
                             $selected = $i;
                         }
                     }
                 }
                 if ($selected == -1) {
                     $staff = new \app\models\MStaff();
                 } else {
                     $staff = $staffs[$selected];
                 }
             } else {
                 $staff = $staffs[0];
             }
         }
         $staff->gh_id = \app\models\MGh::GH_XIANGYANGUNICOM;
         $staff->name = $scorer->name;
         $staff->mobile = $scorer->mobile;
         $staff->cat = \app\models\MStaff::SCENE_CAT_IN;
         $staff->save(false);
     }
 }