123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- namespace app\admin\model;
- use support\Db;
- use support\Model;
- /**
- * 管家模型
- * Class Housekeeper
- * @package app\admin\model
- */
- class Housekeeper extends Model
- {
- const UPDATED_AT = 'housekeeper_update_time';//模型自动更新时间字段
- const DEL_NO = 0;
- const DEL_YES = 1;
- const DEL_STATUS = [
- self::DEL_NO => '未删除',
- self::DEL_YES => '已删除'
- ];
- /**
- *
- * The table associated with the model.
- *
- * @var string
- */
- protected $table = 'housekeeper';
- protected $dateFormat = 'U';//操作数据库时间格式 时间戳
- /**
- * Notes:获取管家列表
- * @param $keywords
- * @param $page
- * @param $limit
- * @return array
- * User: yym
- * Date: 2022/10/28
- */
- public static function getHousekeeperList($keywords, $page, $limit)
- {
- $list = static::where(['housekeeper_del' => static::DEL_NO])
- ->when($keywords != '', function ($query) use ($keywords){
- $query->where('housekeeper_name', 'like', '%' . $keywords . '%')
- ->orWhere('housekeeper_real_name', 'like', '%' . $keywords . '%')
- ->orWhere('housekeeper_phone', 'like', '%' . $keywords . '%');
- })
- ->forPage($page, $limit)
- ->get()
- ->toArray();
- $count = static::where(['housekeeper_del' => static::DEL_NO])
- ->when($keywords != '', function ($query) use ($keywords){
- $query->where('housekeeper_name', 'like', '%' . $keywords . '%')
- ->orWhere('housekeeper_real_name', 'like', '%' . $keywords . '%')
- ->orWhere('housekeeper_phone', 'like', '%' . $keywords . '%');
- })
- ->count();
- return [$list, $count];
- }
- /**
- * Notes:检测账号是否存在
- * @param $account
- * @return bool
- * User: yym
- * Date: 2022/10/28
- */
- public static function checkAccount($account)
- {
- return static::where(['housekeeper_name' => $account, 'housekeeper_del' => static::DEL_NO])->exists();
- }
- /**
- * Notes:检测账号是否存在
- * @param $account
- * @param $id
- * @return bool
- * User: yym
- * Date: 2022/10/28
- */
- public static function checkAccountNo($account, $id)
- {
- return static::where(['housekeeper_name' => $account, 'housekeeper_del' => static::DEL_NO])->where('housekeeper_id', '!=', $id)->exists();
- }
- /**
- * Notes:插入数据
- * @param array $data
- * @return false|int
- * User: yym
- * Date: 2022/10/28
- */
- public static function insertData(array $data)
- {
- if(empty($data))
- {
- return false;
- }
- return static::insertGetId($data);
- }
- /**
- * Notes:根据主键更新数据
- * @param array $data
- * @param int $id
- * @return false|int
- * User: yym
- * Date: 2022/10/28
- */
- public static function updateData(array $data, int $id)
- {
- if(empty($data) || empty($id))
- {
- return false;
- }
- return static::where(['housekeeper_id' => $id])->update($data);
- }
- /**
- * Notes:获取详情
- * @param int $id
- * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
- * User: yym
- * Date: 2022/10/28
- */
- public static function getInfo(int $id)
- {
- return static::where(['housekeeper_id' => $id, 'housekeeper_del' => static::DEL_NO])->first();
- }
- }
|