79 lines
2.5 KiB
PHP
79 lines
2.5 KiB
PHP
<?php
|
|
namespace app\api\model;
|
|
|
|
|
|
/**
|
|
* 优惠券订阅
|
|
* @mixin \think\Model
|
|
*/
|
|
class CouponSubscribe extends BaseModel
|
|
{
|
|
protected $schema = [
|
|
'id' =>'int',
|
|
'platform_id' =>'int',
|
|
'language_id' =>'int',
|
|
'site_id' =>'int',
|
|
'goods_coupon_id' =>'int',
|
|
'email' =>'string',
|
|
'phone' =>'string',
|
|
'create_time' =>'int',
|
|
'update_time' =>'int',
|
|
];
|
|
|
|
/**
|
|
* 获取列表
|
|
* @param array $data 查询条件
|
|
* @param mixed $simple 模糊搜索条件
|
|
* @param mixed $focus 精准搜索条件
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function getAllList($data,$simple = null,$focus = null,$sort = null,$field = null)
|
|
{
|
|
$fields = array_keys($this->schema);
|
|
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
|
if (in_array('platform_id',$fields)) {
|
|
$query->where('platform_id',$data['platform_id']);
|
|
}
|
|
//模糊查询条件
|
|
if (!empty($simple)) {
|
|
foreach ($simple as $key => $item) {
|
|
if (in_array($key,$fields)) {
|
|
$query->where($key,'like',"%".$item."%");
|
|
}
|
|
}
|
|
}
|
|
//精准查询
|
|
if (!empty($focus)) {
|
|
foreach ($focus as $key => $item) {
|
|
if (in_array($key,$fields)) {
|
|
$query->where($key,$item);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
if (isset($data['page']) && isset($data['size'])) {
|
|
$count = $collection->count() ?: 0;
|
|
$page = $collection->limit($data['size'])->page($data['page'])->order($sort)->select()->toArray();
|
|
if (!empty($page)) {
|
|
foreach ($page as $key => $item) {
|
|
$page[$key]['language_name'] = $this->getLanguageName($item['site_id']);
|
|
}
|
|
}
|
|
return ['page'=>$page,'count'=>$count];
|
|
} else {
|
|
$page = $collection->order($sort)->select()->toArray();
|
|
if (!empty($page)) {
|
|
foreach ($page as $key => $item) {
|
|
$page[$key]['language_name'] = $this->getLanguageName($item['site_id']);
|
|
}
|
|
}
|
|
return $page;
|
|
}
|
|
}
|
|
|
|
}
|