Server : nginx/1.20.1 System : Linux iZ2ze9ojcl78uluczwag69Z 4.18.0-240.22.1.el8_3.x86_64 #1 SMP Thu Apr 8 19:01:30 UTC 2021 x86_64 User : www ( 1000) PHP Version : 7.3.28 Disable Function : passthru,exec,system,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv Directory : /www/wwwroot/0531yanglao.com/app/common/model/ |
<?php namespace app\common\model; use think\facade\Db; use think\Model; /** * 推荐位 * @author aaron * */ class Recommend extends BaseModel { protected $pk = 'rid'; public function NursingHome() { return $this->belongsTo(NursingHome::class,'table_id'); } public function sojourn() { return $this->belongsTo(Sojourn::class,'table_id'); } /** * 添加推荐位数据 * @param unknown $table_id 外键 * @param unknown $table_type 类型 * @param unknown $recommend_ids 推荐位 */ public static function createRecommend($table_id, $table_type, $recommend_ids) { Db::startTrans(); //根据外键清空原有值 self::del([ 'table_id' => $table_id, 'table_type' => $table_type, ]); //添加新值 if($recommend_ids) { foreach ($recommend_ids as $recommend_id) { $d = [ 'table_id' => $table_id, 'table_type' => $table_type, 'r_id' => $recommend_id, ]; self::add($d, true); } } Db::commit(); } /** * 更新推荐位排序 * @param unknown $data 数据 * @param unknown $table_id 外键 * @param unknown $sort 排序 * @return boolean */ public static function updateRecommendSort($recommend_id, $sortArr) { Db::startTrans(); //更新值 foreach ($sortArr as $rid=>$sort) { $d = [ 'recommend_id' => $recommend_id, 'sort' => $sort, ]; self::where('rid', $rid)->update($d); } Db::commit(); return true; } /** * 删除推荐位 * @param unknown $table_id */ public static function remove($table_id, $table_type) { return self::destroy(['table_id'=>$table_id, 'table_type'=>$table_type]); } public static function getRecommendCount($table_id, $table_type) { return self::where('table_id',$table_id)->where('table_type',$table_type)->count(); } public static function getRecommendId($table_id) { return self::where('table_id',$table_id)->column('recommend_id'); } /** * 获取推荐位数据 * @param unknown $table_type 类型 * @param unknown $recommend_id * @param number $limit * @return unknown */ public static function getRecommendList($table_type, $recommend_id, $limit = 99, $order = ['sort'=>'asc']) { $return = []; $data = self::with([$table_type]) ->where('r_id',$recommend_id) ->where('table_type',$table_type) ->order($order) ->limit($limit) ->select(); if(!$data->isEmpty()) { foreach ($data as $item) { $sort = $item->sort; $item->$table_type->sort = $sort; $return[] = $item->$table_type; } } return $return; } /*public static function getRecommendList($relation_name, $recommend_id, $where = [], $limit = 99) { $return = []; $data = self::with([$relation_name]) ->where('recommend_id',$recommend_id) ->where('table_type',$relation_name) ->where($where) ->order('sort','desc') ->limit($limit) ->select(); if($data) { foreach ($data as $item) { $return[] = $item->$relation_name; } } return $return; }*/ }