将数据库中查出的列表以指定的 id 作为数组的键名
function convert_arr_key($arr, $key_name)
{
$result = array();
foreach($arr as $key => $val){
$result[$val[$key_name]] = $val;
}
return $result;
}
查询当前时间方面的时间处理
public function statisticalOrder($time,$owner_m_id,$creator_role_id) {
if($time == 'cur_day') {
$start_time = strtotime(date('Y-m-d 00:00:00',time()));
$end_time = ($start_time+86400);
}elseif($time == 'cur_week') {
$start_time = mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"));
$end_time = mktime(23,59,60,date("m"),date("d")-date("w")+7,date("Y"));
}elseif($time == 'cur_month') {
$start_time = strtotime(date('Y-m-1').'-1 day')+24*60*60;
$end_time = strtotime(date('Y-m-1 00:00:00',strtotime('next month')));
}elseif($time == 'cur_year') {
$start_time = strtotime(date('Y-1-1 00:00:00',time()));
$end_time = strtotime(date('Y-1-1 00:00:00',strtotime('+1 year')));
}
$where = array();
$where['c.order_time'] = array(['>',$start_time],['<',$end_time],'AND');
return Db::name('customer')->alias('a')
->where($where)
->join('customerInvite b','a.customer_id=b.customer_id','left')
->join('order c','b.invite_id=c.invite_id','left')
->count();
}
获取指定分类的所有子分类ID(不需要自身id就子集unset掉)
public static function getAllChildcateIds($categoryID)
{
$array[] = $categoryID;
do
{
$ids = '';
$where['parent_id'] = array('in',$categoryID);
$cate = Db::name('merchant')->where($where)->select();
foreach ($cate as $k=>$v)
{
$array[] = $v['mid'];
$ids .= ',' . $v['mid'];
}
$ids = substr($ids, 1, strlen($ids));
$categoryID = $ids;
}
while (!empty($cate));
return $array;
}