Browse Source

Wesmiler 校企小程序 更新 6.15

wesmiler 3 năm trước cách đây
mục cha
commit
f2748015a6

+ 11 - 3
app/api/controller/SourceShool.php

@@ -58,11 +58,19 @@ class SourceShool extends Controller
      */
     public function options()
     {
-        $model = new SourceShoolModel();
-        $list = $model->getOptionList($this->request->param());
-        return $this->renderSuccess(compact('list'));
+            $model = new SourceShoolModel();
+            $list = $model->getOptionList($this->request->param());
+            return $this->renderSuccess(compact('list'));
+
+
     }
 
+    /**
+     * 生源学校学生列表
+     * @return \think\response\Json
+     * @throws \cores\exception\BaseException
+     * @throws \think\db\exception\DbException
+     */
     public function student()
     {
         $model = new UserModel;

+ 15 - 4
app/api/model/SourceShool.php

@@ -101,13 +101,24 @@ class SourceShool extends SourceShoolModel
         return $this->where(function ($query) use ($param){
                 $keyword = isset($param['keyword'])? trim($param['keyword']) : '';
                 if($keyword){
-                    $query->where('source_shools_name','like',"%{$keyword}%")
-                        ->whereOr('address','like',"%{$keyword}%");
+                    $query->where(function($query) use($keyword){
+                        $query->where('source_shools_name','like',"%{$keyword}%")
+                            ->whereOr('address','like',"%{$keyword}%");
+                    });
+                }
+
+                $userId = isset($param['user_id'])? intval($param['user_id']) : 0;
+                if($userId>0){
+                    $query->whereNotIn('source_shools_id', SourceShoolApply::getSchoolsByUser($userId));
                 }
             })
             ->field($field?:'source_shools_id as id,source_shools_name as school_name,students_num')
-            ->order('students_num desc,source_shools_id desc')
-            ->select();
+            ->order('students_num desc,id desc')
+            ->select()
+            ->each(function($item, $k) use ($param){
+                $userId = isset($param['user_id'])? intval($param['user_id']) : 0;
+                $item['is_apply'] = $userId? SourceShoolApply::checkApplyByUser($userId, $item['id']) : 0;
+            });
     }
 
     /**

+ 23 - 1
app/api/model/SourceShoolApply.php

@@ -11,7 +11,7 @@
 declare (strict_types=1);
 
 namespace app\api\model;
-use app\common\model\SourceShool as SourceShoolApplyModel;
+use app\common\model\SourceShoolApply as SourceShoolApplyModel;
 
 /**
  * 生源学校申请模型类
@@ -28,5 +28,27 @@ class SourceShoolApply extends SourceShoolApplyModel
      */
     protected $hidden = [];
 
+    /**
+     * 获取老师已申请通过的生源学校
+     * @param $userId
+     * @return array
+     */
+    public static function getSchoolsByUser($userId)
+    {
+        return self::where(['user_id'=> $userId,'status'=>1])
+            ->column('source_shools_id');
+    }
+
+    /**
+     * 获取老师已申请通过的生源学校
+     * @param $userId
+     * @return array
+     */
+    public static function checkApplyByUser($userId, $schoolId)
+    {
+        $status = self::where(['user_id'=> $userId,'source_shools_id'=>$schoolId])
+            ->value('status');
 
+        return $status == 1? 1 : ($status == 2? 2 : 0);
+    }
 }