Files
spacestation/common/libraries/entity/AutoProductCouponEntity.php
T
2025-07-27 12:22:34 +08:00

124 lines
3.6 KiB
PHP

<?php
class AutoProductCouponEntity
{
public $id;
public $title;
public $userType;
public $timeStart;
public $timeEnd;
public $price;
public $rule;
public $type;
public $productId;
public $status;
public function __construct()
{
}
/**
* 获取适用门店列表
* @return array
*/
public function getBizs()
{
$ci = &get_instance();
$ci->load->model('agent/auto_product_coupon_biz_model', 'autoProductCouponBiz');
$rows = $ci->autoProductCouponBiz->select(['coupon_id' => $this->id], '', '', '', 'biz_id');
$result = [];
if (!empty($rows)) {
foreach ($rows as $row) {
$result[] = $row['biz_id'];
}
}
return $result;
}
/**
* 获取选中门店名称
* @return array
*/
public function getShowBiz($bizs, $cityId = '')
{
$ci = &get_instance();
$ci->load->model('biz/biz_model');
$ci->biz_model->set_db('ssdb');
if (empty($bizs)) {
return [];
}
$biz_string = implode(',', $bizs);
$where = ["id in ($biz_string)" => null];
if ($cityId) {
$where['city_id'] = $cityId;
}
$rows = $ci->biz_model->select($where, '', '', '', 'id,biz_name as name');
$result = [];
if (!empty($rows)) {
foreach ($rows as $row) {
$result[$row['id']] = $row['name'];
}
}
return $result;
}
public function getTypeCn()
{
$typeCn = [
0 => '购车补贴',
];
return isset($typeCn[$this->type]) ? $typeCn[$this->type] : '';
}
/**
* 获取适用门店文案
* @return void
*/
public function getBizTip()
{
$ci = &get_instance();
$ci->load->model('agent/auto_product_coupon_biz_model', 'autoProductCouponBiz');
$ci->load->model('biz/biz_model');
$ci->biz_model->set_db('ssdb');
$where = ['coupon_id' => $this->id];
$total = $ci->autoProductCouponBiz->count($where);
$row = $ci->autoProductCouponBiz->get($where);
$bizName = '';
if ($row) {
$bizRow = $ci->biz_model->get(['id' => $row['biz_id']], 'biz_name');
$bizRow && $bizName = $bizRow['biz_name'] . '等';
}
$result = "适用 {$bizName} {$total}家门店";
return $result;
}
public function getBizList($page = 0, $size = 0)
{
$bizIds = $this->getBizs();
$ci = &get_instance();
$ci->load->model('area_model');
$ci->load->model('biz/biz_model');
$ci->biz_model->set_db('ssdb');
$biz_string = implode(',', $bizIds);
!$biz_string && $biz_string = 0;
$where = ["id in ($biz_string)" => null];
$rows = $ci->biz_model->select($where, '', $page, $size);
$list = [];
if (!empty($rows)) {
foreach ($rows as $row) {
$city = $ci->area_model->get(['city_id' => $row['city_id']]);
$temp = [
'id' => $row['id'],
'biz_name' => $row['biz_name'],
'address' => $row['address'],
'province_name' => $city['province_name'] ?: '',
'city_name' => $city['city_name'] ?: '',
];
$list[] = $temp;
}
}
return ['list' => $list, 'count' => count($bizIds)];
}
}