<?php
|
|
namespace app\operations\model\plus\goodcoupon;
|
|
use app\common\model\plus\goodcoupon\Coupon as GoodCouponModel;
|
use app\common\model\product\Product as ProductModel;
|
|
/**
|
* 模型
|
*/
|
class Coupon extends GoodCouponModel
|
{
|
|
/**
|
* 保存
|
*/
|
public function edit($params)
|
{
|
$this->startTrans();
|
try {
|
(new ProductModel())->where('product_id', '=', $params['product_id'])
|
->save([
|
'is_good' => $params['is_good'],
|
]);
|
// 参与好券
|
if ($params['is_good'] == 1) {
|
// 先删除
|
$model = self::detail($params['product_id']);
|
if(!$model){
|
$model = new self();
|
}
|
$model->save(array_merge($params, [
|
'app_id' => self::$app_id
|
]));
|
}
|
$this->commit();
|
return true;
|
} catch (\Exception $e) {
|
$this->error = $e->getMessage();
|
$this->rollback();
|
return false;
|
}
|
}
|
|
//设置状态
|
public function setStatus($productIds, $is_good)
|
{
|
$productIds = explode(",",$productIds);
|
if($is_good == 1){
|
// 先删除
|
$model = $this;
|
$this->where('product_id', 'in', $productIds)->delete();
|
foreach ($productIds as $val){
|
$save_data=[
|
'product_id' => $val,
|
'app_id' => self::$app_id,
|
];
|
$model->create($save_data);
|
}
|
}
|
return (new ProductModel)->where('product_id', 'in', $productIds)->save(['is_good' => $is_good]);
|
}
|
}
|