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