quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?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]);
    }
}