startTrans(); try { (new StoreModel())->where('store_id', '=', $params['store_id']) ->save([ 'is_good' => $params['is_good'], ]); // 参与分销 if ($params['is_good'] == 1) { // 先删除 $model = self::detail($params['store_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($storeIds, $is_good) { $storeIds = explode(",",$storeIds); if($is_good == 1){ // 先删除之前的以防重复添加 $model = $this; $this->where('store_id', 'in', $storeIds)->delete(); foreach ($storeIds as $val){ $save_data=[ 'store_id' => $val, 'app_id' => self::$app_id, ]; $model->create($save_data); } } return (new StoreModel)->where('store_id', 'in', $storeIds)->save(['is_good' => $is_good]); } }