142 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
		
		
			
		
	
	
			142 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| 
								 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								namespace app\common\model\home;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								use app\common\model\BaseModel;
							 | 
						||
| 
								 | 
							
								use think\Model;
							 | 
						||
| 
								 | 
							
								use traits\model\SoftDelete;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class MediaMatrixCate extends BaseModel
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    use SoftDelete;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    // 表名
							 | 
						||
| 
								 | 
							
								    protected $name = 'home_media_matrix_cate';
							 | 
						||
| 
								 | 
							
								    
							 | 
						||
| 
								 | 
							
								    // 自动写入时间戳字段
							 | 
						||
| 
								 | 
							
								    protected $autoWriteTimestamp = 'integer';
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    // 定义时间戳字段名
							 | 
						||
| 
								 | 
							
								    protected $createTime = 'createtime';
							 | 
						||
| 
								 | 
							
								    protected $updateTime = 'updatetime';
							 | 
						||
| 
								 | 
							
								    protected $deleteTime = 'deletetime';
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    // 追加属性
							 | 
						||
| 
								 | 
							
								    protected $append = [
							 | 
						||
| 
								 | 
							
								        'status_text'
							 | 
						||
| 
								 | 
							
								    ];
							 | 
						||
| 
								 | 
							
								    
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    protected static function init()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        self::afterInsert(function ($row) {
							 | 
						||
| 
								 | 
							
								            if (!$row['weigh']) {
							 | 
						||
| 
								 | 
							
								                $pk = $row->getPk();
							 | 
						||
| 
								 | 
							
								                $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								        });
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    
							 | 
						||
| 
								 | 
							
								    public function getStatusList()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        return ['1' => __('Status 1'), '2' => __('Status 2')];
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function getStatusTextAttr($value, $data)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $value = $value ?: ($data['status'] ?? '');
							 | 
						||
| 
								 | 
							
								        $list = $this->getStatusList();
							 | 
						||
| 
								 | 
							
								        return $list[$value] ?? '';
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**得到基础条件
							 | 
						||
| 
								 | 
							
								     * @param $status
							 | 
						||
| 
								 | 
							
								     * @param null $model
							 | 
						||
| 
								 | 
							
								     * @param string $alisa
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public static function getBaseWhere($whereData = [], $model = null, $alisa = '',$with = false)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        if (!$model) {
							 | 
						||
| 
								 | 
							
								            $model = new static;
							 | 
						||
| 
								 | 
							
								            if ($alisa&&!$with) $model = $model->alias($alisa);
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        if ($alisa) $alisa = $alisa . '.';
							 | 
						||
| 
								 | 
							
								        $tableFields = (new static)->getTableFields();
							 | 
						||
| 
								 | 
							
								        foreach ($tableFields as $fields)
							 | 
						||
| 
								 | 
							
								        {
							 | 
						||
| 
								 | 
							
								            if(in_array($fields, []))continue;
							 | 
						||
| 
								 | 
							
								//            if (isset($whereData[$fields]) && $whereData[$fields]) $model = $model->where("{$alisa}{$fields}", '=', $whereData[$fields]);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            if (isset($whereData[$fields]) && $whereData[$fields]){
							 | 
						||
| 
								 | 
							
								                if(is_array($whereData[$fields])){
							 | 
						||
| 
								 | 
							
								                    $model = $model->where("{$alisa}{$fields}", $whereData[$fields][0], $whereData[$fields][1]);
							 | 
						||
| 
								 | 
							
								                }else{
							 | 
						||
| 
								 | 
							
								                    $model = $model->where("{$alisa}{$fields}", '=', $whereData[$fields]);
							 | 
						||
| 
								 | 
							
								                }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        if (isset($whereData['keywords'])&&$whereData['keywords']){
							 | 
						||
| 
								 | 
							
								            $model = $model->where("{$alisa}name", 'LIKE', "%{$whereData['keywords']}%" );
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        if (isset($whereData['time'])&&$whereData['time']){
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            $model = $model->time(["{$alisa}createtime",$whereData['time']]);
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//        if (isset($whereData['has_evaluate'])&&$whereData['has_evaluate']){
							 | 
						||
| 
								 | 
							
								//            //1查已评价 2查未评价
							 | 
						||
| 
								 | 
							
								//            if($whereData['has_evaluate'] == 1){
							 | 
						||
| 
								 | 
							
								//                //1查已评价
							 | 
						||
| 
								 | 
							
								//                $model = $model->where("{$alisa}classes_evaluate_id", '<>', 0);
							 | 
						||
| 
								 | 
							
								//            }else{
							 | 
						||
| 
								 | 
							
								//                //2查未评价
							 | 
						||
| 
								 | 
							
								//                $model = $model->whereExists(function ($query) use ($alisa) {
							 | 
						||
| 
								 | 
							
								//                    $order_table_name = (new \app\common\model\school\classes\hourorder\Order())->getQuery()->getTable();
							 | 
						||
| 
								 | 
							
								//                    $query->table($order_table_name)->where($order_table_name . '.classes_order_id=' . $alisa . 'id')->where('status', '=', '3');
							 | 
						||
| 
								 | 
							
								//                })->where("{$alisa}classes_evaluate_id", '=', 0);
							 | 
						||
| 
								 | 
							
								//
							 | 
						||
| 
								 | 
							
								//            }
							 | 
						||
| 
								 | 
							
								//        }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        return $model;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public static function allList($page, $limit,$params=[]){
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        $sort = "weigh desc,id desc";
							 | 
						||
| 
								 | 
							
								        if(!empty($params['status'])){
							 | 
						||
| 
								 | 
							
								            $params['status'] = '1';
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        return (new self)->getBaseList($params, $page, $limit,$sort);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								}
							 |