Files
spacestation/common/models/agent/Auto_product_city_model.php
2025-09-09 17:55:20 +08:00

40 lines
1.1 KiB
PHP

<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Auto_product_city_model extends HD_Model
{
private $table_name = 'lc_auto_product_city';
public function __construct()
{
parent::__construct($this->table_name, 'default');
}
/**
* @param $productId
* @param $citys
* @return true|void
*/
public function updateProductCity($productId, $citys = [])
{
if ($citys) {
$cityIds = [];
foreach ($citys as $item) {
$cityIds[] = $item[1];
$replace_batch[] = [
'productId' => $productId,
'provinceId' => $item[0],
'cityId' => $item[1],
];
}
$cityIdString = implode(',', $cityIds);
$cityIdString && $this->delete(['productId' => $productId, "cityId not in ($cityIdString)" => null]);
is_array($replace_batch) && $this->replace_batch($replace_batch);
} else {
$this->delete(['productId' => $productId]);
}
return true;
}
}