51 lines
1.9 KiB
PHP
51 lines
1.9 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class Auto_product_coupon_model extends HD_Model
|
|
{
|
|
private $table_name = 'lc_auto_product_coupon';
|
|
const DEFAULT_CLUES_COMMISSION = 15; //默认线索佣金
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct($this->table_name, 'default');
|
|
$this->load->model('agent/auto_product_coupon_biz_model', 'autoProductCouponBiz');
|
|
}
|
|
|
|
public function saveOrUpdate($params)
|
|
{
|
|
$addData = [
|
|
'title' => $params['title'],
|
|
'timeStart' => $params['dateRange'][0],
|
|
'timeEnd' => $params['dateRange'][1],
|
|
'price' => $params['price'],
|
|
'rule' => $params['rule'],
|
|
'userType' => $params['userType'],
|
|
];
|
|
if ($params['id']) {
|
|
$result = $this->update($addData, ['id' => $params['id']]);
|
|
} else {
|
|
$addData['product_id'] = $params['productId'];
|
|
$result = $this->add($addData);
|
|
$params['id'] = $result;
|
|
}
|
|
//更新适用门店
|
|
if ($params['userType'] || !$params['bizs']) { //全国或未选择适用门店
|
|
$this->autoProductCouponBiz->delete(['coupon_id' => $params['id']]);
|
|
} else {
|
|
$biz_string = implode(',', $params['bizs']);
|
|
$this->autoProductCouponBiz->delete(['coupon_id' => $params['id'], "biz_id not in ($biz_string)" => null]);
|
|
$replace_batch = [];
|
|
foreach ($params['bizs'] as $biz) {
|
|
$replace_batch[] = [
|
|
'product_id' => $params['productId'],
|
|
'biz_id' => $biz,
|
|
'coupon_id' => $params['id'],
|
|
];
|
|
}
|
|
$this->autoProductCouponBiz->replace_batch($replace_batch);
|
|
}
|
|
return $result;
|
|
}
|
|
}
|