<?php
|
|
namespace app\agent\model;
|
|
use app\common\model\agent\Store as StoreModel;
|
|
/**
|
* 超管后台门店模型
|
*/
|
class Store extends StoreModel
|
{
|
/**
|
* 获取全部
|
*/
|
public static function getAll()
|
{
|
$model = new static;
|
$agent_id=self::$agent_id;
|
|
$data = $model->with('agent')->where('agent_id', '=', $agent_id)->where('is_delete', '=', 0)->select();
|
$data->each(function($item,$key){
|
$item['expire_status'] = is_expire_status($item['end_date']);
|
$item['status_name'] = status($item['status']);
|
$item['date_value'] = [$item['register_date'],$item['end_date']];
|
|
$item['month_register'] = 0;
|
});
|
return $data;
|
}
|
/**
|
* 搜索指定数据--搜索
|
*/
|
public static function search($data)
|
{
|
$agent_id=self::$agent_id;
|
$model = new static;
|
|
$list = $model->where('is_delete', '=', 0)->where('agent_id', '=', $agent_id)
|
->where('store_name', 'like', '%'.$data[0].'%')
|
->where('store_type', 'like', '%'.$data[1].'%')
|
->where('status', 'like', '%'.$data[2].'%')
|
->where('store_app_name', 'like', '%'.$data[4].'%')
|
->select();
|
|
$list->each(function($item,$key){
|
$item['expire_status'] = is_expire_status($item['end_date']);
|
$item['status_name'] = status($item['status']);
|
$item['date_value'] = [$item['register_date'],$item['end_date']];
|
|
$item['month_register'] = '预留';
|
});
|
return $list;
|
}
|
/**
|
* 获取头部数据
|
*/
|
public static function gethead()
|
{
|
$agent_id=self::$agent_id;
|
$model = new static;
|
$newtime = strtotime(Date('Y-m-d'));//当日零点时间戳
|
$yetime = $newtime - 86400;//strtotime(date('Y-m-d',strtotime('-1 day')))
|
|
$list = $model->where('is_delete','=',0)->where('agent_id', '=', $agent_id)->select();//总数
|
$list2 = $model->where('is_delete','=',0)->where('agent_id', '=', $agent_id)->where('status','=',1)->select();//通过总数
|
$list3 = $model->where('is_delete','=',0)->where('agent_id', '=', $agent_id)
|
->where('create_time','<=',$newtime)
|
->where('create_time','>=',$yetime)
|
->select();//昨日新增总数
|
$list4 = $model->where('is_delete','=',0)->where('agent_id', '=', $agent_id)->where('end_date','<',date('Y-m-d H:i:s'))->select();//通过总数
|
|
$data = [];
|
$data[] = count($list);//总数
|
$data[] = count($list2);//正常使用总数
|
//$data[] = $date;
|
$data[] = count($list3);//昨日新增总数
|
$data[] = count($list4);//已过期总数
|
|
return $data;
|
}
|
|
|
/**
|
* 获取当前门店总数
|
*/
|
public function getStoreTotal($agent_id,$day = null)
|
{
|
$model = $this;
|
if (!is_null($day)) {
|
$startTime = strtotime($day);
|
$model = $model->where('create_time', '>=', $startTime)
|
->where('create_time', '<', $startTime + 86400);
|
}
|
return $model->where('agent_id', '=', $agent_id)->where('is_delete', '=', '0')->count();
|
}
|
|
/**
|
* 新增
|
*/
|
public function add($data)
|
{
|
$data['agent_id']=self::$agent_id;
|
return $this->save($data);
|
}
|
|
|
/**
|
* 软删除
|
*/
|
public function setDelete()
|
{
|
return $this->save(['is_delete' => 1]);
|
}
|
|
/**
|
* 更新记录
|
*/
|
public function edit($data)
|
{
|
return $this->save($data);
|
}
|
|
}
|