| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 | <?php/** * Created by PhpStorm. * User: Administrator * Date: 2018/11/22 * Time: 15:25 */namespace App\Repositories;use App\Models\Msg;use App\Models\MemberMsgtip;use Prettus\Repository\Eloquent\BaseRepository;/** * Class MsgRepositoryEloquent. * * @package namespace App\Repositories; */class MsgRepository extends BaseRepository{    /**     * Specify Model class name     *     * @return string     */    public function model()    {        return Msg::class;    }    public function addData($data)    {        return Msg::insertGetId($data);    }    public function update(array $data, $id)    {        return $this->model->where('id', $id)->update($data);    }    public function getMemberMsgtipInfo($where)    {        return MemberMsgtip::where($where)->first();    }    public function updateMemberMsgtipInfo($where, $data)    {        return MemberMsgtip::where($where)->update($data);    }    public function addMemberMsgtipInfo($data)    {        return MemberMsgtip::insert($data);    }    public function msg($utype, $uid)    {        if ($utype==1) {            $res = $this->model->orWhere(function ($query) use ($utype, $uid) {                $query->where(['from_uid'=>$uid, 'utype'=>$utype]);            })->orWhere(function ($query) use ($utype, $uid) {                $query->where(['to_uid' => $uid, 'utype' => 2]);            })->select(                [                    'parent_id',                    \DB::raw('group_concat(utype,":",from_uid,":",to_uid,":",message) as result'),                    'created_at'                ]            )->orderBy('id', 'desc')            ->groupBy('parent_id')->paginate(10);        } else {            $res = $this->model->orWhere(function ($query) use ($utype, $uid) {                $query->where(['from_uid'=>$uid, 'utype'=>$utype]);            })->orWhere(function ($query) use ($utype, $uid) {                $query->where(['to_uid' => $uid, 'utype' => 1]);            })->select(                [                    'parent_id',                    \DB::raw('group_concat(utype,":",from_uid,":",to_uid,":",message) as result'),                   'created_at'                ]            )->orderBy('id', 'desc')            ->groupBy('parent_id')->paginate(10);        }        return $res;    }    public function mobileMsg($utype, $uid)    {        $res = $this->model->Where(function ($query) use ($utype, $uid) {            if ($utype == 1) {                $query->Where(['to_uid'=>$uid,'utype'=>2]);            } else {                $query->Where(['from_uid'=>$uid,'utype'=>$utype]);            }        })->with('company')->whereHas('company')->orderBy('id', 'desc')            ->groupBy('parent_id')->paginate(10);        return $res;    }    public function mobileMsgShow($parent_id)    {         return $this->model->where('parent_id', $parent_id)->orderBy('id', 'desc')->paginate(10);    }    /**企业用     * @param $parent_id     * @return mixed     */    public function mobileMsgShows($parent_id)    {        return $this->model->where('parent_id', $parent_id)->orderBy('id', 'desc')->paginate(10);    }    public function findCompanyByPar($utype, $uid, $parent_id)    {        if ($utype == 1) {            return $this->model->where('parent_id', $parent_id)->where(['from_uid'=>$uid, 'utype'=>$utype])->with(['memberInfoMsg','resumes'])                ->whereHas('memberInfoMsg')->first();        } else {            return $this->model->where('parent_id', $parent_id)->where(['from_uid'=>$uid, 'utype'=>$utype])->with('company')                ->whereHas('company')->first();        }    }    public function msgSend($data)    {        return $this->model->create($data);    }    public function msgDelete($parent_id)    {        return $this->model->where('parent_id', $parent_id)->delete();    }}
 |